blob: 2930ca73b9aea669aa59b318f44e642beb084d86 [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;
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +000034 const pch::DeclID ThisDeclID;
Chris Lattner487412d2009-04-27 05:27:42 +000035 const PCHReader::RecordData &Record;
36 unsigned &Idx;
Sebastian Redlab6a0882010-08-09 21:55:28 +000037 pch::TypeID TypeIDForDecl;
Chris Lattner487412d2009-04-27 05:27:42 +000038
Sebastian Redlc67764e2010-07-22 22:43:28 +000039 uint64_t GetCurrentCursorOffset();
40
Chris Lattner487412d2009-04-27 05:27:42 +000041 public:
Sebastian Redlc67764e2010-07-22 22:43:28 +000042 PCHDeclReader(PCHReader &Reader, llvm::BitstreamCursor &Cursor,
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +000043 pch::DeclID thisDeclID, const PCHReader::RecordData &Record,
44 unsigned &Idx)
45 : Reader(Reader), Cursor(Cursor), ThisDeclID(thisDeclID), Record(Record),
Sebastian Redlab6a0882010-08-09 21:55:28 +000046 Idx(Idx), TypeIDForDecl(0) { }
Chris Lattner487412d2009-04-27 05:27:42 +000047
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +000048 void Visit(Decl *D);
49
Chris Lattner487412d2009-04-27 05:27:42 +000050 void VisitDecl(Decl *D);
51 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
52 void VisitNamedDecl(NamedDecl *ND);
Douglas Gregore31bbd92010-02-21 18:22:14 +000053 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000054 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
55 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000056 void VisitTypeDecl(TypeDecl *TD);
57 void VisitTypedefDecl(TypedefDecl *TD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000058 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000059 void VisitTagDecl(TagDecl *TD);
60 void VisitEnumDecl(EnumDecl *ED);
61 void VisitRecordDecl(RecordDecl *RD);
Chris Lattnerca025db2010-05-07 21:43:38 +000062 void VisitCXXRecordDecl(CXXRecordDecl *D);
63 void VisitClassTemplateSpecializationDecl(
64 ClassTemplateSpecializationDecl *D);
65 void VisitClassTemplatePartialSpecializationDecl(
66 ClassTemplatePartialSpecializationDecl *D);
67 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000068 void VisitValueDecl(ValueDecl *VD);
69 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000070 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +000071 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +000072 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattnerca025db2010-05-07 21:43:38 +000073 void VisitCXXMethodDecl(CXXMethodDecl *D);
74 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
75 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
76 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000077 void VisitFieldDecl(FieldDecl *FD);
78 void VisitVarDecl(VarDecl *VD);
79 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
80 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattnerca025db2010-05-07 21:43:38 +000081 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
82 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +000083 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000084 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +000085 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000086 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +000087 void VisitUsingDecl(UsingDecl *D);
88 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000089 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000090 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Abramo Bagnarad7340582010-06-05 05:09:32 +000091 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000092 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000093 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
94 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000095 void VisitBlockDecl(BlockDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +000096
Chris Lattner487412d2009-04-27 05:27:42 +000097 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +000098 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000099
Alexis Hunted053252010-05-30 07:21:58 +0000100 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-04-27 05:27:42 +0000101 void VisitObjCMethodDecl(ObjCMethodDecl *D);
102 void VisitObjCContainerDecl(ObjCContainerDecl *D);
103 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
104 void VisitObjCIvarDecl(ObjCIvarDecl *D);
105 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
106 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
107 void VisitObjCClassDecl(ObjCClassDecl *D);
108 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
109 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
110 void VisitObjCImplDecl(ObjCImplDecl *D);
111 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
112 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
113 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
114 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
115 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
116 };
117}
118
Sebastian Redlc67764e2010-07-22 22:43:28 +0000119uint64_t PCHDeclReader::GetCurrentCursorOffset() {
120 uint64_t Off = 0;
121 for (unsigned I = 0, N = Reader.Chain.size(); I != N; ++I) {
122 PCHReader::PerFileData &F = *Reader.Chain[N - I - 1];
123 if (&Cursor == &F.DeclsCursor) {
124 Off += F.DeclsCursor.GetCurrentBitNo();
125 break;
126 }
127 Off += F.SizeInBits;
128 }
129 return Off;
130}
131
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000132void PCHDeclReader::Visit(Decl *D) {
133 DeclVisitor<PCHDeclReader, void>::Visit(D);
134
Sebastian Redlab6a0882010-08-09 21:55:28 +0000135 // if we have a fully initialized Decl, we can safely read its type now.
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000136 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
Sebastian Redlab6a0882010-08-09 21:55:28 +0000137 TD->setTypeForDecl(Reader.GetType(TypeIDForDecl).getTypePtr());
138 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
139 ID->setTypeForDecl(Reader.GetType(TypeIDForDecl).getTypePtr());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000140 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
141 // FunctionDecl's body was written last after all other Stmts/Exprs.
142 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000143 FD->setLazyBody(GetCurrentCursorOffset());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000144 }
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000145}
146
Chris Lattner487412d2009-04-27 05:27:42 +0000147void PCHDeclReader::VisitDecl(Decl *D) {
148 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
149 D->setLexicalDeclContext(
150 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
151 D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
152 D->setInvalidDecl(Record[Idx++]);
153 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000154 D->initAttrs(Reader.ReadAttributes(Cursor));
Chris Lattner487412d2009-04-27 05:27:42 +0000155 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +0000156 D->setUsed(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000157 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor16bef852009-10-16 20:01:17 +0000158 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner487412d2009-04-27 05:27:42 +0000159}
160
161void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
162 VisitDecl(TU);
Chris Lattnerca025db2010-05-07 21:43:38 +0000163 TU->setAnonymousNamespace(
164 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000165}
166
167void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) {
168 VisitDecl(ND);
Mike Stump11289f42009-09-09 15:08:12 +0000169 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000170}
171
172void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
173 VisitNamedDecl(TD);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000174 // Delay type reading until after we have fully initialized the decl.
Sebastian Redlab6a0882010-08-09 21:55:28 +0000175 TypeIDForDecl = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000176}
177
178void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000179 VisitTypeDecl(TD);
Sebastian Redlc67764e2010-07-22 22:43:28 +0000180 TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000181}
182
183void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
184 VisitTypeDecl(TD);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000185 TD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000186 VisitRedeclarable(TD);
Chris Lattner487412d2009-04-27 05:27:42 +0000187 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
188 TD->setDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000189 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis664b6902009-07-14 03:18:02 +0000190 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000191 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall3e11ebe2010-03-15 10:12:16 +0000192 // FIXME: maybe read optional qualifier and its range.
193 TD->setTypedefForAnonDecl(
194 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000195}
196
197void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
198 VisitTagDecl(ED);
199 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall56774992009-12-09 09:09:27 +0000200 ED->setPromotionType(Reader.GetType(Record[Idx++]));
John McCall9aa35be2010-05-06 08:49:23 +0000201 ED->setNumPositiveBits(Record[Idx++]);
202 ED->setNumNegativeBits(Record[Idx++]);
Argyrios Kyrtzidis282b36b2010-07-06 15:36:48 +0000203 ED->setInstantiationOfMemberEnum(
204 cast_or_null<EnumDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000205}
206
207void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
208 VisitTagDecl(RD);
209 RD->setHasFlexibleArrayMember(Record[Idx++]);
210 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000211 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000212}
213
214void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
215 VisitNamedDecl(VD);
216 VD->setType(Reader.GetType(Record[Idx++]));
217}
218
219void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
220 VisitValueDecl(ECD);
221 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000222 ECD->setInitExpr(Reader.ReadExpr(Cursor));
Chris Lattner487412d2009-04-27 05:27:42 +0000223 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
224}
225
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000226void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
227 VisitValueDecl(DD);
Sebastian Redlc67764e2010-07-22 22:43:28 +0000228 TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
John McCallbcd03502009-12-07 02:54:59 +0000229 if (TInfo)
230 DD->setTypeSourceInfo(TInfo);
John McCall3e11ebe2010-03-15 10:12:16 +0000231 // FIXME: read optional qualifier and its range.
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000232}
233
Chris Lattner487412d2009-04-27 05:27:42 +0000234void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000235 VisitDeclaratorDecl(FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000236
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000237 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000238 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000239 default: assert(false && "Unhandled TemplatedKind!");
240 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000241 case FunctionDecl::TK_NonTemplate:
242 break;
243 case FunctionDecl::TK_FunctionTemplate:
244 FD->setDescribedFunctionTemplate(
245 cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++])));
246 break;
247 case FunctionDecl::TK_MemberSpecialization: {
248 FunctionDecl *InstFD = cast<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
249 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
250 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
251 FD->setInstantiationOfMemberFunction(InstFD, TSK);
252 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
253 break;
254 }
255 case FunctionDecl::TK_FunctionTemplateSpecialization: {
256 FunctionTemplateDecl *Template
257 = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
258 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
259
260 // Template arguments.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000261 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000262 Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000263
264 // Template args as written.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000265 llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000266 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000267 if (Record[Idx++]) { // TemplateArgumentsAsWritten != 0
268 unsigned NumTemplateArgLocs = Record[Idx++];
269 TemplArgLocs.reserve(NumTemplateArgLocs);
270 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000271 TemplArgLocs.push_back(
272 Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx));
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000273
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000274 LAngleLoc = Reader.ReadSourceLocation(Record, Idx);
275 RAngleLoc = Reader.ReadSourceLocation(Record, Idx);
276 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000277
278 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000279
Argyrios Kyrtzidisdde57902010-07-20 13:59:58 +0000280 if (FD->isCanonicalDecl()) // if canonical add to template's set.
281 FD->setFunctionTemplateSpecialization(Template, TemplArgs.size(),
282 TemplArgs.data(), TSK,
283 TemplArgLocs.size(),
284 TemplArgLocs.data(),
285 LAngleLoc, RAngleLoc, POI);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000286 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000287 }
288 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
289 // Templates.
290 UnresolvedSet<8> TemplDecls;
291 unsigned NumTemplates = Record[Idx++];
292 while (NumTemplates--)
293 TemplDecls.addDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
294
295 // Templates args.
296 TemplateArgumentListInfo TemplArgs;
297 unsigned NumArgs = Record[Idx++];
298 while (NumArgs--)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000299 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Cursor,Record, Idx));
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000300 TemplArgs.setLAngleLoc(Reader.ReadSourceLocation(Record, Idx));
301 TemplArgs.setRAngleLoc(Reader.ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000302
303 FD->setDependentTemplateSpecialization(*Reader.getContext(),
304 TemplDecls, TemplArgs);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000305 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000306 }
307 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000308
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000309 // FunctionDecl's body is handled last at PCHReaderDecl::Visit,
310 // after everything else is read.
311
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000312 VisitRedeclarable(FD);
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000313 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
314 FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]);
315 FD->setInlineSpecified(Record[Idx++]);
316 FD->setVirtualAsWritten(Record[Idx++]);
317 FD->setPure(Record[Idx++]);
318 FD->setHasInheritedPrototype(Record[Idx++]);
319 FD->setHasWrittenPrototype(Record[Idx++]);
320 FD->setDeleted(Record[Idx++]);
321 FD->setTrivial(Record[Idx++]);
322 FD->setCopyAssignment(Record[Idx++]);
323 FD->setHasImplicitReturnZero(Record[Idx++]);
324 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
325
Chris Lattnerca025db2010-05-07 21:43:38 +0000326 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000327 unsigned NumParams = Record[Idx++];
328 llvm::SmallVector<ParmVarDecl *, 16> Params;
329 Params.reserve(NumParams);
330 for (unsigned I = 0; I != NumParams; ++I)
331 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000332 FD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000333}
334
335void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
336 VisitNamedDecl(MD);
337 if (Record[Idx++]) {
338 // In practice, this won't be executed (since method definitions
339 // don't occur in header files).
Sebastian Redlc67764e2010-07-22 22:43:28 +0000340 MD->setBody(Reader.ReadStmt(Cursor));
Chris Lattner487412d2009-04-27 05:27:42 +0000341 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
342 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
343 }
344 MD->setInstanceMethod(Record[Idx++]);
345 MD->setVariadic(Record[Idx++]);
346 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000347 MD->setDefined(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000348 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
349 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahaniand9235db2010-04-08 21:29:11 +0000350 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000351 MD->setResultType(Reader.GetType(Record[Idx++]));
Sebastian Redlc67764e2010-07-22 22:43:28 +0000352 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000353 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
354 unsigned NumParams = Record[Idx++];
355 llvm::SmallVector<ParmVarDecl *, 16> Params;
356 Params.reserve(NumParams);
357 for (unsigned I = 0; I != NumParams; ++I)
358 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniancdabb312010-04-09 15:40:42 +0000359 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
360 NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000361}
362
363void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
364 VisitNamedDecl(CD);
Ted Kremenekc7c64312010-01-07 01:20:12 +0000365 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
366 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
367 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner487412d2009-04-27 05:27:42 +0000368}
369
370void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
371 VisitObjCContainerDecl(ID);
Sebastian Redlab6a0882010-08-09 21:55:28 +0000372 ID->setForwardDecl(Record[Idx++]);
373 ID->setImplicitInterfaceDecl(Record[Idx++]);
374 VisitRedeclarable(ID);
375 // Must delay type reading until the redecl chain is complete.
376 TypeIDForDecl = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000377 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
378 (Reader.GetDecl(Record[Idx++])));
379 unsigned NumProtocols = Record[Idx++];
380 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
381 Protocols.reserve(NumProtocols);
382 for (unsigned I = 0; I != NumProtocols; ++I)
383 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000384 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
385 ProtoLocs.reserve(NumProtocols);
386 for (unsigned I = 0; I != NumProtocols; ++I)
387 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
388 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
389 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000390 unsigned NumIvars = Record[Idx++];
391 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
392 IVars.reserve(NumIvars);
393 for (unsigned I = 0; I != NumIvars; ++I)
394 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000395 ID->setCategoryList(
396 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000397 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
398 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisea72f422009-07-18 00:33:23 +0000399 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000400}
401
402void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
403 VisitFieldDecl(IVD);
404 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000405 bool synth = Record[Idx++];
406 IVD->setSynthesize(synth);
Chris Lattner487412d2009-04-27 05:27:42 +0000407}
408
409void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
410 VisitObjCContainerDecl(PD);
411 PD->setForwardDecl(Record[Idx++]);
412 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
413 unsigned NumProtoRefs = Record[Idx++];
414 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
415 ProtoRefs.reserve(NumProtoRefs);
416 for (unsigned I = 0; I != NumProtoRefs; ++I)
417 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000418 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
419 ProtoLocs.reserve(NumProtoRefs);
420 for (unsigned I = 0; I != NumProtoRefs; ++I)
421 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
422 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
423 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000424}
425
426void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
427 VisitFieldDecl(FD);
428}
429
430void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
431 VisitDecl(CD);
432 unsigned NumClassRefs = Record[Idx++];
433 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
434 ClassRefs.reserve(NumClassRefs);
435 for (unsigned I = 0; I != NumClassRefs; ++I)
436 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000437 llvm::SmallVector<SourceLocation, 16> SLocs;
438 SLocs.reserve(NumClassRefs);
439 for (unsigned I = 0; I != NumClassRefs; ++I)
440 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
441 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
442 NumClassRefs);
Chris Lattner487412d2009-04-27 05:27:42 +0000443}
444
445void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
446 VisitDecl(FPD);
447 unsigned NumProtoRefs = Record[Idx++];
448 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
449 ProtoRefs.reserve(NumProtoRefs);
450 for (unsigned I = 0; I != NumProtoRefs; ++I)
451 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000452 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
453 ProtoLocs.reserve(NumProtoRefs);
454 for (unsigned I = 0; I != NumProtoRefs; ++I)
455 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
456 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
457 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000458}
459
460void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
461 VisitObjCContainerDecl(CD);
462 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
463 unsigned NumProtoRefs = Record[Idx++];
464 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
465 ProtoRefs.reserve(NumProtoRefs);
466 for (unsigned I = 0; I != NumProtoRefs; ++I)
467 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000468 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
469 ProtoLocs.reserve(NumProtoRefs);
470 for (unsigned I = 0; I != NumProtoRefs; ++I)
471 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
472 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
473 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000474 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor071676f2010-01-16 16:38:58 +0000475 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
476 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000477}
478
479void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
480 VisitNamedDecl(CAD);
481 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
482}
483
484void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
485 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000486 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Sebastian Redlc67764e2010-07-22 22:43:28 +0000487 D->setType(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000488 // FIXME: stable encoding
489 D->setPropertyAttributes(
490 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000491 D->setPropertyAttributesAsWritten(
492 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000493 // FIXME: stable encoding
494 D->setPropertyImplementation(
495 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
496 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
497 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
498 D->setGetterMethodDecl(
499 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
500 D->setSetterMethodDecl(
501 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
502 D->setPropertyIvarDecl(
503 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
504}
505
506void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000507 VisitObjCContainerDecl(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000508 D->setClassInterface(
509 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000510}
511
512void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
513 VisitObjCImplDecl(D);
514 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
515}
516
517void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
518 VisitObjCImplDecl(D);
519 D->setSuperClass(
520 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +0000521 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
522 = Reader.ReadCXXBaseOrMemberInitializers(Cursor, Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +0000523}
524
525
526void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
527 VisitDecl(D);
528 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
529 D->setPropertyDecl(
530 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
531 D->setPropertyIvarDecl(
532 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisa8607772010-08-09 10:54:37 +0000533 D->setGetterCXXConstructor(Reader.ReadExpr(Cursor));
534 D->setSetterCXXAssignment(Reader.ReadExpr(Cursor));
Chris Lattner487412d2009-04-27 05:27:42 +0000535}
536
537void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000538 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000539 FD->setMutable(Record[Idx++]);
540 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000541 FD->setBitWidth(Reader.ReadExpr(Cursor));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000542 if (!FD->getDeclName()) {
543 FieldDecl *Tmpl = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
544 if (Tmpl)
545 Reader.getContext()->setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
546 }
Chris Lattner487412d2009-04-27 05:27:42 +0000547}
548
549void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000550 VisitDeclaratorDecl(VD);
Chris Lattner487412d2009-04-27 05:27:42 +0000551 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
Douglas Gregorc4df4072010-04-19 22:54:31 +0000552 VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000553 VD->setThreadSpecified(Record[Idx++]);
554 VD->setCXXDirectInitializer(Record[Idx++]);
Douglas Gregor3f324d562010-05-03 18:51:14 +0000555 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor6fd1b182010-05-15 06:01:05 +0000556 VD->setNRVOVariable(Record[Idx++]);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000557 VisitRedeclarable(VD);
Chris Lattner487412d2009-04-27 05:27:42 +0000558 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000559 VD->setInit(Reader.ReadExpr(Cursor));
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000560
561 if (Record[Idx++]) { // HasMemberSpecializationInfo.
562 VarDecl *Tmpl = cast<VarDecl>(Reader.GetDecl(Record[Idx++]));
563 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
564 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
565 Reader.getContext()->setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
566 }
Chris Lattner487412d2009-04-27 05:27:42 +0000567}
568
569void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
570 VisitVarDecl(PD);
571}
572
573void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
574 VisitVarDecl(PD);
575 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallf3cd6652010-03-12 18:31:32 +0000576 PD->setHasInheritedDefaultArg(Record[Idx++]);
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000577 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redlc67764e2010-07-22 22:43:28 +0000578 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(Cursor));
Chris Lattner487412d2009-04-27 05:27:42 +0000579}
580
Chris Lattner487412d2009-04-27 05:27:42 +0000581void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
582 VisitDecl(AD);
Sebastian Redlc67764e2010-07-22 22:43:28 +0000583 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(Cursor)));
Chris Lattner487412d2009-04-27 05:27:42 +0000584}
585
586void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
587 VisitDecl(BD);
Sebastian Redlc67764e2010-07-22 22:43:28 +0000588 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(Cursor)));
589 BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000590 unsigned NumParams = Record[Idx++];
591 llvm::SmallVector<ParmVarDecl *, 16> Params;
592 Params.reserve(NumParams);
593 for (unsigned I = 0; I != NumParams; ++I)
594 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000595 BD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000596}
597
Chris Lattnerca025db2010-05-07 21:43:38 +0000598void PCHDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
599 VisitDecl(D);
600 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
601 D->setHasBraces(Record[Idx++]);
602}
603
604void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
605 VisitNamedDecl(D);
606 D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx));
607 D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx));
608 D->setNextNamespace(
609 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
610
Chris Lattnerca025db2010-05-07 21:43:38 +0000611 bool IsOriginal = Record[Idx++];
Argyrios Kyrtzidisdae2a162010-07-03 07:57:53 +0000612 D->OrigOrAnonNamespace.setInt(IsOriginal);
613 D->OrigOrAnonNamespace.setPointer(
Chris Lattnerca025db2010-05-07 21:43:38 +0000614 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
615}
616
617void PCHDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
618 VisitNamedDecl(D);
619
620 D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx));
621 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
622 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
623 D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx));
624 D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
625}
626
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000627void PCHDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000628 VisitNamedDecl(D);
629 D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
630 D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
631 D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
632
633 // FIXME: It would probably be more efficient to read these into a vector
634 // and then re-cosntruct the shadow decl set over that vector since it
635 // would avoid existence checks.
636 unsigned NumShadows = Record[Idx++];
637 for(unsigned I = 0; I != NumShadows; ++I) {
Argyrios Kyrtzidis00dda6a2010-07-08 13:09:41 +0000638 // Avoid invariant checking of UsingDecl::addShadowDecl, the decl may still
639 // be initializing.
640 D->Shadows.insert(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattnerca025db2010-05-07 21:43:38 +0000641 }
642 D->setTypeName(Record[Idx++]);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000643 NamedDecl *Pattern = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
644 if (Pattern)
645 Reader.getContext()->setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000646}
647
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000648void PCHDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000649 VisitNamedDecl(D);
650 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
651 D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000652 UsingShadowDecl *Pattern
653 = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]));
654 if (Pattern)
655 Reader.getContext()->setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000656}
657
658void PCHDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
659 VisitNamedDecl(D);
660 D->setNamespaceKeyLocation(Reader.ReadSourceLocation(Record, Idx));
661 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
662 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
663 D->setIdentLocation(Reader.ReadSourceLocation(Record, Idx));
664 D->setNominatedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
665 D->setCommonAncestor(cast_or_null<DeclContext>(
666 Reader.GetDecl(Record[Idx++])));
667}
668
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000669void PCHDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000670 VisitValueDecl(D);
671 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
672 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
673 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
674}
675
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000676void PCHDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000677 UnresolvedUsingTypenameDecl *D) {
678 VisitTypeDecl(D);
679 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
680 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
681 D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx));
682 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
683}
684
685void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000686 ASTContext &C = *Reader.getContext();
687
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000688 // We need to allocate the DefinitionData struct ahead of VisitRecordDecl
689 // so that the other CXXRecordDecls can get a pointer even when the owner
690 // is still initializing.
691 bool OwnsDefinitionData = false;
692 enum DataOwnership { Data_NoDefData, Data_Owner, Data_NotOwner };
693 switch ((DataOwnership)Record[Idx++]) {
694 default:
695 assert(0 && "Out of sync with PCHDeclWriter or messed up reading");
696 case Data_NoDefData:
697 break;
698 case Data_Owner:
699 OwnsDefinitionData = true;
700 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
701 break;
702 case Data_NotOwner:
703 D->DefinitionData
704 = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]))->DefinitionData;
705 break;
706 }
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000707
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000708 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000709
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000710 if (OwnsDefinitionData) {
711 assert(D->DefinitionData);
712 struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData;
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000713
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000714 Data.UserDeclaredConstructor = Record[Idx++];
715 Data.UserDeclaredCopyConstructor = Record[Idx++];
716 Data.UserDeclaredCopyAssignment = Record[Idx++];
717 Data.UserDeclaredDestructor = Record[Idx++];
718 Data.Aggregate = Record[Idx++];
719 Data.PlainOldData = Record[Idx++];
720 Data.Empty = Record[Idx++];
721 Data.Polymorphic = Record[Idx++];
722 Data.Abstract = Record[Idx++];
723 Data.HasTrivialConstructor = Record[Idx++];
724 Data.HasTrivialCopyConstructor = Record[Idx++];
725 Data.HasTrivialCopyAssignment = Record[Idx++];
726 Data.HasTrivialDestructor = Record[Idx++];
727 Data.ComputedVisibleConversions = Record[Idx++];
728 Data.DeclaredDefaultConstructor = Record[Idx++];
729 Data.DeclaredCopyConstructor = Record[Idx++];
730 Data.DeclaredCopyAssignment = Record[Idx++];
731 Data.DeclaredDestructor = Record[Idx++];
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000732
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000733 // setBases() is unsuitable since it may try to iterate the bases of an
Nick Lewycky19b9f952010-07-26 16:56:01 +0000734 // uninitialized base.
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000735 Data.NumBases = Record[Idx++];
736 Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases];
737 for (unsigned i = 0; i != Data.NumBases; ++i)
Nick Lewycky19b9f952010-07-26 16:56:01 +0000738 Data.Bases[i] = Reader.ReadCXXBaseSpecifier(Cursor, Record, Idx);
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000739
740 // FIXME: Make VBases lazily computed when needed to avoid storing them.
741 Data.NumVBases = Record[Idx++];
742 Data.VBases = new(C) CXXBaseSpecifier [Data.NumVBases];
743 for (unsigned i = 0; i != Data.NumVBases; ++i)
Nick Lewycky19b9f952010-07-26 16:56:01 +0000744 Data.VBases[i] = Reader.ReadCXXBaseSpecifier(Cursor, Record, Idx);
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000745
746 Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx);
747 Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx);
748 assert(Data.Definition && "Data.Definition should be already set!");
749 Data.FirstFriend
750 = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000751 }
752
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000753 enum CXXRecKind {
754 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
755 };
756 switch ((CXXRecKind)Record[Idx++]) {
757 default:
758 assert(false && "Out of sync with PCHDeclWriter::VisitCXXRecordDecl?");
759 case CXXRecNotTemplate:
760 break;
761 case CXXRecTemplate:
762 D->setDescribedClassTemplate(
763 cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++])));
764 break;
765 case CXXRecMemberSpecialization: {
766 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
767 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
768 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
769 D->setInstantiationOfMemberClass(RD, TSK);
770 D->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
771 break;
772 }
773 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000774}
775
776void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000777 VisitFunctionDecl(D);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000778 unsigned NumOverridenMethods = Record[Idx++];
779 while (NumOverridenMethods--) {
780 CXXMethodDecl *MD = cast<CXXMethodDecl>(Reader.GetDecl(Record[Idx++]));
781 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
782 // MD may be initializing.
783 Reader.getContext()->addOverriddenMethod(D, MD);
784 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000785}
786
787void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000788 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000789
790 D->IsExplicitSpecified = Record[Idx++];
791 D->ImplicitlyDefined = Record[Idx++];
Argyrios Kyrtzidis5b6a03f2010-08-09 10:54:12 +0000792 llvm::tie(D->BaseOrMemberInitializers, D->NumBaseOrMemberInitializers)
793 = Reader.ReadCXXBaseOrMemberInitializers(Cursor, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000794}
795
796void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000797 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000798
799 D->ImplicitlyDefined = Record[Idx++];
800 D->OperatorDelete = cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000801}
802
803void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000804 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000805 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000806}
807
Abramo Bagnarad7340582010-06-05 05:09:32 +0000808void PCHDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
809 VisitDecl(D);
810 D->setColonLoc(Reader.ReadSourceLocation(Record, Idx));
811}
812
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000813void PCHDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000814 VisitDecl(D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000815 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000816 D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000817 else
818 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
819 D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
820 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
821}
822
Chris Lattnerca025db2010-05-07 21:43:38 +0000823void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +0000824 VisitDecl(D);
825 unsigned NumParams = Record[Idx++];
826 D->NumParams = NumParams;
827 D->Params = new TemplateParameterList*[NumParams];
828 for (unsigned i = 0; i != NumParams; ++i)
829 D->Params[i] = Reader.ReadTemplateParameterList(Record, Idx);
830 if (Record[Idx++]) // HasFriendDecl
831 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
832 else
Sebastian Redlc67764e2010-07-22 22:43:28 +0000833 D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +0000834 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000835}
836
837void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000838 VisitNamedDecl(D);
839
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +0000840 NamedDecl *TemplatedDecl
841 = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000842 TemplateParameterList* TemplateParams
843 = Reader.ReadTemplateParameterList(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000844 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +0000845}
846
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000847void PCHDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000848 VisitTemplateDecl(D);
849
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000850 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000851 RedeclarableTemplateDecl *PrevDecl =
852 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]));
853 assert((PrevDecl == 0 || PrevDecl->getKind() == D->getKind()) &&
854 "PrevDecl kind mismatch");
855 if (PrevDecl)
856 D->CommonOrPrev = PrevDecl;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000857 if (PrevDecl == 0) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000858 if (RedeclarableTemplateDecl *RTD
859 = cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
860 assert(RTD->getKind() == D->getKind() &&
861 "InstantiatedFromMemberTemplate kind mismatch");
862 D->setInstantiatedFromMemberTemplateImpl(RTD);
863 if (Record[Idx++])
864 D->setMemberSpecialization();
865 }
Peter Collingbourne2bf3d242010-07-29 16:12:01 +0000866
867 RedeclarableTemplateDecl *LatestDecl =
868 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000869
870 // This decl is a first one and the latest declaration that it points to is
871 // in the same PCH. However, if this actually needs to point to a
872 // redeclaration in another chained PCH, we need to update it by checking
873 // the FirstLatestDeclIDs map which tracks this kind of decls.
874 assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
875 PCHReader::FirstLatestDeclIDMap::iterator I
876 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
877 if (I != Reader.FirstLatestDeclIDs.end()) {
878 Decl *NewLatest = Reader.GetDecl(I->second);
879 assert((LatestDecl->getLocation().isInvalid() ||
880 NewLatest->getLocation().isInvalid() ||
881 Reader.SourceMgr.isBeforeInTranslationUnit(
882 LatestDecl->getLocation(),
883 NewLatest->getLocation())) &&
884 "The new latest is supposed to come after the previous latest");
885 LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
886 }
887
Peter Collingbourne2bf3d242010-07-29 16:12:01 +0000888 assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
889 D->getCommonPtr()->Latest = LatestDecl;
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000890 }
891}
892
893void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
894 VisitRedeclarableTemplateDecl(D);
895
896 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000897 // This ClassTemplateDecl owns a CommonPtr; read it.
898
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000899 // FoldingSets are filled in VisitClassTemplateSpecializationDecl.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000900 unsigned size = Record[Idx++];
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000901 while (size--)
902 cast<ClassTemplateSpecializationDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000903
904 size = Record[Idx++];
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000905 while (size--)
906 cast<ClassTemplatePartialSpecializationDecl>(
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000907 Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000908
909 // InjectedClassNameType is computed.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000910 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000911}
912
913void PCHDeclReader::VisitClassTemplateSpecializationDecl(
914 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000915 VisitCXXRecordDecl(D);
916
917 if (Decl *InstD = Reader.GetDecl(Record[Idx++])) {
918 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
919 D->setInstantiationOf(CTD);
920 } else {
921 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000922 Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000923 D->setInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(InstD),
924 TemplArgs.data(), TemplArgs.size());
925 }
926 }
927
928 // Explicit info.
Sebastian Redlc67764e2010-07-22 22:43:28 +0000929 if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx)) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000930 D->setTypeAsWritten(TyInfo);
931 D->setExternLoc(Reader.ReadSourceLocation(Record, Idx));
932 D->setTemplateKeywordLoc(Reader.ReadSourceLocation(Record, Idx));
933 }
934
935 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000936 Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000937 D->initTemplateArgs(TemplArgs.data(), TemplArgs.size());
938 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
939 if (POI.isValid())
940 D->setPointOfInstantiation(POI);
941 D->setSpecializationKind((TemplateSpecializationKind)Record[Idx++]);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000942
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +0000943 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000944 ClassTemplateDecl *CanonPattern
945 = cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
946 if (ClassTemplatePartialSpecializationDecl *Partial
947 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
Argyrios Kyrtzidisf4cc7dc2010-07-12 21:41:31 +0000948 CanonPattern->getPartialSpecializations().InsertNode(Partial);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000949 } else {
Argyrios Kyrtzidisf4cc7dc2010-07-12 21:41:31 +0000950 CanonPattern->getSpecializations().InsertNode(D);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000951 }
952 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000953}
954
955void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl(
956 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000957 VisitClassTemplateSpecializationDecl(D);
958
959 D->initTemplateParameters(Reader.ReadTemplateParameterList(Record, Idx));
960
961 TemplateArgumentListInfo ArgInfos;
962 unsigned NumArgs = Record[Idx++];
963 while (NumArgs--)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000964 ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000965 D->initTemplateArgsAsWritten(ArgInfos);
966
967 D->setSequenceNumber(Record[Idx++]);
968
969 // These are read/set from/to the first declaration.
970 if (D->getPreviousDeclaration() == 0) {
971 D->setInstantiatedFromMember(
972 cast_or_null<ClassTemplatePartialSpecializationDecl>(
973 Reader.GetDecl(Record[Idx++])));
974 if (Record[Idx++])
Argyrios Kyrtzidisdd2061b2010-07-09 21:11:35 +0000975 D->setMemberSpecialization();
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000976 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000977}
978
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000979void PCHDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000980 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000981
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000982 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000983 // This FunctionTemplateDecl owns a CommonPtr; read it.
984
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +0000985 // Read the function specialization declarations.
986 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
987 // through the specialized FunctionDecl's setFunctionTemplateSpecialization.
988 unsigned NumSpecs = Record[Idx++];
989 while (NumSpecs--)
990 Reader.GetDecl(Record[Idx++]);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000991 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000992}
993
994void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000995 VisitTypeDecl(D);
996
997 D->setDeclaredWithTypename(Record[Idx++]);
998 D->setParameterPack(Record[Idx++]);
999
1000 bool Inherited = Record[Idx++];
Sebastian Redlc67764e2010-07-22 22:43:28 +00001001 TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001002 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001003}
1004
1005void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001006 VisitVarDecl(D);
1007 // TemplateParmPosition.
1008 D->setDepth(Record[Idx++]);
1009 D->setPosition(Record[Idx++]);
1010 // Rest of NonTypeTemplateParmDecl.
1011 if (Record[Idx++]) {
Sebastian Redlc67764e2010-07-22 22:43:28 +00001012 Expr *DefArg = Reader.ReadExpr(Cursor);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001013 bool Inherited = Record[Idx++];
1014 D->setDefaultArgument(DefArg, Inherited);
1015 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001016}
1017
1018void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001019 VisitTemplateDecl(D);
1020 // TemplateParmPosition.
1021 D->setDepth(Record[Idx++]);
1022 D->setPosition(Record[Idx++]);
1023 // Rest of TemplateTemplateParmDecl.
Sebastian Redlc67764e2010-07-22 22:43:28 +00001024 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx);
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001025 bool IsInherited = Record[Idx++];
1026 D->setDefaultArgument(Arg, IsInherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001027}
1028
1029void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001030 VisitDecl(D);
Sebastian Redlc67764e2010-07-22 22:43:28 +00001031 D->AssertExpr = Reader.ReadExpr(Cursor);
1032 D->Message = cast<StringLiteral>(Reader.ReadExpr(Cursor));
Chris Lattnerca025db2010-05-07 21:43:38 +00001033}
1034
Mike Stump11289f42009-09-09 15:08:12 +00001035std::pair<uint64_t, uint64_t>
Chris Lattner487412d2009-04-27 05:27:42 +00001036PCHDeclReader::VisitDeclContext(DeclContext *DC) {
1037 uint64_t LexicalOffset = Record[Idx++];
1038 uint64_t VisibleOffset = Record[Idx++];
1039 return std::make_pair(LexicalOffset, VisibleOffset);
1040}
1041
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001042template <typename T>
1043void PCHDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
1044 enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest };
1045 RedeclKind Kind = (RedeclKind)Record[Idx++];
1046 switch (Kind) {
1047 default:
1048 assert(0 && "Out of sync with PCHDeclWriter::VisitRedeclarable or messed up"
1049 " reading");
1050 case NoRedeclaration:
1051 break;
1052 case PointsToPrevious:
1053 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(
1054 cast_or_null<T>(Reader.GetDecl(Record[Idx++])));
1055 break;
1056 case PointsToLatest:
1057 D->RedeclLink = typename Redeclarable<T>::LatestDeclLink(
1058 cast_or_null<T>(Reader.GetDecl(Record[Idx++])));
1059 break;
1060 }
1061
1062 assert(!(Kind == PointsToPrevious &&
1063 Reader.FirstLatestDeclIDs.find(ThisDeclID) !=
1064 Reader.FirstLatestDeclIDs.end()) &&
1065 "This decl is not first, it should not be in the map");
1066 if (Kind == PointsToPrevious)
1067 return;
1068
1069 // This decl is a first one and the latest declaration that it points to is in
1070 // the same PCH. However, if this actually needs to point to a redeclaration
1071 // in another chained PCH, we need to update it by checking the
1072 // FirstLatestDeclIDs map which tracks this kind of decls.
1073 assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) &&
1074 "Invalid ThisDeclID ?");
1075 PCHReader::FirstLatestDeclIDMap::iterator I
1076 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1077 if (I != Reader.FirstLatestDeclIDs.end()) {
1078 Decl *NewLatest = Reader.GetDecl(I->second);
1079 assert((D->getMostRecentDeclaration()->getLocation().isInvalid() ||
1080 NewLatest->getLocation().isInvalid() ||
1081 Reader.SourceMgr.isBeforeInTranslationUnit(
1082 D->getMostRecentDeclaration()->getLocation(),
1083 NewLatest->getLocation())) &&
1084 "The new latest is supposed to come after the previous latest");
1085 D->RedeclLink
1086 = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest));
1087 }
1088}
1089
Chris Lattner487412d2009-04-27 05:27:42 +00001090//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00001091// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00001092//===----------------------------------------------------------------------===//
1093
Chris Lattner8f63ab52009-04-27 06:01:06 +00001094/// \brief Reads attributes from the current stream position.
Sebastian Redlc67764e2010-07-22 22:43:28 +00001095Attr *PCHReader::ReadAttributes(llvm::BitstreamCursor &DeclsCursor) {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001096 unsigned Code = DeclsCursor.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +00001097 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner8f63ab52009-04-27 06:01:06 +00001098 "Expected unabbreviated record"); (void)Code;
Mike Stump11289f42009-09-09 15:08:12 +00001099
Chris Lattner8f63ab52009-04-27 06:01:06 +00001100 RecordData Record;
1101 unsigned Idx = 0;
1102 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump11289f42009-09-09 15:08:12 +00001103 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001104 (void)RecCode;
1105
1106#define SIMPLE_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001107 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +00001108 New = ::new (*Context) Name##Attr(); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001109 break
1110
1111#define STRING_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001112 case attr::Name: \
Ted Kremenek7f4945a2010-02-11 05:28:37 +00001113 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001114 break
1115
1116#define UNSIGNED_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +00001117 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +00001118 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner8f63ab52009-04-27 06:01:06 +00001119 break
1120
1121 Attr *Attrs = 0;
1122 while (Idx < Record.size()) {
1123 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001124 attr::Kind Kind = (attr::Kind)Record[Idx++];
Chris Lattner8f63ab52009-04-27 06:01:06 +00001125 bool IsInherited = Record[Idx++];
1126
1127 switch (Kind) {
Anton Korobeynikov55bcea12010-01-10 12:58:08 +00001128 default:
1129 assert(0 && "Unknown attribute!");
1130 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001131 STRING_ATTR(Alias);
Daniel Dunbarfc6507e2010-05-27 02:25:39 +00001132 SIMPLE_ATTR(AlignMac68k);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001133 UNSIGNED_ATTR(Aligned);
1134 SIMPLE_ATTR(AlwaysInline);
1135 SIMPLE_ATTR(AnalyzerNoReturn);
1136 STRING_ATTR(Annotate);
1137 STRING_ATTR(AsmLabel);
Alexis Hunt54a02542009-11-25 04:20:27 +00001138 SIMPLE_ATTR(BaseCheck);
Mike Stump11289f42009-09-09 15:08:12 +00001139
Alexis Hunt344393e2010-06-16 23:43:53 +00001140 case attr::Blocks:
Chris Lattner8575daa2009-04-27 21:45:14 +00001141 New = ::new (*Context) BlocksAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001142 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
1143 break;
Mike Stump11289f42009-09-09 15:08:12 +00001144
Eli Friedmane4310c82009-11-09 18:38:53 +00001145 SIMPLE_ATTR(CDecl);
1146
Alexis Hunt344393e2010-06-16 23:43:53 +00001147 case attr::Cleanup:
Chris Lattner8575daa2009-04-27 21:45:14 +00001148 New = ::new (*Context) CleanupAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001149 cast<FunctionDecl>(GetDecl(Record[Idx++])));
1150 break;
1151
1152 SIMPLE_ATTR(Const);
1153 UNSIGNED_ATTR(Constructor);
1154 SIMPLE_ATTR(DLLExport);
1155 SIMPLE_ATTR(DLLImport);
1156 SIMPLE_ATTR(Deprecated);
1157 UNSIGNED_ATTR(Destructor);
1158 SIMPLE_ATTR(FastCall);
Alexis Hunt96d5c762009-11-21 08:43:09 +00001159 SIMPLE_ATTR(Final);
Mike Stump11289f42009-09-09 15:08:12 +00001160
Alexis Hunt344393e2010-06-16 23:43:53 +00001161 case attr::Format: {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001162 std::string Type = ReadString(Record, Idx);
1163 unsigned FormatIdx = Record[Idx++];
1164 unsigned FirstArg = Record[Idx++];
Ted Kremenek7f4945a2010-02-11 05:28:37 +00001165 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001166 break;
1167 }
Mike Stump11289f42009-09-09 15:08:12 +00001168
Alexis Hunt344393e2010-06-16 23:43:53 +00001169 case attr::FormatArg: {
Fariborz Jahanianf1c25022009-05-20 17:41:43 +00001170 unsigned FormatIdx = Record[Idx++];
1171 New = ::new (*Context) FormatArgAttr(FormatIdx);
1172 break;
1173 }
Mike Stump11289f42009-09-09 15:08:12 +00001174
Alexis Hunt344393e2010-06-16 23:43:53 +00001175 case attr::Sentinel: {
Fariborz Jahanian027b8862009-05-13 18:09:35 +00001176 int sentinel = Record[Idx++];
1177 int nullPos = Record[Idx++];
1178 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
1179 break;
1180 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001181
1182 SIMPLE_ATTR(GNUInline);
Alexis Hunt54a02542009-11-25 04:20:27 +00001183 SIMPLE_ATTR(Hiding);
Mike Stump11289f42009-09-09 15:08:12 +00001184
Alexis Hunt344393e2010-06-16 23:43:53 +00001185 case attr::IBAction:
Ted Kremenek06be9682010-02-17 02:37:45 +00001186 New = ::new (*Context) IBActionAttr();
1187 break;
1188
Alexis Hunt344393e2010-06-16 23:43:53 +00001189 case attr::IBOutlet:
Chris Lattner8575daa2009-04-27 21:45:14 +00001190 New = ::new (*Context) IBOutletAttr();
Chris Lattner8f63ab52009-04-27 06:01:06 +00001191 break;
1192
Alexis Hunt344393e2010-06-16 23:43:53 +00001193 case attr::IBOutletCollection: {
Ted Kremenek26bde772010-05-19 17:38:06 +00001194 ObjCInterfaceDecl *D =
1195 cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++]));
1196 New = ::new (*Context) IBOutletCollectionAttr(D);
1197 break;
1198 }
1199
Ryan Flynn1f1fdc02009-08-09 20:07:29 +00001200 SIMPLE_ATTR(Malloc);
Mike Stump3722f582009-08-26 22:31:08 +00001201 SIMPLE_ATTR(NoDebug);
1202 SIMPLE_ATTR(NoInline);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001203 SIMPLE_ATTR(NoReturn);
1204 SIMPLE_ATTR(NoThrow);
Mike Stump11289f42009-09-09 15:08:12 +00001205
Alexis Hunt344393e2010-06-16 23:43:53 +00001206 case attr::NonNull: {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001207 unsigned Size = Record[Idx++];
1208 llvm::SmallVector<unsigned, 16> ArgNums;
1209 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
1210 Idx += Size;
Ted Kremenek510ee252010-02-11 07:31:47 +00001211 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001212 break;
1213 }
Mike Stump11289f42009-09-09 15:08:12 +00001214
Alexis Hunt344393e2010-06-16 23:43:53 +00001215 case attr::ReqdWorkGroupSize: {
Nate Begemanf2758702009-06-26 06:32:41 +00001216 unsigned X = Record[Idx++];
1217 unsigned Y = Record[Idx++];
1218 unsigned Z = Record[Idx++];
1219 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
1220 break;
1221 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001222
1223 SIMPLE_ATTR(ObjCException);
1224 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekd9c66632010-02-18 00:05:45 +00001225 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +00001226 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenekd9c66632010-02-18 00:05:45 +00001227 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +00001228 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001229 SIMPLE_ATTR(Overloadable);
Alexis Hunt54a02542009-11-25 04:20:27 +00001230 SIMPLE_ATTR(Override);
Anders Carlsson68e0b682009-08-08 18:23:56 +00001231 SIMPLE_ATTR(Packed);
Daniel Dunbar40130442010-05-27 01:12:46 +00001232 UNSIGNED_ATTR(MaxFieldAlignment);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001233 SIMPLE_ATTR(Pure);
1234 UNSIGNED_ATTR(Regparm);
1235 STRING_ATTR(Section);
1236 SIMPLE_ATTR(StdCall);
Douglas Gregora941dca2010-05-18 16:57:00 +00001237 SIMPLE_ATTR(ThisCall);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001238 SIMPLE_ATTR(TransparentUnion);
1239 SIMPLE_ATTR(Unavailable);
1240 SIMPLE_ATTR(Unused);
1241 SIMPLE_ATTR(Used);
Mike Stump11289f42009-09-09 15:08:12 +00001242
Alexis Hunt344393e2010-06-16 23:43:53 +00001243 case attr::Visibility:
Chris Lattner8575daa2009-04-27 21:45:14 +00001244 New = ::new (*Context) VisibilityAttr(
Eli Friedman570024a2010-08-05 06:57:20 +00001245 (VisibilityAttr::VisibilityTypes)Record[Idx++],
1246 (bool)Record[Idx++]);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001247 break;
1248
1249 SIMPLE_ATTR(WarnUnusedResult);
1250 SIMPLE_ATTR(Weak);
Rafael Espindolac18086a2010-02-23 22:00:30 +00001251 SIMPLE_ATTR(WeakRef);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001252 SIMPLE_ATTR(WeakImport);
1253 }
1254
1255 assert(New && "Unable to decode attribute?");
1256 New->setInherited(IsInherited);
1257 New->setNext(Attrs);
1258 Attrs = New;
1259 }
1260#undef UNSIGNED_ATTR
1261#undef STRING_ATTR
1262#undef SIMPLE_ATTR
1263
1264 // The list of attributes was built backwards. Reverse the list
1265 // before returning it.
1266 Attr *PrevAttr = 0, *NextAttr = 0;
1267 while (Attrs) {
1268 NextAttr = Attrs->getNext();
1269 Attrs->setNext(PrevAttr);
1270 PrevAttr = Attrs;
1271 Attrs = NextAttr;
1272 }
1273
1274 return PrevAttr;
1275}
1276
1277//===----------------------------------------------------------------------===//
1278// PCHReader Implementation
1279//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001280
1281/// \brief Note that we have loaded the declaration with the given
1282/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001283///
Chris Lattner487412d2009-04-27 05:27:42 +00001284/// This routine notes that this declaration has already been loaded,
1285/// so that future GetDecl calls will return this declaration rather
1286/// than trying to load a new declaration.
1287inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
1288 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1289 DeclsLoaded[Index] = D;
1290}
1291
1292
1293/// \brief Determine whether the consumer will be interested in seeing
1294/// this declaration (via HandleTopLevelDecl).
1295///
1296/// This routine should return true for anything that might affect
1297/// code generation, e.g., inline function definitions, Objective-C
1298/// declarations with metadata, etc.
1299static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001300 if (isa<FileScopeAsmDecl>(D))
1301 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001302 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis4ba81b22010-08-05 09:47:59 +00001303 return Var->isFileVarDecl() &&
1304 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner487412d2009-04-27 05:27:42 +00001305 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1306 return Func->isThisDeclarationADefinition();
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +00001307 return isa<ObjCProtocolDecl>(D) || isa<ObjCImplementationDecl>(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001308}
1309
Sebastian Redl34627792010-07-20 22:46:15 +00001310/// \brief Get the correct cursor and offset for loading a type.
1311PCHReader::RecordLocation PCHReader::DeclCursorForIndex(unsigned Index) {
1312 PerFileData *F = 0;
1313 for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
1314 F = Chain[N - I - 1];
1315 if (Index < F->LocalNumDecls)
1316 break;
1317 Index -= F->LocalNumDecls;
1318 }
1319 assert(F && F->LocalNumDecls > Index && "Broken chain");
Sebastian Redlb2831db2010-07-20 22:55:31 +00001320 return RecordLocation(&F->DeclsCursor, F->DeclOffsets[Index]);
Sebastian Redl34627792010-07-20 22:46:15 +00001321}
1322
Chris Lattner487412d2009-04-27 05:27:42 +00001323/// \brief Read the declaration at the given offset from the PCH file.
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001324Decl *PCHReader::ReadDeclRecord(unsigned Index, pch::DeclID ID) {
Sebastian Redl34627792010-07-20 22:46:15 +00001325 RecordLocation Loc = DeclCursorForIndex(Index);
Sebastian Redlb2831db2010-07-20 22:55:31 +00001326 llvm::BitstreamCursor &DeclsCursor = *Loc.first;
Chris Lattner487412d2009-04-27 05:27:42 +00001327 // Keep track of where we are in the stream, then jump back there
1328 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001329 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001330
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001331 ReadingKindTracker ReadingKind(Read_Decl, *this);
1332
Douglas Gregor1342e842009-07-06 18:54:52 +00001333 // Note that we are loading a declaration record.
Argyrios Kyrtzidisb24355a2010-07-30 10:03:16 +00001334 Deserializing ADecl(this);
Mike Stump11289f42009-09-09 15:08:12 +00001335
Sebastian Redl34627792010-07-20 22:46:15 +00001336 DeclsCursor.JumpToBit(Loc.second);
Chris Lattner487412d2009-04-27 05:27:42 +00001337 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001338 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001339 unsigned Idx = 0;
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001340 PCHDeclReader Reader(*this, DeclsCursor, ID, Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +00001341
Chris Lattner1de76db2009-04-27 05:58:23 +00001342 Decl *D = 0;
1343 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner487412d2009-04-27 05:27:42 +00001344 case pch::DECL_ATTR:
1345 case pch::DECL_CONTEXT_LEXICAL:
1346 case pch::DECL_CONTEXT_VISIBLE:
1347 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1348 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001349 case pch::DECL_TRANSLATION_UNIT:
1350 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +00001351 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +00001352 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001353 case pch::DECL_TYPEDEF:
John McCall703a3f82009-10-24 08:00:42 +00001354 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001355 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001356 case pch::DECL_ENUM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001357 D = EnumDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001358 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001359 case pch::DECL_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001360 D = RecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001361 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001362 case pch::DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +00001363 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001364 0, llvm::APSInt());
1365 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001366 case pch::DECL_FUNCTION:
Mike Stump11289f42009-09-09 15:08:12 +00001367 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001368 QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001369 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001370 case pch::DECL_LINKAGE_SPEC:
1371 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
1372 (LinkageSpecDecl::LanguageIDs)0,
1373 false);
1374 break;
1375 case pch::DECL_NAMESPACE:
1376 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
1377 break;
1378 case pch::DECL_NAMESPACE_ALIAS:
1379 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
1380 SourceLocation(), 0, SourceRange(), 0,
1381 SourceLocation(), 0);
1382 break;
1383 case pch::DECL_USING:
1384 D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(),
1385 SourceLocation(), 0, DeclarationName(), false);
1386 break;
1387 case pch::DECL_USING_SHADOW:
1388 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1389 break;
1390 case pch::DECL_USING_DIRECTIVE:
1391 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
1392 SourceLocation(), SourceRange(), 0,
1393 SourceLocation(), 0, 0);
1394 break;
1395 case pch::DECL_UNRESOLVED_USING_VALUE:
1396 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
1397 SourceRange(), 0, SourceLocation(),
1398 DeclarationName());
1399 break;
1400 case pch::DECL_UNRESOLVED_USING_TYPENAME:
1401 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
1402 SourceLocation(), SourceRange(),
1403 0, SourceLocation(),
1404 DeclarationName());
1405 break;
1406 case pch::DECL_CXX_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001407 D = CXXRecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001408 break;
1409 case pch::DECL_CXX_METHOD:
1410 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
1411 QualType(), 0);
1412 break;
1413 case pch::DECL_CXX_CONSTRUCTOR:
1414 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1415 break;
1416 case pch::DECL_CXX_DESTRUCTOR:
1417 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1418 break;
1419 case pch::DECL_CXX_CONVERSION:
1420 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1421 break;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001422 case pch::DECL_ACCESS_SPEC:
1423 D = AccessSpecDecl::Create(*Context, AS_none, 0, SourceLocation(),
1424 SourceLocation());
1425 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001426 case pch::DECL_FRIEND:
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001427 D = FriendDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001428 break;
1429 case pch::DECL_FRIEND_TEMPLATE:
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001430 D = FriendTemplateDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001431 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001432 case pch::DECL_CLASS_TEMPLATE:
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +00001433 D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(),
1434 DeclarationName(), 0, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001435 break;
1436 case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001437 D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001438 break;
1439 case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001440 D = ClassTemplatePartialSpecializationDecl::Create(*Context,
1441 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001442 break;
1443 case pch::DECL_FUNCTION_TEMPLATE:
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001444 D = FunctionTemplateDecl::Create(*Context, 0, SourceLocation(),
1445 DeclarationName(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001446 break;
1447 case pch::DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001448 D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001449 break;
1450 case pch::DECL_NON_TYPE_TEMPLATE_PARM:
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001451 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0,
1452 QualType(),0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001453 break;
1454 case pch::DECL_TEMPLATE_TEMPLATE_PARM:
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001455 D = TemplateTemplateParmDecl::Create(*Context, 0, SourceLocation(),0,0,0,0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001456 break;
1457 case pch::DECL_STATIC_ASSERT:
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001458 D = StaticAssertDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001459 break;
1460
Chris Lattner8f63ab52009-04-27 06:01:06 +00001461 case pch::DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +00001462 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001463 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001464 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001465 case pch::DECL_OBJC_INTERFACE:
Sebastian Redlab6a0882010-08-09 21:55:28 +00001466 D = ObjCInterfaceDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001467 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001468 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001469 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001470 ObjCIvarDecl::None);
1471 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001472 case pch::DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001473 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001474 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001475 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001476 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001477 QualType(), 0);
1478 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001479 case pch::DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001480 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001481 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001482 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001483 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001484 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001485 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +00001486 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1487 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001488 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001489 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001490 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001491 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001492 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +00001493 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001494 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001495 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001496 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001497 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001498 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001499 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001500 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001501 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001502 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001503 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001504 SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001505 ObjCPropertyImplDecl::Dynamic, 0);
1506 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001507 case pch::DECL_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001508 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +00001509 false);
Chris Lattner487412d2009-04-27 05:27:42 +00001510 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001511 case pch::DECL_VAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001512 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001513 VarDecl::None, VarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001514 break;
1515
1516 case pch::DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001517 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001518 break;
1519
Chris Lattner8f63ab52009-04-27 06:01:06 +00001520 case pch::DECL_PARM_VAR:
Mike Stump11289f42009-09-09 15:08:12 +00001521 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001522 VarDecl::None, VarDecl::None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001523 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001524 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001525 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001526 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001527 case pch::DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +00001528 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001529 break;
1530 }
Chris Lattner487412d2009-04-27 05:27:42 +00001531
1532 assert(D && "Unknown declaration reading PCH file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001533 LoadedDecl(Index, D);
1534 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001535
1536 // If this declaration is also a declaration context, get the
1537 // offsets for its tables of lexical and visible declarations.
1538 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1539 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1540 if (Offsets.first || Offsets.second) {
1541 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1542 DC->setHasExternalVisibleStorage(Offsets.second != 0);
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001543 DeclContextInfo Info;
1544 if (ReadDeclContextStorage(DeclsCursor, Offsets, Info))
1545 return 0;
Sebastian Redl4b1f4902010-07-27 18:24:41 +00001546 DeclContextInfos &Infos = DeclContextOffsets[DC];
1547 // Reading the TU will happen after reading its update blocks, so we need
1548 // to make sure we insert in front. For all other contexts, the vector
1549 // is empty here anyway, so there's no loss in efficiency.
1550 Infos.insert(Infos.begin(), Info);
Chris Lattner487412d2009-04-27 05:27:42 +00001551 }
1552 }
1553 assert(Idx == Record.size());
1554
1555 // If we have deserialized a declaration that has a definition the
Argyrios Kyrtzidis903ccd62010-07-07 15:46:26 +00001556 // AST consumer might need to know about, queue it.
1557 // We don't pass it to the consumer immediately because we may be in recursive
1558 // loading, and some declarations may still be initializing.
1559 if (isConsumerInterestedIn(D))
1560 InterestingDecls.push_back(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001561
1562 return D;
1563}
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001564
1565bool PCHReader::ReadDeclContextStorage(llvm::BitstreamCursor &Cursor,
1566 const std::pair<uint64_t, uint64_t> &Offsets,
1567 DeclContextInfo &Info) {
1568 SavedStreamPosition SavedPosition(Cursor);
1569 // First the lexical decls.
1570 if (Offsets.first != 0) {
1571 Cursor.JumpToBit(Offsets.first);
1572
1573 RecordData Record;
1574 const char *Blob;
1575 unsigned BlobLen;
1576 unsigned Code = Cursor.ReadCode();
1577 unsigned RecCode = Cursor.ReadRecord(Code, Record, &Blob, &BlobLen);
1578 if (RecCode != pch::DECL_CONTEXT_LEXICAL) {
1579 Error("Expected lexical block");
1580 return true;
1581 }
1582
1583 Info.LexicalDecls = reinterpret_cast<const pch::DeclID*>(Blob);
1584 Info.NumLexicalDecls = BlobLen / sizeof(pch::DeclID);
1585 } else {
1586 Info.LexicalDecls = 0;
1587 Info.NumLexicalDecls = 0;
1588 }
1589
1590 // Now the visible decls.
1591 Info.Stream = &Cursor;
1592 Info.OffsetToVisibleDecls = Offsets.second;
1593
1594 return false;
1595}