blob: 28e655ce70df6975596e6658a67b8fd51da24543 [file] [log] [blame]
Chris Lattner487412d2009-04-27 05:27:42 +00001//===--- PCHReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the PCHReader::ReadDeclRecord method, which is the
11// entrypoint for loading a decl.
12//
13//===----------------------------------------------------------------------===//
14
15#include "clang/Frontend/PCHReader.h"
16#include "clang/AST/ASTConsumer.h"
17#include "clang/AST/ASTContext.h"
18#include "clang/AST/DeclVisitor.h"
19#include "clang/AST/DeclGroup.h"
Chris Lattnerca025db2010-05-07 21:43:38 +000020#include "clang/AST/DeclCXX.h"
21#include "clang/AST/DeclTemplate.h"
Chris Lattner487412d2009-04-27 05:27:42 +000022#include "clang/AST/Expr.h"
23using namespace clang;
24
Chris Lattner487412d2009-04-27 05:27:42 +000025
26//===----------------------------------------------------------------------===//
27// Declaration deserialization
28//===----------------------------------------------------------------------===//
29
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000030namespace clang {
Chris Lattner487412d2009-04-27 05:27:42 +000031 class PCHDeclReader : public DeclVisitor<PCHDeclReader, void> {
32 PCHReader &Reader;
33 const PCHReader::RecordData &Record;
34 unsigned &Idx;
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +000035 pch::TypeID TypeIDForTypeDecl;
Chris Lattner487412d2009-04-27 05:27:42 +000036
37 public:
38 PCHDeclReader(PCHReader &Reader, const PCHReader::RecordData &Record,
39 unsigned &Idx)
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +000040 : Reader(Reader), Record(Record), Idx(Idx), TypeIDForTypeDecl(0) { }
Chris Lattner487412d2009-04-27 05:27:42 +000041
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +000042 void Visit(Decl *D);
43
Chris Lattner487412d2009-04-27 05:27:42 +000044 void VisitDecl(Decl *D);
45 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
46 void VisitNamedDecl(NamedDecl *ND);
Douglas Gregore31bbd92010-02-21 18:22:14 +000047 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000048 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
49 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000050 void VisitTypeDecl(TypeDecl *TD);
51 void VisitTypedefDecl(TypedefDecl *TD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000052 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000053 void VisitTagDecl(TagDecl *TD);
54 void VisitEnumDecl(EnumDecl *ED);
55 void VisitRecordDecl(RecordDecl *RD);
Chris Lattnerca025db2010-05-07 21:43:38 +000056 void VisitCXXRecordDecl(CXXRecordDecl *D);
57 void VisitClassTemplateSpecializationDecl(
58 ClassTemplateSpecializationDecl *D);
59 void VisitClassTemplatePartialSpecializationDecl(
60 ClassTemplatePartialSpecializationDecl *D);
61 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000062 void VisitValueDecl(ValueDecl *VD);
63 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000064 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +000065 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +000066 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattnerca025db2010-05-07 21:43:38 +000067 void VisitCXXMethodDecl(CXXMethodDecl *D);
68 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
69 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
70 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000071 void VisitFieldDecl(FieldDecl *FD);
72 void VisitVarDecl(VarDecl *VD);
73 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
74 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattnerca025db2010-05-07 21:43:38 +000075 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
76 void VisitTemplateDecl(TemplateDecl *D);
77 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +000078 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000079 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +000080 void VisitUsingDecl(UsingDecl *D);
81 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000082 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000083 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Abramo Bagnarad7340582010-06-05 05:09:32 +000084 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000085 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000086 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
87 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000088 void VisitBlockDecl(BlockDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +000089
Chris Lattner487412d2009-04-27 05:27:42 +000090 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Chris Lattnerca025db2010-05-07 21:43:38 +000091
Alexis Hunted053252010-05-30 07:21:58 +000092 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-04-27 05:27:42 +000093 void VisitObjCMethodDecl(ObjCMethodDecl *D);
94 void VisitObjCContainerDecl(ObjCContainerDecl *D);
95 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
96 void VisitObjCIvarDecl(ObjCIvarDecl *D);
97 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
98 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
99 void VisitObjCClassDecl(ObjCClassDecl *D);
100 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
101 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
102 void VisitObjCImplDecl(ObjCImplDecl *D);
103 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
104 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
105 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
106 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
107 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
108 };
109}
110
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000111void PCHDeclReader::Visit(Decl *D) {
112 DeclVisitor<PCHDeclReader, void>::Visit(D);
113
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000114 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
115 // if we have a fully initialized TypeDecl, we can safely read its type now.
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000116 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtr());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000117 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
118 // FunctionDecl's body was written last after all other Stmts/Exprs.
119 if (Record[Idx++])
120 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
121 }
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000122}
123
Chris Lattner487412d2009-04-27 05:27:42 +0000124void PCHDeclReader::VisitDecl(Decl *D) {
125 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
126 D->setLexicalDeclContext(
127 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
128 D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
129 D->setInvalidDecl(Record[Idx++]);
130 if (Record[Idx++])
Argyrios Kyrtzidis91167172010-06-11 23:09:25 +0000131 D->initAttrs(Reader.ReadAttributes());
Chris Lattner487412d2009-04-27 05:27:42 +0000132 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +0000133 D->setUsed(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000134 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor16bef852009-10-16 20:01:17 +0000135 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner487412d2009-04-27 05:27:42 +0000136}
137
138void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
139 VisitDecl(TU);
Chris Lattnerca025db2010-05-07 21:43:38 +0000140 TU->setAnonymousNamespace(
141 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000142}
143
144void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) {
145 VisitDecl(ND);
Mike Stump11289f42009-09-09 15:08:12 +0000146 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000147}
148
149void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
150 VisitNamedDecl(TD);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000151 // Delay type reading until after we have fully initialized the decl.
152 TypeIDForTypeDecl = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000153}
154
155void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000156 VisitTypeDecl(TD);
John McCallbcd03502009-12-07 02:54:59 +0000157 TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000158}
159
160void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
161 VisitTypeDecl(TD);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000162 TD->IdentifierNamespace = Record[Idx++];
Douglas Gregorb6b8f9e2009-07-29 23:36:44 +0000163 TD->setPreviousDeclaration(
164 cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000165 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
166 TD->setDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000167 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis664b6902009-07-14 03:18:02 +0000168 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000169 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall3e11ebe2010-03-15 10:12:16 +0000170 // FIXME: maybe read optional qualifier and its range.
171 TD->setTypedefForAnonDecl(
172 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000173}
174
175void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
176 VisitTagDecl(ED);
177 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall56774992009-12-09 09:09:27 +0000178 ED->setPromotionType(Reader.GetType(Record[Idx++]));
John McCall9aa35be2010-05-06 08:49:23 +0000179 ED->setNumPositiveBits(Record[Idx++]);
180 ED->setNumNegativeBits(Record[Idx++]);
Argyrios Kyrtzidis282b36b2010-07-06 15:36:48 +0000181 ED->setInstantiationOfMemberEnum(
182 cast_or_null<EnumDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000183}
184
185void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
186 VisitTagDecl(RD);
187 RD->setHasFlexibleArrayMember(Record[Idx++]);
188 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000189 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000190}
191
192void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
193 VisitNamedDecl(VD);
194 VD->setType(Reader.GetType(Record[Idx++]));
195}
196
197void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
198 VisitValueDecl(ECD);
199 if (Record[Idx++])
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000200 ECD->setInitExpr(Reader.ReadExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000201 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
202}
203
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000204void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
205 VisitValueDecl(DD);
John McCallbcd03502009-12-07 02:54:59 +0000206 TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Record, Idx);
207 if (TInfo)
208 DD->setTypeSourceInfo(TInfo);
John McCall3e11ebe2010-03-15 10:12:16 +0000209 // FIXME: read optional qualifier and its range.
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000210}
211
Chris Lattner487412d2009-04-27 05:27:42 +0000212void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000213 VisitDeclaratorDecl(FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000214
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000215 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000216 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000217 default: assert(false && "Unhandled TemplatedKind!");
218 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000219 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 Kyrtzidis69da4a82010-06-22 09:55:07 +0000239 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000240 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000241
242 // Template args as written.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000243 llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000244 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000245 if (Record[Idx++]) { // TemplateArgumentsAsWritten != 0
246 unsigned NumTemplateArgLocs = Record[Idx++];
247 TemplArgLocs.reserve(NumTemplateArgLocs);
248 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
249 TemplArgLocs.push_back(Reader.ReadTemplateArgumentLoc(Record, Idx));
250
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000251 LAngleLoc = Reader.ReadSourceLocation(Record, Idx);
252 RAngleLoc = Reader.ReadSourceLocation(Record, Idx);
253 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000254
255 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000256
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000257 FD->setFunctionTemplateSpecialization(Template, TemplArgs.size(),
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000258 TemplArgs.data(), TSK,
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000259 TemplArgLocs.size(),
260 TemplArgLocs.data(),
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000261 LAngleLoc, RAngleLoc, POI);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000262 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000263 }
264 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
265 // Templates.
266 UnresolvedSet<8> TemplDecls;
267 unsigned NumTemplates = Record[Idx++];
268 while (NumTemplates--)
269 TemplDecls.addDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
270
271 // Templates args.
272 TemplateArgumentListInfo TemplArgs;
273 unsigned NumArgs = Record[Idx++];
274 while (NumArgs--)
275 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000276 TemplArgs.setLAngleLoc(Reader.ReadSourceLocation(Record, Idx));
277 TemplArgs.setRAngleLoc(Reader.ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000278
279 FD->setDependentTemplateSpecialization(*Reader.getContext(),
280 TemplDecls, TemplArgs);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000281 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000282 }
283 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000284
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000285 // FunctionDecl's body is handled last at PCHReaderDecl::Visit,
286 // after everything else is read.
287
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000288 // Avoid side effects and invariant checking of FunctionDecl's
289 // setPreviousDeclaration.
290 FD->redeclarable_base::setPreviousDeclaration(
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000291 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
292 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
293 FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]);
294 FD->setInlineSpecified(Record[Idx++]);
295 FD->setVirtualAsWritten(Record[Idx++]);
296 FD->setPure(Record[Idx++]);
297 FD->setHasInheritedPrototype(Record[Idx++]);
298 FD->setHasWrittenPrototype(Record[Idx++]);
299 FD->setDeleted(Record[Idx++]);
300 FD->setTrivial(Record[Idx++]);
301 FD->setCopyAssignment(Record[Idx++]);
302 FD->setHasImplicitReturnZero(Record[Idx++]);
303 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
304
Chris Lattnerca025db2010-05-07 21:43:38 +0000305 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000306 unsigned NumParams = Record[Idx++];
307 llvm::SmallVector<ParmVarDecl *, 16> Params;
308 Params.reserve(NumParams);
309 for (unsigned I = 0; I != NumParams; ++I)
310 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000311 FD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000312}
313
314void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
315 VisitNamedDecl(MD);
316 if (Record[Idx++]) {
317 // In practice, this won't be executed (since method definitions
318 // don't occur in header files).
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000319 MD->setBody(Reader.ReadStmt());
Chris Lattner487412d2009-04-27 05:27:42 +0000320 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
321 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
322 }
323 MD->setInstanceMethod(Record[Idx++]);
324 MD->setVariadic(Record[Idx++]);
325 MD->setSynthesized(Record[Idx++]);
326 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
327 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahaniand9235db2010-04-08 21:29:11 +0000328 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000329 MD->setResultType(Reader.GetType(Record[Idx++]));
Douglas Gregor12852d92010-03-08 14:59:44 +0000330 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000331 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
332 unsigned NumParams = Record[Idx++];
333 llvm::SmallVector<ParmVarDecl *, 16> Params;
334 Params.reserve(NumParams);
335 for (unsigned I = 0; I != NumParams; ++I)
336 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniancdabb312010-04-09 15:40:42 +0000337 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
338 NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000339}
340
341void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
342 VisitNamedDecl(CD);
Ted Kremenekc7c64312010-01-07 01:20:12 +0000343 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
344 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
345 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner487412d2009-04-27 05:27:42 +0000346}
347
348void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
349 VisitObjCContainerDecl(ID);
350 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
351 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
352 (Reader.GetDecl(Record[Idx++])));
353 unsigned NumProtocols = Record[Idx++];
354 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
355 Protocols.reserve(NumProtocols);
356 for (unsigned I = 0; I != NumProtocols; ++I)
357 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000358 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
359 ProtoLocs.reserve(NumProtocols);
360 for (unsigned I = 0; I != NumProtocols; ++I)
361 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
362 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
363 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000364 unsigned NumIvars = Record[Idx++];
365 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
366 IVars.reserve(NumIvars);
367 for (unsigned I = 0; I != NumIvars; ++I)
368 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000369 ID->setCategoryList(
370 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
371 ID->setForwardDecl(Record[Idx++]);
372 ID->setImplicitInterfaceDecl(Record[Idx++]);
373 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
374 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisea72f422009-07-18 00:33:23 +0000375 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000376}
377
378void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
379 VisitFieldDecl(IVD);
380 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
381}
382
383void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
384 VisitObjCContainerDecl(PD);
385 PD->setForwardDecl(Record[Idx++]);
386 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
387 unsigned NumProtoRefs = Record[Idx++];
388 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
389 ProtoRefs.reserve(NumProtoRefs);
390 for (unsigned I = 0; I != NumProtoRefs; ++I)
391 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000392 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
393 ProtoLocs.reserve(NumProtoRefs);
394 for (unsigned I = 0; I != NumProtoRefs; ++I)
395 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
396 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
397 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000398}
399
400void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
401 VisitFieldDecl(FD);
402}
403
404void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
405 VisitDecl(CD);
406 unsigned NumClassRefs = Record[Idx++];
407 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
408 ClassRefs.reserve(NumClassRefs);
409 for (unsigned I = 0; I != NumClassRefs; ++I)
410 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000411 llvm::SmallVector<SourceLocation, 16> SLocs;
412 SLocs.reserve(NumClassRefs);
413 for (unsigned I = 0; I != NumClassRefs; ++I)
414 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
415 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
416 NumClassRefs);
Chris Lattner487412d2009-04-27 05:27:42 +0000417}
418
419void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
420 VisitDecl(FPD);
421 unsigned NumProtoRefs = Record[Idx++];
422 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
423 ProtoRefs.reserve(NumProtoRefs);
424 for (unsigned I = 0; I != NumProtoRefs; ++I)
425 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000426 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
427 ProtoLocs.reserve(NumProtoRefs);
428 for (unsigned I = 0; I != NumProtoRefs; ++I)
429 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
430 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
431 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000432}
433
434void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
435 VisitObjCContainerDecl(CD);
436 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
437 unsigned NumProtoRefs = Record[Idx++];
438 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
439 ProtoRefs.reserve(NumProtoRefs);
440 for (unsigned I = 0; I != NumProtoRefs; ++I)
441 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000442 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
443 ProtoLocs.reserve(NumProtoRefs);
444 for (unsigned I = 0; I != NumProtoRefs; ++I)
445 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
446 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
447 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000448 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor071676f2010-01-16 16:38:58 +0000449 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
450 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000451}
452
453void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
454 VisitNamedDecl(CAD);
455 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
456}
457
458void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
459 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000460 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall339bb662010-06-04 20:50:08 +0000461 D->setType(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000462 // FIXME: stable encoding
463 D->setPropertyAttributes(
464 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000465 D->setPropertyAttributesAsWritten(
466 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000467 // FIXME: stable encoding
468 D->setPropertyImplementation(
469 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
470 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
471 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
472 D->setGetterMethodDecl(
473 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
474 D->setSetterMethodDecl(
475 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
476 D->setPropertyIvarDecl(
477 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
478}
479
480void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000481 VisitObjCContainerDecl(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000482 D->setClassInterface(
483 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000484}
485
486void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
487 VisitObjCImplDecl(D);
488 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
489}
490
491void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
492 VisitObjCImplDecl(D);
493 D->setSuperClass(
494 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanianc83726e2010-04-28 16:11:27 +0000495 // FIXME. Add reading of IvarInitializers and NumIvarInitializers.
Chris Lattner487412d2009-04-27 05:27:42 +0000496}
497
498
499void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
500 VisitDecl(D);
501 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
502 D->setPropertyDecl(
503 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
504 D->setPropertyIvarDecl(
505 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanian25491a22010-05-05 21:52:17 +0000506 // FIXME. read GetterCXXConstructor and SetterCXXAssignment
Chris Lattner487412d2009-04-27 05:27:42 +0000507}
508
509void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000510 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000511 FD->setMutable(Record[Idx++]);
512 if (Record[Idx++])
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000513 FD->setBitWidth(Reader.ReadExpr());
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000514 if (!FD->getDeclName()) {
515 FieldDecl *Tmpl = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
516 if (Tmpl)
517 Reader.getContext()->setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
518 }
Chris Lattner487412d2009-04-27 05:27:42 +0000519}
520
521void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000522 VisitDeclaratorDecl(VD);
Chris Lattner487412d2009-04-27 05:27:42 +0000523 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
Douglas Gregorc4df4072010-04-19 22:54:31 +0000524 VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000525 VD->setThreadSpecified(Record[Idx++]);
526 VD->setCXXDirectInitializer(Record[Idx++]);
527 VD->setDeclaredInCondition(Record[Idx++]);
Douglas Gregor3f324d562010-05-03 18:51:14 +0000528 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor6fd1b182010-05-15 06:01:05 +0000529 VD->setNRVOVariable(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000530 VD->setPreviousDeclaration(
531 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000532 if (Record[Idx++])
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000533 VD->setInit(Reader.ReadExpr());
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000534
535 if (Record[Idx++]) { // HasMemberSpecializationInfo.
536 VarDecl *Tmpl = cast<VarDecl>(Reader.GetDecl(Record[Idx++]));
537 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
538 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
539 Reader.getContext()->setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
540 }
Chris Lattner487412d2009-04-27 05:27:42 +0000541}
542
543void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
544 VisitVarDecl(PD);
545}
546
547void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
548 VisitVarDecl(PD);
549 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallf3cd6652010-03-12 18:31:32 +0000550 PD->setHasInheritedDefaultArg(Record[Idx++]);
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000551 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
552 PD->setUninstantiatedDefaultArg(Reader.ReadExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000553}
554
Chris Lattner487412d2009-04-27 05:27:42 +0000555void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
556 VisitDecl(AD);
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000557 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr()));
Chris Lattner487412d2009-04-27 05:27:42 +0000558}
559
560void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
561 VisitDecl(BD);
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000562 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt()));
John McCalla3ccba02010-06-04 11:21:44 +0000563 BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000564 unsigned NumParams = Record[Idx++];
565 llvm::SmallVector<ParmVarDecl *, 16> Params;
566 Params.reserve(NumParams);
567 for (unsigned I = 0; I != NumParams; ++I)
568 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000569 BD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000570}
571
Chris Lattnerca025db2010-05-07 21:43:38 +0000572void PCHDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
573 VisitDecl(D);
574 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
575 D->setHasBraces(Record[Idx++]);
576}
577
578void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
579 VisitNamedDecl(D);
580 D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx));
581 D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx));
582 D->setNextNamespace(
583 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
584
Chris Lattnerca025db2010-05-07 21:43:38 +0000585 bool IsOriginal = Record[Idx++];
Argyrios Kyrtzidisdae2a162010-07-03 07:57:53 +0000586 D->OrigOrAnonNamespace.setInt(IsOriginal);
587 D->OrigOrAnonNamespace.setPointer(
Chris Lattnerca025db2010-05-07 21:43:38 +0000588 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
589}
590
591void PCHDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
592 VisitNamedDecl(D);
593
594 D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx));
595 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
596 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
597 D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx));
598 D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
599}
600
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000601void PCHDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000602 VisitNamedDecl(D);
603 D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
604 D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
605 D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
606
607 // FIXME: It would probably be more efficient to read these into a vector
608 // and then re-cosntruct the shadow decl set over that vector since it
609 // would avoid existence checks.
610 unsigned NumShadows = Record[Idx++];
611 for(unsigned I = 0; I != NumShadows; ++I) {
Argyrios Kyrtzidis00dda6a2010-07-08 13:09:41 +0000612 // Avoid invariant checking of UsingDecl::addShadowDecl, the decl may still
613 // be initializing.
614 D->Shadows.insert(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattnerca025db2010-05-07 21:43:38 +0000615 }
616 D->setTypeName(Record[Idx++]);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000617 NamedDecl *Pattern = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
618 if (Pattern)
619 Reader.getContext()->setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000620}
621
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000622void PCHDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000623 VisitNamedDecl(D);
624 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
625 D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000626 UsingShadowDecl *Pattern
627 = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]));
628 if (Pattern)
629 Reader.getContext()->setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000630}
631
632void PCHDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
633 VisitNamedDecl(D);
634 D->setNamespaceKeyLocation(Reader.ReadSourceLocation(Record, Idx));
635 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
636 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
637 D->setIdentLocation(Reader.ReadSourceLocation(Record, Idx));
638 D->setNominatedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
639 D->setCommonAncestor(cast_or_null<DeclContext>(
640 Reader.GetDecl(Record[Idx++])));
641}
642
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000643void PCHDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000644 VisitValueDecl(D);
645 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
646 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
647 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
648}
649
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000650void PCHDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000651 UnresolvedUsingTypenameDecl *D) {
652 VisitTypeDecl(D);
653 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
654 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
655 D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx));
656 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
657}
658
659void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000660 ASTContext &C = *Reader.getContext();
661
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000662 // We need to allocate the DefinitionData struct ahead of VisitRecordDecl
663 // so that the other CXXRecordDecls can get a pointer even when the owner
664 // is still initializing.
665 bool OwnsDefinitionData = false;
666 enum DataOwnership { Data_NoDefData, Data_Owner, Data_NotOwner };
667 switch ((DataOwnership)Record[Idx++]) {
668 default:
669 assert(0 && "Out of sync with PCHDeclWriter or messed up reading");
670 case Data_NoDefData:
671 break;
672 case Data_Owner:
673 OwnsDefinitionData = true;
674 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
675 break;
676 case Data_NotOwner:
677 D->DefinitionData
678 = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]))->DefinitionData;
679 break;
680 }
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000681
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000682 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000683
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000684 if (OwnsDefinitionData) {
685 assert(D->DefinitionData);
686 struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData;
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000687
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000688 Data.UserDeclaredConstructor = Record[Idx++];
689 Data.UserDeclaredCopyConstructor = Record[Idx++];
690 Data.UserDeclaredCopyAssignment = Record[Idx++];
691 Data.UserDeclaredDestructor = Record[Idx++];
692 Data.Aggregate = Record[Idx++];
693 Data.PlainOldData = Record[Idx++];
694 Data.Empty = Record[Idx++];
695 Data.Polymorphic = Record[Idx++];
696 Data.Abstract = Record[Idx++];
697 Data.HasTrivialConstructor = Record[Idx++];
698 Data.HasTrivialCopyConstructor = Record[Idx++];
699 Data.HasTrivialCopyAssignment = Record[Idx++];
700 Data.HasTrivialDestructor = Record[Idx++];
701 Data.ComputedVisibleConversions = Record[Idx++];
702 Data.DeclaredDefaultConstructor = Record[Idx++];
703 Data.DeclaredCopyConstructor = Record[Idx++];
704 Data.DeclaredCopyAssignment = Record[Idx++];
705 Data.DeclaredDestructor = Record[Idx++];
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000706
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000707 // setBases() is unsuitable since it may try to iterate the bases of an
708 // unitialized base.
709 Data.NumBases = Record[Idx++];
710 Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases];
711 for (unsigned i = 0; i != Data.NumBases; ++i)
712 Data.Bases[i] = Reader.ReadCXXBaseSpecifier(Record, Idx);
713
714 // FIXME: Make VBases lazily computed when needed to avoid storing them.
715 Data.NumVBases = Record[Idx++];
716 Data.VBases = new(C) CXXBaseSpecifier [Data.NumVBases];
717 for (unsigned i = 0; i != Data.NumVBases; ++i)
718 Data.VBases[i] = Reader.ReadCXXBaseSpecifier(Record, Idx);
719
720 Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx);
721 Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx);
722 assert(Data.Definition && "Data.Definition should be already set!");
723 Data.FirstFriend
724 = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000725 }
726
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000727 enum CXXRecKind {
728 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
729 };
730 switch ((CXXRecKind)Record[Idx++]) {
731 default:
732 assert(false && "Out of sync with PCHDeclWriter::VisitCXXRecordDecl?");
733 case CXXRecNotTemplate:
734 break;
735 case CXXRecTemplate:
736 D->setDescribedClassTemplate(
737 cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++])));
738 break;
739 case CXXRecMemberSpecialization: {
740 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
741 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
742 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
743 D->setInstantiationOfMemberClass(RD, TSK);
744 D->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
745 break;
746 }
747 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000748}
749
750void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000751 VisitFunctionDecl(D);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000752 unsigned NumOverridenMethods = Record[Idx++];
753 while (NumOverridenMethods--) {
754 CXXMethodDecl *MD = cast<CXXMethodDecl>(Reader.GetDecl(Record[Idx++]));
755 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
756 // MD may be initializing.
757 Reader.getContext()->addOverriddenMethod(D, MD);
758 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000759}
760
761void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000762 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000763
764 D->IsExplicitSpecified = Record[Idx++];
765 D->ImplicitlyDefined = Record[Idx++];
766
767 unsigned NumInitializers = Record[Idx++];
768 D->NumBaseOrMemberInitializers = NumInitializers;
769 if (NumInitializers) {
770 ASTContext &C = *Reader.getContext();
771
772 D->BaseOrMemberInitializers
773 = new (C) CXXBaseOrMemberInitializer*[NumInitializers];
774 for (unsigned i=0; i != NumInitializers; ++i) {
Duncan Sands16143962010-07-06 18:19:40 +0000775 TypeSourceInfo *BaseClassInfo = 0;
776 bool IsBaseVirtual = false;
777 FieldDecl *Member = 0;
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000778
779 bool IsBaseInitializer = Record[Idx++];
780 if (IsBaseInitializer) {
781 BaseClassInfo = Reader.GetTypeSourceInfo(Record, Idx);
782 IsBaseVirtual = Record[Idx++];
783 } else {
784 Member = cast<FieldDecl>(Reader.GetDecl(Record[Idx++]));
785 }
786 SourceLocation MemberLoc = Reader.ReadSourceLocation(Record, Idx);
787 Expr *Init = Reader.ReadExpr();
788 FieldDecl *AnonUnionMember
789 = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
790 SourceLocation LParenLoc = Reader.ReadSourceLocation(Record, Idx);
791 SourceLocation RParenLoc = Reader.ReadSourceLocation(Record, Idx);
792 bool IsWritten = Record[Idx++];
793 unsigned SourceOrderOrNumArrayIndices;
794 llvm::SmallVector<VarDecl *, 8> Indices;
795 if (IsWritten) {
796 SourceOrderOrNumArrayIndices = Record[Idx++];
797 } else {
798 SourceOrderOrNumArrayIndices = Record[Idx++];
799 Indices.reserve(SourceOrderOrNumArrayIndices);
800 for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i)
801 Indices.push_back(cast<VarDecl>(Reader.GetDecl(Record[Idx++])));
802 }
803
804 CXXBaseOrMemberInitializer *BOMInit;
805 if (IsBaseInitializer) {
806 BOMInit = new (C) CXXBaseOrMemberInitializer(C, BaseClassInfo,
807 IsBaseVirtual, LParenLoc,
808 Init, RParenLoc);
809 } else if (IsWritten) {
810 BOMInit = new (C) CXXBaseOrMemberInitializer(C, Member, MemberLoc,
811 LParenLoc, Init, RParenLoc);
812 } else {
813 BOMInit = CXXBaseOrMemberInitializer::Create(C, Member, MemberLoc,
814 LParenLoc, Init, RParenLoc,
815 Indices.data(),
816 Indices.size());
817 }
818
819 BOMInit->setAnonUnionMember(AnonUnionMember);
820 D->BaseOrMemberInitializers[i] = BOMInit;
821 }
822 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000823}
824
825void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000826 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000827
828 D->ImplicitlyDefined = Record[Idx++];
829 D->OperatorDelete = cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000830}
831
832void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000833 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000834 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000835}
836
Abramo Bagnarad7340582010-06-05 05:09:32 +0000837void PCHDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
838 VisitDecl(D);
839 D->setColonLoc(Reader.ReadSourceLocation(Record, Idx));
840}
841
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000842void PCHDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000843 VisitDecl(D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000844 if (Record[Idx++])
845 D->Friend = Reader.GetTypeSourceInfo(Record, Idx);
846 else
847 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
848 D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
849 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
850}
851
Chris Lattnerca025db2010-05-07 21:43:38 +0000852void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
853 assert(false && "cannot read FriendTemplateDecl");
854}
855
856void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000857 VisitNamedDecl(D);
858
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +0000859 NamedDecl *TemplatedDecl
860 = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000861 TemplateParameterList* TemplateParams
862 = Reader.ReadTemplateParameterList(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000863 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +0000864}
865
866void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000867 VisitTemplateDecl(D);
868
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000869 D->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000870 ClassTemplateDecl *PrevDecl =
871 cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +0000872 D->setPreviousDeclaration(PrevDecl);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000873 if (PrevDecl == 0) {
874 // This ClassTemplateDecl owns a CommonPtr; read it.
875
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000876 // FoldingSets are filled in VisitClassTemplateSpecializationDecl.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000877 unsigned size = Record[Idx++];
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000878 while (size--)
879 cast<ClassTemplateSpecializationDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000880
881 size = Record[Idx++];
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000882 while (size--)
883 cast<ClassTemplatePartialSpecializationDecl>(
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000884 Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000885
886 // InjectedClassNameType is computed.
887
888 if (ClassTemplateDecl *CTD
889 = cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
890 D->setInstantiatedFromMemberTemplate(CTD);
891 if (Record[Idx++])
892 D->setMemberSpecialization();
893 }
894 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000895}
896
897void PCHDeclReader::VisitClassTemplateSpecializationDecl(
898 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000899 VisitCXXRecordDecl(D);
900
901 if (Decl *InstD = Reader.GetDecl(Record[Idx++])) {
902 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
903 D->setInstantiationOf(CTD);
904 } else {
905 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
906 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
907 D->setInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(InstD),
908 TemplArgs.data(), TemplArgs.size());
909 }
910 }
911
912 // Explicit info.
913 if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Record, Idx)) {
914 D->setTypeAsWritten(TyInfo);
915 D->setExternLoc(Reader.ReadSourceLocation(Record, Idx));
916 D->setTemplateKeywordLoc(Reader.ReadSourceLocation(Record, Idx));
917 }
918
919 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
920 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
921 D->initTemplateArgs(TemplArgs.data(), TemplArgs.size());
922 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
923 if (POI.isValid())
924 D->setPointOfInstantiation(POI);
925 D->setSpecializationKind((TemplateSpecializationKind)Record[Idx++]);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000926
927 if (Record[Idx++]) { // IsKeptInFoldingSet.
928 ClassTemplateDecl *CanonPattern
929 = cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
930 if (ClassTemplatePartialSpecializationDecl *Partial
931 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
Chandler Carruth62e5e562010-07-11 07:42:13 +0000932 ClassTemplatePartialSpecializationDecl *Inserted
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000933 = CanonPattern->getPartialSpecializations().GetOrInsertNode(Partial);
Chandler Carruth62e5e562010-07-11 07:42:13 +0000934 (void)Inserted;
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000935 assert(Inserted == Partial && "Already inserted!");
936 } else {
Chandler Carruth62e5e562010-07-11 07:42:13 +0000937 ClassTemplateSpecializationDecl *Inserted
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000938 = CanonPattern->getSpecializations().GetOrInsertNode(D);
Chandler Carruth62e5e562010-07-11 07:42:13 +0000939 (void)Inserted;
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000940 assert(Inserted == D && "Already inserted!");
941 }
942 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000943}
944
945void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl(
946 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000947 VisitClassTemplateSpecializationDecl(D);
948
949 D->initTemplateParameters(Reader.ReadTemplateParameterList(Record, Idx));
950
951 TemplateArgumentListInfo ArgInfos;
952 unsigned NumArgs = Record[Idx++];
953 while (NumArgs--)
954 ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
955 D->initTemplateArgsAsWritten(ArgInfos);
956
957 D->setSequenceNumber(Record[Idx++]);
958
959 // These are read/set from/to the first declaration.
960 if (D->getPreviousDeclaration() == 0) {
961 D->setInstantiatedFromMember(
962 cast_or_null<ClassTemplatePartialSpecializationDecl>(
963 Reader.GetDecl(Record[Idx++])));
964 if (Record[Idx++])
Argyrios Kyrtzidisdd2061b2010-07-09 21:11:35 +0000965 D->setMemberSpecialization();
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000966 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000967}
968
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000969void PCHDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
970 VisitTemplateDecl(D);
971
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000972 D->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000973 FunctionTemplateDecl *PrevDecl =
974 cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
975 D->setPreviousDeclaration(PrevDecl);
976 if (PrevDecl == 0) {
977 // This FunctionTemplateDecl owns a CommonPtr; read it.
978
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +0000979 // Read the function specialization declarations.
980 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
981 // through the specialized FunctionDecl's setFunctionTemplateSpecialization.
982 unsigned NumSpecs = Record[Idx++];
983 while (NumSpecs--)
984 Reader.GetDecl(Record[Idx++]);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000985
986 if (FunctionTemplateDecl *CTD
987 = cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
988 D->setInstantiatedFromMemberTemplate(CTD);
989 if (Record[Idx++])
990 D->setMemberSpecialization();
991 }
992 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000993}
994
995void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000996 VisitTypeDecl(D);
997
998 D->setDeclaredWithTypename(Record[Idx++]);
999 D->setParameterPack(Record[Idx++]);
1000
1001 bool Inherited = Record[Idx++];
1002 TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Record, Idx);
1003 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001004}
1005
1006void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001007 VisitVarDecl(D);
1008 // TemplateParmPosition.
1009 D->setDepth(Record[Idx++]);
1010 D->setPosition(Record[Idx++]);
1011 // Rest of NonTypeTemplateParmDecl.
1012 if (Record[Idx++]) {
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001013 Expr *DefArg = Reader.ReadExpr();
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001014 bool Inherited = Record[Idx++];
1015 D->setDefaultArgument(DefArg, Inherited);
1016 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001017}
1018
1019void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001020 VisitTemplateDecl(D);
1021 // TemplateParmPosition.
1022 D->setDepth(Record[Idx++]);
1023 D->setPosition(Record[Idx++]);
1024 // Rest of TemplateTemplateParmDecl.
1025 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(Record, Idx);
1026 bool IsInherited = Record[Idx++];
1027 D->setDefaultArgument(Arg, IsInherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001028}
1029
1030void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
1031 assert(false && "cannot read StaticAssertDecl");
1032}
1033
Mike Stump11289f42009-09-09 15:08:12 +00001034std::pair<uint64_t, uint64_t>
Chris Lattner487412d2009-04-27 05:27:42 +00001035PCHDeclReader::VisitDeclContext(DeclContext *DC) {
1036 uint64_t LexicalOffset = Record[Idx++];
1037 uint64_t VisibleOffset = Record[Idx++];
1038 return std::make_pair(LexicalOffset, VisibleOffset);
1039}
1040
1041//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00001042// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00001043//===----------------------------------------------------------------------===//
1044
Chris Lattner8f63ab52009-04-27 06:01:06 +00001045/// \brief Reads attributes from the current stream position.
1046Attr *PCHReader::ReadAttributes() {
1047 unsigned Code = DeclsCursor.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +00001048 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner8f63ab52009-04-27 06:01:06 +00001049 "Expected unabbreviated record"); (void)Code;
Mike Stump11289f42009-09-09 15:08:12 +00001050
Chris Lattner8f63ab52009-04-27 06:01:06 +00001051 RecordData Record;
1052 unsigned Idx = 0;
1053 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump11289f42009-09-09 15:08:12 +00001054 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001055 (void)RecCode;
1056
1057#define SIMPLE_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001058 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +00001059 New = ::new (*Context) Name##Attr(); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001060 break
1061
1062#define STRING_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001063 case attr::Name: \
Ted Kremenek7f4945a2010-02-11 05:28:37 +00001064 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001065 break
1066
1067#define UNSIGNED_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001068 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +00001069 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001070 break
1071
1072 Attr *Attrs = 0;
1073 while (Idx < Record.size()) {
1074 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001075 attr::Kind Kind = (attr::Kind)Record[Idx++];
Chris Lattner8f63ab52009-04-27 06:01:06 +00001076 bool IsInherited = Record[Idx++];
1077
1078 switch (Kind) {
Anton Korobeynikov55bcea12010-01-10 12:58:08 +00001079 default:
1080 assert(0 && "Unknown attribute!");
1081 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001082 STRING_ATTR(Alias);
Daniel Dunbarfc6507e2010-05-27 02:25:39 +00001083 SIMPLE_ATTR(AlignMac68k);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001084 UNSIGNED_ATTR(Aligned);
1085 SIMPLE_ATTR(AlwaysInline);
1086 SIMPLE_ATTR(AnalyzerNoReturn);
1087 STRING_ATTR(Annotate);
1088 STRING_ATTR(AsmLabel);
Alexis Hunt54a02542009-11-25 04:20:27 +00001089 SIMPLE_ATTR(BaseCheck);
Mike Stump11289f42009-09-09 15:08:12 +00001090
Alexis Hunt344393e2010-06-16 23:43:53 +00001091 case attr::Blocks:
Chris Lattner8575daa2009-04-27 21:45:14 +00001092 New = ::new (*Context) BlocksAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001093 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
1094 break;
Mike Stump11289f42009-09-09 15:08:12 +00001095
Eli Friedmane4310c82009-11-09 18:38:53 +00001096 SIMPLE_ATTR(CDecl);
1097
Alexis Hunt344393e2010-06-16 23:43:53 +00001098 case attr::Cleanup:
Chris Lattner8575daa2009-04-27 21:45:14 +00001099 New = ::new (*Context) CleanupAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001100 cast<FunctionDecl>(GetDecl(Record[Idx++])));
1101 break;
1102
1103 SIMPLE_ATTR(Const);
1104 UNSIGNED_ATTR(Constructor);
1105 SIMPLE_ATTR(DLLExport);
1106 SIMPLE_ATTR(DLLImport);
1107 SIMPLE_ATTR(Deprecated);
1108 UNSIGNED_ATTR(Destructor);
1109 SIMPLE_ATTR(FastCall);
Alexis Hunt96d5c762009-11-21 08:43:09 +00001110 SIMPLE_ATTR(Final);
Mike Stump11289f42009-09-09 15:08:12 +00001111
Alexis Hunt344393e2010-06-16 23:43:53 +00001112 case attr::Format: {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001113 std::string Type = ReadString(Record, Idx);
1114 unsigned FormatIdx = Record[Idx++];
1115 unsigned FirstArg = Record[Idx++];
Ted Kremenek7f4945a2010-02-11 05:28:37 +00001116 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001117 break;
1118 }
Mike Stump11289f42009-09-09 15:08:12 +00001119
Alexis Hunt344393e2010-06-16 23:43:53 +00001120 case attr::FormatArg: {
Fariborz Jahanianf1c25022009-05-20 17:41:43 +00001121 unsigned FormatIdx = Record[Idx++];
1122 New = ::new (*Context) FormatArgAttr(FormatIdx);
1123 break;
1124 }
Mike Stump11289f42009-09-09 15:08:12 +00001125
Alexis Hunt344393e2010-06-16 23:43:53 +00001126 case attr::Sentinel: {
Fariborz Jahanian027b8862009-05-13 18:09:35 +00001127 int sentinel = Record[Idx++];
1128 int nullPos = Record[Idx++];
1129 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
1130 break;
1131 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001132
1133 SIMPLE_ATTR(GNUInline);
Alexis Hunt54a02542009-11-25 04:20:27 +00001134 SIMPLE_ATTR(Hiding);
Mike Stump11289f42009-09-09 15:08:12 +00001135
Alexis Hunt344393e2010-06-16 23:43:53 +00001136 case attr::IBAction:
Ted Kremenek06be9682010-02-17 02:37:45 +00001137 New = ::new (*Context) IBActionAttr();
1138 break;
1139
Alexis Hunt344393e2010-06-16 23:43:53 +00001140 case attr::IBOutlet:
Chris Lattner8575daa2009-04-27 21:45:14 +00001141 New = ::new (*Context) IBOutletAttr();
Chris Lattner8f63ab52009-04-27 06:01:06 +00001142 break;
1143
Alexis Hunt344393e2010-06-16 23:43:53 +00001144 case attr::IBOutletCollection: {
Ted Kremenek26bde772010-05-19 17:38:06 +00001145 ObjCInterfaceDecl *D =
1146 cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++]));
1147 New = ::new (*Context) IBOutletCollectionAttr(D);
1148 break;
1149 }
1150
Ryan Flynn1f1fdc02009-08-09 20:07:29 +00001151 SIMPLE_ATTR(Malloc);
Mike Stump3722f582009-08-26 22:31:08 +00001152 SIMPLE_ATTR(NoDebug);
1153 SIMPLE_ATTR(NoInline);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001154 SIMPLE_ATTR(NoReturn);
1155 SIMPLE_ATTR(NoThrow);
Mike Stump11289f42009-09-09 15:08:12 +00001156
Alexis Hunt344393e2010-06-16 23:43:53 +00001157 case attr::NonNull: {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001158 unsigned Size = Record[Idx++];
1159 llvm::SmallVector<unsigned, 16> ArgNums;
1160 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
1161 Idx += Size;
Ted Kremenek510ee252010-02-11 07:31:47 +00001162 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001163 break;
1164 }
Mike Stump11289f42009-09-09 15:08:12 +00001165
Alexis Hunt344393e2010-06-16 23:43:53 +00001166 case attr::ReqdWorkGroupSize: {
Nate Begemanf2758702009-06-26 06:32:41 +00001167 unsigned X = Record[Idx++];
1168 unsigned Y = Record[Idx++];
1169 unsigned Z = Record[Idx++];
1170 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
1171 break;
1172 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001173
1174 SIMPLE_ATTR(ObjCException);
1175 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekd9c66632010-02-18 00:05:45 +00001176 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +00001177 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenekd9c66632010-02-18 00:05:45 +00001178 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +00001179 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001180 SIMPLE_ATTR(Overloadable);
Alexis Hunt54a02542009-11-25 04:20:27 +00001181 SIMPLE_ATTR(Override);
Anders Carlsson68e0b682009-08-08 18:23:56 +00001182 SIMPLE_ATTR(Packed);
Daniel Dunbar40130442010-05-27 01:12:46 +00001183 UNSIGNED_ATTR(MaxFieldAlignment);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001184 SIMPLE_ATTR(Pure);
1185 UNSIGNED_ATTR(Regparm);
1186 STRING_ATTR(Section);
1187 SIMPLE_ATTR(StdCall);
Douglas Gregora941dca2010-05-18 16:57:00 +00001188 SIMPLE_ATTR(ThisCall);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001189 SIMPLE_ATTR(TransparentUnion);
1190 SIMPLE_ATTR(Unavailable);
1191 SIMPLE_ATTR(Unused);
1192 SIMPLE_ATTR(Used);
Mike Stump11289f42009-09-09 15:08:12 +00001193
Alexis Hunt344393e2010-06-16 23:43:53 +00001194 case attr::Visibility:
Chris Lattner8575daa2009-04-27 21:45:14 +00001195 New = ::new (*Context) VisibilityAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001196 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
1197 break;
1198
1199 SIMPLE_ATTR(WarnUnusedResult);
1200 SIMPLE_ATTR(Weak);
Rafael Espindolac18086a2010-02-23 22:00:30 +00001201 SIMPLE_ATTR(WeakRef);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001202 SIMPLE_ATTR(WeakImport);
1203 }
1204
1205 assert(New && "Unable to decode attribute?");
1206 New->setInherited(IsInherited);
1207 New->setNext(Attrs);
1208 Attrs = New;
1209 }
1210#undef UNSIGNED_ATTR
1211#undef STRING_ATTR
1212#undef SIMPLE_ATTR
1213
1214 // The list of attributes was built backwards. Reverse the list
1215 // before returning it.
1216 Attr *PrevAttr = 0, *NextAttr = 0;
1217 while (Attrs) {
1218 NextAttr = Attrs->getNext();
1219 Attrs->setNext(PrevAttr);
1220 PrevAttr = Attrs;
1221 Attrs = NextAttr;
1222 }
1223
1224 return PrevAttr;
1225}
1226
1227//===----------------------------------------------------------------------===//
1228// PCHReader Implementation
1229//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001230
1231/// \brief Note that we have loaded the declaration with the given
1232/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001233///
Chris Lattner487412d2009-04-27 05:27:42 +00001234/// This routine notes that this declaration has already been loaded,
1235/// so that future GetDecl calls will return this declaration rather
1236/// than trying to load a new declaration.
1237inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
1238 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1239 DeclsLoaded[Index] = D;
1240}
1241
1242
1243/// \brief Determine whether the consumer will be interested in seeing
1244/// this declaration (via HandleTopLevelDecl).
1245///
1246/// This routine should return true for anything that might affect
1247/// code generation, e.g., inline function definitions, Objective-C
1248/// declarations with metadata, etc.
1249static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001250 if (isa<FileScopeAsmDecl>(D))
1251 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001252 if (VarDecl *Var = dyn_cast<VarDecl>(D))
1253 return Var->isFileVarDecl() && Var->getInit();
1254 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1255 return Func->isThisDeclarationADefinition();
1256 return isa<ObjCProtocolDecl>(D);
1257}
1258
1259/// \brief Read the declaration at the given offset from the PCH file.
1260Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
1261 // Keep track of where we are in the stream, then jump back there
1262 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001263 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001264
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001265 ReadingKindTracker ReadingKind(Read_Decl, *this);
1266
Douglas Gregor1342e842009-07-06 18:54:52 +00001267 // Note that we are loading a declaration record.
1268 LoadingTypeOrDecl Loading(*this);
Mike Stump11289f42009-09-09 15:08:12 +00001269
Chris Lattner1de76db2009-04-27 05:58:23 +00001270 DeclsCursor.JumpToBit(Offset);
Chris Lattner487412d2009-04-27 05:27:42 +00001271 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001272 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001273 unsigned Idx = 0;
1274 PCHDeclReader Reader(*this, Record, Idx);
1275
Chris Lattner1de76db2009-04-27 05:58:23 +00001276 Decl *D = 0;
1277 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner487412d2009-04-27 05:27:42 +00001278 case pch::DECL_ATTR:
1279 case pch::DECL_CONTEXT_LEXICAL:
1280 case pch::DECL_CONTEXT_VISIBLE:
1281 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1282 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001283 case pch::DECL_TRANSLATION_UNIT:
1284 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +00001285 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +00001286 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001287 case pch::DECL_TYPEDEF:
John McCall703a3f82009-10-24 08:00:42 +00001288 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001289 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001290 case pch::DECL_ENUM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001291 D = EnumDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001292 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001293 case pch::DECL_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001294 D = RecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001295 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001296 case pch::DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +00001297 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001298 0, llvm::APSInt());
1299 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001300 case pch::DECL_FUNCTION:
Mike Stump11289f42009-09-09 15:08:12 +00001301 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001302 QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001303 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001304 case pch::DECL_LINKAGE_SPEC:
1305 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
1306 (LinkageSpecDecl::LanguageIDs)0,
1307 false);
1308 break;
1309 case pch::DECL_NAMESPACE:
1310 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
1311 break;
1312 case pch::DECL_NAMESPACE_ALIAS:
1313 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
1314 SourceLocation(), 0, SourceRange(), 0,
1315 SourceLocation(), 0);
1316 break;
1317 case pch::DECL_USING:
1318 D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(),
1319 SourceLocation(), 0, DeclarationName(), false);
1320 break;
1321 case pch::DECL_USING_SHADOW:
1322 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1323 break;
1324 case pch::DECL_USING_DIRECTIVE:
1325 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
1326 SourceLocation(), SourceRange(), 0,
1327 SourceLocation(), 0, 0);
1328 break;
1329 case pch::DECL_UNRESOLVED_USING_VALUE:
1330 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
1331 SourceRange(), 0, SourceLocation(),
1332 DeclarationName());
1333 break;
1334 case pch::DECL_UNRESOLVED_USING_TYPENAME:
1335 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
1336 SourceLocation(), SourceRange(),
1337 0, SourceLocation(),
1338 DeclarationName());
1339 break;
1340 case pch::DECL_CXX_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001341 D = CXXRecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001342 break;
1343 case pch::DECL_CXX_METHOD:
1344 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
1345 QualType(), 0);
1346 break;
1347 case pch::DECL_CXX_CONSTRUCTOR:
1348 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1349 break;
1350 case pch::DECL_CXX_DESTRUCTOR:
1351 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1352 break;
1353 case pch::DECL_CXX_CONVERSION:
1354 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1355 break;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001356 case pch::DECL_ACCESS_SPEC:
1357 D = AccessSpecDecl::Create(*Context, AS_none, 0, SourceLocation(),
1358 SourceLocation());
1359 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001360 case pch::DECL_FRIEND:
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001361 D = FriendDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001362 break;
1363 case pch::DECL_FRIEND_TEMPLATE:
1364 assert(false && "cannot read FriendTemplateDecl");
1365 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001366 case pch::DECL_CLASS_TEMPLATE:
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +00001367 D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(),
1368 DeclarationName(), 0, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001369 break;
1370 case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001371 D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001372 break;
1373 case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001374 D = ClassTemplatePartialSpecializationDecl::Create(*Context,
1375 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001376 break;
1377 case pch::DECL_FUNCTION_TEMPLATE:
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001378 D = FunctionTemplateDecl::Create(*Context, 0, SourceLocation(),
1379 DeclarationName(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001380 break;
1381 case pch::DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001382 D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001383 break;
1384 case pch::DECL_NON_TYPE_TEMPLATE_PARM:
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001385 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0,
1386 QualType(),0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001387 break;
1388 case pch::DECL_TEMPLATE_TEMPLATE_PARM:
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001389 D = TemplateTemplateParmDecl::Create(*Context, 0, SourceLocation(),0,0,0,0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001390 break;
1391 case pch::DECL_STATIC_ASSERT:
1392 assert(false && "cannot read StaticAssertDecl");
1393 break;
1394
Chris Lattner8f63ab52009-04-27 06:01:06 +00001395 case pch::DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +00001396 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001397 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001398 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001399 case pch::DECL_OBJC_INTERFACE:
Chris Lattner8575daa2009-04-27 21:45:14 +00001400 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001401 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001402 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001403 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001404 ObjCIvarDecl::None);
1405 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001406 case pch::DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001407 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001408 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001409 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001410 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001411 QualType(), 0);
1412 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001413 case pch::DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001414 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001415 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001416 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001417 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001418 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001419 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +00001420 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1421 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001422 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001423 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001424 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001425 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001426 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +00001427 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001428 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001429 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001430 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001431 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001432 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001433 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001434 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001435 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001436 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001437 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001438 SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001439 ObjCPropertyImplDecl::Dynamic, 0);
1440 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001441 case pch::DECL_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001442 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +00001443 false);
Chris Lattner487412d2009-04-27 05:27:42 +00001444 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001445 case pch::DECL_VAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001446 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001447 VarDecl::None, VarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001448 break;
1449
1450 case pch::DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001451 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001452 break;
1453
Chris Lattner8f63ab52009-04-27 06:01:06 +00001454 case pch::DECL_PARM_VAR:
Mike Stump11289f42009-09-09 15:08:12 +00001455 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001456 VarDecl::None, VarDecl::None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001457 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001458 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001459 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001460 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001461 case pch::DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +00001462 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001463 break;
1464 }
Chris Lattner487412d2009-04-27 05:27:42 +00001465
1466 assert(D && "Unknown declaration reading PCH file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001467 LoadedDecl(Index, D);
1468 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001469
1470 // If this declaration is also a declaration context, get the
1471 // offsets for its tables of lexical and visible declarations.
1472 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1473 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1474 if (Offsets.first || Offsets.second) {
1475 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1476 DC->setHasExternalVisibleStorage(Offsets.second != 0);
1477 DeclContextOffsets[DC] = Offsets;
1478 }
1479 }
1480 assert(Idx == Record.size());
1481
1482 // If we have deserialized a declaration that has a definition the
Argyrios Kyrtzidis903ccd62010-07-07 15:46:26 +00001483 // AST consumer might need to know about, queue it.
1484 // We don't pass it to the consumer immediately because we may be in recursive
1485 // loading, and some declarations may still be initializing.
1486 if (isConsumerInterestedIn(D))
1487 InterestingDecls.push_back(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001488
1489 return D;
1490}