blob: 94485d2d8f8eadf7e476721827d36f1fbe364b56 [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;
Sebastian Redlc67764e2010-07-22 22:43:28 +000033 llvm::BitstreamCursor &Cursor;
Chris Lattner487412d2009-04-27 05:27:42 +000034 const PCHReader::RecordData &Record;
35 unsigned &Idx;
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +000036 pch::TypeID TypeIDForTypeDecl;
Chris Lattner487412d2009-04-27 05:27:42 +000037
Sebastian Redlc67764e2010-07-22 22:43:28 +000038 uint64_t GetCurrentCursorOffset();
39
Chris Lattner487412d2009-04-27 05:27:42 +000040 public:
Sebastian Redlc67764e2010-07-22 22:43:28 +000041 PCHDeclReader(PCHReader &Reader, llvm::BitstreamCursor &Cursor,
42 const PCHReader::RecordData &Record, unsigned &Idx)
43 : Reader(Reader), Cursor(Cursor), Record(Record), Idx(Idx),
44 TypeIDForTypeDecl(0) { }
Chris Lattner487412d2009-04-27 05:27:42 +000045
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +000046 void Visit(Decl *D);
47
Chris Lattner487412d2009-04-27 05:27:42 +000048 void VisitDecl(Decl *D);
49 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
50 void VisitNamedDecl(NamedDecl *ND);
Douglas Gregore31bbd92010-02-21 18:22:14 +000051 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000052 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
53 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000054 void VisitTypeDecl(TypeDecl *TD);
55 void VisitTypedefDecl(TypedefDecl *TD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000056 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000057 void VisitTagDecl(TagDecl *TD);
58 void VisitEnumDecl(EnumDecl *ED);
59 void VisitRecordDecl(RecordDecl *RD);
Chris Lattnerca025db2010-05-07 21:43:38 +000060 void VisitCXXRecordDecl(CXXRecordDecl *D);
61 void VisitClassTemplateSpecializationDecl(
62 ClassTemplateSpecializationDecl *D);
63 void VisitClassTemplatePartialSpecializationDecl(
64 ClassTemplatePartialSpecializationDecl *D);
65 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000066 void VisitValueDecl(ValueDecl *VD);
67 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000068 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +000069 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +000070 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattnerca025db2010-05-07 21:43:38 +000071 void VisitCXXMethodDecl(CXXMethodDecl *D);
72 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
73 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
74 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000075 void VisitFieldDecl(FieldDecl *FD);
76 void VisitVarDecl(VarDecl *VD);
77 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
78 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattnerca025db2010-05-07 21:43:38 +000079 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
80 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +000081 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000082 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +000083 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000084 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +000085 void VisitUsingDecl(UsingDecl *D);
86 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000087 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000088 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Abramo Bagnarad7340582010-06-05 05:09:32 +000089 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000090 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000091 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
92 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000093 void VisitBlockDecl(BlockDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +000094
Chris Lattner487412d2009-04-27 05:27:42 +000095 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Chris Lattnerca025db2010-05-07 21:43:38 +000096
Alexis Hunted053252010-05-30 07:21:58 +000097 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-04-27 05:27:42 +000098 void VisitObjCMethodDecl(ObjCMethodDecl *D);
99 void VisitObjCContainerDecl(ObjCContainerDecl *D);
100 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
101 void VisitObjCIvarDecl(ObjCIvarDecl *D);
102 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
103 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
104 void VisitObjCClassDecl(ObjCClassDecl *D);
105 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
106 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
107 void VisitObjCImplDecl(ObjCImplDecl *D);
108 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
109 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
110 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
111 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
112 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
113 };
114}
115
Sebastian Redlc67764e2010-07-22 22:43:28 +0000116uint64_t PCHDeclReader::GetCurrentCursorOffset() {
117 uint64_t Off = 0;
118 for (unsigned I = 0, N = Reader.Chain.size(); I != N; ++I) {
119 PCHReader::PerFileData &F = *Reader.Chain[N - I - 1];
120 if (&Cursor == &F.DeclsCursor) {
121 Off += F.DeclsCursor.GetCurrentBitNo();
122 break;
123 }
124 Off += F.SizeInBits;
125 }
126 return Off;
127}
128
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000129void PCHDeclReader::Visit(Decl *D) {
130 DeclVisitor<PCHDeclReader, void>::Visit(D);
131
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000132 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
133 // if we have a fully initialized TypeDecl, we can safely read its type now.
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000134 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtr());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000135 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
136 // FunctionDecl's body was written last after all other Stmts/Exprs.
137 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000138 FD->setLazyBody(GetCurrentCursorOffset());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000139 }
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000140}
141
Chris Lattner487412d2009-04-27 05:27:42 +0000142void PCHDeclReader::VisitDecl(Decl *D) {
143 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
144 D->setLexicalDeclContext(
145 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
146 D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
147 D->setInvalidDecl(Record[Idx++]);
148 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000149 D->initAttrs(Reader.ReadAttributes(Cursor));
Chris Lattner487412d2009-04-27 05:27:42 +0000150 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +0000151 D->setUsed(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000152 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor16bef852009-10-16 20:01:17 +0000153 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner487412d2009-04-27 05:27:42 +0000154}
155
156void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
157 VisitDecl(TU);
Chris Lattnerca025db2010-05-07 21:43:38 +0000158 TU->setAnonymousNamespace(
159 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000160}
161
162void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) {
163 VisitDecl(ND);
Mike Stump11289f42009-09-09 15:08:12 +0000164 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000165}
166
167void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
168 VisitNamedDecl(TD);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000169 // Delay type reading until after we have fully initialized the decl.
170 TypeIDForTypeDecl = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000171}
172
173void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000174 VisitTypeDecl(TD);
Sebastian Redlc67764e2010-07-22 22:43:28 +0000175 TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000176}
177
178void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
179 VisitTypeDecl(TD);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000180 TD->IdentifierNamespace = Record[Idx++];
Douglas Gregorb6b8f9e2009-07-29 23:36:44 +0000181 TD->setPreviousDeclaration(
182 cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000183 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
184 TD->setDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000185 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis664b6902009-07-14 03:18:02 +0000186 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000187 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall3e11ebe2010-03-15 10:12:16 +0000188 // FIXME: maybe read optional qualifier and its range.
189 TD->setTypedefForAnonDecl(
190 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000191}
192
193void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
194 VisitTagDecl(ED);
195 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall56774992009-12-09 09:09:27 +0000196 ED->setPromotionType(Reader.GetType(Record[Idx++]));
John McCall9aa35be2010-05-06 08:49:23 +0000197 ED->setNumPositiveBits(Record[Idx++]);
198 ED->setNumNegativeBits(Record[Idx++]);
Argyrios Kyrtzidis282b36b2010-07-06 15:36:48 +0000199 ED->setInstantiationOfMemberEnum(
200 cast_or_null<EnumDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000201}
202
203void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
204 VisitTagDecl(RD);
205 RD->setHasFlexibleArrayMember(Record[Idx++]);
206 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000207 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000208}
209
210void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
211 VisitNamedDecl(VD);
212 VD->setType(Reader.GetType(Record[Idx++]));
213}
214
215void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
216 VisitValueDecl(ECD);
217 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000218 ECD->setInitExpr(Reader.ReadExpr(Cursor));
Chris Lattner487412d2009-04-27 05:27:42 +0000219 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
220}
221
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000222void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
223 VisitValueDecl(DD);
Sebastian Redlc67764e2010-07-22 22:43:28 +0000224 TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
John McCallbcd03502009-12-07 02:54:59 +0000225 if (TInfo)
226 DD->setTypeSourceInfo(TInfo);
John McCall3e11ebe2010-03-15 10:12:16 +0000227 // FIXME: read optional qualifier and its range.
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000228}
229
Chris Lattner487412d2009-04-27 05:27:42 +0000230void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000231 VisitDeclaratorDecl(FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000232
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000233 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000234 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000235 default: assert(false && "Unhandled TemplatedKind!");
236 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000237 case FunctionDecl::TK_NonTemplate:
238 break;
239 case FunctionDecl::TK_FunctionTemplate:
240 FD->setDescribedFunctionTemplate(
241 cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++])));
242 break;
243 case FunctionDecl::TK_MemberSpecialization: {
244 FunctionDecl *InstFD = cast<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
245 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
246 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
247 FD->setInstantiationOfMemberFunction(InstFD, TSK);
248 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
249 break;
250 }
251 case FunctionDecl::TK_FunctionTemplateSpecialization: {
252 FunctionTemplateDecl *Template
253 = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
254 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
255
256 // Template arguments.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000257 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000258 Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000259
260 // Template args as written.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000261 llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000262 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000263 if (Record[Idx++]) { // TemplateArgumentsAsWritten != 0
264 unsigned NumTemplateArgLocs = Record[Idx++];
265 TemplArgLocs.reserve(NumTemplateArgLocs);
266 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000267 TemplArgLocs.push_back(
268 Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx));
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000269
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000270 LAngleLoc = Reader.ReadSourceLocation(Record, Idx);
271 RAngleLoc = Reader.ReadSourceLocation(Record, Idx);
272 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000273
274 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000275
Argyrios Kyrtzidisdde57902010-07-20 13:59:58 +0000276 if (FD->isCanonicalDecl()) // if canonical add to template's set.
277 FD->setFunctionTemplateSpecialization(Template, TemplArgs.size(),
278 TemplArgs.data(), TSK,
279 TemplArgLocs.size(),
280 TemplArgLocs.data(),
281 LAngleLoc, RAngleLoc, POI);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000282 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000283 }
284 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
285 // Templates.
286 UnresolvedSet<8> TemplDecls;
287 unsigned NumTemplates = Record[Idx++];
288 while (NumTemplates--)
289 TemplDecls.addDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
290
291 // Templates args.
292 TemplateArgumentListInfo TemplArgs;
293 unsigned NumArgs = Record[Idx++];
294 while (NumArgs--)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000295 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Cursor,Record, Idx));
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000296 TemplArgs.setLAngleLoc(Reader.ReadSourceLocation(Record, Idx));
297 TemplArgs.setRAngleLoc(Reader.ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000298
299 FD->setDependentTemplateSpecialization(*Reader.getContext(),
300 TemplDecls, TemplArgs);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000301 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000302 }
303 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000304
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000305 // FunctionDecl's body is handled last at PCHReaderDecl::Visit,
306 // after everything else is read.
307
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000308 // Avoid side effects and invariant checking of FunctionDecl's
309 // setPreviousDeclaration.
310 FD->redeclarable_base::setPreviousDeclaration(
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000311 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
312 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
313 FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]);
314 FD->setInlineSpecified(Record[Idx++]);
315 FD->setVirtualAsWritten(Record[Idx++]);
316 FD->setPure(Record[Idx++]);
317 FD->setHasInheritedPrototype(Record[Idx++]);
318 FD->setHasWrittenPrototype(Record[Idx++]);
319 FD->setDeleted(Record[Idx++]);
320 FD->setTrivial(Record[Idx++]);
321 FD->setCopyAssignment(Record[Idx++]);
322 FD->setHasImplicitReturnZero(Record[Idx++]);
323 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
324
Chris Lattnerca025db2010-05-07 21:43:38 +0000325 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000326 unsigned NumParams = Record[Idx++];
327 llvm::SmallVector<ParmVarDecl *, 16> Params;
328 Params.reserve(NumParams);
329 for (unsigned I = 0; I != NumParams; ++I)
330 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000331 FD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000332}
333
334void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
335 VisitNamedDecl(MD);
336 if (Record[Idx++]) {
337 // In practice, this won't be executed (since method definitions
338 // don't occur in header files).
Sebastian Redlc67764e2010-07-22 22:43:28 +0000339 MD->setBody(Reader.ReadStmt(Cursor));
Chris Lattner487412d2009-04-27 05:27:42 +0000340 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
341 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
342 }
343 MD->setInstanceMethod(Record[Idx++]);
344 MD->setVariadic(Record[Idx++]);
345 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000346 MD->setDefined(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000347 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
348 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahaniand9235db2010-04-08 21:29:11 +0000349 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000350 MD->setResultType(Reader.GetType(Record[Idx++]));
Sebastian Redlc67764e2010-07-22 22:43:28 +0000351 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000352 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
353 unsigned NumParams = Record[Idx++];
354 llvm::SmallVector<ParmVarDecl *, 16> Params;
355 Params.reserve(NumParams);
356 for (unsigned I = 0; I != NumParams; ++I)
357 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniancdabb312010-04-09 15:40:42 +0000358 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
359 NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000360}
361
362void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
363 VisitNamedDecl(CD);
Ted Kremenekc7c64312010-01-07 01:20:12 +0000364 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
365 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
366 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner487412d2009-04-27 05:27:42 +0000367}
368
369void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
370 VisitObjCContainerDecl(ID);
371 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
372 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
373 (Reader.GetDecl(Record[Idx++])));
374 unsigned NumProtocols = Record[Idx++];
375 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
376 Protocols.reserve(NumProtocols);
377 for (unsigned I = 0; I != NumProtocols; ++I)
378 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000379 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
380 ProtoLocs.reserve(NumProtocols);
381 for (unsigned I = 0; I != NumProtocols; ++I)
382 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
383 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
384 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000385 unsigned NumIvars = Record[Idx++];
386 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
387 IVars.reserve(NumIvars);
388 for (unsigned I = 0; I != NumIvars; ++I)
389 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000390 ID->setCategoryList(
391 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
392 ID->setForwardDecl(Record[Idx++]);
393 ID->setImplicitInterfaceDecl(Record[Idx++]);
394 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
395 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisea72f422009-07-18 00:33:23 +0000396 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000397}
398
399void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
400 VisitFieldDecl(IVD);
401 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000402 bool synth = Record[Idx++];
403 IVD->setSynthesize(synth);
Chris Lattner487412d2009-04-27 05:27:42 +0000404}
405
406void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
407 VisitObjCContainerDecl(PD);
408 PD->setForwardDecl(Record[Idx++]);
409 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
410 unsigned NumProtoRefs = Record[Idx++];
411 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
412 ProtoRefs.reserve(NumProtoRefs);
413 for (unsigned I = 0; I != NumProtoRefs; ++I)
414 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000415 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
416 ProtoLocs.reserve(NumProtoRefs);
417 for (unsigned I = 0; I != NumProtoRefs; ++I)
418 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
419 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
420 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000421}
422
423void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
424 VisitFieldDecl(FD);
425}
426
427void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
428 VisitDecl(CD);
429 unsigned NumClassRefs = Record[Idx++];
430 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
431 ClassRefs.reserve(NumClassRefs);
432 for (unsigned I = 0; I != NumClassRefs; ++I)
433 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000434 llvm::SmallVector<SourceLocation, 16> SLocs;
435 SLocs.reserve(NumClassRefs);
436 for (unsigned I = 0; I != NumClassRefs; ++I)
437 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
438 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
439 NumClassRefs);
Chris Lattner487412d2009-04-27 05:27:42 +0000440}
441
442void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
443 VisitDecl(FPD);
444 unsigned NumProtoRefs = Record[Idx++];
445 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
446 ProtoRefs.reserve(NumProtoRefs);
447 for (unsigned I = 0; I != NumProtoRefs; ++I)
448 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000449 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
450 ProtoLocs.reserve(NumProtoRefs);
451 for (unsigned I = 0; I != NumProtoRefs; ++I)
452 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
453 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
454 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000455}
456
457void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
458 VisitObjCContainerDecl(CD);
459 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
460 unsigned NumProtoRefs = Record[Idx++];
461 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
462 ProtoRefs.reserve(NumProtoRefs);
463 for (unsigned I = 0; I != NumProtoRefs; ++I)
464 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000465 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
466 ProtoLocs.reserve(NumProtoRefs);
467 for (unsigned I = 0; I != NumProtoRefs; ++I)
468 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
469 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
470 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000471 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor071676f2010-01-16 16:38:58 +0000472 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
473 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000474}
475
476void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
477 VisitNamedDecl(CAD);
478 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
479}
480
481void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
482 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000483 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Sebastian Redlc67764e2010-07-22 22:43:28 +0000484 D->setType(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000485 // FIXME: stable encoding
486 D->setPropertyAttributes(
487 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000488 D->setPropertyAttributesAsWritten(
489 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000490 // FIXME: stable encoding
491 D->setPropertyImplementation(
492 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
493 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
494 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
495 D->setGetterMethodDecl(
496 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
497 D->setSetterMethodDecl(
498 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
499 D->setPropertyIvarDecl(
500 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
501}
502
503void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000504 VisitObjCContainerDecl(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000505 D->setClassInterface(
506 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000507}
508
509void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
510 VisitObjCImplDecl(D);
511 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
512}
513
514void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
515 VisitObjCImplDecl(D);
516 D->setSuperClass(
517 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanianc83726e2010-04-28 16:11:27 +0000518 // FIXME. Add reading of IvarInitializers and NumIvarInitializers.
Chris Lattner487412d2009-04-27 05:27:42 +0000519}
520
521
522void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
523 VisitDecl(D);
524 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
525 D->setPropertyDecl(
526 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
527 D->setPropertyIvarDecl(
528 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanian25491a22010-05-05 21:52:17 +0000529 // FIXME. read GetterCXXConstructor and SetterCXXAssignment
Chris Lattner487412d2009-04-27 05:27:42 +0000530}
531
532void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000533 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000534 FD->setMutable(Record[Idx++]);
535 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000536 FD->setBitWidth(Reader.ReadExpr(Cursor));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000537 if (!FD->getDeclName()) {
538 FieldDecl *Tmpl = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
539 if (Tmpl)
540 Reader.getContext()->setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
541 }
Chris Lattner487412d2009-04-27 05:27:42 +0000542}
543
544void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000545 VisitDeclaratorDecl(VD);
Chris Lattner487412d2009-04-27 05:27:42 +0000546 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
Douglas Gregorc4df4072010-04-19 22:54:31 +0000547 VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000548 VD->setThreadSpecified(Record[Idx++]);
549 VD->setCXXDirectInitializer(Record[Idx++]);
550 VD->setDeclaredInCondition(Record[Idx++]);
Douglas Gregor3f324d562010-05-03 18:51:14 +0000551 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor6fd1b182010-05-15 06:01:05 +0000552 VD->setNRVOVariable(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000553 VD->setPreviousDeclaration(
554 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000555 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000556 VD->setInit(Reader.ReadExpr(Cursor));
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000557
558 if (Record[Idx++]) { // HasMemberSpecializationInfo.
559 VarDecl *Tmpl = cast<VarDecl>(Reader.GetDecl(Record[Idx++]));
560 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
561 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
562 Reader.getContext()->setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
563 }
Chris Lattner487412d2009-04-27 05:27:42 +0000564}
565
566void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
567 VisitVarDecl(PD);
568}
569
570void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
571 VisitVarDecl(PD);
572 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallf3cd6652010-03-12 18:31:32 +0000573 PD->setHasInheritedDefaultArg(Record[Idx++]);
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000574 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redlc67764e2010-07-22 22:43:28 +0000575 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(Cursor));
Chris Lattner487412d2009-04-27 05:27:42 +0000576}
577
Chris Lattner487412d2009-04-27 05:27:42 +0000578void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
579 VisitDecl(AD);
Sebastian Redlc67764e2010-07-22 22:43:28 +0000580 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(Cursor)));
Chris Lattner487412d2009-04-27 05:27:42 +0000581}
582
583void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
584 VisitDecl(BD);
Sebastian Redlc67764e2010-07-22 22:43:28 +0000585 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(Cursor)));
586 BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000587 unsigned NumParams = Record[Idx++];
588 llvm::SmallVector<ParmVarDecl *, 16> Params;
589 Params.reserve(NumParams);
590 for (unsigned I = 0; I != NumParams; ++I)
591 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000592 BD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000593}
594
Chris Lattnerca025db2010-05-07 21:43:38 +0000595void PCHDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
596 VisitDecl(D);
597 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
598 D->setHasBraces(Record[Idx++]);
599}
600
601void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
602 VisitNamedDecl(D);
603 D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx));
604 D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx));
605 D->setNextNamespace(
606 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
607
Chris Lattnerca025db2010-05-07 21:43:38 +0000608 bool IsOriginal = Record[Idx++];
Argyrios Kyrtzidisdae2a162010-07-03 07:57:53 +0000609 D->OrigOrAnonNamespace.setInt(IsOriginal);
610 D->OrigOrAnonNamespace.setPointer(
Chris Lattnerca025db2010-05-07 21:43:38 +0000611 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
612}
613
614void PCHDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
615 VisitNamedDecl(D);
616
617 D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx));
618 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
619 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
620 D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx));
621 D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
622}
623
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000624void PCHDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000625 VisitNamedDecl(D);
626 D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
627 D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
628 D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
629
630 // FIXME: It would probably be more efficient to read these into a vector
631 // and then re-cosntruct the shadow decl set over that vector since it
632 // would avoid existence checks.
633 unsigned NumShadows = Record[Idx++];
634 for(unsigned I = 0; I != NumShadows; ++I) {
Argyrios Kyrtzidis00dda6a2010-07-08 13:09:41 +0000635 // Avoid invariant checking of UsingDecl::addShadowDecl, the decl may still
636 // be initializing.
637 D->Shadows.insert(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattnerca025db2010-05-07 21:43:38 +0000638 }
639 D->setTypeName(Record[Idx++]);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000640 NamedDecl *Pattern = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
641 if (Pattern)
642 Reader.getContext()->setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000643}
644
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000645void PCHDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000646 VisitNamedDecl(D);
647 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
648 D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000649 UsingShadowDecl *Pattern
650 = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]));
651 if (Pattern)
652 Reader.getContext()->setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000653}
654
655void PCHDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
656 VisitNamedDecl(D);
657 D->setNamespaceKeyLocation(Reader.ReadSourceLocation(Record, Idx));
658 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
659 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
660 D->setIdentLocation(Reader.ReadSourceLocation(Record, Idx));
661 D->setNominatedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
662 D->setCommonAncestor(cast_or_null<DeclContext>(
663 Reader.GetDecl(Record[Idx++])));
664}
665
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000666void PCHDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000667 VisitValueDecl(D);
668 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
669 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
670 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
671}
672
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000673void PCHDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000674 UnresolvedUsingTypenameDecl *D) {
675 VisitTypeDecl(D);
676 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
677 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
678 D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx));
679 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
680}
681
682void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000683 ASTContext &C = *Reader.getContext();
684
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000685 // We need to allocate the DefinitionData struct ahead of VisitRecordDecl
686 // so that the other CXXRecordDecls can get a pointer even when the owner
687 // is still initializing.
688 bool OwnsDefinitionData = false;
689 enum DataOwnership { Data_NoDefData, Data_Owner, Data_NotOwner };
690 switch ((DataOwnership)Record[Idx++]) {
691 default:
692 assert(0 && "Out of sync with PCHDeclWriter or messed up reading");
693 case Data_NoDefData:
694 break;
695 case Data_Owner:
696 OwnsDefinitionData = true;
697 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
698 break;
699 case Data_NotOwner:
700 D->DefinitionData
701 = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]))->DefinitionData;
702 break;
703 }
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000704
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000705 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000706
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000707 if (OwnsDefinitionData) {
708 assert(D->DefinitionData);
709 struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData;
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000710
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000711 Data.UserDeclaredConstructor = Record[Idx++];
712 Data.UserDeclaredCopyConstructor = Record[Idx++];
713 Data.UserDeclaredCopyAssignment = Record[Idx++];
714 Data.UserDeclaredDestructor = Record[Idx++];
715 Data.Aggregate = Record[Idx++];
716 Data.PlainOldData = Record[Idx++];
717 Data.Empty = Record[Idx++];
718 Data.Polymorphic = Record[Idx++];
719 Data.Abstract = Record[Idx++];
720 Data.HasTrivialConstructor = Record[Idx++];
721 Data.HasTrivialCopyConstructor = Record[Idx++];
722 Data.HasTrivialCopyAssignment = Record[Idx++];
723 Data.HasTrivialDestructor = Record[Idx++];
724 Data.ComputedVisibleConversions = Record[Idx++];
725 Data.DeclaredDefaultConstructor = Record[Idx++];
726 Data.DeclaredCopyConstructor = Record[Idx++];
727 Data.DeclaredCopyAssignment = Record[Idx++];
728 Data.DeclaredDestructor = Record[Idx++];
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000729
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000730 // setBases() is unsuitable since it may try to iterate the bases of an
Nick Lewycky19b9f952010-07-26 16:56:01 +0000731 // uninitialized base.
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000732 Data.NumBases = Record[Idx++];
733 Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases];
734 for (unsigned i = 0; i != Data.NumBases; ++i)
Nick Lewycky19b9f952010-07-26 16:56:01 +0000735 Data.Bases[i] = Reader.ReadCXXBaseSpecifier(Cursor, Record, Idx);
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000736
737 // FIXME: Make VBases lazily computed when needed to avoid storing them.
738 Data.NumVBases = Record[Idx++];
739 Data.VBases = new(C) CXXBaseSpecifier [Data.NumVBases];
740 for (unsigned i = 0; i != Data.NumVBases; ++i)
Nick Lewycky19b9f952010-07-26 16:56:01 +0000741 Data.VBases[i] = Reader.ReadCXXBaseSpecifier(Cursor, Record, Idx);
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000742
743 Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx);
744 Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx);
745 assert(Data.Definition && "Data.Definition should be already set!");
746 Data.FirstFriend
747 = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000748 }
749
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000750 enum CXXRecKind {
751 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
752 };
753 switch ((CXXRecKind)Record[Idx++]) {
754 default:
755 assert(false && "Out of sync with PCHDeclWriter::VisitCXXRecordDecl?");
756 case CXXRecNotTemplate:
757 break;
758 case CXXRecTemplate:
759 D->setDescribedClassTemplate(
760 cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++])));
761 break;
762 case CXXRecMemberSpecialization: {
763 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
764 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
765 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
766 D->setInstantiationOfMemberClass(RD, TSK);
767 D->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
768 break;
769 }
770 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000771}
772
773void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000774 VisitFunctionDecl(D);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000775 unsigned NumOverridenMethods = Record[Idx++];
776 while (NumOverridenMethods--) {
777 CXXMethodDecl *MD = cast<CXXMethodDecl>(Reader.GetDecl(Record[Idx++]));
778 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
779 // MD may be initializing.
780 Reader.getContext()->addOverriddenMethod(D, MD);
781 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000782}
783
784void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000785 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000786
787 D->IsExplicitSpecified = Record[Idx++];
788 D->ImplicitlyDefined = Record[Idx++];
789
790 unsigned NumInitializers = Record[Idx++];
791 D->NumBaseOrMemberInitializers = NumInitializers;
792 if (NumInitializers) {
793 ASTContext &C = *Reader.getContext();
794
795 D->BaseOrMemberInitializers
796 = new (C) CXXBaseOrMemberInitializer*[NumInitializers];
797 for (unsigned i=0; i != NumInitializers; ++i) {
Duncan Sands16143962010-07-06 18:19:40 +0000798 TypeSourceInfo *BaseClassInfo = 0;
799 bool IsBaseVirtual = false;
800 FieldDecl *Member = 0;
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000801
802 bool IsBaseInitializer = Record[Idx++];
803 if (IsBaseInitializer) {
Sebastian Redlc67764e2010-07-22 22:43:28 +0000804 BaseClassInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000805 IsBaseVirtual = Record[Idx++];
806 } else {
807 Member = cast<FieldDecl>(Reader.GetDecl(Record[Idx++]));
808 }
809 SourceLocation MemberLoc = Reader.ReadSourceLocation(Record, Idx);
Sebastian Redlc67764e2010-07-22 22:43:28 +0000810 Expr *Init = Reader.ReadExpr(Cursor);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000811 FieldDecl *AnonUnionMember
812 = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
813 SourceLocation LParenLoc = Reader.ReadSourceLocation(Record, Idx);
814 SourceLocation RParenLoc = Reader.ReadSourceLocation(Record, Idx);
815 bool IsWritten = Record[Idx++];
816 unsigned SourceOrderOrNumArrayIndices;
817 llvm::SmallVector<VarDecl *, 8> Indices;
818 if (IsWritten) {
819 SourceOrderOrNumArrayIndices = Record[Idx++];
820 } else {
821 SourceOrderOrNumArrayIndices = Record[Idx++];
822 Indices.reserve(SourceOrderOrNumArrayIndices);
823 for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i)
824 Indices.push_back(cast<VarDecl>(Reader.GetDecl(Record[Idx++])));
825 }
826
827 CXXBaseOrMemberInitializer *BOMInit;
828 if (IsBaseInitializer) {
829 BOMInit = new (C) CXXBaseOrMemberInitializer(C, BaseClassInfo,
830 IsBaseVirtual, LParenLoc,
831 Init, RParenLoc);
832 } else if (IsWritten) {
833 BOMInit = new (C) CXXBaseOrMemberInitializer(C, Member, MemberLoc,
834 LParenLoc, Init, RParenLoc);
835 } else {
836 BOMInit = CXXBaseOrMemberInitializer::Create(C, Member, MemberLoc,
837 LParenLoc, Init, RParenLoc,
838 Indices.data(),
839 Indices.size());
840 }
841
842 BOMInit->setAnonUnionMember(AnonUnionMember);
843 D->BaseOrMemberInitializers[i] = BOMInit;
844 }
845 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000846}
847
848void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000849 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000850
851 D->ImplicitlyDefined = Record[Idx++];
852 D->OperatorDelete = cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000853}
854
855void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000856 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000857 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000858}
859
Abramo Bagnarad7340582010-06-05 05:09:32 +0000860void PCHDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
861 VisitDecl(D);
862 D->setColonLoc(Reader.ReadSourceLocation(Record, Idx));
863}
864
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000865void PCHDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000866 VisitDecl(D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000867 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000868 D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000869 else
870 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
871 D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
872 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
873}
874
Chris Lattnerca025db2010-05-07 21:43:38 +0000875void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +0000876 VisitDecl(D);
877 unsigned NumParams = Record[Idx++];
878 D->NumParams = NumParams;
879 D->Params = new TemplateParameterList*[NumParams];
880 for (unsigned i = 0; i != NumParams; ++i)
881 D->Params[i] = Reader.ReadTemplateParameterList(Record, Idx);
882 if (Record[Idx++]) // HasFriendDecl
883 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
884 else
Sebastian Redlc67764e2010-07-22 22:43:28 +0000885 D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +0000886 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000887}
888
889void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000890 VisitNamedDecl(D);
891
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +0000892 NamedDecl *TemplatedDecl
893 = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000894 TemplateParameterList* TemplateParams
895 = Reader.ReadTemplateParameterList(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000896 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +0000897}
898
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000899void PCHDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000900 VisitTemplateDecl(D);
901
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000902 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000903 RedeclarableTemplateDecl *PrevDecl =
904 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]));
905 assert((PrevDecl == 0 || PrevDecl->getKind() == D->getKind()) &&
906 "PrevDecl kind mismatch");
907 if (PrevDecl)
908 D->CommonOrPrev = PrevDecl;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000909 if (PrevDecl == 0) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000910 if (RedeclarableTemplateDecl *RTD
911 = cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
912 assert(RTD->getKind() == D->getKind() &&
913 "InstantiatedFromMemberTemplate kind mismatch");
914 D->setInstantiatedFromMemberTemplateImpl(RTD);
915 if (Record[Idx++])
916 D->setMemberSpecialization();
917 }
918 }
919}
920
921void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
922 VisitRedeclarableTemplateDecl(D);
923
924 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000925 // This ClassTemplateDecl owns a CommonPtr; read it.
926
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000927 // FoldingSets are filled in VisitClassTemplateSpecializationDecl.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000928 unsigned size = Record[Idx++];
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000929 while (size--)
930 cast<ClassTemplateSpecializationDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000931
932 size = Record[Idx++];
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000933 while (size--)
934 cast<ClassTemplatePartialSpecializationDecl>(
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000935 Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000936
937 // InjectedClassNameType is computed.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000938 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000939}
940
941void PCHDeclReader::VisitClassTemplateSpecializationDecl(
942 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000943 VisitCXXRecordDecl(D);
944
945 if (Decl *InstD = Reader.GetDecl(Record[Idx++])) {
946 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
947 D->setInstantiationOf(CTD);
948 } else {
949 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000950 Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000951 D->setInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(InstD),
952 TemplArgs.data(), TemplArgs.size());
953 }
954 }
955
956 // Explicit info.
Sebastian Redlc67764e2010-07-22 22:43:28 +0000957 if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx)) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000958 D->setTypeAsWritten(TyInfo);
959 D->setExternLoc(Reader.ReadSourceLocation(Record, Idx));
960 D->setTemplateKeywordLoc(Reader.ReadSourceLocation(Record, Idx));
961 }
962
963 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000964 Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000965 D->initTemplateArgs(TemplArgs.data(), TemplArgs.size());
966 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
967 if (POI.isValid())
968 D->setPointOfInstantiation(POI);
969 D->setSpecializationKind((TemplateSpecializationKind)Record[Idx++]);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000970
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +0000971 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000972 ClassTemplateDecl *CanonPattern
973 = cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
974 if (ClassTemplatePartialSpecializationDecl *Partial
975 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
Argyrios Kyrtzidisf4cc7dc2010-07-12 21:41:31 +0000976 CanonPattern->getPartialSpecializations().InsertNode(Partial);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000977 } else {
Argyrios Kyrtzidisf4cc7dc2010-07-12 21:41:31 +0000978 CanonPattern->getSpecializations().InsertNode(D);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000979 }
980 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000981}
982
983void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl(
984 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000985 VisitClassTemplateSpecializationDecl(D);
986
987 D->initTemplateParameters(Reader.ReadTemplateParameterList(Record, Idx));
988
989 TemplateArgumentListInfo ArgInfos;
990 unsigned NumArgs = Record[Idx++];
991 while (NumArgs--)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000992 ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000993 D->initTemplateArgsAsWritten(ArgInfos);
994
995 D->setSequenceNumber(Record[Idx++]);
996
997 // These are read/set from/to the first declaration.
998 if (D->getPreviousDeclaration() == 0) {
999 D->setInstantiatedFromMember(
1000 cast_or_null<ClassTemplatePartialSpecializationDecl>(
1001 Reader.GetDecl(Record[Idx++])));
1002 if (Record[Idx++])
Argyrios Kyrtzidisdd2061b2010-07-09 21:11:35 +00001003 D->setMemberSpecialization();
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001004 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001005}
1006
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001007void PCHDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001008 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001009
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001010 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001011 // This FunctionTemplateDecl owns a CommonPtr; read it.
1012
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001013 // Read the function specialization declarations.
1014 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
1015 // through the specialized FunctionDecl's setFunctionTemplateSpecialization.
1016 unsigned NumSpecs = Record[Idx++];
1017 while (NumSpecs--)
1018 Reader.GetDecl(Record[Idx++]);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001019 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001020}
1021
1022void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001023 VisitTypeDecl(D);
1024
1025 D->setDeclaredWithTypename(Record[Idx++]);
1026 D->setParameterPack(Record[Idx++]);
1027
1028 bool Inherited = Record[Idx++];
Sebastian Redlc67764e2010-07-22 22:43:28 +00001029 TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001030 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001031}
1032
1033void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001034 VisitVarDecl(D);
1035 // TemplateParmPosition.
1036 D->setDepth(Record[Idx++]);
1037 D->setPosition(Record[Idx++]);
1038 // Rest of NonTypeTemplateParmDecl.
1039 if (Record[Idx++]) {
Sebastian Redlc67764e2010-07-22 22:43:28 +00001040 Expr *DefArg = Reader.ReadExpr(Cursor);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001041 bool Inherited = Record[Idx++];
1042 D->setDefaultArgument(DefArg, Inherited);
1043 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001044}
1045
1046void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001047 VisitTemplateDecl(D);
1048 // TemplateParmPosition.
1049 D->setDepth(Record[Idx++]);
1050 D->setPosition(Record[Idx++]);
1051 // Rest of TemplateTemplateParmDecl.
Sebastian Redlc67764e2010-07-22 22:43:28 +00001052 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx);
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001053 bool IsInherited = Record[Idx++];
1054 D->setDefaultArgument(Arg, IsInherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001055}
1056
1057void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001058 VisitDecl(D);
Sebastian Redlc67764e2010-07-22 22:43:28 +00001059 D->AssertExpr = Reader.ReadExpr(Cursor);
1060 D->Message = cast<StringLiteral>(Reader.ReadExpr(Cursor));
Chris Lattnerca025db2010-05-07 21:43:38 +00001061}
1062
Mike Stump11289f42009-09-09 15:08:12 +00001063std::pair<uint64_t, uint64_t>
Chris Lattner487412d2009-04-27 05:27:42 +00001064PCHDeclReader::VisitDeclContext(DeclContext *DC) {
1065 uint64_t LexicalOffset = Record[Idx++];
1066 uint64_t VisibleOffset = Record[Idx++];
1067 return std::make_pair(LexicalOffset, VisibleOffset);
1068}
1069
1070//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00001071// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00001072//===----------------------------------------------------------------------===//
1073
Chris Lattner8f63ab52009-04-27 06:01:06 +00001074/// \brief Reads attributes from the current stream position.
Sebastian Redlc67764e2010-07-22 22:43:28 +00001075Attr *PCHReader::ReadAttributes(llvm::BitstreamCursor &DeclsCursor) {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001076 unsigned Code = DeclsCursor.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +00001077 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner8f63ab52009-04-27 06:01:06 +00001078 "Expected unabbreviated record"); (void)Code;
Mike Stump11289f42009-09-09 15:08:12 +00001079
Chris Lattner8f63ab52009-04-27 06:01:06 +00001080 RecordData Record;
1081 unsigned Idx = 0;
1082 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump11289f42009-09-09 15:08:12 +00001083 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001084 (void)RecCode;
1085
1086#define SIMPLE_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001087 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +00001088 New = ::new (*Context) Name##Attr(); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001089 break
1090
1091#define STRING_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001092 case attr::Name: \
Ted Kremenek7f4945a2010-02-11 05:28:37 +00001093 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001094 break
1095
1096#define UNSIGNED_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001097 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +00001098 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001099 break
1100
1101 Attr *Attrs = 0;
1102 while (Idx < Record.size()) {
1103 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001104 attr::Kind Kind = (attr::Kind)Record[Idx++];
Chris Lattner8f63ab52009-04-27 06:01:06 +00001105 bool IsInherited = Record[Idx++];
1106
1107 switch (Kind) {
Anton Korobeynikov55bcea12010-01-10 12:58:08 +00001108 default:
1109 assert(0 && "Unknown attribute!");
1110 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001111 STRING_ATTR(Alias);
Daniel Dunbarfc6507e2010-05-27 02:25:39 +00001112 SIMPLE_ATTR(AlignMac68k);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001113 UNSIGNED_ATTR(Aligned);
1114 SIMPLE_ATTR(AlwaysInline);
1115 SIMPLE_ATTR(AnalyzerNoReturn);
1116 STRING_ATTR(Annotate);
1117 STRING_ATTR(AsmLabel);
Alexis Hunt54a02542009-11-25 04:20:27 +00001118 SIMPLE_ATTR(BaseCheck);
Mike Stump11289f42009-09-09 15:08:12 +00001119
Alexis Hunt344393e2010-06-16 23:43:53 +00001120 case attr::Blocks:
Chris Lattner8575daa2009-04-27 21:45:14 +00001121 New = ::new (*Context) BlocksAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001122 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
1123 break;
Mike Stump11289f42009-09-09 15:08:12 +00001124
Eli Friedmane4310c82009-11-09 18:38:53 +00001125 SIMPLE_ATTR(CDecl);
1126
Alexis Hunt344393e2010-06-16 23:43:53 +00001127 case attr::Cleanup:
Chris Lattner8575daa2009-04-27 21:45:14 +00001128 New = ::new (*Context) CleanupAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001129 cast<FunctionDecl>(GetDecl(Record[Idx++])));
1130 break;
1131
1132 SIMPLE_ATTR(Const);
1133 UNSIGNED_ATTR(Constructor);
1134 SIMPLE_ATTR(DLLExport);
1135 SIMPLE_ATTR(DLLImport);
1136 SIMPLE_ATTR(Deprecated);
1137 UNSIGNED_ATTR(Destructor);
1138 SIMPLE_ATTR(FastCall);
Alexis Hunt96d5c762009-11-21 08:43:09 +00001139 SIMPLE_ATTR(Final);
Mike Stump11289f42009-09-09 15:08:12 +00001140
Alexis Hunt344393e2010-06-16 23:43:53 +00001141 case attr::Format: {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001142 std::string Type = ReadString(Record, Idx);
1143 unsigned FormatIdx = Record[Idx++];
1144 unsigned FirstArg = Record[Idx++];
Ted Kremenek7f4945a2010-02-11 05:28:37 +00001145 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001146 break;
1147 }
Mike Stump11289f42009-09-09 15:08:12 +00001148
Alexis Hunt344393e2010-06-16 23:43:53 +00001149 case attr::FormatArg: {
Fariborz Jahanianf1c25022009-05-20 17:41:43 +00001150 unsigned FormatIdx = Record[Idx++];
1151 New = ::new (*Context) FormatArgAttr(FormatIdx);
1152 break;
1153 }
Mike Stump11289f42009-09-09 15:08:12 +00001154
Alexis Hunt344393e2010-06-16 23:43:53 +00001155 case attr::Sentinel: {
Fariborz Jahanian027b8862009-05-13 18:09:35 +00001156 int sentinel = Record[Idx++];
1157 int nullPos = Record[Idx++];
1158 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
1159 break;
1160 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001161
1162 SIMPLE_ATTR(GNUInline);
Alexis Hunt54a02542009-11-25 04:20:27 +00001163 SIMPLE_ATTR(Hiding);
Mike Stump11289f42009-09-09 15:08:12 +00001164
Alexis Hunt344393e2010-06-16 23:43:53 +00001165 case attr::IBAction:
Ted Kremenek06be9682010-02-17 02:37:45 +00001166 New = ::new (*Context) IBActionAttr();
1167 break;
1168
Alexis Hunt344393e2010-06-16 23:43:53 +00001169 case attr::IBOutlet:
Chris Lattner8575daa2009-04-27 21:45:14 +00001170 New = ::new (*Context) IBOutletAttr();
Chris Lattner8f63ab52009-04-27 06:01:06 +00001171 break;
1172
Alexis Hunt344393e2010-06-16 23:43:53 +00001173 case attr::IBOutletCollection: {
Ted Kremenek26bde772010-05-19 17:38:06 +00001174 ObjCInterfaceDecl *D =
1175 cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++]));
1176 New = ::new (*Context) IBOutletCollectionAttr(D);
1177 break;
1178 }
1179
Ryan Flynn1f1fdc02009-08-09 20:07:29 +00001180 SIMPLE_ATTR(Malloc);
Mike Stump3722f582009-08-26 22:31:08 +00001181 SIMPLE_ATTR(NoDebug);
1182 SIMPLE_ATTR(NoInline);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001183 SIMPLE_ATTR(NoReturn);
1184 SIMPLE_ATTR(NoThrow);
Mike Stump11289f42009-09-09 15:08:12 +00001185
Alexis Hunt344393e2010-06-16 23:43:53 +00001186 case attr::NonNull: {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001187 unsigned Size = Record[Idx++];
1188 llvm::SmallVector<unsigned, 16> ArgNums;
1189 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
1190 Idx += Size;
Ted Kremenek510ee252010-02-11 07:31:47 +00001191 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001192 break;
1193 }
Mike Stump11289f42009-09-09 15:08:12 +00001194
Alexis Hunt344393e2010-06-16 23:43:53 +00001195 case attr::ReqdWorkGroupSize: {
Nate Begemanf2758702009-06-26 06:32:41 +00001196 unsigned X = Record[Idx++];
1197 unsigned Y = Record[Idx++];
1198 unsigned Z = Record[Idx++];
1199 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
1200 break;
1201 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001202
1203 SIMPLE_ATTR(ObjCException);
1204 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekd9c66632010-02-18 00:05:45 +00001205 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +00001206 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenekd9c66632010-02-18 00:05:45 +00001207 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +00001208 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001209 SIMPLE_ATTR(Overloadable);
Alexis Hunt54a02542009-11-25 04:20:27 +00001210 SIMPLE_ATTR(Override);
Anders Carlsson68e0b682009-08-08 18:23:56 +00001211 SIMPLE_ATTR(Packed);
Daniel Dunbar40130442010-05-27 01:12:46 +00001212 UNSIGNED_ATTR(MaxFieldAlignment);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001213 SIMPLE_ATTR(Pure);
1214 UNSIGNED_ATTR(Regparm);
1215 STRING_ATTR(Section);
1216 SIMPLE_ATTR(StdCall);
Douglas Gregora941dca2010-05-18 16:57:00 +00001217 SIMPLE_ATTR(ThisCall);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001218 SIMPLE_ATTR(TransparentUnion);
1219 SIMPLE_ATTR(Unavailable);
1220 SIMPLE_ATTR(Unused);
1221 SIMPLE_ATTR(Used);
Mike Stump11289f42009-09-09 15:08:12 +00001222
Alexis Hunt344393e2010-06-16 23:43:53 +00001223 case attr::Visibility:
Chris Lattner8575daa2009-04-27 21:45:14 +00001224 New = ::new (*Context) VisibilityAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001225 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
1226 break;
1227
1228 SIMPLE_ATTR(WarnUnusedResult);
1229 SIMPLE_ATTR(Weak);
Rafael Espindolac18086a2010-02-23 22:00:30 +00001230 SIMPLE_ATTR(WeakRef);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001231 SIMPLE_ATTR(WeakImport);
1232 }
1233
1234 assert(New && "Unable to decode attribute?");
1235 New->setInherited(IsInherited);
1236 New->setNext(Attrs);
1237 Attrs = New;
1238 }
1239#undef UNSIGNED_ATTR
1240#undef STRING_ATTR
1241#undef SIMPLE_ATTR
1242
1243 // The list of attributes was built backwards. Reverse the list
1244 // before returning it.
1245 Attr *PrevAttr = 0, *NextAttr = 0;
1246 while (Attrs) {
1247 NextAttr = Attrs->getNext();
1248 Attrs->setNext(PrevAttr);
1249 PrevAttr = Attrs;
1250 Attrs = NextAttr;
1251 }
1252
1253 return PrevAttr;
1254}
1255
1256//===----------------------------------------------------------------------===//
1257// PCHReader Implementation
1258//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001259
1260/// \brief Note that we have loaded the declaration with the given
1261/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001262///
Chris Lattner487412d2009-04-27 05:27:42 +00001263/// This routine notes that this declaration has already been loaded,
1264/// so that future GetDecl calls will return this declaration rather
1265/// than trying to load a new declaration.
1266inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
1267 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1268 DeclsLoaded[Index] = D;
1269}
1270
1271
1272/// \brief Determine whether the consumer will be interested in seeing
1273/// this declaration (via HandleTopLevelDecl).
1274///
1275/// This routine should return true for anything that might affect
1276/// code generation, e.g., inline function definitions, Objective-C
1277/// declarations with metadata, etc.
1278static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001279 if (isa<FileScopeAsmDecl>(D))
1280 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001281 if (VarDecl *Var = dyn_cast<VarDecl>(D))
1282 return Var->isFileVarDecl() && Var->getInit();
1283 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1284 return Func->isThisDeclarationADefinition();
1285 return isa<ObjCProtocolDecl>(D);
1286}
1287
Sebastian Redl34627792010-07-20 22:46:15 +00001288/// \brief Get the correct cursor and offset for loading a type.
1289PCHReader::RecordLocation PCHReader::DeclCursorForIndex(unsigned Index) {
1290 PerFileData *F = 0;
1291 for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
1292 F = Chain[N - I - 1];
1293 if (Index < F->LocalNumDecls)
1294 break;
1295 Index -= F->LocalNumDecls;
1296 }
1297 assert(F && F->LocalNumDecls > Index && "Broken chain");
Sebastian Redlb2831db2010-07-20 22:55:31 +00001298 return RecordLocation(&F->DeclsCursor, F->DeclOffsets[Index]);
Sebastian Redl34627792010-07-20 22:46:15 +00001299}
1300
Chris Lattner487412d2009-04-27 05:27:42 +00001301/// \brief Read the declaration at the given offset from the PCH file.
Sebastian Redl34627792010-07-20 22:46:15 +00001302Decl *PCHReader::ReadDeclRecord(unsigned Index) {
1303 RecordLocation Loc = DeclCursorForIndex(Index);
Sebastian Redlb2831db2010-07-20 22:55:31 +00001304 llvm::BitstreamCursor &DeclsCursor = *Loc.first;
Chris Lattner487412d2009-04-27 05:27:42 +00001305 // Keep track of where we are in the stream, then jump back there
1306 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001307 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001308
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001309 ReadingKindTracker ReadingKind(Read_Decl, *this);
1310
Douglas Gregor1342e842009-07-06 18:54:52 +00001311 // Note that we are loading a declaration record.
1312 LoadingTypeOrDecl Loading(*this);
Mike Stump11289f42009-09-09 15:08:12 +00001313
Sebastian Redl34627792010-07-20 22:46:15 +00001314 DeclsCursor.JumpToBit(Loc.second);
Chris Lattner487412d2009-04-27 05:27:42 +00001315 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001316 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001317 unsigned Idx = 0;
Sebastian Redlc67764e2010-07-22 22:43:28 +00001318 PCHDeclReader Reader(*this, DeclsCursor, Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +00001319
Chris Lattner1de76db2009-04-27 05:58:23 +00001320 Decl *D = 0;
1321 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner487412d2009-04-27 05:27:42 +00001322 case pch::DECL_ATTR:
1323 case pch::DECL_CONTEXT_LEXICAL:
1324 case pch::DECL_CONTEXT_VISIBLE:
1325 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1326 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001327 case pch::DECL_TRANSLATION_UNIT:
1328 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +00001329 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +00001330 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001331 case pch::DECL_TYPEDEF:
John McCall703a3f82009-10-24 08:00:42 +00001332 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001333 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001334 case pch::DECL_ENUM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001335 D = EnumDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001336 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001337 case pch::DECL_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001338 D = RecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001339 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001340 case pch::DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +00001341 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001342 0, llvm::APSInt());
1343 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001344 case pch::DECL_FUNCTION:
Mike Stump11289f42009-09-09 15:08:12 +00001345 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001346 QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001347 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001348 case pch::DECL_LINKAGE_SPEC:
1349 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
1350 (LinkageSpecDecl::LanguageIDs)0,
1351 false);
1352 break;
1353 case pch::DECL_NAMESPACE:
1354 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
1355 break;
1356 case pch::DECL_NAMESPACE_ALIAS:
1357 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
1358 SourceLocation(), 0, SourceRange(), 0,
1359 SourceLocation(), 0);
1360 break;
1361 case pch::DECL_USING:
1362 D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(),
1363 SourceLocation(), 0, DeclarationName(), false);
1364 break;
1365 case pch::DECL_USING_SHADOW:
1366 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1367 break;
1368 case pch::DECL_USING_DIRECTIVE:
1369 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
1370 SourceLocation(), SourceRange(), 0,
1371 SourceLocation(), 0, 0);
1372 break;
1373 case pch::DECL_UNRESOLVED_USING_VALUE:
1374 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
1375 SourceRange(), 0, SourceLocation(),
1376 DeclarationName());
1377 break;
1378 case pch::DECL_UNRESOLVED_USING_TYPENAME:
1379 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
1380 SourceLocation(), SourceRange(),
1381 0, SourceLocation(),
1382 DeclarationName());
1383 break;
1384 case pch::DECL_CXX_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001385 D = CXXRecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001386 break;
1387 case pch::DECL_CXX_METHOD:
1388 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
1389 QualType(), 0);
1390 break;
1391 case pch::DECL_CXX_CONSTRUCTOR:
1392 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1393 break;
1394 case pch::DECL_CXX_DESTRUCTOR:
1395 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1396 break;
1397 case pch::DECL_CXX_CONVERSION:
1398 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1399 break;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001400 case pch::DECL_ACCESS_SPEC:
1401 D = AccessSpecDecl::Create(*Context, AS_none, 0, SourceLocation(),
1402 SourceLocation());
1403 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001404 case pch::DECL_FRIEND:
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001405 D = FriendDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001406 break;
1407 case pch::DECL_FRIEND_TEMPLATE:
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001408 D = FriendTemplateDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001409 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001410 case pch::DECL_CLASS_TEMPLATE:
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +00001411 D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(),
1412 DeclarationName(), 0, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001413 break;
1414 case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001415 D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001416 break;
1417 case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001418 D = ClassTemplatePartialSpecializationDecl::Create(*Context,
1419 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001420 break;
1421 case pch::DECL_FUNCTION_TEMPLATE:
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001422 D = FunctionTemplateDecl::Create(*Context, 0, SourceLocation(),
1423 DeclarationName(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001424 break;
1425 case pch::DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001426 D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001427 break;
1428 case pch::DECL_NON_TYPE_TEMPLATE_PARM:
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001429 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0,
1430 QualType(),0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001431 break;
1432 case pch::DECL_TEMPLATE_TEMPLATE_PARM:
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001433 D = TemplateTemplateParmDecl::Create(*Context, 0, SourceLocation(),0,0,0,0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001434 break;
1435 case pch::DECL_STATIC_ASSERT:
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001436 D = StaticAssertDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001437 break;
1438
Chris Lattner8f63ab52009-04-27 06:01:06 +00001439 case pch::DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +00001440 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001441 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001442 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001443 case pch::DECL_OBJC_INTERFACE:
Chris Lattner8575daa2009-04-27 21:45:14 +00001444 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001445 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001446 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001447 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001448 ObjCIvarDecl::None);
1449 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001450 case pch::DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001451 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001452 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001453 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001454 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001455 QualType(), 0);
1456 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001457 case pch::DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001458 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001459 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001460 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001461 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001462 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001463 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +00001464 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1465 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001466 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001467 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001468 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001469 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001470 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +00001471 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001472 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001473 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001474 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001475 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001476 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001477 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001478 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001479 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001480 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001481 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001482 SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001483 ObjCPropertyImplDecl::Dynamic, 0);
1484 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001485 case pch::DECL_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001486 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +00001487 false);
Chris Lattner487412d2009-04-27 05:27:42 +00001488 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001489 case pch::DECL_VAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001490 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001491 VarDecl::None, VarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001492 break;
1493
1494 case pch::DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001495 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001496 break;
1497
Chris Lattner8f63ab52009-04-27 06:01:06 +00001498 case pch::DECL_PARM_VAR:
Mike Stump11289f42009-09-09 15:08:12 +00001499 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001500 VarDecl::None, VarDecl::None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001501 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001502 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001503 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001504 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001505 case pch::DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +00001506 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001507 break;
1508 }
Chris Lattner487412d2009-04-27 05:27:42 +00001509
1510 assert(D && "Unknown declaration reading PCH file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001511 LoadedDecl(Index, D);
1512 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001513
1514 // If this declaration is also a declaration context, get the
1515 // offsets for its tables of lexical and visible declarations.
1516 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1517 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1518 if (Offsets.first || Offsets.second) {
1519 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1520 DC->setHasExternalVisibleStorage(Offsets.second != 0);
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001521 DeclContextInfo Info;
1522 if (ReadDeclContextStorage(DeclsCursor, Offsets, Info))
1523 return 0;
Sebastian Redl4b1f4902010-07-27 18:24:41 +00001524 DeclContextInfos &Infos = DeclContextOffsets[DC];
1525 // Reading the TU will happen after reading its update blocks, so we need
1526 // to make sure we insert in front. For all other contexts, the vector
1527 // is empty here anyway, so there's no loss in efficiency.
1528 Infos.insert(Infos.begin(), Info);
Chris Lattner487412d2009-04-27 05:27:42 +00001529 }
1530 }
1531 assert(Idx == Record.size());
1532
1533 // If we have deserialized a declaration that has a definition the
Argyrios Kyrtzidis903ccd62010-07-07 15:46:26 +00001534 // AST consumer might need to know about, queue it.
1535 // We don't pass it to the consumer immediately because we may be in recursive
1536 // loading, and some declarations may still be initializing.
1537 if (isConsumerInterestedIn(D))
1538 InterestingDecls.push_back(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001539
1540 return D;
1541}
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001542
1543bool PCHReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor,
1544 const std::pair<uint64_t, uint64_t> &Offsets,
1545 DeclContextInfo &Info) {
1546 SavedStreamPosition SavedPosition(Cursor);
1547 // First the lexical decls.
1548 if (Offsets.first != 0) {
1549 Cursor.JumpToBit(Offsets.first);
1550
1551 RecordData Record;
1552 const char *Blob;
1553 unsigned BlobLen;
1554 unsigned Code = Cursor.ReadCode();
1555 unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen);
1556 if (RecCode != pch::DECL_CONTEXT_LEXICAL) {
1557 Error("Expected lexical block");
1558 return true;
1559 }
1560
1561 Info.LexicalDecls = reinterpret_cast<const pch::DeclID*>(Blob);
1562 Info.NumLexicalDecls = BlobLen / sizeof(pch::DeclID);
1563 } else {
1564 Info.LexicalDecls = 0;
1565 Info.NumLexicalDecls = 0;
1566 }
1567
1568 // Now the visible decls.
1569 Info.Stream = &Cursor;
1570 Info.OffsetToVisibleDecls = Offsets.second;
1571
1572 return false;
1573}