blob: be4f72ec3b7e75e1f9cb0ec7d0840f5c6e784ac3 [file] [log] [blame]
Chris Lattner487412d2009-04-27 05:27:42 +00001//===--- PCHReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the PCHReader::ReadDeclRecord method, which is the
11// entrypoint for loading a decl.
12//
13//===----------------------------------------------------------------------===//
14
15#include "clang/Frontend/PCHReader.h"
16#include "clang/AST/ASTConsumer.h"
17#include "clang/AST/ASTContext.h"
18#include "clang/AST/DeclVisitor.h"
19#include "clang/AST/DeclGroup.h"
Chris Lattnerca025db2010-05-07 21:43:38 +000020#include "clang/AST/DeclCXX.h"
21#include "clang/AST/DeclTemplate.h"
Chris Lattner487412d2009-04-27 05:27:42 +000022#include "clang/AST/Expr.h"
23using namespace clang;
24
Chris Lattner487412d2009-04-27 05:27:42 +000025
26//===----------------------------------------------------------------------===//
27// Declaration deserialization
28//===----------------------------------------------------------------------===//
29
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000030namespace clang {
Chris Lattner487412d2009-04-27 05:27:42 +000031 class PCHDeclReader : public DeclVisitor<PCHDeclReader, void> {
32 PCHReader &Reader;
33 const PCHReader::RecordData &Record;
34 unsigned &Idx;
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +000035 pch::TypeID TypeIDForTypeDecl;
Chris Lattner487412d2009-04-27 05:27:42 +000036
37 public:
38 PCHDeclReader(PCHReader &Reader, const PCHReader::RecordData &Record,
39 unsigned &Idx)
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +000040 : Reader(Reader), Record(Record), Idx(Idx), TypeIDForTypeDecl(0) { }
Chris Lattner487412d2009-04-27 05:27:42 +000041
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +000042 void Visit(Decl *D);
43
Chris Lattner487412d2009-04-27 05:27:42 +000044 void VisitDecl(Decl *D);
45 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
46 void VisitNamedDecl(NamedDecl *ND);
Douglas Gregore31bbd92010-02-21 18:22:14 +000047 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000048 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
49 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000050 void VisitTypeDecl(TypeDecl *TD);
51 void VisitTypedefDecl(TypedefDecl *TD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000052 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000053 void VisitTagDecl(TagDecl *TD);
54 void VisitEnumDecl(EnumDecl *ED);
55 void VisitRecordDecl(RecordDecl *RD);
Chris Lattnerca025db2010-05-07 21:43:38 +000056 void VisitCXXRecordDecl(CXXRecordDecl *D);
57 void VisitClassTemplateSpecializationDecl(
58 ClassTemplateSpecializationDecl *D);
59 void VisitClassTemplatePartialSpecializationDecl(
60 ClassTemplatePartialSpecializationDecl *D);
61 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000062 void VisitValueDecl(ValueDecl *VD);
63 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000064 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +000065 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +000066 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattnerca025db2010-05-07 21:43:38 +000067 void VisitCXXMethodDecl(CXXMethodDecl *D);
68 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
69 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
70 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000071 void VisitFieldDecl(FieldDecl *FD);
72 void VisitVarDecl(VarDecl *VD);
73 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
74 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattnerca025db2010-05-07 21:43:38 +000075 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
76 void VisitTemplateDecl(TemplateDecl *D);
77 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +000078 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000079 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +000080 void VisitUsingDecl(UsingDecl *D);
81 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000082 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000083 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Abramo Bagnarad7340582010-06-05 05:09:32 +000084 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000085 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000086 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
87 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000088 void VisitBlockDecl(BlockDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +000089
Chris Lattner487412d2009-04-27 05:27:42 +000090 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Chris Lattnerca025db2010-05-07 21:43:38 +000091
Alexis Hunted053252010-05-30 07:21:58 +000092 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-04-27 05:27:42 +000093 void VisitObjCMethodDecl(ObjCMethodDecl *D);
94 void VisitObjCContainerDecl(ObjCContainerDecl *D);
95 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
96 void VisitObjCIvarDecl(ObjCIvarDecl *D);
97 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
98 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
99 void VisitObjCClassDecl(ObjCClassDecl *D);
100 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
101 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
102 void VisitObjCImplDecl(ObjCImplDecl *D);
103 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
104 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
105 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
106 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
107 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
108 };
109}
110
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000111void PCHDeclReader::Visit(Decl *D) {
112 DeclVisitor<PCHDeclReader, void>::Visit(D);
113
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000114 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
115 // if we have a fully initialized TypeDecl, we can safely read its type now.
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000116 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtr());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000117 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
118 // FunctionDecl's body was written last after all other Stmts/Exprs.
119 if (Record[Idx++])
120 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
121 }
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000122}
123
Chris Lattner487412d2009-04-27 05:27:42 +0000124void PCHDeclReader::VisitDecl(Decl *D) {
125 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
126 D->setLexicalDeclContext(
127 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
128 D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
129 D->setInvalidDecl(Record[Idx++]);
130 if (Record[Idx++])
Argyrios Kyrtzidis91167172010-06-11 23:09:25 +0000131 D->initAttrs(Reader.ReadAttributes());
Chris Lattner487412d2009-04-27 05:27:42 +0000132 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +0000133 D->setUsed(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000134 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor16bef852009-10-16 20:01:17 +0000135 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner487412d2009-04-27 05:27:42 +0000136}
137
138void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
139 VisitDecl(TU);
Chris Lattnerca025db2010-05-07 21:43:38 +0000140 TU->setAnonymousNamespace(
141 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000142}
143
144void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) {
145 VisitDecl(ND);
Mike Stump11289f42009-09-09 15:08:12 +0000146 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000147}
148
149void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
150 VisitNamedDecl(TD);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000151 // Delay type reading until after we have fully initialized the decl.
152 TypeIDForTypeDecl = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000153}
154
155void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000156 VisitTypeDecl(TD);
John McCallbcd03502009-12-07 02:54:59 +0000157 TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000158}
159
160void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
161 VisitTypeDecl(TD);
Douglas Gregorb6b8f9e2009-07-29 23:36:44 +0000162 TD->setPreviousDeclaration(
163 cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000164 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
165 TD->setDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000166 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis664b6902009-07-14 03:18:02 +0000167 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000168 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall3e11ebe2010-03-15 10:12:16 +0000169 // FIXME: maybe read optional qualifier and its range.
170 TD->setTypedefForAnonDecl(
171 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000172}
173
174void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
175 VisitTagDecl(ED);
176 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall56774992009-12-09 09:09:27 +0000177 ED->setPromotionType(Reader.GetType(Record[Idx++]));
John McCall9aa35be2010-05-06 08:49:23 +0000178 ED->setNumPositiveBits(Record[Idx++]);
179 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor7a749382009-05-27 17:20:35 +0000180 // FIXME: C++ InstantiatedFrom
Chris Lattner487412d2009-04-27 05:27:42 +0000181}
182
183void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
184 VisitTagDecl(RD);
185 RD->setHasFlexibleArrayMember(Record[Idx++]);
186 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000187 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000188}
189
190void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
191 VisitNamedDecl(VD);
192 VD->setType(Reader.GetType(Record[Idx++]));
193}
194
195void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
196 VisitValueDecl(ECD);
197 if (Record[Idx++])
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000198 ECD->setInitExpr(Reader.ReadExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000199 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
200}
201
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000202void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
203 VisitValueDecl(DD);
John McCallbcd03502009-12-07 02:54:59 +0000204 TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Record, Idx);
205 if (TInfo)
206 DD->setTypeSourceInfo(TInfo);
John McCall3e11ebe2010-03-15 10:12:16 +0000207 // FIXME: read optional qualifier and its range.
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000208}
209
Chris Lattner487412d2009-04-27 05:27:42 +0000210void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000211 VisitDeclaratorDecl(FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000212
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000213 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000214 default: assert(false && "Unhandled TemplatedKind!");
215 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000216 case FunctionDecl::TK_NonTemplate:
217 break;
218 case FunctionDecl::TK_FunctionTemplate:
219 FD->setDescribedFunctionTemplate(
220 cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++])));
221 break;
222 case FunctionDecl::TK_MemberSpecialization: {
223 FunctionDecl *InstFD = cast<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
224 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
225 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
226 FD->setInstantiationOfMemberFunction(InstFD, TSK);
227 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
228 break;
229 }
230 case FunctionDecl::TK_FunctionTemplateSpecialization: {
231 FunctionTemplateDecl *Template
232 = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
233 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
234
235 // Template arguments.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000236 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000237 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000238
239 // Template args as written.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000240 llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000241 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000242 if (Record[Idx++]) { // TemplateArgumentsAsWritten != 0
243 unsigned NumTemplateArgLocs = Record[Idx++];
244 TemplArgLocs.reserve(NumTemplateArgLocs);
245 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
246 TemplArgLocs.push_back(Reader.ReadTemplateArgumentLoc(Record, Idx));
247
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000248 LAngleLoc = Reader.ReadSourceLocation(Record, Idx);
249 RAngleLoc = Reader.ReadSourceLocation(Record, Idx);
250 }
251
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000252 FD->setFunctionTemplateSpecialization(Template, TemplArgs.size(),
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000253 TemplArgs.data(), TSK,
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000254 TemplArgLocs.size(),
255 TemplArgLocs.data(),
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000256 LAngleLoc, RAngleLoc);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000257 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000258 }
259 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
260 // Templates.
261 UnresolvedSet<8> TemplDecls;
262 unsigned NumTemplates = Record[Idx++];
263 while (NumTemplates--)
264 TemplDecls.addDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
265
266 // Templates args.
267 TemplateArgumentListInfo TemplArgs;
268 unsigned NumArgs = Record[Idx++];
269 while (NumArgs--)
270 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
271
272 FD->setDependentTemplateSpecialization(*Reader.getContext(),
273 TemplDecls, TemplArgs);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000274 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000275 }
276 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000277
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000278 // FunctionDecl's body is handled last at PCHReaderDecl::Visit,
279 // after everything else is read.
280
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000281 FD->setPreviousDeclaration(
282 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
283 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
284 FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]);
285 FD->setInlineSpecified(Record[Idx++]);
286 FD->setVirtualAsWritten(Record[Idx++]);
287 FD->setPure(Record[Idx++]);
288 FD->setHasInheritedPrototype(Record[Idx++]);
289 FD->setHasWrittenPrototype(Record[Idx++]);
290 FD->setDeleted(Record[Idx++]);
291 FD->setTrivial(Record[Idx++]);
292 FD->setCopyAssignment(Record[Idx++]);
293 FD->setHasImplicitReturnZero(Record[Idx++]);
294 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
295
Chris Lattnerca025db2010-05-07 21:43:38 +0000296 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000297 unsigned NumParams = Record[Idx++];
298 llvm::SmallVector<ParmVarDecl *, 16> Params;
299 Params.reserve(NumParams);
300 for (unsigned I = 0; I != NumParams; ++I)
301 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000302 FD->setParams(Params.data(), NumParams);
John McCallb9467b62010-04-24 01:30:58 +0000303
304 // FIXME: order this properly w.r.t. friendness
305 // FIXME: this same thing needs to happen for function templates
306 if (FD->isOverloadedOperator() && !FD->getDeclContext()->isRecord())
307 FD->setNonMemberOperator();
Chris Lattner487412d2009-04-27 05:27:42 +0000308}
309
310void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
311 VisitNamedDecl(MD);
312 if (Record[Idx++]) {
313 // In practice, this won't be executed (since method definitions
314 // don't occur in header files).
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000315 MD->setBody(Reader.ReadStmt());
Chris Lattner487412d2009-04-27 05:27:42 +0000316 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
317 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
318 }
319 MD->setInstanceMethod(Record[Idx++]);
320 MD->setVariadic(Record[Idx++]);
321 MD->setSynthesized(Record[Idx++]);
322 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
323 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahaniand9235db2010-04-08 21:29:11 +0000324 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000325 MD->setResultType(Reader.GetType(Record[Idx++]));
Douglas Gregor12852d92010-03-08 14:59:44 +0000326 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000327 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
328 unsigned NumParams = Record[Idx++];
329 llvm::SmallVector<ParmVarDecl *, 16> Params;
330 Params.reserve(NumParams);
331 for (unsigned I = 0; I != NumParams; ++I)
332 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniancdabb312010-04-09 15:40:42 +0000333 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
334 NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000335}
336
337void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
338 VisitNamedDecl(CD);
Ted Kremenekc7c64312010-01-07 01:20:12 +0000339 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
340 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
341 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner487412d2009-04-27 05:27:42 +0000342}
343
344void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
345 VisitObjCContainerDecl(ID);
346 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
347 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
348 (Reader.GetDecl(Record[Idx++])));
349 unsigned NumProtocols = Record[Idx++];
350 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
351 Protocols.reserve(NumProtocols);
352 for (unsigned I = 0; I != NumProtocols; ++I)
353 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000354 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
355 ProtoLocs.reserve(NumProtocols);
356 for (unsigned I = 0; I != NumProtocols; ++I)
357 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
358 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
359 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000360 unsigned NumIvars = Record[Idx++];
361 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
362 IVars.reserve(NumIvars);
363 for (unsigned I = 0; I != NumIvars; ++I)
364 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000365 ID->setCategoryList(
366 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
367 ID->setForwardDecl(Record[Idx++]);
368 ID->setImplicitInterfaceDecl(Record[Idx++]);
369 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
370 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisea72f422009-07-18 00:33:23 +0000371 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000372}
373
374void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
375 VisitFieldDecl(IVD);
376 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
377}
378
379void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
380 VisitObjCContainerDecl(PD);
381 PD->setForwardDecl(Record[Idx++]);
382 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
383 unsigned NumProtoRefs = Record[Idx++];
384 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
385 ProtoRefs.reserve(NumProtoRefs);
386 for (unsigned I = 0; I != NumProtoRefs; ++I)
387 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000388 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
389 ProtoLocs.reserve(NumProtoRefs);
390 for (unsigned I = 0; I != NumProtoRefs; ++I)
391 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
392 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
393 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000394}
395
396void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
397 VisitFieldDecl(FD);
398}
399
400void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
401 VisitDecl(CD);
402 unsigned NumClassRefs = Record[Idx++];
403 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
404 ClassRefs.reserve(NumClassRefs);
405 for (unsigned I = 0; I != NumClassRefs; ++I)
406 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000407 llvm::SmallVector<SourceLocation, 16> SLocs;
408 SLocs.reserve(NumClassRefs);
409 for (unsigned I = 0; I != NumClassRefs; ++I)
410 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
411 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
412 NumClassRefs);
Chris Lattner487412d2009-04-27 05:27:42 +0000413}
414
415void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
416 VisitDecl(FPD);
417 unsigned NumProtoRefs = Record[Idx++];
418 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
419 ProtoRefs.reserve(NumProtoRefs);
420 for (unsigned I = 0; I != NumProtoRefs; ++I)
421 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000422 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
423 ProtoLocs.reserve(NumProtoRefs);
424 for (unsigned I = 0; I != NumProtoRefs; ++I)
425 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
426 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
427 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000428}
429
430void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
431 VisitObjCContainerDecl(CD);
432 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
433 unsigned NumProtoRefs = Record[Idx++];
434 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
435 ProtoRefs.reserve(NumProtoRefs);
436 for (unsigned I = 0; I != NumProtoRefs; ++I)
437 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000438 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
439 ProtoLocs.reserve(NumProtoRefs);
440 for (unsigned I = 0; I != NumProtoRefs; ++I)
441 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
442 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
443 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000444 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor071676f2010-01-16 16:38:58 +0000445 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
446 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000447}
448
449void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
450 VisitNamedDecl(CAD);
451 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
452}
453
454void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
455 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000456 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall339bb662010-06-04 20:50:08 +0000457 D->setType(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000458 // FIXME: stable encoding
459 D->setPropertyAttributes(
460 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000461 D->setPropertyAttributesAsWritten(
462 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000463 // FIXME: stable encoding
464 D->setPropertyImplementation(
465 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
466 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
467 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
468 D->setGetterMethodDecl(
469 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
470 D->setSetterMethodDecl(
471 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
472 D->setPropertyIvarDecl(
473 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
474}
475
476void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000477 VisitObjCContainerDecl(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000478 D->setClassInterface(
479 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000480}
481
482void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
483 VisitObjCImplDecl(D);
484 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
485}
486
487void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
488 VisitObjCImplDecl(D);
489 D->setSuperClass(
490 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanianc83726e2010-04-28 16:11:27 +0000491 // FIXME. Add reading of IvarInitializers and NumIvarInitializers.
Chris Lattner487412d2009-04-27 05:27:42 +0000492}
493
494
495void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
496 VisitDecl(D);
497 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
498 D->setPropertyDecl(
499 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
500 D->setPropertyIvarDecl(
501 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanian25491a22010-05-05 21:52:17 +0000502 // FIXME. read GetterCXXConstructor and SetterCXXAssignment
Chris Lattner487412d2009-04-27 05:27:42 +0000503}
504
505void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000506 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000507 FD->setMutable(Record[Idx++]);
508 if (Record[Idx++])
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000509 FD->setBitWidth(Reader.ReadExpr());
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000510 if (!FD->getDeclName()) {
511 FieldDecl *Tmpl = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
512 if (Tmpl)
513 Reader.getContext()->setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
514 }
Chris Lattner487412d2009-04-27 05:27:42 +0000515}
516
517void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000518 VisitDeclaratorDecl(VD);
Chris Lattner487412d2009-04-27 05:27:42 +0000519 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
Douglas Gregorc4df4072010-04-19 22:54:31 +0000520 VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000521 VD->setThreadSpecified(Record[Idx++]);
522 VD->setCXXDirectInitializer(Record[Idx++]);
523 VD->setDeclaredInCondition(Record[Idx++]);
Douglas Gregor3f324d562010-05-03 18:51:14 +0000524 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor6fd1b182010-05-15 06:01:05 +0000525 VD->setNRVOVariable(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000526 VD->setPreviousDeclaration(
527 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000528 if (Record[Idx++])
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000529 VD->setInit(Reader.ReadExpr());
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000530
531 if (Record[Idx++]) { // HasMemberSpecializationInfo.
532 VarDecl *Tmpl = cast<VarDecl>(Reader.GetDecl(Record[Idx++]));
533 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
534 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
535 Reader.getContext()->setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
536 }
Chris Lattner487412d2009-04-27 05:27:42 +0000537}
538
539void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
540 VisitVarDecl(PD);
541}
542
543void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
544 VisitVarDecl(PD);
545 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallf3cd6652010-03-12 18:31:32 +0000546 PD->setHasInheritedDefaultArg(Record[Idx++]);
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000547 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
548 PD->setUninstantiatedDefaultArg(Reader.ReadExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000549}
550
Chris Lattner487412d2009-04-27 05:27:42 +0000551void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
552 VisitDecl(AD);
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000553 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr()));
Chris Lattner487412d2009-04-27 05:27:42 +0000554}
555
556void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
557 VisitDecl(BD);
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000558 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt()));
John McCalla3ccba02010-06-04 11:21:44 +0000559 BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000560 unsigned NumParams = Record[Idx++];
561 llvm::SmallVector<ParmVarDecl *, 16> Params;
562 Params.reserve(NumParams);
563 for (unsigned I = 0; I != NumParams; ++I)
564 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000565 BD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000566}
567
Chris Lattnerca025db2010-05-07 21:43:38 +0000568void PCHDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
569 VisitDecl(D);
570 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
571 D->setHasBraces(Record[Idx++]);
572}
573
574void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
575 VisitNamedDecl(D);
576 D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx));
577 D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx));
578 D->setNextNamespace(
579 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
580
Chris Lattnerca025db2010-05-07 21:43:38 +0000581 bool IsOriginal = Record[Idx++];
Argyrios Kyrtzidisdae2a162010-07-03 07:57:53 +0000582 D->OrigOrAnonNamespace.setInt(IsOriginal);
583 D->OrigOrAnonNamespace.setPointer(
Chris Lattnerca025db2010-05-07 21:43:38 +0000584 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
585}
586
587void PCHDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
588 VisitNamedDecl(D);
589
590 D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx));
591 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
592 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
593 D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx));
594 D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
595}
596
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000597void PCHDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000598 VisitNamedDecl(D);
599 D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
600 D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
601 D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
602
603 // FIXME: It would probably be more efficient to read these into a vector
604 // and then re-cosntruct the shadow decl set over that vector since it
605 // would avoid existence checks.
606 unsigned NumShadows = Record[Idx++];
607 for(unsigned I = 0; I != NumShadows; ++I) {
608 D->addShadowDecl(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])));
609 }
610 D->setTypeName(Record[Idx++]);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000611 NamedDecl *Pattern = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
612 if (Pattern)
613 Reader.getContext()->setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000614}
615
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000616void PCHDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000617 VisitNamedDecl(D);
618 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
619 D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000620 UsingShadowDecl *Pattern
621 = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]));
622 if (Pattern)
623 Reader.getContext()->setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000624}
625
626void PCHDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
627 VisitNamedDecl(D);
628 D->setNamespaceKeyLocation(Reader.ReadSourceLocation(Record, Idx));
629 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
630 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
631 D->setIdentLocation(Reader.ReadSourceLocation(Record, Idx));
632 D->setNominatedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
633 D->setCommonAncestor(cast_or_null<DeclContext>(
634 Reader.GetDecl(Record[Idx++])));
635}
636
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000637void PCHDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000638 VisitValueDecl(D);
639 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
640 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
641 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
642}
643
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000644void PCHDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000645 UnresolvedUsingTypenameDecl *D) {
646 VisitTypeDecl(D);
647 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
648 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
649 D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx));
650 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
651}
652
653void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000654 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000655
656 ASTContext &C = *Reader.getContext();
657
658 if (D->isFirstDeclaration()) {
659 if (Record[Idx++]) { // DefinitionData != 0
660 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(0);
661 struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData;
662
663 Data.UserDeclaredConstructor = Record[Idx++];
664 Data.UserDeclaredCopyConstructor = Record[Idx++];
665 Data.UserDeclaredCopyAssignment = Record[Idx++];
666 Data.UserDeclaredDestructor = Record[Idx++];
667 Data.Aggregate = Record[Idx++];
668 Data.PlainOldData = Record[Idx++];
669 Data.Empty = Record[Idx++];
670 Data.Polymorphic = Record[Idx++];
671 Data.Abstract = Record[Idx++];
672 Data.HasTrivialConstructor = Record[Idx++];
673 Data.HasTrivialCopyConstructor = Record[Idx++];
674 Data.HasTrivialCopyAssignment = Record[Idx++];
675 Data.HasTrivialDestructor = Record[Idx++];
676 Data.ComputedVisibleConversions = Record[Idx++];
Douglas Gregor9672f922010-07-03 00:47:00 +0000677 Data.DeclaredDefaultConstructor = Record[Idx++];
Douglas Gregora6d69502010-07-02 23:41:54 +0000678 Data.DeclaredCopyConstructor = Record[Idx++];
Douglas Gregor330b9cf2010-07-02 21:50:04 +0000679 Data.DeclaredCopyAssignment = Record[Idx++];
Douglas Gregor7454c562010-07-02 20:37:36 +0000680 Data.DeclaredDestructor = Record[Idx++];
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000681
682 // setBases() is unsuitable since it may try to iterate the bases of an
683 // unitialized base.
684 Data.NumBases = Record[Idx++];
685 Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases];
686 for (unsigned i = 0; i != Data.NumBases; ++i)
Argyrios Kyrtzidis3701fcd2010-07-02 23:30:27 +0000687 Data.Bases[i] = Reader.ReadCXXBaseSpecifier(Record, Idx);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000688
689 // FIXME: Make VBases lazily computed when needed to avoid storing them.
690 Data.NumVBases = Record[Idx++];
691 Data.VBases = new(C) CXXBaseSpecifier [Data.NumVBases];
692 for (unsigned i = 0; i != Data.NumVBases; ++i)
Argyrios Kyrtzidis3701fcd2010-07-02 23:30:27 +0000693 Data.VBases[i] = Reader.ReadCXXBaseSpecifier(Record, Idx);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000694
695 Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx);
696 Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx);
697 Data.Definition = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
698 Data.FirstFriend
699 = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
700 }
701 } else {
702 D->DefinitionData = D->getPreviousDeclaration()->DefinitionData;
703 }
704
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000705 enum CXXRecKind {
706 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
707 };
708 switch ((CXXRecKind)Record[Idx++]) {
709 default:
710 assert(false && "Out of sync with PCHDeclWriter::VisitCXXRecordDecl?");
711 case CXXRecNotTemplate:
712 break;
713 case CXXRecTemplate:
714 D->setDescribedClassTemplate(
715 cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++])));
716 break;
717 case CXXRecMemberSpecialization: {
718 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
719 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
720 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
721 D->setInstantiationOfMemberClass(RD, TSK);
722 D->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
723 break;
724 }
725 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000726}
727
728void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000729 VisitFunctionDecl(D);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000730 unsigned NumOverridenMethods = Record[Idx++];
731 while (NumOverridenMethods--) {
732 CXXMethodDecl *MD = cast<CXXMethodDecl>(Reader.GetDecl(Record[Idx++]));
733 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
734 // MD may be initializing.
735 Reader.getContext()->addOverriddenMethod(D, MD);
736 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000737}
738
739void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000740 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000741
742 D->IsExplicitSpecified = Record[Idx++];
743 D->ImplicitlyDefined = Record[Idx++];
744
745 unsigned NumInitializers = Record[Idx++];
746 D->NumBaseOrMemberInitializers = NumInitializers;
747 if (NumInitializers) {
748 ASTContext &C = *Reader.getContext();
749
750 D->BaseOrMemberInitializers
751 = new (C) CXXBaseOrMemberInitializer*[NumInitializers];
752 for (unsigned i=0; i != NumInitializers; ++i) {
753 TypeSourceInfo *BaseClassInfo;
754 bool IsBaseVirtual;
755 FieldDecl *Member;
756
757 bool IsBaseInitializer = Record[Idx++];
758 if (IsBaseInitializer) {
759 BaseClassInfo = Reader.GetTypeSourceInfo(Record, Idx);
760 IsBaseVirtual = Record[Idx++];
761 } else {
762 Member = cast<FieldDecl>(Reader.GetDecl(Record[Idx++]));
763 }
764 SourceLocation MemberLoc = Reader.ReadSourceLocation(Record, Idx);
765 Expr *Init = Reader.ReadExpr();
766 FieldDecl *AnonUnionMember
767 = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
768 SourceLocation LParenLoc = Reader.ReadSourceLocation(Record, Idx);
769 SourceLocation RParenLoc = Reader.ReadSourceLocation(Record, Idx);
770 bool IsWritten = Record[Idx++];
771 unsigned SourceOrderOrNumArrayIndices;
772 llvm::SmallVector<VarDecl *, 8> Indices;
773 if (IsWritten) {
774 SourceOrderOrNumArrayIndices = Record[Idx++];
775 } else {
776 SourceOrderOrNumArrayIndices = Record[Idx++];
777 Indices.reserve(SourceOrderOrNumArrayIndices);
778 for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i)
779 Indices.push_back(cast<VarDecl>(Reader.GetDecl(Record[Idx++])));
780 }
781
782 CXXBaseOrMemberInitializer *BOMInit;
783 if (IsBaseInitializer) {
784 BOMInit = new (C) CXXBaseOrMemberInitializer(C, BaseClassInfo,
785 IsBaseVirtual, LParenLoc,
786 Init, RParenLoc);
787 } else if (IsWritten) {
788 BOMInit = new (C) CXXBaseOrMemberInitializer(C, Member, MemberLoc,
789 LParenLoc, Init, RParenLoc);
790 } else {
791 BOMInit = CXXBaseOrMemberInitializer::Create(C, Member, MemberLoc,
792 LParenLoc, Init, RParenLoc,
793 Indices.data(),
794 Indices.size());
795 }
796
797 BOMInit->setAnonUnionMember(AnonUnionMember);
798 D->BaseOrMemberInitializers[i] = BOMInit;
799 }
800 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000801}
802
803void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000804 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000805
806 D->ImplicitlyDefined = Record[Idx++];
807 D->OperatorDelete = cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000808}
809
810void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000811 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000812 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000813}
814
Abramo Bagnarad7340582010-06-05 05:09:32 +0000815void PCHDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
816 VisitDecl(D);
817 D->setColonLoc(Reader.ReadSourceLocation(Record, Idx));
818}
819
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000820void PCHDeclReader::VisitFriendDecl(FriendDecl *D) {
821 if (Record[Idx++])
822 D->Friend = Reader.GetTypeSourceInfo(Record, Idx);
823 else
824 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
825 D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
826 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
827}
828
Chris Lattnerca025db2010-05-07 21:43:38 +0000829void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
830 assert(false && "cannot read FriendTemplateDecl");
831}
832
833void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000834 VisitNamedDecl(D);
835
836 NamedDecl *TemplatedDecl = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000837 TemplateParameterList* TemplateParams
838 = Reader.ReadTemplateParameterList(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000839 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +0000840}
841
842void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000843 VisitTemplateDecl(D);
844
845 ClassTemplateDecl *PrevDecl =
846 cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +0000847 D->setPreviousDeclaration(PrevDecl);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000848 if (PrevDecl == 0) {
849 // This ClassTemplateDecl owns a CommonPtr; read it.
850
851 unsigned size = Record[Idx++];
852 while (size--) {
853 ClassTemplateSpecializationDecl *CTSD
854 = cast<ClassTemplateSpecializationDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidise23371e2010-07-02 11:55:37 +0000855 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
856 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000857 llvm::FoldingSetNodeID ID;
858 void *InsertPos = 0;
Argyrios Kyrtzidise23371e2010-07-02 11:55:37 +0000859 ClassTemplateSpecializationDecl::Profile(ID, TemplArgs.data(),
860 TemplArgs.size(),
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000861 *Reader.getContext());
862 D->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
863 D->getSpecializations().InsertNode(CTSD, InsertPos);
864 }
865
866 size = Record[Idx++];
867 while (size--) {
868 ClassTemplatePartialSpecializationDecl *CTSD
869 = cast<ClassTemplatePartialSpecializationDecl>(
870 Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidise23371e2010-07-02 11:55:37 +0000871 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
872 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000873 llvm::FoldingSetNodeID ID;
874 void *InsertPos = 0;
Argyrios Kyrtzidise23371e2010-07-02 11:55:37 +0000875 ClassTemplatePartialSpecializationDecl::Profile(ID, TemplArgs.data(),
876 TemplArgs.size(),
877 *Reader.getContext());
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000878 D->getPartialSpecializations().FindNodeOrInsertPos(ID, InsertPos);
879 D->getPartialSpecializations().InsertNode(CTSD, InsertPos);
880 }
881
882 // InjectedClassNameType is computed.
883
884 if (ClassTemplateDecl *CTD
885 = cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
886 D->setInstantiatedFromMemberTemplate(CTD);
887 if (Record[Idx++])
888 D->setMemberSpecialization();
889 }
890 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000891}
892
893void PCHDeclReader::VisitClassTemplateSpecializationDecl(
894 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000895 VisitCXXRecordDecl(D);
896
897 if (Decl *InstD = Reader.GetDecl(Record[Idx++])) {
898 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
899 D->setInstantiationOf(CTD);
900 } else {
901 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
902 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
903 D->setInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(InstD),
904 TemplArgs.data(), TemplArgs.size());
905 }
906 }
907
908 // Explicit info.
909 if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Record, Idx)) {
910 D->setTypeAsWritten(TyInfo);
911 D->setExternLoc(Reader.ReadSourceLocation(Record, Idx));
912 D->setTemplateKeywordLoc(Reader.ReadSourceLocation(Record, Idx));
913 }
914
915 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
916 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
917 D->initTemplateArgs(TemplArgs.data(), TemplArgs.size());
918 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
919 if (POI.isValid())
920 D->setPointOfInstantiation(POI);
921 D->setSpecializationKind((TemplateSpecializationKind)Record[Idx++]);
Chris Lattnerca025db2010-05-07 21:43:38 +0000922}
923
924void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl(
925 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000926 VisitClassTemplateSpecializationDecl(D);
927
928 D->initTemplateParameters(Reader.ReadTemplateParameterList(Record, Idx));
929
930 TemplateArgumentListInfo ArgInfos;
931 unsigned NumArgs = Record[Idx++];
932 while (NumArgs--)
933 ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
934 D->initTemplateArgsAsWritten(ArgInfos);
935
936 D->setSequenceNumber(Record[Idx++]);
937
938 // These are read/set from/to the first declaration.
939 if (D->getPreviousDeclaration() == 0) {
940 D->setInstantiatedFromMember(
941 cast_or_null<ClassTemplatePartialSpecializationDecl>(
942 Reader.GetDecl(Record[Idx++])));
943 if (Record[Idx++])
944 D->isMemberSpecialization();
945 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000946}
947
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000948void PCHDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
949 VisitTemplateDecl(D);
950
951 FunctionTemplateDecl *PrevDecl =
952 cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
953 D->setPreviousDeclaration(PrevDecl);
954 if (PrevDecl == 0) {
955 // This FunctionTemplateDecl owns a CommonPtr; read it.
956
957 // FunctionTemplateSpecializationInfos are filled through the
958 // templated FunctionDecl's setFunctionTemplateSpecialization, no need to
959 // read them here.
960
961 if (FunctionTemplateDecl *CTD
962 = cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
963 D->setInstantiatedFromMemberTemplate(CTD);
964 if (Record[Idx++])
965 D->setMemberSpecialization();
966 }
967 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000968}
969
970void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000971 VisitTypeDecl(D);
972
973 D->setDeclaredWithTypename(Record[Idx++]);
974 D->setParameterPack(Record[Idx++]);
975
976 bool Inherited = Record[Idx++];
977 TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Record, Idx);
978 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +0000979}
980
981void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +0000982 VisitVarDecl(D);
983 // TemplateParmPosition.
984 D->setDepth(Record[Idx++]);
985 D->setPosition(Record[Idx++]);
986 // Rest of NonTypeTemplateParmDecl.
987 if (Record[Idx++]) {
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000988 Expr *DefArg = Reader.ReadExpr();
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +0000989 bool Inherited = Record[Idx++];
990 D->setDefaultArgument(DefArg, Inherited);
991 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000992}
993
994void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
995 assert(false && "cannot read TemplateTemplateParmDecl");
996}
997
998void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
999 assert(false && "cannot read StaticAssertDecl");
1000}
1001
Mike Stump11289f42009-09-09 15:08:12 +00001002std::pair<uint64_t, uint64_t>
Chris Lattner487412d2009-04-27 05:27:42 +00001003PCHDeclReader::VisitDeclContext(DeclContext *DC) {
1004 uint64_t LexicalOffset = Record[Idx++];
1005 uint64_t VisibleOffset = Record[Idx++];
1006 return std::make_pair(LexicalOffset, VisibleOffset);
1007}
1008
1009//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00001010// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00001011//===----------------------------------------------------------------------===//
1012
Chris Lattner8f63ab52009-04-27 06:01:06 +00001013/// \brief Reads attributes from the current stream position.
1014Attr *PCHReader::ReadAttributes() {
1015 unsigned Code = DeclsCursor.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +00001016 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner8f63ab52009-04-27 06:01:06 +00001017 "Expected unabbreviated record"); (void)Code;
Mike Stump11289f42009-09-09 15:08:12 +00001018
Chris Lattner8f63ab52009-04-27 06:01:06 +00001019 RecordData Record;
1020 unsigned Idx = 0;
1021 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump11289f42009-09-09 15:08:12 +00001022 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001023 (void)RecCode;
1024
1025#define SIMPLE_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001026 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +00001027 New = ::new (*Context) Name##Attr(); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001028 break
1029
1030#define STRING_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001031 case attr::Name: \
Ted Kremenek7f4945a2010-02-11 05:28:37 +00001032 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001033 break
1034
1035#define UNSIGNED_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001036 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +00001037 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001038 break
1039
1040 Attr *Attrs = 0;
1041 while (Idx < Record.size()) {
1042 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001043 attr::Kind Kind = (attr::Kind)Record[Idx++];
Chris Lattner8f63ab52009-04-27 06:01:06 +00001044 bool IsInherited = Record[Idx++];
1045
1046 switch (Kind) {
Anton Korobeynikov55bcea12010-01-10 12:58:08 +00001047 default:
1048 assert(0 && "Unknown attribute!");
1049 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001050 STRING_ATTR(Alias);
Daniel Dunbarfc6507e2010-05-27 02:25:39 +00001051 SIMPLE_ATTR(AlignMac68k);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001052 UNSIGNED_ATTR(Aligned);
1053 SIMPLE_ATTR(AlwaysInline);
1054 SIMPLE_ATTR(AnalyzerNoReturn);
1055 STRING_ATTR(Annotate);
1056 STRING_ATTR(AsmLabel);
Alexis Hunt54a02542009-11-25 04:20:27 +00001057 SIMPLE_ATTR(BaseCheck);
Mike Stump11289f42009-09-09 15:08:12 +00001058
Alexis Hunt344393e2010-06-16 23:43:53 +00001059 case attr::Blocks:
Chris Lattner8575daa2009-04-27 21:45:14 +00001060 New = ::new (*Context) BlocksAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001061 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
1062 break;
Mike Stump11289f42009-09-09 15:08:12 +00001063
Eli Friedmane4310c82009-11-09 18:38:53 +00001064 SIMPLE_ATTR(CDecl);
1065
Alexis Hunt344393e2010-06-16 23:43:53 +00001066 case attr::Cleanup:
Chris Lattner8575daa2009-04-27 21:45:14 +00001067 New = ::new (*Context) CleanupAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001068 cast<FunctionDecl>(GetDecl(Record[Idx++])));
1069 break;
1070
1071 SIMPLE_ATTR(Const);
1072 UNSIGNED_ATTR(Constructor);
1073 SIMPLE_ATTR(DLLExport);
1074 SIMPLE_ATTR(DLLImport);
1075 SIMPLE_ATTR(Deprecated);
1076 UNSIGNED_ATTR(Destructor);
1077 SIMPLE_ATTR(FastCall);
Alexis Hunt96d5c762009-11-21 08:43:09 +00001078 SIMPLE_ATTR(Final);
Mike Stump11289f42009-09-09 15:08:12 +00001079
Alexis Hunt344393e2010-06-16 23:43:53 +00001080 case attr::Format: {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001081 std::string Type = ReadString(Record, Idx);
1082 unsigned FormatIdx = Record[Idx++];
1083 unsigned FirstArg = Record[Idx++];
Ted Kremenek7f4945a2010-02-11 05:28:37 +00001084 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001085 break;
1086 }
Mike Stump11289f42009-09-09 15:08:12 +00001087
Alexis Hunt344393e2010-06-16 23:43:53 +00001088 case attr::FormatArg: {
Fariborz Jahanianf1c25022009-05-20 17:41:43 +00001089 unsigned FormatIdx = Record[Idx++];
1090 New = ::new (*Context) FormatArgAttr(FormatIdx);
1091 break;
1092 }
Mike Stump11289f42009-09-09 15:08:12 +00001093
Alexis Hunt344393e2010-06-16 23:43:53 +00001094 case attr::Sentinel: {
Fariborz Jahanian027b8862009-05-13 18:09:35 +00001095 int sentinel = Record[Idx++];
1096 int nullPos = Record[Idx++];
1097 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
1098 break;
1099 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001100
1101 SIMPLE_ATTR(GNUInline);
Alexis Hunt54a02542009-11-25 04:20:27 +00001102 SIMPLE_ATTR(Hiding);
Mike Stump11289f42009-09-09 15:08:12 +00001103
Alexis Hunt344393e2010-06-16 23:43:53 +00001104 case attr::IBAction:
Ted Kremenek06be9682010-02-17 02:37:45 +00001105 New = ::new (*Context) IBActionAttr();
1106 break;
1107
Alexis Hunt344393e2010-06-16 23:43:53 +00001108 case attr::IBOutlet:
Chris Lattner8575daa2009-04-27 21:45:14 +00001109 New = ::new (*Context) IBOutletAttr();
Chris Lattner8f63ab52009-04-27 06:01:06 +00001110 break;
1111
Alexis Hunt344393e2010-06-16 23:43:53 +00001112 case attr::IBOutletCollection: {
Ted Kremenek26bde772010-05-19 17:38:06 +00001113 ObjCInterfaceDecl *D =
1114 cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++]));
1115 New = ::new (*Context) IBOutletCollectionAttr(D);
1116 break;
1117 }
1118
Ryan Flynn1f1fdc02009-08-09 20:07:29 +00001119 SIMPLE_ATTR(Malloc);
Mike Stump3722f582009-08-26 22:31:08 +00001120 SIMPLE_ATTR(NoDebug);
1121 SIMPLE_ATTR(NoInline);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001122 SIMPLE_ATTR(NoReturn);
1123 SIMPLE_ATTR(NoThrow);
Mike Stump11289f42009-09-09 15:08:12 +00001124
Alexis Hunt344393e2010-06-16 23:43:53 +00001125 case attr::NonNull: {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001126 unsigned Size = Record[Idx++];
1127 llvm::SmallVector<unsigned, 16> ArgNums;
1128 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
1129 Idx += Size;
Ted Kremenek510ee252010-02-11 07:31:47 +00001130 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001131 break;
1132 }
Mike Stump11289f42009-09-09 15:08:12 +00001133
Alexis Hunt344393e2010-06-16 23:43:53 +00001134 case attr::ReqdWorkGroupSize: {
Nate Begemanf2758702009-06-26 06:32:41 +00001135 unsigned X = Record[Idx++];
1136 unsigned Y = Record[Idx++];
1137 unsigned Z = Record[Idx++];
1138 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
1139 break;
1140 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001141
1142 SIMPLE_ATTR(ObjCException);
1143 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekd9c66632010-02-18 00:05:45 +00001144 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +00001145 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenekd9c66632010-02-18 00:05:45 +00001146 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +00001147 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001148 SIMPLE_ATTR(Overloadable);
Alexis Hunt54a02542009-11-25 04:20:27 +00001149 SIMPLE_ATTR(Override);
Anders Carlsson68e0b682009-08-08 18:23:56 +00001150 SIMPLE_ATTR(Packed);
Daniel Dunbar40130442010-05-27 01:12:46 +00001151 UNSIGNED_ATTR(MaxFieldAlignment);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001152 SIMPLE_ATTR(Pure);
1153 UNSIGNED_ATTR(Regparm);
1154 STRING_ATTR(Section);
1155 SIMPLE_ATTR(StdCall);
Douglas Gregora941dca2010-05-18 16:57:00 +00001156 SIMPLE_ATTR(ThisCall);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001157 SIMPLE_ATTR(TransparentUnion);
1158 SIMPLE_ATTR(Unavailable);
1159 SIMPLE_ATTR(Unused);
1160 SIMPLE_ATTR(Used);
Mike Stump11289f42009-09-09 15:08:12 +00001161
Alexis Hunt344393e2010-06-16 23:43:53 +00001162 case attr::Visibility:
Chris Lattner8575daa2009-04-27 21:45:14 +00001163 New = ::new (*Context) VisibilityAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001164 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
1165 break;
1166
1167 SIMPLE_ATTR(WarnUnusedResult);
1168 SIMPLE_ATTR(Weak);
Rafael Espindolac18086a2010-02-23 22:00:30 +00001169 SIMPLE_ATTR(WeakRef);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001170 SIMPLE_ATTR(WeakImport);
1171 }
1172
1173 assert(New && "Unable to decode attribute?");
1174 New->setInherited(IsInherited);
1175 New->setNext(Attrs);
1176 Attrs = New;
1177 }
1178#undef UNSIGNED_ATTR
1179#undef STRING_ATTR
1180#undef SIMPLE_ATTR
1181
1182 // The list of attributes was built backwards. Reverse the list
1183 // before returning it.
1184 Attr *PrevAttr = 0, *NextAttr = 0;
1185 while (Attrs) {
1186 NextAttr = Attrs->getNext();
1187 Attrs->setNext(PrevAttr);
1188 PrevAttr = Attrs;
1189 Attrs = NextAttr;
1190 }
1191
1192 return PrevAttr;
1193}
1194
1195//===----------------------------------------------------------------------===//
1196// PCHReader Implementation
1197//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001198
1199/// \brief Note that we have loaded the declaration with the given
1200/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001201///
Chris Lattner487412d2009-04-27 05:27:42 +00001202/// This routine notes that this declaration has already been loaded,
1203/// so that future GetDecl calls will return this declaration rather
1204/// than trying to load a new declaration.
1205inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
1206 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1207 DeclsLoaded[Index] = D;
1208}
1209
1210
1211/// \brief Determine whether the consumer will be interested in seeing
1212/// this declaration (via HandleTopLevelDecl).
1213///
1214/// This routine should return true for anything that might affect
1215/// code generation, e.g., inline function definitions, Objective-C
1216/// declarations with metadata, etc.
1217static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001218 if (isa<FileScopeAsmDecl>(D))
1219 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001220 if (VarDecl *Var = dyn_cast<VarDecl>(D))
1221 return Var->isFileVarDecl() && Var->getInit();
1222 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1223 return Func->isThisDeclarationADefinition();
1224 return isa<ObjCProtocolDecl>(D);
1225}
1226
1227/// \brief Read the declaration at the given offset from the PCH file.
1228Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
1229 // Keep track of where we are in the stream, then jump back there
1230 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001231 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001232
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001233 ReadingKindTracker ReadingKind(Read_Decl, *this);
1234
Douglas Gregor1342e842009-07-06 18:54:52 +00001235 // Note that we are loading a declaration record.
1236 LoadingTypeOrDecl Loading(*this);
Mike Stump11289f42009-09-09 15:08:12 +00001237
Chris Lattner1de76db2009-04-27 05:58:23 +00001238 DeclsCursor.JumpToBit(Offset);
Chris Lattner487412d2009-04-27 05:27:42 +00001239 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001240 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001241 unsigned Idx = 0;
1242 PCHDeclReader Reader(*this, Record, Idx);
1243
Chris Lattner1de76db2009-04-27 05:58:23 +00001244 Decl *D = 0;
1245 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner487412d2009-04-27 05:27:42 +00001246 case pch::DECL_ATTR:
1247 case pch::DECL_CONTEXT_LEXICAL:
1248 case pch::DECL_CONTEXT_VISIBLE:
1249 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1250 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001251 case pch::DECL_TRANSLATION_UNIT:
1252 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +00001253 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +00001254 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001255 case pch::DECL_TYPEDEF:
John McCall703a3f82009-10-24 08:00:42 +00001256 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001257 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001258 case pch::DECL_ENUM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001259 D = EnumDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001260 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001261 case pch::DECL_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001262 D = RecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001263 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001264 case pch::DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +00001265 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001266 0, llvm::APSInt());
1267 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001268 case pch::DECL_FUNCTION:
Mike Stump11289f42009-09-09 15:08:12 +00001269 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001270 QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001271 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001272 case pch::DECL_LINKAGE_SPEC:
1273 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
1274 (LinkageSpecDecl::LanguageIDs)0,
1275 false);
1276 break;
1277 case pch::DECL_NAMESPACE:
1278 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
1279 break;
1280 case pch::DECL_NAMESPACE_ALIAS:
1281 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
1282 SourceLocation(), 0, SourceRange(), 0,
1283 SourceLocation(), 0);
1284 break;
1285 case pch::DECL_USING:
1286 D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(),
1287 SourceLocation(), 0, DeclarationName(), false);
1288 break;
1289 case pch::DECL_USING_SHADOW:
1290 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1291 break;
1292 case pch::DECL_USING_DIRECTIVE:
1293 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
1294 SourceLocation(), SourceRange(), 0,
1295 SourceLocation(), 0, 0);
1296 break;
1297 case pch::DECL_UNRESOLVED_USING_VALUE:
1298 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
1299 SourceRange(), 0, SourceLocation(),
1300 DeclarationName());
1301 break;
1302 case pch::DECL_UNRESOLVED_USING_TYPENAME:
1303 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
1304 SourceLocation(), SourceRange(),
1305 0, SourceLocation(),
1306 DeclarationName());
1307 break;
1308 case pch::DECL_CXX_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001309 D = CXXRecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001310 break;
1311 case pch::DECL_CXX_METHOD:
1312 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
1313 QualType(), 0);
1314 break;
1315 case pch::DECL_CXX_CONSTRUCTOR:
1316 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1317 break;
1318 case pch::DECL_CXX_DESTRUCTOR:
1319 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1320 break;
1321 case pch::DECL_CXX_CONVERSION:
1322 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1323 break;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001324 case pch::DECL_ACCESS_SPEC:
1325 D = AccessSpecDecl::Create(*Context, AS_none, 0, SourceLocation(),
1326 SourceLocation());
1327 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001328 case pch::DECL_FRIEND:
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001329 D = FriendDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001330 break;
1331 case pch::DECL_FRIEND_TEMPLATE:
1332 assert(false && "cannot read FriendTemplateDecl");
1333 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001334 case pch::DECL_CLASS_TEMPLATE:
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +00001335 D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(),
1336 DeclarationName(), 0, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001337 break;
1338 case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001339 D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001340 break;
1341 case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001342 D = ClassTemplatePartialSpecializationDecl::Create(*Context,
1343 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001344 break;
1345 case pch::DECL_FUNCTION_TEMPLATE:
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001346 D = FunctionTemplateDecl::Create(*Context, 0, SourceLocation(),
1347 DeclarationName(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001348 break;
1349 case pch::DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001350 D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001351 break;
1352 case pch::DECL_NON_TYPE_TEMPLATE_PARM:
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001353 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0,
1354 QualType(),0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001355 break;
1356 case pch::DECL_TEMPLATE_TEMPLATE_PARM:
1357 assert(false && "cannot read TemplateTemplateParmDecl");
1358 break;
1359 case pch::DECL_STATIC_ASSERT:
1360 assert(false && "cannot read StaticAssertDecl");
1361 break;
1362
Chris Lattner8f63ab52009-04-27 06:01:06 +00001363 case pch::DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +00001364 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001365 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001366 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001367 case pch::DECL_OBJC_INTERFACE:
Chris Lattner8575daa2009-04-27 21:45:14 +00001368 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001369 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001370 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001371 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001372 ObjCIvarDecl::None);
1373 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001374 case pch::DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001375 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001376 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001377 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001378 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001379 QualType(), 0);
1380 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001381 case pch::DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001382 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001383 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001384 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001385 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001386 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001387 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +00001388 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1389 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001390 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001391 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001392 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001393 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001394 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +00001395 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001396 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001397 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001398 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001399 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001400 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001401 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001402 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001403 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001404 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001405 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001406 SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001407 ObjCPropertyImplDecl::Dynamic, 0);
1408 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001409 case pch::DECL_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001410 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +00001411 false);
Chris Lattner487412d2009-04-27 05:27:42 +00001412 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001413 case pch::DECL_VAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001414 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001415 VarDecl::None, VarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001416 break;
1417
1418 case pch::DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001419 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001420 break;
1421
Chris Lattner8f63ab52009-04-27 06:01:06 +00001422 case pch::DECL_PARM_VAR:
Mike Stump11289f42009-09-09 15:08:12 +00001423 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001424 VarDecl::None, VarDecl::None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001425 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001426 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001427 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001428 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001429 case pch::DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +00001430 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001431 break;
1432 }
Chris Lattner487412d2009-04-27 05:27:42 +00001433
1434 assert(D && "Unknown declaration reading PCH file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001435 LoadedDecl(Index, D);
1436 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001437
1438 // If this declaration is also a declaration context, get the
1439 // offsets for its tables of lexical and visible declarations.
1440 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1441 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1442 if (Offsets.first || Offsets.second) {
1443 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1444 DC->setHasExternalVisibleStorage(Offsets.second != 0);
1445 DeclContextOffsets[DC] = Offsets;
1446 }
1447 }
1448 assert(Idx == Record.size());
1449
1450 // If we have deserialized a declaration that has a definition the
1451 // AST consumer might need to know about, notify the consumer
1452 // about that definition now or queue it for later.
1453 if (isConsumerInterestedIn(D)) {
1454 if (Consumer) {
1455 DeclGroupRef DG(D);
1456 Consumer->HandleTopLevelDecl(DG);
1457 } else {
1458 InterestingDecls.push_back(D);
1459 }
1460 }
1461
1462 return D;
1463}