blob: 8af8dc8d78d246520561790c933f13a8ae57e2c6 [file] [log] [blame]
Chris Lattner487412d2009-04-27 05:27:42 +00001//===--- PCHReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the PCHReader::ReadDeclRecord method, which is the
11// entrypoint for loading a decl.
12//
13//===----------------------------------------------------------------------===//
14
15#include "clang/Frontend/PCHReader.h"
16#include "clang/AST/ASTConsumer.h"
17#include "clang/AST/ASTContext.h"
18#include "clang/AST/DeclVisitor.h"
19#include "clang/AST/DeclGroup.h"
Chris Lattnerca025db2010-05-07 21:43:38 +000020#include "clang/AST/DeclCXX.h"
21#include "clang/AST/DeclTemplate.h"
Chris Lattner487412d2009-04-27 05:27:42 +000022#include "clang/AST/Expr.h"
23using namespace clang;
24
Chris Lattner487412d2009-04-27 05:27:42 +000025
26//===----------------------------------------------------------------------===//
27// Declaration deserialization
28//===----------------------------------------------------------------------===//
29
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000030namespace clang {
Chris Lattner487412d2009-04-27 05:27:42 +000031 class PCHDeclReader : public DeclVisitor<PCHDeclReader, void> {
32 PCHReader &Reader;
33 const PCHReader::RecordData &Record;
34 unsigned &Idx;
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +000035 pch::TypeID TypeIDForTypeDecl;
Chris Lattner487412d2009-04-27 05:27:42 +000036
37 public:
38 PCHDeclReader(PCHReader &Reader, const PCHReader::RecordData &Record,
39 unsigned &Idx)
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +000040 : Reader(Reader), Record(Record), Idx(Idx), TypeIDForTypeDecl(0) { }
Chris Lattner487412d2009-04-27 05:27:42 +000041
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +000042 CXXBaseSpecifier ReadCXXBaseSpecifier();
John McCall1c70e992010-06-03 19:28:45 +000043
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +000044 void Visit(Decl *D);
45
Chris Lattner487412d2009-04-27 05:27:42 +000046 void VisitDecl(Decl *D);
47 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
48 void VisitNamedDecl(NamedDecl *ND);
Douglas Gregore31bbd92010-02-21 18:22:14 +000049 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000050 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
51 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000052 void VisitTypeDecl(TypeDecl *TD);
53 void VisitTypedefDecl(TypedefDecl *TD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000054 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000055 void VisitTagDecl(TagDecl *TD);
56 void VisitEnumDecl(EnumDecl *ED);
57 void VisitRecordDecl(RecordDecl *RD);
Chris Lattnerca025db2010-05-07 21:43:38 +000058 void VisitCXXRecordDecl(CXXRecordDecl *D);
59 void VisitClassTemplateSpecializationDecl(
60 ClassTemplateSpecializationDecl *D);
61 void VisitClassTemplatePartialSpecializationDecl(
62 ClassTemplatePartialSpecializationDecl *D);
63 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000064 void VisitValueDecl(ValueDecl *VD);
65 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000066 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +000067 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +000068 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattnerca025db2010-05-07 21:43:38 +000069 void VisitCXXMethodDecl(CXXMethodDecl *D);
70 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
71 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
72 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000073 void VisitFieldDecl(FieldDecl *FD);
74 void VisitVarDecl(VarDecl *VD);
75 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
76 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattnerca025db2010-05-07 21:43:38 +000077 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
78 void VisitTemplateDecl(TemplateDecl *D);
79 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +000080 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000081 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +000082 void VisitUsingDecl(UsingDecl *D);
83 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000084 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000085 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Abramo Bagnarad7340582010-06-05 05:09:32 +000086 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000087 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000088 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
89 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000090 void VisitBlockDecl(BlockDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +000091
Chris Lattner487412d2009-04-27 05:27:42 +000092 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Chris Lattnerca025db2010-05-07 21:43:38 +000093
Alexis Hunted053252010-05-30 07:21:58 +000094 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-04-27 05:27:42 +000095 void VisitObjCMethodDecl(ObjCMethodDecl *D);
96 void VisitObjCContainerDecl(ObjCContainerDecl *D);
97 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
98 void VisitObjCIvarDecl(ObjCIvarDecl *D);
99 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
100 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
101 void VisitObjCClassDecl(ObjCClassDecl *D);
102 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
103 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
104 void VisitObjCImplDecl(ObjCImplDecl *D);
105 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
106 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
107 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
108 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
109 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
110 };
111}
112
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000113void PCHDeclReader::Visit(Decl *D) {
114 DeclVisitor<PCHDeclReader, void>::Visit(D);
115
116 // if we have a fully initialized TypeDecl, we can safely read its type now.
117 if (TypeDecl *TD = dyn_cast<TypeDecl>(D))
118 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtr());
119}
120
Chris Lattner487412d2009-04-27 05:27:42 +0000121void PCHDeclReader::VisitDecl(Decl *D) {
122 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
123 D->setLexicalDeclContext(
124 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
125 D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
126 D->setInvalidDecl(Record[Idx++]);
127 if (Record[Idx++])
Argyrios Kyrtzidis91167172010-06-11 23:09:25 +0000128 D->initAttrs(Reader.ReadAttributes());
Chris Lattner487412d2009-04-27 05:27:42 +0000129 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +0000130 D->setUsed(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000131 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor16bef852009-10-16 20:01:17 +0000132 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner487412d2009-04-27 05:27:42 +0000133}
134
135void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
136 VisitDecl(TU);
Chris Lattnerca025db2010-05-07 21:43:38 +0000137 TU->setAnonymousNamespace(
138 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000139}
140
141void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) {
142 VisitDecl(ND);
Mike Stump11289f42009-09-09 15:08:12 +0000143 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000144}
145
146void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
147 VisitNamedDecl(TD);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000148 // Delay type reading until after we have fully initialized the decl.
149 TypeIDForTypeDecl = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000150}
151
152void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000153 VisitTypeDecl(TD);
John McCallbcd03502009-12-07 02:54:59 +0000154 TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000155}
156
157void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
158 VisitTypeDecl(TD);
Douglas Gregorb6b8f9e2009-07-29 23:36:44 +0000159 TD->setPreviousDeclaration(
160 cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000161 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
162 TD->setDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000163 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis664b6902009-07-14 03:18:02 +0000164 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000165 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall3e11ebe2010-03-15 10:12:16 +0000166 // FIXME: maybe read optional qualifier and its range.
167 TD->setTypedefForAnonDecl(
168 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000169}
170
171void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
172 VisitTagDecl(ED);
173 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall56774992009-12-09 09:09:27 +0000174 ED->setPromotionType(Reader.GetType(Record[Idx++]));
John McCall9aa35be2010-05-06 08:49:23 +0000175 ED->setNumPositiveBits(Record[Idx++]);
176 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor7a749382009-05-27 17:20:35 +0000177 // FIXME: C++ InstantiatedFrom
Chris Lattner487412d2009-04-27 05:27:42 +0000178}
179
180void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
181 VisitTagDecl(RD);
182 RD->setHasFlexibleArrayMember(Record[Idx++]);
183 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000184 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000185}
186
187void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
188 VisitNamedDecl(VD);
189 VD->setType(Reader.GetType(Record[Idx++]));
190}
191
192void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
193 VisitValueDecl(ECD);
194 if (Record[Idx++])
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000195 ECD->setInitExpr(Reader.ReadExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000196 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
197}
198
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000199void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
200 VisitValueDecl(DD);
John McCallbcd03502009-12-07 02:54:59 +0000201 TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Record, Idx);
202 if (TInfo)
203 DD->setTypeSourceInfo(TInfo);
John McCall3e11ebe2010-03-15 10:12:16 +0000204 // FIXME: read optional qualifier and its range.
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000205}
206
Chris Lattner487412d2009-04-27 05:27:42 +0000207void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000208 VisitDeclaratorDecl(FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000209
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000210 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000211 default: assert(false && "Unhandled TemplatedKind!");
212 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000213 case FunctionDecl::TK_NonTemplate:
214 break;
215 case FunctionDecl::TK_FunctionTemplate:
216 FD->setDescribedFunctionTemplate(
217 cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++])));
218 break;
219 case FunctionDecl::TK_MemberSpecialization: {
220 FunctionDecl *InstFD = cast<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
221 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
222 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
223 FD->setInstantiationOfMemberFunction(InstFD, TSK);
224 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
225 break;
226 }
227 case FunctionDecl::TK_FunctionTemplateSpecialization: {
228 FunctionTemplateDecl *Template
229 = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
230 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
231
232 // Template arguments.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000233 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000234 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000235
236 // Template args as written.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000237 llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000238 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000239 if (Record[Idx++]) { // TemplateArgumentsAsWritten != 0
240 unsigned NumTemplateArgLocs = Record[Idx++];
241 TemplArgLocs.reserve(NumTemplateArgLocs);
242 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
243 TemplArgLocs.push_back(Reader.ReadTemplateArgumentLoc(Record, Idx));
244
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000245 LAngleLoc = Reader.ReadSourceLocation(Record, Idx);
246 RAngleLoc = Reader.ReadSourceLocation(Record, Idx);
247 }
248
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000249 FD->setFunctionTemplateSpecialization(Template, TemplArgs.size(),
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000250 TemplArgs.data(), TSK,
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000251 TemplArgLocs.size(),
252 TemplArgLocs.data(),
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000253 LAngleLoc, RAngleLoc);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000254 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000255 }
256 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
257 // Templates.
258 UnresolvedSet<8> TemplDecls;
259 unsigned NumTemplates = Record[Idx++];
260 while (NumTemplates--)
261 TemplDecls.addDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
262
263 // Templates args.
264 TemplateArgumentListInfo TemplArgs;
265 unsigned NumArgs = Record[Idx++];
266 while (NumArgs--)
267 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
268
269 FD->setDependentTemplateSpecialization(*Reader.getContext(),
270 TemplDecls, TemplArgs);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000271 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000272 }
273 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000274
275 if (Record[Idx++])
276 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
277 FD->setPreviousDeclaration(
278 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
279 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
280 FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]);
281 FD->setInlineSpecified(Record[Idx++]);
282 FD->setVirtualAsWritten(Record[Idx++]);
283 FD->setPure(Record[Idx++]);
284 FD->setHasInheritedPrototype(Record[Idx++]);
285 FD->setHasWrittenPrototype(Record[Idx++]);
286 FD->setDeleted(Record[Idx++]);
287 FD->setTrivial(Record[Idx++]);
288 FD->setCopyAssignment(Record[Idx++]);
289 FD->setHasImplicitReturnZero(Record[Idx++]);
290 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
291
Chris Lattnerca025db2010-05-07 21:43:38 +0000292 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000293 unsigned NumParams = Record[Idx++];
294 llvm::SmallVector<ParmVarDecl *, 16> Params;
295 Params.reserve(NumParams);
296 for (unsigned I = 0; I != NumParams; ++I)
297 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000298 FD->setParams(Params.data(), NumParams);
John McCallb9467b62010-04-24 01:30:58 +0000299
300 // FIXME: order this properly w.r.t. friendness
301 // FIXME: this same thing needs to happen for function templates
302 if (FD->isOverloadedOperator() && !FD->getDeclContext()->isRecord())
303 FD->setNonMemberOperator();
Chris Lattner487412d2009-04-27 05:27:42 +0000304}
305
306void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
307 VisitNamedDecl(MD);
308 if (Record[Idx++]) {
309 // In practice, this won't be executed (since method definitions
310 // don't occur in header files).
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000311 MD->setBody(Reader.ReadStmt());
Chris Lattner487412d2009-04-27 05:27:42 +0000312 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
313 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
314 }
315 MD->setInstanceMethod(Record[Idx++]);
316 MD->setVariadic(Record[Idx++]);
317 MD->setSynthesized(Record[Idx++]);
318 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
319 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahaniand9235db2010-04-08 21:29:11 +0000320 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000321 MD->setResultType(Reader.GetType(Record[Idx++]));
Douglas Gregor12852d92010-03-08 14:59:44 +0000322 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000323 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
324 unsigned NumParams = Record[Idx++];
325 llvm::SmallVector<ParmVarDecl *, 16> Params;
326 Params.reserve(NumParams);
327 for (unsigned I = 0; I != NumParams; ++I)
328 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniancdabb312010-04-09 15:40:42 +0000329 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
330 NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000331}
332
333void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
334 VisitNamedDecl(CD);
Ted Kremenekc7c64312010-01-07 01:20:12 +0000335 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
336 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
337 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner487412d2009-04-27 05:27:42 +0000338}
339
340void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
341 VisitObjCContainerDecl(ID);
342 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
343 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
344 (Reader.GetDecl(Record[Idx++])));
345 unsigned NumProtocols = Record[Idx++];
346 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
347 Protocols.reserve(NumProtocols);
348 for (unsigned I = 0; I != NumProtocols; ++I)
349 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000350 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
351 ProtoLocs.reserve(NumProtocols);
352 for (unsigned I = 0; I != NumProtocols; ++I)
353 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
354 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
355 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000356 unsigned NumIvars = Record[Idx++];
357 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
358 IVars.reserve(NumIvars);
359 for (unsigned I = 0; I != NumIvars; ++I)
360 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000361 ID->setCategoryList(
362 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
363 ID->setForwardDecl(Record[Idx++]);
364 ID->setImplicitInterfaceDecl(Record[Idx++]);
365 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
366 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisea72f422009-07-18 00:33:23 +0000367 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000368}
369
370void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
371 VisitFieldDecl(IVD);
372 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
373}
374
375void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
376 VisitObjCContainerDecl(PD);
377 PD->setForwardDecl(Record[Idx++]);
378 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
379 unsigned NumProtoRefs = Record[Idx++];
380 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
381 ProtoRefs.reserve(NumProtoRefs);
382 for (unsigned I = 0; I != NumProtoRefs; ++I)
383 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000384 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
385 ProtoLocs.reserve(NumProtoRefs);
386 for (unsigned I = 0; I != NumProtoRefs; ++I)
387 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
388 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
389 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000390}
391
392void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
393 VisitFieldDecl(FD);
394}
395
396void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
397 VisitDecl(CD);
398 unsigned NumClassRefs = Record[Idx++];
399 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
400 ClassRefs.reserve(NumClassRefs);
401 for (unsigned I = 0; I != NumClassRefs; ++I)
402 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000403 llvm::SmallVector<SourceLocation, 16> SLocs;
404 SLocs.reserve(NumClassRefs);
405 for (unsigned I = 0; I != NumClassRefs; ++I)
406 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
407 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
408 NumClassRefs);
Chris Lattner487412d2009-04-27 05:27:42 +0000409}
410
411void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
412 VisitDecl(FPD);
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 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
423 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000424}
425
426void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
427 VisitObjCContainerDecl(CD);
428 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
429 unsigned NumProtoRefs = Record[Idx++];
430 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
431 ProtoRefs.reserve(NumProtoRefs);
432 for (unsigned I = 0; I != NumProtoRefs; ++I)
433 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000434 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
435 ProtoLocs.reserve(NumProtoRefs);
436 for (unsigned I = 0; I != NumProtoRefs; ++I)
437 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
438 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
439 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000440 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor071676f2010-01-16 16:38:58 +0000441 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
442 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000443}
444
445void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
446 VisitNamedDecl(CAD);
447 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
448}
449
450void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
451 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000452 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall339bb662010-06-04 20:50:08 +0000453 D->setType(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000454 // FIXME: stable encoding
455 D->setPropertyAttributes(
456 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000457 D->setPropertyAttributesAsWritten(
458 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000459 // FIXME: stable encoding
460 D->setPropertyImplementation(
461 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
462 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
463 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
464 D->setGetterMethodDecl(
465 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
466 D->setSetterMethodDecl(
467 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
468 D->setPropertyIvarDecl(
469 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
470}
471
472void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000473 VisitObjCContainerDecl(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000474 D->setClassInterface(
475 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000476}
477
478void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
479 VisitObjCImplDecl(D);
480 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
481}
482
483void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
484 VisitObjCImplDecl(D);
485 D->setSuperClass(
486 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanianc83726e2010-04-28 16:11:27 +0000487 // FIXME. Add reading of IvarInitializers and NumIvarInitializers.
Chris Lattner487412d2009-04-27 05:27:42 +0000488}
489
490
491void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
492 VisitDecl(D);
493 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
494 D->setPropertyDecl(
495 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
496 D->setPropertyIvarDecl(
497 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanian25491a22010-05-05 21:52:17 +0000498 // FIXME. read GetterCXXConstructor and SetterCXXAssignment
Chris Lattner487412d2009-04-27 05:27:42 +0000499}
500
501void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000502 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000503 FD->setMutable(Record[Idx++]);
504 if (Record[Idx++])
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000505 FD->setBitWidth(Reader.ReadExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000506}
507
508void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000509 VisitDeclaratorDecl(VD);
Chris Lattner487412d2009-04-27 05:27:42 +0000510 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
Douglas Gregorc4df4072010-04-19 22:54:31 +0000511 VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000512 VD->setThreadSpecified(Record[Idx++]);
513 VD->setCXXDirectInitializer(Record[Idx++]);
514 VD->setDeclaredInCondition(Record[Idx++]);
Douglas Gregor3f324d562010-05-03 18:51:14 +0000515 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor6fd1b182010-05-15 06:01:05 +0000516 VD->setNRVOVariable(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000517 VD->setPreviousDeclaration(
518 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000519 if (Record[Idx++])
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000520 VD->setInit(Reader.ReadExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000521}
522
523void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
524 VisitVarDecl(PD);
525}
526
527void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
528 VisitVarDecl(PD);
529 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallf3cd6652010-03-12 18:31:32 +0000530 PD->setHasInheritedDefaultArg(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000531}
532
Chris Lattner487412d2009-04-27 05:27:42 +0000533void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
534 VisitDecl(AD);
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000535 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr()));
Chris Lattner487412d2009-04-27 05:27:42 +0000536}
537
538void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
539 VisitDecl(BD);
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000540 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt()));
John McCalla3ccba02010-06-04 11:21:44 +0000541 BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000542 unsigned NumParams = Record[Idx++];
543 llvm::SmallVector<ParmVarDecl *, 16> Params;
544 Params.reserve(NumParams);
545 for (unsigned I = 0; I != NumParams; ++I)
546 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000547 BD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000548}
549
Chris Lattnerca025db2010-05-07 21:43:38 +0000550void PCHDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
551 VisitDecl(D);
552 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
553 D->setHasBraces(Record[Idx++]);
554}
555
556void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
557 VisitNamedDecl(D);
558 D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx));
559 D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx));
560 D->setNextNamespace(
561 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
562
563 // Only read one reference--the original or anonymous namespace.
564 bool IsOriginal = Record[Idx++];
565 if (IsOriginal)
566 D->setAnonymousNamespace(
567 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
568 else
569 D->setOriginalNamespace(
570 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
571}
572
573void PCHDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
574 VisitNamedDecl(D);
575
576 D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx));
577 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
578 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
579 D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx));
580 D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
581}
582
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000583void PCHDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000584 VisitNamedDecl(D);
585 D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
586 D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
587 D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
588
589 // FIXME: It would probably be more efficient to read these into a vector
590 // and then re-cosntruct the shadow decl set over that vector since it
591 // would avoid existence checks.
592 unsigned NumShadows = Record[Idx++];
593 for(unsigned I = 0; I != NumShadows; ++I) {
594 D->addShadowDecl(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])));
595 }
596 D->setTypeName(Record[Idx++]);
597}
598
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000599void PCHDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000600 VisitNamedDecl(D);
601 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
602 D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
603}
604
605void PCHDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
606 VisitNamedDecl(D);
607 D->setNamespaceKeyLocation(Reader.ReadSourceLocation(Record, Idx));
608 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
609 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
610 D->setIdentLocation(Reader.ReadSourceLocation(Record, Idx));
611 D->setNominatedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
612 D->setCommonAncestor(cast_or_null<DeclContext>(
613 Reader.GetDecl(Record[Idx++])));
614}
615
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000616void PCHDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000617 VisitValueDecl(D);
618 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
619 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
620 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
621}
622
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000623void PCHDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000624 UnresolvedUsingTypenameDecl *D) {
625 VisitTypeDecl(D);
626 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
627 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
628 D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx));
629 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
630}
631
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000632CXXBaseSpecifier PCHDeclReader::ReadCXXBaseSpecifier() {
John McCall1c70e992010-06-03 19:28:45 +0000633 bool isVirtual = static_cast<bool>(Record[Idx++]);
634 bool isBaseOfClass = static_cast<bool>(Record[Idx++]);
635 AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]);
636 QualType T = Reader.GetType(Record[Idx++]);
637 SourceRange Range = Reader.ReadSourceRange(Record, Idx);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000638 return CXXBaseSpecifier(Range, isVirtual, isBaseOfClass, AS, T);
John McCall1c70e992010-06-03 19:28:45 +0000639}
640
Chris Lattnerca025db2010-05-07 21:43:38 +0000641void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000642 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000643
644 ASTContext &C = *Reader.getContext();
645
646 if (D->isFirstDeclaration()) {
647 if (Record[Idx++]) { // DefinitionData != 0
648 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(0);
649 struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData;
650
651 Data.UserDeclaredConstructor = Record[Idx++];
652 Data.UserDeclaredCopyConstructor = Record[Idx++];
653 Data.UserDeclaredCopyAssignment = Record[Idx++];
654 Data.UserDeclaredDestructor = Record[Idx++];
655 Data.Aggregate = Record[Idx++];
656 Data.PlainOldData = Record[Idx++];
657 Data.Empty = Record[Idx++];
658 Data.Polymorphic = Record[Idx++];
659 Data.Abstract = Record[Idx++];
660 Data.HasTrivialConstructor = Record[Idx++];
661 Data.HasTrivialCopyConstructor = Record[Idx++];
662 Data.HasTrivialCopyAssignment = Record[Idx++];
663 Data.HasTrivialDestructor = Record[Idx++];
664 Data.ComputedVisibleConversions = Record[Idx++];
665
666 // setBases() is unsuitable since it may try to iterate the bases of an
667 // unitialized base.
668 Data.NumBases = Record[Idx++];
669 Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases];
670 for (unsigned i = 0; i != Data.NumBases; ++i)
671 Data.Bases[i] = ReadCXXBaseSpecifier();
672
673 // FIXME: Make VBases lazily computed when needed to avoid storing them.
674 Data.NumVBases = Record[Idx++];
675 Data.VBases = new(C) CXXBaseSpecifier [Data.NumVBases];
676 for (unsigned i = 0; i != Data.NumVBases; ++i)
677 Data.VBases[i] = ReadCXXBaseSpecifier();
678
679 Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx);
680 Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx);
681 Data.Definition = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
682 Data.FirstFriend
683 = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
684 }
685 } else {
686 D->DefinitionData = D->getPreviousDeclaration()->DefinitionData;
687 }
688
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000689 enum CXXRecKind {
690 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
691 };
692 switch ((CXXRecKind)Record[Idx++]) {
693 default:
694 assert(false && "Out of sync with PCHDeclWriter::VisitCXXRecordDecl?");
695 case CXXRecNotTemplate:
696 break;
697 case CXXRecTemplate:
698 D->setDescribedClassTemplate(
699 cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++])));
700 break;
701 case CXXRecMemberSpecialization: {
702 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
703 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
704 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
705 D->setInstantiationOfMemberClass(RD, TSK);
706 D->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
707 break;
708 }
709 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000710}
711
712void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
713 // assert(false && "cannot read CXXMethodDecl");
714 VisitFunctionDecl(D);
715}
716
717void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
718 // assert(false && "cannot read CXXConstructorDecl");
719 VisitCXXMethodDecl(D);
720}
721
722void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
723 // assert(false && "cannot read CXXDestructorDecl");
724 VisitCXXMethodDecl(D);
725}
726
727void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
728 // assert(false && "cannot read CXXConversionDecl");
729 VisitCXXMethodDecl(D);
730}
731
Abramo Bagnarad7340582010-06-05 05:09:32 +0000732void PCHDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
733 VisitDecl(D);
734 D->setColonLoc(Reader.ReadSourceLocation(Record, Idx));
735}
736
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000737void PCHDeclReader::VisitFriendDecl(FriendDecl *D) {
738 if (Record[Idx++])
739 D->Friend = Reader.GetTypeSourceInfo(Record, Idx);
740 else
741 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
742 D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
743 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
744}
745
Chris Lattnerca025db2010-05-07 21:43:38 +0000746void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
747 assert(false && "cannot read FriendTemplateDecl");
748}
749
750void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000751 VisitNamedDecl(D);
752
753 NamedDecl *TemplatedDecl = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000754 TemplateParameterList* TemplateParams
755 = Reader.ReadTemplateParameterList(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000756 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +0000757}
758
759void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000760 VisitTemplateDecl(D);
761
762 ClassTemplateDecl *PrevDecl =
763 cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +0000764 D->setPreviousDeclaration(PrevDecl);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000765 if (PrevDecl == 0) {
766 // This ClassTemplateDecl owns a CommonPtr; read it.
767
768 unsigned size = Record[Idx++];
769 while (size--) {
770 ClassTemplateSpecializationDecl *CTSD
771 = cast<ClassTemplateSpecializationDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidise23371e2010-07-02 11:55:37 +0000772 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
773 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000774 llvm::FoldingSetNodeID ID;
775 void *InsertPos = 0;
Argyrios Kyrtzidise23371e2010-07-02 11:55:37 +0000776 ClassTemplateSpecializationDecl::Profile(ID, TemplArgs.data(),
777 TemplArgs.size(),
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000778 *Reader.getContext());
779 D->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
780 D->getSpecializations().InsertNode(CTSD, InsertPos);
781 }
782
783 size = Record[Idx++];
784 while (size--) {
785 ClassTemplatePartialSpecializationDecl *CTSD
786 = cast<ClassTemplatePartialSpecializationDecl>(
787 Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidise23371e2010-07-02 11:55:37 +0000788 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
789 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000790 llvm::FoldingSetNodeID ID;
791 void *InsertPos = 0;
Argyrios Kyrtzidise23371e2010-07-02 11:55:37 +0000792 ClassTemplatePartialSpecializationDecl::Profile(ID, TemplArgs.data(),
793 TemplArgs.size(),
794 *Reader.getContext());
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000795 D->getPartialSpecializations().FindNodeOrInsertPos(ID, InsertPos);
796 D->getPartialSpecializations().InsertNode(CTSD, InsertPos);
797 }
798
799 // InjectedClassNameType is computed.
800
801 if (ClassTemplateDecl *CTD
802 = cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
803 D->setInstantiatedFromMemberTemplate(CTD);
804 if (Record[Idx++])
805 D->setMemberSpecialization();
806 }
807 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000808}
809
810void PCHDeclReader::VisitClassTemplateSpecializationDecl(
811 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000812 VisitCXXRecordDecl(D);
813
814 if (Decl *InstD = Reader.GetDecl(Record[Idx++])) {
815 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
816 D->setInstantiationOf(CTD);
817 } else {
818 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
819 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
820 D->setInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(InstD),
821 TemplArgs.data(), TemplArgs.size());
822 }
823 }
824
825 // Explicit info.
826 if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Record, Idx)) {
827 D->setTypeAsWritten(TyInfo);
828 D->setExternLoc(Reader.ReadSourceLocation(Record, Idx));
829 D->setTemplateKeywordLoc(Reader.ReadSourceLocation(Record, Idx));
830 }
831
832 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
833 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
834 D->initTemplateArgs(TemplArgs.data(), TemplArgs.size());
835 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
836 if (POI.isValid())
837 D->setPointOfInstantiation(POI);
838 D->setSpecializationKind((TemplateSpecializationKind)Record[Idx++]);
Chris Lattnerca025db2010-05-07 21:43:38 +0000839}
840
841void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl(
842 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000843 VisitClassTemplateSpecializationDecl(D);
844
845 D->initTemplateParameters(Reader.ReadTemplateParameterList(Record, Idx));
846
847 TemplateArgumentListInfo ArgInfos;
848 unsigned NumArgs = Record[Idx++];
849 while (NumArgs--)
850 ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
851 D->initTemplateArgsAsWritten(ArgInfos);
852
853 D->setSequenceNumber(Record[Idx++]);
854
855 // These are read/set from/to the first declaration.
856 if (D->getPreviousDeclaration() == 0) {
857 D->setInstantiatedFromMember(
858 cast_or_null<ClassTemplatePartialSpecializationDecl>(
859 Reader.GetDecl(Record[Idx++])));
860 if (Record[Idx++])
861 D->isMemberSpecialization();
862 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000863}
864
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000865void PCHDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
866 VisitTemplateDecl(D);
867
868 FunctionTemplateDecl *PrevDecl =
869 cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
870 D->setPreviousDeclaration(PrevDecl);
871 if (PrevDecl == 0) {
872 // This FunctionTemplateDecl owns a CommonPtr; read it.
873
874 // FunctionTemplateSpecializationInfos are filled through the
875 // templated FunctionDecl's setFunctionTemplateSpecialization, no need to
876 // read them here.
877
878 if (FunctionTemplateDecl *CTD
879 = cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
880 D->setInstantiatedFromMemberTemplate(CTD);
881 if (Record[Idx++])
882 D->setMemberSpecialization();
883 }
884 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000885}
886
887void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000888 VisitTypeDecl(D);
889
890 D->setDeclaredWithTypename(Record[Idx++]);
891 D->setParameterPack(Record[Idx++]);
892
893 bool Inherited = Record[Idx++];
894 TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Record, Idx);
895 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +0000896}
897
898void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +0000899 VisitVarDecl(D);
900 // TemplateParmPosition.
901 D->setDepth(Record[Idx++]);
902 D->setPosition(Record[Idx++]);
903 // Rest of NonTypeTemplateParmDecl.
904 if (Record[Idx++]) {
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000905 Expr *DefArg = Reader.ReadExpr();
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +0000906 bool Inherited = Record[Idx++];
907 D->setDefaultArgument(DefArg, Inherited);
908 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000909}
910
911void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
912 assert(false && "cannot read TemplateTemplateParmDecl");
913}
914
915void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
916 assert(false && "cannot read StaticAssertDecl");
917}
918
Mike Stump11289f42009-09-09 15:08:12 +0000919std::pair<uint64_t, uint64_t>
Chris Lattner487412d2009-04-27 05:27:42 +0000920PCHDeclReader::VisitDeclContext(DeclContext *DC) {
921 uint64_t LexicalOffset = Record[Idx++];
922 uint64_t VisibleOffset = Record[Idx++];
923 return std::make_pair(LexicalOffset, VisibleOffset);
924}
925
926//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +0000927// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +0000928//===----------------------------------------------------------------------===//
929
Chris Lattner8f63ab52009-04-27 06:01:06 +0000930/// \brief Reads attributes from the current stream position.
931Attr *PCHReader::ReadAttributes() {
932 unsigned Code = DeclsCursor.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +0000933 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner8f63ab52009-04-27 06:01:06 +0000934 "Expected unabbreviated record"); (void)Code;
Mike Stump11289f42009-09-09 15:08:12 +0000935
Chris Lattner8f63ab52009-04-27 06:01:06 +0000936 RecordData Record;
937 unsigned Idx = 0;
938 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump11289f42009-09-09 15:08:12 +0000939 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner8f63ab52009-04-27 06:01:06 +0000940 (void)RecCode;
941
942#define SIMPLE_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +0000943 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +0000944 New = ::new (*Context) Name##Attr(); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000945 break
946
947#define STRING_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +0000948 case attr::Name: \
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000949 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000950 break
951
952#define UNSIGNED_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +0000953 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +0000954 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000955 break
956
957 Attr *Attrs = 0;
958 while (Idx < Record.size()) {
959 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +0000960 attr::Kind Kind = (attr::Kind)Record[Idx++];
Chris Lattner8f63ab52009-04-27 06:01:06 +0000961 bool IsInherited = Record[Idx++];
962
963 switch (Kind) {
Anton Korobeynikov55bcea12010-01-10 12:58:08 +0000964 default:
965 assert(0 && "Unknown attribute!");
966 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000967 STRING_ATTR(Alias);
Daniel Dunbarfc6507e2010-05-27 02:25:39 +0000968 SIMPLE_ATTR(AlignMac68k);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000969 UNSIGNED_ATTR(Aligned);
970 SIMPLE_ATTR(AlwaysInline);
971 SIMPLE_ATTR(AnalyzerNoReturn);
972 STRING_ATTR(Annotate);
973 STRING_ATTR(AsmLabel);
Alexis Hunt54a02542009-11-25 04:20:27 +0000974 SIMPLE_ATTR(BaseCheck);
Mike Stump11289f42009-09-09 15:08:12 +0000975
Alexis Hunt344393e2010-06-16 23:43:53 +0000976 case attr::Blocks:
Chris Lattner8575daa2009-04-27 21:45:14 +0000977 New = ::new (*Context) BlocksAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000978 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
979 break;
Mike Stump11289f42009-09-09 15:08:12 +0000980
Eli Friedmane4310c82009-11-09 18:38:53 +0000981 SIMPLE_ATTR(CDecl);
982
Alexis Hunt344393e2010-06-16 23:43:53 +0000983 case attr::Cleanup:
Chris Lattner8575daa2009-04-27 21:45:14 +0000984 New = ::new (*Context) CleanupAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000985 cast<FunctionDecl>(GetDecl(Record[Idx++])));
986 break;
987
988 SIMPLE_ATTR(Const);
989 UNSIGNED_ATTR(Constructor);
990 SIMPLE_ATTR(DLLExport);
991 SIMPLE_ATTR(DLLImport);
992 SIMPLE_ATTR(Deprecated);
993 UNSIGNED_ATTR(Destructor);
994 SIMPLE_ATTR(FastCall);
Alexis Hunt96d5c762009-11-21 08:43:09 +0000995 SIMPLE_ATTR(Final);
Mike Stump11289f42009-09-09 15:08:12 +0000996
Alexis Hunt344393e2010-06-16 23:43:53 +0000997 case attr::Format: {
Chris Lattner8f63ab52009-04-27 06:01:06 +0000998 std::string Type = ReadString(Record, Idx);
999 unsigned FormatIdx = Record[Idx++];
1000 unsigned FirstArg = Record[Idx++];
Ted Kremenek7f4945a2010-02-11 05:28:37 +00001001 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001002 break;
1003 }
Mike Stump11289f42009-09-09 15:08:12 +00001004
Alexis Hunt344393e2010-06-16 23:43:53 +00001005 case attr::FormatArg: {
Fariborz Jahanianf1c25022009-05-20 17:41:43 +00001006 unsigned FormatIdx = Record[Idx++];
1007 New = ::new (*Context) FormatArgAttr(FormatIdx);
1008 break;
1009 }
Mike Stump11289f42009-09-09 15:08:12 +00001010
Alexis Hunt344393e2010-06-16 23:43:53 +00001011 case attr::Sentinel: {
Fariborz Jahanian027b8862009-05-13 18:09:35 +00001012 int sentinel = Record[Idx++];
1013 int nullPos = Record[Idx++];
1014 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
1015 break;
1016 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001017
1018 SIMPLE_ATTR(GNUInline);
Alexis Hunt54a02542009-11-25 04:20:27 +00001019 SIMPLE_ATTR(Hiding);
Mike Stump11289f42009-09-09 15:08:12 +00001020
Alexis Hunt344393e2010-06-16 23:43:53 +00001021 case attr::IBAction:
Ted Kremenek06be9682010-02-17 02:37:45 +00001022 New = ::new (*Context) IBActionAttr();
1023 break;
1024
Alexis Hunt344393e2010-06-16 23:43:53 +00001025 case attr::IBOutlet:
Chris Lattner8575daa2009-04-27 21:45:14 +00001026 New = ::new (*Context) IBOutletAttr();
Chris Lattner8f63ab52009-04-27 06:01:06 +00001027 break;
1028
Alexis Hunt344393e2010-06-16 23:43:53 +00001029 case attr::IBOutletCollection: {
Ted Kremenek26bde772010-05-19 17:38:06 +00001030 ObjCInterfaceDecl *D =
1031 cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++]));
1032 New = ::new (*Context) IBOutletCollectionAttr(D);
1033 break;
1034 }
1035
Ryan Flynn1f1fdc02009-08-09 20:07:29 +00001036 SIMPLE_ATTR(Malloc);
Mike Stump3722f582009-08-26 22:31:08 +00001037 SIMPLE_ATTR(NoDebug);
1038 SIMPLE_ATTR(NoInline);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001039 SIMPLE_ATTR(NoReturn);
1040 SIMPLE_ATTR(NoThrow);
Mike Stump11289f42009-09-09 15:08:12 +00001041
Alexis Hunt344393e2010-06-16 23:43:53 +00001042 case attr::NonNull: {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001043 unsigned Size = Record[Idx++];
1044 llvm::SmallVector<unsigned, 16> ArgNums;
1045 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
1046 Idx += Size;
Ted Kremenek510ee252010-02-11 07:31:47 +00001047 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001048 break;
1049 }
Mike Stump11289f42009-09-09 15:08:12 +00001050
Alexis Hunt344393e2010-06-16 23:43:53 +00001051 case attr::ReqdWorkGroupSize: {
Nate Begemanf2758702009-06-26 06:32:41 +00001052 unsigned X = Record[Idx++];
1053 unsigned Y = Record[Idx++];
1054 unsigned Z = Record[Idx++];
1055 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
1056 break;
1057 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001058
1059 SIMPLE_ATTR(ObjCException);
1060 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekd9c66632010-02-18 00:05:45 +00001061 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +00001062 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenekd9c66632010-02-18 00:05:45 +00001063 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +00001064 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001065 SIMPLE_ATTR(Overloadable);
Alexis Hunt54a02542009-11-25 04:20:27 +00001066 SIMPLE_ATTR(Override);
Anders Carlsson68e0b682009-08-08 18:23:56 +00001067 SIMPLE_ATTR(Packed);
Daniel Dunbar40130442010-05-27 01:12:46 +00001068 UNSIGNED_ATTR(MaxFieldAlignment);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001069 SIMPLE_ATTR(Pure);
1070 UNSIGNED_ATTR(Regparm);
1071 STRING_ATTR(Section);
1072 SIMPLE_ATTR(StdCall);
Douglas Gregora941dca2010-05-18 16:57:00 +00001073 SIMPLE_ATTR(ThisCall);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001074 SIMPLE_ATTR(TransparentUnion);
1075 SIMPLE_ATTR(Unavailable);
1076 SIMPLE_ATTR(Unused);
1077 SIMPLE_ATTR(Used);
Mike Stump11289f42009-09-09 15:08:12 +00001078
Alexis Hunt344393e2010-06-16 23:43:53 +00001079 case attr::Visibility:
Chris Lattner8575daa2009-04-27 21:45:14 +00001080 New = ::new (*Context) VisibilityAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001081 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
1082 break;
1083
1084 SIMPLE_ATTR(WarnUnusedResult);
1085 SIMPLE_ATTR(Weak);
Rafael Espindolac18086a2010-02-23 22:00:30 +00001086 SIMPLE_ATTR(WeakRef);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001087 SIMPLE_ATTR(WeakImport);
1088 }
1089
1090 assert(New && "Unable to decode attribute?");
1091 New->setInherited(IsInherited);
1092 New->setNext(Attrs);
1093 Attrs = New;
1094 }
1095#undef UNSIGNED_ATTR
1096#undef STRING_ATTR
1097#undef SIMPLE_ATTR
1098
1099 // The list of attributes was built backwards. Reverse the list
1100 // before returning it.
1101 Attr *PrevAttr = 0, *NextAttr = 0;
1102 while (Attrs) {
1103 NextAttr = Attrs->getNext();
1104 Attrs->setNext(PrevAttr);
1105 PrevAttr = Attrs;
1106 Attrs = NextAttr;
1107 }
1108
1109 return PrevAttr;
1110}
1111
1112//===----------------------------------------------------------------------===//
1113// PCHReader Implementation
1114//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001115
1116/// \brief Note that we have loaded the declaration with the given
1117/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001118///
Chris Lattner487412d2009-04-27 05:27:42 +00001119/// This routine notes that this declaration has already been loaded,
1120/// so that future GetDecl calls will return this declaration rather
1121/// than trying to load a new declaration.
1122inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
1123 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1124 DeclsLoaded[Index] = D;
1125}
1126
1127
1128/// \brief Determine whether the consumer will be interested in seeing
1129/// this declaration (via HandleTopLevelDecl).
1130///
1131/// This routine should return true for anything that might affect
1132/// code generation, e.g., inline function definitions, Objective-C
1133/// declarations with metadata, etc.
1134static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001135 if (isa<FileScopeAsmDecl>(D))
1136 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001137 if (VarDecl *Var = dyn_cast<VarDecl>(D))
1138 return Var->isFileVarDecl() && Var->getInit();
1139 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1140 return Func->isThisDeclarationADefinition();
1141 return isa<ObjCProtocolDecl>(D);
1142}
1143
1144/// \brief Read the declaration at the given offset from the PCH file.
1145Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
1146 // Keep track of where we are in the stream, then jump back there
1147 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001148 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001149
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001150 ReadingKindTracker ReadingKind(Read_Decl, *this);
1151
Douglas Gregor1342e842009-07-06 18:54:52 +00001152 // Note that we are loading a declaration record.
1153 LoadingTypeOrDecl Loading(*this);
Mike Stump11289f42009-09-09 15:08:12 +00001154
Chris Lattner1de76db2009-04-27 05:58:23 +00001155 DeclsCursor.JumpToBit(Offset);
Chris Lattner487412d2009-04-27 05:27:42 +00001156 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001157 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001158 unsigned Idx = 0;
1159 PCHDeclReader Reader(*this, Record, Idx);
1160
Chris Lattner1de76db2009-04-27 05:58:23 +00001161 Decl *D = 0;
1162 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner487412d2009-04-27 05:27:42 +00001163 case pch::DECL_ATTR:
1164 case pch::DECL_CONTEXT_LEXICAL:
1165 case pch::DECL_CONTEXT_VISIBLE:
1166 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1167 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001168 case pch::DECL_TRANSLATION_UNIT:
1169 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +00001170 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +00001171 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001172 case pch::DECL_TYPEDEF:
John McCall703a3f82009-10-24 08:00:42 +00001173 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001174 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001175 case pch::DECL_ENUM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001176 D = EnumDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001177 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001178 case pch::DECL_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001179 D = RecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001180 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001181 case pch::DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +00001182 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001183 0, llvm::APSInt());
1184 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001185 case pch::DECL_FUNCTION:
Mike Stump11289f42009-09-09 15:08:12 +00001186 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001187 QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001188 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001189 case pch::DECL_LINKAGE_SPEC:
1190 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
1191 (LinkageSpecDecl::LanguageIDs)0,
1192 false);
1193 break;
1194 case pch::DECL_NAMESPACE:
1195 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
1196 break;
1197 case pch::DECL_NAMESPACE_ALIAS:
1198 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
1199 SourceLocation(), 0, SourceRange(), 0,
1200 SourceLocation(), 0);
1201 break;
1202 case pch::DECL_USING:
1203 D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(),
1204 SourceLocation(), 0, DeclarationName(), false);
1205 break;
1206 case pch::DECL_USING_SHADOW:
1207 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1208 break;
1209 case pch::DECL_USING_DIRECTIVE:
1210 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
1211 SourceLocation(), SourceRange(), 0,
1212 SourceLocation(), 0, 0);
1213 break;
1214 case pch::DECL_UNRESOLVED_USING_VALUE:
1215 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
1216 SourceRange(), 0, SourceLocation(),
1217 DeclarationName());
1218 break;
1219 case pch::DECL_UNRESOLVED_USING_TYPENAME:
1220 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
1221 SourceLocation(), SourceRange(),
1222 0, SourceLocation(),
1223 DeclarationName());
1224 break;
1225 case pch::DECL_CXX_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001226 D = CXXRecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001227 break;
1228 case pch::DECL_CXX_METHOD:
1229 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
1230 QualType(), 0);
1231 break;
1232 case pch::DECL_CXX_CONSTRUCTOR:
1233 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1234 break;
1235 case pch::DECL_CXX_DESTRUCTOR:
1236 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1237 break;
1238 case pch::DECL_CXX_CONVERSION:
1239 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1240 break;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001241 case pch::DECL_ACCESS_SPEC:
1242 D = AccessSpecDecl::Create(*Context, AS_none, 0, SourceLocation(),
1243 SourceLocation());
1244 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001245 case pch::DECL_FRIEND:
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001246 D = FriendDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001247 break;
1248 case pch::DECL_FRIEND_TEMPLATE:
1249 assert(false && "cannot read FriendTemplateDecl");
1250 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001251 case pch::DECL_CLASS_TEMPLATE:
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +00001252 D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(),
1253 DeclarationName(), 0, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001254 break;
1255 case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001256 D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001257 break;
1258 case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001259 D = ClassTemplatePartialSpecializationDecl::Create(*Context,
1260 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001261 break;
1262 case pch::DECL_FUNCTION_TEMPLATE:
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001263 D = FunctionTemplateDecl::Create(*Context, 0, SourceLocation(),
1264 DeclarationName(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001265 break;
1266 case pch::DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001267 D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001268 break;
1269 case pch::DECL_NON_TYPE_TEMPLATE_PARM:
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001270 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0,
1271 QualType(),0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001272 break;
1273 case pch::DECL_TEMPLATE_TEMPLATE_PARM:
1274 assert(false && "cannot read TemplateTemplateParmDecl");
1275 break;
1276 case pch::DECL_STATIC_ASSERT:
1277 assert(false && "cannot read StaticAssertDecl");
1278 break;
1279
Chris Lattner8f63ab52009-04-27 06:01:06 +00001280 case pch::DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +00001281 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001282 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001283 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001284 case pch::DECL_OBJC_INTERFACE:
Chris Lattner8575daa2009-04-27 21:45:14 +00001285 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001286 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001287 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001288 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001289 ObjCIvarDecl::None);
1290 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001291 case pch::DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001292 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001293 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001294 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001295 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001296 QualType(), 0);
1297 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001298 case pch::DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001299 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001300 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001301 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001302 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001303 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001304 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +00001305 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1306 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001307 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001308 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001309 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001310 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001311 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +00001312 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001313 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001314 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001315 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001316 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001317 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001318 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001319 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001320 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001321 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001322 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001323 SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001324 ObjCPropertyImplDecl::Dynamic, 0);
1325 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001326 case pch::DECL_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001327 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +00001328 false);
Chris Lattner487412d2009-04-27 05:27:42 +00001329 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001330 case pch::DECL_VAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001331 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001332 VarDecl::None, VarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001333 break;
1334
1335 case pch::DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001336 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001337 break;
1338
Chris Lattner8f63ab52009-04-27 06:01:06 +00001339 case pch::DECL_PARM_VAR:
Mike Stump11289f42009-09-09 15:08:12 +00001340 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001341 VarDecl::None, VarDecl::None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001342 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001343 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001344 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001345 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001346 case pch::DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +00001347 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001348 break;
1349 }
Chris Lattner487412d2009-04-27 05:27:42 +00001350
1351 assert(D && "Unknown declaration reading PCH file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001352 LoadedDecl(Index, D);
1353 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001354
1355 // If this declaration is also a declaration context, get the
1356 // offsets for its tables of lexical and visible declarations.
1357 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1358 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1359 if (Offsets.first || Offsets.second) {
1360 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1361 DC->setHasExternalVisibleStorage(Offsets.second != 0);
1362 DeclContextOffsets[DC] = Offsets;
1363 }
1364 }
1365 assert(Idx == Record.size());
1366
1367 // If we have deserialized a declaration that has a definition the
1368 // AST consumer might need to know about, notify the consumer
1369 // about that definition now or queue it for later.
1370 if (isConsumerInterestedIn(D)) {
1371 if (Consumer) {
1372 DeclGroupRef DG(D);
1373 Consumer->HandleTopLevelDecl(DG);
1374 } else {
1375 InterestingDecls.push_back(D);
1376 }
1377 }
1378
1379 return D;
1380}