blob: fa7382c2a025de30855a51bd1b23931f888be87e [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 Kyrtzidis2c2167a2010-07-02 11:55:32 +000042 CXXBaseSpecifier ReadCXXBaseSpecifier();
John McCall1c70e992010-06-03 19:28:45 +000043
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +000044 void Visit(Decl *D);
45
Chris Lattner487412d2009-04-27 05:27:42 +000046 void VisitDecl(Decl *D);
47 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
48 void VisitNamedDecl(NamedDecl *ND);
Douglas Gregore31bbd92010-02-21 18:22:14 +000049 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000050 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
51 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000052 void VisitTypeDecl(TypeDecl *TD);
53 void VisitTypedefDecl(TypedefDecl *TD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000054 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000055 void VisitTagDecl(TagDecl *TD);
56 void VisitEnumDecl(EnumDecl *ED);
57 void VisitRecordDecl(RecordDecl *RD);
Chris Lattnerca025db2010-05-07 21:43:38 +000058 void VisitCXXRecordDecl(CXXRecordDecl *D);
59 void VisitClassTemplateSpecializationDecl(
60 ClassTemplateSpecializationDecl *D);
61 void VisitClassTemplatePartialSpecializationDecl(
62 ClassTemplatePartialSpecializationDecl *D);
63 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000064 void VisitValueDecl(ValueDecl *VD);
65 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000066 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +000067 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +000068 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattnerca025db2010-05-07 21:43:38 +000069 void VisitCXXMethodDecl(CXXMethodDecl *D);
70 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
71 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
72 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000073 void VisitFieldDecl(FieldDecl *FD);
74 void VisitVarDecl(VarDecl *VD);
75 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
76 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattnerca025db2010-05-07 21:43:38 +000077 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
78 void VisitTemplateDecl(TemplateDecl *D);
79 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +000080 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000081 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +000082 void VisitUsingDecl(UsingDecl *D);
83 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000084 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000085 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Abramo Bagnarad7340582010-06-05 05:09:32 +000086 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000087 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000088 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
89 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000090 void VisitBlockDecl(BlockDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +000091
Chris Lattner487412d2009-04-27 05:27:42 +000092 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Chris Lattnerca025db2010-05-07 21:43:38 +000093
Alexis Hunted053252010-05-30 07:21:58 +000094 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-04-27 05:27:42 +000095 void VisitObjCMethodDecl(ObjCMethodDecl *D);
96 void VisitObjCContainerDecl(ObjCContainerDecl *D);
97 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
98 void VisitObjCIvarDecl(ObjCIvarDecl *D);
99 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
100 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
101 void VisitObjCClassDecl(ObjCClassDecl *D);
102 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
103 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
104 void VisitObjCImplDecl(ObjCImplDecl *D);
105 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
106 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
107 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
108 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
109 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
110 };
111}
112
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000113void PCHDeclReader::Visit(Decl *D) {
114 DeclVisitor<PCHDeclReader, void>::Visit(D);
115
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000116 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
117 // if we have a fully initialized TypeDecl, we can safely read its type now.
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000118 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtr());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000119 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
120 // FunctionDecl's body was written last after all other Stmts/Exprs.
121 if (Record[Idx++])
122 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
123 }
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000124}
125
Chris Lattner487412d2009-04-27 05:27:42 +0000126void PCHDeclReader::VisitDecl(Decl *D) {
127 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
128 D->setLexicalDeclContext(
129 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
130 D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
131 D->setInvalidDecl(Record[Idx++]);
132 if (Record[Idx++])
Argyrios Kyrtzidis91167172010-06-11 23:09:25 +0000133 D->initAttrs(Reader.ReadAttributes());
Chris Lattner487412d2009-04-27 05:27:42 +0000134 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +0000135 D->setUsed(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000136 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor16bef852009-10-16 20:01:17 +0000137 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner487412d2009-04-27 05:27:42 +0000138}
139
140void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
141 VisitDecl(TU);
Chris Lattnerca025db2010-05-07 21:43:38 +0000142 TU->setAnonymousNamespace(
143 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000144}
145
146void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) {
147 VisitDecl(ND);
Mike Stump11289f42009-09-09 15:08:12 +0000148 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000149}
150
151void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
152 VisitNamedDecl(TD);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000153 // Delay type reading until after we have fully initialized the decl.
154 TypeIDForTypeDecl = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000155}
156
157void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000158 VisitTypeDecl(TD);
John McCallbcd03502009-12-07 02:54:59 +0000159 TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000160}
161
162void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
163 VisitTypeDecl(TD);
Douglas Gregorb6b8f9e2009-07-29 23:36:44 +0000164 TD->setPreviousDeclaration(
165 cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000166 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
167 TD->setDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000168 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis664b6902009-07-14 03:18:02 +0000169 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000170 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall3e11ebe2010-03-15 10:12:16 +0000171 // FIXME: maybe read optional qualifier and its range.
172 TD->setTypedefForAnonDecl(
173 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000174}
175
176void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
177 VisitTagDecl(ED);
178 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall56774992009-12-09 09:09:27 +0000179 ED->setPromotionType(Reader.GetType(Record[Idx++]));
John McCall9aa35be2010-05-06 08:49:23 +0000180 ED->setNumPositiveBits(Record[Idx++]);
181 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor7a749382009-05-27 17:20:35 +0000182 // FIXME: C++ InstantiatedFrom
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 Kyrtzidis69da4a82010-06-22 09:55:07 +0000215 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000216 default: assert(false && "Unhandled TemplatedKind!");
217 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000218 case FunctionDecl::TK_NonTemplate:
219 break;
220 case FunctionDecl::TK_FunctionTemplate:
221 FD->setDescribedFunctionTemplate(
222 cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++])));
223 break;
224 case FunctionDecl::TK_MemberSpecialization: {
225 FunctionDecl *InstFD = cast<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
226 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
227 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
228 FD->setInstantiationOfMemberFunction(InstFD, TSK);
229 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
230 break;
231 }
232 case FunctionDecl::TK_FunctionTemplateSpecialization: {
233 FunctionTemplateDecl *Template
234 = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
235 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
236
237 // Template arguments.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000238 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000239 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000240
241 // Template args as written.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000242 llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000243 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000244 if (Record[Idx++]) { // TemplateArgumentsAsWritten != 0
245 unsigned NumTemplateArgLocs = Record[Idx++];
246 TemplArgLocs.reserve(NumTemplateArgLocs);
247 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
248 TemplArgLocs.push_back(Reader.ReadTemplateArgumentLoc(Record, Idx));
249
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000250 LAngleLoc = Reader.ReadSourceLocation(Record, Idx);
251 RAngleLoc = Reader.ReadSourceLocation(Record, Idx);
252 }
253
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000254 FD->setFunctionTemplateSpecialization(Template, TemplArgs.size(),
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000255 TemplArgs.data(), TSK,
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000256 TemplArgLocs.size(),
257 TemplArgLocs.data(),
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000258 LAngleLoc, RAngleLoc);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000259 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000260 }
261 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
262 // Templates.
263 UnresolvedSet<8> TemplDecls;
264 unsigned NumTemplates = Record[Idx++];
265 while (NumTemplates--)
266 TemplDecls.addDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
267
268 // Templates args.
269 TemplateArgumentListInfo TemplArgs;
270 unsigned NumArgs = Record[Idx++];
271 while (NumArgs--)
272 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
273
274 FD->setDependentTemplateSpecialization(*Reader.getContext(),
275 TemplDecls, TemplArgs);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000276 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000277 }
278 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000279
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000280 // FunctionDecl's body is handled last at PCHReaderDecl::Visit,
281 // after everything else is read.
282
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000283 FD->setPreviousDeclaration(
284 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
285 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
286 FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]);
287 FD->setInlineSpecified(Record[Idx++]);
288 FD->setVirtualAsWritten(Record[Idx++]);
289 FD->setPure(Record[Idx++]);
290 FD->setHasInheritedPrototype(Record[Idx++]);
291 FD->setHasWrittenPrototype(Record[Idx++]);
292 FD->setDeleted(Record[Idx++]);
293 FD->setTrivial(Record[Idx++]);
294 FD->setCopyAssignment(Record[Idx++]);
295 FD->setHasImplicitReturnZero(Record[Idx++]);
296 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
297
Chris Lattnerca025db2010-05-07 21:43:38 +0000298 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000299 unsigned NumParams = Record[Idx++];
300 llvm::SmallVector<ParmVarDecl *, 16> Params;
301 Params.reserve(NumParams);
302 for (unsigned I = 0; I != NumParams; ++I)
303 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000304 FD->setParams(Params.data(), NumParams);
John McCallb9467b62010-04-24 01:30:58 +0000305
306 // FIXME: order this properly w.r.t. friendness
307 // FIXME: this same thing needs to happen for function templates
308 if (FD->isOverloadedOperator() && !FD->getDeclContext()->isRecord())
309 FD->setNonMemberOperator();
Chris Lattner487412d2009-04-27 05:27:42 +0000310}
311
312void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
313 VisitNamedDecl(MD);
314 if (Record[Idx++]) {
315 // In practice, this won't be executed (since method definitions
316 // don't occur in header files).
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000317 MD->setBody(Reader.ReadStmt());
Chris Lattner487412d2009-04-27 05:27:42 +0000318 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
319 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
320 }
321 MD->setInstanceMethod(Record[Idx++]);
322 MD->setVariadic(Record[Idx++]);
323 MD->setSynthesized(Record[Idx++]);
324 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
325 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahaniand9235db2010-04-08 21:29:11 +0000326 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000327 MD->setResultType(Reader.GetType(Record[Idx++]));
Douglas Gregor12852d92010-03-08 14:59:44 +0000328 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000329 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
330 unsigned NumParams = Record[Idx++];
331 llvm::SmallVector<ParmVarDecl *, 16> Params;
332 Params.reserve(NumParams);
333 for (unsigned I = 0; I != NumParams; ++I)
334 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniancdabb312010-04-09 15:40:42 +0000335 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
336 NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000337}
338
339void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
340 VisitNamedDecl(CD);
Ted Kremenekc7c64312010-01-07 01:20:12 +0000341 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
342 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
343 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner487412d2009-04-27 05:27:42 +0000344}
345
346void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
347 VisitObjCContainerDecl(ID);
348 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
349 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
350 (Reader.GetDecl(Record[Idx++])));
351 unsigned NumProtocols = Record[Idx++];
352 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
353 Protocols.reserve(NumProtocols);
354 for (unsigned I = 0; I != NumProtocols; ++I)
355 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000356 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
357 ProtoLocs.reserve(NumProtocols);
358 for (unsigned I = 0; I != NumProtocols; ++I)
359 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
360 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
361 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000362 unsigned NumIvars = Record[Idx++];
363 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
364 IVars.reserve(NumIvars);
365 for (unsigned I = 0; I != NumIvars; ++I)
366 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000367 ID->setCategoryList(
368 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
369 ID->setForwardDecl(Record[Idx++]);
370 ID->setImplicitInterfaceDecl(Record[Idx++]);
371 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
372 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisea72f422009-07-18 00:33:23 +0000373 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000374}
375
376void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
377 VisitFieldDecl(IVD);
378 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
379}
380
381void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
382 VisitObjCContainerDecl(PD);
383 PD->setForwardDecl(Record[Idx++]);
384 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
385 unsigned NumProtoRefs = Record[Idx++];
386 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
387 ProtoRefs.reserve(NumProtoRefs);
388 for (unsigned I = 0; I != NumProtoRefs; ++I)
389 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000390 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
391 ProtoLocs.reserve(NumProtoRefs);
392 for (unsigned I = 0; I != NumProtoRefs; ++I)
393 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
394 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
395 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000396}
397
398void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
399 VisitFieldDecl(FD);
400}
401
402void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
403 VisitDecl(CD);
404 unsigned NumClassRefs = Record[Idx++];
405 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
406 ClassRefs.reserve(NumClassRefs);
407 for (unsigned I = 0; I != NumClassRefs; ++I)
408 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000409 llvm::SmallVector<SourceLocation, 16> SLocs;
410 SLocs.reserve(NumClassRefs);
411 for (unsigned I = 0; I != NumClassRefs; ++I)
412 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
413 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
414 NumClassRefs);
Chris Lattner487412d2009-04-27 05:27:42 +0000415}
416
417void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
418 VisitDecl(FPD);
419 unsigned NumProtoRefs = Record[Idx++];
420 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
421 ProtoRefs.reserve(NumProtoRefs);
422 for (unsigned I = 0; I != NumProtoRefs; ++I)
423 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000424 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
425 ProtoLocs.reserve(NumProtoRefs);
426 for (unsigned I = 0; I != NumProtoRefs; ++I)
427 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
428 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
429 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000430}
431
432void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
433 VisitObjCContainerDecl(CD);
434 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
435 unsigned NumProtoRefs = Record[Idx++];
436 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
437 ProtoRefs.reserve(NumProtoRefs);
438 for (unsigned I = 0; I != NumProtoRefs; ++I)
439 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000440 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
441 ProtoLocs.reserve(NumProtoRefs);
442 for (unsigned I = 0; I != NumProtoRefs; ++I)
443 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
444 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
445 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000446 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor071676f2010-01-16 16:38:58 +0000447 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
448 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000449}
450
451void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
452 VisitNamedDecl(CAD);
453 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
454}
455
456void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
457 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000458 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall339bb662010-06-04 20:50:08 +0000459 D->setType(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000460 // FIXME: stable encoding
461 D->setPropertyAttributes(
462 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000463 D->setPropertyAttributesAsWritten(
464 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000465 // FIXME: stable encoding
466 D->setPropertyImplementation(
467 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
468 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
469 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
470 D->setGetterMethodDecl(
471 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
472 D->setSetterMethodDecl(
473 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
474 D->setPropertyIvarDecl(
475 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
476}
477
478void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000479 VisitObjCContainerDecl(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000480 D->setClassInterface(
481 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000482}
483
484void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
485 VisitObjCImplDecl(D);
486 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
487}
488
489void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
490 VisitObjCImplDecl(D);
491 D->setSuperClass(
492 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanianc83726e2010-04-28 16:11:27 +0000493 // FIXME. Add reading of IvarInitializers and NumIvarInitializers.
Chris Lattner487412d2009-04-27 05:27:42 +0000494}
495
496
497void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
498 VisitDecl(D);
499 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
500 D->setPropertyDecl(
501 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
502 D->setPropertyIvarDecl(
503 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanian25491a22010-05-05 21:52:17 +0000504 // FIXME. read GetterCXXConstructor and SetterCXXAssignment
Chris Lattner487412d2009-04-27 05:27:42 +0000505}
506
507void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000508 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000509 FD->setMutable(Record[Idx++]);
510 if (Record[Idx++])
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000511 FD->setBitWidth(Reader.ReadExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000512}
513
514void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000515 VisitDeclaratorDecl(VD);
Chris Lattner487412d2009-04-27 05:27:42 +0000516 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
Douglas Gregorc4df4072010-04-19 22:54:31 +0000517 VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000518 VD->setThreadSpecified(Record[Idx++]);
519 VD->setCXXDirectInitializer(Record[Idx++]);
520 VD->setDeclaredInCondition(Record[Idx++]);
Douglas Gregor3f324d562010-05-03 18:51:14 +0000521 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor6fd1b182010-05-15 06:01:05 +0000522 VD->setNRVOVariable(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000523 VD->setPreviousDeclaration(
524 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000525 if (Record[Idx++])
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000526 VD->setInit(Reader.ReadExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000527}
528
529void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
530 VisitVarDecl(PD);
531}
532
533void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
534 VisitVarDecl(PD);
535 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallf3cd6652010-03-12 18:31:32 +0000536 PD->setHasInheritedDefaultArg(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000537}
538
Chris Lattner487412d2009-04-27 05:27:42 +0000539void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
540 VisitDecl(AD);
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000541 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr()));
Chris Lattner487412d2009-04-27 05:27:42 +0000542}
543
544void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
545 VisitDecl(BD);
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000546 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt()));
John McCalla3ccba02010-06-04 11:21:44 +0000547 BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000548 unsigned NumParams = Record[Idx++];
549 llvm::SmallVector<ParmVarDecl *, 16> Params;
550 Params.reserve(NumParams);
551 for (unsigned I = 0; I != NumParams; ++I)
552 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000553 BD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000554}
555
Chris Lattnerca025db2010-05-07 21:43:38 +0000556void PCHDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
557 VisitDecl(D);
558 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
559 D->setHasBraces(Record[Idx++]);
560}
561
562void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
563 VisitNamedDecl(D);
564 D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx));
565 D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx));
566 D->setNextNamespace(
567 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
568
569 // Only read one reference--the original or anonymous namespace.
570 bool IsOriginal = Record[Idx++];
571 if (IsOriginal)
572 D->setAnonymousNamespace(
573 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
574 else
575 D->setOriginalNamespace(
576 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
577}
578
579void PCHDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
580 VisitNamedDecl(D);
581
582 D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx));
583 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
584 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
585 D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx));
586 D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
587}
588
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000589void PCHDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000590 VisitNamedDecl(D);
591 D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
592 D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
593 D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
594
595 // FIXME: It would probably be more efficient to read these into a vector
596 // and then re-cosntruct the shadow decl set over that vector since it
597 // would avoid existence checks.
598 unsigned NumShadows = Record[Idx++];
599 for(unsigned I = 0; I != NumShadows; ++I) {
600 D->addShadowDecl(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])));
601 }
602 D->setTypeName(Record[Idx++]);
603}
604
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000605void PCHDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000606 VisitNamedDecl(D);
607 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
608 D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
609}
610
611void PCHDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
612 VisitNamedDecl(D);
613 D->setNamespaceKeyLocation(Reader.ReadSourceLocation(Record, Idx));
614 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
615 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
616 D->setIdentLocation(Reader.ReadSourceLocation(Record, Idx));
617 D->setNominatedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
618 D->setCommonAncestor(cast_or_null<DeclContext>(
619 Reader.GetDecl(Record[Idx++])));
620}
621
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000622void PCHDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000623 VisitValueDecl(D);
624 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
625 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
626 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
627}
628
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000629void PCHDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000630 UnresolvedUsingTypenameDecl *D) {
631 VisitTypeDecl(D);
632 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
633 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
634 D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx));
635 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
636}
637
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000638CXXBaseSpecifier PCHDeclReader::ReadCXXBaseSpecifier() {
John McCall1c70e992010-06-03 19:28:45 +0000639 bool isVirtual = static_cast<bool>(Record[Idx++]);
640 bool isBaseOfClass = static_cast<bool>(Record[Idx++]);
641 AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]);
642 QualType T = Reader.GetType(Record[Idx++]);
643 SourceRange Range = Reader.ReadSourceRange(Record, Idx);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000644 return CXXBaseSpecifier(Range, isVirtual, isBaseOfClass, AS, T);
John McCall1c70e992010-06-03 19:28:45 +0000645}
646
Chris Lattnerca025db2010-05-07 21:43:38 +0000647void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000648 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000649
650 ASTContext &C = *Reader.getContext();
651
652 if (D->isFirstDeclaration()) {
653 if (Record[Idx++]) { // DefinitionData != 0
654 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(0);
655 struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData;
656
657 Data.UserDeclaredConstructor = Record[Idx++];
658 Data.UserDeclaredCopyConstructor = Record[Idx++];
659 Data.UserDeclaredCopyAssignment = Record[Idx++];
660 Data.UserDeclaredDestructor = Record[Idx++];
661 Data.Aggregate = Record[Idx++];
662 Data.PlainOldData = Record[Idx++];
663 Data.Empty = Record[Idx++];
664 Data.Polymorphic = Record[Idx++];
665 Data.Abstract = Record[Idx++];
666 Data.HasTrivialConstructor = Record[Idx++];
667 Data.HasTrivialCopyConstructor = Record[Idx++];
668 Data.HasTrivialCopyAssignment = Record[Idx++];
669 Data.HasTrivialDestructor = Record[Idx++];
670 Data.ComputedVisibleConversions = Record[Idx++];
Douglas Gregor330b9cf2010-07-02 21:50:04 +0000671 Data.DeclaredCopyAssignment = Record[Idx++];
Douglas Gregor7454c562010-07-02 20:37:36 +0000672 Data.DeclaredDestructor = Record[Idx++];
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000673
674 // setBases() is unsuitable since it may try to iterate the bases of an
675 // unitialized base.
676 Data.NumBases = Record[Idx++];
677 Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases];
678 for (unsigned i = 0; i != Data.NumBases; ++i)
679 Data.Bases[i] = ReadCXXBaseSpecifier();
680
681 // FIXME: Make VBases lazily computed when needed to avoid storing them.
682 Data.NumVBases = Record[Idx++];
683 Data.VBases = new(C) CXXBaseSpecifier [Data.NumVBases];
684 for (unsigned i = 0; i != Data.NumVBases; ++i)
685 Data.VBases[i] = ReadCXXBaseSpecifier();
686
687 Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx);
688 Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx);
689 Data.Definition = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
690 Data.FirstFriend
691 = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
692 }
693 } else {
694 D->DefinitionData = D->getPreviousDeclaration()->DefinitionData;
695 }
696
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000697 enum CXXRecKind {
698 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
699 };
700 switch ((CXXRecKind)Record[Idx++]) {
701 default:
702 assert(false && "Out of sync with PCHDeclWriter::VisitCXXRecordDecl?");
703 case CXXRecNotTemplate:
704 break;
705 case CXXRecTemplate:
706 D->setDescribedClassTemplate(
707 cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++])));
708 break;
709 case CXXRecMemberSpecialization: {
710 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
711 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
712 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
713 D->setInstantiationOfMemberClass(RD, TSK);
714 D->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
715 break;
716 }
717 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000718}
719
720void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000721 VisitFunctionDecl(D);
722}
723
724void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000725 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000726
727 D->IsExplicitSpecified = Record[Idx++];
728 D->ImplicitlyDefined = Record[Idx++];
729
730 unsigned NumInitializers = Record[Idx++];
731 D->NumBaseOrMemberInitializers = NumInitializers;
732 if (NumInitializers) {
733 ASTContext &C = *Reader.getContext();
734
735 D->BaseOrMemberInitializers
736 = new (C) CXXBaseOrMemberInitializer*[NumInitializers];
737 for (unsigned i=0; i != NumInitializers; ++i) {
738 TypeSourceInfo *BaseClassInfo;
739 bool IsBaseVirtual;
740 FieldDecl *Member;
741
742 bool IsBaseInitializer = Record[Idx++];
743 if (IsBaseInitializer) {
744 BaseClassInfo = Reader.GetTypeSourceInfo(Record, Idx);
745 IsBaseVirtual = Record[Idx++];
746 } else {
747 Member = cast<FieldDecl>(Reader.GetDecl(Record[Idx++]));
748 }
749 SourceLocation MemberLoc = Reader.ReadSourceLocation(Record, Idx);
750 Expr *Init = Reader.ReadExpr();
751 FieldDecl *AnonUnionMember
752 = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
753 SourceLocation LParenLoc = Reader.ReadSourceLocation(Record, Idx);
754 SourceLocation RParenLoc = Reader.ReadSourceLocation(Record, Idx);
755 bool IsWritten = Record[Idx++];
756 unsigned SourceOrderOrNumArrayIndices;
757 llvm::SmallVector<VarDecl *, 8> Indices;
758 if (IsWritten) {
759 SourceOrderOrNumArrayIndices = Record[Idx++];
760 } else {
761 SourceOrderOrNumArrayIndices = Record[Idx++];
762 Indices.reserve(SourceOrderOrNumArrayIndices);
763 for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i)
764 Indices.push_back(cast<VarDecl>(Reader.GetDecl(Record[Idx++])));
765 }
766
767 CXXBaseOrMemberInitializer *BOMInit;
768 if (IsBaseInitializer) {
769 BOMInit = new (C) CXXBaseOrMemberInitializer(C, BaseClassInfo,
770 IsBaseVirtual, LParenLoc,
771 Init, RParenLoc);
772 } else if (IsWritten) {
773 BOMInit = new (C) CXXBaseOrMemberInitializer(C, Member, MemberLoc,
774 LParenLoc, Init, RParenLoc);
775 } else {
776 BOMInit = CXXBaseOrMemberInitializer::Create(C, Member, MemberLoc,
777 LParenLoc, Init, RParenLoc,
778 Indices.data(),
779 Indices.size());
780 }
781
782 BOMInit->setAnonUnionMember(AnonUnionMember);
783 D->BaseOrMemberInitializers[i] = BOMInit;
784 }
785 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000786}
787
788void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000789 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000790
791 D->ImplicitlyDefined = Record[Idx++];
792 D->OperatorDelete = cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000793}
794
795void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000796 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000797 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000798}
799
Abramo Bagnarad7340582010-06-05 05:09:32 +0000800void PCHDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
801 VisitDecl(D);
802 D->setColonLoc(Reader.ReadSourceLocation(Record, Idx));
803}
804
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000805void PCHDeclReader::VisitFriendDecl(FriendDecl *D) {
806 if (Record[Idx++])
807 D->Friend = Reader.GetTypeSourceInfo(Record, Idx);
808 else
809 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
810 D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
811 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
812}
813
Chris Lattnerca025db2010-05-07 21:43:38 +0000814void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
815 assert(false && "cannot read FriendTemplateDecl");
816}
817
818void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000819 VisitNamedDecl(D);
820
821 NamedDecl *TemplatedDecl = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000822 TemplateParameterList* TemplateParams
823 = Reader.ReadTemplateParameterList(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000824 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +0000825}
826
827void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000828 VisitTemplateDecl(D);
829
830 ClassTemplateDecl *PrevDecl =
831 cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +0000832 D->setPreviousDeclaration(PrevDecl);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000833 if (PrevDecl == 0) {
834 // This ClassTemplateDecl owns a CommonPtr; read it.
835
836 unsigned size = Record[Idx++];
837 while (size--) {
838 ClassTemplateSpecializationDecl *CTSD
839 = cast<ClassTemplateSpecializationDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidise23371e2010-07-02 11:55:37 +0000840 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
841 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000842 llvm::FoldingSetNodeID ID;
843 void *InsertPos = 0;
Argyrios Kyrtzidise23371e2010-07-02 11:55:37 +0000844 ClassTemplateSpecializationDecl::Profile(ID, TemplArgs.data(),
845 TemplArgs.size(),
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000846 *Reader.getContext());
847 D->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
848 D->getSpecializations().InsertNode(CTSD, InsertPos);
849 }
850
851 size = Record[Idx++];
852 while (size--) {
853 ClassTemplatePartialSpecializationDecl *CTSD
854 = cast<ClassTemplatePartialSpecializationDecl>(
855 Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidise23371e2010-07-02 11:55:37 +0000856 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
857 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000858 llvm::FoldingSetNodeID ID;
859 void *InsertPos = 0;
Argyrios Kyrtzidise23371e2010-07-02 11:55:37 +0000860 ClassTemplatePartialSpecializationDecl::Profile(ID, TemplArgs.data(),
861 TemplArgs.size(),
862 *Reader.getContext());
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000863 D->getPartialSpecializations().FindNodeOrInsertPos(ID, InsertPos);
864 D->getPartialSpecializations().InsertNode(CTSD, InsertPos);
865 }
866
867 // InjectedClassNameType is computed.
868
869 if (ClassTemplateDecl *CTD
870 = cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
871 D->setInstantiatedFromMemberTemplate(CTD);
872 if (Record[Idx++])
873 D->setMemberSpecialization();
874 }
875 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000876}
877
878void PCHDeclReader::VisitClassTemplateSpecializationDecl(
879 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000880 VisitCXXRecordDecl(D);
881
882 if (Decl *InstD = Reader.GetDecl(Record[Idx++])) {
883 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
884 D->setInstantiationOf(CTD);
885 } else {
886 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
887 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
888 D->setInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(InstD),
889 TemplArgs.data(), TemplArgs.size());
890 }
891 }
892
893 // Explicit info.
894 if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Record, Idx)) {
895 D->setTypeAsWritten(TyInfo);
896 D->setExternLoc(Reader.ReadSourceLocation(Record, Idx));
897 D->setTemplateKeywordLoc(Reader.ReadSourceLocation(Record, Idx));
898 }
899
900 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
901 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
902 D->initTemplateArgs(TemplArgs.data(), TemplArgs.size());
903 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
904 if (POI.isValid())
905 D->setPointOfInstantiation(POI);
906 D->setSpecializationKind((TemplateSpecializationKind)Record[Idx++]);
Chris Lattnerca025db2010-05-07 21:43:38 +0000907}
908
909void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl(
910 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000911 VisitClassTemplateSpecializationDecl(D);
912
913 D->initTemplateParameters(Reader.ReadTemplateParameterList(Record, Idx));
914
915 TemplateArgumentListInfo ArgInfos;
916 unsigned NumArgs = Record[Idx++];
917 while (NumArgs--)
918 ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
919 D->initTemplateArgsAsWritten(ArgInfos);
920
921 D->setSequenceNumber(Record[Idx++]);
922
923 // These are read/set from/to the first declaration.
924 if (D->getPreviousDeclaration() == 0) {
925 D->setInstantiatedFromMember(
926 cast_or_null<ClassTemplatePartialSpecializationDecl>(
927 Reader.GetDecl(Record[Idx++])));
928 if (Record[Idx++])
929 D->isMemberSpecialization();
930 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000931}
932
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000933void PCHDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
934 VisitTemplateDecl(D);
935
936 FunctionTemplateDecl *PrevDecl =
937 cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
938 D->setPreviousDeclaration(PrevDecl);
939 if (PrevDecl == 0) {
940 // This FunctionTemplateDecl owns a CommonPtr; read it.
941
942 // FunctionTemplateSpecializationInfos are filled through the
943 // templated FunctionDecl's setFunctionTemplateSpecialization, no need to
944 // read them here.
945
946 if (FunctionTemplateDecl *CTD
947 = cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
948 D->setInstantiatedFromMemberTemplate(CTD);
949 if (Record[Idx++])
950 D->setMemberSpecialization();
951 }
952 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000953}
954
955void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000956 VisitTypeDecl(D);
957
958 D->setDeclaredWithTypename(Record[Idx++]);
959 D->setParameterPack(Record[Idx++]);
960
961 bool Inherited = Record[Idx++];
962 TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Record, Idx);
963 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +0000964}
965
966void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +0000967 VisitVarDecl(D);
968 // TemplateParmPosition.
969 D->setDepth(Record[Idx++]);
970 D->setPosition(Record[Idx++]);
971 // Rest of NonTypeTemplateParmDecl.
972 if (Record[Idx++]) {
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000973 Expr *DefArg = Reader.ReadExpr();
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +0000974 bool Inherited = Record[Idx++];
975 D->setDefaultArgument(DefArg, Inherited);
976 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000977}
978
979void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
980 assert(false && "cannot read TemplateTemplateParmDecl");
981}
982
983void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
984 assert(false && "cannot read StaticAssertDecl");
985}
986
Mike Stump11289f42009-09-09 15:08:12 +0000987std::pair<uint64_t, uint64_t>
Chris Lattner487412d2009-04-27 05:27:42 +0000988PCHDeclReader::VisitDeclContext(DeclContext *DC) {
989 uint64_t LexicalOffset = Record[Idx++];
990 uint64_t VisibleOffset = Record[Idx++];
991 return std::make_pair(LexicalOffset, VisibleOffset);
992}
993
994//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +0000995// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +0000996//===----------------------------------------------------------------------===//
997
Chris Lattner8f63ab52009-04-27 06:01:06 +0000998/// \brief Reads attributes from the current stream position.
999Attr *PCHReader::ReadAttributes() {
1000 unsigned Code = DeclsCursor.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +00001001 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner8f63ab52009-04-27 06:01:06 +00001002 "Expected unabbreviated record"); (void)Code;
Mike Stump11289f42009-09-09 15:08:12 +00001003
Chris Lattner8f63ab52009-04-27 06:01:06 +00001004 RecordData Record;
1005 unsigned Idx = 0;
1006 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump11289f42009-09-09 15:08:12 +00001007 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001008 (void)RecCode;
1009
1010#define SIMPLE_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001011 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +00001012 New = ::new (*Context) Name##Attr(); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001013 break
1014
1015#define STRING_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001016 case attr::Name: \
Ted Kremenek7f4945a2010-02-11 05:28:37 +00001017 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001018 break
1019
1020#define UNSIGNED_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001021 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +00001022 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001023 break
1024
1025 Attr *Attrs = 0;
1026 while (Idx < Record.size()) {
1027 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001028 attr::Kind Kind = (attr::Kind)Record[Idx++];
Chris Lattner8f63ab52009-04-27 06:01:06 +00001029 bool IsInherited = Record[Idx++];
1030
1031 switch (Kind) {
Anton Korobeynikov55bcea12010-01-10 12:58:08 +00001032 default:
1033 assert(0 && "Unknown attribute!");
1034 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001035 STRING_ATTR(Alias);
Daniel Dunbarfc6507e2010-05-27 02:25:39 +00001036 SIMPLE_ATTR(AlignMac68k);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001037 UNSIGNED_ATTR(Aligned);
1038 SIMPLE_ATTR(AlwaysInline);
1039 SIMPLE_ATTR(AnalyzerNoReturn);
1040 STRING_ATTR(Annotate);
1041 STRING_ATTR(AsmLabel);
Alexis Hunt54a02542009-11-25 04:20:27 +00001042 SIMPLE_ATTR(BaseCheck);
Mike Stump11289f42009-09-09 15:08:12 +00001043
Alexis Hunt344393e2010-06-16 23:43:53 +00001044 case attr::Blocks:
Chris Lattner8575daa2009-04-27 21:45:14 +00001045 New = ::new (*Context) BlocksAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001046 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
1047 break;
Mike Stump11289f42009-09-09 15:08:12 +00001048
Eli Friedmane4310c82009-11-09 18:38:53 +00001049 SIMPLE_ATTR(CDecl);
1050
Alexis Hunt344393e2010-06-16 23:43:53 +00001051 case attr::Cleanup:
Chris Lattner8575daa2009-04-27 21:45:14 +00001052 New = ::new (*Context) CleanupAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001053 cast<FunctionDecl>(GetDecl(Record[Idx++])));
1054 break;
1055
1056 SIMPLE_ATTR(Const);
1057 UNSIGNED_ATTR(Constructor);
1058 SIMPLE_ATTR(DLLExport);
1059 SIMPLE_ATTR(DLLImport);
1060 SIMPLE_ATTR(Deprecated);
1061 UNSIGNED_ATTR(Destructor);
1062 SIMPLE_ATTR(FastCall);
Alexis Hunt96d5c762009-11-21 08:43:09 +00001063 SIMPLE_ATTR(Final);
Mike Stump11289f42009-09-09 15:08:12 +00001064
Alexis Hunt344393e2010-06-16 23:43:53 +00001065 case attr::Format: {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001066 std::string Type = ReadString(Record, Idx);
1067 unsigned FormatIdx = Record[Idx++];
1068 unsigned FirstArg = Record[Idx++];
Ted Kremenek7f4945a2010-02-11 05:28:37 +00001069 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001070 break;
1071 }
Mike Stump11289f42009-09-09 15:08:12 +00001072
Alexis Hunt344393e2010-06-16 23:43:53 +00001073 case attr::FormatArg: {
Fariborz Jahanianf1c25022009-05-20 17:41:43 +00001074 unsigned FormatIdx = Record[Idx++];
1075 New = ::new (*Context) FormatArgAttr(FormatIdx);
1076 break;
1077 }
Mike Stump11289f42009-09-09 15:08:12 +00001078
Alexis Hunt344393e2010-06-16 23:43:53 +00001079 case attr::Sentinel: {
Fariborz Jahanian027b8862009-05-13 18:09:35 +00001080 int sentinel = Record[Idx++];
1081 int nullPos = Record[Idx++];
1082 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
1083 break;
1084 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001085
1086 SIMPLE_ATTR(GNUInline);
Alexis Hunt54a02542009-11-25 04:20:27 +00001087 SIMPLE_ATTR(Hiding);
Mike Stump11289f42009-09-09 15:08:12 +00001088
Alexis Hunt344393e2010-06-16 23:43:53 +00001089 case attr::IBAction:
Ted Kremenek06be9682010-02-17 02:37:45 +00001090 New = ::new (*Context) IBActionAttr();
1091 break;
1092
Alexis Hunt344393e2010-06-16 23:43:53 +00001093 case attr::IBOutlet:
Chris Lattner8575daa2009-04-27 21:45:14 +00001094 New = ::new (*Context) IBOutletAttr();
Chris Lattner8f63ab52009-04-27 06:01:06 +00001095 break;
1096
Alexis Hunt344393e2010-06-16 23:43:53 +00001097 case attr::IBOutletCollection: {
Ted Kremenek26bde772010-05-19 17:38:06 +00001098 ObjCInterfaceDecl *D =
1099 cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++]));
1100 New = ::new (*Context) IBOutletCollectionAttr(D);
1101 break;
1102 }
1103
Ryan Flynn1f1fdc02009-08-09 20:07:29 +00001104 SIMPLE_ATTR(Malloc);
Mike Stump3722f582009-08-26 22:31:08 +00001105 SIMPLE_ATTR(NoDebug);
1106 SIMPLE_ATTR(NoInline);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001107 SIMPLE_ATTR(NoReturn);
1108 SIMPLE_ATTR(NoThrow);
Mike Stump11289f42009-09-09 15:08:12 +00001109
Alexis Hunt344393e2010-06-16 23:43:53 +00001110 case attr::NonNull: {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001111 unsigned Size = Record[Idx++];
1112 llvm::SmallVector<unsigned, 16> ArgNums;
1113 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
1114 Idx += Size;
Ted Kremenek510ee252010-02-11 07:31:47 +00001115 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001116 break;
1117 }
Mike Stump11289f42009-09-09 15:08:12 +00001118
Alexis Hunt344393e2010-06-16 23:43:53 +00001119 case attr::ReqdWorkGroupSize: {
Nate Begemanf2758702009-06-26 06:32:41 +00001120 unsigned X = Record[Idx++];
1121 unsigned Y = Record[Idx++];
1122 unsigned Z = Record[Idx++];
1123 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
1124 break;
1125 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001126
1127 SIMPLE_ATTR(ObjCException);
1128 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekd9c66632010-02-18 00:05:45 +00001129 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +00001130 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenekd9c66632010-02-18 00:05:45 +00001131 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +00001132 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001133 SIMPLE_ATTR(Overloadable);
Alexis Hunt54a02542009-11-25 04:20:27 +00001134 SIMPLE_ATTR(Override);
Anders Carlsson68e0b682009-08-08 18:23:56 +00001135 SIMPLE_ATTR(Packed);
Daniel Dunbar40130442010-05-27 01:12:46 +00001136 UNSIGNED_ATTR(MaxFieldAlignment);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001137 SIMPLE_ATTR(Pure);
1138 UNSIGNED_ATTR(Regparm);
1139 STRING_ATTR(Section);
1140 SIMPLE_ATTR(StdCall);
Douglas Gregora941dca2010-05-18 16:57:00 +00001141 SIMPLE_ATTR(ThisCall);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001142 SIMPLE_ATTR(TransparentUnion);
1143 SIMPLE_ATTR(Unavailable);
1144 SIMPLE_ATTR(Unused);
1145 SIMPLE_ATTR(Used);
Mike Stump11289f42009-09-09 15:08:12 +00001146
Alexis Hunt344393e2010-06-16 23:43:53 +00001147 case attr::Visibility:
Chris Lattner8575daa2009-04-27 21:45:14 +00001148 New = ::new (*Context) VisibilityAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001149 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
1150 break;
1151
1152 SIMPLE_ATTR(WarnUnusedResult);
1153 SIMPLE_ATTR(Weak);
Rafael Espindolac18086a2010-02-23 22:00:30 +00001154 SIMPLE_ATTR(WeakRef);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001155 SIMPLE_ATTR(WeakImport);
1156 }
1157
1158 assert(New && "Unable to decode attribute?");
1159 New->setInherited(IsInherited);
1160 New->setNext(Attrs);
1161 Attrs = New;
1162 }
1163#undef UNSIGNED_ATTR
1164#undef STRING_ATTR
1165#undef SIMPLE_ATTR
1166
1167 // The list of attributes was built backwards. Reverse the list
1168 // before returning it.
1169 Attr *PrevAttr = 0, *NextAttr = 0;
1170 while (Attrs) {
1171 NextAttr = Attrs->getNext();
1172 Attrs->setNext(PrevAttr);
1173 PrevAttr = Attrs;
1174 Attrs = NextAttr;
1175 }
1176
1177 return PrevAttr;
1178}
1179
1180//===----------------------------------------------------------------------===//
1181// PCHReader Implementation
1182//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001183
1184/// \brief Note that we have loaded the declaration with the given
1185/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001186///
Chris Lattner487412d2009-04-27 05:27:42 +00001187/// This routine notes that this declaration has already been loaded,
1188/// so that future GetDecl calls will return this declaration rather
1189/// than trying to load a new declaration.
1190inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
1191 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1192 DeclsLoaded[Index] = D;
1193}
1194
1195
1196/// \brief Determine whether the consumer will be interested in seeing
1197/// this declaration (via HandleTopLevelDecl).
1198///
1199/// This routine should return true for anything that might affect
1200/// code generation, e.g., inline function definitions, Objective-C
1201/// declarations with metadata, etc.
1202static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001203 if (isa<FileScopeAsmDecl>(D))
1204 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001205 if (VarDecl *Var = dyn_cast<VarDecl>(D))
1206 return Var->isFileVarDecl() && Var->getInit();
1207 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1208 return Func->isThisDeclarationADefinition();
1209 return isa<ObjCProtocolDecl>(D);
1210}
1211
1212/// \brief Read the declaration at the given offset from the PCH file.
1213Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
1214 // Keep track of where we are in the stream, then jump back there
1215 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001216 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001217
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001218 ReadingKindTracker ReadingKind(Read_Decl, *this);
1219
Douglas Gregor1342e842009-07-06 18:54:52 +00001220 // Note that we are loading a declaration record.
1221 LoadingTypeOrDecl Loading(*this);
Mike Stump11289f42009-09-09 15:08:12 +00001222
Chris Lattner1de76db2009-04-27 05:58:23 +00001223 DeclsCursor.JumpToBit(Offset);
Chris Lattner487412d2009-04-27 05:27:42 +00001224 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001225 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001226 unsigned Idx = 0;
1227 PCHDeclReader Reader(*this, Record, Idx);
1228
Chris Lattner1de76db2009-04-27 05:58:23 +00001229 Decl *D = 0;
1230 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner487412d2009-04-27 05:27:42 +00001231 case pch::DECL_ATTR:
1232 case pch::DECL_CONTEXT_LEXICAL:
1233 case pch::DECL_CONTEXT_VISIBLE:
1234 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1235 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001236 case pch::DECL_TRANSLATION_UNIT:
1237 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +00001238 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +00001239 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001240 case pch::DECL_TYPEDEF:
John McCall703a3f82009-10-24 08:00:42 +00001241 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001242 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001243 case pch::DECL_ENUM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001244 D = EnumDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001245 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001246 case pch::DECL_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001247 D = RecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001248 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001249 case pch::DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +00001250 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001251 0, llvm::APSInt());
1252 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001253 case pch::DECL_FUNCTION:
Mike Stump11289f42009-09-09 15:08:12 +00001254 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001255 QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001256 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001257 case pch::DECL_LINKAGE_SPEC:
1258 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
1259 (LinkageSpecDecl::LanguageIDs)0,
1260 false);
1261 break;
1262 case pch::DECL_NAMESPACE:
1263 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
1264 break;
1265 case pch::DECL_NAMESPACE_ALIAS:
1266 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
1267 SourceLocation(), 0, SourceRange(), 0,
1268 SourceLocation(), 0);
1269 break;
1270 case pch::DECL_USING:
1271 D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(),
1272 SourceLocation(), 0, DeclarationName(), false);
1273 break;
1274 case pch::DECL_USING_SHADOW:
1275 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1276 break;
1277 case pch::DECL_USING_DIRECTIVE:
1278 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
1279 SourceLocation(), SourceRange(), 0,
1280 SourceLocation(), 0, 0);
1281 break;
1282 case pch::DECL_UNRESOLVED_USING_VALUE:
1283 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
1284 SourceRange(), 0, SourceLocation(),
1285 DeclarationName());
1286 break;
1287 case pch::DECL_UNRESOLVED_USING_TYPENAME:
1288 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
1289 SourceLocation(), SourceRange(),
1290 0, SourceLocation(),
1291 DeclarationName());
1292 break;
1293 case pch::DECL_CXX_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001294 D = CXXRecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001295 break;
1296 case pch::DECL_CXX_METHOD:
1297 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
1298 QualType(), 0);
1299 break;
1300 case pch::DECL_CXX_CONSTRUCTOR:
1301 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1302 break;
1303 case pch::DECL_CXX_DESTRUCTOR:
1304 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1305 break;
1306 case pch::DECL_CXX_CONVERSION:
1307 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1308 break;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001309 case pch::DECL_ACCESS_SPEC:
1310 D = AccessSpecDecl::Create(*Context, AS_none, 0, SourceLocation(),
1311 SourceLocation());
1312 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001313 case pch::DECL_FRIEND:
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001314 D = FriendDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001315 break;
1316 case pch::DECL_FRIEND_TEMPLATE:
1317 assert(false && "cannot read FriendTemplateDecl");
1318 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001319 case pch::DECL_CLASS_TEMPLATE:
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +00001320 D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(),
1321 DeclarationName(), 0, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001322 break;
1323 case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001324 D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001325 break;
1326 case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001327 D = ClassTemplatePartialSpecializationDecl::Create(*Context,
1328 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001329 break;
1330 case pch::DECL_FUNCTION_TEMPLATE:
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001331 D = FunctionTemplateDecl::Create(*Context, 0, SourceLocation(),
1332 DeclarationName(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001333 break;
1334 case pch::DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001335 D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001336 break;
1337 case pch::DECL_NON_TYPE_TEMPLATE_PARM:
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001338 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0,
1339 QualType(),0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001340 break;
1341 case pch::DECL_TEMPLATE_TEMPLATE_PARM:
1342 assert(false && "cannot read TemplateTemplateParmDecl");
1343 break;
1344 case pch::DECL_STATIC_ASSERT:
1345 assert(false && "cannot read StaticAssertDecl");
1346 break;
1347
Chris Lattner8f63ab52009-04-27 06:01:06 +00001348 case pch::DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +00001349 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001350 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001351 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001352 case pch::DECL_OBJC_INTERFACE:
Chris Lattner8575daa2009-04-27 21:45:14 +00001353 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001354 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001355 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001356 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001357 ObjCIvarDecl::None);
1358 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001359 case pch::DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001360 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001361 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001362 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001363 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001364 QualType(), 0);
1365 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001366 case pch::DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001367 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001368 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001369 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001370 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001371 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001372 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +00001373 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1374 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001375 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001376 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001377 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001378 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001379 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +00001380 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001381 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001382 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001383 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001384 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001385 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001386 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001387 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001388 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001389 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001390 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001391 SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001392 ObjCPropertyImplDecl::Dynamic, 0);
1393 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001394 case pch::DECL_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001395 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +00001396 false);
Chris Lattner487412d2009-04-27 05:27:42 +00001397 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001398 case pch::DECL_VAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001399 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001400 VarDecl::None, VarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001401 break;
1402
1403 case pch::DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001404 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001405 break;
1406
Chris Lattner8f63ab52009-04-27 06:01:06 +00001407 case pch::DECL_PARM_VAR:
Mike Stump11289f42009-09-09 15:08:12 +00001408 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001409 VarDecl::None, VarDecl::None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001410 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001411 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001412 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001413 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001414 case pch::DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +00001415 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001416 break;
1417 }
Chris Lattner487412d2009-04-27 05:27:42 +00001418
1419 assert(D && "Unknown declaration reading PCH file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001420 LoadedDecl(Index, D);
1421 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001422
1423 // If this declaration is also a declaration context, get the
1424 // offsets for its tables of lexical and visible declarations.
1425 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1426 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1427 if (Offsets.first || Offsets.second) {
1428 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1429 DC->setHasExternalVisibleStorage(Offsets.second != 0);
1430 DeclContextOffsets[DC] = Offsets;
1431 }
1432 }
1433 assert(Idx == Record.size());
1434
1435 // If we have deserialized a declaration that has a definition the
1436 // AST consumer might need to know about, notify the consumer
1437 // about that definition now or queue it for later.
1438 if (isConsumerInterestedIn(D)) {
1439 if (Consumer) {
1440 DeclGroupRef DG(D);
1441 Consumer->HandleTopLevelDecl(DG);
1442 } else {
1443 InterestingDecls.push_back(D);
1444 }
1445 }
1446
1447 return D;
1448}