blob: ea99ff249d4d3aa4fe2192c9e62addaa77288bfe [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 Lattner487412d2009-04-27 05:27:42 +0000209 if (Record[Idx++])
Chris Lattner1de76db2009-04-27 05:58:23 +0000210 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
Chris Lattner487412d2009-04-27 05:27:42 +0000211 FD->setPreviousDeclaration(
212 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
213 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
Douglas Gregorc4df4072010-04-19 22:54:31 +0000214 FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]);
Douglas Gregor35b57532009-10-27 21:01:01 +0000215 FD->setInlineSpecified(Record[Idx++]);
Anders Carlsson0a7c01f2009-05-14 22:15:41 +0000216 FD->setVirtualAsWritten(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000217 FD->setPure(Record[Idx++]);
Anders Carlssone0dd1d52009-05-14 21:46:00 +0000218 FD->setHasInheritedPrototype(Record[Idx++]);
219 FD->setHasWrittenPrototype(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000220 FD->setDeleted(Record[Idx++]);
Daniel Dunbarb45012d2009-09-22 05:38:14 +0000221 FD->setTrivial(Record[Idx++]);
222 FD->setCopyAssignment(Record[Idx++]);
223 FD->setHasImplicitReturnZero(Record[Idx++]);
Argyrios Kyrtzidis1ead0b42009-06-20 08:09:34 +0000224 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000225
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000226 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000227 default: assert(false && "Unhandled TemplatedKind!");
228 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000229 case FunctionDecl::TK_NonTemplate:
230 break;
231 case FunctionDecl::TK_FunctionTemplate:
232 FD->setDescribedFunctionTemplate(
233 cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++])));
234 break;
235 case FunctionDecl::TK_MemberSpecialization: {
236 FunctionDecl *InstFD = cast<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
237 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
238 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
239 FD->setInstantiationOfMemberFunction(InstFD, TSK);
240 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
241 break;
242 }
243 case FunctionDecl::TK_FunctionTemplateSpecialization: {
244 FunctionTemplateDecl *Template
245 = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
246 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
247
248 // Template arguments.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000249 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000250 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000251
252 // Template args as written.
253 unsigned NumTemplateArgLocs = Record[Idx++];
254 llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
255 TemplArgLocs.reserve(NumTemplateArgLocs);
256 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
257 TemplArgLocs.push_back(Reader.ReadTemplateArgumentLoc(Record, Idx));
258
259 SourceLocation LAngleLoc, RAngleLoc;
260 if (NumTemplateArgLocs) {
261 LAngleLoc = Reader.ReadSourceLocation(Record, Idx);
262 RAngleLoc = Reader.ReadSourceLocation(Record, Idx);
263 }
264
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000265 FD->setFunctionTemplateSpecialization(Template, TemplArgs.size(),
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000266 TemplArgs.data(), TSK,
267 NumTemplateArgLocs,
268 NumTemplateArgLocs ? TemplArgLocs.data() : 0,
269 LAngleLoc, RAngleLoc);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000270 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000271 }
272 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
273 // Templates.
274 UnresolvedSet<8> TemplDecls;
275 unsigned NumTemplates = Record[Idx++];
276 while (NumTemplates--)
277 TemplDecls.addDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
278
279 // Templates args.
280 TemplateArgumentListInfo TemplArgs;
281 unsigned NumArgs = Record[Idx++];
282 while (NumArgs--)
283 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
284
285 FD->setDependentTemplateSpecialization(*Reader.getContext(),
286 TemplDecls, TemplArgs);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000287 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000288 }
289 }
290
Chris Lattnerca025db2010-05-07 21:43:38 +0000291 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000292 unsigned NumParams = Record[Idx++];
293 llvm::SmallVector<ParmVarDecl *, 16> Params;
294 Params.reserve(NumParams);
295 for (unsigned I = 0; I != NumParams; ++I)
296 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000297 FD->setParams(Params.data(), NumParams);
John McCallb9467b62010-04-24 01:30:58 +0000298
299 // FIXME: order this properly w.r.t. friendness
300 // FIXME: this same thing needs to happen for function templates
301 if (FD->isOverloadedOperator() && !FD->getDeclContext()->isRecord())
302 FD->setNonMemberOperator();
Chris Lattner487412d2009-04-27 05:27:42 +0000303}
304
305void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
306 VisitNamedDecl(MD);
307 if (Record[Idx++]) {
308 // In practice, this won't be executed (since method definitions
309 // don't occur in header files).
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000310 MD->setBody(Reader.ReadStmt());
Chris Lattner487412d2009-04-27 05:27:42 +0000311 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
312 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
313 }
314 MD->setInstanceMethod(Record[Idx++]);
315 MD->setVariadic(Record[Idx++]);
316 MD->setSynthesized(Record[Idx++]);
317 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
318 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahaniand9235db2010-04-08 21:29:11 +0000319 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000320 MD->setResultType(Reader.GetType(Record[Idx++]));
Douglas Gregor12852d92010-03-08 14:59:44 +0000321 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000322 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
323 unsigned NumParams = Record[Idx++];
324 llvm::SmallVector<ParmVarDecl *, 16> Params;
325 Params.reserve(NumParams);
326 for (unsigned I = 0; I != NumParams; ++I)
327 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniancdabb312010-04-09 15:40:42 +0000328 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
329 NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000330}
331
332void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
333 VisitNamedDecl(CD);
Ted Kremenekc7c64312010-01-07 01:20:12 +0000334 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
335 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
336 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner487412d2009-04-27 05:27:42 +0000337}
338
339void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
340 VisitObjCContainerDecl(ID);
341 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
342 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
343 (Reader.GetDecl(Record[Idx++])));
344 unsigned NumProtocols = Record[Idx++];
345 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
346 Protocols.reserve(NumProtocols);
347 for (unsigned I = 0; I != NumProtocols; ++I)
348 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000349 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
350 ProtoLocs.reserve(NumProtocols);
351 for (unsigned I = 0; I != NumProtocols; ++I)
352 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
353 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
354 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000355 unsigned NumIvars = Record[Idx++];
356 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
357 IVars.reserve(NumIvars);
358 for (unsigned I = 0; I != NumIvars; ++I)
359 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000360 ID->setCategoryList(
361 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
362 ID->setForwardDecl(Record[Idx++]);
363 ID->setImplicitInterfaceDecl(Record[Idx++]);
364 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
365 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisea72f422009-07-18 00:33:23 +0000366 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000367}
368
369void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
370 VisitFieldDecl(IVD);
371 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
372}
373
374void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
375 VisitObjCContainerDecl(PD);
376 PD->setForwardDecl(Record[Idx++]);
377 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
378 unsigned NumProtoRefs = Record[Idx++];
379 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
380 ProtoRefs.reserve(NumProtoRefs);
381 for (unsigned I = 0; I != NumProtoRefs; ++I)
382 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000383 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
384 ProtoLocs.reserve(NumProtoRefs);
385 for (unsigned I = 0; I != NumProtoRefs; ++I)
386 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
387 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
388 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000389}
390
391void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
392 VisitFieldDecl(FD);
393}
394
395void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
396 VisitDecl(CD);
397 unsigned NumClassRefs = Record[Idx++];
398 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
399 ClassRefs.reserve(NumClassRefs);
400 for (unsigned I = 0; I != NumClassRefs; ++I)
401 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000402 llvm::SmallVector<SourceLocation, 16> SLocs;
403 SLocs.reserve(NumClassRefs);
404 for (unsigned I = 0; I != NumClassRefs; ++I)
405 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
406 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
407 NumClassRefs);
Chris Lattner487412d2009-04-27 05:27:42 +0000408}
409
410void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
411 VisitDecl(FPD);
412 unsigned NumProtoRefs = Record[Idx++];
413 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
414 ProtoRefs.reserve(NumProtoRefs);
415 for (unsigned I = 0; I != NumProtoRefs; ++I)
416 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000417 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
418 ProtoLocs.reserve(NumProtoRefs);
419 for (unsigned I = 0; I != NumProtoRefs; ++I)
420 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
421 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
422 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000423}
424
425void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
426 VisitObjCContainerDecl(CD);
427 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
428 unsigned NumProtoRefs = Record[Idx++];
429 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
430 ProtoRefs.reserve(NumProtoRefs);
431 for (unsigned I = 0; I != NumProtoRefs; ++I)
432 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000433 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
434 ProtoLocs.reserve(NumProtoRefs);
435 for (unsigned I = 0; I != NumProtoRefs; ++I)
436 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
437 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
438 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000439 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor071676f2010-01-16 16:38:58 +0000440 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
441 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000442}
443
444void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
445 VisitNamedDecl(CAD);
446 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
447}
448
449void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
450 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000451 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall339bb662010-06-04 20:50:08 +0000452 D->setType(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000453 // FIXME: stable encoding
454 D->setPropertyAttributes(
455 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000456 D->setPropertyAttributesAsWritten(
457 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000458 // FIXME: stable encoding
459 D->setPropertyImplementation(
460 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
461 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
462 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
463 D->setGetterMethodDecl(
464 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
465 D->setSetterMethodDecl(
466 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
467 D->setPropertyIvarDecl(
468 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
469}
470
471void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000472 VisitObjCContainerDecl(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000473 D->setClassInterface(
474 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000475}
476
477void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
478 VisitObjCImplDecl(D);
479 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
480}
481
482void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
483 VisitObjCImplDecl(D);
484 D->setSuperClass(
485 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanianc83726e2010-04-28 16:11:27 +0000486 // FIXME. Add reading of IvarInitializers and NumIvarInitializers.
Chris Lattner487412d2009-04-27 05:27:42 +0000487}
488
489
490void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
491 VisitDecl(D);
492 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
493 D->setPropertyDecl(
494 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
495 D->setPropertyIvarDecl(
496 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanian25491a22010-05-05 21:52:17 +0000497 // FIXME. read GetterCXXConstructor and SetterCXXAssignment
Chris Lattner487412d2009-04-27 05:27:42 +0000498}
499
500void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000501 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000502 FD->setMutable(Record[Idx++]);
503 if (Record[Idx++])
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000504 FD->setBitWidth(Reader.ReadExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000505}
506
507void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000508 VisitDeclaratorDecl(VD);
Chris Lattner487412d2009-04-27 05:27:42 +0000509 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
Douglas Gregorc4df4072010-04-19 22:54:31 +0000510 VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000511 VD->setThreadSpecified(Record[Idx++]);
512 VD->setCXXDirectInitializer(Record[Idx++]);
513 VD->setDeclaredInCondition(Record[Idx++]);
Douglas Gregor3f324d562010-05-03 18:51:14 +0000514 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor6fd1b182010-05-15 06:01:05 +0000515 VD->setNRVOVariable(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000516 VD->setPreviousDeclaration(
517 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000518 if (Record[Idx++])
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000519 VD->setInit(Reader.ReadExpr());
Chris Lattner487412d2009-04-27 05:27:42 +0000520}
521
522void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
523 VisitVarDecl(PD);
524}
525
526void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
527 VisitVarDecl(PD);
528 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallf3cd6652010-03-12 18:31:32 +0000529 PD->setHasInheritedDefaultArg(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000530}
531
Chris Lattner487412d2009-04-27 05:27:42 +0000532void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
533 VisitDecl(AD);
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000534 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr()));
Chris Lattner487412d2009-04-27 05:27:42 +0000535}
536
537void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
538 VisitDecl(BD);
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000539 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt()));
John McCalla3ccba02010-06-04 11:21:44 +0000540 BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000541 unsigned NumParams = Record[Idx++];
542 llvm::SmallVector<ParmVarDecl *, 16> Params;
543 Params.reserve(NumParams);
544 for (unsigned I = 0; I != NumParams; ++I)
545 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000546 BD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000547}
548
Chris Lattnerca025db2010-05-07 21:43:38 +0000549void PCHDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
550 VisitDecl(D);
551 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
552 D->setHasBraces(Record[Idx++]);
553}
554
555void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
556 VisitNamedDecl(D);
557 D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx));
558 D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx));
559 D->setNextNamespace(
560 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
561
562 // Only read one reference--the original or anonymous namespace.
563 bool IsOriginal = Record[Idx++];
564 if (IsOriginal)
565 D->setAnonymousNamespace(
566 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
567 else
568 D->setOriginalNamespace(
569 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
570}
571
572void PCHDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
573 VisitNamedDecl(D);
574
575 D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx));
576 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
577 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
578 D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx));
579 D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
580}
581
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000582void PCHDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000583 VisitNamedDecl(D);
584 D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
585 D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
586 D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
587
588 // FIXME: It would probably be more efficient to read these into a vector
589 // and then re-cosntruct the shadow decl set over that vector since it
590 // would avoid existence checks.
591 unsigned NumShadows = Record[Idx++];
592 for(unsigned I = 0; I != NumShadows; ++I) {
593 D->addShadowDecl(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])));
594 }
595 D->setTypeName(Record[Idx++]);
596}
597
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000598void PCHDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000599 VisitNamedDecl(D);
600 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
601 D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
602}
603
604void PCHDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
605 VisitNamedDecl(D);
606 D->setNamespaceKeyLocation(Reader.ReadSourceLocation(Record, Idx));
607 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
608 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
609 D->setIdentLocation(Reader.ReadSourceLocation(Record, Idx));
610 D->setNominatedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
611 D->setCommonAncestor(cast_or_null<DeclContext>(
612 Reader.GetDecl(Record[Idx++])));
613}
614
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000615void PCHDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000616 VisitValueDecl(D);
617 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
618 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
619 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
620}
621
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000622void PCHDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000623 UnresolvedUsingTypenameDecl *D) {
624 VisitTypeDecl(D);
625 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
626 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
627 D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx));
628 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
629}
630
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000631CXXBaseSpecifier PCHDeclReader::ReadCXXBaseSpecifier() {
John McCall1c70e992010-06-03 19:28:45 +0000632 bool isVirtual = static_cast<bool>(Record[Idx++]);
633 bool isBaseOfClass = static_cast<bool>(Record[Idx++]);
634 AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]);
635 QualType T = Reader.GetType(Record[Idx++]);
636 SourceRange Range = Reader.ReadSourceRange(Record, Idx);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000637 return CXXBaseSpecifier(Range, isVirtual, isBaseOfClass, AS, T);
John McCall1c70e992010-06-03 19:28:45 +0000638}
639
Chris Lattnerca025db2010-05-07 21:43:38 +0000640void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000641 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000642
643 ASTContext &C = *Reader.getContext();
644
645 if (D->isFirstDeclaration()) {
646 if (Record[Idx++]) { // DefinitionData != 0
647 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(0);
648 struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData;
649
650 Data.UserDeclaredConstructor = Record[Idx++];
651 Data.UserDeclaredCopyConstructor = Record[Idx++];
652 Data.UserDeclaredCopyAssignment = Record[Idx++];
653 Data.UserDeclaredDestructor = Record[Idx++];
654 Data.Aggregate = Record[Idx++];
655 Data.PlainOldData = Record[Idx++];
656 Data.Empty = Record[Idx++];
657 Data.Polymorphic = Record[Idx++];
658 Data.Abstract = Record[Idx++];
659 Data.HasTrivialConstructor = Record[Idx++];
660 Data.HasTrivialCopyConstructor = Record[Idx++];
661 Data.HasTrivialCopyAssignment = Record[Idx++];
662 Data.HasTrivialDestructor = Record[Idx++];
663 Data.ComputedVisibleConversions = Record[Idx++];
664
665 // setBases() is unsuitable since it may try to iterate the bases of an
666 // unitialized base.
667 Data.NumBases = Record[Idx++];
668 Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases];
669 for (unsigned i = 0; i != Data.NumBases; ++i)
670 Data.Bases[i] = ReadCXXBaseSpecifier();
671
672 // FIXME: Make VBases lazily computed when needed to avoid storing them.
673 Data.NumVBases = Record[Idx++];
674 Data.VBases = new(C) CXXBaseSpecifier [Data.NumVBases];
675 for (unsigned i = 0; i != Data.NumVBases; ++i)
676 Data.VBases[i] = ReadCXXBaseSpecifier();
677
678 Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx);
679 Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx);
680 Data.Definition = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
681 Data.FirstFriend
682 = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
683 }
684 } else {
685 D->DefinitionData = D->getPreviousDeclaration()->DefinitionData;
686 }
687
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000688 enum CXXRecKind {
689 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
690 };
691 switch ((CXXRecKind)Record[Idx++]) {
692 default:
693 assert(false && "Out of sync with PCHDeclWriter::VisitCXXRecordDecl?");
694 case CXXRecNotTemplate:
695 break;
696 case CXXRecTemplate:
697 D->setDescribedClassTemplate(
698 cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++])));
699 break;
700 case CXXRecMemberSpecialization: {
701 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
702 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
703 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
704 D->setInstantiationOfMemberClass(RD, TSK);
705 D->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
706 break;
707 }
708 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000709}
710
711void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
712 // assert(false && "cannot read CXXMethodDecl");
713 VisitFunctionDecl(D);
714}
715
716void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
717 // assert(false && "cannot read CXXConstructorDecl");
718 VisitCXXMethodDecl(D);
719}
720
721void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
722 // assert(false && "cannot read CXXDestructorDecl");
723 VisitCXXMethodDecl(D);
724}
725
726void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
727 // assert(false && "cannot read CXXConversionDecl");
728 VisitCXXMethodDecl(D);
729}
730
Abramo Bagnarad7340582010-06-05 05:09:32 +0000731void PCHDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
732 VisitDecl(D);
733 D->setColonLoc(Reader.ReadSourceLocation(Record, Idx));
734}
735
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000736void PCHDeclReader::VisitFriendDecl(FriendDecl *D) {
737 if (Record[Idx++])
738 D->Friend = Reader.GetTypeSourceInfo(Record, Idx);
739 else
740 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
741 D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
742 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
743}
744
Chris Lattnerca025db2010-05-07 21:43:38 +0000745void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
746 assert(false && "cannot read FriendTemplateDecl");
747}
748
749void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000750 VisitNamedDecl(D);
751
752 NamedDecl *TemplatedDecl = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000753 TemplateParameterList* TemplateParams
754 = Reader.ReadTemplateParameterList(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000755 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +0000756}
757
758void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000759 VisitTemplateDecl(D);
760
761 ClassTemplateDecl *PrevDecl =
762 cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +0000763 D->setPreviousDeclaration(PrevDecl);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000764 if (PrevDecl == 0) {
765 // This ClassTemplateDecl owns a CommonPtr; read it.
766
767 unsigned size = Record[Idx++];
768 while (size--) {
769 ClassTemplateSpecializationDecl *CTSD
770 = cast<ClassTemplateSpecializationDecl>(Reader.GetDecl(Record[Idx++]));
771 llvm::FoldingSetNodeID ID;
772 void *InsertPos = 0;
773 ClassTemplateSpecializationDecl::Profile(ID,
774 CTSD->getTemplateArgs().getFlatArgumentList(),
775 CTSD->getTemplateArgs().flat_size(),
776 *Reader.getContext());
777 D->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
778 D->getSpecializations().InsertNode(CTSD, InsertPos);
779 }
780
781 size = Record[Idx++];
782 while (size--) {
783 ClassTemplatePartialSpecializationDecl *CTSD
784 = cast<ClassTemplatePartialSpecializationDecl>(
785 Reader.GetDecl(Record[Idx++]));
786 llvm::FoldingSetNodeID ID;
787 void *InsertPos = 0;
788 ClassTemplatePartialSpecializationDecl::Profile(ID,
789 CTSD->getTemplateArgs().getFlatArgumentList(),
790 CTSD->getTemplateArgs().flat_size(),
791 *Reader.getContext());
792 D->getPartialSpecializations().FindNodeOrInsertPos(ID, InsertPos);
793 D->getPartialSpecializations().InsertNode(CTSD, InsertPos);
794 }
795
796 // InjectedClassNameType is computed.
797
798 if (ClassTemplateDecl *CTD
799 = cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
800 D->setInstantiatedFromMemberTemplate(CTD);
801 if (Record[Idx++])
802 D->setMemberSpecialization();
803 }
804 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000805}
806
807void PCHDeclReader::VisitClassTemplateSpecializationDecl(
808 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000809 VisitCXXRecordDecl(D);
810
811 if (Decl *InstD = Reader.GetDecl(Record[Idx++])) {
812 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
813 D->setInstantiationOf(CTD);
814 } else {
815 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
816 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
817 D->setInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(InstD),
818 TemplArgs.data(), TemplArgs.size());
819 }
820 }
821
822 // Explicit info.
823 if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Record, Idx)) {
824 D->setTypeAsWritten(TyInfo);
825 D->setExternLoc(Reader.ReadSourceLocation(Record, Idx));
826 D->setTemplateKeywordLoc(Reader.ReadSourceLocation(Record, Idx));
827 }
828
829 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
830 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
831 D->initTemplateArgs(TemplArgs.data(), TemplArgs.size());
832 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
833 if (POI.isValid())
834 D->setPointOfInstantiation(POI);
835 D->setSpecializationKind((TemplateSpecializationKind)Record[Idx++]);
Chris Lattnerca025db2010-05-07 21:43:38 +0000836}
837
838void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl(
839 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000840 VisitClassTemplateSpecializationDecl(D);
841
842 D->initTemplateParameters(Reader.ReadTemplateParameterList(Record, Idx));
843
844 TemplateArgumentListInfo ArgInfos;
845 unsigned NumArgs = Record[Idx++];
846 while (NumArgs--)
847 ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
848 D->initTemplateArgsAsWritten(ArgInfos);
849
850 D->setSequenceNumber(Record[Idx++]);
851
852 // These are read/set from/to the first declaration.
853 if (D->getPreviousDeclaration() == 0) {
854 D->setInstantiatedFromMember(
855 cast_or_null<ClassTemplatePartialSpecializationDecl>(
856 Reader.GetDecl(Record[Idx++])));
857 if (Record[Idx++])
858 D->isMemberSpecialization();
859 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000860}
861
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000862void PCHDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
863 VisitTemplateDecl(D);
864
865 FunctionTemplateDecl *PrevDecl =
866 cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
867 D->setPreviousDeclaration(PrevDecl);
868 if (PrevDecl == 0) {
869 // This FunctionTemplateDecl owns a CommonPtr; read it.
870
871 // FunctionTemplateSpecializationInfos are filled through the
872 // templated FunctionDecl's setFunctionTemplateSpecialization, no need to
873 // read them here.
874
875 if (FunctionTemplateDecl *CTD
876 = cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
877 D->setInstantiatedFromMemberTemplate(CTD);
878 if (Record[Idx++])
879 D->setMemberSpecialization();
880 }
881 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000882}
883
884void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000885 VisitTypeDecl(D);
886
887 D->setDeclaredWithTypename(Record[Idx++]);
888 D->setParameterPack(Record[Idx++]);
889
890 bool Inherited = Record[Idx++];
891 TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Record, Idx);
892 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +0000893}
894
895void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +0000896 VisitVarDecl(D);
897 // TemplateParmPosition.
898 D->setDepth(Record[Idx++]);
899 D->setPosition(Record[Idx++]);
900 // Rest of NonTypeTemplateParmDecl.
901 if (Record[Idx++]) {
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +0000902 Expr *DefArg = Reader.ReadExpr();
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +0000903 bool Inherited = Record[Idx++];
904 D->setDefaultArgument(DefArg, Inherited);
905 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000906}
907
908void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
909 assert(false && "cannot read TemplateTemplateParmDecl");
910}
911
912void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
913 assert(false && "cannot read StaticAssertDecl");
914}
915
Mike Stump11289f42009-09-09 15:08:12 +0000916std::pair<uint64_t, uint64_t>
Chris Lattner487412d2009-04-27 05:27:42 +0000917PCHDeclReader::VisitDeclContext(DeclContext *DC) {
918 uint64_t LexicalOffset = Record[Idx++];
919 uint64_t VisibleOffset = Record[Idx++];
920 return std::make_pair(LexicalOffset, VisibleOffset);
921}
922
923//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +0000924// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +0000925//===----------------------------------------------------------------------===//
926
Chris Lattner8f63ab52009-04-27 06:01:06 +0000927/// \brief Reads attributes from the current stream position.
928Attr *PCHReader::ReadAttributes() {
929 unsigned Code = DeclsCursor.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +0000930 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner8f63ab52009-04-27 06:01:06 +0000931 "Expected unabbreviated record"); (void)Code;
Mike Stump11289f42009-09-09 15:08:12 +0000932
Chris Lattner8f63ab52009-04-27 06:01:06 +0000933 RecordData Record;
934 unsigned Idx = 0;
935 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump11289f42009-09-09 15:08:12 +0000936 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner8f63ab52009-04-27 06:01:06 +0000937 (void)RecCode;
938
939#define SIMPLE_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +0000940 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +0000941 New = ::new (*Context) Name##Attr(); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000942 break
943
944#define STRING_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +0000945 case attr::Name: \
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000946 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000947 break
948
949#define UNSIGNED_ATTR(Name) \
Alexis Hunt344393e2010-06-16 23:43:53 +0000950 case attr::Name: \
Chris Lattner8575daa2009-04-27 21:45:14 +0000951 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner8f63ab52009-04-27 06:01:06 +0000952 break
953
954 Attr *Attrs = 0;
955 while (Idx < Record.size()) {
956 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +0000957 attr::Kind Kind = (attr::Kind)Record[Idx++];
Chris Lattner8f63ab52009-04-27 06:01:06 +0000958 bool IsInherited = Record[Idx++];
959
960 switch (Kind) {
Anton Korobeynikov55bcea12010-01-10 12:58:08 +0000961 default:
962 assert(0 && "Unknown attribute!");
963 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +0000964 STRING_ATTR(Alias);
Daniel Dunbarfc6507e2010-05-27 02:25:39 +0000965 SIMPLE_ATTR(AlignMac68k);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000966 UNSIGNED_ATTR(Aligned);
967 SIMPLE_ATTR(AlwaysInline);
968 SIMPLE_ATTR(AnalyzerNoReturn);
969 STRING_ATTR(Annotate);
970 STRING_ATTR(AsmLabel);
Alexis Hunt54a02542009-11-25 04:20:27 +0000971 SIMPLE_ATTR(BaseCheck);
Mike Stump11289f42009-09-09 15:08:12 +0000972
Alexis Hunt344393e2010-06-16 23:43:53 +0000973 case attr::Blocks:
Chris Lattner8575daa2009-04-27 21:45:14 +0000974 New = ::new (*Context) BlocksAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000975 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
976 break;
Mike Stump11289f42009-09-09 15:08:12 +0000977
Eli Friedmane4310c82009-11-09 18:38:53 +0000978 SIMPLE_ATTR(CDecl);
979
Alexis Hunt344393e2010-06-16 23:43:53 +0000980 case attr::Cleanup:
Chris Lattner8575daa2009-04-27 21:45:14 +0000981 New = ::new (*Context) CleanupAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +0000982 cast<FunctionDecl>(GetDecl(Record[Idx++])));
983 break;
984
985 SIMPLE_ATTR(Const);
986 UNSIGNED_ATTR(Constructor);
987 SIMPLE_ATTR(DLLExport);
988 SIMPLE_ATTR(DLLImport);
989 SIMPLE_ATTR(Deprecated);
990 UNSIGNED_ATTR(Destructor);
991 SIMPLE_ATTR(FastCall);
Alexis Hunt96d5c762009-11-21 08:43:09 +0000992 SIMPLE_ATTR(Final);
Mike Stump11289f42009-09-09 15:08:12 +0000993
Alexis Hunt344393e2010-06-16 23:43:53 +0000994 case attr::Format: {
Chris Lattner8f63ab52009-04-27 06:01:06 +0000995 std::string Type = ReadString(Record, Idx);
996 unsigned FormatIdx = Record[Idx++];
997 unsigned FirstArg = Record[Idx++];
Ted Kremenek7f4945a2010-02-11 05:28:37 +0000998 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner8f63ab52009-04-27 06:01:06 +0000999 break;
1000 }
Mike Stump11289f42009-09-09 15:08:12 +00001001
Alexis Hunt344393e2010-06-16 23:43:53 +00001002 case attr::FormatArg: {
Fariborz Jahanianf1c25022009-05-20 17:41:43 +00001003 unsigned FormatIdx = Record[Idx++];
1004 New = ::new (*Context) FormatArgAttr(FormatIdx);
1005 break;
1006 }
Mike Stump11289f42009-09-09 15:08:12 +00001007
Alexis Hunt344393e2010-06-16 23:43:53 +00001008 case attr::Sentinel: {
Fariborz Jahanian027b8862009-05-13 18:09:35 +00001009 int sentinel = Record[Idx++];
1010 int nullPos = Record[Idx++];
1011 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
1012 break;
1013 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001014
1015 SIMPLE_ATTR(GNUInline);
Alexis Hunt54a02542009-11-25 04:20:27 +00001016 SIMPLE_ATTR(Hiding);
Mike Stump11289f42009-09-09 15:08:12 +00001017
Alexis Hunt344393e2010-06-16 23:43:53 +00001018 case attr::IBAction:
Ted Kremenek06be9682010-02-17 02:37:45 +00001019 New = ::new (*Context) IBActionAttr();
1020 break;
1021
Alexis Hunt344393e2010-06-16 23:43:53 +00001022 case attr::IBOutlet:
Chris Lattner8575daa2009-04-27 21:45:14 +00001023 New = ::new (*Context) IBOutletAttr();
Chris Lattner8f63ab52009-04-27 06:01:06 +00001024 break;
1025
Alexis Hunt344393e2010-06-16 23:43:53 +00001026 case attr::IBOutletCollection: {
Ted Kremenek26bde772010-05-19 17:38:06 +00001027 ObjCInterfaceDecl *D =
1028 cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++]));
1029 New = ::new (*Context) IBOutletCollectionAttr(D);
1030 break;
1031 }
1032
Ryan Flynn1f1fdc02009-08-09 20:07:29 +00001033 SIMPLE_ATTR(Malloc);
Mike Stump3722f582009-08-26 22:31:08 +00001034 SIMPLE_ATTR(NoDebug);
1035 SIMPLE_ATTR(NoInline);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001036 SIMPLE_ATTR(NoReturn);
1037 SIMPLE_ATTR(NoThrow);
Mike Stump11289f42009-09-09 15:08:12 +00001038
Alexis Hunt344393e2010-06-16 23:43:53 +00001039 case attr::NonNull: {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001040 unsigned Size = Record[Idx++];
1041 llvm::SmallVector<unsigned, 16> ArgNums;
1042 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
1043 Idx += Size;
Ted Kremenek510ee252010-02-11 07:31:47 +00001044 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001045 break;
1046 }
Mike Stump11289f42009-09-09 15:08:12 +00001047
Alexis Hunt344393e2010-06-16 23:43:53 +00001048 case attr::ReqdWorkGroupSize: {
Nate Begemanf2758702009-06-26 06:32:41 +00001049 unsigned X = Record[Idx++];
1050 unsigned Y = Record[Idx++];
1051 unsigned Z = Record[Idx++];
1052 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
1053 break;
1054 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001055
1056 SIMPLE_ATTR(ObjCException);
1057 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenekd9c66632010-02-18 00:05:45 +00001058 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +00001059 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenekd9c66632010-02-18 00:05:45 +00001060 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenek9ecdfaf2009-05-09 02:44:38 +00001061 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001062 SIMPLE_ATTR(Overloadable);
Alexis Hunt54a02542009-11-25 04:20:27 +00001063 SIMPLE_ATTR(Override);
Anders Carlsson68e0b682009-08-08 18:23:56 +00001064 SIMPLE_ATTR(Packed);
Daniel Dunbar40130442010-05-27 01:12:46 +00001065 UNSIGNED_ATTR(MaxFieldAlignment);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001066 SIMPLE_ATTR(Pure);
1067 UNSIGNED_ATTR(Regparm);
1068 STRING_ATTR(Section);
1069 SIMPLE_ATTR(StdCall);
Douglas Gregora941dca2010-05-18 16:57:00 +00001070 SIMPLE_ATTR(ThisCall);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001071 SIMPLE_ATTR(TransparentUnion);
1072 SIMPLE_ATTR(Unavailable);
1073 SIMPLE_ATTR(Unused);
1074 SIMPLE_ATTR(Used);
Mike Stump11289f42009-09-09 15:08:12 +00001075
Alexis Hunt344393e2010-06-16 23:43:53 +00001076 case attr::Visibility:
Chris Lattner8575daa2009-04-27 21:45:14 +00001077 New = ::new (*Context) VisibilityAttr(
Chris Lattner8f63ab52009-04-27 06:01:06 +00001078 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
1079 break;
1080
1081 SIMPLE_ATTR(WarnUnusedResult);
1082 SIMPLE_ATTR(Weak);
Rafael Espindolac18086a2010-02-23 22:00:30 +00001083 SIMPLE_ATTR(WeakRef);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001084 SIMPLE_ATTR(WeakImport);
1085 }
1086
1087 assert(New && "Unable to decode attribute?");
1088 New->setInherited(IsInherited);
1089 New->setNext(Attrs);
1090 Attrs = New;
1091 }
1092#undef UNSIGNED_ATTR
1093#undef STRING_ATTR
1094#undef SIMPLE_ATTR
1095
1096 // The list of attributes was built backwards. Reverse the list
1097 // before returning it.
1098 Attr *PrevAttr = 0, *NextAttr = 0;
1099 while (Attrs) {
1100 NextAttr = Attrs->getNext();
1101 Attrs->setNext(PrevAttr);
1102 PrevAttr = Attrs;
1103 Attrs = NextAttr;
1104 }
1105
1106 return PrevAttr;
1107}
1108
1109//===----------------------------------------------------------------------===//
1110// PCHReader Implementation
1111//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001112
1113/// \brief Note that we have loaded the declaration with the given
1114/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001115///
Chris Lattner487412d2009-04-27 05:27:42 +00001116/// This routine notes that this declaration has already been loaded,
1117/// so that future GetDecl calls will return this declaration rather
1118/// than trying to load a new declaration.
1119inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
1120 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1121 DeclsLoaded[Index] = D;
1122}
1123
1124
1125/// \brief Determine whether the consumer will be interested in seeing
1126/// this declaration (via HandleTopLevelDecl).
1127///
1128/// This routine should return true for anything that might affect
1129/// code generation, e.g., inline function definitions, Objective-C
1130/// declarations with metadata, etc.
1131static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001132 if (isa<FileScopeAsmDecl>(D))
1133 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001134 if (VarDecl *Var = dyn_cast<VarDecl>(D))
1135 return Var->isFileVarDecl() && Var->getInit();
1136 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1137 return Func->isThisDeclarationADefinition();
1138 return isa<ObjCProtocolDecl>(D);
1139}
1140
1141/// \brief Read the declaration at the given offset from the PCH file.
1142Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
1143 // Keep track of where we are in the stream, then jump back there
1144 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001145 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001146
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001147 ReadingKindTracker ReadingKind(Read_Decl, *this);
1148
Douglas Gregor1342e842009-07-06 18:54:52 +00001149 // Note that we are loading a declaration record.
1150 LoadingTypeOrDecl Loading(*this);
Mike Stump11289f42009-09-09 15:08:12 +00001151
Chris Lattner1de76db2009-04-27 05:58:23 +00001152 DeclsCursor.JumpToBit(Offset);
Chris Lattner487412d2009-04-27 05:27:42 +00001153 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001154 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001155 unsigned Idx = 0;
1156 PCHDeclReader Reader(*this, Record, Idx);
1157
Chris Lattner1de76db2009-04-27 05:58:23 +00001158 Decl *D = 0;
1159 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner487412d2009-04-27 05:27:42 +00001160 case pch::DECL_ATTR:
1161 case pch::DECL_CONTEXT_LEXICAL:
1162 case pch::DECL_CONTEXT_VISIBLE:
1163 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1164 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001165 case pch::DECL_TRANSLATION_UNIT:
1166 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +00001167 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +00001168 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001169 case pch::DECL_TYPEDEF:
John McCall703a3f82009-10-24 08:00:42 +00001170 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001171 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001172 case pch::DECL_ENUM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001173 D = EnumDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001174 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001175 case pch::DECL_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001176 D = RecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001177 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001178 case pch::DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +00001179 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001180 0, llvm::APSInt());
1181 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001182 case pch::DECL_FUNCTION:
Mike Stump11289f42009-09-09 15:08:12 +00001183 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001184 QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001185 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001186 case pch::DECL_LINKAGE_SPEC:
1187 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
1188 (LinkageSpecDecl::LanguageIDs)0,
1189 false);
1190 break;
1191 case pch::DECL_NAMESPACE:
1192 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
1193 break;
1194 case pch::DECL_NAMESPACE_ALIAS:
1195 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
1196 SourceLocation(), 0, SourceRange(), 0,
1197 SourceLocation(), 0);
1198 break;
1199 case pch::DECL_USING:
1200 D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(),
1201 SourceLocation(), 0, DeclarationName(), false);
1202 break;
1203 case pch::DECL_USING_SHADOW:
1204 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1205 break;
1206 case pch::DECL_USING_DIRECTIVE:
1207 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
1208 SourceLocation(), SourceRange(), 0,
1209 SourceLocation(), 0, 0);
1210 break;
1211 case pch::DECL_UNRESOLVED_USING_VALUE:
1212 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
1213 SourceRange(), 0, SourceLocation(),
1214 DeclarationName());
1215 break;
1216 case pch::DECL_UNRESOLVED_USING_TYPENAME:
1217 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
1218 SourceLocation(), SourceRange(),
1219 0, SourceLocation(),
1220 DeclarationName());
1221 break;
1222 case pch::DECL_CXX_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001223 D = CXXRecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001224 break;
1225 case pch::DECL_CXX_METHOD:
1226 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
1227 QualType(), 0);
1228 break;
1229 case pch::DECL_CXX_CONSTRUCTOR:
1230 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1231 break;
1232 case pch::DECL_CXX_DESTRUCTOR:
1233 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1234 break;
1235 case pch::DECL_CXX_CONVERSION:
1236 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1237 break;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001238 case pch::DECL_ACCESS_SPEC:
1239 D = AccessSpecDecl::Create(*Context, AS_none, 0, SourceLocation(),
1240 SourceLocation());
1241 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001242 case pch::DECL_FRIEND:
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001243 D = FriendDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001244 break;
1245 case pch::DECL_FRIEND_TEMPLATE:
1246 assert(false && "cannot read FriendTemplateDecl");
1247 break;
Chris Lattnerca025db2010-05-07 21:43:38 +00001248 case pch::DECL_CLASS_TEMPLATE:
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +00001249 D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(),
1250 DeclarationName(), 0, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001251 break;
1252 case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001253 D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001254 break;
1255 case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001256 D = ClassTemplatePartialSpecializationDecl::Create(*Context,
1257 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001258 break;
1259 case pch::DECL_FUNCTION_TEMPLATE:
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001260 D = FunctionTemplateDecl::Create(*Context, 0, SourceLocation(),
1261 DeclarationName(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001262 break;
1263 case pch::DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001264 D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001265 break;
1266 case pch::DECL_NON_TYPE_TEMPLATE_PARM:
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001267 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0,
1268 QualType(),0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001269 break;
1270 case pch::DECL_TEMPLATE_TEMPLATE_PARM:
1271 assert(false && "cannot read TemplateTemplateParmDecl");
1272 break;
1273 case pch::DECL_STATIC_ASSERT:
1274 assert(false && "cannot read StaticAssertDecl");
1275 break;
1276
Chris Lattner8f63ab52009-04-27 06:01:06 +00001277 case pch::DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +00001278 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001279 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001280 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001281 case pch::DECL_OBJC_INTERFACE:
Chris Lattner8575daa2009-04-27 21:45:14 +00001282 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001283 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001284 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001285 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001286 ObjCIvarDecl::None);
1287 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001288 case pch::DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001289 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001290 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001291 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001292 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001293 QualType(), 0);
1294 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001295 case pch::DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001296 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001297 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001298 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001299 D = ObjCForwardProtocolDecl::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_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +00001302 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1303 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001304 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001305 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001306 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001307 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001308 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +00001309 D = ObjCImplementationDecl::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_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001312 D = ObjCCompatibleAliasDecl::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_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001315 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001316 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001317 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001318 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001319 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001320 SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001321 ObjCPropertyImplDecl::Dynamic, 0);
1322 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001323 case pch::DECL_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001324 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +00001325 false);
Chris Lattner487412d2009-04-27 05:27:42 +00001326 break;
Chris Lattner487412d2009-04-27 05:27:42 +00001327 case pch::DECL_VAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001328 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001329 VarDecl::None, VarDecl::None);
Chris Lattner487412d2009-04-27 05:27:42 +00001330 break;
1331
1332 case pch::DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001333 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001334 break;
1335
Chris Lattner8f63ab52009-04-27 06:01:06 +00001336 case pch::DECL_PARM_VAR:
Mike Stump11289f42009-09-09 15:08:12 +00001337 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregorc4df4072010-04-19 22:54:31 +00001338 VarDecl::None, VarDecl::None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001339 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001340 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001341 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001342 break;
Chris Lattner8f63ab52009-04-27 06:01:06 +00001343 case pch::DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +00001344 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001345 break;
1346 }
Chris Lattner487412d2009-04-27 05:27:42 +00001347
1348 assert(D && "Unknown declaration reading PCH file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001349 LoadedDecl(Index, D);
1350 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001351
1352 // If this declaration is also a declaration context, get the
1353 // offsets for its tables of lexical and visible declarations.
1354 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1355 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1356 if (Offsets.first || Offsets.second) {
1357 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1358 DC->setHasExternalVisibleStorage(Offsets.second != 0);
1359 DeclContextOffsets[DC] = Offsets;
1360 }
1361 }
1362 assert(Idx == Record.size());
1363
1364 // If we have deserialized a declaration that has a definition the
1365 // AST consumer might need to know about, notify the consumer
1366 // about that definition now or queue it for later.
1367 if (isConsumerInterestedIn(D)) {
1368 if (Consumer) {
1369 DeclGroupRef DG(D);
1370 Consumer->HandleTopLevelDecl(DG);
1371 } else {
1372 InterestingDecls.push_back(D);
1373 }
1374 }
1375
1376 return D;
1377}