blob: fe2947d64f9b3ec357332c9ea54da90451e4a0af [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);
81 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +000082 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000083 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +000084 void VisitUsingDecl(UsingDecl *D);
85 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000086 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000087 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Abramo Bagnarad7340582010-06-05 05:09:32 +000088 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000089 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000090 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
91 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000092 void VisitBlockDecl(BlockDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +000093
Chris Lattner487412d2009-04-27 05:27:42 +000094 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Chris Lattnerca025db2010-05-07 21:43:38 +000095
Alexis Hunted053252010-05-30 07:21:58 +000096 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-04-27 05:27:42 +000097 void VisitObjCMethodDecl(ObjCMethodDecl *D);
98 void VisitObjCContainerDecl(ObjCContainerDecl *D);
99 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
100 void VisitObjCIvarDecl(ObjCIvarDecl *D);
101 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
102 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
103 void VisitObjCClassDecl(ObjCClassDecl *D);
104 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
105 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
106 void VisitObjCImplDecl(ObjCImplDecl *D);
107 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
108 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
109 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
110 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
111 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
112 };
113}
114
Sebastian Redlc67764e2010-07-22 22:43:28 +0000115uint64_t PCHDeclReader::GetCurrentCursorOffset() {
116 uint64_t Off = 0;
117 for (unsigned I = 0, N = Reader.Chain.size(); I != N; ++I) {
118 PCHReader::PerFileData &F = *Reader.Chain[N - I - 1];
119 if (&Cursor == &F.DeclsCursor) {
120 Off += F.DeclsCursor.GetCurrentBitNo();
121 break;
122 }
123 Off += F.SizeInBits;
124 }
125 return Off;
126}
127
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000128void PCHDeclReader::Visit(Decl *D) {
129 DeclVisitor<PCHDeclReader, void>::Visit(D);
130
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000131 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
132 // if we have a fully initialized TypeDecl, we can safely read its type now.
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000133 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtr());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000134 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
135 // FunctionDecl's body was written last after all other Stmts/Exprs.
136 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000137 FD->setLazyBody(GetCurrentCursorOffset());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000138 }
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000139}
140
Chris Lattner487412d2009-04-27 05:27:42 +0000141void PCHDeclReader::VisitDecl(Decl *D) {
142 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
143 D->setLexicalDeclContext(
144 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
145 D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
146 D->setInvalidDecl(Record[Idx++]);
147 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000148 D->initAttrs(Reader.ReadAttributes(Cursor));
Chris Lattner487412d2009-04-27 05:27:42 +0000149 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +0000150 D->setUsed(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000151 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor16bef852009-10-16 20:01:17 +0000152 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner487412d2009-04-27 05:27:42 +0000153}
154
155void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
156 VisitDecl(TU);
Chris Lattnerca025db2010-05-07 21:43:38 +0000157 TU->setAnonymousNamespace(
158 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000159}
160
161void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) {
162 VisitDecl(ND);
Mike Stump11289f42009-09-09 15:08:12 +0000163 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000164}
165
166void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
167 VisitNamedDecl(TD);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000168 // Delay type reading until after we have fully initialized the decl.
169 TypeIDForTypeDecl = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000170}
171
172void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000173 VisitTypeDecl(TD);
Sebastian Redlc67764e2010-07-22 22:43:28 +0000174 TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000175}
176
177void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
178 VisitTypeDecl(TD);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000179 TD->IdentifierNamespace = Record[Idx++];
Douglas Gregorb6b8f9e2009-07-29 23:36:44 +0000180 TD->setPreviousDeclaration(
181 cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000182 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
183 TD->setDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000184 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis664b6902009-07-14 03:18:02 +0000185 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000186 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall3e11ebe2010-03-15 10:12:16 +0000187 // FIXME: maybe read optional qualifier and its range.
188 TD->setTypedefForAnonDecl(
189 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000190}
191
192void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
193 VisitTagDecl(ED);
194 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall56774992009-12-09 09:09:27 +0000195 ED->setPromotionType(Reader.GetType(Record[Idx++]));
John McCall9aa35be2010-05-06 08:49:23 +0000196 ED->setNumPositiveBits(Record[Idx++]);
197 ED->setNumNegativeBits(Record[Idx++]);
Argyrios Kyrtzidis282b36b2010-07-06 15:36:48 +0000198 ED->setInstantiationOfMemberEnum(
199 cast_or_null<EnumDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000200}
201
202void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
203 VisitTagDecl(RD);
204 RD->setHasFlexibleArrayMember(Record[Idx++]);
205 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000206 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000207}
208
209void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
210 VisitNamedDecl(VD);
211 VD->setType(Reader.GetType(Record[Idx++]));
212}
213
214void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
215 VisitValueDecl(ECD);
216 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000217 ECD->setInitExpr(Reader.ReadExpr(Cursor));
Chris Lattner487412d2009-04-27 05:27:42 +0000218 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
219}
220
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000221void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
222 VisitValueDecl(DD);
Sebastian Redlc67764e2010-07-22 22:43:28 +0000223 TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
John McCallbcd03502009-12-07 02:54:59 +0000224 if (TInfo)
225 DD->setTypeSourceInfo(TInfo);
John McCall3e11ebe2010-03-15 10:12:16 +0000226 // FIXME: read optional qualifier and its range.
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000227}
228
Chris Lattner487412d2009-04-27 05:27:42 +0000229void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000230 VisitDeclaratorDecl(FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000231
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000232 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000233 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000234 default: assert(false && "Unhandled TemplatedKind!");
235 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000236 case FunctionDecl::TK_NonTemplate:
237 break;
238 case FunctionDecl::TK_FunctionTemplate:
239 FD->setDescribedFunctionTemplate(
240 cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++])));
241 break;
242 case FunctionDecl::TK_MemberSpecialization: {
243 FunctionDecl *InstFD = cast<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
244 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
245 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
246 FD->setInstantiationOfMemberFunction(InstFD, TSK);
247 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
248 break;
249 }
250 case FunctionDecl::TK_FunctionTemplateSpecialization: {
251 FunctionTemplateDecl *Template
252 = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
253 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
254
255 // Template arguments.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000256 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000257 Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000258
259 // Template args as written.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000260 llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000261 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000262 if (Record[Idx++]) { // TemplateArgumentsAsWritten != 0
263 unsigned NumTemplateArgLocs = Record[Idx++];
264 TemplArgLocs.reserve(NumTemplateArgLocs);
265 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000266 TemplArgLocs.push_back(
267 Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx));
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000268
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000269 LAngleLoc = Reader.ReadSourceLocation(Record, Idx);
270 RAngleLoc = Reader.ReadSourceLocation(Record, Idx);
271 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000272
273 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000274
Argyrios Kyrtzidisdde57902010-07-20 13:59:58 +0000275 if (FD->isCanonicalDecl()) // if canonical add to template's set.
276 FD->setFunctionTemplateSpecialization(Template, TemplArgs.size(),
277 TemplArgs.data(), TSK,
278 TemplArgLocs.size(),
279 TemplArgLocs.data(),
280 LAngleLoc, RAngleLoc, POI);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000281 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000282 }
283 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
284 // Templates.
285 UnresolvedSet<8> TemplDecls;
286 unsigned NumTemplates = Record[Idx++];
287 while (NumTemplates--)
288 TemplDecls.addDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
289
290 // Templates args.
291 TemplateArgumentListInfo TemplArgs;
292 unsigned NumArgs = Record[Idx++];
293 while (NumArgs--)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000294 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Cursor,Record, Idx));
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000295 TemplArgs.setLAngleLoc(Reader.ReadSourceLocation(Record, Idx));
296 TemplArgs.setRAngleLoc(Reader.ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000297
298 FD->setDependentTemplateSpecialization(*Reader.getContext(),
299 TemplDecls, TemplArgs);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000300 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000301 }
302 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000303
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000304 // FunctionDecl's body is handled last at PCHReaderDecl::Visit,
305 // after everything else is read.
306
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000307 // Avoid side effects and invariant checking of FunctionDecl's
308 // setPreviousDeclaration.
309 FD->redeclarable_base::setPreviousDeclaration(
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000310 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
311 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
312 FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]);
313 FD->setInlineSpecified(Record[Idx++]);
314 FD->setVirtualAsWritten(Record[Idx++]);
315 FD->setPure(Record[Idx++]);
316 FD->setHasInheritedPrototype(Record[Idx++]);
317 FD->setHasWrittenPrototype(Record[Idx++]);
318 FD->setDeleted(Record[Idx++]);
319 FD->setTrivial(Record[Idx++]);
320 FD->setCopyAssignment(Record[Idx++]);
321 FD->setHasImplicitReturnZero(Record[Idx++]);
322 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
323
Chris Lattnerca025db2010-05-07 21:43:38 +0000324 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000325 unsigned NumParams = Record[Idx++];
326 llvm::SmallVector<ParmVarDecl *, 16> Params;
327 Params.reserve(NumParams);
328 for (unsigned I = 0; I != NumParams; ++I)
329 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000330 FD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000331}
332
333void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
334 VisitNamedDecl(MD);
335 if (Record[Idx++]) {
336 // In practice, this won't be executed (since method definitions
337 // don't occur in header files).
Sebastian Redlc67764e2010-07-22 22:43:28 +0000338 MD->setBody(Reader.ReadStmt(Cursor));
Chris Lattner487412d2009-04-27 05:27:42 +0000339 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
340 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
341 }
342 MD->setInstanceMethod(Record[Idx++]);
343 MD->setVariadic(Record[Idx++]);
344 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000345 MD->setDefined(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000346 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
347 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahaniand9235db2010-04-08 21:29:11 +0000348 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000349 MD->setResultType(Reader.GetType(Record[Idx++]));
Sebastian Redlc67764e2010-07-22 22:43:28 +0000350 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000351 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
352 unsigned NumParams = Record[Idx++];
353 llvm::SmallVector<ParmVarDecl *, 16> Params;
354 Params.reserve(NumParams);
355 for (unsigned I = 0; I != NumParams; ++I)
356 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniancdabb312010-04-09 15:40:42 +0000357 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
358 NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000359}
360
361void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
362 VisitNamedDecl(CD);
Ted Kremenekc7c64312010-01-07 01:20:12 +0000363 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
364 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
365 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner487412d2009-04-27 05:27:42 +0000366}
367
368void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
369 VisitObjCContainerDecl(ID);
370 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
371 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
372 (Reader.GetDecl(Record[Idx++])));
373 unsigned NumProtocols = Record[Idx++];
374 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
375 Protocols.reserve(NumProtocols);
376 for (unsigned I = 0; I != NumProtocols; ++I)
377 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000378 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
379 ProtoLocs.reserve(NumProtocols);
380 for (unsigned I = 0; I != NumProtocols; ++I)
381 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
382 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
383 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000384 unsigned NumIvars = Record[Idx++];
385 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
386 IVars.reserve(NumIvars);
387 for (unsigned I = 0; I != NumIvars; ++I)
388 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000389 ID->setCategoryList(
390 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
391 ID->setForwardDecl(Record[Idx++]);
392 ID->setImplicitInterfaceDecl(Record[Idx++]);
393 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
394 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisea72f422009-07-18 00:33:23 +0000395 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000396}
397
398void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
399 VisitFieldDecl(IVD);
400 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000401 bool synth = Record[Idx++];
402 IVD->setSynthesize(synth);
Chris Lattner487412d2009-04-27 05:27:42 +0000403}
404
405void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
406 VisitObjCContainerDecl(PD);
407 PD->setForwardDecl(Record[Idx++]);
408 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
409 unsigned NumProtoRefs = Record[Idx++];
410 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
411 ProtoRefs.reserve(NumProtoRefs);
412 for (unsigned I = 0; I != NumProtoRefs; ++I)
413 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000414 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
415 ProtoLocs.reserve(NumProtoRefs);
416 for (unsigned I = 0; I != NumProtoRefs; ++I)
417 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
418 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
419 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000420}
421
422void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
423 VisitFieldDecl(FD);
424}
425
426void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
427 VisitDecl(CD);
428 unsigned NumClassRefs = Record[Idx++];
429 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
430 ClassRefs.reserve(NumClassRefs);
431 for (unsigned I = 0; I != NumClassRefs; ++I)
432 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000433 llvm::SmallVector<SourceLocation, 16> SLocs;
434 SLocs.reserve(NumClassRefs);
435 for (unsigned I = 0; I != NumClassRefs; ++I)
436 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
437 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
438 NumClassRefs);
Chris Lattner487412d2009-04-27 05:27:42 +0000439}
440
441void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
442 VisitDecl(FPD);
443 unsigned NumProtoRefs = Record[Idx++];
444 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
445 ProtoRefs.reserve(NumProtoRefs);
446 for (unsigned I = 0; I != NumProtoRefs; ++I)
447 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000448 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
449 ProtoLocs.reserve(NumProtoRefs);
450 for (unsigned I = 0; I != NumProtoRefs; ++I)
451 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
452 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
453 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000454}
455
456void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
457 VisitObjCContainerDecl(CD);
458 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
459 unsigned NumProtoRefs = Record[Idx++];
460 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
461 ProtoRefs.reserve(NumProtoRefs);
462 for (unsigned I = 0; I != NumProtoRefs; ++I)
463 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000464 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
465 ProtoLocs.reserve(NumProtoRefs);
466 for (unsigned I = 0; I != NumProtoRefs; ++I)
467 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
468 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
469 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000470 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor071676f2010-01-16 16:38:58 +0000471 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
472 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000473}
474
475void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
476 VisitNamedDecl(CAD);
477 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
478}
479
480void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
481 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000482 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Sebastian Redlc67764e2010-07-22 22:43:28 +0000483 D->setType(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000484 // FIXME: stable encoding
485 D->setPropertyAttributes(
486 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000487 D->setPropertyAttributesAsWritten(
488 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000489 // FIXME: stable encoding
490 D->setPropertyImplementation(
491 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
492 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
493 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
494 D->setGetterMethodDecl(
495 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
496 D->setSetterMethodDecl(
497 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
498 D->setPropertyIvarDecl(
499 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
500}
501
502void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000503 VisitObjCContainerDecl(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000504 D->setClassInterface(
505 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000506}
507
508void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
509 VisitObjCImplDecl(D);
510 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
511}
512
513void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
514 VisitObjCImplDecl(D);
515 D->setSuperClass(
516 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanianc83726e2010-04-28 16:11:27 +0000517 // FIXME. Add reading of IvarInitializers and NumIvarInitializers.
Chris Lattner487412d2009-04-27 05:27:42 +0000518}
519
520
521void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
522 VisitDecl(D);
523 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
524 D->setPropertyDecl(
525 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
526 D->setPropertyIvarDecl(
527 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanian25491a22010-05-05 21:52:17 +0000528 // FIXME. read GetterCXXConstructor and SetterCXXAssignment
Chris Lattner487412d2009-04-27 05:27:42 +0000529}
530
531void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000532 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000533 FD->setMutable(Record[Idx++]);
534 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000535 FD->setBitWidth(Reader.ReadExpr(Cursor));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000536 if (!FD->getDeclName()) {
537 FieldDecl *Tmpl = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
538 if (Tmpl)
539 Reader.getContext()->setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
540 }
Chris Lattner487412d2009-04-27 05:27:42 +0000541}
542
543void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000544 VisitDeclaratorDecl(VD);
Chris Lattner487412d2009-04-27 05:27:42 +0000545 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
Douglas Gregorc4df4072010-04-19 22:54:31 +0000546 VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000547 VD->setThreadSpecified(Record[Idx++]);
548 VD->setCXXDirectInitializer(Record[Idx++]);
549 VD->setDeclaredInCondition(Record[Idx++]);
Douglas Gregor3f324d562010-05-03 18:51:14 +0000550 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor6fd1b182010-05-15 06:01:05 +0000551 VD->setNRVOVariable(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000552 VD->setPreviousDeclaration(
553 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000554 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000555 VD->setInit(Reader.ReadExpr(Cursor));
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000556
557 if (Record[Idx++]) { // HasMemberSpecializationInfo.
558 VarDecl *Tmpl = cast<VarDecl>(Reader.GetDecl(Record[Idx++]));
559 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
560 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
561 Reader.getContext()->setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
562 }
Chris Lattner487412d2009-04-27 05:27:42 +0000563}
564
565void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
566 VisitVarDecl(PD);
567}
568
569void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
570 VisitVarDecl(PD);
571 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallf3cd6652010-03-12 18:31:32 +0000572 PD->setHasInheritedDefaultArg(Record[Idx++]);
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000573 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redlc67764e2010-07-22 22:43:28 +0000574 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(Cursor));
Chris Lattner487412d2009-04-27 05:27:42 +0000575}
576
Chris Lattner487412d2009-04-27 05:27:42 +0000577void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
578 VisitDecl(AD);
Sebastian Redlc67764e2010-07-22 22:43:28 +0000579 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(Cursor)));
Chris Lattner487412d2009-04-27 05:27:42 +0000580}
581
582void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
583 VisitDecl(BD);
Sebastian Redlc67764e2010-07-22 22:43:28 +0000584 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(Cursor)));
585 BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000586 unsigned NumParams = Record[Idx++];
587 llvm::SmallVector<ParmVarDecl *, 16> Params;
588 Params.reserve(NumParams);
589 for (unsigned I = 0; I != NumParams; ++I)
590 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000591 BD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000592}
593
Chris Lattnerca025db2010-05-07 21:43:38 +0000594void PCHDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
595 VisitDecl(D);
596 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
597 D->setHasBraces(Record[Idx++]);
598}
599
600void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
601 VisitNamedDecl(D);
602 D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx));
603 D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx));
604 D->setNextNamespace(
605 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
606
Chris Lattnerca025db2010-05-07 21:43:38 +0000607 bool IsOriginal = Record[Idx++];
Argyrios Kyrtzidisdae2a162010-07-03 07:57:53 +0000608 D->OrigOrAnonNamespace.setInt(IsOriginal);
609 D->OrigOrAnonNamespace.setPointer(
Chris Lattnerca025db2010-05-07 21:43:38 +0000610 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
611}
612
613void PCHDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
614 VisitNamedDecl(D);
615
616 D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx));
617 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
618 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
619 D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx));
620 D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
621}
622
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000623void PCHDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000624 VisitNamedDecl(D);
625 D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
626 D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
627 D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
628
629 // FIXME: It would probably be more efficient to read these into a vector
630 // and then re-cosntruct the shadow decl set over that vector since it
631 // would avoid existence checks.
632 unsigned NumShadows = Record[Idx++];
633 for(unsigned I = 0; I != NumShadows; ++I) {
Argyrios Kyrtzidis00dda6a2010-07-08 13:09:41 +0000634 // Avoid invariant checking of UsingDecl::addShadowDecl, the decl may still
635 // be initializing.
636 D->Shadows.insert(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattnerca025db2010-05-07 21:43:38 +0000637 }
638 D->setTypeName(Record[Idx++]);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000639 NamedDecl *Pattern = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
640 if (Pattern)
641 Reader.getContext()->setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000642}
643
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000644void PCHDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000645 VisitNamedDecl(D);
646 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
647 D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000648 UsingShadowDecl *Pattern
649 = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]));
650 if (Pattern)
651 Reader.getContext()->setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000652}
653
654void PCHDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
655 VisitNamedDecl(D);
656 D->setNamespaceKeyLocation(Reader.ReadSourceLocation(Record, Idx));
657 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
658 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
659 D->setIdentLocation(Reader.ReadSourceLocation(Record, Idx));
660 D->setNominatedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
661 D->setCommonAncestor(cast_or_null<DeclContext>(
662 Reader.GetDecl(Record[Idx++])));
663}
664
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000665void PCHDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000666 VisitValueDecl(D);
667 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
668 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
669 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
670}
671
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000672void PCHDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000673 UnresolvedUsingTypenameDecl *D) {
674 VisitTypeDecl(D);
675 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
676 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
677 D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx));
678 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
679}
680
681void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000682 ASTContext &C = *Reader.getContext();
683
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000684 // We need to allocate the DefinitionData struct ahead of VisitRecordDecl
685 // so that the other CXXRecordDecls can get a pointer even when the owner
686 // is still initializing.
687 bool OwnsDefinitionData = false;
688 enum DataOwnership { Data_NoDefData, Data_Owner, Data_NotOwner };
689 switch ((DataOwnership)Record[Idx++]) {
690 default:
691 assert(0 && "Out of sync with PCHDeclWriter or messed up reading");
692 case Data_NoDefData:
693 break;
694 case Data_Owner:
695 OwnsDefinitionData = true;
696 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
697 break;
698 case Data_NotOwner:
699 D->DefinitionData
700 = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]))->DefinitionData;
701 break;
702 }
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000703
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000704 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000705
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000706 if (OwnsDefinitionData) {
707 assert(D->DefinitionData);
708 struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData;
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000709
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000710 Data.UserDeclaredConstructor = Record[Idx++];
711 Data.UserDeclaredCopyConstructor = Record[Idx++];
712 Data.UserDeclaredCopyAssignment = Record[Idx++];
713 Data.UserDeclaredDestructor = Record[Idx++];
714 Data.Aggregate = Record[Idx++];
715 Data.PlainOldData = Record[Idx++];
716 Data.Empty = Record[Idx++];
717 Data.Polymorphic = Record[Idx++];
718 Data.Abstract = Record[Idx++];
719 Data.HasTrivialConstructor = Record[Idx++];
720 Data.HasTrivialCopyConstructor = Record[Idx++];
721 Data.HasTrivialCopyAssignment = Record[Idx++];
722 Data.HasTrivialDestructor = Record[Idx++];
723 Data.ComputedVisibleConversions = Record[Idx++];
724 Data.DeclaredDefaultConstructor = Record[Idx++];
725 Data.DeclaredCopyConstructor = Record[Idx++];
726 Data.DeclaredCopyAssignment = Record[Idx++];
727 Data.DeclaredDestructor = Record[Idx++];
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000728
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000729 // setBases() is unsuitable since it may try to iterate the bases of an
Nick Lewycky19b9f952010-07-26 16:56:01 +0000730 // uninitialized base.
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000731 Data.NumBases = Record[Idx++];
732 Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases];
733 for (unsigned i = 0; i != Data.NumBases; ++i)
Nick Lewycky19b9f952010-07-26 16:56:01 +0000734 Data.Bases[i] = Reader.ReadCXXBaseSpecifier(Cursor, Record, Idx);
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000735
736 // FIXME: Make VBases lazily computed when needed to avoid storing them.
737 Data.NumVBases = Record[Idx++];
738 Data.VBases = new(C) CXXBaseSpecifier [Data.NumVBases];
739 for (unsigned i = 0; i != Data.NumVBases; ++i)
Nick Lewycky19b9f952010-07-26 16:56:01 +0000740 Data.VBases[i] = Reader.ReadCXXBaseSpecifier(Cursor, Record, Idx);
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000741
742 Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx);
743 Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx);
744 assert(Data.Definition && "Data.Definition should be already set!");
745 Data.FirstFriend
746 = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000747 }
748
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000749 enum CXXRecKind {
750 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
751 };
752 switch ((CXXRecKind)Record[Idx++]) {
753 default:
754 assert(false && "Out of sync with PCHDeclWriter::VisitCXXRecordDecl?");
755 case CXXRecNotTemplate:
756 break;
757 case CXXRecTemplate:
758 D->setDescribedClassTemplate(
759 cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++])));
760 break;
761 case CXXRecMemberSpecialization: {
762 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
763 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
764 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
765 D->setInstantiationOfMemberClass(RD, TSK);
766 D->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
767 break;
768 }
769 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000770}
771
772void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000773 VisitFunctionDecl(D);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000774 unsigned NumOverridenMethods = Record[Idx++];
775 while (NumOverridenMethods--) {
776 CXXMethodDecl *MD = cast<CXXMethodDecl>(Reader.GetDecl(Record[Idx++]));
777 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
778 // MD may be initializing.
779 Reader.getContext()->addOverriddenMethod(D, MD);
780 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000781}
782
783void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000784 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000785
786 D->IsExplicitSpecified = Record[Idx++];
787 D->ImplicitlyDefined = Record[Idx++];
788
789 unsigned NumInitializers = Record[Idx++];
790 D->NumBaseOrMemberInitializers = NumInitializers;
791 if (NumInitializers) {
792 ASTContext &C = *Reader.getContext();
793
794 D->BaseOrMemberInitializers
795 = new (C) CXXBaseOrMemberInitializer*[NumInitializers];
796 for (unsigned i=0; i != NumInitializers; ++i) {
Duncan Sands16143962010-07-06 18:19:40 +0000797 TypeSourceInfo *BaseClassInfo = 0;
798 bool IsBaseVirtual = false;
799 FieldDecl *Member = 0;
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000800
801 bool IsBaseInitializer = Record[Idx++];
802 if (IsBaseInitializer) {
Sebastian Redlc67764e2010-07-22 22:43:28 +0000803 BaseClassInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000804 IsBaseVirtual = Record[Idx++];
805 } else {
806 Member = cast<FieldDecl>(Reader.GetDecl(Record[Idx++]));
807 }
808 SourceLocation MemberLoc = Reader.ReadSourceLocation(Record, Idx);
Sebastian Redlc67764e2010-07-22 22:43:28 +0000809 Expr *Init = Reader.ReadExpr(Cursor);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000810 FieldDecl *AnonUnionMember
811 = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
812 SourceLocation LParenLoc = Reader.ReadSourceLocation(Record, Idx);
813 SourceLocation RParenLoc = Reader.ReadSourceLocation(Record, Idx);
814 bool IsWritten = Record[Idx++];
815 unsigned SourceOrderOrNumArrayIndices;
816 llvm::SmallVector<VarDecl *, 8> Indices;
817 if (IsWritten) {
818 SourceOrderOrNumArrayIndices = Record[Idx++];
819 } else {
820 SourceOrderOrNumArrayIndices = Record[Idx++];
821 Indices.reserve(SourceOrderOrNumArrayIndices);
822 for (unsigned i=0; i != SourceOrderOrNumArrayIndices; ++i)
823 Indices.push_back(cast<VarDecl>(Reader.GetDecl(Record[Idx++])));
824 }
825
826 CXXBaseOrMemberInitializer *BOMInit;
827 if (IsBaseInitializer) {
828 BOMInit = new (C) CXXBaseOrMemberInitializer(C, BaseClassInfo,
829 IsBaseVirtual, LParenLoc,
830 Init, RParenLoc);
831 } else if (IsWritten) {
832 BOMInit = new (C) CXXBaseOrMemberInitializer(C, Member, MemberLoc,
833 LParenLoc, Init, RParenLoc);
834 } else {
835 BOMInit = CXXBaseOrMemberInitializer::Create(C, Member, MemberLoc,
836 LParenLoc, Init, RParenLoc,
837 Indices.data(),
838 Indices.size());
839 }
840
841 BOMInit->setAnonUnionMember(AnonUnionMember);
842 D->BaseOrMemberInitializers[i] = BOMInit;
843 }
844 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000845}
846
847void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000848 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000849
850 D->ImplicitlyDefined = Record[Idx++];
851 D->OperatorDelete = cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000852}
853
854void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000855 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000856 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000857}
858
Abramo Bagnarad7340582010-06-05 05:09:32 +0000859void PCHDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
860 VisitDecl(D);
861 D->setColonLoc(Reader.ReadSourceLocation(Record, Idx));
862}
863
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000864void PCHDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000865 VisitDecl(D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000866 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000867 D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000868 else
869 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
870 D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
871 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
872}
873
Chris Lattnerca025db2010-05-07 21:43:38 +0000874void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +0000875 VisitDecl(D);
876 unsigned NumParams = Record[Idx++];
877 D->NumParams = NumParams;
878 D->Params = new TemplateParameterList*[NumParams];
879 for (unsigned i = 0; i != NumParams; ++i)
880 D->Params[i] = Reader.ReadTemplateParameterList(Record, Idx);
881 if (Record[Idx++]) // HasFriendDecl
882 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
883 else
Sebastian Redlc67764e2010-07-22 22:43:28 +0000884 D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +0000885 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000886}
887
888void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000889 VisitNamedDecl(D);
890
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +0000891 NamedDecl *TemplatedDecl
892 = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000893 TemplateParameterList* TemplateParams
894 = Reader.ReadTemplateParameterList(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000895 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +0000896}
897
898void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000899 VisitTemplateDecl(D);
900
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000901 D->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000902 ClassTemplateDecl *PrevDecl =
903 cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +0000904 D->setPreviousDeclaration(PrevDecl);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000905 if (PrevDecl == 0) {
906 // This ClassTemplateDecl owns a CommonPtr; read it.
907
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000908 // FoldingSets are filled in VisitClassTemplateSpecializationDecl.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000909 unsigned size = Record[Idx++];
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000910 while (size--)
911 cast<ClassTemplateSpecializationDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000912
913 size = Record[Idx++];
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000914 while (size--)
915 cast<ClassTemplatePartialSpecializationDecl>(
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000916 Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000917
918 // InjectedClassNameType is computed.
919
920 if (ClassTemplateDecl *CTD
921 = cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
922 D->setInstantiatedFromMemberTemplate(CTD);
923 if (Record[Idx++])
924 D->setMemberSpecialization();
925 }
926 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000927}
928
929void PCHDeclReader::VisitClassTemplateSpecializationDecl(
930 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000931 VisitCXXRecordDecl(D);
932
933 if (Decl *InstD = Reader.GetDecl(Record[Idx++])) {
934 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
935 D->setInstantiationOf(CTD);
936 } else {
937 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000938 Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000939 D->setInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(InstD),
940 TemplArgs.data(), TemplArgs.size());
941 }
942 }
943
944 // Explicit info.
Sebastian Redlc67764e2010-07-22 22:43:28 +0000945 if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx)) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000946 D->setTypeAsWritten(TyInfo);
947 D->setExternLoc(Reader.ReadSourceLocation(Record, Idx));
948 D->setTemplateKeywordLoc(Reader.ReadSourceLocation(Record, Idx));
949 }
950
951 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000952 Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000953 D->initTemplateArgs(TemplArgs.data(), TemplArgs.size());
954 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
955 if (POI.isValid())
956 D->setPointOfInstantiation(POI);
957 D->setSpecializationKind((TemplateSpecializationKind)Record[Idx++]);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000958
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +0000959 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000960 ClassTemplateDecl *CanonPattern
961 = cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
962 if (ClassTemplatePartialSpecializationDecl *Partial
963 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
Argyrios Kyrtzidisf4cc7dc2010-07-12 21:41:31 +0000964 CanonPattern->getPartialSpecializations().InsertNode(Partial);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000965 } else {
Argyrios Kyrtzidisf4cc7dc2010-07-12 21:41:31 +0000966 CanonPattern->getSpecializations().InsertNode(D);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000967 }
968 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000969}
970
971void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl(
972 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000973 VisitClassTemplateSpecializationDecl(D);
974
975 D->initTemplateParameters(Reader.ReadTemplateParameterList(Record, Idx));
976
977 TemplateArgumentListInfo ArgInfos;
978 unsigned NumArgs = Record[Idx++];
979 while (NumArgs--)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000980 ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000981 D->initTemplateArgsAsWritten(ArgInfos);
982
983 D->setSequenceNumber(Record[Idx++]);
984
985 // These are read/set from/to the first declaration.
986 if (D->getPreviousDeclaration() == 0) {
987 D->setInstantiatedFromMember(
988 cast_or_null<ClassTemplatePartialSpecializationDecl>(
989 Reader.GetDecl(Record[Idx++])));
990 if (Record[Idx++])
Argyrios Kyrtzidisdd2061b2010-07-09 21:11:35 +0000991 D->setMemberSpecialization();
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000992 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000993}
994
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000995void PCHDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
996 VisitTemplateDecl(D);
997
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000998 D->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000999 FunctionTemplateDecl *PrevDecl =
1000 cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
1001 D->setPreviousDeclaration(PrevDecl);
1002 if (PrevDecl == 0) {
1003 // This FunctionTemplateDecl owns a CommonPtr; read it.
1004
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001005 // Read the function specialization declarations.
1006 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
1007 // through the specialized FunctionDecl's setFunctionTemplateSpecialization.
1008 unsigned NumSpecs = Record[Idx++];
1009 while (NumSpecs--)
1010 Reader.GetDecl(Record[Idx++]);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001011
1012 if (FunctionTemplateDecl *CTD
1013 = cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
1014 D->setInstantiatedFromMemberTemplate(CTD);
1015 if (Record[Idx++])
1016 D->setMemberSpecialization();
1017 }
1018 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001019}
1020
1021void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001022 VisitTypeDecl(D);
1023
1024 D->setDeclaredWithTypename(Record[Idx++]);
1025 D->setParameterPack(Record[Idx++]);
1026
1027 bool Inherited = Record[Idx++];
Sebastian Redlc67764e2010-07-22 22:43:28 +00001028 TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001029 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001030}
1031
1032void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001033 VisitVarDecl(D);
1034 // TemplateParmPosition.
1035 D->setDepth(Record[Idx++]);
1036 D->setPosition(Record[Idx++]);
1037 // Rest of NonTypeTemplateParmDecl.
1038 if (Record[Idx++]) {
Sebastian Redlc67764e2010-07-22 22:43:28 +00001039 Expr *DefArg = Reader.ReadExpr(Cursor);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001040 bool Inherited = Record[Idx++];
1041 D->setDefaultArgument(DefArg, Inherited);
1042 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001043}
1044
1045void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001046 VisitTemplateDecl(D);
1047 // TemplateParmPosition.
1048 D->setDepth(Record[Idx++]);
1049 D->setPosition(Record[Idx++]);
1050 // Rest of TemplateTemplateParmDecl.
Sebastian Redlc67764e2010-07-22 22:43:28 +00001051 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx);
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001052 bool IsInherited = Record[Idx++];
1053 D->setDefaultArgument(Arg, IsInherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001054}
1055
1056void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001057 VisitDecl(D);
Sebastian Redlc67764e2010-07-22 22:43:28 +00001058 D->AssertExpr = Reader.ReadExpr(Cursor);
1059 D->Message = cast<StringLiteral>(Reader.ReadExpr(Cursor));
Chris Lattnerca025db2010-05-07 21:43:38 +00001060}
1061
Mike Stump11289f42009-09-09 15:08:12 +00001062std::pair<uint64_t, uint64_t>
Chris Lattner487412d2009-04-27 05:27:42 +00001063PCHDeclReader::VisitDeclContext(DeclContext *DC) {
1064 uint64_t LexicalOffset = Record[Idx++];
1065 uint64_t VisibleOffset = Record[Idx++];
1066 return std::make_pair(LexicalOffset, VisibleOffset);
1067}
1068
1069//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00001070// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00001071//===----------------------------------------------------------------------===//
1072
Chris Lattner8f63ab52009-04-27 06:01:06 +00001073/// \brief Reads attributes from the current stream position.
Sebastian Redlc67764e2010-07-22 22:43:28 +00001074Attr *PCHReader::ReadAttributes(llvm::BitstreamCursor &DeclsCursor) {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001075 unsigned Code = DeclsCursor.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +00001076 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner8f63ab52009-04-27 06:01:06 +00001077 "Expected unabbreviated record"); (void)Code;
Mike Stump11289f42009-09-09 15:08:12 +00001078
Chris Lattner8f63ab52009-04-27 06:01:06 +00001079 RecordData Record;
1080 unsigned Idx = 0;
1081 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump11289f42009-09-09 15:08:12 +00001082 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001083 (void)RecCode;
1084
1085#define SIMPLE_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001086 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +00001087 New = ::new (*Context) Name##Attr(); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001088 break
1089
1090#define STRING_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001091 case attr::Name: \
Ted Kremenek7f4945a2010-02-11 05:28:37 +00001092 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001093 break
1094
1095#define UNSIGNED_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001096 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +00001097 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001098 break
1099
1100 Attr *Attrs = 0;
1101 while (Idx < Record.size()) {
1102 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001103 attr::Kind Kind = (attr::Kind)Record[Idx++];
Chris Lattner8f63ab52009-04-27 06:01:06 +00001104 bool IsInherited = Record[Idx++];
1105
1106 switch (Kind) {
Anton Korobeynikov55bcea12010-01-10 12:58:08 +00001107 default:
1108 assert(0 && "Unknown attribute!");
1109 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001110 STRING_ATTR(Alias);
Daniel Dunbarfc6507e2010-05-27 02:25:39 +00001111 SIMPLE_ATTR(AlignMac68k);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001112 UNSIGNED_ATTR(Aligned);
1113 SIMPLE_ATTR(AlwaysInline);
1114 SIMPLE_ATTR(AnalyzerNoReturn);
1115 STRING_ATTR(Annotate);
1116 STRING_ATTR(AsmLabel);
Alexis Hunt54a02542009-11-25 04:20:27 +00001117 SIMPLE_ATTR(BaseCheck);
Mike Stump11289f42009-09-09 15:08:12 +00001118
Alexis Hunt344393e2010-06-16 23:43:53 +00001119 case attr::Blocks:
Chris Lattner8575daa2009-04-27 21:45:14 +00001120 New = ::new (*Context) BlocksAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001121 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
1122 break;
Mike Stump11289f42009-09-09 15:08:12 +00001123
Eli Friedmane4310c82009-11-09 18:38:53 +00001124 SIMPLE_ATTR(CDecl);
1125
Alexis Hunt344393e2010-06-16 23:43:53 +00001126 case attr::Cleanup:
Chris Lattner8575daa2009-04-27 21:45:14 +00001127 New = ::new (*Context) CleanupAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001128 cast<FunctionDecl>(GetDecl(Record[Idx++])));
1129 break;
1130
1131 SIMPLE_ATTR(Const);
1132 UNSIGNED_ATTR(Constructor);
1133 SIMPLE_ATTR(DLLExport);
1134 SIMPLE_ATTR(DLLImport);
1135 SIMPLE_ATTR(Deprecated);
1136 UNSIGNED_ATTR(Destructor);
1137 SIMPLE_ATTR(FastCall);
Alexis Hunt96d5c762009-11-21 08:43:09 +00001138 SIMPLE_ATTR(Final);
Mike Stump11289f42009-09-09 15:08:12 +00001139
Alexis Hunt344393e2010-06-16 23:43:53 +00001140 case attr::Format: {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001141 std::string Type = ReadString(Record, Idx);
1142 unsigned FormatIdx = Record[Idx++];
1143 unsigned FirstArg = Record[Idx++];
Ted Kremenek7f4945a2010-02-11 05:28:37 +00001144 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001145 break;
1146 }
Mike Stump11289f42009-09-09 15:08:12 +00001147
Alexis Hunt344393e2010-06-16 23:43:53 +00001148 case attr::FormatArg: {
Fariborz Jahanianf1c25022009-05-20 17:41:43 +00001149 unsigned FormatIdx = Record[Idx++];
1150 New = ::new (*Context) FormatArgAttr(FormatIdx);
1151 break;
1152 }
Mike Stump11289f42009-09-09 15:08:12 +00001153
Alexis Hunt344393e2010-06-16 23:43:53 +00001154 case attr::Sentinel: {
Fariborz Jahanian027b8862009-05-13 18:09:35 +00001155 int sentinel = Record[Idx++];
1156 int nullPos = Record[Idx++];
1157 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
1158 break;
1159 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001160
1161 SIMPLE_ATTR(GNUInline);
Alexis Hunt54a02542009-11-25 04:20:27 +00001162 SIMPLE_ATTR(Hiding);
Mike Stump11289f42009-09-09 15:08:12 +00001163
Alexis Hunt344393e2010-06-16 23:43:53 +00001164 case attr::IBAction:
Ted Kremenek06be9682010-02-17 02:37:45 +00001165 New = ::new (*Context) IBActionAttr();
1166 break;
1167
Alexis Hunt344393e2010-06-16 23:43:53 +00001168 case attr::IBOutlet:
Chris Lattner8575daa2009-04-27 21:45:14 +00001169 New = ::new (*Context) IBOutletAttr();
Chris Lattner8f63ab52009-04-27 06:01:06 +00001170 break;
1171
Alexis Hunt344393e2010-06-16 23:43:53 +00001172 case attr::IBOutletCollection: {
Ted Kremenek26bde772010-05-19 17:38:06 +00001173 ObjCInterfaceDecl *D =
1174 cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++]));
1175 New = ::new (*Context) IBOutletCollectionAttr(D);
1176 break;
1177 }
1178
Ryan Flynn1f1fdc02009-08-09 20:07:29 +00001179 SIMPLE_ATTR(Malloc);
Mike Stump3722f582009-08-26 22:31:08 +00001180 SIMPLE_ATTR(NoDebug);
1181 SIMPLE_ATTR(NoInline);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001182 SIMPLE_ATTR(NoReturn);
1183 SIMPLE_ATTR(NoThrow);
Mike Stump11289f42009-09-09 15:08:12 +00001184
Alexis Hunt344393e2010-06-16 23:43:53 +00001185 case attr::NonNull: {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001186 unsigned Size = Record[Idx++];
1187 llvm::SmallVector<unsigned, 16> ArgNums;
1188 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
1189 Idx += Size;
Ted Kremenek510ee252010-02-11 07:31:47 +00001190 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001191 break;
1192 }
Mike Stump11289f42009-09-09 15:08:12 +00001193
Alexis Hunt344393e2010-06-16 23:43:53 +00001194 case attr::ReqdWorkGroupSize: {
Nate Begemanf2758702009-06-26 06:32:41 +00001195 unsigned X = Record[Idx++];
1196 unsigned Y = Record[Idx++];
1197 unsigned Z = Record[Idx++];
1198 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
1199 break;
1200 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001201
1202 SIMPLE_ATTR(ObjCException);
1203 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekd9c66632010-02-18 00:05:45 +00001204 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +00001205 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenekd9c66632010-02-18 00:05:45 +00001206 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +00001207 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001208 SIMPLE_ATTR(Overloadable);
Alexis Hunt54a02542009-11-25 04:20:27 +00001209 SIMPLE_ATTR(Override);
Anders Carlsson68e0b682009-08-08 18:23:56 +00001210 SIMPLE_ATTR(Packed);
Daniel Dunbar40130442010-05-27 01:12:46 +00001211 UNSIGNED_ATTR(MaxFieldAlignment);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001212 SIMPLE_ATTR(Pure);
1213 UNSIGNED_ATTR(Regparm);
1214 STRING_ATTR(Section);
1215 SIMPLE_ATTR(StdCall);
Douglas Gregora941dca2010-05-18 16:57:00 +00001216 SIMPLE_ATTR(ThisCall);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001217 SIMPLE_ATTR(TransparentUnion);
1218 SIMPLE_ATTR(Unavailable);
1219 SIMPLE_ATTR(Unused);
1220 SIMPLE_ATTR(Used);
Mike Stump11289f42009-09-09 15:08:12 +00001221
Alexis Hunt344393e2010-06-16 23:43:53 +00001222 case attr::Visibility:
Chris Lattner8575daa2009-04-27 21:45:14 +00001223 New = ::new (*Context) VisibilityAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001224 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
1225 break;
1226
1227 SIMPLE_ATTR(WarnUnusedResult);
1228 SIMPLE_ATTR(Weak);
Rafael Espindolac18086a2010-02-23 22:00:30 +00001229 SIMPLE_ATTR(WeakRef);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001230 SIMPLE_ATTR(WeakImport);
1231 }
1232
1233 assert(New && "Unable to decode attribute?");
1234 New->setInherited(IsInherited);
1235 New->setNext(Attrs);
1236 Attrs = New;
1237 }
1238#undef UNSIGNED_ATTR
1239#undef STRING_ATTR
1240#undef SIMPLE_ATTR
1241
1242 // The list of attributes was built backwards. Reverse the list
1243 // before returning it.
1244 Attr *PrevAttr = 0, *NextAttr = 0;
1245 while (Attrs) {
1246 NextAttr = Attrs->getNext();
1247 Attrs->setNext(PrevAttr);
1248 PrevAttr = Attrs;
1249 Attrs = NextAttr;
1250 }
1251
1252 return PrevAttr;
1253}
1254
1255//===----------------------------------------------------------------------===//
1256// PCHReader Implementation
1257//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001258
1259/// \brief Note that we have loaded the declaration with the given
1260/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001261///
Chris Lattner487412d2009-04-27 05:27:42 +00001262/// This routine notes that this declaration has already been loaded,
1263/// so that future GetDecl calls will return this declaration rather
1264/// than trying to load a new declaration.
1265inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
1266 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1267 DeclsLoaded[Index] = D;
1268}
1269
1270
1271/// \brief Determine whether the consumer will be interested in seeing
1272/// this declaration (via HandleTopLevelDecl).
1273///
1274/// This routine should return true for anything that might affect
1275/// code generation, e.g., inline function definitions, Objective-C
1276/// declarations with metadata, etc.
1277static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001278 if (isa<FileScopeAsmDecl>(D))
1279 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001280 if (VarDecl *Var = dyn_cast<VarDecl>(D))
1281 return Var->isFileVarDecl() && Var->getInit();
1282 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1283 return Func->isThisDeclarationADefinition();
1284 return isa<ObjCProtocolDecl>(D);
1285}
1286
Sebastian Redl34627792010-07-20 22:46:15 +00001287/// \brief Get the correct cursor and offset for loading a type.
1288PCHReader::RecordLocation PCHReader::DeclCursorForIndex(unsigned Index) {
1289 PerFileData *F = 0;
1290 for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
1291 F = Chain[N - I - 1];
1292 if (Index < F->LocalNumDecls)
1293 break;
1294 Index -= F->LocalNumDecls;
1295 }
1296 assert(F && F->LocalNumDecls > Index && "Broken chain");
Sebastian Redlb2831db2010-07-20 22:55:31 +00001297 return RecordLocation(&F->DeclsCursor, F->DeclOffsets[Index]);
Sebastian Redl34627792010-07-20 22:46:15 +00001298}
1299
Chris Lattner487412d2009-04-27 05:27:42 +00001300/// \brief Read the declaration at the given offset from the PCH file.
Sebastian Redl34627792010-07-20 22:46:15 +00001301Decl *PCHReader::ReadDeclRecord(unsigned Index) {
1302 RecordLocation Loc = DeclCursorForIndex(Index);
Sebastian Redlb2831db2010-07-20 22:55:31 +00001303 llvm::BitstreamCursor &DeclsCursor = *Loc.first;
Chris Lattner487412d2009-04-27 05:27:42 +00001304 // Keep track of where we are in the stream, then jump back there
1305 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001306 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001307
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001308 ReadingKindTracker ReadingKind(Read_Decl, *this);
1309
Douglas Gregor1342e842009-07-06 18:54:52 +00001310 // Note that we are loading a declaration record.
1311 LoadingTypeOrDecl Loading(*this);
Mike Stump11289f42009-09-09 15:08:12 +00001312
Sebastian Redl34627792010-07-20 22:46:15 +00001313 DeclsCursor.JumpToBit(Loc.second);
Chris Lattner487412d2009-04-27 05:27:42 +00001314 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001315 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001316 unsigned Idx = 0;
Sebastian Redlc67764e2010-07-22 22:43:28 +00001317 PCHDeclReader Reader(*this, DeclsCursor, Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +00001318
Chris Lattner1de76db2009-04-27 05:58:23 +00001319 Decl *D = 0;
1320 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner487412d2009-04-27 05:27:42 +00001321 case pch::DECL_ATTR:
1322 case pch::DECL_CONTEXT_LEXICAL:
1323 case pch::DECL_CONTEXT_VISIBLE:
1324 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1325 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001326 case pch::DECL_TRANSLATION_UNIT:
1327 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +00001328 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +00001329 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001330 case pch::DECL_TYPEDEF:
John McCall703a3f82009-10-24 08:00:42 +00001331 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001332 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001333 case pch::DECL_ENUM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001334 D = EnumDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001335 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001336 case pch::DECL_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001337 D = RecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001338 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001339 case pch::DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +00001340 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001341 0, llvm::APSInt());
1342 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001343 case pch::DECL_FUNCTION:
Mike Stump11289f42009-09-09 15:08:12 +00001344 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001345 QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001346 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001347 case pch::DECL_LINKAGE_SPEC:
1348 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
1349 (LinkageSpecDecl::LanguageIDs)0,
1350 false);
1351 break;
1352 case pch::DECL_NAMESPACE:
1353 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
1354 break;
1355 case pch::DECL_NAMESPACE_ALIAS:
1356 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
1357 SourceLocation(), 0, SourceRange(), 0,
1358 SourceLocation(), 0);
1359 break;
1360 case pch::DECL_USING:
1361 D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(),
1362 SourceLocation(), 0, DeclarationName(), false);
1363 break;
1364 case pch::DECL_USING_SHADOW:
1365 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1366 break;
1367 case pch::DECL_USING_DIRECTIVE:
1368 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
1369 SourceLocation(), SourceRange(), 0,
1370 SourceLocation(), 0, 0);
1371 break;
1372 case pch::DECL_UNRESOLVED_USING_VALUE:
1373 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
1374 SourceRange(), 0, SourceLocation(),
1375 DeclarationName());
1376 break;
1377 case pch::DECL_UNRESOLVED_USING_TYPENAME:
1378 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
1379 SourceLocation(), SourceRange(),
1380 0, SourceLocation(),
1381 DeclarationName());
1382 break;
1383 case pch::DECL_CXX_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001384 D = CXXRecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001385 break;
1386 case pch::DECL_CXX_METHOD:
1387 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
1388 QualType(), 0);
1389 break;
1390 case pch::DECL_CXX_CONSTRUCTOR:
1391 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1392 break;
1393 case pch::DECL_CXX_DESTRUCTOR:
1394 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1395 break;
1396 case pch::DECL_CXX_CONVERSION:
1397 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1398 break;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001399 case pch::DECL_ACCESS_SPEC:
1400 D = AccessSpecDecl::Create(*Context, AS_none, 0, SourceLocation(),
1401 SourceLocation());
1402 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001403 case pch::DECL_FRIEND:
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001404 D = FriendDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001405 break;
1406 case pch::DECL_FRIEND_TEMPLATE:
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001407 D = FriendTemplateDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001408 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001409 case pch::DECL_CLASS_TEMPLATE:
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +00001410 D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(),
1411 DeclarationName(), 0, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001412 break;
1413 case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001414 D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001415 break;
1416 case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001417 D = ClassTemplatePartialSpecializationDecl::Create(*Context,
1418 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001419 break;
1420 case pch::DECL_FUNCTION_TEMPLATE:
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001421 D = FunctionTemplateDecl::Create(*Context, 0, SourceLocation(),
1422 DeclarationName(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001423 break;
1424 case pch::DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001425 D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001426 break;
1427 case pch::DECL_NON_TYPE_TEMPLATE_PARM:
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001428 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0,
1429 QualType(),0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001430 break;
1431 case pch::DECL_TEMPLATE_TEMPLATE_PARM:
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001432 D = TemplateTemplateParmDecl::Create(*Context, 0, SourceLocation(),0,0,0,0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001433 break;
1434 case pch::DECL_STATIC_ASSERT:
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001435 D = StaticAssertDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001436 break;
1437
Chris Lattner8f63ab52009-04-27 06:01:06 +00001438 case pch::DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +00001439 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001440 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001441 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001442 case pch::DECL_OBJC_INTERFACE:
Chris Lattner8575daa2009-04-27 21:45:14 +00001443 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001444 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001445 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001446 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001447 ObjCIvarDecl::None);
1448 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001449 case pch::DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001450 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001451 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001452 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001453 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001454 QualType(), 0);
1455 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001456 case pch::DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001457 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001458 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001459 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001460 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001461 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001462 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +00001463 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1464 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001465 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001466 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001467 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001468 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001469 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +00001470 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001471 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001472 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001473 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001474 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001475 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001476 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001477 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001478 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001479 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001480 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001481 SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001482 ObjCPropertyImplDecl::Dynamic, 0);
1483 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001484 case pch::DECL_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001485 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +00001486 false);
Chris Lattner487412d2009-04-27 05:27:42 +00001487 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001488 case pch::DECL_VAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001489 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001490 VarDecl::None, VarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001491 break;
1492
1493 case pch::DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001494 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001495 break;
1496
Chris Lattner8f63ab52009-04-27 06:01:06 +00001497 case pch::DECL_PARM_VAR:
Mike Stump11289f42009-09-09 15:08:12 +00001498 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001499 VarDecl::None, VarDecl::None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001500 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001501 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001502 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001503 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001504 case pch::DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +00001505 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001506 break;
1507 }
Chris Lattner487412d2009-04-27 05:27:42 +00001508
1509 assert(D && "Unknown declaration reading PCH file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001510 LoadedDecl(Index, D);
1511 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001512
1513 // If this declaration is also a declaration context, get the
1514 // offsets for its tables of lexical and visible declarations.
1515 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1516 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1517 if (Offsets.first || Offsets.second) {
1518 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1519 DC->setHasExternalVisibleStorage(Offsets.second != 0);
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001520 DeclContextInfo Info;
1521 if (ReadDeclContextStorage(DeclsCursor, Offsets, Info))
1522 return 0;
Sebastian Redl4b1f4902010-07-27 18:24:41 +00001523 DeclContextInfos &Infos = DeclContextOffsets[DC];
1524 // Reading the TU will happen after reading its update blocks, so we need
1525 // to make sure we insert in front. For all other contexts, the vector
1526 // is empty here anyway, so there's no loss in efficiency.
1527 Infos.insert(Infos.begin(), Info);
Chris Lattner487412d2009-04-27 05:27:42 +00001528 }
1529 }
1530 assert(Idx == Record.size());
1531
1532 // If we have deserialized a declaration that has a definition the
Argyrios Kyrtzidis903ccd62010-07-07 15:46:26 +00001533 // AST consumer might need to know about, queue it.
1534 // We don't pass it to the consumer immediately because we may be in recursive
1535 // loading, and some declarations may still be initializing.
1536 if (isConsumerInterestedIn(D))
1537 InterestingDecls.push_back(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001538
1539 return D;
1540}
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001541
1542bool PCHReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor,
1543 const std::pair<uint64_t, uint64_t> &Offsets,
1544 DeclContextInfo &Info) {
1545 SavedStreamPosition SavedPosition(Cursor);
1546 // First the lexical decls.
1547 if (Offsets.first != 0) {
1548 Cursor.JumpToBit(Offsets.first);
1549
1550 RecordData Record;
1551 const char *Blob;
1552 unsigned BlobLen;
1553 unsigned Code = Cursor.ReadCode();
1554 unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen);
1555 if (RecCode != pch::DECL_CONTEXT_LEXICAL) {
1556 Error("Expected lexical block");
1557 return true;
1558 }
1559
1560 Info.LexicalDecls = reinterpret_cast<const pch::DeclID*>(Blob);
1561 Info.NumLexicalDecls = BlobLen / sizeof(pch::DeclID);
1562 } else {
1563 Info.LexicalDecls = 0;
1564 Info.NumLexicalDecls = 0;
1565 }
1566
1567 // Now the visible decls.
1568 Info.Stream = &Cursor;
1569 Info.OffsetToVisibleDecls = Offsets.second;
1570
1571 return false;
1572}