blob: 7297fefcb26ec351a2480071d655cafd14363a72 [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++])
Sebastian Redl3d3f0b12010-07-19 22:38:35 +0000120 FD->setLazyBody(Reader.Chain[0]->DeclsCursor.GetCurrentBitNo());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000121 }
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 Kyrtzidisdde57902010-07-20 13:59:58 +0000257 if (FD->isCanonicalDecl()) // if canonical add to template's set.
258 FD->setFunctionTemplateSpecialization(Template, TemplArgs.size(),
259 TemplArgs.data(), TSK,
260 TemplArgLocs.size(),
261 TemplArgLocs.data(),
262 LAngleLoc, RAngleLoc, POI);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000263 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000264 }
265 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
266 // Templates.
267 UnresolvedSet<8> TemplDecls;
268 unsigned NumTemplates = Record[Idx++];
269 while (NumTemplates--)
270 TemplDecls.addDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
271
272 // Templates args.
273 TemplateArgumentListInfo TemplArgs;
274 unsigned NumArgs = Record[Idx++];
275 while (NumArgs--)
276 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000277 TemplArgs.setLAngleLoc(Reader.ReadSourceLocation(Record, Idx));
278 TemplArgs.setRAngleLoc(Reader.ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000279
280 FD->setDependentTemplateSpecialization(*Reader.getContext(),
281 TemplDecls, TemplArgs);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000282 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000283 }
284 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000285
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000286 // FunctionDecl's body is handled last at PCHReaderDecl::Visit,
287 // after everything else is read.
288
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000289 // Avoid side effects and invariant checking of FunctionDecl's
290 // setPreviousDeclaration.
291 FD->redeclarable_base::setPreviousDeclaration(
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000292 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
293 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
294 FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]);
295 FD->setInlineSpecified(Record[Idx++]);
296 FD->setVirtualAsWritten(Record[Idx++]);
297 FD->setPure(Record[Idx++]);
298 FD->setHasInheritedPrototype(Record[Idx++]);
299 FD->setHasWrittenPrototype(Record[Idx++]);
300 FD->setDeleted(Record[Idx++]);
301 FD->setTrivial(Record[Idx++]);
302 FD->setCopyAssignment(Record[Idx++]);
303 FD->setHasImplicitReturnZero(Record[Idx++]);
304 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
305
Chris Lattnerca025db2010-05-07 21:43:38 +0000306 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000307 unsigned NumParams = Record[Idx++];
308 llvm::SmallVector<ParmVarDecl *, 16> Params;
309 Params.reserve(NumParams);
310 for (unsigned I = 0; I != NumParams; ++I)
311 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000312 FD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000313}
314
315void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
316 VisitNamedDecl(MD);
317 if (Record[Idx++]) {
318 // In practice, this won't be executed (since method definitions
319 // don't occur in header files).
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000320 MD->setBody(Reader.ReadStmt());
Chris Lattner487412d2009-04-27 05:27:42 +0000321 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
322 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
323 }
324 MD->setInstanceMethod(Record[Idx++]);
325 MD->setVariadic(Record[Idx++]);
326 MD->setSynthesized(Record[Idx++]);
327 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
328 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahaniand9235db2010-04-08 21:29:11 +0000329 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000330 MD->setResultType(Reader.GetType(Record[Idx++]));
Douglas Gregor12852d92010-03-08 14:59:44 +0000331 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000332 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
333 unsigned NumParams = Record[Idx++];
334 llvm::SmallVector<ParmVarDecl *, 16> Params;
335 Params.reserve(NumParams);
336 for (unsigned I = 0; I != NumParams; ++I)
337 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniancdabb312010-04-09 15:40:42 +0000338 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
339 NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000340}
341
342void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
343 VisitNamedDecl(CD);
Ted Kremenekc7c64312010-01-07 01:20:12 +0000344 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
345 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
346 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner487412d2009-04-27 05:27:42 +0000347}
348
349void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
350 VisitObjCContainerDecl(ID);
351 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
352 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
353 (Reader.GetDecl(Record[Idx++])));
354 unsigned NumProtocols = Record[Idx++];
355 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
356 Protocols.reserve(NumProtocols);
357 for (unsigned I = 0; I != NumProtocols; ++I)
358 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000359 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
360 ProtoLocs.reserve(NumProtocols);
361 for (unsigned I = 0; I != NumProtocols; ++I)
362 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
363 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
364 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000365 unsigned NumIvars = Record[Idx++];
366 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
367 IVars.reserve(NumIvars);
368 for (unsigned I = 0; I != NumIvars; ++I)
369 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000370 ID->setCategoryList(
371 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
372 ID->setForwardDecl(Record[Idx++]);
373 ID->setImplicitInterfaceDecl(Record[Idx++]);
374 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
375 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisea72f422009-07-18 00:33:23 +0000376 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000377}
378
379void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
380 VisitFieldDecl(IVD);
381 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000382 bool synth = Record[Idx++];
383 IVD->setSynthesize(synth);
Chris Lattner487412d2009-04-27 05:27:42 +0000384}
385
386void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
387 VisitObjCContainerDecl(PD);
388 PD->setForwardDecl(Record[Idx++]);
389 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
390 unsigned NumProtoRefs = Record[Idx++];
391 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
392 ProtoRefs.reserve(NumProtoRefs);
393 for (unsigned I = 0; I != NumProtoRefs; ++I)
394 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000395 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
396 ProtoLocs.reserve(NumProtoRefs);
397 for (unsigned I = 0; I != NumProtoRefs; ++I)
398 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
399 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
400 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000401}
402
403void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
404 VisitFieldDecl(FD);
405}
406
407void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
408 VisitDecl(CD);
409 unsigned NumClassRefs = Record[Idx++];
410 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
411 ClassRefs.reserve(NumClassRefs);
412 for (unsigned I = 0; I != NumClassRefs; ++I)
413 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000414 llvm::SmallVector<SourceLocation, 16> SLocs;
415 SLocs.reserve(NumClassRefs);
416 for (unsigned I = 0; I != NumClassRefs; ++I)
417 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
418 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
419 NumClassRefs);
Chris Lattner487412d2009-04-27 05:27:42 +0000420}
421
422void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
423 VisitDecl(FPD);
424 unsigned NumProtoRefs = Record[Idx++];
425 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
426 ProtoRefs.reserve(NumProtoRefs);
427 for (unsigned I = 0; I != NumProtoRefs; ++I)
428 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000429 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
430 ProtoLocs.reserve(NumProtoRefs);
431 for (unsigned I = 0; I != NumProtoRefs; ++I)
432 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
433 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
434 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000435}
436
437void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
438 VisitObjCContainerDecl(CD);
439 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
440 unsigned NumProtoRefs = Record[Idx++];
441 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
442 ProtoRefs.reserve(NumProtoRefs);
443 for (unsigned I = 0; I != NumProtoRefs; ++I)
444 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000445 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
446 ProtoLocs.reserve(NumProtoRefs);
447 for (unsigned I = 0; I != NumProtoRefs; ++I)
448 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
449 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
450 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000451 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor071676f2010-01-16 16:38:58 +0000452 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
453 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000454}
455
456void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
457 VisitNamedDecl(CAD);
458 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
459}
460
461void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
462 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000463 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall339bb662010-06-04 20:50:08 +0000464 D->setType(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000465 // FIXME: stable encoding
466 D->setPropertyAttributes(
467 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000468 D->setPropertyAttributesAsWritten(
469 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000470 // FIXME: stable encoding
471 D->setPropertyImplementation(
472 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
473 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
474 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
475 D->setGetterMethodDecl(
476 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
477 D->setSetterMethodDecl(
478 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
479 D->setPropertyIvarDecl(
480 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
481}
482
483void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000484 VisitObjCContainerDecl(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000485 D->setClassInterface(
486 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000487}
488
489void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
490 VisitObjCImplDecl(D);
491 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
492}
493
494void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
495 VisitObjCImplDecl(D);
496 D->setSuperClass(
497 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanianc83726e2010-04-28 16:11:27 +0000498 // FIXME. Add reading of IvarInitializers and NumIvarInitializers.
Chris Lattner487412d2009-04-27 05:27:42 +0000499}
500
501
502void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
503 VisitDecl(D);
504 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
505 D->setPropertyDecl(
506 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
507 D->setPropertyIvarDecl(
508 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanian25491a22010-05-05 21:52:17 +0000509 // FIXME. read GetterCXXConstructor and SetterCXXAssignment
Chris Lattner487412d2009-04-27 05:27:42 +0000510}
511
512void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000513 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000514 FD->setMutable(Record[Idx++]);
515 if (Record[Idx++])
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000516 FD->setBitWidth(Reader.ReadExpr());
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000517 if (!FD->getDeclName()) {
518 FieldDecl *Tmpl = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
519 if (Tmpl)
520 Reader.getContext()->setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
521 }
Chris Lattner487412d2009-04-27 05:27:42 +0000522}
523
524void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000525 VisitDeclaratorDecl(VD);
Chris Lattner487412d2009-04-27 05:27:42 +0000526 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
Douglas Gregorc4df4072010-04-19 22:54:31 +0000527 VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000528 VD->setThreadSpecified(Record[Idx++]);
529 VD->setCXXDirectInitializer(Record[Idx++]);
530 VD->setDeclaredInCondition(Record[Idx++]);
Douglas Gregor3f324d562010-05-03 18:51:14 +0000531 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor6fd1b182010-05-15 06:01:05 +0000532 VD->setNRVOVariable(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000533 VD->setPreviousDeclaration(
534 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000535 if (Record[Idx++])
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000536 VD->setInit(Reader.ReadExpr());
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000537
538 if (Record[Idx++]) { // HasMemberSpecializationInfo.
539 VarDecl *Tmpl = cast<VarDecl>(Reader.GetDecl(Record[Idx++]));
540 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
541 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
542 Reader.getContext()->setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
543 }
Chris Lattner487412d2009-04-27 05:27:42 +0000544}
545
546void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
547 VisitVarDecl(PD);
548}
549
550void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
551 VisitVarDecl(PD);
552 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallf3cd6652010-03-12 18:31:32 +0000553 PD->setHasInheritedDefaultArg(Record[Idx++]);
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000554 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
555 PD->setUninstantiatedDefaultArg(Reader.ReadExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000556}
557
Chris Lattner487412d2009-04-27 05:27:42 +0000558void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
559 VisitDecl(AD);
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000560 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr()));
Chris Lattner487412d2009-04-27 05:27:42 +0000561}
562
563void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
564 VisitDecl(BD);
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000565 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt()));
John McCalla3ccba02010-06-04 11:21:44 +0000566 BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000567 unsigned NumParams = Record[Idx++];
568 llvm::SmallVector<ParmVarDecl *, 16> Params;
569 Params.reserve(NumParams);
570 for (unsigned I = 0; I != NumParams; ++I)
571 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000572 BD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000573}
574
Chris Lattnerca025db2010-05-07 21:43:38 +0000575void PCHDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
576 VisitDecl(D);
577 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
578 D->setHasBraces(Record[Idx++]);
579}
580
581void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
582 VisitNamedDecl(D);
583 D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx));
584 D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx));
585 D->setNextNamespace(
586 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
587
Chris Lattnerca025db2010-05-07 21:43:38 +0000588 bool IsOriginal = Record[Idx++];
Argyrios Kyrtzidisdae2a162010-07-03 07:57:53 +0000589 D->OrigOrAnonNamespace.setInt(IsOriginal);
590 D->OrigOrAnonNamespace.setPointer(
Chris Lattnerca025db2010-05-07 21:43:38 +0000591 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
592}
593
594void PCHDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
595 VisitNamedDecl(D);
596
597 D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx));
598 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
599 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
600 D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx));
601 D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
602}
603
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000604void PCHDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000605 VisitNamedDecl(D);
606 D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
607 D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
608 D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
609
610 // FIXME: It would probably be more efficient to read these into a vector
611 // and then re-cosntruct the shadow decl set over that vector since it
612 // would avoid existence checks.
613 unsigned NumShadows = Record[Idx++];
614 for(unsigned I = 0; I != NumShadows; ++I) {
Argyrios Kyrtzidis00dda6a2010-07-08 13:09:41 +0000615 // Avoid invariant checking of UsingDecl::addShadowDecl, the decl may still
616 // be initializing.
617 D->Shadows.insert(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattnerca025db2010-05-07 21:43:38 +0000618 }
619 D->setTypeName(Record[Idx++]);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000620 NamedDecl *Pattern = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
621 if (Pattern)
622 Reader.getContext()->setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000623}
624
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000625void PCHDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000626 VisitNamedDecl(D);
627 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
628 D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000629 UsingShadowDecl *Pattern
630 = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]));
631 if (Pattern)
632 Reader.getContext()->setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000633}
634
635void PCHDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
636 VisitNamedDecl(D);
637 D->setNamespaceKeyLocation(Reader.ReadSourceLocation(Record, Idx));
638 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
639 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
640 D->setIdentLocation(Reader.ReadSourceLocation(Record, Idx));
641 D->setNominatedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
642 D->setCommonAncestor(cast_or_null<DeclContext>(
643 Reader.GetDecl(Record[Idx++])));
644}
645
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000646void PCHDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000647 VisitValueDecl(D);
648 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
649 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
650 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
651}
652
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000653void PCHDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000654 UnresolvedUsingTypenameDecl *D) {
655 VisitTypeDecl(D);
656 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
657 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
658 D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx));
659 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
660}
661
662void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000663 ASTContext &C = *Reader.getContext();
664
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000665 // We need to allocate the DefinitionData struct ahead of VisitRecordDecl
666 // so that the other CXXRecordDecls can get a pointer even when the owner
667 // is still initializing.
668 bool OwnsDefinitionData = false;
669 enum DataOwnership { Data_NoDefData, Data_Owner, Data_NotOwner };
670 switch ((DataOwnership)Record[Idx++]) {
671 default:
672 assert(0 && "Out of sync with PCHDeclWriter or messed up reading");
673 case Data_NoDefData:
674 break;
675 case Data_Owner:
676 OwnsDefinitionData = true;
677 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
678 break;
679 case Data_NotOwner:
680 D->DefinitionData
681 = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]))->DefinitionData;
682 break;
683 }
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000684
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000685 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000686
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000687 if (OwnsDefinitionData) {
688 assert(D->DefinitionData);
689 struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData;
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000690
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000691 Data.UserDeclaredConstructor = Record[Idx++];
692 Data.UserDeclaredCopyConstructor = Record[Idx++];
693 Data.UserDeclaredCopyAssignment = Record[Idx++];
694 Data.UserDeclaredDestructor = Record[Idx++];
695 Data.Aggregate = Record[Idx++];
696 Data.PlainOldData = Record[Idx++];
697 Data.Empty = Record[Idx++];
698 Data.Polymorphic = Record[Idx++];
699 Data.Abstract = Record[Idx++];
700 Data.HasTrivialConstructor = Record[Idx++];
701 Data.HasTrivialCopyConstructor = Record[Idx++];
702 Data.HasTrivialCopyAssignment = Record[Idx++];
703 Data.HasTrivialDestructor = Record[Idx++];
704 Data.ComputedVisibleConversions = Record[Idx++];
705 Data.DeclaredDefaultConstructor = Record[Idx++];
706 Data.DeclaredCopyConstructor = Record[Idx++];
707 Data.DeclaredCopyAssignment = Record[Idx++];
708 Data.DeclaredDestructor = Record[Idx++];
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000709
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000710 // setBases() is unsuitable since it may try to iterate the bases of an
711 // unitialized base.
712 Data.NumBases = Record[Idx++];
713 Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases];
714 for (unsigned i = 0; i != Data.NumBases; ++i)
715 Data.Bases[i] = Reader.ReadCXXBaseSpecifier(Record, Idx);
716
717 // FIXME: Make VBases lazily computed when needed to avoid storing them.
718 Data.NumVBases = Record[Idx++];
719 Data.VBases = new(C) CXXBaseSpecifier [Data.NumVBases];
720 for (unsigned i = 0; i != Data.NumVBases; ++i)
721 Data.VBases[i] = Reader.ReadCXXBaseSpecifier(Record, Idx);
722
723 Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx);
724 Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx);
725 assert(Data.Definition && "Data.Definition should be already set!");
726 Data.FirstFriend
727 = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000728 }
729
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000730 enum CXXRecKind {
731 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
732 };
733 switch ((CXXRecKind)Record[Idx++]) {
734 default:
735 assert(false && "Out of sync with PCHDeclWriter::VisitCXXRecordDecl?");
736 case CXXRecNotTemplate:
737 break;
738 case CXXRecTemplate:
739 D->setDescribedClassTemplate(
740 cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++])));
741 break;
742 case CXXRecMemberSpecialization: {
743 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
744 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
745 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
746 D->setInstantiationOfMemberClass(RD, TSK);
747 D->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
748 break;
749 }
750 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000751}
752
753void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000754 VisitFunctionDecl(D);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000755 unsigned NumOverridenMethods = Record[Idx++];
756 while (NumOverridenMethods--) {
757 CXXMethodDecl *MD = cast<CXXMethodDecl>(Reader.GetDecl(Record[Idx++]));
758 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
759 // MD may be initializing.
760 Reader.getContext()->addOverriddenMethod(D, MD);
761 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000762}
763
764void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000765 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000766
767 D->IsExplicitSpecified = Record[Idx++];
768 D->ImplicitlyDefined = Record[Idx++];
769
770 unsigned NumInitializers = Record[Idx++];
771 D->NumBaseOrMemberInitializers = NumInitializers;
772 if (NumInitializers) {
773 ASTContext &C = *Reader.getContext();
774
775 D->BaseOrMemberInitializers
776 = new (C) CXXBaseOrMemberInitializer*[NumInitializers];
777 for (unsigned i=0; i != NumInitializers; ++i) {
Duncan Sands16143962010-07-06 18:19:40 +0000778 TypeSourceInfo *BaseClassInfo = 0;
779 bool IsBaseVirtual = false;
780 FieldDecl *Member = 0;
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000781
782 bool IsBaseInitializer = Record[Idx++];
783 if (IsBaseInitializer) {
784 BaseClassInfo = Reader.GetTypeSourceInfo(Record, Idx);
785 IsBaseVirtual = Record[Idx++];
786 } else {
787 Member = cast<FieldDecl>(Reader.GetDecl(Record[Idx++]));
788 }
789 SourceLocation MemberLoc = Reader.ReadSourceLocation(Record, Idx);
790 Expr *Init = Reader.ReadExpr();
791 FieldDecl *AnonUnionMember
792 = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
793 SourceLocation LParenLoc = Reader.ReadSourceLocation(Record, Idx);
794 SourceLocation RParenLoc = Reader.ReadSourceLocation(Record, Idx);
795 bool IsWritten = Record[Idx++];
796 unsigned SourceOrderOrNumArrayIndices;
797 llvm::SmallVector<VarDecl *, 8> Indices;
798 if (IsWritten) {
799 SourceOrderOrNumArrayIndices = Record[Idx++];
800 } else {
801 SourceOrderOrNumArrayIndices = Record[Idx++];
802 Indices.reserve(SourceOrderOrNumArrayIndices);
803 for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i)
804 Indices.push_back(cast<VarDecl>(Reader.GetDecl(Record[Idx++])));
805 }
806
807 CXXBaseOrMemberInitializer *BOMInit;
808 if (IsBaseInitializer) {
809 BOMInit = new (C) CXXBaseOrMemberInitializer(C, BaseClassInfo,
810 IsBaseVirtual, LParenLoc,
811 Init, RParenLoc);
812 } else if (IsWritten) {
813 BOMInit = new (C) CXXBaseOrMemberInitializer(C, Member, MemberLoc,
814 LParenLoc, Init, RParenLoc);
815 } else {
816 BOMInit = CXXBaseOrMemberInitializer::Create(C, Member, MemberLoc,
817 LParenLoc, Init, RParenLoc,
818 Indices.data(),
819 Indices.size());
820 }
821
822 BOMInit->setAnonUnionMember(AnonUnionMember);
823 D->BaseOrMemberInitializers[i] = BOMInit;
824 }
825 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000826}
827
828void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000829 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000830
831 D->ImplicitlyDefined = Record[Idx++];
832 D->OperatorDelete = cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000833}
834
835void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000836 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000837 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000838}
839
Abramo Bagnarad7340582010-06-05 05:09:32 +0000840void PCHDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
841 VisitDecl(D);
842 D->setColonLoc(Reader.ReadSourceLocation(Record, Idx));
843}
844
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000845void PCHDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000846 VisitDecl(D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000847 if (Record[Idx++])
848 D->Friend = Reader.GetTypeSourceInfo(Record, Idx);
849 else
850 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
851 D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
852 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
853}
854
Chris Lattnerca025db2010-05-07 21:43:38 +0000855void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +0000856 VisitDecl(D);
857 unsigned NumParams = Record[Idx++];
858 D->NumParams = NumParams;
859 D->Params = new TemplateParameterList*[NumParams];
860 for (unsigned i = 0; i != NumParams; ++i)
861 D->Params[i] = Reader.ReadTemplateParameterList(Record, Idx);
862 if (Record[Idx++]) // HasFriendDecl
863 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
864 else
865 D->Friend = Reader.GetTypeSourceInfo(Record, Idx);
866 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000867}
868
869void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000870 VisitNamedDecl(D);
871
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +0000872 NamedDecl *TemplatedDecl
873 = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000874 TemplateParameterList* TemplateParams
875 = Reader.ReadTemplateParameterList(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000876 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +0000877}
878
879void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000880 VisitTemplateDecl(D);
881
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000882 D->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000883 ClassTemplateDecl *PrevDecl =
884 cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +0000885 D->setPreviousDeclaration(PrevDecl);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000886 if (PrevDecl == 0) {
887 // This ClassTemplateDecl owns a CommonPtr; read it.
888
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000889 // FoldingSets are filled in VisitClassTemplateSpecializationDecl.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000890 unsigned size = Record[Idx++];
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000891 while (size--)
892 cast<ClassTemplateSpecializationDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000893
894 size = Record[Idx++];
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000895 while (size--)
896 cast<ClassTemplatePartialSpecializationDecl>(
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000897 Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000898
899 // InjectedClassNameType is computed.
900
901 if (ClassTemplateDecl *CTD
902 = cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
903 D->setInstantiatedFromMemberTemplate(CTD);
904 if (Record[Idx++])
905 D->setMemberSpecialization();
906 }
907 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000908}
909
910void PCHDeclReader::VisitClassTemplateSpecializationDecl(
911 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000912 VisitCXXRecordDecl(D);
913
914 if (Decl *InstD = Reader.GetDecl(Record[Idx++])) {
915 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
916 D->setInstantiationOf(CTD);
917 } else {
918 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
919 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
920 D->setInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(InstD),
921 TemplArgs.data(), TemplArgs.size());
922 }
923 }
924
925 // Explicit info.
926 if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Record, Idx)) {
927 D->setTypeAsWritten(TyInfo);
928 D->setExternLoc(Reader.ReadSourceLocation(Record, Idx));
929 D->setTemplateKeywordLoc(Reader.ReadSourceLocation(Record, Idx));
930 }
931
932 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
933 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
934 D->initTemplateArgs(TemplArgs.data(), TemplArgs.size());
935 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
936 if (POI.isValid())
937 D->setPointOfInstantiation(POI);
938 D->setSpecializationKind((TemplateSpecializationKind)Record[Idx++]);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000939
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +0000940 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000941 ClassTemplateDecl *CanonPattern
942 = cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
943 if (ClassTemplatePartialSpecializationDecl *Partial
944 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
Argyrios Kyrtzidisf4cc7dc2010-07-12 21:41:31 +0000945 CanonPattern->getPartialSpecializations().InsertNode(Partial);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000946 } else {
Argyrios Kyrtzidisf4cc7dc2010-07-12 21:41:31 +0000947 CanonPattern->getSpecializations().InsertNode(D);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000948 }
949 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000950}
951
952void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl(
953 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000954 VisitClassTemplateSpecializationDecl(D);
955
956 D->initTemplateParameters(Reader.ReadTemplateParameterList(Record, Idx));
957
958 TemplateArgumentListInfo ArgInfos;
959 unsigned NumArgs = Record[Idx++];
960 while (NumArgs--)
961 ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
962 D->initTemplateArgsAsWritten(ArgInfos);
963
964 D->setSequenceNumber(Record[Idx++]);
965
966 // These are read/set from/to the first declaration.
967 if (D->getPreviousDeclaration() == 0) {
968 D->setInstantiatedFromMember(
969 cast_or_null<ClassTemplatePartialSpecializationDecl>(
970 Reader.GetDecl(Record[Idx++])));
971 if (Record[Idx++])
Argyrios Kyrtzidisdd2061b2010-07-09 21:11:35 +0000972 D->setMemberSpecialization();
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000973 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000974}
975
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000976void PCHDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
977 VisitTemplateDecl(D);
978
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000979 D->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000980 FunctionTemplateDecl *PrevDecl =
981 cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
982 D->setPreviousDeclaration(PrevDecl);
983 if (PrevDecl == 0) {
984 // This FunctionTemplateDecl owns a CommonPtr; read it.
985
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +0000986 // Read the function specialization declarations.
987 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
988 // through the specialized FunctionDecl's setFunctionTemplateSpecialization.
989 unsigned NumSpecs = Record[Idx++];
990 while (NumSpecs--)
991 Reader.GetDecl(Record[Idx++]);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000992
993 if (FunctionTemplateDecl *CTD
994 = cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
995 D->setInstantiatedFromMemberTemplate(CTD);
996 if (Record[Idx++])
997 D->setMemberSpecialization();
998 }
999 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001000}
1001
1002void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001003 VisitTypeDecl(D);
1004
1005 D->setDeclaredWithTypename(Record[Idx++]);
1006 D->setParameterPack(Record[Idx++]);
1007
1008 bool Inherited = Record[Idx++];
1009 TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Record, Idx);
1010 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001011}
1012
1013void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001014 VisitVarDecl(D);
1015 // TemplateParmPosition.
1016 D->setDepth(Record[Idx++]);
1017 D->setPosition(Record[Idx++]);
1018 // Rest of NonTypeTemplateParmDecl.
1019 if (Record[Idx++]) {
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001020 Expr *DefArg = Reader.ReadExpr();
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001021 bool Inherited = Record[Idx++];
1022 D->setDefaultArgument(DefArg, Inherited);
1023 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001024}
1025
1026void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001027 VisitTemplateDecl(D);
1028 // TemplateParmPosition.
1029 D->setDepth(Record[Idx++]);
1030 D->setPosition(Record[Idx++]);
1031 // Rest of TemplateTemplateParmDecl.
1032 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(Record, Idx);
1033 bool IsInherited = Record[Idx++];
1034 D->setDefaultArgument(Arg, IsInherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001035}
1036
1037void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
1038 assert(false && "cannot read StaticAssertDecl");
1039}
1040
Mike Stump11289f42009-09-09 15:08:12 +00001041std::pair<uint64_t, uint64_t>
Chris Lattner487412d2009-04-27 05:27:42 +00001042PCHDeclReader::VisitDeclContext(DeclContext *DC) {
1043 uint64_t LexicalOffset = Record[Idx++];
1044 uint64_t VisibleOffset = Record[Idx++];
1045 return std::make_pair(LexicalOffset, VisibleOffset);
1046}
1047
1048//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00001049// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00001050//===----------------------------------------------------------------------===//
1051
Chris Lattner8f63ab52009-04-27 06:01:06 +00001052/// \brief Reads attributes from the current stream position.
1053Attr *PCHReader::ReadAttributes() {
Sebastian Redl34522812010-07-16 17:50:48 +00001054 llvm::BitstreamCursor &DeclsCursor = Chain[0]->DeclsCursor;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001055 unsigned Code = DeclsCursor.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +00001056 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner8f63ab52009-04-27 06:01:06 +00001057 "Expected unabbreviated record"); (void)Code;
Mike Stump11289f42009-09-09 15:08:12 +00001058
Chris Lattner8f63ab52009-04-27 06:01:06 +00001059 RecordData Record;
1060 unsigned Idx = 0;
1061 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump11289f42009-09-09 15:08:12 +00001062 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001063 (void)RecCode;
1064
1065#define SIMPLE_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001066 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +00001067 New = ::new (*Context) Name##Attr(); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001068 break
1069
1070#define STRING_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001071 case attr::Name: \
Ted Kremenek7f4945a2010-02-11 05:28:37 +00001072 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001073 break
1074
1075#define UNSIGNED_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001076 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +00001077 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001078 break
1079
1080 Attr *Attrs = 0;
1081 while (Idx < Record.size()) {
1082 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001083 attr::Kind Kind = (attr::Kind)Record[Idx++];
Chris Lattner8f63ab52009-04-27 06:01:06 +00001084 bool IsInherited = Record[Idx++];
1085
1086 switch (Kind) {
Anton Korobeynikov55bcea12010-01-10 12:58:08 +00001087 default:
1088 assert(0 && "Unknown attribute!");
1089 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001090 STRING_ATTR(Alias);
Daniel Dunbarfc6507e2010-05-27 02:25:39 +00001091 SIMPLE_ATTR(AlignMac68k);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001092 UNSIGNED_ATTR(Aligned);
1093 SIMPLE_ATTR(AlwaysInline);
1094 SIMPLE_ATTR(AnalyzerNoReturn);
1095 STRING_ATTR(Annotate);
1096 STRING_ATTR(AsmLabel);
Alexis Hunt54a02542009-11-25 04:20:27 +00001097 SIMPLE_ATTR(BaseCheck);
Mike Stump11289f42009-09-09 15:08:12 +00001098
Alexis Hunt344393e2010-06-16 23:43:53 +00001099 case attr::Blocks:
Chris Lattner8575daa2009-04-27 21:45:14 +00001100 New = ::new (*Context) BlocksAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001101 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
1102 break;
Mike Stump11289f42009-09-09 15:08:12 +00001103
Eli Friedmane4310c82009-11-09 18:38:53 +00001104 SIMPLE_ATTR(CDecl);
1105
Alexis Hunt344393e2010-06-16 23:43:53 +00001106 case attr::Cleanup:
Chris Lattner8575daa2009-04-27 21:45:14 +00001107 New = ::new (*Context) CleanupAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001108 cast<FunctionDecl>(GetDecl(Record[Idx++])));
1109 break;
1110
1111 SIMPLE_ATTR(Const);
1112 UNSIGNED_ATTR(Constructor);
1113 SIMPLE_ATTR(DLLExport);
1114 SIMPLE_ATTR(DLLImport);
1115 SIMPLE_ATTR(Deprecated);
1116 UNSIGNED_ATTR(Destructor);
1117 SIMPLE_ATTR(FastCall);
Alexis Hunt96d5c762009-11-21 08:43:09 +00001118 SIMPLE_ATTR(Final);
Mike Stump11289f42009-09-09 15:08:12 +00001119
Alexis Hunt344393e2010-06-16 23:43:53 +00001120 case attr::Format: {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001121 std::string Type = ReadString(Record, Idx);
1122 unsigned FormatIdx = Record[Idx++];
1123 unsigned FirstArg = Record[Idx++];
Ted Kremenek7f4945a2010-02-11 05:28:37 +00001124 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001125 break;
1126 }
Mike Stump11289f42009-09-09 15:08:12 +00001127
Alexis Hunt344393e2010-06-16 23:43:53 +00001128 case attr::FormatArg: {
Fariborz Jahanianf1c25022009-05-20 17:41:43 +00001129 unsigned FormatIdx = Record[Idx++];
1130 New = ::new (*Context) FormatArgAttr(FormatIdx);
1131 break;
1132 }
Mike Stump11289f42009-09-09 15:08:12 +00001133
Alexis Hunt344393e2010-06-16 23:43:53 +00001134 case attr::Sentinel: {
Fariborz Jahanian027b8862009-05-13 18:09:35 +00001135 int sentinel = Record[Idx++];
1136 int nullPos = Record[Idx++];
1137 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
1138 break;
1139 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001140
1141 SIMPLE_ATTR(GNUInline);
Alexis Hunt54a02542009-11-25 04:20:27 +00001142 SIMPLE_ATTR(Hiding);
Mike Stump11289f42009-09-09 15:08:12 +00001143
Alexis Hunt344393e2010-06-16 23:43:53 +00001144 case attr::IBAction:
Ted Kremenek06be9682010-02-17 02:37:45 +00001145 New = ::new (*Context) IBActionAttr();
1146 break;
1147
Alexis Hunt344393e2010-06-16 23:43:53 +00001148 case attr::IBOutlet:
Chris Lattner8575daa2009-04-27 21:45:14 +00001149 New = ::new (*Context) IBOutletAttr();
Chris Lattner8f63ab52009-04-27 06:01:06 +00001150 break;
1151
Alexis Hunt344393e2010-06-16 23:43:53 +00001152 case attr::IBOutletCollection: {
Ted Kremenek26bde772010-05-19 17:38:06 +00001153 ObjCInterfaceDecl *D =
1154 cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++]));
1155 New = ::new (*Context) IBOutletCollectionAttr(D);
1156 break;
1157 }
1158
Ryan Flynn1f1fdc02009-08-09 20:07:29 +00001159 SIMPLE_ATTR(Malloc);
Mike Stump3722f582009-08-26 22:31:08 +00001160 SIMPLE_ATTR(NoDebug);
1161 SIMPLE_ATTR(NoInline);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001162 SIMPLE_ATTR(NoReturn);
1163 SIMPLE_ATTR(NoThrow);
Mike Stump11289f42009-09-09 15:08:12 +00001164
Alexis Hunt344393e2010-06-16 23:43:53 +00001165 case attr::NonNull: {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001166 unsigned Size = Record[Idx++];
1167 llvm::SmallVector<unsigned, 16> ArgNums;
1168 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
1169 Idx += Size;
Ted Kremenek510ee252010-02-11 07:31:47 +00001170 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001171 break;
1172 }
Mike Stump11289f42009-09-09 15:08:12 +00001173
Alexis Hunt344393e2010-06-16 23:43:53 +00001174 case attr::ReqdWorkGroupSize: {
Nate Begemanf2758702009-06-26 06:32:41 +00001175 unsigned X = Record[Idx++];
1176 unsigned Y = Record[Idx++];
1177 unsigned Z = Record[Idx++];
1178 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
1179 break;
1180 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001181
1182 SIMPLE_ATTR(ObjCException);
1183 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekd9c66632010-02-18 00:05:45 +00001184 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +00001185 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenekd9c66632010-02-18 00:05:45 +00001186 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +00001187 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001188 SIMPLE_ATTR(Overloadable);
Alexis Hunt54a02542009-11-25 04:20:27 +00001189 SIMPLE_ATTR(Override);
Anders Carlsson68e0b682009-08-08 18:23:56 +00001190 SIMPLE_ATTR(Packed);
Daniel Dunbar40130442010-05-27 01:12:46 +00001191 UNSIGNED_ATTR(MaxFieldAlignment);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001192 SIMPLE_ATTR(Pure);
1193 UNSIGNED_ATTR(Regparm);
1194 STRING_ATTR(Section);
1195 SIMPLE_ATTR(StdCall);
Douglas Gregora941dca2010-05-18 16:57:00 +00001196 SIMPLE_ATTR(ThisCall);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001197 SIMPLE_ATTR(TransparentUnion);
1198 SIMPLE_ATTR(Unavailable);
1199 SIMPLE_ATTR(Unused);
1200 SIMPLE_ATTR(Used);
Mike Stump11289f42009-09-09 15:08:12 +00001201
Alexis Hunt344393e2010-06-16 23:43:53 +00001202 case attr::Visibility:
Chris Lattner8575daa2009-04-27 21:45:14 +00001203 New = ::new (*Context) VisibilityAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001204 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
1205 break;
1206
1207 SIMPLE_ATTR(WarnUnusedResult);
1208 SIMPLE_ATTR(Weak);
Rafael Espindolac18086a2010-02-23 22:00:30 +00001209 SIMPLE_ATTR(WeakRef);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001210 SIMPLE_ATTR(WeakImport);
1211 }
1212
1213 assert(New && "Unable to decode attribute?");
1214 New->setInherited(IsInherited);
1215 New->setNext(Attrs);
1216 Attrs = New;
1217 }
1218#undef UNSIGNED_ATTR
1219#undef STRING_ATTR
1220#undef SIMPLE_ATTR
1221
1222 // The list of attributes was built backwards. Reverse the list
1223 // before returning it.
1224 Attr *PrevAttr = 0, *NextAttr = 0;
1225 while (Attrs) {
1226 NextAttr = Attrs->getNext();
1227 Attrs->setNext(PrevAttr);
1228 PrevAttr = Attrs;
1229 Attrs = NextAttr;
1230 }
1231
1232 return PrevAttr;
1233}
1234
1235//===----------------------------------------------------------------------===//
1236// PCHReader Implementation
1237//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001238
1239/// \brief Note that we have loaded the declaration with the given
1240/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001241///
Chris Lattner487412d2009-04-27 05:27:42 +00001242/// This routine notes that this declaration has already been loaded,
1243/// so that future GetDecl calls will return this declaration rather
1244/// than trying to load a new declaration.
1245inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
1246 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1247 DeclsLoaded[Index] = D;
1248}
1249
1250
1251/// \brief Determine whether the consumer will be interested in seeing
1252/// this declaration (via HandleTopLevelDecl).
1253///
1254/// This routine should return true for anything that might affect
1255/// code generation, e.g., inline function definitions, Objective-C
1256/// declarations with metadata, etc.
1257static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001258 if (isa<FileScopeAsmDecl>(D))
1259 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001260 if (VarDecl *Var = dyn_cast<VarDecl>(D))
1261 return Var->isFileVarDecl() && Var->getInit();
1262 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1263 return Func->isThisDeclarationADefinition();
1264 return isa<ObjCProtocolDecl>(D);
1265}
1266
Sebastian Redl34627792010-07-20 22:46:15 +00001267/// \brief Get the correct cursor and offset for loading a type.
1268PCHReader::RecordLocation PCHReader::DeclCursorForIndex(unsigned Index) {
1269 PerFileData *F = 0;
1270 for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
1271 F = Chain[N - I - 1];
1272 if (Index < F->LocalNumDecls)
1273 break;
1274 Index -= F->LocalNumDecls;
1275 }
1276 assert(F && F->LocalNumDecls > Index && "Broken chain");
Sebastian Redlb2831db2010-07-20 22:55:31 +00001277 return RecordLocation(&F->DeclsCursor, F->DeclOffsets[Index]);
Sebastian Redl34627792010-07-20 22:46:15 +00001278}
1279
Chris Lattner487412d2009-04-27 05:27:42 +00001280/// \brief Read the declaration at the given offset from the PCH file.
Sebastian Redl34627792010-07-20 22:46:15 +00001281Decl *PCHReader::ReadDeclRecord(unsigned Index) {
1282 RecordLocation Loc = DeclCursorForIndex(Index);
Sebastian Redlb2831db2010-07-20 22:55:31 +00001283 llvm::BitstreamCursor &DeclsCursor = *Loc.first;
Chris Lattner487412d2009-04-27 05:27:42 +00001284 // Keep track of where we are in the stream, then jump back there
1285 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001286 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001287
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001288 ReadingKindTracker ReadingKind(Read_Decl, *this);
1289
Douglas Gregor1342e842009-07-06 18:54:52 +00001290 // Note that we are loading a declaration record.
1291 LoadingTypeOrDecl Loading(*this);
Mike Stump11289f42009-09-09 15:08:12 +00001292
Sebastian Redl34627792010-07-20 22:46:15 +00001293 DeclsCursor.JumpToBit(Loc.second);
Chris Lattner487412d2009-04-27 05:27:42 +00001294 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001295 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001296 unsigned Idx = 0;
1297 PCHDeclReader Reader(*this, Record, Idx);
1298
Chris Lattner1de76db2009-04-27 05:58:23 +00001299 Decl *D = 0;
1300 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner487412d2009-04-27 05:27:42 +00001301 case pch::DECL_ATTR:
1302 case pch::DECL_CONTEXT_LEXICAL:
1303 case pch::DECL_CONTEXT_VISIBLE:
1304 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1305 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001306 case pch::DECL_TRANSLATION_UNIT:
1307 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +00001308 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +00001309 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001310 case pch::DECL_TYPEDEF:
John McCall703a3f82009-10-24 08:00:42 +00001311 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001312 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001313 case pch::DECL_ENUM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001314 D = EnumDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001315 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001316 case pch::DECL_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001317 D = RecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001318 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001319 case pch::DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +00001320 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001321 0, llvm::APSInt());
1322 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001323 case pch::DECL_FUNCTION:
Mike Stump11289f42009-09-09 15:08:12 +00001324 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001325 QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001326 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001327 case pch::DECL_LINKAGE_SPEC:
1328 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
1329 (LinkageSpecDecl::LanguageIDs)0,
1330 false);
1331 break;
1332 case pch::DECL_NAMESPACE:
1333 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
1334 break;
1335 case pch::DECL_NAMESPACE_ALIAS:
1336 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
1337 SourceLocation(), 0, SourceRange(), 0,
1338 SourceLocation(), 0);
1339 break;
1340 case pch::DECL_USING:
1341 D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(),
1342 SourceLocation(), 0, DeclarationName(), false);
1343 break;
1344 case pch::DECL_USING_SHADOW:
1345 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1346 break;
1347 case pch::DECL_USING_DIRECTIVE:
1348 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
1349 SourceLocation(), SourceRange(), 0,
1350 SourceLocation(), 0, 0);
1351 break;
1352 case pch::DECL_UNRESOLVED_USING_VALUE:
1353 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
1354 SourceRange(), 0, SourceLocation(),
1355 DeclarationName());
1356 break;
1357 case pch::DECL_UNRESOLVED_USING_TYPENAME:
1358 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
1359 SourceLocation(), SourceRange(),
1360 0, SourceLocation(),
1361 DeclarationName());
1362 break;
1363 case pch::DECL_CXX_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001364 D = CXXRecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001365 break;
1366 case pch::DECL_CXX_METHOD:
1367 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
1368 QualType(), 0);
1369 break;
1370 case pch::DECL_CXX_CONSTRUCTOR:
1371 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1372 break;
1373 case pch::DECL_CXX_DESTRUCTOR:
1374 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1375 break;
1376 case pch::DECL_CXX_CONVERSION:
1377 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1378 break;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001379 case pch::DECL_ACCESS_SPEC:
1380 D = AccessSpecDecl::Create(*Context, AS_none, 0, SourceLocation(),
1381 SourceLocation());
1382 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001383 case pch::DECL_FRIEND:
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001384 D = FriendDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001385 break;
1386 case pch::DECL_FRIEND_TEMPLATE:
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001387 D = FriendTemplateDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001388 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001389 case pch::DECL_CLASS_TEMPLATE:
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +00001390 D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(),
1391 DeclarationName(), 0, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001392 break;
1393 case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001394 D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001395 break;
1396 case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001397 D = ClassTemplatePartialSpecializationDecl::Create(*Context,
1398 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001399 break;
1400 case pch::DECL_FUNCTION_TEMPLATE:
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001401 D = FunctionTemplateDecl::Create(*Context, 0, SourceLocation(),
1402 DeclarationName(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001403 break;
1404 case pch::DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001405 D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001406 break;
1407 case pch::DECL_NON_TYPE_TEMPLATE_PARM:
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001408 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0,
1409 QualType(),0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001410 break;
1411 case pch::DECL_TEMPLATE_TEMPLATE_PARM:
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001412 D = TemplateTemplateParmDecl::Create(*Context, 0, SourceLocation(),0,0,0,0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001413 break;
1414 case pch::DECL_STATIC_ASSERT:
1415 assert(false && "cannot read StaticAssertDecl");
1416 break;
1417
Chris Lattner8f63ab52009-04-27 06:01:06 +00001418 case pch::DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +00001419 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001420 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001421 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001422 case pch::DECL_OBJC_INTERFACE:
Chris Lattner8575daa2009-04-27 21:45:14 +00001423 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001424 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001425 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001426 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001427 ObjCIvarDecl::None);
1428 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001429 case pch::DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001430 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001431 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001432 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001433 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001434 QualType(), 0);
1435 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001436 case pch::DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001437 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001438 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001439 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001440 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001441 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001442 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +00001443 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1444 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001445 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001446 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001447 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001448 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001449 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +00001450 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001451 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001452 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001453 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001454 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001455 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001456 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001457 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001458 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001459 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001460 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001461 SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001462 ObjCPropertyImplDecl::Dynamic, 0);
1463 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001464 case pch::DECL_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001465 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +00001466 false);
Chris Lattner487412d2009-04-27 05:27:42 +00001467 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001468 case pch::DECL_VAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001469 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001470 VarDecl::None, VarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001471 break;
1472
1473 case pch::DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001474 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001475 break;
1476
Chris Lattner8f63ab52009-04-27 06:01:06 +00001477 case pch::DECL_PARM_VAR:
Mike Stump11289f42009-09-09 15:08:12 +00001478 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001479 VarDecl::None, VarDecl::None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001480 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001481 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001482 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001483 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001484 case pch::DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +00001485 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001486 break;
1487 }
Chris Lattner487412d2009-04-27 05:27:42 +00001488
1489 assert(D && "Unknown declaration reading PCH file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001490 LoadedDecl(Index, D);
1491 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001492
1493 // If this declaration is also a declaration context, get the
1494 // offsets for its tables of lexical and visible declarations.
1495 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1496 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1497 if (Offsets.first || Offsets.second) {
1498 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1499 DC->setHasExternalVisibleStorage(Offsets.second != 0);
Sebastian Redl5c415f32010-07-22 17:01:13 +00001500 PCHReader::DeclContextInfo Info = {
1501 Loc.first,
1502 Offsets.first,
1503 Offsets.second
1504 };
1505 DeclContextOffsets[DC].push_back(Info);
Chris Lattner487412d2009-04-27 05:27:42 +00001506 }
1507 }
1508 assert(Idx == Record.size());
1509
1510 // If we have deserialized a declaration that has a definition the
Argyrios Kyrtzidis903ccd62010-07-07 15:46:26 +00001511 // AST consumer might need to know about, queue it.
1512 // We don't pass it to the consumer immediately because we may be in recursive
1513 // loading, and some declarations may still be initializing.
1514 if (isConsumerInterestedIn(D))
1515 InterestingDecls.push_back(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001516
1517 return D;
1518}