blob: 1877a2199d04e640c83bd3bc79bcaf2354472747 [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
John McCall5250f272010-06-03 19:28:45 +000041 CXXBaseSpecifier *ReadCXXBaseSpecifier();
42
Chris Lattner698f9252009-04-27 05:27:42 +000043 void VisitDecl(Decl *D);
44 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
45 void VisitNamedDecl(NamedDecl *ND);
Douglas Gregor0cef4832010-02-21 18:22:14 +000046 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000047 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
48 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000049 void VisitTypeDecl(TypeDecl *TD);
50 void VisitTypedefDecl(TypedefDecl *TD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000051 void VisitUnresolvedUsingTypename(UnresolvedUsingTypenameDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000052 void VisitTagDecl(TagDecl *TD);
53 void VisitEnumDecl(EnumDecl *ED);
54 void VisitRecordDecl(RecordDecl *RD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000055 void VisitCXXRecordDecl(CXXRecordDecl *D);
56 void VisitClassTemplateSpecializationDecl(
57 ClassTemplateSpecializationDecl *D);
58 void VisitClassTemplatePartialSpecializationDecl(
59 ClassTemplatePartialSpecializationDecl *D);
60 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000061 void VisitValueDecl(ValueDecl *VD);
62 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000063 void VisitUnresolvedUsingValue(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +000064 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner698f9252009-04-27 05:27:42 +000065 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000066 void VisitCXXMethodDecl(CXXMethodDecl *D);
67 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
68 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
69 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000070 void VisitFieldDecl(FieldDecl *FD);
71 void VisitVarDecl(VarDecl *VD);
72 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
73 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000074 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
75 void VisitTemplateDecl(TemplateDecl *D);
76 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +000077 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000078 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Argyrios Kyrtzidisb01a5522010-06-20 14:40:59 +000079 void VisitUsingDecl(UsingDecl *D);
80 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000081 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000082 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Abramo Bagnara6206d532010-06-05 05:09:32 +000083 void VisitAccessSpecDecl(AccessSpecDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000084 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
85 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000086 void VisitBlockDecl(BlockDecl *BD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000087
Chris Lattner698f9252009-04-27 05:27:42 +000088 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000089
Sean Hunt9a555912010-05-30 07:21:58 +000090 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner698f9252009-04-27 05:27:42 +000091 void VisitObjCMethodDecl(ObjCMethodDecl *D);
92 void VisitObjCContainerDecl(ObjCContainerDecl *D);
93 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
94 void VisitObjCIvarDecl(ObjCIvarDecl *D);
95 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
96 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
97 void VisitObjCClassDecl(ObjCClassDecl *D);
98 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
99 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
100 void VisitObjCImplDecl(ObjCImplDecl *D);
101 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
102 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
103 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
104 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
105 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
106 };
107}
108
109void PCHDeclReader::VisitDecl(Decl *D) {
110 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
111 D->setLexicalDeclContext(
112 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
113 D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
114 D->setInvalidDecl(Record[Idx++]);
115 if (Record[Idx++])
Argyrios Kyrtzidis1715bf52010-06-11 23:09:25 +0000116 D->initAttrs(Reader.ReadAttributes());
Chris Lattner698f9252009-04-27 05:27:42 +0000117 D->setImplicit(Record[Idx++]);
Douglas Gregore0762c92009-06-19 23:52:42 +0000118 D->setUsed(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000119 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor7d1d49d2009-10-16 20:01:17 +0000120 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner698f9252009-04-27 05:27:42 +0000121}
122
123void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
124 VisitDecl(TU);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000125 TU->setAnonymousNamespace(
126 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000127}
128
129void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) {
130 VisitDecl(ND);
Mike Stump1eb44332009-09-09 15:08:12 +0000131 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000132}
133
134void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
135 VisitNamedDecl(TD);
136 TD->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
137}
138
139void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
140 // Note that we cannot use VisitTypeDecl here, because we need to
141 // set the underlying type of the typedef *before* we try to read
142 // the type associated with the TypedefDecl.
143 VisitNamedDecl(TD);
John McCallba6a9bd2009-10-24 08:00:42 +0000144 uint64_t TypeData = Record[Idx++];
John McCalla93c9342009-12-07 02:54:59 +0000145 TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
John McCallba6a9bd2009-10-24 08:00:42 +0000146 TD->setTypeForDecl(Reader.GetType(TypeData).getTypePtr());
Chris Lattner698f9252009-04-27 05:27:42 +0000147}
148
149void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
150 VisitTypeDecl(TD);
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +0000151 TD->setPreviousDeclaration(
152 cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000153 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
154 TD->setDefinition(Record[Idx++]);
Douglas Gregorb37b6482010-02-12 17:40:34 +0000155 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidisad93a742009-07-14 03:18:02 +0000156 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000157 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCallb6217662010-03-15 10:12:16 +0000158 // FIXME: maybe read optional qualifier and its range.
159 TD->setTypedefForAnonDecl(
160 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000161}
162
163void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
164 VisitTagDecl(ED);
165 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall842aef82009-12-09 09:09:27 +0000166 ED->setPromotionType(Reader.GetType(Record[Idx++]));
John McCall1b5a6182010-05-06 08:49:23 +0000167 ED->setNumPositiveBits(Record[Idx++]);
168 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor8dbc3c62009-05-27 17:20:35 +0000169 // FIXME: C++ InstantiatedFrom
Chris Lattner698f9252009-04-27 05:27:42 +0000170}
171
172void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
173 VisitTagDecl(RD);
174 RD->setHasFlexibleArrayMember(Record[Idx++]);
175 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian643b7df2009-07-08 16:37:44 +0000176 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000177}
178
179void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
180 VisitNamedDecl(VD);
181 VD->setType(Reader.GetType(Record[Idx++]));
182}
183
184void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
185 VisitValueDecl(ECD);
186 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000187 ECD->setInitExpr(Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000188 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
189}
190
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000191void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
192 VisitValueDecl(DD);
John McCalla93c9342009-12-07 02:54:59 +0000193 TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Record, Idx);
194 if (TInfo)
195 DD->setTypeSourceInfo(TInfo);
John McCallb6217662010-03-15 10:12:16 +0000196 // FIXME: read optional qualifier and its range.
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000197}
198
Chris Lattner698f9252009-04-27 05:27:42 +0000199void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000200 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000201 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000202 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
Chris Lattner698f9252009-04-27 05:27:42 +0000203 FD->setPreviousDeclaration(
204 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
205 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
Douglas Gregor16573fa2010-04-19 22:54:31 +0000206 FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]);
Douglas Gregor0130f3c2009-10-27 21:01:01 +0000207 FD->setInlineSpecified(Record[Idx++]);
Anders Carlsson77b7f1d2009-05-14 22:15:41 +0000208 FD->setVirtualAsWritten(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000209 FD->setPure(Record[Idx++]);
Anders Carlssona75e8532009-05-14 21:46:00 +0000210 FD->setHasInheritedPrototype(Record[Idx++]);
211 FD->setHasWrittenPrototype(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000212 FD->setDeleted(Record[Idx++]);
Daniel Dunbar7f8b57a2009-09-22 05:38:14 +0000213 FD->setTrivial(Record[Idx++]);
214 FD->setCopyAssignment(Record[Idx++]);
215 FD->setHasImplicitReturnZero(Record[Idx++]);
Argyrios Kyrtzidis8cff90e2009-06-20 08:09:34 +0000216 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000217
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000218 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
219 case FunctionDecl::TK_NonTemplate:
220 break;
221 case FunctionDecl::TK_FunctionTemplate:
222 FD->setDescribedFunctionTemplate(
223 cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++])));
224 break;
225 case FunctionDecl::TK_MemberSpecialization: {
226 FunctionDecl *InstFD = cast<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
227 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
228 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
229 FD->setInstantiationOfMemberFunction(InstFD, TSK);
230 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
231 break;
232 }
233 case FunctionDecl::TK_FunctionTemplateSpecialization: {
234 FunctionTemplateDecl *Template
235 = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
236 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
237
238 // Template arguments.
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000239 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000240 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000241
242 // Template args as written.
243 unsigned NumTemplateArgLocs = Record[Idx++];
244 llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
245 TemplArgLocs.reserve(NumTemplateArgLocs);
246 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
247 TemplArgLocs.push_back(Reader.ReadTemplateArgumentLoc(Record, Idx));
248
249 SourceLocation LAngleLoc, RAngleLoc;
250 if (NumTemplateArgLocs) {
251 LAngleLoc = Reader.ReadSourceLocation(Record, Idx);
252 RAngleLoc = Reader.ReadSourceLocation(Record, Idx);
253 }
254
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000255 FD->setFunctionTemplateSpecialization(Template, TemplArgs.size(),
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000256 TemplArgs.data(), TSK,
257 NumTemplateArgLocs,
258 NumTemplateArgLocs ? TemplArgLocs.data() : 0,
259 LAngleLoc, RAngleLoc);
260 }
261 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
262 // Templates.
263 UnresolvedSet<8> TemplDecls;
264 unsigned NumTemplates = Record[Idx++];
265 while (NumTemplates--)
266 TemplDecls.addDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
267
268 // Templates args.
269 TemplateArgumentListInfo TemplArgs;
270 unsigned NumArgs = Record[Idx++];
271 while (NumArgs--)
272 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
273
274 FD->setDependentTemplateSpecialization(*Reader.getContext(),
275 TemplDecls, TemplArgs);
276 }
277 }
278
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000279 // Read in the parameters.
Chris Lattner698f9252009-04-27 05:27:42 +0000280 unsigned NumParams = Record[Idx++];
281 llvm::SmallVector<ParmVarDecl *, 16> Params;
282 Params.reserve(NumParams);
283 for (unsigned I = 0; I != NumParams; ++I)
284 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor838db382010-02-11 01:19:42 +0000285 FD->setParams(Params.data(), NumParams);
John McCall76d32642010-04-24 01:30:58 +0000286
287 // FIXME: order this properly w.r.t. friendness
288 // FIXME: this same thing needs to happen for function templates
289 if (FD->isOverloadedOperator() && !FD->getDeclContext()->isRecord())
290 FD->setNonMemberOperator();
Chris Lattner698f9252009-04-27 05:27:42 +0000291}
292
293void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
294 VisitNamedDecl(MD);
295 if (Record[Idx++]) {
296 // In practice, this won't be executed (since method definitions
297 // don't occur in header files).
Chris Lattnerda930612009-04-27 05:58:23 +0000298 MD->setBody(Reader.ReadDeclStmt());
Chris Lattner698f9252009-04-27 05:27:42 +0000299 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
300 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
301 }
302 MD->setInstanceMethod(Record[Idx++]);
303 MD->setVariadic(Record[Idx++]);
304 MD->setSynthesized(Record[Idx++]);
305 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
306 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahanian7732cc92010-04-08 21:29:11 +0000307 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000308 MD->setResultType(Reader.GetType(Record[Idx++]));
Douglas Gregor4bc1cb62010-03-08 14:59:44 +0000309 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000310 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
311 unsigned NumParams = Record[Idx++];
312 llvm::SmallVector<ParmVarDecl *, 16> Params;
313 Params.reserve(NumParams);
314 for (unsigned I = 0; I != NumParams; ++I)
315 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanian4ecb25f2010-04-09 15:40:42 +0000316 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
317 NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000318}
319
320void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
321 VisitNamedDecl(CD);
Ted Kremenek782f2f52010-01-07 01:20:12 +0000322 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
323 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
324 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner698f9252009-04-27 05:27:42 +0000325}
326
327void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
328 VisitObjCContainerDecl(ID);
329 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
330 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
331 (Reader.GetDecl(Record[Idx++])));
332 unsigned NumProtocols = Record[Idx++];
333 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
334 Protocols.reserve(NumProtocols);
335 for (unsigned I = 0; I != NumProtocols; ++I)
336 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000337 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
338 ProtoLocs.reserve(NumProtocols);
339 for (unsigned I = 0; I != NumProtocols; ++I)
340 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
341 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
342 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000343 unsigned NumIvars = Record[Idx++];
344 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
345 IVars.reserve(NumIvars);
346 for (unsigned I = 0; I != NumIvars; ++I)
347 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000348 ID->setCategoryList(
349 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
350 ID->setForwardDecl(Record[Idx++]);
351 ID->setImplicitInterfaceDecl(Record[Idx++]);
352 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
353 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisc999f1f2009-07-18 00:33:23 +0000354 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000355}
356
357void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
358 VisitFieldDecl(IVD);
359 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
360}
361
362void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
363 VisitObjCContainerDecl(PD);
364 PD->setForwardDecl(Record[Idx++]);
365 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
366 unsigned NumProtoRefs = Record[Idx++];
367 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
368 ProtoRefs.reserve(NumProtoRefs);
369 for (unsigned I = 0; I != NumProtoRefs; ++I)
370 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000371 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
372 ProtoLocs.reserve(NumProtoRefs);
373 for (unsigned I = 0; I != NumProtoRefs; ++I)
374 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
375 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
376 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000377}
378
379void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
380 VisitFieldDecl(FD);
381}
382
383void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
384 VisitDecl(CD);
385 unsigned NumClassRefs = Record[Idx++];
386 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
387 ClassRefs.reserve(NumClassRefs);
388 for (unsigned I = 0; I != NumClassRefs; ++I)
389 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek321c22f2009-11-18 00:28:11 +0000390 llvm::SmallVector<SourceLocation, 16> SLocs;
391 SLocs.reserve(NumClassRefs);
392 for (unsigned I = 0; I != NumClassRefs; ++I)
393 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
394 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
395 NumClassRefs);
Chris Lattner698f9252009-04-27 05:27:42 +0000396}
397
398void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
399 VisitDecl(FPD);
400 unsigned NumProtoRefs = Record[Idx++];
401 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
402 ProtoRefs.reserve(NumProtoRefs);
403 for (unsigned I = 0; I != NumProtoRefs; ++I)
404 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000405 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
406 ProtoLocs.reserve(NumProtoRefs);
407 for (unsigned I = 0; I != NumProtoRefs; ++I)
408 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
409 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
410 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000411}
412
413void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
414 VisitObjCContainerDecl(CD);
415 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
416 unsigned NumProtoRefs = Record[Idx++];
417 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
418 ProtoRefs.reserve(NumProtoRefs);
419 for (unsigned I = 0; I != NumProtoRefs; ++I)
420 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000421 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
422 ProtoLocs.reserve(NumProtoRefs);
423 for (unsigned I = 0; I != NumProtoRefs; ++I)
424 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
425 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
426 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000427 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor3db211b2010-01-16 16:38:58 +0000428 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
429 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000430}
431
432void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
433 VisitNamedDecl(CAD);
434 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
435}
436
437void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
438 VisitNamedDecl(D);
Fariborz Jahaniand0502402010-01-21 17:36:00 +0000439 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall83a230c2010-06-04 20:50:08 +0000440 D->setType(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000441 // FIXME: stable encoding
442 D->setPropertyAttributes(
443 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000444 D->setPropertyAttributesAsWritten(
445 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000446 // FIXME: stable encoding
447 D->setPropertyImplementation(
448 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
449 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
450 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
451 D->setGetterMethodDecl(
452 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
453 D->setSetterMethodDecl(
454 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
455 D->setPropertyIvarDecl(
456 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
457}
458
459void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidisaecae622009-07-27 19:04:32 +0000460 VisitObjCContainerDecl(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000461 D->setClassInterface(
462 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000463}
464
465void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
466 VisitObjCImplDecl(D);
467 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
468}
469
470void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
471 VisitObjCImplDecl(D);
472 D->setSuperClass(
473 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniane4498c62010-04-28 16:11:27 +0000474 // FIXME. Add reading of IvarInitializers and NumIvarInitializers.
Chris Lattner698f9252009-04-27 05:27:42 +0000475}
476
477
478void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
479 VisitDecl(D);
480 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
481 D->setPropertyDecl(
482 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
483 D->setPropertyIvarDecl(
484 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanian17cb3262010-05-05 21:52:17 +0000485 // FIXME. read GetterCXXConstructor and SetterCXXAssignment
Chris Lattner698f9252009-04-27 05:27:42 +0000486}
487
488void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000489 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000490 FD->setMutable(Record[Idx++]);
491 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000492 FD->setBitWidth(Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000493}
494
495void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000496 VisitDeclaratorDecl(VD);
Chris Lattner698f9252009-04-27 05:27:42 +0000497 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
Douglas Gregor16573fa2010-04-19 22:54:31 +0000498 VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000499 VD->setThreadSpecified(Record[Idx++]);
500 VD->setCXXDirectInitializer(Record[Idx++]);
501 VD->setDeclaredInCondition(Record[Idx++]);
Douglas Gregor324b54d2010-05-03 18:51:14 +0000502 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor5077c382010-05-15 06:01:05 +0000503 VD->setNRVOVariable(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000504 VD->setPreviousDeclaration(
505 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000506 if (Record[Idx++])
Douglas Gregor838db382010-02-11 01:19:42 +0000507 VD->setInit(Reader.ReadDeclExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000508}
509
510void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
511 VisitVarDecl(PD);
512}
513
514void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
515 VisitVarDecl(PD);
516 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallbf73b352010-03-12 18:31:32 +0000517 PD->setHasInheritedDefaultArg(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000518}
519
Chris Lattner698f9252009-04-27 05:27:42 +0000520void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
521 VisitDecl(AD);
Chris Lattnerda930612009-04-27 05:58:23 +0000522 AD->setAsmString(cast<StringLiteral>(Reader.ReadDeclExpr()));
Chris Lattner698f9252009-04-27 05:27:42 +0000523}
524
525void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
526 VisitDecl(BD);
Chris Lattnerda930612009-04-27 05:58:23 +0000527 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadDeclStmt()));
John McCall82dc0092010-06-04 11:21:44 +0000528 BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000529 unsigned NumParams = Record[Idx++];
530 llvm::SmallVector<ParmVarDecl *, 16> Params;
531 Params.reserve(NumParams);
532 for (unsigned I = 0; I != NumParams; ++I)
533 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor838db382010-02-11 01:19:42 +0000534 BD->setParams(Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000535}
536
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000537void PCHDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
538 VisitDecl(D);
539 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
540 D->setHasBraces(Record[Idx++]);
541}
542
543void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
544 VisitNamedDecl(D);
545 D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx));
546 D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx));
547 D->setNextNamespace(
548 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
549
550 // Only read one reference--the original or anonymous namespace.
551 bool IsOriginal = Record[Idx++];
552 if (IsOriginal)
553 D->setAnonymousNamespace(
554 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
555 else
556 D->setOriginalNamespace(
557 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
558}
559
560void PCHDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
561 VisitNamedDecl(D);
562
563 D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx));
564 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
565 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
566 D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx));
567 D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
568}
569
Argyrios Kyrtzidisb01a5522010-06-20 14:40:59 +0000570void PCHDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000571 VisitNamedDecl(D);
572 D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
573 D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
574 D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
575
576 // FIXME: It would probably be more efficient to read these into a vector
577 // and then re-cosntruct the shadow decl set over that vector since it
578 // would avoid existence checks.
579 unsigned NumShadows = Record[Idx++];
580 for(unsigned I = 0; I != NumShadows; ++I) {
581 D->addShadowDecl(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])));
582 }
583 D->setTypeName(Record[Idx++]);
584}
585
Argyrios Kyrtzidisb01a5522010-06-20 14:40:59 +0000586void PCHDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000587 VisitNamedDecl(D);
588 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
589 D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
590}
591
592void PCHDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
593 VisitNamedDecl(D);
594 D->setNamespaceKeyLocation(Reader.ReadSourceLocation(Record, Idx));
595 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
596 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
597 D->setIdentLocation(Reader.ReadSourceLocation(Record, Idx));
598 D->setNominatedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
599 D->setCommonAncestor(cast_or_null<DeclContext>(
600 Reader.GetDecl(Record[Idx++])));
601}
602
603void PCHDeclReader::VisitUnresolvedUsingValue(UnresolvedUsingValueDecl *D) {
604 VisitValueDecl(D);
605 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
606 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
607 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
608}
609
610void PCHDeclReader::VisitUnresolvedUsingTypename(
611 UnresolvedUsingTypenameDecl *D) {
612 VisitTypeDecl(D);
613 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
614 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
615 D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx));
616 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
617}
618
John McCall5250f272010-06-03 19:28:45 +0000619CXXBaseSpecifier *PCHDeclReader::ReadCXXBaseSpecifier() {
620 bool isVirtual = static_cast<bool>(Record[Idx++]);
621 bool isBaseOfClass = static_cast<bool>(Record[Idx++]);
622 AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]);
623 QualType T = Reader.GetType(Record[Idx++]);
624 SourceRange Range = Reader.ReadSourceRange(Record, Idx);
625 return new (*Reader.getContext())
626 CXXBaseSpecifier(Range, isVirtual, isBaseOfClass, AS, T);
627}
628
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000629void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
630 // assert(false && "cannot read CXXRecordDecl");
631 VisitRecordDecl(D);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000632
633 enum CXXRecKind {
634 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
635 };
636 switch ((CXXRecKind)Record[Idx++]) {
637 default:
638 assert(false && "Out of sync with PCHDeclWriter::VisitCXXRecordDecl?");
639 case CXXRecNotTemplate:
640 break;
641 case CXXRecTemplate:
642 D->setDescribedClassTemplate(
643 cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++])));
644 break;
645 case CXXRecMemberSpecialization: {
646 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
647 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
648 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
649 D->setInstantiationOfMemberClass(RD, TSK);
650 D->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
651 break;
652 }
653 }
John McCall5250f272010-06-03 19:28:45 +0000654
Argyrios Kyrtzidis28d16d72010-06-19 19:29:21 +0000655 // FIXME: Hack. See PCHDeclWriter::VisitTypeDecl.
656 D->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
657
John McCall5250f272010-06-03 19:28:45 +0000658 // FIXME: this is far from complete
659
660 if (D->isDefinition()) {
661 D->setDefinition(false); // make peace with an assertion
662 D->startDefinition();
663
664 unsigned NumBases = Record[Idx++];
665
666 llvm::SmallVector<CXXBaseSpecifier*, 4> Bases;
667 Bases.reserve(NumBases);
668 for (unsigned I = 0; I != NumBases; ++I)
669 Bases.push_back(ReadCXXBaseSpecifier());
670 D->setBases(Bases.begin(), NumBases);
671
672 // FIXME: there's a lot of stuff we do here that's kindof sketchy
673 // if we're leaving the context incomplete.
674 D->completeDefinition();
675 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000676}
677
678void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
679 // assert(false && "cannot read CXXMethodDecl");
680 VisitFunctionDecl(D);
681}
682
683void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
684 // assert(false && "cannot read CXXConstructorDecl");
685 VisitCXXMethodDecl(D);
686}
687
688void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
689 // assert(false && "cannot read CXXDestructorDecl");
690 VisitCXXMethodDecl(D);
691}
692
693void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
694 // assert(false && "cannot read CXXConversionDecl");
695 VisitCXXMethodDecl(D);
696}
697
Abramo Bagnara6206d532010-06-05 05:09:32 +0000698void PCHDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
699 VisitDecl(D);
700 D->setColonLoc(Reader.ReadSourceLocation(Record, Idx));
701}
702
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000703void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
704 assert(false && "cannot read FriendTemplateDecl");
705}
706
707void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000708 VisitNamedDecl(D);
709
710 NamedDecl *TemplatedDecl = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000711 TemplateParameterList* TemplateParams
712 = Reader.ReadTemplateParameterList(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000713 D->init(TemplatedDecl, TemplateParams);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000714}
715
716void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000717 VisitTemplateDecl(D);
718
719 ClassTemplateDecl *PrevDecl =
720 cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis5bf1bdc2010-06-21 10:57:41 +0000721 D->setPreviousDeclaration(PrevDecl);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000722 if (PrevDecl == 0) {
723 // This ClassTemplateDecl owns a CommonPtr; read it.
724
725 unsigned size = Record[Idx++];
726 while (size--) {
727 ClassTemplateSpecializationDecl *CTSD
728 = cast<ClassTemplateSpecializationDecl>(Reader.GetDecl(Record[Idx++]));
729 llvm::FoldingSetNodeID ID;
730 void *InsertPos = 0;
731 ClassTemplateSpecializationDecl::Profile(ID,
732 CTSD->getTemplateArgs().getFlatArgumentList(),
733 CTSD->getTemplateArgs().flat_size(),
734 *Reader.getContext());
735 D->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
736 D->getSpecializations().InsertNode(CTSD, InsertPos);
737 }
738
739 size = Record[Idx++];
740 while (size--) {
741 ClassTemplatePartialSpecializationDecl *CTSD
742 = cast<ClassTemplatePartialSpecializationDecl>(
743 Reader.GetDecl(Record[Idx++]));
744 llvm::FoldingSetNodeID ID;
745 void *InsertPos = 0;
746 ClassTemplatePartialSpecializationDecl::Profile(ID,
747 CTSD->getTemplateArgs().getFlatArgumentList(),
748 CTSD->getTemplateArgs().flat_size(),
749 *Reader.getContext());
750 D->getPartialSpecializations().FindNodeOrInsertPos(ID, InsertPos);
751 D->getPartialSpecializations().InsertNode(CTSD, InsertPos);
752 }
753
754 // InjectedClassNameType is computed.
755
756 if (ClassTemplateDecl *CTD
757 = cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
758 D->setInstantiatedFromMemberTemplate(CTD);
759 if (Record[Idx++])
760 D->setMemberSpecialization();
761 }
762 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000763}
764
765void PCHDeclReader::VisitClassTemplateSpecializationDecl(
766 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000767 VisitCXXRecordDecl(D);
768
769 if (Decl *InstD = Reader.GetDecl(Record[Idx++])) {
770 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
771 D->setInstantiationOf(CTD);
772 } else {
773 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
774 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
775 D->setInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(InstD),
776 TemplArgs.data(), TemplArgs.size());
777 }
778 }
779
780 // Explicit info.
781 if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Record, Idx)) {
782 D->setTypeAsWritten(TyInfo);
783 D->setExternLoc(Reader.ReadSourceLocation(Record, Idx));
784 D->setTemplateKeywordLoc(Reader.ReadSourceLocation(Record, Idx));
785 }
786
787 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
788 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
789 D->initTemplateArgs(TemplArgs.data(), TemplArgs.size());
790 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
791 if (POI.isValid())
792 D->setPointOfInstantiation(POI);
793 D->setSpecializationKind((TemplateSpecializationKind)Record[Idx++]);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000794}
795
796void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl(
797 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000798 VisitClassTemplateSpecializationDecl(D);
799
800 D->initTemplateParameters(Reader.ReadTemplateParameterList(Record, Idx));
801
802 TemplateArgumentListInfo ArgInfos;
803 unsigned NumArgs = Record[Idx++];
804 while (NumArgs--)
805 ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
806 D->initTemplateArgsAsWritten(ArgInfos);
807
808 D->setSequenceNumber(Record[Idx++]);
809
810 // These are read/set from/to the first declaration.
811 if (D->getPreviousDeclaration() == 0) {
812 D->setInstantiatedFromMember(
813 cast_or_null<ClassTemplatePartialSpecializationDecl>(
814 Reader.GetDecl(Record[Idx++])));
815 if (Record[Idx++])
816 D->isMemberSpecialization();
817 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000818}
819
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000820void PCHDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
821 VisitTemplateDecl(D);
822
823 FunctionTemplateDecl *PrevDecl =
824 cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
825 D->setPreviousDeclaration(PrevDecl);
826 if (PrevDecl == 0) {
827 // This FunctionTemplateDecl owns a CommonPtr; read it.
828
829 // FunctionTemplateSpecializationInfos are filled through the
830 // templated FunctionDecl's setFunctionTemplateSpecialization, no need to
831 // read them here.
832
833 if (FunctionTemplateDecl *CTD
834 = cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
835 D->setInstantiatedFromMemberTemplate(CTD);
836 if (Record[Idx++])
837 D->setMemberSpecialization();
838 }
839 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000840}
841
842void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000843 VisitTypeDecl(D);
844
845 D->setDeclaredWithTypename(Record[Idx++]);
846 D->setParameterPack(Record[Idx++]);
847
848 bool Inherited = Record[Idx++];
849 TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Record, Idx);
850 D->setDefaultArgument(DefArg, Inherited);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000851}
852
853void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
854 assert(false && "cannot read NonTypeTemplateParmDecl");
855}
856
857void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
858 assert(false && "cannot read TemplateTemplateParmDecl");
859}
860
861void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
862 assert(false && "cannot read StaticAssertDecl");
863}
864
Mike Stump1eb44332009-09-09 15:08:12 +0000865std::pair<uint64_t, uint64_t>
Chris Lattner698f9252009-04-27 05:27:42 +0000866PCHDeclReader::VisitDeclContext(DeclContext *DC) {
867 uint64_t LexicalOffset = Record[Idx++];
868 uint64_t VisibleOffset = Record[Idx++];
869 return std::make_pair(LexicalOffset, VisibleOffset);
870}
871
872//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000873// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +0000874//===----------------------------------------------------------------------===//
875
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000876/// \brief Reads attributes from the current stream position.
877Attr *PCHReader::ReadAttributes() {
878 unsigned Code = DeclsCursor.ReadCode();
Mike Stump1eb44332009-09-09 15:08:12 +0000879 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000880 "Expected unabbreviated record"); (void)Code;
Mike Stump1eb44332009-09-09 15:08:12 +0000881
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000882 RecordData Record;
883 unsigned Idx = 0;
884 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump1eb44332009-09-09 15:08:12 +0000885 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000886 (void)RecCode;
887
888#define SIMPLE_ATTR(Name) \
Sean Hunt387475d2010-06-16 23:43:53 +0000889 case attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000890 New = ::new (*Context) Name##Attr(); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000891 break
892
893#define STRING_ATTR(Name) \
Sean Hunt387475d2010-06-16 23:43:53 +0000894 case attr::Name: \
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000895 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000896 break
897
898#define UNSIGNED_ATTR(Name) \
Sean Hunt387475d2010-06-16 23:43:53 +0000899 case attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000900 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000901 break
902
903 Attr *Attrs = 0;
904 while (Idx < Record.size()) {
905 Attr *New = 0;
Sean Hunt387475d2010-06-16 23:43:53 +0000906 attr::Kind Kind = (attr::Kind)Record[Idx++];
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000907 bool IsInherited = Record[Idx++];
908
909 switch (Kind) {
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000910 default:
911 assert(0 && "Unknown attribute!");
912 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000913 STRING_ATTR(Alias);
Daniel Dunbar4e9255f2010-05-27 02:25:39 +0000914 SIMPLE_ATTR(AlignMac68k);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000915 UNSIGNED_ATTR(Aligned);
916 SIMPLE_ATTR(AlwaysInline);
917 SIMPLE_ATTR(AnalyzerNoReturn);
918 STRING_ATTR(Annotate);
919 STRING_ATTR(AsmLabel);
Sean Hunt7725e672009-11-25 04:20:27 +0000920 SIMPLE_ATTR(BaseCheck);
Mike Stump1eb44332009-09-09 15:08:12 +0000921
Sean Hunt387475d2010-06-16 23:43:53 +0000922 case attr::Blocks:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000923 New = ::new (*Context) BlocksAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000924 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
925 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000926
Eli Friedman8f4c59e2009-11-09 18:38:53 +0000927 SIMPLE_ATTR(CDecl);
928
Sean Hunt387475d2010-06-16 23:43:53 +0000929 case attr::Cleanup:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000930 New = ::new (*Context) CleanupAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000931 cast<FunctionDecl>(GetDecl(Record[Idx++])));
932 break;
933
934 SIMPLE_ATTR(Const);
935 UNSIGNED_ATTR(Constructor);
936 SIMPLE_ATTR(DLLExport);
937 SIMPLE_ATTR(DLLImport);
938 SIMPLE_ATTR(Deprecated);
939 UNSIGNED_ATTR(Destructor);
940 SIMPLE_ATTR(FastCall);
Sean Huntbbd37c62009-11-21 08:43:09 +0000941 SIMPLE_ATTR(Final);
Mike Stump1eb44332009-09-09 15:08:12 +0000942
Sean Hunt387475d2010-06-16 23:43:53 +0000943 case attr::Format: {
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000944 std::string Type = ReadString(Record, Idx);
945 unsigned FormatIdx = Record[Idx++];
946 unsigned FirstArg = Record[Idx++];
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000947 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000948 break;
949 }
Mike Stump1eb44332009-09-09 15:08:12 +0000950
Sean Hunt387475d2010-06-16 23:43:53 +0000951 case attr::FormatArg: {
Fariborz Jahanian5b160922009-05-20 17:41:43 +0000952 unsigned FormatIdx = Record[Idx++];
953 New = ::new (*Context) FormatArgAttr(FormatIdx);
954 break;
955 }
Mike Stump1eb44332009-09-09 15:08:12 +0000956
Sean Hunt387475d2010-06-16 23:43:53 +0000957 case attr::Sentinel: {
Fariborz Jahanian5b530052009-05-13 18:09:35 +0000958 int sentinel = Record[Idx++];
959 int nullPos = Record[Idx++];
960 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
961 break;
962 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000963
964 SIMPLE_ATTR(GNUInline);
Sean Hunt7725e672009-11-25 04:20:27 +0000965 SIMPLE_ATTR(Hiding);
Mike Stump1eb44332009-09-09 15:08:12 +0000966
Sean Hunt387475d2010-06-16 23:43:53 +0000967 case attr::IBAction:
Ted Kremenekefbddd22010-02-17 02:37:45 +0000968 New = ::new (*Context) IBActionAttr();
969 break;
970
Sean Hunt387475d2010-06-16 23:43:53 +0000971 case attr::IBOutlet:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000972 New = ::new (*Context) IBOutletAttr();
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000973 break;
974
Sean Hunt387475d2010-06-16 23:43:53 +0000975 case attr::IBOutletCollection: {
Ted Kremenek857e9182010-05-19 17:38:06 +0000976 ObjCInterfaceDecl *D =
977 cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++]));
978 New = ::new (*Context) IBOutletCollectionAttr(D);
979 break;
980 }
981
Ryan Flynn76168e22009-08-09 20:07:29 +0000982 SIMPLE_ATTR(Malloc);
Mike Stump1feade82009-08-26 22:31:08 +0000983 SIMPLE_ATTR(NoDebug);
984 SIMPLE_ATTR(NoInline);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000985 SIMPLE_ATTR(NoReturn);
986 SIMPLE_ATTR(NoThrow);
Mike Stump1eb44332009-09-09 15:08:12 +0000987
Sean Hunt387475d2010-06-16 23:43:53 +0000988 case attr::NonNull: {
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000989 unsigned Size = Record[Idx++];
990 llvm::SmallVector<unsigned, 16> ArgNums;
991 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
992 Idx += Size;
Ted Kremenek59616112010-02-11 07:31:47 +0000993 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000994 break;
995 }
Mike Stump1eb44332009-09-09 15:08:12 +0000996
Sean Hunt387475d2010-06-16 23:43:53 +0000997 case attr::ReqdWorkGroupSize: {
Nate Begeman6f3d8382009-06-26 06:32:41 +0000998 unsigned X = Record[Idx++];
999 unsigned Y = Record[Idx++];
1000 unsigned Z = Record[Idx++];
1001 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
1002 break;
1003 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001004
1005 SIMPLE_ATTR(ObjCException);
1006 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenek31c780d2010-02-18 00:05:45 +00001007 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenekb71368d2009-05-09 02:44:38 +00001008 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenek31c780d2010-02-18 00:05:45 +00001009 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenekb71368d2009-05-09 02:44:38 +00001010 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001011 SIMPLE_ATTR(Overloadable);
Sean Hunt7725e672009-11-25 04:20:27 +00001012 SIMPLE_ATTR(Override);
Anders Carlssona860e752009-08-08 18:23:56 +00001013 SIMPLE_ATTR(Packed);
Daniel Dunbar8a2c92c2010-05-27 01:12:46 +00001014 UNSIGNED_ATTR(MaxFieldAlignment);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001015 SIMPLE_ATTR(Pure);
1016 UNSIGNED_ATTR(Regparm);
1017 STRING_ATTR(Section);
1018 SIMPLE_ATTR(StdCall);
Douglas Gregorf813a2c2010-05-18 16:57:00 +00001019 SIMPLE_ATTR(ThisCall);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001020 SIMPLE_ATTR(TransparentUnion);
1021 SIMPLE_ATTR(Unavailable);
1022 SIMPLE_ATTR(Unused);
1023 SIMPLE_ATTR(Used);
Mike Stump1eb44332009-09-09 15:08:12 +00001024
Sean Hunt387475d2010-06-16 23:43:53 +00001025 case attr::Visibility:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001026 New = ::new (*Context) VisibilityAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001027 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
1028 break;
1029
1030 SIMPLE_ATTR(WarnUnusedResult);
1031 SIMPLE_ATTR(Weak);
Rafael Espindola11e8ce72010-02-23 22:00:30 +00001032 SIMPLE_ATTR(WeakRef);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001033 SIMPLE_ATTR(WeakImport);
1034 }
1035
1036 assert(New && "Unable to decode attribute?");
1037 New->setInherited(IsInherited);
1038 New->setNext(Attrs);
1039 Attrs = New;
1040 }
1041#undef UNSIGNED_ATTR
1042#undef STRING_ATTR
1043#undef SIMPLE_ATTR
1044
1045 // The list of attributes was built backwards. Reverse the list
1046 // before returning it.
1047 Attr *PrevAttr = 0, *NextAttr = 0;
1048 while (Attrs) {
1049 NextAttr = Attrs->getNext();
1050 Attrs->setNext(PrevAttr);
1051 PrevAttr = Attrs;
1052 Attrs = NextAttr;
1053 }
1054
1055 return PrevAttr;
1056}
1057
1058//===----------------------------------------------------------------------===//
1059// PCHReader Implementation
1060//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +00001061
1062/// \brief Note that we have loaded the declaration with the given
1063/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +00001064///
Chris Lattner698f9252009-04-27 05:27:42 +00001065/// This routine notes that this declaration has already been loaded,
1066/// so that future GetDecl calls will return this declaration rather
1067/// than trying to load a new declaration.
1068inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
1069 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1070 DeclsLoaded[Index] = D;
1071}
1072
1073
1074/// \brief Determine whether the consumer will be interested in seeing
1075/// this declaration (via HandleTopLevelDecl).
1076///
1077/// This routine should return true for anything that might affect
1078/// code generation, e.g., inline function definitions, Objective-C
1079/// declarations with metadata, etc.
1080static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar04a0b502009-09-17 03:06:44 +00001081 if (isa<FileScopeAsmDecl>(D))
1082 return true;
Chris Lattner698f9252009-04-27 05:27:42 +00001083 if (VarDecl *Var = dyn_cast<VarDecl>(D))
1084 return Var->isFileVarDecl() && Var->getInit();
1085 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1086 return Func->isThisDeclarationADefinition();
1087 return isa<ObjCProtocolDecl>(D);
1088}
1089
1090/// \brief Read the declaration at the given offset from the PCH file.
1091Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
1092 // Keep track of where we are in the stream, then jump back there
1093 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +00001094 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +00001095
Douglas Gregord89275b2009-07-06 18:54:52 +00001096 // Note that we are loading a declaration record.
1097 LoadingTypeOrDecl Loading(*this);
Mike Stump1eb44332009-09-09 15:08:12 +00001098
Chris Lattnerda930612009-04-27 05:58:23 +00001099 DeclsCursor.JumpToBit(Offset);
Chris Lattner698f9252009-04-27 05:27:42 +00001100 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +00001101 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +00001102 unsigned Idx = 0;
1103 PCHDeclReader Reader(*this, Record, Idx);
1104
Chris Lattnerda930612009-04-27 05:58:23 +00001105 Decl *D = 0;
1106 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner698f9252009-04-27 05:27:42 +00001107 case pch::DECL_ATTR:
1108 case pch::DECL_CONTEXT_LEXICAL:
1109 case pch::DECL_CONTEXT_VISIBLE:
1110 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1111 break;
Chris Lattner698f9252009-04-27 05:27:42 +00001112 case pch::DECL_TRANSLATION_UNIT:
1113 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001114 D = Context->getTranslationUnitDecl();
Chris Lattner698f9252009-04-27 05:27:42 +00001115 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001116 case pch::DECL_TYPEDEF:
John McCallba6a9bd2009-10-24 08:00:42 +00001117 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001118 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001119 case pch::DECL_ENUM:
Douglas Gregor741dd9a2009-07-21 14:46:17 +00001120 D = EnumDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001121 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001122 case pch::DECL_RECORD:
Abramo Bagnara465d41b2010-05-11 21:36:43 +00001123 D = RecordDecl::Create(*Context, TTK_Struct, 0, SourceLocation(),
Douglas Gregor741dd9a2009-07-21 14:46:17 +00001124 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001125 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001126 case pch::DECL_ENUM_CONSTANT:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001127 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +00001128 0, llvm::APSInt());
1129 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001130 case pch::DECL_FUNCTION:
Mike Stump1eb44332009-09-09 15:08:12 +00001131 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +00001132 QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001133 break;
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001134 case pch::DECL_LINKAGE_SPEC:
1135 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
1136 (LinkageSpecDecl::LanguageIDs)0,
1137 false);
1138 break;
1139 case pch::DECL_NAMESPACE:
1140 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
1141 break;
1142 case pch::DECL_NAMESPACE_ALIAS:
1143 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
1144 SourceLocation(), 0, SourceRange(), 0,
1145 SourceLocation(), 0);
1146 break;
1147 case pch::DECL_USING:
1148 D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(),
1149 SourceLocation(), 0, DeclarationName(), false);
1150 break;
1151 case pch::DECL_USING_SHADOW:
1152 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1153 break;
1154 case pch::DECL_USING_DIRECTIVE:
1155 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
1156 SourceLocation(), SourceRange(), 0,
1157 SourceLocation(), 0, 0);
1158 break;
1159 case pch::DECL_UNRESOLVED_USING_VALUE:
1160 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
1161 SourceRange(), 0, SourceLocation(),
1162 DeclarationName());
1163 break;
1164 case pch::DECL_UNRESOLVED_USING_TYPENAME:
1165 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
1166 SourceLocation(), SourceRange(),
1167 0, SourceLocation(),
1168 DeclarationName());
1169 break;
1170 case pch::DECL_CXX_RECORD:
Abramo Bagnara465d41b2010-05-11 21:36:43 +00001171 D = CXXRecordDecl::Create(*Context, TTK_Struct, 0,
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001172 SourceLocation(), 0, SourceLocation(), 0);
1173 break;
1174 case pch::DECL_CXX_METHOD:
1175 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
1176 QualType(), 0);
1177 break;
1178 case pch::DECL_CXX_CONSTRUCTOR:
1179 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1180 break;
1181 case pch::DECL_CXX_DESTRUCTOR:
1182 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1183 break;
1184 case pch::DECL_CXX_CONVERSION:
1185 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1186 break;
Abramo Bagnara6206d532010-06-05 05:09:32 +00001187 case pch::DECL_ACCESS_SPEC:
1188 D = AccessSpecDecl::Create(*Context, AS_none, 0, SourceLocation(),
1189 SourceLocation());
1190 break;
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001191 case pch::DECL_FRIEND:
1192 assert(false && "cannot read FriendDecl");
1193 break;
1194 case pch::DECL_FRIEND_TEMPLATE:
1195 assert(false && "cannot read FriendTemplateDecl");
1196 break;
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001197 case pch::DECL_CLASS_TEMPLATE:
Argyrios Kyrtzidis5bf1bdc2010-06-21 10:57:41 +00001198 D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(),
1199 DeclarationName(), 0, 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001200 break;
1201 case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION:
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001202 D = ClassTemplateSpecializationDecl::CreateEmpty(*Context);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001203 break;
1204 case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +00001205 D = ClassTemplatePartialSpecializationDecl::CreateEmpty(*Context);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001206 break;
1207 case pch::DECL_FUNCTION_TEMPLATE:
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001208 D = FunctionTemplateDecl::Create(*Context, 0, SourceLocation(),
1209 DeclarationName(), 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001210 break;
1211 case pch::DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001212 D = TemplateTypeParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0,0,0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001213 break;
1214 case pch::DECL_NON_TYPE_TEMPLATE_PARM:
1215 assert(false && "cannot read NonTypeTemplateParmDecl");
1216 break;
1217 case pch::DECL_TEMPLATE_TEMPLATE_PARM:
1218 assert(false && "cannot read TemplateTemplateParmDecl");
1219 break;
1220 case pch::DECL_STATIC_ASSERT:
1221 assert(false && "cannot read StaticAssertDecl");
1222 break;
1223
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001224 case pch::DECL_OBJC_METHOD:
Mike Stump1eb44332009-09-09 15:08:12 +00001225 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor4bc1cb62010-03-08 14:59:44 +00001226 Selector(), QualType(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001227 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001228 case pch::DECL_OBJC_INTERFACE:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001229 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001230 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001231 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +00001232 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +00001233 ObjCIvarDecl::None);
1234 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001235 case pch::DECL_OBJC_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001236 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001237 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001238 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +00001239 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +00001240 QualType(), 0);
1241 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001242 case pch::DECL_OBJC_CLASS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001243 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001244 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001245 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001246 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001247 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001248 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor3db211b2010-01-16 16:38:58 +00001249 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1250 SourceLocation(), SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001251 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001252 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001253 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001254 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001255 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001256 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001257 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001258 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001259 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001260 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001261 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahaniand0502402010-01-21 17:36:00 +00001262 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall83a230c2010-06-04 20:50:08 +00001263 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001264 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001265 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001266 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +00001267 SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +00001268 ObjCPropertyImplDecl::Dynamic, 0);
1269 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001270 case pch::DECL_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +00001271 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +00001272 false);
Chris Lattner698f9252009-04-27 05:27:42 +00001273 break;
Chris Lattner698f9252009-04-27 05:27:42 +00001274 case pch::DECL_VAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +00001275 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregor16573fa2010-04-19 22:54:31 +00001276 VarDecl::None, VarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +00001277 break;
1278
1279 case pch::DECL_IMPLICIT_PARAM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001280 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +00001281 break;
1282
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001283 case pch::DECL_PARM_VAR:
Mike Stump1eb44332009-09-09 15:08:12 +00001284 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregor16573fa2010-04-19 22:54:31 +00001285 VarDecl::None, VarDecl::None, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001286 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001287 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001288 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001289 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001290 case pch::DECL_BLOCK:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001291 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001292 break;
1293 }
Chris Lattner698f9252009-04-27 05:27:42 +00001294
1295 assert(D && "Unknown declaration reading PCH file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001296 LoadedDecl(Index, D);
1297 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +00001298
1299 // If this declaration is also a declaration context, get the
1300 // offsets for its tables of lexical and visible declarations.
1301 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1302 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1303 if (Offsets.first || Offsets.second) {
1304 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1305 DC->setHasExternalVisibleStorage(Offsets.second != 0);
1306 DeclContextOffsets[DC] = Offsets;
1307 }
1308 }
1309 assert(Idx == Record.size());
1310
1311 // If we have deserialized a declaration that has a definition the
1312 // AST consumer might need to know about, notify the consumer
1313 // about that definition now or queue it for later.
1314 if (isConsumerInterestedIn(D)) {
1315 if (Consumer) {
1316 DeclGroupRef DG(D);
1317 Consumer->HandleTopLevelDecl(DG);
1318 } else {
1319 InterestingDecls.push_back(D);
1320 }
1321 }
1322
1323 return D;
1324}