blob: 2bdf1662d55aa88b766551d4df850c562edbf369 [file] [log] [blame]
Chris Lattner698f9252009-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 Lattner6ad9ac02010-05-07 21:43:38 +000020#include "clang/AST/DeclCXX.h"
21#include "clang/AST/DeclTemplate.h"
Chris Lattner698f9252009-04-27 05:27:42 +000022#include "clang/AST/Expr.h"
23using namespace clang;
24
Chris Lattner698f9252009-04-27 05:27:42 +000025
26//===----------------------------------------------------------------------===//
27// Declaration deserialization
28//===----------------------------------------------------------------------===//
29
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +000030namespace clang {
Chris Lattner698f9252009-04-27 05:27:42 +000031 class PCHDeclReader : public DeclVisitor<PCHDeclReader, void> {
32 PCHReader &Reader;
33 const PCHReader::RecordData &Record;
34 unsigned &Idx;
35
36 public:
37 PCHDeclReader(PCHReader &Reader, const PCHReader::RecordData &Record,
38 unsigned &Idx)
39 : Reader(Reader), Record(Record), Idx(Idx) { }
40
John McCall5250f272010-06-03 19:28:45 +000041 CXXBaseSpecifier *ReadCXXBaseSpecifier();
42
Chris Lattner698f9252009-04-27 05:27:42 +000043 void VisitDecl(Decl *D);
44 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
45 void VisitNamedDecl(NamedDecl *ND);
Douglas Gregor0cef4832010-02-21 18:22:14 +000046 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000047 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
48 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000049 void VisitTypeDecl(TypeDecl *TD);
50 void VisitTypedefDecl(TypedefDecl *TD);
Argyrios Kyrtzidis8f4eae92010-06-30 08:49:30 +000051 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000052 void VisitTagDecl(TagDecl *TD);
53 void VisitEnumDecl(EnumDecl *ED);
54 void VisitRecordDecl(RecordDecl *RD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000055 void VisitCXXRecordDecl(CXXRecordDecl *D);
56 void VisitClassTemplateSpecializationDecl(
57 ClassTemplateSpecializationDecl *D);
58 void VisitClassTemplatePartialSpecializationDecl(
59 ClassTemplatePartialSpecializationDecl *D);
60 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000061 void VisitValueDecl(ValueDecl *VD);
62 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidis8f4eae92010-06-30 08:49:30 +000063 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +000064 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner698f9252009-04-27 05:27:42 +000065 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000066 void VisitCXXMethodDecl(CXXMethodDecl *D);
67 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
68 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
69 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000070 void VisitFieldDecl(FieldDecl *FD);
71 void VisitVarDecl(VarDecl *VD);
72 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
73 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000074 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
75 void VisitTemplateDecl(TemplateDecl *D);
76 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +000077 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000078 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Argyrios Kyrtzidisb01a5522010-06-20 14:40:59 +000079 void VisitUsingDecl(UsingDecl *D);
80 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000081 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000082 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Abramo Bagnara6206d532010-06-05 05:09:32 +000083 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +000084 void VisitFriendDecl(FriendDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000085 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
86 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000087 void VisitBlockDecl(BlockDecl *BD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000088
Chris Lattner698f9252009-04-27 05:27:42 +000089 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000090
Sean Hunt9a555912010-05-30 07:21:58 +000091 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner698f9252009-04-27 05:27:42 +000092 void VisitObjCMethodDecl(ObjCMethodDecl *D);
93 void VisitObjCContainerDecl(ObjCContainerDecl *D);
94 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
95 void VisitObjCIvarDecl(ObjCIvarDecl *D);
96 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
97 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
98 void VisitObjCClassDecl(ObjCClassDecl *D);
99 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
100 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
101 void VisitObjCImplDecl(ObjCImplDecl *D);
102 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
103 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
104 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
105 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
106 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
107 };
108}
109
110void PCHDeclReader::VisitDecl(Decl *D) {
111 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
112 D->setLexicalDeclContext(
113 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
114 D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
115 D->setInvalidDecl(Record[Idx++]);
116 if (Record[Idx++])
Argyrios Kyrtzidis1715bf52010-06-11 23:09:25 +0000117 D->initAttrs(Reader.ReadAttributes());
Chris Lattner698f9252009-04-27 05:27:42 +0000118 D->setImplicit(Record[Idx++]);
Douglas Gregore0762c92009-06-19 23:52:42 +0000119 D->setUsed(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000120 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor7d1d49d2009-10-16 20:01:17 +0000121 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner698f9252009-04-27 05:27:42 +0000122}
123
124void PCHDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
125 VisitDecl(TU);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000126 TU->setAnonymousNamespace(
127 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000128}
129
130void PCHDeclReader::VisitNamedDecl(NamedDecl *ND) {
131 VisitDecl(ND);
Mike Stump1eb44332009-09-09 15:08:12 +0000132 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000133}
134
135void PCHDeclReader::VisitTypeDecl(TypeDecl *TD) {
136 VisitNamedDecl(TD);
137 TD->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
138}
139
140void PCHDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
141 // Note that we cannot use VisitTypeDecl here, because we need to
142 // set the underlying type of the typedef *before* we try to read
143 // the type associated with the TypedefDecl.
144 VisitNamedDecl(TD);
John McCallba6a9bd2009-10-24 08:00:42 +0000145 uint64_t TypeData = Record[Idx++];
John McCalla93c9342009-12-07 02:54:59 +0000146 TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
John McCallba6a9bd2009-10-24 08:00:42 +0000147 TD->setTypeForDecl(Reader.GetType(TypeData).getTypePtr());
Chris Lattner698f9252009-04-27 05:27:42 +0000148}
149
150void PCHDeclReader::VisitTagDecl(TagDecl *TD) {
151 VisitTypeDecl(TD);
Douglas Gregor8e9e9ef2009-07-29 23:36:44 +0000152 TD->setPreviousDeclaration(
153 cast_or_null<TagDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000154 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
155 TD->setDefinition(Record[Idx++]);
Douglas Gregorb37b6482010-02-12 17:40:34 +0000156 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidisad93a742009-07-14 03:18:02 +0000157 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000158 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCallb6217662010-03-15 10:12:16 +0000159 // FIXME: maybe read optional qualifier and its range.
160 TD->setTypedefForAnonDecl(
161 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000162}
163
164void PCHDeclReader::VisitEnumDecl(EnumDecl *ED) {
165 VisitTagDecl(ED);
166 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall842aef82009-12-09 09:09:27 +0000167 ED->setPromotionType(Reader.GetType(Record[Idx++]));
John McCall1b5a6182010-05-06 08:49:23 +0000168 ED->setNumPositiveBits(Record[Idx++]);
169 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor8dbc3c62009-05-27 17:20:35 +0000170 // FIXME: C++ InstantiatedFrom
Chris Lattner698f9252009-04-27 05:27:42 +0000171}
172
173void PCHDeclReader::VisitRecordDecl(RecordDecl *RD) {
174 VisitTagDecl(RD);
175 RD->setHasFlexibleArrayMember(Record[Idx++]);
176 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian643b7df2009-07-08 16:37:44 +0000177 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000178}
179
180void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {
181 VisitNamedDecl(VD);
182 VD->setType(Reader.GetType(Record[Idx++]));
183}
184
185void PCHDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
186 VisitValueDecl(ECD);
187 if (Record[Idx++])
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000188 ECD->setInitExpr(Reader.ReadExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000189 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
190}
191
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000192void PCHDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
193 VisitValueDecl(DD);
John McCalla93c9342009-12-07 02:54:59 +0000194 TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Record, Idx);
195 if (TInfo)
196 DD->setTypeSourceInfo(TInfo);
John McCallb6217662010-03-15 10:12:16 +0000197 // FIXME: read optional qualifier and its range.
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000198}
199
Chris Lattner698f9252009-04-27 05:27:42 +0000200void PCHDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000201 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000202 if (Record[Idx++])
Chris Lattnerda930612009-04-27 05:58:23 +0000203 FD->setLazyBody(Reader.getDeclsCursor().GetCurrentBitNo());
Chris Lattner698f9252009-04-27 05:27:42 +0000204 FD->setPreviousDeclaration(
205 cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++])));
206 FD->setStorageClass((FunctionDecl::StorageClass)Record[Idx++]);
Douglas Gregor16573fa2010-04-19 22:54:31 +0000207 FD->setStorageClassAsWritten((FunctionDecl::StorageClass)Record[Idx++]);
Douglas Gregor0130f3c2009-10-27 21:01:01 +0000208 FD->setInlineSpecified(Record[Idx++]);
Anders Carlsson77b7f1d2009-05-14 22:15:41 +0000209 FD->setVirtualAsWritten(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000210 FD->setPure(Record[Idx++]);
Anders Carlssona75e8532009-05-14 21:46:00 +0000211 FD->setHasInheritedPrototype(Record[Idx++]);
212 FD->setHasWrittenPrototype(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000213 FD->setDeleted(Record[Idx++]);
Daniel Dunbar7f8b57a2009-09-22 05:38:14 +0000214 FD->setTrivial(Record[Idx++]);
215 FD->setCopyAssignment(Record[Idx++]);
216 FD->setHasImplicitReturnZero(Record[Idx++]);
Argyrios Kyrtzidis8cff90e2009-06-20 08:09:34 +0000217 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000218
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000219 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000220 default: assert(false && "Unhandled TemplatedKind!");
221 break;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000222 case FunctionDecl::TK_NonTemplate:
223 break;
224 case FunctionDecl::TK_FunctionTemplate:
225 FD->setDescribedFunctionTemplate(
226 cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++])));
227 break;
228 case FunctionDecl::TK_MemberSpecialization: {
229 FunctionDecl *InstFD = cast<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
230 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
231 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
232 FD->setInstantiationOfMemberFunction(InstFD, TSK);
233 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
234 break;
235 }
236 case FunctionDecl::TK_FunctionTemplateSpecialization: {
237 FunctionTemplateDecl *Template
238 = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
239 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
240
241 // Template arguments.
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000242 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000243 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000244
245 // Template args as written.
246 unsigned NumTemplateArgLocs = Record[Idx++];
247 llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
248 TemplArgLocs.reserve(NumTemplateArgLocs);
249 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
250 TemplArgLocs.push_back(Reader.ReadTemplateArgumentLoc(Record, Idx));
251
252 SourceLocation LAngleLoc, RAngleLoc;
253 if (NumTemplateArgLocs) {
254 LAngleLoc = Reader.ReadSourceLocation(Record, Idx);
255 RAngleLoc = Reader.ReadSourceLocation(Record, Idx);
256 }
257
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000258 FD->setFunctionTemplateSpecialization(Template, TemplArgs.size(),
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000259 TemplArgs.data(), TSK,
260 NumTemplateArgLocs,
261 NumTemplateArgLocs ? TemplArgLocs.data() : 0,
262 LAngleLoc, RAngleLoc);
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000263 break;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000264 }
265 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
266 // Templates.
267 UnresolvedSet<8> TemplDecls;
268 unsigned NumTemplates = Record[Idx++];
269 while (NumTemplates--)
270 TemplDecls.addDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
271
272 // Templates args.
273 TemplateArgumentListInfo TemplArgs;
274 unsigned NumArgs = Record[Idx++];
275 while (NumArgs--)
276 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
277
278 FD->setDependentTemplateSpecialization(*Reader.getContext(),
279 TemplDecls, TemplArgs);
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000280 break;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000281 }
282 }
283
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000284 // Read in the parameters.
Chris Lattner698f9252009-04-27 05:27:42 +0000285 unsigned NumParams = Record[Idx++];
286 llvm::SmallVector<ParmVarDecl *, 16> Params;
287 Params.reserve(NumParams);
288 for (unsigned I = 0; I != NumParams; ++I)
289 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor838db382010-02-11 01:19:42 +0000290 FD->setParams(Params.data(), NumParams);
John McCall76d32642010-04-24 01:30:58 +0000291
292 // FIXME: order this properly w.r.t. friendness
293 // FIXME: this same thing needs to happen for function templates
294 if (FD->isOverloadedOperator() && !FD->getDeclContext()->isRecord())
295 FD->setNonMemberOperator();
Chris Lattner698f9252009-04-27 05:27:42 +0000296}
297
298void PCHDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
299 VisitNamedDecl(MD);
300 if (Record[Idx++]) {
301 // In practice, this won't be executed (since method definitions
302 // don't occur in header files).
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000303 MD->setBody(Reader.ReadStmt());
Chris Lattner698f9252009-04-27 05:27:42 +0000304 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
305 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
306 }
307 MD->setInstanceMethod(Record[Idx++]);
308 MD->setVariadic(Record[Idx++]);
309 MD->setSynthesized(Record[Idx++]);
310 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
311 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahanian7732cc92010-04-08 21:29:11 +0000312 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000313 MD->setResultType(Reader.GetType(Record[Idx++]));
Douglas Gregor4bc1cb62010-03-08 14:59:44 +0000314 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000315 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
316 unsigned NumParams = Record[Idx++];
317 llvm::SmallVector<ParmVarDecl *, 16> Params;
318 Params.reserve(NumParams);
319 for (unsigned I = 0; I != NumParams; ++I)
320 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanian4ecb25f2010-04-09 15:40:42 +0000321 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
322 NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000323}
324
325void PCHDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
326 VisitNamedDecl(CD);
Ted Kremenek782f2f52010-01-07 01:20:12 +0000327 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
328 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
329 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner698f9252009-04-27 05:27:42 +0000330}
331
332void PCHDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
333 VisitObjCContainerDecl(ID);
334 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
335 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
336 (Reader.GetDecl(Record[Idx++])));
337 unsigned NumProtocols = Record[Idx++];
338 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
339 Protocols.reserve(NumProtocols);
340 for (unsigned I = 0; I != NumProtocols; ++I)
341 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000342 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
343 ProtoLocs.reserve(NumProtocols);
344 for (unsigned I = 0; I != NumProtocols; ++I)
345 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
346 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
347 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000348 unsigned NumIvars = Record[Idx++];
349 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
350 IVars.reserve(NumIvars);
351 for (unsigned I = 0; I != NumIvars; ++I)
352 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000353 ID->setCategoryList(
354 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
355 ID->setForwardDecl(Record[Idx++]);
356 ID->setImplicitInterfaceDecl(Record[Idx++]);
357 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
358 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisc999f1f2009-07-18 00:33:23 +0000359 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000360}
361
362void PCHDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
363 VisitFieldDecl(IVD);
364 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
365}
366
367void PCHDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
368 VisitObjCContainerDecl(PD);
369 PD->setForwardDecl(Record[Idx++]);
370 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
371 unsigned NumProtoRefs = Record[Idx++];
372 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
373 ProtoRefs.reserve(NumProtoRefs);
374 for (unsigned I = 0; I != NumProtoRefs; ++I)
375 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000376 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
377 ProtoLocs.reserve(NumProtoRefs);
378 for (unsigned I = 0; I != NumProtoRefs; ++I)
379 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
380 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
381 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000382}
383
384void PCHDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
385 VisitFieldDecl(FD);
386}
387
388void PCHDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
389 VisitDecl(CD);
390 unsigned NumClassRefs = Record[Idx++];
391 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
392 ClassRefs.reserve(NumClassRefs);
393 for (unsigned I = 0; I != NumClassRefs; ++I)
394 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek321c22f2009-11-18 00:28:11 +0000395 llvm::SmallVector<SourceLocation, 16> SLocs;
396 SLocs.reserve(NumClassRefs);
397 for (unsigned I = 0; I != NumClassRefs; ++I)
398 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
399 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
400 NumClassRefs);
Chris Lattner698f9252009-04-27 05:27:42 +0000401}
402
403void PCHDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
404 VisitDecl(FPD);
405 unsigned NumProtoRefs = Record[Idx++];
406 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
407 ProtoRefs.reserve(NumProtoRefs);
408 for (unsigned I = 0; I != NumProtoRefs; ++I)
409 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000410 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
411 ProtoLocs.reserve(NumProtoRefs);
412 for (unsigned I = 0; I != NumProtoRefs; ++I)
413 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
414 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
415 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000416}
417
418void PCHDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
419 VisitObjCContainerDecl(CD);
420 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
421 unsigned NumProtoRefs = Record[Idx++];
422 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
423 ProtoRefs.reserve(NumProtoRefs);
424 for (unsigned I = 0; I != NumProtoRefs; ++I)
425 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000426 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
427 ProtoLocs.reserve(NumProtoRefs);
428 for (unsigned I = 0; I != NumProtoRefs; ++I)
429 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
430 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
431 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000432 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor3db211b2010-01-16 16:38:58 +0000433 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
434 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000435}
436
437void PCHDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
438 VisitNamedDecl(CAD);
439 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
440}
441
442void PCHDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
443 VisitNamedDecl(D);
Fariborz Jahaniand0502402010-01-21 17:36:00 +0000444 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall83a230c2010-06-04 20:50:08 +0000445 D->setType(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000446 // FIXME: stable encoding
447 D->setPropertyAttributes(
448 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000449 D->setPropertyAttributesAsWritten(
450 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000451 // FIXME: stable encoding
452 D->setPropertyImplementation(
453 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
454 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
455 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
456 D->setGetterMethodDecl(
457 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
458 D->setSetterMethodDecl(
459 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
460 D->setPropertyIvarDecl(
461 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
462}
463
464void PCHDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidisaecae622009-07-27 19:04:32 +0000465 VisitObjCContainerDecl(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000466 D->setClassInterface(
467 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000468}
469
470void PCHDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
471 VisitObjCImplDecl(D);
472 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
473}
474
475void PCHDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
476 VisitObjCImplDecl(D);
477 D->setSuperClass(
478 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniane4498c62010-04-28 16:11:27 +0000479 // FIXME. Add reading of IvarInitializers and NumIvarInitializers.
Chris Lattner698f9252009-04-27 05:27:42 +0000480}
481
482
483void PCHDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
484 VisitDecl(D);
485 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
486 D->setPropertyDecl(
487 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
488 D->setPropertyIvarDecl(
489 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanian17cb3262010-05-05 21:52:17 +0000490 // FIXME. read GetterCXXConstructor and SetterCXXAssignment
Chris Lattner698f9252009-04-27 05:27:42 +0000491}
492
493void PCHDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000494 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000495 FD->setMutable(Record[Idx++]);
496 if (Record[Idx++])
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000497 FD->setBitWidth(Reader.ReadExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000498}
499
500void PCHDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000501 VisitDeclaratorDecl(VD);
Chris Lattner698f9252009-04-27 05:27:42 +0000502 VD->setStorageClass((VarDecl::StorageClass)Record[Idx++]);
Douglas Gregor16573fa2010-04-19 22:54:31 +0000503 VD->setStorageClassAsWritten((VarDecl::StorageClass)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000504 VD->setThreadSpecified(Record[Idx++]);
505 VD->setCXXDirectInitializer(Record[Idx++]);
506 VD->setDeclaredInCondition(Record[Idx++]);
Douglas Gregor324b54d2010-05-03 18:51:14 +0000507 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor5077c382010-05-15 06:01:05 +0000508 VD->setNRVOVariable(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000509 VD->setPreviousDeclaration(
510 cast_or_null<VarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000511 if (Record[Idx++])
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000512 VD->setInit(Reader.ReadExpr());
Chris Lattner698f9252009-04-27 05:27:42 +0000513}
514
515void PCHDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
516 VisitVarDecl(PD);
517}
518
519void PCHDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
520 VisitVarDecl(PD);
521 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallbf73b352010-03-12 18:31:32 +0000522 PD->setHasInheritedDefaultArg(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000523}
524
Chris Lattner698f9252009-04-27 05:27:42 +0000525void PCHDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
526 VisitDecl(AD);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000527 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr()));
Chris Lattner698f9252009-04-27 05:27:42 +0000528}
529
530void PCHDeclReader::VisitBlockDecl(BlockDecl *BD) {
531 VisitDecl(BD);
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000532 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt()));
John McCall82dc0092010-06-04 11:21:44 +0000533 BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000534 unsigned NumParams = Record[Idx++];
535 llvm::SmallVector<ParmVarDecl *, 16> Params;
536 Params.reserve(NumParams);
537 for (unsigned I = 0; I != NumParams; ++I)
538 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor838db382010-02-11 01:19:42 +0000539 BD->setParams(Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000540}
541
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000542void PCHDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
543 VisitDecl(D);
544 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
545 D->setHasBraces(Record[Idx++]);
546}
547
548void PCHDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
549 VisitNamedDecl(D);
550 D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx));
551 D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx));
552 D->setNextNamespace(
553 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
554
555 // Only read one reference--the original or anonymous namespace.
556 bool IsOriginal = Record[Idx++];
557 if (IsOriginal)
558 D->setAnonymousNamespace(
559 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
560 else
561 D->setOriginalNamespace(
562 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
563}
564
565void PCHDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
566 VisitNamedDecl(D);
567
568 D->setAliasLoc(Reader.ReadSourceLocation(Record, Idx));
569 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
570 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
571 D->setTargetNameLoc(Reader.ReadSourceLocation(Record, Idx));
572 D->setAliasedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
573}
574
Argyrios Kyrtzidisb01a5522010-06-20 14:40:59 +0000575void PCHDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000576 VisitNamedDecl(D);
577 D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
578 D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
579 D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
580
581 // FIXME: It would probably be more efficient to read these into a vector
582 // and then re-cosntruct the shadow decl set over that vector since it
583 // would avoid existence checks.
584 unsigned NumShadows = Record[Idx++];
585 for(unsigned I = 0; I != NumShadows; ++I) {
586 D->addShadowDecl(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])));
587 }
588 D->setTypeName(Record[Idx++]);
589}
590
Argyrios Kyrtzidisb01a5522010-06-20 14:40:59 +0000591void PCHDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000592 VisitNamedDecl(D);
593 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
594 D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
595}
596
597void PCHDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
598 VisitNamedDecl(D);
599 D->setNamespaceKeyLocation(Reader.ReadSourceLocation(Record, Idx));
600 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
601 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
602 D->setIdentLocation(Reader.ReadSourceLocation(Record, Idx));
603 D->setNominatedNamespace(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
604 D->setCommonAncestor(cast_or_null<DeclContext>(
605 Reader.GetDecl(Record[Idx++])));
606}
607
Argyrios Kyrtzidis8f4eae92010-06-30 08:49:30 +0000608void PCHDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000609 VisitValueDecl(D);
610 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
611 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
612 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
613}
614
Argyrios Kyrtzidis8f4eae92010-06-30 08:49:30 +0000615void PCHDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000616 UnresolvedUsingTypenameDecl *D) {
617 VisitTypeDecl(D);
618 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
619 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
620 D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx));
621 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
622}
623
John McCall5250f272010-06-03 19:28:45 +0000624CXXBaseSpecifier *PCHDeclReader::ReadCXXBaseSpecifier() {
625 bool isVirtual = static_cast<bool>(Record[Idx++]);
626 bool isBaseOfClass = static_cast<bool>(Record[Idx++]);
627 AccessSpecifier AS = static_cast<AccessSpecifier>(Record[Idx++]);
628 QualType T = Reader.GetType(Record[Idx++]);
629 SourceRange Range = Reader.ReadSourceRange(Record, Idx);
630 return new (*Reader.getContext())
631 CXXBaseSpecifier(Range, isVirtual, isBaseOfClass, AS, T);
632}
633
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000634void PCHDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
635 // assert(false && "cannot read CXXRecordDecl");
636 VisitRecordDecl(D);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000637
638 enum CXXRecKind {
639 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
640 };
641 switch ((CXXRecKind)Record[Idx++]) {
642 default:
643 assert(false && "Out of sync with PCHDeclWriter::VisitCXXRecordDecl?");
644 case CXXRecNotTemplate:
645 break;
646 case CXXRecTemplate:
647 D->setDescribedClassTemplate(
648 cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++])));
649 break;
650 case CXXRecMemberSpecialization: {
651 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
652 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
653 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
654 D->setInstantiationOfMemberClass(RD, TSK);
655 D->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
656 break;
657 }
658 }
John McCall5250f272010-06-03 19:28:45 +0000659
Argyrios Kyrtzidis28d16d72010-06-19 19:29:21 +0000660 // FIXME: Hack. See PCHDeclWriter::VisitTypeDecl.
661 D->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
662
John McCall5250f272010-06-03 19:28:45 +0000663 // FIXME: this is far from complete
664
665 if (D->isDefinition()) {
666 D->setDefinition(false); // make peace with an assertion
667 D->startDefinition();
668
669 unsigned NumBases = Record[Idx++];
670
671 llvm::SmallVector<CXXBaseSpecifier*, 4> Bases;
672 Bases.reserve(NumBases);
673 for (unsigned I = 0; I != NumBases; ++I)
674 Bases.push_back(ReadCXXBaseSpecifier());
675 D->setBases(Bases.begin(), NumBases);
676
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +0000677 D->data().FirstFriend
678 = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
679
John McCall5250f272010-06-03 19:28:45 +0000680 // FIXME: there's a lot of stuff we do here that's kindof sketchy
681 // if we're leaving the context incomplete.
682 D->completeDefinition();
683 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000684}
685
686void PCHDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
687 // assert(false && "cannot read CXXMethodDecl");
688 VisitFunctionDecl(D);
689}
690
691void PCHDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
692 // assert(false && "cannot read CXXConstructorDecl");
693 VisitCXXMethodDecl(D);
694}
695
696void PCHDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
697 // assert(false && "cannot read CXXDestructorDecl");
698 VisitCXXMethodDecl(D);
699}
700
701void PCHDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
702 // assert(false && "cannot read CXXConversionDecl");
703 VisitCXXMethodDecl(D);
704}
705
Abramo Bagnara6206d532010-06-05 05:09:32 +0000706void PCHDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
707 VisitDecl(D);
708 D->setColonLoc(Reader.ReadSourceLocation(Record, Idx));
709}
710
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +0000711void PCHDeclReader::VisitFriendDecl(FriendDecl *D) {
712 if (Record[Idx++])
713 D->Friend = Reader.GetTypeSourceInfo(Record, Idx);
714 else
715 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
716 D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
717 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
718}
719
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000720void PCHDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
721 assert(false && "cannot read FriendTemplateDecl");
722}
723
724void PCHDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000725 VisitNamedDecl(D);
726
727 NamedDecl *TemplatedDecl = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000728 TemplateParameterList* TemplateParams
729 = Reader.ReadTemplateParameterList(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000730 D->init(TemplatedDecl, TemplateParams);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000731}
732
733void PCHDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000734 VisitTemplateDecl(D);
735
736 ClassTemplateDecl *PrevDecl =
737 cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis5bf1bdc2010-06-21 10:57:41 +0000738 D->setPreviousDeclaration(PrevDecl);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000739 if (PrevDecl == 0) {
740 // This ClassTemplateDecl owns a CommonPtr; read it.
741
742 unsigned size = Record[Idx++];
743 while (size--) {
744 ClassTemplateSpecializationDecl *CTSD
745 = cast<ClassTemplateSpecializationDecl>(Reader.GetDecl(Record[Idx++]));
746 llvm::FoldingSetNodeID ID;
747 void *InsertPos = 0;
748 ClassTemplateSpecializationDecl::Profile(ID,
749 CTSD->getTemplateArgs().getFlatArgumentList(),
750 CTSD->getTemplateArgs().flat_size(),
751 *Reader.getContext());
752 D->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
753 D->getSpecializations().InsertNode(CTSD, InsertPos);
754 }
755
756 size = Record[Idx++];
757 while (size--) {
758 ClassTemplatePartialSpecializationDecl *CTSD
759 = cast<ClassTemplatePartialSpecializationDecl>(
760 Reader.GetDecl(Record[Idx++]));
761 llvm::FoldingSetNodeID ID;
762 void *InsertPos = 0;
763 ClassTemplatePartialSpecializationDecl::Profile(ID,
764 CTSD->getTemplateArgs().getFlatArgumentList(),
765 CTSD->getTemplateArgs().flat_size(),
766 *Reader.getContext());
767 D->getPartialSpecializations().FindNodeOrInsertPos(ID, InsertPos);
768 D->getPartialSpecializations().InsertNode(CTSD, InsertPos);
769 }
770
771 // InjectedClassNameType is computed.
772
773 if (ClassTemplateDecl *CTD
774 = cast_or_null<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
775 D->setInstantiatedFromMemberTemplate(CTD);
776 if (Record[Idx++])
777 D->setMemberSpecialization();
778 }
779 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000780}
781
782void PCHDeclReader::VisitClassTemplateSpecializationDecl(
783 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000784 VisitCXXRecordDecl(D);
785
786 if (Decl *InstD = Reader.GetDecl(Record[Idx++])) {
787 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
788 D->setInstantiationOf(CTD);
789 } else {
790 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
791 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
792 D->setInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(InstD),
793 TemplArgs.data(), TemplArgs.size());
794 }
795 }
796
797 // Explicit info.
798 if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Record, Idx)) {
799 D->setTypeAsWritten(TyInfo);
800 D->setExternLoc(Reader.ReadSourceLocation(Record, Idx));
801 D->setTemplateKeywordLoc(Reader.ReadSourceLocation(Record, Idx));
802 }
803
804 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
805 Reader.ReadTemplateArgumentList(TemplArgs, Record, Idx);
806 D->initTemplateArgs(TemplArgs.data(), TemplArgs.size());
807 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
808 if (POI.isValid())
809 D->setPointOfInstantiation(POI);
810 D->setSpecializationKind((TemplateSpecializationKind)Record[Idx++]);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000811}
812
813void PCHDeclReader::VisitClassTemplatePartialSpecializationDecl(
814 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000815 VisitClassTemplateSpecializationDecl(D);
816
817 D->initTemplateParameters(Reader.ReadTemplateParameterList(Record, Idx));
818
819 TemplateArgumentListInfo ArgInfos;
820 unsigned NumArgs = Record[Idx++];
821 while (NumArgs--)
822 ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Record, Idx));
823 D->initTemplateArgsAsWritten(ArgInfos);
824
825 D->setSequenceNumber(Record[Idx++]);
826
827 // These are read/set from/to the first declaration.
828 if (D->getPreviousDeclaration() == 0) {
829 D->setInstantiatedFromMember(
830 cast_or_null<ClassTemplatePartialSpecializationDecl>(
831 Reader.GetDecl(Record[Idx++])));
832 if (Record[Idx++])
833 D->isMemberSpecialization();
834 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000835}
836
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000837void PCHDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
838 VisitTemplateDecl(D);
839
840 FunctionTemplateDecl *PrevDecl =
841 cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
842 D->setPreviousDeclaration(PrevDecl);
843 if (PrevDecl == 0) {
844 // This FunctionTemplateDecl owns a CommonPtr; read it.
845
846 // FunctionTemplateSpecializationInfos are filled through the
847 // templated FunctionDecl's setFunctionTemplateSpecialization, no need to
848 // read them here.
849
850 if (FunctionTemplateDecl *CTD
851 = cast_or_null<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
852 D->setInstantiatedFromMemberTemplate(CTD);
853 if (Record[Idx++])
854 D->setMemberSpecialization();
855 }
856 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000857}
858
859void PCHDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000860 VisitTypeDecl(D);
861
862 D->setDeclaredWithTypename(Record[Idx++]);
863 D->setParameterPack(Record[Idx++]);
864
865 bool Inherited = Record[Idx++];
866 TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Record, Idx);
867 D->setDefaultArgument(DefArg, Inherited);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000868}
869
870void PCHDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Argyrios Kyrtzidisb24e1992010-06-25 16:25:09 +0000871 VisitVarDecl(D);
872 // TemplateParmPosition.
873 D->setDepth(Record[Idx++]);
874 D->setPosition(Record[Idx++]);
875 // Rest of NonTypeTemplateParmDecl.
876 if (Record[Idx++]) {
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +0000877 Expr *DefArg = Reader.ReadExpr();
Argyrios Kyrtzidisb24e1992010-06-25 16:25:09 +0000878 bool Inherited = Record[Idx++];
879 D->setDefaultArgument(DefArg, Inherited);
880 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000881}
882
883void PCHDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
884 assert(false && "cannot read TemplateTemplateParmDecl");
885}
886
887void PCHDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
888 assert(false && "cannot read StaticAssertDecl");
889}
890
Mike Stump1eb44332009-09-09 15:08:12 +0000891std::pair<uint64_t, uint64_t>
Chris Lattner698f9252009-04-27 05:27:42 +0000892PCHDeclReader::VisitDeclContext(DeclContext *DC) {
893 uint64_t LexicalOffset = Record[Idx++];
894 uint64_t VisibleOffset = Record[Idx++];
895 return std::make_pair(LexicalOffset, VisibleOffset);
896}
897
898//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000899// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +0000900//===----------------------------------------------------------------------===//
901
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000902/// \brief Reads attributes from the current stream position.
903Attr *PCHReader::ReadAttributes() {
904 unsigned Code = DeclsCursor.ReadCode();
Mike Stump1eb44332009-09-09 15:08:12 +0000905 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000906 "Expected unabbreviated record"); (void)Code;
Mike Stump1eb44332009-09-09 15:08:12 +0000907
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000908 RecordData Record;
909 unsigned Idx = 0;
910 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Mike Stump1eb44332009-09-09 15:08:12 +0000911 assert(RecCode == pch::DECL_ATTR && "Expected attribute record");
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000912 (void)RecCode;
913
914#define SIMPLE_ATTR(Name) \
Sean Hunt387475d2010-06-16 23:43:53 +0000915 case attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000916 New = ::new (*Context) Name##Attr(); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000917 break
918
919#define STRING_ATTR(Name) \
Sean Hunt387475d2010-06-16 23:43:53 +0000920 case attr::Name: \
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000921 New = ::new (*Context) Name##Attr(*Context, ReadString(Record, Idx)); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000922 break
923
924#define UNSIGNED_ATTR(Name) \
Sean Hunt387475d2010-06-16 23:43:53 +0000925 case attr::Name: \
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000926 New = ::new (*Context) Name##Attr(Record[Idx++]); \
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000927 break
928
929 Attr *Attrs = 0;
930 while (Idx < Record.size()) {
931 Attr *New = 0;
Sean Hunt387475d2010-06-16 23:43:53 +0000932 attr::Kind Kind = (attr::Kind)Record[Idx++];
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000933 bool IsInherited = Record[Idx++];
934
935 switch (Kind) {
Anton Korobeynikov82d0a412010-01-10 12:58:08 +0000936 default:
937 assert(0 && "Unknown attribute!");
938 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000939 STRING_ATTR(Alias);
Daniel Dunbar4e9255f2010-05-27 02:25:39 +0000940 SIMPLE_ATTR(AlignMac68k);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000941 UNSIGNED_ATTR(Aligned);
942 SIMPLE_ATTR(AlwaysInline);
943 SIMPLE_ATTR(AnalyzerNoReturn);
944 STRING_ATTR(Annotate);
945 STRING_ATTR(AsmLabel);
Sean Hunt7725e672009-11-25 04:20:27 +0000946 SIMPLE_ATTR(BaseCheck);
Mike Stump1eb44332009-09-09 15:08:12 +0000947
Sean Hunt387475d2010-06-16 23:43:53 +0000948 case attr::Blocks:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000949 New = ::new (*Context) BlocksAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000950 (BlocksAttr::BlocksAttrTypes)Record[Idx++]);
951 break;
Mike Stump1eb44332009-09-09 15:08:12 +0000952
Eli Friedman8f4c59e2009-11-09 18:38:53 +0000953 SIMPLE_ATTR(CDecl);
954
Sean Hunt387475d2010-06-16 23:43:53 +0000955 case attr::Cleanup:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000956 New = ::new (*Context) CleanupAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000957 cast<FunctionDecl>(GetDecl(Record[Idx++])));
958 break;
959
960 SIMPLE_ATTR(Const);
961 UNSIGNED_ATTR(Constructor);
962 SIMPLE_ATTR(DLLExport);
963 SIMPLE_ATTR(DLLImport);
964 SIMPLE_ATTR(Deprecated);
965 UNSIGNED_ATTR(Destructor);
966 SIMPLE_ATTR(FastCall);
Sean Huntbbd37c62009-11-21 08:43:09 +0000967 SIMPLE_ATTR(Final);
Mike Stump1eb44332009-09-09 15:08:12 +0000968
Sean Hunt387475d2010-06-16 23:43:53 +0000969 case attr::Format: {
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000970 std::string Type = ReadString(Record, Idx);
971 unsigned FormatIdx = Record[Idx++];
972 unsigned FirstArg = Record[Idx++];
Ted Kremenek3d2c43e2010-02-11 05:28:37 +0000973 New = ::new (*Context) FormatAttr(*Context, Type, FormatIdx, FirstArg);
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000974 break;
975 }
Mike Stump1eb44332009-09-09 15:08:12 +0000976
Sean Hunt387475d2010-06-16 23:43:53 +0000977 case attr::FormatArg: {
Fariborz Jahanian5b160922009-05-20 17:41:43 +0000978 unsigned FormatIdx = Record[Idx++];
979 New = ::new (*Context) FormatArgAttr(FormatIdx);
980 break;
981 }
Mike Stump1eb44332009-09-09 15:08:12 +0000982
Sean Hunt387475d2010-06-16 23:43:53 +0000983 case attr::Sentinel: {
Fariborz Jahanian5b530052009-05-13 18:09:35 +0000984 int sentinel = Record[Idx++];
985 int nullPos = Record[Idx++];
986 New = ::new (*Context) SentinelAttr(sentinel, nullPos);
987 break;
988 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000989
990 SIMPLE_ATTR(GNUInline);
Sean Hunt7725e672009-11-25 04:20:27 +0000991 SIMPLE_ATTR(Hiding);
Mike Stump1eb44332009-09-09 15:08:12 +0000992
Sean Hunt387475d2010-06-16 23:43:53 +0000993 case attr::IBAction:
Ted Kremenekefbddd22010-02-17 02:37:45 +0000994 New = ::new (*Context) IBActionAttr();
995 break;
996
Sean Hunt387475d2010-06-16 23:43:53 +0000997 case attr::IBOutlet:
Chris Lattnerd1d64a02009-04-27 21:45:14 +0000998 New = ::new (*Context) IBOutletAttr();
Chris Lattner4e3fcc82009-04-27 06:01:06 +0000999 break;
1000
Sean Hunt387475d2010-06-16 23:43:53 +00001001 case attr::IBOutletCollection: {
Ted Kremenek857e9182010-05-19 17:38:06 +00001002 ObjCInterfaceDecl *D =
1003 cast_or_null<ObjCInterfaceDecl>(GetDecl(Record[Idx++]));
1004 New = ::new (*Context) IBOutletCollectionAttr(D);
1005 break;
1006 }
1007
Ryan Flynn76168e22009-08-09 20:07:29 +00001008 SIMPLE_ATTR(Malloc);
Mike Stump1feade82009-08-26 22:31:08 +00001009 SIMPLE_ATTR(NoDebug);
1010 SIMPLE_ATTR(NoInline);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001011 SIMPLE_ATTR(NoReturn);
1012 SIMPLE_ATTR(NoThrow);
Mike Stump1eb44332009-09-09 15:08:12 +00001013
Sean Hunt387475d2010-06-16 23:43:53 +00001014 case attr::NonNull: {
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001015 unsigned Size = Record[Idx++];
1016 llvm::SmallVector<unsigned, 16> ArgNums;
1017 ArgNums.insert(ArgNums.end(), &Record[Idx], &Record[Idx] + Size);
1018 Idx += Size;
Ted Kremenek59616112010-02-11 07:31:47 +00001019 New = ::new (*Context) NonNullAttr(*Context, ArgNums.data(), Size);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001020 break;
1021 }
Mike Stump1eb44332009-09-09 15:08:12 +00001022
Sean Hunt387475d2010-06-16 23:43:53 +00001023 case attr::ReqdWorkGroupSize: {
Nate Begeman6f3d8382009-06-26 06:32:41 +00001024 unsigned X = Record[Idx++];
1025 unsigned Y = Record[Idx++];
1026 unsigned Z = Record[Idx++];
1027 New = ::new (*Context) ReqdWorkGroupSizeAttr(X, Y, Z);
1028 break;
1029 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001030
1031 SIMPLE_ATTR(ObjCException);
1032 SIMPLE_ATTR(ObjCNSObject);
Ted Kremenek31c780d2010-02-18 00:05:45 +00001033 SIMPLE_ATTR(CFReturnsNotRetained);
Ted Kremenekb71368d2009-05-09 02:44:38 +00001034 SIMPLE_ATTR(CFReturnsRetained);
Ted Kremenek31c780d2010-02-18 00:05:45 +00001035 SIMPLE_ATTR(NSReturnsNotRetained);
Ted Kremenekb71368d2009-05-09 02:44:38 +00001036 SIMPLE_ATTR(NSReturnsRetained);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001037 SIMPLE_ATTR(Overloadable);
Sean Hunt7725e672009-11-25 04:20:27 +00001038 SIMPLE_ATTR(Override);
Anders Carlssona860e752009-08-08 18:23:56 +00001039 SIMPLE_ATTR(Packed);
Daniel Dunbar8a2c92c2010-05-27 01:12:46 +00001040 UNSIGNED_ATTR(MaxFieldAlignment);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001041 SIMPLE_ATTR(Pure);
1042 UNSIGNED_ATTR(Regparm);
1043 STRING_ATTR(Section);
1044 SIMPLE_ATTR(StdCall);
Douglas Gregorf813a2c2010-05-18 16:57:00 +00001045 SIMPLE_ATTR(ThisCall);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001046 SIMPLE_ATTR(TransparentUnion);
1047 SIMPLE_ATTR(Unavailable);
1048 SIMPLE_ATTR(Unused);
1049 SIMPLE_ATTR(Used);
Mike Stump1eb44332009-09-09 15:08:12 +00001050
Sean Hunt387475d2010-06-16 23:43:53 +00001051 case attr::Visibility:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001052 New = ::new (*Context) VisibilityAttr(
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001053 (VisibilityAttr::VisibilityTypes)Record[Idx++]);
1054 break;
1055
1056 SIMPLE_ATTR(WarnUnusedResult);
1057 SIMPLE_ATTR(Weak);
Rafael Espindola11e8ce72010-02-23 22:00:30 +00001058 SIMPLE_ATTR(WeakRef);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001059 SIMPLE_ATTR(WeakImport);
1060 }
1061
1062 assert(New && "Unable to decode attribute?");
1063 New->setInherited(IsInherited);
1064 New->setNext(Attrs);
1065 Attrs = New;
1066 }
1067#undef UNSIGNED_ATTR
1068#undef STRING_ATTR
1069#undef SIMPLE_ATTR
1070
1071 // The list of attributes was built backwards. Reverse the list
1072 // before returning it.
1073 Attr *PrevAttr = 0, *NextAttr = 0;
1074 while (Attrs) {
1075 NextAttr = Attrs->getNext();
1076 Attrs->setNext(PrevAttr);
1077 PrevAttr = Attrs;
1078 Attrs = NextAttr;
1079 }
1080
1081 return PrevAttr;
1082}
1083
1084//===----------------------------------------------------------------------===//
1085// PCHReader Implementation
1086//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +00001087
1088/// \brief Note that we have loaded the declaration with the given
1089/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +00001090///
Chris Lattner698f9252009-04-27 05:27:42 +00001091/// This routine notes that this declaration has already been loaded,
1092/// so that future GetDecl calls will return this declaration rather
1093/// than trying to load a new declaration.
1094inline void PCHReader::LoadedDecl(unsigned Index, Decl *D) {
1095 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1096 DeclsLoaded[Index] = D;
1097}
1098
1099
1100/// \brief Determine whether the consumer will be interested in seeing
1101/// this declaration (via HandleTopLevelDecl).
1102///
1103/// This routine should return true for anything that might affect
1104/// code generation, e.g., inline function definitions, Objective-C
1105/// declarations with metadata, etc.
1106static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar04a0b502009-09-17 03:06:44 +00001107 if (isa<FileScopeAsmDecl>(D))
1108 return true;
Chris Lattner698f9252009-04-27 05:27:42 +00001109 if (VarDecl *Var = dyn_cast<VarDecl>(D))
1110 return Var->isFileVarDecl() && Var->getInit();
1111 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1112 return Func->isThisDeclarationADefinition();
1113 return isa<ObjCProtocolDecl>(D);
1114}
1115
1116/// \brief Read the declaration at the given offset from the PCH file.
1117Decl *PCHReader::ReadDeclRecord(uint64_t Offset, unsigned Index) {
1118 // Keep track of where we are in the stream, then jump back there
1119 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +00001120 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +00001121
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001122 ReadingKindTracker ReadingKind(Read_Decl, *this);
1123
Douglas Gregord89275b2009-07-06 18:54:52 +00001124 // Note that we are loading a declaration record.
1125 LoadingTypeOrDecl Loading(*this);
Mike Stump1eb44332009-09-09 15:08:12 +00001126
Chris Lattnerda930612009-04-27 05:58:23 +00001127 DeclsCursor.JumpToBit(Offset);
Chris Lattner698f9252009-04-27 05:27:42 +00001128 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +00001129 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +00001130 unsigned Idx = 0;
1131 PCHDeclReader Reader(*this, Record, Idx);
1132
Chris Lattnerda930612009-04-27 05:58:23 +00001133 Decl *D = 0;
1134 switch ((pch::DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
Chris Lattner698f9252009-04-27 05:27:42 +00001135 case pch::DECL_ATTR:
1136 case pch::DECL_CONTEXT_LEXICAL:
1137 case pch::DECL_CONTEXT_VISIBLE:
1138 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1139 break;
Chris Lattner698f9252009-04-27 05:27:42 +00001140 case pch::DECL_TRANSLATION_UNIT:
1141 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001142 D = Context->getTranslationUnitDecl();
Chris Lattner698f9252009-04-27 05:27:42 +00001143 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001144 case pch::DECL_TYPEDEF:
John McCallba6a9bd2009-10-24 08:00:42 +00001145 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001146 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001147 case pch::DECL_ENUM:
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +00001148 D = EnumDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001149 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001150 case pch::DECL_RECORD:
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +00001151 D = RecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001152 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001153 case pch::DECL_ENUM_CONSTANT:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001154 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +00001155 0, llvm::APSInt());
1156 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001157 case pch::DECL_FUNCTION:
Mike Stump1eb44332009-09-09 15:08:12 +00001158 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +00001159 QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001160 break;
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001161 case pch::DECL_LINKAGE_SPEC:
1162 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
1163 (LinkageSpecDecl::LanguageIDs)0,
1164 false);
1165 break;
1166 case pch::DECL_NAMESPACE:
1167 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
1168 break;
1169 case pch::DECL_NAMESPACE_ALIAS:
1170 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
1171 SourceLocation(), 0, SourceRange(), 0,
1172 SourceLocation(), 0);
1173 break;
1174 case pch::DECL_USING:
1175 D = UsingDecl::Create(*Context, 0, SourceLocation(), SourceRange(),
1176 SourceLocation(), 0, DeclarationName(), false);
1177 break;
1178 case pch::DECL_USING_SHADOW:
1179 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1180 break;
1181 case pch::DECL_USING_DIRECTIVE:
1182 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
1183 SourceLocation(), SourceRange(), 0,
1184 SourceLocation(), 0, 0);
1185 break;
1186 case pch::DECL_UNRESOLVED_USING_VALUE:
1187 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
1188 SourceRange(), 0, SourceLocation(),
1189 DeclarationName());
1190 break;
1191 case pch::DECL_UNRESOLVED_USING_TYPENAME:
1192 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
1193 SourceLocation(), SourceRange(),
1194 0, SourceLocation(),
1195 DeclarationName());
1196 break;
1197 case pch::DECL_CXX_RECORD:
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +00001198 D = CXXRecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001199 break;
1200 case pch::DECL_CXX_METHOD:
1201 D = CXXMethodDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
1202 QualType(), 0);
1203 break;
1204 case pch::DECL_CXX_CONSTRUCTOR:
1205 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1206 break;
1207 case pch::DECL_CXX_DESTRUCTOR:
1208 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1209 break;
1210 case pch::DECL_CXX_CONVERSION:
1211 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1212 break;
Abramo Bagnara6206d532010-06-05 05:09:32 +00001213 case pch::DECL_ACCESS_SPEC:
1214 D = AccessSpecDecl::Create(*Context, AS_none, 0, SourceLocation(),
1215 SourceLocation());
1216 break;
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001217 case pch::DECL_FRIEND:
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001218 D = FriendDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001219 break;
1220 case pch::DECL_FRIEND_TEMPLATE:
1221 assert(false && "cannot read FriendTemplateDecl");
1222 break;
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001223 case pch::DECL_CLASS_TEMPLATE:
Argyrios Kyrtzidis5bf1bdc2010-06-21 10:57:41 +00001224 D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(),
1225 DeclarationName(), 0, 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001226 break;
1227 case pch::DECL_CLASS_TEMPLATE_SPECIALIZATION:
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +00001228 D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001229 break;
1230 case pch::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +00001231 D = ClassTemplatePartialSpecializationDecl::Create(*Context,
1232 Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001233 break;
1234 case pch::DECL_FUNCTION_TEMPLATE:
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001235 D = FunctionTemplateDecl::Create(*Context, 0, SourceLocation(),
1236 DeclarationName(), 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001237 break;
1238 case pch::DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +00001239 D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001240 break;
1241 case pch::DECL_NON_TYPE_TEMPLATE_PARM:
Argyrios Kyrtzidisb24e1992010-06-25 16:25:09 +00001242 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0,
1243 QualType(),0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001244 break;
1245 case pch::DECL_TEMPLATE_TEMPLATE_PARM:
1246 assert(false && "cannot read TemplateTemplateParmDecl");
1247 break;
1248 case pch::DECL_STATIC_ASSERT:
1249 assert(false && "cannot read StaticAssertDecl");
1250 break;
1251
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001252 case pch::DECL_OBJC_METHOD:
Mike Stump1eb44332009-09-09 15:08:12 +00001253 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor4bc1cb62010-03-08 14:59:44 +00001254 Selector(), QualType(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001255 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001256 case pch::DECL_OBJC_INTERFACE:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001257 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001258 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001259 case pch::DECL_OBJC_IVAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +00001260 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +00001261 ObjCIvarDecl::None);
1262 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001263 case pch::DECL_OBJC_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001264 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001265 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001266 case pch::DECL_OBJC_AT_DEFS_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +00001267 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +00001268 QualType(), 0);
1269 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001270 case pch::DECL_OBJC_CLASS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001271 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001272 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001273 case pch::DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001274 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001275 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001276 case pch::DECL_OBJC_CATEGORY:
Douglas Gregor3db211b2010-01-16 16:38:58 +00001277 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1278 SourceLocation(), SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001279 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001280 case pch::DECL_OBJC_CATEGORY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001281 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001282 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001283 case pch::DECL_OBJC_IMPLEMENTATION:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001284 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001285 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001286 case pch::DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001287 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001288 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001289 case pch::DECL_OBJC_PROPERTY:
Fariborz Jahaniand0502402010-01-21 17:36:00 +00001290 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall83a230c2010-06-04 20:50:08 +00001291 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001292 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001293 case pch::DECL_OBJC_PROPERTY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001294 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +00001295 SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +00001296 ObjCPropertyImplDecl::Dynamic, 0);
1297 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001298 case pch::DECL_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +00001299 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +00001300 false);
Chris Lattner698f9252009-04-27 05:27:42 +00001301 break;
Chris Lattner698f9252009-04-27 05:27:42 +00001302 case pch::DECL_VAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +00001303 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregor16573fa2010-04-19 22:54:31 +00001304 VarDecl::None, VarDecl::None);
Chris Lattner698f9252009-04-27 05:27:42 +00001305 break;
1306
1307 case pch::DECL_IMPLICIT_PARAM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001308 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +00001309 break;
1310
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001311 case pch::DECL_PARM_VAR:
Mike Stump1eb44332009-09-09 15:08:12 +00001312 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Douglas Gregor16573fa2010-04-19 22:54:31 +00001313 VarDecl::None, VarDecl::None, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001314 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001315 case pch::DECL_FILE_SCOPE_ASM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001316 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001317 break;
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001318 case pch::DECL_BLOCK:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001319 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001320 break;
1321 }
Chris Lattner698f9252009-04-27 05:27:42 +00001322
1323 assert(D && "Unknown declaration reading PCH file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001324 LoadedDecl(Index, D);
1325 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +00001326
1327 // If this declaration is also a declaration context, get the
1328 // offsets for its tables of lexical and visible declarations.
1329 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1330 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1331 if (Offsets.first || Offsets.second) {
1332 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1333 DC->setHasExternalVisibleStorage(Offsets.second != 0);
1334 DeclContextOffsets[DC] = Offsets;
1335 }
1336 }
1337 assert(Idx == Record.size());
1338
1339 // If we have deserialized a declaration that has a definition the
1340 // AST consumer might need to know about, notify the consumer
1341 // about that definition now or queue it for later.
1342 if (isConsumerInterestedIn(D)) {
1343 if (Consumer) {
1344 DeclGroupRef DG(D);
1345 Consumer->HandleTopLevelDecl(DG);
1346 } else {
1347 InterestingDecls.push_back(D);
1348 }
1349 }
1350
1351 return D;
1352}