1 //===--- ASTReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the ASTReader::ReadDeclRecord method, which is the
11 // entrypoint for loading a decl.
13 //===----------------------------------------------------------------------===//
15 #include "ASTCommon.h"
16 #include "clang/Serialization/ASTReader.h"
17 #include "clang/AST/ASTConsumer.h"
18 #include "clang/AST/ASTContext.h"
19 #include "clang/AST/DeclVisitor.h"
20 #include "clang/AST/DeclGroup.h"
21 #include "clang/AST/DeclCXX.h"
22 #include "clang/AST/DeclTemplate.h"
23 #include "clang/AST/Expr.h"
24 using namespace clang
;
25 using namespace clang::serialization
;
27 //===----------------------------------------------------------------------===//
28 // Declaration deserialization
29 //===----------------------------------------------------------------------===//
32 class ASTDeclReader
: public DeclVisitor
<ASTDeclReader
, void> {
34 ASTReader::PerFileData
&F
;
35 llvm::BitstreamCursor
&Cursor
;
36 const DeclID ThisDeclID
;
37 typedef ASTReader::RecordData RecordData
;
38 const RecordData
&Record
;
40 TypeID TypeIDForTypeDecl
;
42 uint64_t GetCurrentCursorOffset();
43 SourceLocation
ReadSourceLocation(const RecordData
&R
, unsigned &I
) {
44 return Reader
.ReadSourceLocation(F
, R
, I
);
46 SourceRange
ReadSourceRange(const RecordData
&R
, unsigned &I
) {
47 return Reader
.ReadSourceRange(F
, R
, I
);
49 TypeSourceInfo
*GetTypeSourceInfo(const RecordData
&R
, unsigned &I
) {
50 return Reader
.GetTypeSourceInfo(F
, R
, I
);
52 void ReadQualifierInfo(QualifierInfo
&Info
,
53 const RecordData
&R
, unsigned &I
) {
54 Reader
.ReadQualifierInfo(F
, Info
, R
, I
);
56 void ReadDeclarationNameLoc(DeclarationNameLoc
&DNLoc
, DeclarationName Name
,
57 const RecordData
&R
, unsigned &I
) {
58 Reader
.ReadDeclarationNameLoc(F
, DNLoc
, Name
, R
, I
);
60 void ReadDeclarationNameInfo(DeclarationNameInfo
&NameInfo
,
61 const RecordData
&R
, unsigned &I
) {
62 Reader
.ReadDeclarationNameInfo(F
, NameInfo
, R
, I
);
65 void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData
&Data
,
66 const RecordData
&R
, unsigned &I
);
68 void InitializeCXXDefinitionData(CXXRecordDecl
*D
,
69 CXXRecordDecl
*DefinitionDecl
,
70 const RecordData
&Record
, unsigned &Idx
);
72 ASTDeclReader(ASTReader
&Reader
, ASTReader::PerFileData
&F
,
73 llvm::BitstreamCursor
&Cursor
, DeclID thisDeclID
,
74 const RecordData
&Record
, unsigned &Idx
)
75 : Reader(Reader
), F(F
), Cursor(Cursor
), ThisDeclID(thisDeclID
),
76 Record(Record
), Idx(Idx
), TypeIDForTypeDecl(0) { }
80 void UpdateDecl(Decl
*D
, const RecordData
&Record
);
82 void VisitDecl(Decl
*D
);
83 void VisitTranslationUnitDecl(TranslationUnitDecl
*TU
);
84 void VisitNamedDecl(NamedDecl
*ND
);
85 void VisitNamespaceDecl(NamespaceDecl
*D
);
86 void VisitUsingDirectiveDecl(UsingDirectiveDecl
*D
);
87 void VisitNamespaceAliasDecl(NamespaceAliasDecl
*D
);
88 void VisitTypeDecl(TypeDecl
*TD
);
89 void VisitTypedefDecl(TypedefDecl
*TD
);
90 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl
*D
);
91 void VisitTagDecl(TagDecl
*TD
);
92 void VisitEnumDecl(EnumDecl
*ED
);
93 void VisitRecordDecl(RecordDecl
*RD
);
94 void VisitCXXRecordDecl(CXXRecordDecl
*D
);
95 void VisitClassTemplateSpecializationDecl(
96 ClassTemplateSpecializationDecl
*D
);
97 void VisitClassTemplatePartialSpecializationDecl(
98 ClassTemplatePartialSpecializationDecl
*D
);
99 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl
*D
);
100 void VisitValueDecl(ValueDecl
*VD
);
101 void VisitEnumConstantDecl(EnumConstantDecl
*ECD
);
102 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl
*D
);
103 void VisitDeclaratorDecl(DeclaratorDecl
*DD
);
104 void VisitFunctionDecl(FunctionDecl
*FD
);
105 void VisitCXXMethodDecl(CXXMethodDecl
*D
);
106 void VisitCXXConstructorDecl(CXXConstructorDecl
*D
);
107 void VisitCXXDestructorDecl(CXXDestructorDecl
*D
);
108 void VisitCXXConversionDecl(CXXConversionDecl
*D
);
109 void VisitFieldDecl(FieldDecl
*FD
);
110 void VisitIndirectFieldDecl(IndirectFieldDecl
*FD
);
111 void VisitVarDecl(VarDecl
*VD
);
112 void VisitImplicitParamDecl(ImplicitParamDecl
*PD
);
113 void VisitParmVarDecl(ParmVarDecl
*PD
);
114 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl
*D
);
115 void VisitTemplateDecl(TemplateDecl
*D
);
116 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl
*D
);
117 void VisitClassTemplateDecl(ClassTemplateDecl
*D
);
118 void VisitFunctionTemplateDecl(FunctionTemplateDecl
*D
);
119 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl
*D
);
120 void VisitUsingDecl(UsingDecl
*D
);
121 void VisitUsingShadowDecl(UsingShadowDecl
*D
);
122 void VisitLinkageSpecDecl(LinkageSpecDecl
*D
);
123 void VisitFileScopeAsmDecl(FileScopeAsmDecl
*AD
);
124 void VisitAccessSpecDecl(AccessSpecDecl
*D
);
125 void VisitFriendDecl(FriendDecl
*D
);
126 void VisitFriendTemplateDecl(FriendTemplateDecl
*D
);
127 void VisitStaticAssertDecl(StaticAssertDecl
*D
);
128 void VisitBlockDecl(BlockDecl
*BD
);
130 std::pair
<uint64_t, uint64_t> VisitDeclContext(DeclContext
*DC
);
131 template <typename T
> void VisitRedeclarable(Redeclarable
<T
> *D
);
133 // FIXME: Reorder according to DeclNodes.td?
134 void VisitObjCMethodDecl(ObjCMethodDecl
*D
);
135 void VisitObjCContainerDecl(ObjCContainerDecl
*D
);
136 void VisitObjCInterfaceDecl(ObjCInterfaceDecl
*D
);
137 void VisitObjCIvarDecl(ObjCIvarDecl
*D
);
138 void VisitObjCProtocolDecl(ObjCProtocolDecl
*D
);
139 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl
*D
);
140 void VisitObjCClassDecl(ObjCClassDecl
*D
);
141 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl
*D
);
142 void VisitObjCCategoryDecl(ObjCCategoryDecl
*D
);
143 void VisitObjCImplDecl(ObjCImplDecl
*D
);
144 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl
*D
);
145 void VisitObjCImplementationDecl(ObjCImplementationDecl
*D
);
146 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl
*D
);
147 void VisitObjCPropertyDecl(ObjCPropertyDecl
*D
);
148 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl
*D
);
152 uint64_t ASTDeclReader::GetCurrentCursorOffset() {
154 for (unsigned I
= 0, N
= Reader
.Chain
.size(); I
!= N
; ++I
) {
155 ASTReader::PerFileData
&F
= *Reader
.Chain
[N
- I
- 1];
156 if (&Cursor
== &F
.DeclsCursor
) {
157 Off
+= F
.DeclsCursor
.GetCurrentBitNo();
165 void ASTDeclReader::Visit(Decl
*D
) {
166 DeclVisitor
<ASTDeclReader
, void>::Visit(D
);
168 if (TypeDecl
*TD
= dyn_cast
<TypeDecl
>(D
)) {
169 // if we have a fully initialized TypeDecl, we can safely read its type now.
170 TD
->setTypeForDecl(Reader
.GetType(TypeIDForTypeDecl
).getTypePtrOrNull());
171 } else if (FunctionDecl
*FD
= dyn_cast
<FunctionDecl
>(D
)) {
172 // FunctionDecl's body was written last after all other Stmts/Exprs.
174 FD
->setLazyBody(GetCurrentCursorOffset());
178 void ASTDeclReader::VisitDecl(Decl
*D
) {
179 D
->setDeclContext(cast_or_null
<DeclContext
>(Reader
.GetDecl(Record
[Idx
++])));
180 D
->setLexicalDeclContext(
181 cast_or_null
<DeclContext
>(Reader
.GetDecl(Record
[Idx
++])));
182 D
->setLocation(ReadSourceLocation(Record
, Idx
));
183 D
->setInvalidDecl(Record
[Idx
++]);
184 if (Record
[Idx
++]) { // hasAttrs
186 Reader
.ReadAttributes(F
, Attrs
, Record
, Idx
);
189 D
->setImplicit(Record
[Idx
++]);
190 D
->setUsed(Record
[Idx
++]);
191 D
->setAccess((AccessSpecifier
)Record
[Idx
++]);
192 D
->setPCHLevel(Record
[Idx
++] + (F
.Type
<= ASTReader::PCH
));
195 void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl
*TU
) {
197 TU
->setAnonymousNamespace(
198 cast_or_null
<NamespaceDecl
>(Reader
.GetDecl(Record
[Idx
++])));
201 void ASTDeclReader::VisitNamedDecl(NamedDecl
*ND
) {
203 ND
->setDeclName(Reader
.ReadDeclarationName(Record
, Idx
));
206 void ASTDeclReader::VisitTypeDecl(TypeDecl
*TD
) {
208 // Delay type reading until after we have fully initialized the decl.
209 TypeIDForTypeDecl
= Record
[Idx
++];
212 void ASTDeclReader::VisitTypedefDecl(TypedefDecl
*TD
) {
214 TD
->setTypeSourceInfo(GetTypeSourceInfo(Record
, Idx
));
217 void ASTDeclReader::VisitTagDecl(TagDecl
*TD
) {
219 VisitRedeclarable(TD
);
220 TD
->IdentifierNamespace
= Record
[Idx
++];
221 TD
->setTagKind((TagDecl::TagKind
)Record
[Idx
++]);
222 TD
->setDefinition(Record
[Idx
++]);
223 TD
->setEmbeddedInDeclarator(Record
[Idx
++]);
224 TD
->setRBraceLoc(ReadSourceLocation(Record
, Idx
));
225 TD
->setTagKeywordLoc(ReadSourceLocation(Record
, Idx
));
226 if (Record
[Idx
++]) { // hasExtInfo
227 TagDecl::ExtInfo
*Info
= new (*Reader
.getContext()) TagDecl::ExtInfo();
228 ReadQualifierInfo(*Info
, Record
, Idx
);
229 TD
->TypedefDeclOrQualifier
= Info
;
231 TD
->setTypedefForAnonDecl(
232 cast_or_null
<TypedefDecl
>(Reader
.GetDecl(Record
[Idx
++])));
235 void ASTDeclReader::VisitEnumDecl(EnumDecl
*ED
) {
237 if (TypeSourceInfo
*TI
= Reader
.GetTypeSourceInfo(F
, Record
, Idx
))
238 ED
->setIntegerTypeSourceInfo(TI
);
240 ED
->setIntegerType(Reader
.GetType(Record
[Idx
++]));
241 ED
->setPromotionType(Reader
.GetType(Record
[Idx
++]));
242 ED
->setNumPositiveBits(Record
[Idx
++]);
243 ED
->setNumNegativeBits(Record
[Idx
++]);
244 ED
->IsScoped
= Record
[Idx
++];
245 ED
->IsScopedUsingClassTag
= Record
[Idx
++];
246 ED
->IsFixed
= Record
[Idx
++];
247 ED
->setInstantiationOfMemberEnum(
248 cast_or_null
<EnumDecl
>(Reader
.GetDecl(Record
[Idx
++])));
251 void ASTDeclReader::VisitRecordDecl(RecordDecl
*RD
) {
253 RD
->setHasFlexibleArrayMember(Record
[Idx
++]);
254 RD
->setAnonymousStructOrUnion(Record
[Idx
++]);
255 RD
->setHasObjectMember(Record
[Idx
++]);
258 void ASTDeclReader::VisitValueDecl(ValueDecl
*VD
) {
260 VD
->setType(Reader
.GetType(Record
[Idx
++]));
263 void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl
*ECD
) {
266 ECD
->setInitExpr(Reader
.ReadExpr(F
));
267 ECD
->setInitVal(Reader
.ReadAPSInt(Record
, Idx
));
270 void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl
*DD
) {
272 if (Record
[Idx
++]) { // hasExtInfo
273 DeclaratorDecl::ExtInfo
*Info
274 = new (*Reader
.getContext()) DeclaratorDecl::ExtInfo();
275 ReadQualifierInfo(*Info
, Record
, Idx
);
276 Info
->TInfo
= GetTypeSourceInfo(Record
, Idx
);
279 DD
->DeclInfo
= GetTypeSourceInfo(Record
, Idx
);
282 void ASTDeclReader::VisitFunctionDecl(FunctionDecl
*FD
) {
283 VisitDeclaratorDecl(FD
);
284 VisitRedeclarable(FD
);
286 ReadDeclarationNameLoc(FD
->DNLoc
, FD
->getDeclName(), Record
, Idx
);
287 FD
->IdentifierNamespace
= Record
[Idx
++];
288 switch ((FunctionDecl::TemplatedKind
)Record
[Idx
++]) {
289 default: assert(false && "Unhandled TemplatedKind!");
291 case FunctionDecl::TK_NonTemplate
:
293 case FunctionDecl::TK_FunctionTemplate
:
294 FD
->setDescribedFunctionTemplate(
295 cast
<FunctionTemplateDecl
>(Reader
.GetDecl(Record
[Idx
++])));
297 case FunctionDecl::TK_MemberSpecialization
: {
298 FunctionDecl
*InstFD
= cast
<FunctionDecl
>(Reader
.GetDecl(Record
[Idx
++]));
299 TemplateSpecializationKind TSK
= (TemplateSpecializationKind
)Record
[Idx
++];
300 SourceLocation POI
= ReadSourceLocation(Record
, Idx
);
301 FD
->setInstantiationOfMemberFunction(*Reader
.getContext(), InstFD
, TSK
);
302 FD
->getMemberSpecializationInfo()->setPointOfInstantiation(POI
);
305 case FunctionDecl::TK_FunctionTemplateSpecialization
: {
306 FunctionTemplateDecl
*Template
307 = cast
<FunctionTemplateDecl
>(Reader
.GetDecl(Record
[Idx
++]));
308 TemplateSpecializationKind TSK
= (TemplateSpecializationKind
)Record
[Idx
++];
310 // Template arguments.
311 llvm::SmallVector
<TemplateArgument
, 8> TemplArgs
;
312 Reader
.ReadTemplateArgumentList(TemplArgs
, F
, Record
, Idx
);
314 // Template args as written.
315 llvm::SmallVector
<TemplateArgumentLoc
, 8> TemplArgLocs
;
316 SourceLocation LAngleLoc
, RAngleLoc
;
317 if (Record
[Idx
++]) { // TemplateArgumentsAsWritten != 0
318 unsigned NumTemplateArgLocs
= Record
[Idx
++];
319 TemplArgLocs
.reserve(NumTemplateArgLocs
);
320 for (unsigned i
=0; i
!= NumTemplateArgLocs
; ++i
)
321 TemplArgLocs
.push_back(
322 Reader
.ReadTemplateArgumentLoc(F
, Record
, Idx
));
324 LAngleLoc
= ReadSourceLocation(Record
, Idx
);
325 RAngleLoc
= ReadSourceLocation(Record
, Idx
);
328 SourceLocation POI
= ReadSourceLocation(Record
, Idx
);
330 ASTContext
&C
= *Reader
.getContext();
331 TemplateArgumentList
*TemplArgList
332 = TemplateArgumentList::CreateCopy(C
, TemplArgs
.data(), TemplArgs
.size());
333 TemplateArgumentListInfo
*TemplArgsInfo
334 = new (C
) TemplateArgumentListInfo(LAngleLoc
, RAngleLoc
);
335 for (unsigned i
=0, e
= TemplArgLocs
.size(); i
!= e
; ++i
)
336 TemplArgsInfo
->addArgument(TemplArgLocs
[i
]);
337 FunctionTemplateSpecializationInfo
*FTInfo
338 = FunctionTemplateSpecializationInfo::Create(C
, FD
, Template
, TSK
,
341 FD
->TemplateOrSpecialization
= FTInfo
;
343 if (FD
->isCanonicalDecl()) { // if canonical add to template's set.
344 // The template that contains the specializations set. It's not safe to
345 // use getCanonicalDecl on Template since it may still be initializing.
346 FunctionTemplateDecl
*CanonTemplate
347 = cast
<FunctionTemplateDecl
>(Reader
.GetDecl(Record
[Idx
++]));
348 // Get the InsertPos by FindNodeOrInsertPos() instead of calling
349 // InsertNode(FTInfo) directly to avoid the getASTContext() call in
350 // FunctionTemplateSpecializationInfo's Profile().
351 // We avoid getASTContext because a decl in the parent hierarchy may
353 llvm::FoldingSetNodeID ID
;
354 FunctionTemplateSpecializationInfo::Profile(ID
, TemplArgs
.data(),
355 TemplArgs
.size(), C
);
357 CanonTemplate
->getSpecializations().FindNodeOrInsertPos(ID
, InsertPos
);
358 assert(InsertPos
&& "Another specialization already inserted!");
359 CanonTemplate
->getSpecializations().InsertNode(FTInfo
, InsertPos
);
363 case FunctionDecl::TK_DependentFunctionTemplateSpecialization
: {
365 UnresolvedSet
<8> TemplDecls
;
366 unsigned NumTemplates
= Record
[Idx
++];
367 while (NumTemplates
--)
368 TemplDecls
.addDecl(cast
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++])));
371 TemplateArgumentListInfo TemplArgs
;
372 unsigned NumArgs
= Record
[Idx
++];
374 TemplArgs
.addArgument(Reader
.ReadTemplateArgumentLoc(F
, Record
, Idx
));
375 TemplArgs
.setLAngleLoc(ReadSourceLocation(Record
, Idx
));
376 TemplArgs
.setRAngleLoc(ReadSourceLocation(Record
, Idx
));
378 FD
->setDependentTemplateSpecialization(*Reader
.getContext(),
379 TemplDecls
, TemplArgs
);
384 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
385 // after everything else is read.
387 FD
->SClass
= (StorageClass
)Record
[Idx
++];
388 FD
->SClassAsWritten
= (StorageClass
)Record
[Idx
++];
389 FD
->IsInline
= Record
[Idx
++];
390 FD
->IsInlineSpecified
= Record
[Idx
++];
391 FD
->IsVirtualAsWritten
= Record
[Idx
++];
392 FD
->IsPure
= Record
[Idx
++];
393 FD
->HasInheritedPrototype
= Record
[Idx
++];
394 FD
->HasWrittenPrototype
= Record
[Idx
++];
395 FD
->IsDeleted
= Record
[Idx
++];
396 FD
->IsTrivial
= Record
[Idx
++];
397 FD
->HasImplicitReturnZero
= Record
[Idx
++];
398 FD
->EndRangeLoc
= ReadSourceLocation(Record
, Idx
);
400 // Read in the parameters.
401 unsigned NumParams
= Record
[Idx
++];
402 llvm::SmallVector
<ParmVarDecl
*, 16> Params
;
403 Params
.reserve(NumParams
);
404 for (unsigned I
= 0; I
!= NumParams
; ++I
)
405 Params
.push_back(cast
<ParmVarDecl
>(Reader
.GetDecl(Record
[Idx
++])));
406 FD
->setParams(*Reader
.getContext(), Params
.data(), NumParams
);
409 void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl
*MD
) {
412 // In practice, this won't be executed (since method definitions
413 // don't occur in header files).
414 MD
->setBody(Reader
.ReadStmt(F
));
415 MD
->setSelfDecl(cast
<ImplicitParamDecl
>(Reader
.GetDecl(Record
[Idx
++])));
416 MD
->setCmdDecl(cast
<ImplicitParamDecl
>(Reader
.GetDecl(Record
[Idx
++])));
418 MD
->setInstanceMethod(Record
[Idx
++]);
419 MD
->setVariadic(Record
[Idx
++]);
420 MD
->setSynthesized(Record
[Idx
++]);
421 MD
->setDefined(Record
[Idx
++]);
422 MD
->setDeclImplementation((ObjCMethodDecl::ImplementationControl
)Record
[Idx
++]);
423 MD
->setObjCDeclQualifier((Decl::ObjCDeclQualifier
)Record
[Idx
++]);
424 MD
->setNumSelectorArgs(unsigned(Record
[Idx
++]));
425 MD
->setResultType(Reader
.GetType(Record
[Idx
++]));
426 MD
->setResultTypeSourceInfo(GetTypeSourceInfo(Record
, Idx
));
427 MD
->setEndLoc(ReadSourceLocation(Record
, Idx
));
428 unsigned NumParams
= Record
[Idx
++];
429 llvm::SmallVector
<ParmVarDecl
*, 16> Params
;
430 Params
.reserve(NumParams
);
431 for (unsigned I
= 0; I
!= NumParams
; ++I
)
432 Params
.push_back(cast
<ParmVarDecl
>(Reader
.GetDecl(Record
[Idx
++])));
433 MD
->setMethodParams(*Reader
.getContext(), Params
.data(), NumParams
,
437 void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl
*CD
) {
439 SourceLocation A
= ReadSourceLocation(Record
, Idx
);
440 SourceLocation B
= ReadSourceLocation(Record
, Idx
);
441 CD
->setAtEndRange(SourceRange(A
, B
));
444 void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl
*ID
) {
445 VisitObjCContainerDecl(ID
);
446 ID
->setTypeForDecl(Reader
.GetType(Record
[Idx
++]).getTypePtrOrNull());
447 ID
->setSuperClass(cast_or_null
<ObjCInterfaceDecl
>
448 (Reader
.GetDecl(Record
[Idx
++])));
450 // Read the directly referenced protocols and their SourceLocations.
451 unsigned NumProtocols
= Record
[Idx
++];
452 llvm::SmallVector
<ObjCProtocolDecl
*, 16> Protocols
;
453 Protocols
.reserve(NumProtocols
);
454 for (unsigned I
= 0; I
!= NumProtocols
; ++I
)
455 Protocols
.push_back(cast
<ObjCProtocolDecl
>(Reader
.GetDecl(Record
[Idx
++])));
456 llvm::SmallVector
<SourceLocation
, 16> ProtoLocs
;
457 ProtoLocs
.reserve(NumProtocols
);
458 for (unsigned I
= 0; I
!= NumProtocols
; ++I
)
459 ProtoLocs
.push_back(ReadSourceLocation(Record
, Idx
));
460 ID
->setProtocolList(Protocols
.data(), NumProtocols
, ProtoLocs
.data(),
461 *Reader
.getContext());
463 // Read the transitive closure of protocols referenced by this class.
464 NumProtocols
= Record
[Idx
++];
466 Protocols
.reserve(NumProtocols
);
467 for (unsigned I
= 0; I
!= NumProtocols
; ++I
)
468 Protocols
.push_back(cast
<ObjCProtocolDecl
>(Reader
.GetDecl(Record
[Idx
++])));
469 ID
->AllReferencedProtocols
.set(Protocols
.data(), NumProtocols
,
470 *Reader
.getContext());
473 unsigned NumIvars
= Record
[Idx
++];
474 llvm::SmallVector
<ObjCIvarDecl
*, 16> IVars
;
475 IVars
.reserve(NumIvars
);
476 for (unsigned I
= 0; I
!= NumIvars
; ++I
)
477 IVars
.push_back(cast
<ObjCIvarDecl
>(Reader
.GetDecl(Record
[Idx
++])));
479 cast_or_null
<ObjCCategoryDecl
>(Reader
.GetDecl(Record
[Idx
++])));
480 // We will rebuild this list lazily.
482 ID
->setForwardDecl(Record
[Idx
++]);
483 ID
->setImplicitInterfaceDecl(Record
[Idx
++]);
484 ID
->setClassLoc(ReadSourceLocation(Record
, Idx
));
485 ID
->setSuperClassLoc(ReadSourceLocation(Record
, Idx
));
486 ID
->setLocEnd(ReadSourceLocation(Record
, Idx
));
489 void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl
*IVD
) {
491 IVD
->setAccessControl((ObjCIvarDecl::AccessControl
)Record
[Idx
++]);
492 // This field will be built lazily.
494 bool synth
= Record
[Idx
++];
495 IVD
->setSynthesize(synth
);
498 void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl
*PD
) {
499 VisitObjCContainerDecl(PD
);
500 PD
->setForwardDecl(Record
[Idx
++]);
501 PD
->setLocEnd(ReadSourceLocation(Record
, Idx
));
502 unsigned NumProtoRefs
= Record
[Idx
++];
503 llvm::SmallVector
<ObjCProtocolDecl
*, 16> ProtoRefs
;
504 ProtoRefs
.reserve(NumProtoRefs
);
505 for (unsigned I
= 0; I
!= NumProtoRefs
; ++I
)
506 ProtoRefs
.push_back(cast
<ObjCProtocolDecl
>(Reader
.GetDecl(Record
[Idx
++])));
507 llvm::SmallVector
<SourceLocation
, 16> ProtoLocs
;
508 ProtoLocs
.reserve(NumProtoRefs
);
509 for (unsigned I
= 0; I
!= NumProtoRefs
; ++I
)
510 ProtoLocs
.push_back(ReadSourceLocation(Record
, Idx
));
511 PD
->setProtocolList(ProtoRefs
.data(), NumProtoRefs
, ProtoLocs
.data(),
512 *Reader
.getContext());
515 void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl
*FD
) {
519 void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl
*CD
) {
521 unsigned NumClassRefs
= Record
[Idx
++];
522 llvm::SmallVector
<ObjCInterfaceDecl
*, 16> ClassRefs
;
523 ClassRefs
.reserve(NumClassRefs
);
524 for (unsigned I
= 0; I
!= NumClassRefs
; ++I
)
525 ClassRefs
.push_back(cast
<ObjCInterfaceDecl
>(Reader
.GetDecl(Record
[Idx
++])));
526 llvm::SmallVector
<SourceLocation
, 16> SLocs
;
527 SLocs
.reserve(NumClassRefs
);
528 for (unsigned I
= 0; I
!= NumClassRefs
; ++I
)
529 SLocs
.push_back(ReadSourceLocation(Record
, Idx
));
530 CD
->setClassList(*Reader
.getContext(), ClassRefs
.data(), SLocs
.data(),
534 void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl
*FPD
) {
536 unsigned NumProtoRefs
= Record
[Idx
++];
537 llvm::SmallVector
<ObjCProtocolDecl
*, 16> ProtoRefs
;
538 ProtoRefs
.reserve(NumProtoRefs
);
539 for (unsigned I
= 0; I
!= NumProtoRefs
; ++I
)
540 ProtoRefs
.push_back(cast
<ObjCProtocolDecl
>(Reader
.GetDecl(Record
[Idx
++])));
541 llvm::SmallVector
<SourceLocation
, 16> ProtoLocs
;
542 ProtoLocs
.reserve(NumProtoRefs
);
543 for (unsigned I
= 0; I
!= NumProtoRefs
; ++I
)
544 ProtoLocs
.push_back(ReadSourceLocation(Record
, Idx
));
545 FPD
->setProtocolList(ProtoRefs
.data(), NumProtoRefs
, ProtoLocs
.data(),
546 *Reader
.getContext());
549 void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl
*CD
) {
550 VisitObjCContainerDecl(CD
);
551 CD
->setClassInterface(cast
<ObjCInterfaceDecl
>(Reader
.GetDecl(Record
[Idx
++])));
552 unsigned NumProtoRefs
= Record
[Idx
++];
553 llvm::SmallVector
<ObjCProtocolDecl
*, 16> ProtoRefs
;
554 ProtoRefs
.reserve(NumProtoRefs
);
555 for (unsigned I
= 0; I
!= NumProtoRefs
; ++I
)
556 ProtoRefs
.push_back(cast
<ObjCProtocolDecl
>(Reader
.GetDecl(Record
[Idx
++])));
557 llvm::SmallVector
<SourceLocation
, 16> ProtoLocs
;
558 ProtoLocs
.reserve(NumProtoRefs
);
559 for (unsigned I
= 0; I
!= NumProtoRefs
; ++I
)
560 ProtoLocs
.push_back(ReadSourceLocation(Record
, Idx
));
561 CD
->setProtocolList(ProtoRefs
.data(), NumProtoRefs
, ProtoLocs
.data(),
562 *Reader
.getContext());
563 CD
->setNextClassCategory(cast_or_null
<ObjCCategoryDecl
>(Reader
.GetDecl(Record
[Idx
++])));
564 CD
->setHasSynthBitfield(Record
[Idx
++]);
565 CD
->setAtLoc(ReadSourceLocation(Record
, Idx
));
566 CD
->setCategoryNameLoc(ReadSourceLocation(Record
, Idx
));
569 void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl
*CAD
) {
571 CAD
->setClassInterface(cast
<ObjCInterfaceDecl
>(Reader
.GetDecl(Record
[Idx
++])));
574 void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl
*D
) {
576 D
->setAtLoc(ReadSourceLocation(Record
, Idx
));
577 D
->setType(GetTypeSourceInfo(Record
, Idx
));
578 // FIXME: stable encoding
579 D
->setPropertyAttributes(
580 (ObjCPropertyDecl::PropertyAttributeKind
)Record
[Idx
++]);
581 D
->setPropertyAttributesAsWritten(
582 (ObjCPropertyDecl::PropertyAttributeKind
)Record
[Idx
++]);
583 // FIXME: stable encoding
584 D
->setPropertyImplementation(
585 (ObjCPropertyDecl::PropertyControl
)Record
[Idx
++]);
586 D
->setGetterName(Reader
.ReadDeclarationName(Record
, Idx
).getObjCSelector());
587 D
->setSetterName(Reader
.ReadDeclarationName(Record
, Idx
).getObjCSelector());
588 D
->setGetterMethodDecl(
589 cast_or_null
<ObjCMethodDecl
>(Reader
.GetDecl(Record
[Idx
++])));
590 D
->setSetterMethodDecl(
591 cast_or_null
<ObjCMethodDecl
>(Reader
.GetDecl(Record
[Idx
++])));
592 D
->setPropertyIvarDecl(
593 cast_or_null
<ObjCIvarDecl
>(Reader
.GetDecl(Record
[Idx
++])));
596 void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl
*D
) {
597 VisitObjCContainerDecl(D
);
598 D
->setClassInterface(
599 cast_or_null
<ObjCInterfaceDecl
>(Reader
.GetDecl(Record
[Idx
++])));
602 void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl
*D
) {
603 VisitObjCImplDecl(D
);
604 D
->setIdentifier(Reader
.GetIdentifierInfo(Record
, Idx
));
607 void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl
*D
) {
608 VisitObjCImplDecl(D
);
610 cast_or_null
<ObjCInterfaceDecl
>(Reader
.GetDecl(Record
[Idx
++])));
611 llvm::tie(D
->IvarInitializers
, D
->NumIvarInitializers
)
612 = Reader
.ReadCXXCtorInitializers(F
, Record
, Idx
);
613 D
->setHasSynthBitfield(Record
[Idx
++]);
617 void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl
*D
) {
619 D
->setAtLoc(ReadSourceLocation(Record
, Idx
));
621 cast_or_null
<ObjCPropertyDecl
>(Reader
.GetDecl(Record
[Idx
++])));
622 D
->PropertyIvarDecl
=
623 cast_or_null
<ObjCIvarDecl
>(Reader
.GetDecl(Record
[Idx
++]));
624 D
->IvarLoc
= ReadSourceLocation(Record
, Idx
);
625 D
->setGetterCXXConstructor(Reader
.ReadExpr(F
));
626 D
->setSetterCXXAssignment(Reader
.ReadExpr(F
));
629 void ASTDeclReader::VisitFieldDecl(FieldDecl
*FD
) {
630 VisitDeclaratorDecl(FD
);
631 FD
->setMutable(Record
[Idx
++]);
633 FD
->setBitWidth(Reader
.ReadExpr(F
));
634 if (!FD
->getDeclName()) {
635 FieldDecl
*Tmpl
= cast_or_null
<FieldDecl
>(Reader
.GetDecl(Record
[Idx
++]));
637 Reader
.getContext()->setInstantiatedFromUnnamedFieldDecl(FD
, Tmpl
);
641 void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl
*FD
) {
644 FD
->ChainingSize
= Record
[Idx
++];
645 assert(FD
->ChainingSize
>= 2 && "Anonymous chaining must be >= 2");
646 FD
->Chaining
= new (*Reader
.getContext())NamedDecl
*[FD
->ChainingSize
];
648 for (unsigned I
= 0; I
!= FD
->ChainingSize
; ++I
)
649 FD
->Chaining
[I
] = cast
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++]));
652 void ASTDeclReader::VisitVarDecl(VarDecl
*VD
) {
653 VisitDeclaratorDecl(VD
);
654 VisitRedeclarable(VD
);
655 VD
->SClass
= (StorageClass
)Record
[Idx
++];
656 VD
->setStorageClassAsWritten((StorageClass
)Record
[Idx
++]);
657 VD
->setThreadSpecified(Record
[Idx
++]);
658 VD
->setCXXDirectInitializer(Record
[Idx
++]);
659 VD
->setExceptionVariable(Record
[Idx
++]);
660 VD
->setNRVOVariable(Record
[Idx
++]);
662 VD
->setInit(Reader
.ReadExpr(F
));
664 if (Record
[Idx
++]) { // HasMemberSpecializationInfo.
665 VarDecl
*Tmpl
= cast
<VarDecl
>(Reader
.GetDecl(Record
[Idx
++]));
666 TemplateSpecializationKind TSK
= (TemplateSpecializationKind
)Record
[Idx
++];
667 SourceLocation POI
= ReadSourceLocation(Record
, Idx
);
668 Reader
.getContext()->setInstantiatedFromStaticDataMember(VD
, Tmpl
, TSK
,POI
);
672 void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl
*PD
) {
676 void ASTDeclReader::VisitParmVarDecl(ParmVarDecl
*PD
) {
678 PD
->setObjCDeclQualifier((Decl::ObjCDeclQualifier
)Record
[Idx
++]);
679 PD
->setHasInheritedDefaultArg(Record
[Idx
++]);
680 if (Record
[Idx
++]) // hasUninstantiatedDefaultArg.
681 PD
->setUninstantiatedDefaultArg(Reader
.ReadExpr(F
));
684 void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl
*AD
) {
686 AD
->setAsmString(cast
<StringLiteral
>(Reader
.ReadExpr(F
)));
689 void ASTDeclReader::VisitBlockDecl(BlockDecl
*BD
) {
691 BD
->setBody(cast_or_null
<CompoundStmt
>(Reader
.ReadStmt(F
)));
692 BD
->setSignatureAsWritten(GetTypeSourceInfo(Record
, Idx
));
693 unsigned NumParams
= Record
[Idx
++];
694 llvm::SmallVector
<ParmVarDecl
*, 16> Params
;
695 Params
.reserve(NumParams
);
696 for (unsigned I
= 0; I
!= NumParams
; ++I
)
697 Params
.push_back(cast
<ParmVarDecl
>(Reader
.GetDecl(Record
[Idx
++])));
698 BD
->setParams(Params
.data(), NumParams
);
701 void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl
*D
) {
703 D
->setLanguage((LinkageSpecDecl::LanguageIDs
)Record
[Idx
++]);
704 D
->setHasBraces(Record
[Idx
++]);
707 void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl
*D
) {
709 D
->IsInline
= Record
[Idx
++];
710 D
->LBracLoc
= ReadSourceLocation(Record
, Idx
);
711 D
->RBracLoc
= ReadSourceLocation(Record
, Idx
);
712 D
->NextNamespace
= Record
[Idx
++];
714 bool IsOriginal
= Record
[Idx
++];
715 D
->OrigOrAnonNamespace
.setInt(IsOriginal
);
716 D
->OrigOrAnonNamespace
.setPointer(
717 cast_or_null
<NamespaceDecl
>(Reader
.GetDecl(Record
[Idx
++])));
720 void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl
*D
) {
722 D
->NamespaceLoc
= ReadSourceLocation(Record
, Idx
);
723 D
->setQualifierRange(ReadSourceRange(Record
, Idx
));
724 D
->setQualifier(Reader
.ReadNestedNameSpecifier(Record
, Idx
));
725 D
->IdentLoc
= ReadSourceLocation(Record
, Idx
);
726 D
->Namespace
= cast
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++]));
729 void ASTDeclReader::VisitUsingDecl(UsingDecl
*D
) {
731 D
->setUsingLocation(ReadSourceLocation(Record
, Idx
));
732 D
->setNestedNameRange(ReadSourceRange(Record
, Idx
));
733 D
->setTargetNestedNameDecl(Reader
.ReadNestedNameSpecifier(Record
, Idx
));
734 ReadDeclarationNameLoc(D
->DNLoc
, D
->getDeclName(), Record
, Idx
);
735 D
->FirstUsingShadow
= cast_or_null
<UsingShadowDecl
>(Reader
.GetDecl(Record
[Idx
++]));
736 D
->setTypeName(Record
[Idx
++]);
737 NamedDecl
*Pattern
= cast_or_null
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++]));
739 Reader
.getContext()->setInstantiatedFromUsingDecl(D
, Pattern
);
742 void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl
*D
) {
744 D
->setTargetDecl(cast
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++])));
745 D
->UsingOrNextShadow
= cast_or_null
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++]));
746 UsingShadowDecl
*Pattern
747 = cast_or_null
<UsingShadowDecl
>(Reader
.GetDecl(Record
[Idx
++]));
749 Reader
.getContext()->setInstantiatedFromUsingShadowDecl(D
, Pattern
);
752 void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl
*D
) {
754 D
->UsingLoc
= ReadSourceLocation(Record
, Idx
);
755 D
->NamespaceLoc
= ReadSourceLocation(Record
, Idx
);
756 D
->QualifierRange
= ReadSourceRange(Record
, Idx
);
757 D
->Qualifier
= Reader
.ReadNestedNameSpecifier(Record
, Idx
);
758 D
->NominatedNamespace
= cast
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++]));
759 D
->CommonAncestor
= cast_or_null
<DeclContext
>(Reader
.GetDecl(Record
[Idx
++]));
762 void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl
*D
) {
764 D
->setTargetNestedNameRange(ReadSourceRange(Record
, Idx
));
765 D
->setUsingLoc(ReadSourceLocation(Record
, Idx
));
766 D
->setTargetNestedNameSpecifier(Reader
.ReadNestedNameSpecifier(Record
, Idx
));
767 ReadDeclarationNameLoc(D
->DNLoc
, D
->getDeclName(), Record
, Idx
);
770 void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
771 UnresolvedUsingTypenameDecl
*D
) {
773 D
->TargetNestedNameRange
= ReadSourceRange(Record
, Idx
);
774 D
->UsingLocation
= ReadSourceLocation(Record
, Idx
);
775 D
->TypenameLocation
= ReadSourceLocation(Record
, Idx
);
776 D
->TargetNestedNameSpecifier
= Reader
.ReadNestedNameSpecifier(Record
, Idx
);
779 void ASTDeclReader::ReadCXXDefinitionData(
780 struct CXXRecordDecl::DefinitionData
&Data
,
781 const RecordData
&Record
, unsigned &Idx
) {
782 Data
.UserDeclaredConstructor
= Record
[Idx
++];
783 Data
.UserDeclaredCopyConstructor
= Record
[Idx
++];
784 Data
.UserDeclaredCopyAssignment
= Record
[Idx
++];
785 Data
.UserDeclaredDestructor
= Record
[Idx
++];
786 Data
.Aggregate
= Record
[Idx
++];
787 Data
.PlainOldData
= Record
[Idx
++];
788 Data
.Empty
= Record
[Idx
++];
789 Data
.Polymorphic
= Record
[Idx
++];
790 Data
.Abstract
= Record
[Idx
++];
791 Data
.HasTrivialConstructor
= Record
[Idx
++];
792 Data
.HasTrivialCopyConstructor
= Record
[Idx
++];
793 Data
.HasTrivialCopyAssignment
= Record
[Idx
++];
794 Data
.HasTrivialDestructor
= Record
[Idx
++];
795 Data
.ComputedVisibleConversions
= Record
[Idx
++];
796 Data
.DeclaredDefaultConstructor
= Record
[Idx
++];
797 Data
.DeclaredCopyConstructor
= Record
[Idx
++];
798 Data
.DeclaredCopyAssignment
= Record
[Idx
++];
799 Data
.DeclaredDestructor
= Record
[Idx
++];
801 Data
.NumBases
= Record
[Idx
++];
803 Data
.Bases
= Reader
.GetCXXBaseSpecifiersOffset(Record
[Idx
++]);
804 Data
.NumVBases
= Record
[Idx
++];
806 Data
.VBases
= Reader
.GetCXXBaseSpecifiersOffset(Record
[Idx
++]);
808 Reader
.ReadUnresolvedSet(Data
.Conversions
, Record
, Idx
);
809 Reader
.ReadUnresolvedSet(Data
.VisibleConversions
, Record
, Idx
);
810 assert(Data
.Definition
&& "Data.Definition should be already set!");
812 = cast_or_null
<FriendDecl
>(Reader
.GetDecl(Record
[Idx
++]));
815 void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl
*D
,
816 CXXRecordDecl
*DefinitionDecl
,
817 const RecordData
&Record
,
819 ASTContext
&C
= *Reader
.getContext();
821 if (D
== DefinitionDecl
) {
822 D
->DefinitionData
= new (C
) struct CXXRecordDecl::DefinitionData(D
);
823 ReadCXXDefinitionData(*D
->DefinitionData
, Record
, Idx
);
824 // We read the definition info. Check if there are pending forward
825 // references that need to point to this DefinitionData pointer.
826 ASTReader::PendingForwardRefsMap::iterator
827 FindI
= Reader
.PendingForwardRefs
.find(D
);
828 if (FindI
!= Reader
.PendingForwardRefs
.end()) {
829 ASTReader::ForwardRefs
&Refs
= FindI
->second
;
830 for (ASTReader::ForwardRefs::iterator
831 I
= Refs
.begin(), E
= Refs
.end(); I
!= E
; ++I
)
832 (*I
)->DefinitionData
= D
->DefinitionData
;
834 // We later check whether PendingForwardRefs is empty to make sure all
835 // pending references were linked.
836 Reader
.PendingForwardRefs
.erase(D
);
839 } else if (DefinitionDecl
) {
840 if (DefinitionDecl
->DefinitionData
) {
841 D
->DefinitionData
= DefinitionDecl
->DefinitionData
;
843 // The definition is still initializing.
844 Reader
.PendingForwardRefs
[DefinitionDecl
].push_back(D
);
849 void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl
*D
) {
852 CXXRecordDecl
*DefinitionDecl
853 = cast_or_null
<CXXRecordDecl
>(Reader
.GetDecl(Record
[Idx
++]));
854 InitializeCXXDefinitionData(D
, DefinitionDecl
, Record
, Idx
);
856 ASTContext
&C
= *Reader
.getContext();
859 CXXRecNotTemplate
= 0, CXXRecTemplate
, CXXRecMemberSpecialization
861 switch ((CXXRecKind
)Record
[Idx
++]) {
863 assert(false && "Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
864 case CXXRecNotTemplate
:
867 D
->TemplateOrInstantiation
868 = cast
<ClassTemplateDecl
>(Reader
.GetDecl(Record
[Idx
++]));
870 case CXXRecMemberSpecialization
: {
871 CXXRecordDecl
*RD
= cast
<CXXRecordDecl
>(Reader
.GetDecl(Record
[Idx
++]));
872 TemplateSpecializationKind TSK
= (TemplateSpecializationKind
)Record
[Idx
++];
873 SourceLocation POI
= ReadSourceLocation(Record
, Idx
);
874 MemberSpecializationInfo
*MSI
= new (C
) MemberSpecializationInfo(RD
, TSK
);
875 MSI
->setPointOfInstantiation(POI
);
876 D
->TemplateOrInstantiation
= MSI
;
881 // Load the key function to avoid deserializing every method so we can
883 if (D
->IsDefinition
) {
885 = cast_or_null
<CXXMethodDecl
>(Reader
.GetDecl(Record
[Idx
++]));
887 C
.KeyFunctions
[D
] = Key
;
891 void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl
*D
) {
892 VisitFunctionDecl(D
);
893 unsigned NumOverridenMethods
= Record
[Idx
++];
894 while (NumOverridenMethods
--) {
895 CXXMethodDecl
*MD
= cast
<CXXMethodDecl
>(Reader
.GetDecl(Record
[Idx
++]));
896 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
897 // MD may be initializing.
898 Reader
.getContext()->addOverriddenMethod(D
, MD
);
902 void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl
*D
) {
903 VisitCXXMethodDecl(D
);
905 D
->IsExplicitSpecified
= Record
[Idx
++];
906 D
->ImplicitlyDefined
= Record
[Idx
++];
907 llvm::tie(D
->CtorInitializers
, D
->NumCtorInitializers
)
908 = Reader
.ReadCXXCtorInitializers(F
, Record
, Idx
);
911 void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl
*D
) {
912 VisitCXXMethodDecl(D
);
914 D
->ImplicitlyDefined
= Record
[Idx
++];
915 D
->OperatorDelete
= cast_or_null
<FunctionDecl
>(Reader
.GetDecl(Record
[Idx
++]));
918 void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl
*D
) {
919 VisitCXXMethodDecl(D
);
920 D
->IsExplicitSpecified
= Record
[Idx
++];
923 void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl
*D
) {
925 D
->setColonLoc(ReadSourceLocation(Record
, Idx
));
928 void ASTDeclReader::VisitFriendDecl(FriendDecl
*D
) {
931 D
->Friend
= GetTypeSourceInfo(Record
, Idx
);
933 D
->Friend
= cast
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++]));
934 D
->NextFriend
= Record
[Idx
++];
935 D
->UnsupportedFriend
= (Record
[Idx
++] != 0);
936 D
->FriendLoc
= ReadSourceLocation(Record
, Idx
);
939 void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl
*D
) {
941 unsigned NumParams
= Record
[Idx
++];
942 D
->NumParams
= NumParams
;
943 D
->Params
= new TemplateParameterList
*[NumParams
];
944 for (unsigned i
= 0; i
!= NumParams
; ++i
)
945 D
->Params
[i
] = Reader
.ReadTemplateParameterList(F
, Record
, Idx
);
946 if (Record
[Idx
++]) // HasFriendDecl
947 D
->Friend
= cast
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++]));
949 D
->Friend
= GetTypeSourceInfo(Record
, Idx
);
950 D
->FriendLoc
= ReadSourceLocation(Record
, Idx
);
953 void ASTDeclReader::VisitTemplateDecl(TemplateDecl
*D
) {
956 NamedDecl
*TemplatedDecl
957 = cast_or_null
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++]));
958 TemplateParameterList
* TemplateParams
959 = Reader
.ReadTemplateParameterList(F
, Record
, Idx
);
960 D
->init(TemplatedDecl
, TemplateParams
);
963 void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl
*D
) {
964 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
965 // can be used while this is still initializing.
967 assert(D
->CommonOrPrev
.isNull() && "getCommonPtr was called earlier on this");
968 RedeclarableTemplateDecl
*PrevDecl
=
969 cast_or_null
<RedeclarableTemplateDecl
>(Reader
.GetDecl(Record
[Idx
++]));
970 assert((PrevDecl
== 0 || PrevDecl
->getKind() == D
->getKind()) &&
971 "PrevDecl kind mismatch");
973 D
->CommonOrPrev
= PrevDecl
;
975 D
->CommonOrPrev
= D
->newCommon(*Reader
.getContext());
976 if (RedeclarableTemplateDecl
*RTD
977 = cast_or_null
<RedeclarableTemplateDecl
>(Reader
.GetDecl(Record
[Idx
++]))) {
978 assert(RTD
->getKind() == D
->getKind() &&
979 "InstantiatedFromMemberTemplate kind mismatch");
980 D
->setInstantiatedFromMemberTemplateImpl(RTD
);
982 D
->setMemberSpecialization();
985 RedeclarableTemplateDecl
*LatestDecl
=
986 cast_or_null
<RedeclarableTemplateDecl
>(Reader
.GetDecl(Record
[Idx
++]));
988 // This decl is a first one and the latest declaration that it points to is
989 // in the same AST file. However, if this actually needs to point to a
990 // redeclaration in another AST file, we need to update it by checking
991 // the FirstLatestDeclIDs map which tracks this kind of decls.
992 assert(Reader
.GetDecl(ThisDeclID
) == D
&& "Invalid ThisDeclID ?");
993 ASTReader::FirstLatestDeclIDMap::iterator I
994 = Reader
.FirstLatestDeclIDs
.find(ThisDeclID
);
995 if (I
!= Reader
.FirstLatestDeclIDs
.end()) {
996 Decl
*NewLatest
= Reader
.GetDecl(I
->second
);
997 assert((LatestDecl
->getLocation().isInvalid() ||
998 NewLatest
->getLocation().isInvalid() ||
999 !Reader
.SourceMgr
.isBeforeInTranslationUnit(
1000 NewLatest
->getLocation(),
1001 LatestDecl
->getLocation())) &&
1002 "The new latest is supposed to come after the previous latest");
1003 LatestDecl
= cast
<RedeclarableTemplateDecl
>(NewLatest
);
1006 assert(LatestDecl
->getKind() == D
->getKind() && "Latest kind mismatch");
1007 D
->getCommonPtr()->Latest
= LatestDecl
;
1010 VisitTemplateDecl(D
);
1011 D
->IdentifierNamespace
= Record
[Idx
++];
1014 void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl
*D
) {
1015 VisitRedeclarableTemplateDecl(D
);
1017 if (D
->getPreviousDeclaration() == 0) {
1018 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1019 // the specializations.
1020 llvm::SmallVector
<serialization::DeclID
, 2> SpecIDs
;
1021 SpecIDs
.push_back(0);
1024 unsigned Size
= Record
[Idx
++];
1026 SpecIDs
.append(Record
.begin() + Idx
, Record
.begin() + Idx
+ Size
);
1029 // Partial specializations.
1030 Size
= Record
[Idx
++];
1032 SpecIDs
.append(Record
.begin() + Idx
, Record
.begin() + Idx
+ Size
);
1036 typedef serialization::DeclID DeclID
;
1038 ClassTemplateDecl::Common
*CommonPtr
= D
->getCommonPtr();
1039 CommonPtr
->LazySpecializations
1040 = new (*Reader
.getContext()) DeclID
[SpecIDs
.size()];
1041 memcpy(CommonPtr
->LazySpecializations
, SpecIDs
.data(),
1042 SpecIDs
.size() * sizeof(DeclID
));
1045 // InjectedClassNameType is computed.
1049 void ASTDeclReader::VisitClassTemplateSpecializationDecl(
1050 ClassTemplateSpecializationDecl
*D
) {
1051 VisitCXXRecordDecl(D
);
1053 ASTContext
&C
= *Reader
.getContext();
1054 if (Decl
*InstD
= Reader
.GetDecl(Record
[Idx
++])) {
1055 if (ClassTemplateDecl
*CTD
= dyn_cast
<ClassTemplateDecl
>(InstD
)) {
1056 D
->SpecializedTemplate
= CTD
;
1058 llvm::SmallVector
<TemplateArgument
, 8> TemplArgs
;
1059 Reader
.ReadTemplateArgumentList(TemplArgs
, F
, Record
, Idx
);
1060 TemplateArgumentList
*ArgList
1061 = TemplateArgumentList::CreateCopy(C
, TemplArgs
.data(),
1063 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization
*PS
1064 = new (C
) ClassTemplateSpecializationDecl::
1065 SpecializedPartialSpecialization();
1066 PS
->PartialSpecialization
1067 = cast
<ClassTemplatePartialSpecializationDecl
>(InstD
);
1068 PS
->TemplateArgs
= ArgList
;
1069 D
->SpecializedTemplate
= PS
;
1074 if (TypeSourceInfo
*TyInfo
= GetTypeSourceInfo(Record
, Idx
)) {
1075 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo
*ExplicitInfo
1076 = new (C
) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo
;
1077 ExplicitInfo
->TypeAsWritten
= TyInfo
;
1078 ExplicitInfo
->ExternLoc
= ReadSourceLocation(Record
, Idx
);
1079 ExplicitInfo
->TemplateKeywordLoc
= ReadSourceLocation(Record
, Idx
);
1080 D
->ExplicitInfo
= ExplicitInfo
;
1083 llvm::SmallVector
<TemplateArgument
, 8> TemplArgs
;
1084 Reader
.ReadTemplateArgumentList(TemplArgs
, F
, Record
, Idx
);
1085 D
->TemplateArgs
= TemplateArgumentList::CreateCopy(C
, TemplArgs
.data(),
1087 D
->PointOfInstantiation
= ReadSourceLocation(Record
, Idx
);
1088 D
->SpecializationKind
= (TemplateSpecializationKind
)Record
[Idx
++];
1090 if (D
->isCanonicalDecl()) { // It's kept in the folding set.
1091 ClassTemplateDecl
*CanonPattern
1092 = cast
<ClassTemplateDecl
>(Reader
.GetDecl(Record
[Idx
++]));
1093 if (ClassTemplatePartialSpecializationDecl
*Partial
1094 = dyn_cast
<ClassTemplatePartialSpecializationDecl
>(D
)) {
1095 CanonPattern
->getCommonPtr()->PartialSpecializations
.InsertNode(Partial
);
1097 CanonPattern
->getCommonPtr()->Specializations
.InsertNode(D
);
1102 void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
1103 ClassTemplatePartialSpecializationDecl
*D
) {
1104 VisitClassTemplateSpecializationDecl(D
);
1106 ASTContext
&C
= *Reader
.getContext();
1107 D
->TemplateParams
= Reader
.ReadTemplateParameterList(F
, Record
, Idx
);
1109 unsigned NumArgs
= Record
[Idx
++];
1111 D
->NumArgsAsWritten
= NumArgs
;
1112 D
->ArgsAsWritten
= new (C
) TemplateArgumentLoc
[NumArgs
];
1113 for (unsigned i
=0; i
!= NumArgs
; ++i
)
1114 D
->ArgsAsWritten
[i
] = Reader
.ReadTemplateArgumentLoc(F
, Record
, Idx
);
1117 D
->SequenceNumber
= Record
[Idx
++];
1119 // These are read/set from/to the first declaration.
1120 if (D
->getPreviousDeclaration() == 0) {
1121 D
->InstantiatedFromMember
.setPointer(
1122 cast_or_null
<ClassTemplatePartialSpecializationDecl
>(
1123 Reader
.GetDecl(Record
[Idx
++])));
1124 D
->InstantiatedFromMember
.setInt(Record
[Idx
++]);
1128 void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl
*D
) {
1129 VisitRedeclarableTemplateDecl(D
);
1131 if (D
->getPreviousDeclaration() == 0) {
1132 // This FunctionTemplateDecl owns a CommonPtr; read it.
1134 // Read the function specialization declarations.
1135 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
1136 // when reading the specialized FunctionDecl.
1137 unsigned NumSpecs
= Record
[Idx
++];
1139 Reader
.GetDecl(Record
[Idx
++]);
1143 void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl
*D
) {
1146 D
->setDeclaredWithTypename(Record
[Idx
++]);
1147 D
->setParameterPack(Record
[Idx
++]);
1149 bool Inherited
= Record
[Idx
++];
1150 TypeSourceInfo
*DefArg
= GetTypeSourceInfo(Record
, Idx
);
1151 D
->setDefaultArgument(DefArg
, Inherited
);
1154 void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl
*D
) {
1156 // TemplateParmPosition.
1157 D
->setDepth(Record
[Idx
++]);
1158 D
->setPosition(Record
[Idx
++]);
1159 if (D
->isExpandedParameterPack()) {
1160 void **Data
= reinterpret_cast<void **>(D
+ 1);
1161 for (unsigned I
= 0, N
= D
->getNumExpansionTypes(); I
!= N
; ++I
) {
1162 Data
[2*I
] = Reader
.GetType(Record
[Idx
++]).getAsOpaquePtr();
1163 Data
[2*I
+ 1] = GetTypeSourceInfo(Record
, Idx
);
1166 // Rest of NonTypeTemplateParmDecl.
1167 D
->ParameterPack
= Record
[Idx
++];
1168 if (Record
[Idx
++]) {
1169 Expr
*DefArg
= Reader
.ReadExpr(F
);
1170 bool Inherited
= Record
[Idx
++];
1171 D
->setDefaultArgument(DefArg
, Inherited
);
1176 void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl
*D
) {
1177 VisitTemplateDecl(D
);
1178 // TemplateParmPosition.
1179 D
->setDepth(Record
[Idx
++]);
1180 D
->setPosition(Record
[Idx
++]);
1181 // Rest of TemplateTemplateParmDecl.
1182 TemplateArgumentLoc Arg
= Reader
.ReadTemplateArgumentLoc(F
, Record
, Idx
);
1183 bool IsInherited
= Record
[Idx
++];
1184 D
->setDefaultArgument(Arg
, IsInherited
);
1185 D
->ParameterPack
= Record
[Idx
++];
1188 void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl
*D
) {
1190 D
->AssertExpr
= Reader
.ReadExpr(F
);
1191 D
->Message
= cast
<StringLiteral
>(Reader
.ReadExpr(F
));
1194 std::pair
<uint64_t, uint64_t>
1195 ASTDeclReader::VisitDeclContext(DeclContext
*DC
) {
1196 uint64_t LexicalOffset
= Record
[Idx
++];
1197 uint64_t VisibleOffset
= Record
[Idx
++];
1198 return std::make_pair(LexicalOffset
, VisibleOffset
);
1201 template <typename T
>
1202 void ASTDeclReader::VisitRedeclarable(Redeclarable
<T
> *D
) {
1203 enum RedeclKind
{ NoRedeclaration
= 0, PointsToPrevious
, PointsToLatest
};
1204 RedeclKind Kind
= (RedeclKind
)Record
[Idx
++];
1207 assert(0 && "Out of sync with ASTDeclWriter::VisitRedeclarable or messed up"
1209 case NoRedeclaration
:
1211 case PointsToPrevious
:
1212 D
->RedeclLink
= typename Redeclarable
<T
>::PreviousDeclLink(
1213 cast_or_null
<T
>(Reader
.GetDecl(Record
[Idx
++])));
1215 case PointsToLatest
:
1216 D
->RedeclLink
= typename Redeclarable
<T
>::LatestDeclLink(
1217 cast_or_null
<T
>(Reader
.GetDecl(Record
[Idx
++])));
1221 assert(!(Kind
== PointsToPrevious
&&
1222 Reader
.FirstLatestDeclIDs
.find(ThisDeclID
) !=
1223 Reader
.FirstLatestDeclIDs
.end()) &&
1224 "This decl is not first, it should not be in the map");
1225 if (Kind
== PointsToPrevious
)
1228 // This decl is a first one and the latest declaration that it points to is in
1229 // the same AST file. However, if this actually needs to point to a
1230 // redeclaration in another AST file, we need to update it by checking the
1231 // FirstLatestDeclIDs map which tracks this kind of decls.
1232 assert(Reader
.GetDecl(ThisDeclID
) == static_cast<T
*>(D
) &&
1233 "Invalid ThisDeclID ?");
1234 ASTReader::FirstLatestDeclIDMap::iterator I
1235 = Reader
.FirstLatestDeclIDs
.find(ThisDeclID
);
1236 if (I
!= Reader
.FirstLatestDeclIDs
.end()) {
1237 Decl
*NewLatest
= Reader
.GetDecl(I
->second
);
1239 = typename Redeclarable
<T
>::LatestDeclLink(cast_or_null
<T
>(NewLatest
));
1243 //===----------------------------------------------------------------------===//
1244 // Attribute Reading
1245 //===----------------------------------------------------------------------===//
1247 /// \brief Reads attributes from the current stream position.
1248 void ASTReader::ReadAttributes(PerFileData
&F
, AttrVec
&Attrs
,
1249 const RecordData
&Record
, unsigned &Idx
) {
1250 for (unsigned i
= 0, e
= Record
[Idx
++]; i
!= e
; ++i
) {
1252 attr::Kind Kind
= (attr::Kind
)Record
[Idx
++];
1253 SourceLocation Loc
= ReadSourceLocation(F
, Record
, Idx
);
1255 #include "clang/Serialization/AttrPCHRead.inc"
1257 assert(New
&& "Unable to decode attribute?");
1258 Attrs
.push_back(New
);
1262 //===----------------------------------------------------------------------===//
1263 // ASTReader Implementation
1264 //===----------------------------------------------------------------------===//
1266 /// \brief Note that we have loaded the declaration with the given
1269 /// This routine notes that this declaration has already been loaded,
1270 /// so that future GetDecl calls will return this declaration rather
1271 /// than trying to load a new declaration.
1272 inline void ASTReader::LoadedDecl(unsigned Index
, Decl
*D
) {
1273 assert(!DeclsLoaded
[Index
] && "Decl loaded twice?");
1274 DeclsLoaded
[Index
] = D
;
1278 /// \brief Determine whether the consumer will be interested in seeing
1279 /// this declaration (via HandleTopLevelDecl).
1281 /// This routine should return true for anything that might affect
1282 /// code generation, e.g., inline function definitions, Objective-C
1283 /// declarations with metadata, etc.
1284 static bool isConsumerInterestedIn(Decl
*D
) {
1285 if (isa
<FileScopeAsmDecl
>(D
))
1287 if (VarDecl
*Var
= dyn_cast
<VarDecl
>(D
))
1288 return Var
->isFileVarDecl() &&
1289 Var
->isThisDeclarationADefinition() == VarDecl::Definition
;
1290 if (FunctionDecl
*Func
= dyn_cast
<FunctionDecl
>(D
))
1291 return Func
->isThisDeclarationADefinition();
1292 return isa
<ObjCProtocolDecl
>(D
) || isa
<ObjCImplementationDecl
>(D
);
1295 /// \brief Get the correct cursor and offset for loading a type.
1296 ASTReader::RecordLocation
1297 ASTReader::DeclCursorForIndex(unsigned Index
, DeclID ID
) {
1298 // See if there's an override.
1299 DeclReplacementMap::iterator It
= ReplacedDecls
.find(ID
);
1300 if (It
!= ReplacedDecls
.end())
1301 return RecordLocation(It
->second
.first
, It
->second
.second
);
1304 for (unsigned I
= 0, N
= Chain
.size(); I
!= N
; ++I
) {
1305 F
= Chain
[N
- I
- 1];
1306 if (Index
< F
->LocalNumDecls
)
1308 Index
-= F
->LocalNumDecls
;
1310 assert(F
&& F
->LocalNumDecls
> Index
&& "Broken chain");
1311 return RecordLocation(F
, F
->DeclOffsets
[Index
]);
1314 /// \brief Read the declaration at the given offset from the AST file.
1315 Decl
*ASTReader::ReadDeclRecord(unsigned Index
, DeclID ID
) {
1316 RecordLocation Loc
= DeclCursorForIndex(Index
, ID
);
1317 llvm::BitstreamCursor
&DeclsCursor
= Loc
.F
->DeclsCursor
;
1318 // Keep track of where we are in the stream, then jump back there
1319 // after reading this declaration.
1320 SavedStreamPosition
SavedPosition(DeclsCursor
);
1322 ReadingKindTracker
ReadingKind(Read_Decl
, *this);
1324 // Note that we are loading a declaration record.
1325 Deserializing
ADecl(this);
1327 DeclsCursor
.JumpToBit(Loc
.Offset
);
1329 unsigned Code
= DeclsCursor
.ReadCode();
1331 ASTDeclReader
Reader(*this, *Loc
.F
, DeclsCursor
, ID
, Record
, Idx
);
1334 switch ((DeclCode
)DeclsCursor
.ReadRecord(Code
, Record
)) {
1335 case DECL_CONTEXT_LEXICAL
:
1336 case DECL_CONTEXT_VISIBLE
:
1337 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1339 case DECL_TRANSLATION_UNIT
:
1340 assert(Index
== 0 && "Translation unit must be at index 0");
1341 D
= Context
->getTranslationUnitDecl();
1344 D
= TypedefDecl::Create(*Context
, 0, SourceLocation(), 0, 0);
1347 D
= EnumDecl::Create(*Context
, Decl::EmptyShell());
1350 D
= RecordDecl::Create(*Context
, Decl::EmptyShell());
1352 case DECL_ENUM_CONSTANT
:
1353 D
= EnumConstantDecl::Create(*Context
, 0, SourceLocation(), 0, QualType(),
1357 D
= FunctionDecl::Create(*Context
, 0, SourceLocation(), DeclarationName(),
1360 case DECL_LINKAGE_SPEC
:
1361 D
= LinkageSpecDecl::Create(*Context
, 0, SourceLocation(),
1362 (LinkageSpecDecl::LanguageIDs
)0,
1365 case DECL_NAMESPACE
:
1366 D
= NamespaceDecl::Create(*Context
, 0, SourceLocation(), 0);
1368 case DECL_NAMESPACE_ALIAS
:
1369 D
= NamespaceAliasDecl::Create(*Context
, 0, SourceLocation(),
1370 SourceLocation(), 0, SourceRange(), 0,
1371 SourceLocation(), 0);
1374 D
= UsingDecl::Create(*Context
, 0, SourceRange(), SourceLocation(),
1375 0, DeclarationNameInfo(), false);
1377 case DECL_USING_SHADOW
:
1378 D
= UsingShadowDecl::Create(*Context
, 0, SourceLocation(), 0, 0);
1380 case DECL_USING_DIRECTIVE
:
1381 D
= UsingDirectiveDecl::Create(*Context
, 0, SourceLocation(),
1382 SourceLocation(), SourceRange(), 0,
1383 SourceLocation(), 0, 0);
1385 case DECL_UNRESOLVED_USING_VALUE
:
1386 D
= UnresolvedUsingValueDecl::Create(*Context
, 0, SourceLocation(),
1388 DeclarationNameInfo());
1390 case DECL_UNRESOLVED_USING_TYPENAME
:
1391 D
= UnresolvedUsingTypenameDecl::Create(*Context
, 0, SourceLocation(),
1392 SourceLocation(), SourceRange(),
1393 0, SourceLocation(),
1396 case DECL_CXX_RECORD
:
1397 D
= CXXRecordDecl::Create(*Context
, Decl::EmptyShell());
1399 case DECL_CXX_METHOD
:
1400 D
= CXXMethodDecl::Create(*Context
, 0, DeclarationNameInfo(),
1403 case DECL_CXX_CONSTRUCTOR
:
1404 D
= CXXConstructorDecl::Create(*Context
, Decl::EmptyShell());
1406 case DECL_CXX_DESTRUCTOR
:
1407 D
= CXXDestructorDecl::Create(*Context
, Decl::EmptyShell());
1409 case DECL_CXX_CONVERSION
:
1410 D
= CXXConversionDecl::Create(*Context
, Decl::EmptyShell());
1412 case DECL_ACCESS_SPEC
:
1413 D
= AccessSpecDecl::Create(*Context
, Decl::EmptyShell());
1416 D
= FriendDecl::Create(*Context
, Decl::EmptyShell());
1418 case DECL_FRIEND_TEMPLATE
:
1419 D
= FriendTemplateDecl::Create(*Context
, Decl::EmptyShell());
1421 case DECL_CLASS_TEMPLATE
:
1422 D
= ClassTemplateDecl::Create(*Context
, 0, SourceLocation(),
1423 DeclarationName(), 0, 0, 0);
1425 case DECL_CLASS_TEMPLATE_SPECIALIZATION
:
1426 D
= ClassTemplateSpecializationDecl::Create(*Context
, Decl::EmptyShell());
1428 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION
:
1429 D
= ClassTemplatePartialSpecializationDecl::Create(*Context
,
1430 Decl::EmptyShell());
1432 case DECL_FUNCTION_TEMPLATE
:
1433 D
= FunctionTemplateDecl::Create(*Context
, 0, SourceLocation(),
1434 DeclarationName(), 0, 0);
1436 case DECL_TEMPLATE_TYPE_PARM
:
1437 D
= TemplateTypeParmDecl::Create(*Context
, Decl::EmptyShell());
1439 case DECL_NON_TYPE_TEMPLATE_PARM
:
1440 D
= NonTypeTemplateParmDecl::Create(*Context
, 0, SourceLocation(), 0,0,0,
1441 QualType(), false, 0);
1443 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK
:
1444 D
= NonTypeTemplateParmDecl::Create(*Context
, 0, SourceLocation(), 0, 0,
1445 0, QualType(), 0, 0, Record
[Idx
++],
1448 case DECL_TEMPLATE_TEMPLATE_PARM
:
1449 D
= TemplateTemplateParmDecl::Create(*Context
, 0, SourceLocation(), 0, 0,
1452 case DECL_STATIC_ASSERT
:
1453 D
= StaticAssertDecl::Create(*Context
, 0, SourceLocation(), 0, 0);
1456 case DECL_OBJC_METHOD
:
1457 D
= ObjCMethodDecl::Create(*Context
, SourceLocation(), SourceLocation(),
1458 Selector(), QualType(), 0, 0);
1460 case DECL_OBJC_INTERFACE
:
1461 D
= ObjCInterfaceDecl::Create(*Context
, 0, SourceLocation(), 0);
1463 case DECL_OBJC_IVAR
:
1464 D
= ObjCIvarDecl::Create(*Context
, 0, SourceLocation(), 0, QualType(), 0,
1465 ObjCIvarDecl::None
);
1467 case DECL_OBJC_PROTOCOL
:
1468 D
= ObjCProtocolDecl::Create(*Context
, 0, SourceLocation(), 0);
1470 case DECL_OBJC_AT_DEFS_FIELD
:
1471 D
= ObjCAtDefsFieldDecl::Create(*Context
, 0, SourceLocation(), 0,
1474 case DECL_OBJC_CLASS
:
1475 D
= ObjCClassDecl::Create(*Context
, 0, SourceLocation());
1477 case DECL_OBJC_FORWARD_PROTOCOL
:
1478 D
= ObjCForwardProtocolDecl::Create(*Context
, 0, SourceLocation());
1480 case DECL_OBJC_CATEGORY
:
1481 D
= ObjCCategoryDecl::Create(*Context
, 0, SourceLocation(),
1482 SourceLocation(), SourceLocation(), 0);
1484 case DECL_OBJC_CATEGORY_IMPL
:
1485 D
= ObjCCategoryImplDecl::Create(*Context
, 0, SourceLocation(), 0, 0);
1487 case DECL_OBJC_IMPLEMENTATION
:
1488 D
= ObjCImplementationDecl::Create(*Context
, 0, SourceLocation(), 0, 0);
1490 case DECL_OBJC_COMPATIBLE_ALIAS
:
1491 D
= ObjCCompatibleAliasDecl::Create(*Context
, 0, SourceLocation(), 0, 0);
1493 case DECL_OBJC_PROPERTY
:
1494 D
= ObjCPropertyDecl::Create(*Context
, 0, SourceLocation(), 0, SourceLocation(),
1497 case DECL_OBJC_PROPERTY_IMPL
:
1498 D
= ObjCPropertyImplDecl::Create(*Context
, 0, SourceLocation(),
1499 SourceLocation(), 0,
1500 ObjCPropertyImplDecl::Dynamic
, 0,
1504 D
= FieldDecl::Create(*Context
, 0, SourceLocation(), 0, QualType(), 0, 0,
1507 case DECL_INDIRECTFIELD
:
1508 D
= IndirectFieldDecl::Create(*Context
, 0, SourceLocation(), 0, QualType(),
1512 D
= VarDecl::Create(*Context
, 0, SourceLocation(), 0, QualType(), 0,
1516 case DECL_IMPLICIT_PARAM
:
1517 D
= ImplicitParamDecl::Create(*Context
, 0, SourceLocation(), 0, QualType());
1521 D
= ParmVarDecl::Create(*Context
, 0, SourceLocation(), 0, QualType(), 0,
1522 SC_None
, SC_None
, 0);
1524 case DECL_FILE_SCOPE_ASM
:
1525 D
= FileScopeAsmDecl::Create(*Context
, 0, SourceLocation(), 0);
1528 D
= BlockDecl::Create(*Context
, 0, SourceLocation());
1530 case DECL_CXX_BASE_SPECIFIERS
:
1531 Error("attempt to read a C++ base-specifier record as a declaration");
1535 assert(D
&& "Unknown declaration reading AST file");
1536 LoadedDecl(Index
, D
);
1539 // If this declaration is also a declaration context, get the
1540 // offsets for its tables of lexical and visible declarations.
1541 if (DeclContext
*DC
= dyn_cast
<DeclContext
>(D
)) {
1542 std::pair
<uint64_t, uint64_t> Offsets
= Reader
.VisitDeclContext(DC
);
1543 if (Offsets
.first
|| Offsets
.second
) {
1544 DC
->setHasExternalLexicalStorage(Offsets
.first
!= 0);
1545 DC
->setHasExternalVisibleStorage(Offsets
.second
!= 0);
1546 DeclContextInfo Info
;
1547 if (ReadDeclContextStorage(DeclsCursor
, Offsets
, Info
))
1549 DeclContextInfos
&Infos
= DeclContextOffsets
[DC
];
1550 // Reading the TU will happen after reading its lexical update blocks,
1551 // so we need to make sure we insert in front. For all other contexts,
1552 // the vector is empty here anyway, so there's no loss in efficiency.
1553 Infos
.insert(Infos
.begin(), Info
);
1555 // Now add the pending visible updates for this decl context, if it has
1557 DeclContextVisibleUpdatesPending::iterator I
=
1558 PendingVisibleUpdates
.find(ID
);
1559 if (I
!= PendingVisibleUpdates
.end()) {
1560 DeclContextVisibleUpdates
&U
= I
->second
;
1561 Info
.LexicalDecls
= 0;
1562 Info
.NumLexicalDecls
= 0;
1563 for (DeclContextVisibleUpdates::iterator UI
= U
.begin(), UE
= U
.end();
1565 Info
.NameLookupTableData
= *UI
;
1566 Infos
.push_back(Info
);
1568 PendingVisibleUpdates
.erase(I
);
1572 assert(Idx
== Record
.size());
1574 // The declaration may have been modified by files later in the chain.
1575 // If this is the case, read the record containing the updates from each file
1576 // and pass it to ASTDeclReader to make the modifications.
1577 DeclUpdateOffsetsMap::iterator UpdI
= DeclUpdateOffsets
.find(ID
);
1578 if (UpdI
!= DeclUpdateOffsets
.end()) {
1579 FileOffsetsTy
&UpdateOffsets
= UpdI
->second
;
1580 for (FileOffsetsTy::iterator
1581 I
= UpdateOffsets
.begin(), E
= UpdateOffsets
.end(); I
!= E
; ++I
) {
1582 PerFileData
*F
= I
->first
;
1583 uint64_t Offset
= I
->second
;
1584 llvm::BitstreamCursor
&Cursor
= F
->DeclsCursor
;
1585 SavedStreamPosition
SavedPosition(Cursor
);
1586 Cursor
.JumpToBit(Offset
);
1588 unsigned Code
= Cursor
.ReadCode();
1589 unsigned RecCode
= Cursor
.ReadRecord(Code
, Record
);
1591 assert(RecCode
== DECL_UPDATES
&& "Expected DECL_UPDATES record!");
1592 Reader
.UpdateDecl(D
, Record
);
1596 // If we have deserialized a declaration that has a definition the
1597 // AST consumer might need to know about, queue it.
1598 // We don't pass it to the consumer immediately because we may be in recursive
1599 // loading, and some declarations may still be initializing.
1600 if (isConsumerInterestedIn(D
))
1601 InterestingDecls
.push_back(D
);
1606 void ASTDeclReader::UpdateDecl(Decl
*D
, const RecordData
&Record
) {
1608 while (Idx
< Record
.size()) {
1609 switch ((DeclUpdateKind
)Record
[Idx
++]) {
1610 case UPD_CXX_SET_DEFINITIONDATA
: {
1611 CXXRecordDecl
*RD
= cast
<CXXRecordDecl
>(D
);
1613 DefinitionDecl
= cast
<CXXRecordDecl
>(Reader
.GetDecl(Record
[Idx
++]));
1614 assert(!RD
->DefinitionData
&& "DefinitionData is already set!");
1615 InitializeCXXDefinitionData(RD
, DefinitionDecl
, Record
, Idx
);
1619 case UPD_CXX_ADDED_IMPLICIT_MEMBER
:
1620 cast
<CXXRecordDecl
>(D
)->addedMember(Reader
.GetDecl(Record
[Idx
++]));
1623 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION
:
1624 // It will be added to the template's specializations set when loaded.
1625 Reader
.GetDecl(Record
[Idx
++]);