blob: 9bc709907915aba3b5f0cdf9fca69149981ebd95 [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++];
671
672 // setBases() is unsuitable since it may try to iterate the bases of an
673 // unitialized base.
674 Data.NumBases = Record[Idx++];
675 Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases];
676 for (unsigned i = 0; i != Data.NumBases; ++i)
677 Data.Bases[i] = ReadCXXBaseSpecifier();
678
679 // FIXME: Make VBases lazily computed when needed to avoid storing them.
680 Data.NumVBases = Record[Idx++];
681 Data.VBases = new(C) CXXBaseSpecifier [Data.NumVBases];
682 for (unsigned i = 0; i != Data.NumVBases; ++i)
683 Data.VBases[i] = ReadCXXBaseSpecifier();
684
685 Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx);
686 Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx);
687 Data.Definition = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
688 Data.FirstFriend
689 = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
690 }
691 } else {
692 D->DefinitionData = D->getPreviousDeclaration()->DefinitionData;
693 }
694
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000695 enum CXXRecKind {
696 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
697 };
698 switch ((CXXRecKind)Record[Idx++]) {
699 default:
700 assert(false && "Out of sync with PCHDeclWriter::VisitCXXRecordDecl?");
701 case CXXRecNotTemplate:
702 break;
703 case CXXRecTemplate:
704 D->setDescribedClassTemplate(
705 cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++])));
706 break;
707 case CXXRecMemberSpecialization: {
708 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
709 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
710 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
711 D->setInstantiationOfMemberClass(RD, TSK);
712 D->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
713 break;
714 }
715 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000716}
717
718void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000719 VisitFunctionDecl(D);
720}
721
722void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000723 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000724
725 D->IsExplicitSpecified = Record[Idx++];
726 D->ImplicitlyDefined = Record[Idx++];
727
728 unsigned NumInitializers = Record[Idx++];
729 D->NumBaseOrMemberInitializers = NumInitializers;
730 if (NumInitializers) {
731 ASTContext &C = *Reader.getContext();
732
733 D->BaseOrMemberInitializers
734 = new (C) CXXBaseOrMemberInitializer*[NumInitializers];
735 for (unsigned i=0; i != NumInitializers; ++i) {
736 TypeSourceInfo *BaseClassInfo;
737 bool IsBaseVirtual;
738 FieldDecl *Member;
739
740 bool IsBaseInitializer = Record[Idx++];
741 if (IsBaseInitializer) {
742 BaseClassInfo = Reader.GetTypeSourceInfo(Record, Idx);
743 IsBaseVirtual = Record[Idx++];
744 } else {
745 Member = cast<FieldDecl>(Reader.GetDecl(Record[Idx++]));
746 }
747 SourceLocation MemberLoc = Reader.ReadSourceLocation(Record, Idx);
748 Expr *Init = Reader.ReadExpr();
749 FieldDecl *AnonUnionMember
750 = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
751 SourceLocation LParenLoc = Reader.ReadSourceLocation(Record, Idx);
752 SourceLocation RParenLoc = Reader.ReadSourceLocation(Record, Idx);
753 bool IsWritten = Record[Idx++];
754 unsigned SourceOrderOrNumArrayIndices;
755 llvm::SmallVector<VarDecl *, 8> Indices;
756 if (IsWritten) {
757 SourceOrderOrNumArrayIndices = Record[Idx++];
758 } else {
759 SourceOrderOrNumArrayIndices = Record[Idx++];
760 Indices.reserve(SourceOrderOrNumArrayIndices);
761 for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i)
762 Indices.push_back(cast<VarDecl>(Reader.GetDecl(Record[Idx++])));
763 }
764
765 CXXBaseOrMemberInitializer *BOMInit;
766 if (IsBaseInitializer) {
767 BOMInit = new (C) CXXBaseOrMemberInitializer(C, BaseClassInfo,
768 IsBaseVirtual, LParenLoc,
769 Init, RParenLoc);
770 } else if (IsWritten) {
771 BOMInit = new (C) CXXBaseOrMemberInitializer(C, Member, MemberLoc,
772 LParenLoc, Init, RParenLoc);
773 } else {
774 BOMInit = CXXBaseOrMemberInitializer::Create(C, Member, MemberLoc,
775 LParenLoc, Init, RParenLoc,
776 Indices.data(),
777 Indices.size());
778 }
779
780 BOMInit->setAnonUnionMember(AnonUnionMember);
781 D->BaseOrMemberInitializers[i] = BOMInit;
782 }
783 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000784}
785
786void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000787 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000788
789 D->ImplicitlyDefined = Record[Idx++];
790 D->OperatorDelete = cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000791}
792
793void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000794 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000795 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000796}
797
Abramo Bagnarad7340582010-06-05 05:09:32 +0000798void PCHDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
799 VisitDecl(D);
800 D->setColonLoc(Reader.ReadSourceLocation(Record, Idx));
801}
802
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000803void PCHDeclReader::VisitFriendDecl(FriendDecl *D) {
804 if (Record[Idx++])
805 D->Friend = Reader.GetTypeSourceInfo(Record, Idx);
806 else
807 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
808 D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
809 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
810}
811
Chris Lattnerca025db2010-05-07 21:43:38 +0000812void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
813 assert(false && "cannot read FriendTemplateDecl");
814}
815
816void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000817 VisitNamedDecl(D);
818
819 NamedDecl *TemplatedDecl = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000820 TemplateParameterList* TemplateParams
821 = Reader.ReadTemplateParameterList(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000822 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +0000823}
824
825void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000826 VisitTemplateDecl(D);
827
828 ClassTemplateDecl *PrevDecl =
829 cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +0000830 D->setPreviousDeclaration(PrevDecl);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000831 if (PrevDecl == 0) {
832 // This ClassTemplateDecl owns a CommonPtr; read it.
833
834 unsigned size = Record[Idx++];
835 while (size--) {
836 ClassTemplateSpecializationDecl *CTSD
837 = cast<ClassTemplateSpecializationDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidise23371e2010-07-02 11:55:37 +0000838 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
839 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000840 llvm::FoldingSetNodeID ID;
841 void *InsertPos = 0;
Argyrios Kyrtzidise23371e2010-07-02 11:55:37 +0000842 ClassTemplateSpecializationDecl::Profile(ID, TemplArgs.data(),
843 TemplArgs.size(),
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000844 *Reader.getContext());
845 D->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
846 D->getSpecializations().InsertNode(CTSD, InsertPos);
847 }
848
849 size = Record[Idx++];
850 while (size--) {
851 ClassTemplatePartialSpecializationDecl *CTSD
852 = cast<ClassTemplatePartialSpecializationDecl>(
853 Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidise23371e2010-07-02 11:55:37 +0000854 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
855 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000856 llvm::FoldingSetNodeID ID;
857 void *InsertPos = 0;
Argyrios Kyrtzidise23371e2010-07-02 11:55:37 +0000858 ClassTemplatePartialSpecializationDecl::Profile(ID, TemplArgs.data(),
859 TemplArgs.size(),
860 *Reader.getContext());
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000861 D->getPartialSpecializations().FindNodeOrInsertPos(ID, InsertPos);
862 D->getPartialSpecializations().InsertNode(CTSD, InsertPos);
863 }
864
865 // InjectedClassNameType is computed.
866
867 if (ClassTemplateDecl *CTD
868 = cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
869 D->setInstantiatedFromMemberTemplate(CTD);
870 if (Record[Idx++])
871 D->setMemberSpecialization();
872 }
873 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000874}
875
876void PCHDeclReader::VisitClassTemplateSpecializationDecl(
877 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000878 VisitCXXRecordDecl(D);
879
880 if (Decl *InstD = Reader.GetDecl(Record[Idx++])) {
881 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
882 D->setInstantiationOf(CTD);
883 } else {
884 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
885 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
886 D->setInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(InstD),
887 TemplArgs.data(), TemplArgs.size());
888 }
889 }
890
891 // Explicit info.
892 if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Record, Idx)) {
893 D->setTypeAsWritten(TyInfo);
894 D->setExternLoc(Reader.ReadSourceLocation(Record, Idx));
895 D->setTemplateKeywordLoc(Reader.ReadSourceLocation(Record, Idx));
896 }
897
898 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
899 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
900 D->initTemplateArgs(TemplArgs.data(), TemplArgs.size());
901 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
902 if (POI.isValid())
903 D->setPointOfInstantiation(POI);
904 D->setSpecializationKind((TemplateSpecializationKind)Record[Idx++]);
Chris Lattnerca025db2010-05-07 21:43:38 +0000905}
906
907void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl(
908 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000909 VisitClassTemplateSpecializationDecl(D);
910
911 D->initTemplateParameters(Reader.ReadTemplateParameterList(Record, Idx));
912
913 TemplateArgumentListInfo ArgInfos;
914 unsigned NumArgs = Record[Idx++];
915 while (NumArgs--)
916 ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
917 D->initTemplateArgsAsWritten(ArgInfos);
918
919 D->setSequenceNumber(Record[Idx++]);
920
921 // These are read/set from/to the first declaration.
922 if (D->getPreviousDeclaration() == 0) {
923 D->setInstantiatedFromMember(
924 cast_or_null<ClassTemplatePartialSpecializationDecl>(
925 Reader.GetDecl(Record[Idx++])));
926 if (Record[Idx++])
927 D->isMemberSpecialization();
928 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000929}
930
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000931void PCHDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
932 VisitTemplateDecl(D);
933
934 FunctionTemplateDecl *PrevDecl =
935 cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
936 D->setPreviousDeclaration(PrevDecl);
937 if (PrevDecl == 0) {
938 // This FunctionTemplateDecl owns a CommonPtr; read it.
939
940 // FunctionTemplateSpecializationInfos are filled through the
941 // templated FunctionDecl's setFunctionTemplateSpecialization, no need to
942 // read them here.
943
944 if (FunctionTemplateDecl *CTD
945 = cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
946 D->setInstantiatedFromMemberTemplate(CTD);
947 if (Record[Idx++])
948 D->setMemberSpecialization();
949 }
950 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000951}
952
953void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000954 VisitTypeDecl(D);
955
956 D->setDeclaredWithTypename(Record[Idx++]);
957 D->setParameterPack(Record[Idx++]);
958
959 bool Inherited = Record[Idx++];
960 TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Record, Idx);
961 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +0000962}
963
964void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +0000965 VisitVarDecl(D);
966 // TemplateParmPosition.
967 D->setDepth(Record[Idx++]);
968 D->setPosition(Record[Idx++]);
969 // Rest of NonTypeTemplateParmDecl.
970 if (Record[Idx++]) {
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000971 Expr *DefArg = Reader.ReadExpr();
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +0000972 bool Inherited = Record[Idx++];
973 D->setDefaultArgument(DefArg, Inherited);
974 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000975}
976
977void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
978 assert(false && "cannot read TemplateTemplateParmDecl");
979}
980
981void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
982 assert(false && "cannot read StaticAssertDecl");
983}
984
Mike Stump11289f42009-09-09 15:08:12 +0000985std::pair<uint64_t, uint64_t>
Chris Lattner487412d2009-04-27 05:27:42 +0000986PCHDeclReader::VisitDeclContext(DeclContext *DC) {
987 uint64_t LexicalOffset = Record[Idx++];
988 uint64_t VisibleOffset = Record[Idx++];
989 return std::make_pair(LexicalOffset, VisibleOffset);
990}
991
992//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +0000993// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +0000994//===----------------------------------------------------------------------===//
995
Chris Lattner8f63ab52009-04-27 06:01:06 +0000996/// \brief Reads attributes from the current stream position.
997Attr *PCHReader::ReadAttributes() {
998 unsigned Code = DeclsCursor.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +0000999 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner8f63ab52009-04-27 06:01:06 +00001000 "Expected unabbreviated record"); (void)Code;
Mike Stump11289f42009-09-09 15:08:12 +00001001
Chris Lattner8f63ab52009-04-27 06:01:06 +00001002 RecordData Record;
1003 unsigned Idx = 0;
1004 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump11289f42009-09-09 15:08:12 +00001005 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001006 (void)RecCode;
1007
1008#define SIMPLE_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001009 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +00001010 New = ::new (*Context) Name##Attr(); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001011 break
1012
1013#define STRING_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001014 case attr::Name: \
Ted Kremenek7f4945a2010-02-11 05:28:37 +00001015 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001016 break
1017
1018#define UNSIGNED_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001019 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +00001020 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001021 break
1022
1023 Attr *Attrs = 0;
1024 while (Idx < Record.size()) {
1025 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001026 attr::Kind Kind = (attr::Kind)Record[Idx++];
Chris Lattner8f63ab52009-04-27 06:01:06 +00001027 bool IsInherited = Record[Idx++];
1028
1029 switch (Kind) {
Anton Korobeynikov55bcea12010-01-10 12:58:08 +00001030 default:
1031 assert(0 && "Unknown attribute!");
1032 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001033 STRING_ATTR(Alias);
Daniel Dunbarfc6507e2010-05-27 02:25:39 +00001034 SIMPLE_ATTR(AlignMac68k);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001035 UNSIGNED_ATTR(Aligned);
1036 SIMPLE_ATTR(AlwaysInline);
1037 SIMPLE_ATTR(AnalyzerNoReturn);
1038 STRING_ATTR(Annotate);
1039 STRING_ATTR(AsmLabel);
Alexis Hunt54a02542009-11-25 04:20:27 +00001040 SIMPLE_ATTR(BaseCheck);
Mike Stump11289f42009-09-09 15:08:12 +00001041
Alexis Hunt344393e2010-06-16 23:43:53 +00001042 case attr::Blocks:
Chris Lattner8575daa2009-04-27 21:45:14 +00001043 New = ::new (*Context) BlocksAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001044 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
1045 break;
Mike Stump11289f42009-09-09 15:08:12 +00001046
Eli Friedmane4310c82009-11-09 18:38:53 +00001047 SIMPLE_ATTR(CDecl);
1048
Alexis Hunt344393e2010-06-16 23:43:53 +00001049 case attr::Cleanup:
Chris Lattner8575daa2009-04-27 21:45:14 +00001050 New = ::new (*Context) CleanupAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001051 cast<FunctionDecl>(GetDecl(Record[Idx++])));
1052 break;
1053
1054 SIMPLE_ATTR(Const);
1055 UNSIGNED_ATTR(Constructor);
1056 SIMPLE_ATTR(DLLExport);
1057 SIMPLE_ATTR(DLLImport);
1058 SIMPLE_ATTR(Deprecated);
1059 UNSIGNED_ATTR(Destructor);
1060 SIMPLE_ATTR(FastCall);
Alexis Hunt96d5c762009-11-21 08:43:09 +00001061 SIMPLE_ATTR(Final);
Mike Stump11289f42009-09-09 15:08:12 +00001062
Alexis Hunt344393e2010-06-16 23:43:53 +00001063 case attr::Format: {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001064 std::string Type = ReadString(Record, Idx);
1065 unsigned FormatIdx = Record[Idx++];
1066 unsigned FirstArg = Record[Idx++];
Ted Kremenek7f4945a2010-02-11 05:28:37 +00001067 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001068 break;
1069 }
Mike Stump11289f42009-09-09 15:08:12 +00001070
Alexis Hunt344393e2010-06-16 23:43:53 +00001071 case attr::FormatArg: {
Fariborz Jahanianf1c25022009-05-20 17:41:43 +00001072 unsigned FormatIdx = Record[Idx++];
1073 New = ::new (*Context) FormatArgAttr(FormatIdx);
1074 break;
1075 }
Mike Stump11289f42009-09-09 15:08:12 +00001076
Alexis Hunt344393e2010-06-16 23:43:53 +00001077 case attr::Sentinel: {
Fariborz Jahanian027b8862009-05-13 18:09:35 +00001078 int sentinel = Record[Idx++];
1079 int nullPos = Record[Idx++];
1080 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
1081 break;
1082 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001083
1084 SIMPLE_ATTR(GNUInline);
Alexis Hunt54a02542009-11-25 04:20:27 +00001085 SIMPLE_ATTR(Hiding);
Mike Stump11289f42009-09-09 15:08:12 +00001086
Alexis Hunt344393e2010-06-16 23:43:53 +00001087 case attr::IBAction:
Ted Kremenek06be9682010-02-17 02:37:45 +00001088 New = ::new (*Context) IBActionAttr();
1089 break;
1090
Alexis Hunt344393e2010-06-16 23:43:53 +00001091 case attr::IBOutlet:
Chris Lattner8575daa2009-04-27 21:45:14 +00001092 New = ::new (*Context) IBOutletAttr();
Chris Lattner8f63ab52009-04-27 06:01:06 +00001093 break;
1094
Alexis Hunt344393e2010-06-16 23:43:53 +00001095 case attr::IBOutletCollection: {
Ted Kremenek26bde772010-05-19 17:38:06 +00001096 ObjCInterfaceDecl *D =
1097 cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++]));
1098 New = ::new (*Context) IBOutletCollectionAttr(D);
1099 break;
1100 }
1101
Ryan Flynn1f1fdc02009-08-09 20:07:29 +00001102 SIMPLE_ATTR(Malloc);
Mike Stump3722f582009-08-26 22:31:08 +00001103 SIMPLE_ATTR(NoDebug);
1104 SIMPLE_ATTR(NoInline);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001105 SIMPLE_ATTR(NoReturn);
1106 SIMPLE_ATTR(NoThrow);
Mike Stump11289f42009-09-09 15:08:12 +00001107
Alexis Hunt344393e2010-06-16 23:43:53 +00001108 case attr::NonNull: {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001109 unsigned Size = Record[Idx++];
1110 llvm::SmallVector<unsigned, 16> ArgNums;
1111 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
1112 Idx += Size;
Ted Kremenek510ee252010-02-11 07:31:47 +00001113 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001114 break;
1115 }
Mike Stump11289f42009-09-09 15:08:12 +00001116
Alexis Hunt344393e2010-06-16 23:43:53 +00001117 case attr::ReqdWorkGroupSize: {
Nate Begemanf2758702009-06-26 06:32:41 +00001118 unsigned X = Record[Idx++];
1119 unsigned Y = Record[Idx++];
1120 unsigned Z = Record[Idx++];
1121 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
1122 break;
1123 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001124
1125 SIMPLE_ATTR(ObjCException);
1126 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekd9c66632010-02-18 00:05:45 +00001127 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +00001128 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenekd9c66632010-02-18 00:05:45 +00001129 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +00001130 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001131 SIMPLE_ATTR(Overloadable);
Alexis Hunt54a02542009-11-25 04:20:27 +00001132 SIMPLE_ATTR(Override);
Anders Carlsson68e0b682009-08-08 18:23:56 +00001133 SIMPLE_ATTR(Packed);
Daniel Dunbar40130442010-05-27 01:12:46 +00001134 UNSIGNED_ATTR(MaxFieldAlignment);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001135 SIMPLE_ATTR(Pure);
1136 UNSIGNED_ATTR(Regparm);
1137 STRING_ATTR(Section);
1138 SIMPLE_ATTR(StdCall);
Douglas Gregora941dca2010-05-18 16:57:00 +00001139 SIMPLE_ATTR(ThisCall);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001140 SIMPLE_ATTR(TransparentUnion);
1141 SIMPLE_ATTR(Unavailable);
1142 SIMPLE_ATTR(Unused);
1143 SIMPLE_ATTR(Used);
Mike Stump11289f42009-09-09 15:08:12 +00001144
Alexis Hunt344393e2010-06-16 23:43:53 +00001145 case attr::Visibility:
Chris Lattner8575daa2009-04-27 21:45:14 +00001146 New = ::new (*Context) VisibilityAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001147 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
1148 break;
1149
1150 SIMPLE_ATTR(WarnUnusedResult);
1151 SIMPLE_ATTR(Weak);
Rafael Espindolac18086a2010-02-23 22:00:30 +00001152 SIMPLE_ATTR(WeakRef);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001153 SIMPLE_ATTR(WeakImport);
1154 }
1155
1156 assert(New && "Unable to decode attribute?");
1157 New->setInherited(IsInherited);
1158 New->setNext(Attrs);
1159 Attrs = New;
1160 }
1161#undef UNSIGNED_ATTR
1162#undef STRING_ATTR
1163#undef SIMPLE_ATTR
1164
1165 // The list of attributes was built backwards. Reverse the list
1166 // before returning it.
1167 Attr *PrevAttr = 0, *NextAttr = 0;
1168 while (Attrs) {
1169 NextAttr = Attrs->getNext();
1170 Attrs->setNext(PrevAttr);
1171 PrevAttr = Attrs;
1172 Attrs = NextAttr;
1173 }
1174
1175 return PrevAttr;
1176}
1177
1178//===----------------------------------------------------------------------===//
1179// PCHReader Implementation
1180//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001181
1182/// \brief Note that we have loaded the declaration with the given
1183/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001184///
Chris Lattner487412d2009-04-27 05:27:42 +00001185/// This routine notes that this declaration has already been loaded,
1186/// so that future GetDecl calls will return this declaration rather
1187/// than trying to load a new declaration.
1188inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
1189 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1190 DeclsLoaded[Index] = D;
1191}
1192
1193
1194/// \brief Determine whether the consumer will be interested in seeing
1195/// this declaration (via HandleTopLevelDecl).
1196///
1197/// This routine should return true for anything that might affect
1198/// code generation, e.g., inline function definitions, Objective-C
1199/// declarations with metadata, etc.
1200static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001201 if (isa<FileScopeAsmDecl>(D))
1202 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001203 if (VarDecl *Var = dyn_cast<VarDecl>(D))
1204 return Var->isFileVarDecl() && Var->getInit();
1205 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1206 return Func->isThisDeclarationADefinition();
1207 return isa<ObjCProtocolDecl>(D);
1208}
1209
1210/// \brief Read the declaration at the given offset from the PCH file.
1211Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
1212 // Keep track of where we are in the stream, then jump back there
1213 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001214 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001215
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001216 ReadingKindTracker ReadingKind(Read_Decl, *this);
1217
Douglas Gregor1342e842009-07-06 18:54:52 +00001218 // Note that we are loading a declaration record.
1219 LoadingTypeOrDecl Loading(*this);
Mike Stump11289f42009-09-09 15:08:12 +00001220
Chris Lattner1de76db2009-04-27 05:58:23 +00001221 DeclsCursor.JumpToBit(Offset);
Chris Lattner487412d2009-04-27 05:27:42 +00001222 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001223 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001224 unsigned Idx = 0;
1225 PCHDeclReader Reader(*this, Record, Idx);
1226
Chris Lattner1de76db2009-04-27 05:58:23 +00001227 Decl *D = 0;
1228 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner487412d2009-04-27 05:27:42 +00001229 case pch::DECL_ATTR:
1230 case pch::DECL_CONTEXT_LEXICAL:
1231 case pch::DECL_CONTEXT_VISIBLE:
1232 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1233 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001234 case pch::DECL_TRANSLATION_UNIT:
1235 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +00001236 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +00001237 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001238 case pch::DECL_TYPEDEF:
John McCall703a3f82009-10-24 08:00:42 +00001239 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001240 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001241 case pch::DECL_ENUM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001242 D = EnumDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001243 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001244 case pch::DECL_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001245 D = RecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001246 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001247 case pch::DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +00001248 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001249 0, llvm::APSInt());
1250 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001251 case pch::DECL_FUNCTION:
Mike Stump11289f42009-09-09 15:08:12 +00001252 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001253 QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001254 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001255 case pch::DECL_LINKAGE_SPEC:
1256 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
1257 (LinkageSpecDecl::LanguageIDs)0,
1258 false);
1259 break;
1260 case pch::DECL_NAMESPACE:
1261 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
1262 break;
1263 case pch::DECL_NAMESPACE_ALIAS:
1264 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
1265 SourceLocation(), 0, SourceRange(), 0,
1266 SourceLocation(), 0);
1267 break;
1268 case pch::DECL_USING:
1269 D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(),
1270 SourceLocation(), 0, DeclarationName(), false);
1271 break;
1272 case pch::DECL_USING_SHADOW:
1273 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1274 break;
1275 case pch::DECL_USING_DIRECTIVE:
1276 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
1277 SourceLocation(), SourceRange(), 0,
1278 SourceLocation(), 0, 0);
1279 break;
1280 case pch::DECL_UNRESOLVED_USING_VALUE:
1281 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
1282 SourceRange(), 0, SourceLocation(),
1283 DeclarationName());
1284 break;
1285 case pch::DECL_UNRESOLVED_USING_TYPENAME:
1286 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
1287 SourceLocation(), SourceRange(),
1288 0, SourceLocation(),
1289 DeclarationName());
1290 break;
1291 case pch::DECL_CXX_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001292 D = CXXRecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001293 break;
1294 case pch::DECL_CXX_METHOD:
1295 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
1296 QualType(), 0);
1297 break;
1298 case pch::DECL_CXX_CONSTRUCTOR:
1299 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1300 break;
1301 case pch::DECL_CXX_DESTRUCTOR:
1302 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1303 break;
1304 case pch::DECL_CXX_CONVERSION:
1305 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1306 break;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001307 case pch::DECL_ACCESS_SPEC:
1308 D = AccessSpecDecl::Create(*Context, AS_none, 0, SourceLocation(),
1309 SourceLocation());
1310 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001311 case pch::DECL_FRIEND:
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001312 D = FriendDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001313 break;
1314 case pch::DECL_FRIEND_TEMPLATE:
1315 assert(false && "cannot read FriendTemplateDecl");
1316 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001317 case pch::DECL_CLASS_TEMPLATE:
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +00001318 D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(),
1319 DeclarationName(), 0, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001320 break;
1321 case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001322 D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001323 break;
1324 case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001325 D = ClassTemplatePartialSpecializationDecl::Create(*Context,
1326 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001327 break;
1328 case pch::DECL_FUNCTION_TEMPLATE:
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001329 D = FunctionTemplateDecl::Create(*Context, 0, SourceLocation(),
1330 DeclarationName(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001331 break;
1332 case pch::DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001333 D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001334 break;
1335 case pch::DECL_NON_TYPE_TEMPLATE_PARM:
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001336 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0,
1337 QualType(),0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001338 break;
1339 case pch::DECL_TEMPLATE_TEMPLATE_PARM:
1340 assert(false && "cannot read TemplateTemplateParmDecl");
1341 break;
1342 case pch::DECL_STATIC_ASSERT:
1343 assert(false && "cannot read StaticAssertDecl");
1344 break;
1345
Chris Lattner8f63ab52009-04-27 06:01:06 +00001346 case pch::DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +00001347 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001348 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001349 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001350 case pch::DECL_OBJC_INTERFACE:
Chris Lattner8575daa2009-04-27 21:45:14 +00001351 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001352 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001353 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001354 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001355 ObjCIvarDecl::None);
1356 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001357 case pch::DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001358 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001359 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001360 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001361 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001362 QualType(), 0);
1363 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001364 case pch::DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001365 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001366 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001367 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001368 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001369 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001370 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +00001371 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1372 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001373 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001374 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001375 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001376 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001377 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +00001378 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001379 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001380 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001381 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001382 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001383 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001384 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001385 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001386 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001387 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001388 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001389 SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001390 ObjCPropertyImplDecl::Dynamic, 0);
1391 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001392 case pch::DECL_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001393 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +00001394 false);
Chris Lattner487412d2009-04-27 05:27:42 +00001395 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001396 case pch::DECL_VAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001397 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001398 VarDecl::None, VarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001399 break;
1400
1401 case pch::DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001402 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001403 break;
1404
Chris Lattner8f63ab52009-04-27 06:01:06 +00001405 case pch::DECL_PARM_VAR:
Mike Stump11289f42009-09-09 15:08:12 +00001406 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001407 VarDecl::None, VarDecl::None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001408 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001409 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001410 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001411 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001412 case pch::DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +00001413 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001414 break;
1415 }
Chris Lattner487412d2009-04-27 05:27:42 +00001416
1417 assert(D && "Unknown declaration reading PCH file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001418 LoadedDecl(Index, D);
1419 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001420
1421 // If this declaration is also a declaration context, get the
1422 // offsets for its tables of lexical and visible declarations.
1423 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1424 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1425 if (Offsets.first || Offsets.second) {
1426 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1427 DC->setHasExternalVisibleStorage(Offsets.second != 0);
1428 DeclContextOffsets[DC] = Offsets;
1429 }
1430 }
1431 assert(Idx == Record.size());
1432
1433 // If we have deserialized a declaration that has a definition the
1434 // AST consumer might need to know about, notify the consumer
1435 // about that definition now or queue it for later.
1436 if (isConsumerInterestedIn(D)) {
1437 if (Consumer) {
1438 DeclGroupRef DG(D);
1439 Consumer->HandleTopLevelDecl(DG);
1440 } else {
1441 InterestingDecls.push_back(D);
1442 }
1443 }
1444
1445 return D;
1446}