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) { }
78 static void attachPreviousDecl(Decl
*D
, Decl
*previous
);
82 void UpdateDecl(Decl
*D
, const RecordData
&Record
);
84 void VisitDecl(Decl
*D
);
85 void VisitTranslationUnitDecl(TranslationUnitDecl
*TU
);
86 void VisitNamedDecl(NamedDecl
*ND
);
87 void VisitNamespaceDecl(NamespaceDecl
*D
);
88 void VisitUsingDirectiveDecl(UsingDirectiveDecl
*D
);
89 void VisitNamespaceAliasDecl(NamespaceAliasDecl
*D
);
90 void VisitTypeDecl(TypeDecl
*TD
);
91 void VisitTypedefDecl(TypedefDecl
*TD
);
92 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl
*D
);
93 void VisitTagDecl(TagDecl
*TD
);
94 void VisitEnumDecl(EnumDecl
*ED
);
95 void VisitRecordDecl(RecordDecl
*RD
);
96 void VisitCXXRecordDecl(CXXRecordDecl
*D
);
97 void VisitClassTemplateSpecializationDecl(
98 ClassTemplateSpecializationDecl
*D
);
99 void VisitClassTemplatePartialSpecializationDecl(
100 ClassTemplatePartialSpecializationDecl
*D
);
101 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl
*D
);
102 void VisitValueDecl(ValueDecl
*VD
);
103 void VisitEnumConstantDecl(EnumConstantDecl
*ECD
);
104 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl
*D
);
105 void VisitDeclaratorDecl(DeclaratorDecl
*DD
);
106 void VisitFunctionDecl(FunctionDecl
*FD
);
107 void VisitCXXMethodDecl(CXXMethodDecl
*D
);
108 void VisitCXXConstructorDecl(CXXConstructorDecl
*D
);
109 void VisitCXXDestructorDecl(CXXDestructorDecl
*D
);
110 void VisitCXXConversionDecl(CXXConversionDecl
*D
);
111 void VisitFieldDecl(FieldDecl
*FD
);
112 void VisitIndirectFieldDecl(IndirectFieldDecl
*FD
);
113 void VisitVarDecl(VarDecl
*VD
);
114 void VisitImplicitParamDecl(ImplicitParamDecl
*PD
);
115 void VisitParmVarDecl(ParmVarDecl
*PD
);
116 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl
*D
);
117 void VisitTemplateDecl(TemplateDecl
*D
);
118 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl
*D
);
119 void VisitClassTemplateDecl(ClassTemplateDecl
*D
);
120 void VisitFunctionTemplateDecl(FunctionTemplateDecl
*D
);
121 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl
*D
);
122 void VisitUsingDecl(UsingDecl
*D
);
123 void VisitUsingShadowDecl(UsingShadowDecl
*D
);
124 void VisitLinkageSpecDecl(LinkageSpecDecl
*D
);
125 void VisitFileScopeAsmDecl(FileScopeAsmDecl
*AD
);
126 void VisitAccessSpecDecl(AccessSpecDecl
*D
);
127 void VisitFriendDecl(FriendDecl
*D
);
128 void VisitFriendTemplateDecl(FriendTemplateDecl
*D
);
129 void VisitStaticAssertDecl(StaticAssertDecl
*D
);
130 void VisitBlockDecl(BlockDecl
*BD
);
132 std::pair
<uint64_t, uint64_t> VisitDeclContext(DeclContext
*DC
);
133 template <typename T
> void VisitRedeclarable(Redeclarable
<T
> *D
);
135 // FIXME: Reorder according to DeclNodes.td?
136 void VisitObjCMethodDecl(ObjCMethodDecl
*D
);
137 void VisitObjCContainerDecl(ObjCContainerDecl
*D
);
138 void VisitObjCInterfaceDecl(ObjCInterfaceDecl
*D
);
139 void VisitObjCIvarDecl(ObjCIvarDecl
*D
);
140 void VisitObjCProtocolDecl(ObjCProtocolDecl
*D
);
141 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl
*D
);
142 void VisitObjCClassDecl(ObjCClassDecl
*D
);
143 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl
*D
);
144 void VisitObjCCategoryDecl(ObjCCategoryDecl
*D
);
145 void VisitObjCImplDecl(ObjCImplDecl
*D
);
146 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl
*D
);
147 void VisitObjCImplementationDecl(ObjCImplementationDecl
*D
);
148 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl
*D
);
149 void VisitObjCPropertyDecl(ObjCPropertyDecl
*D
);
150 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl
*D
);
154 uint64_t ASTDeclReader::GetCurrentCursorOffset() {
156 for (unsigned I
= 0, N
= Reader
.Chain
.size(); I
!= N
; ++I
) {
157 ASTReader::PerFileData
&F
= *Reader
.Chain
[N
- I
- 1];
158 if (&Cursor
== &F
.DeclsCursor
) {
159 Off
+= F
.DeclsCursor
.GetCurrentBitNo();
167 void ASTDeclReader::Visit(Decl
*D
) {
168 DeclVisitor
<ASTDeclReader
, void>::Visit(D
);
170 if (TypeDecl
*TD
= dyn_cast
<TypeDecl
>(D
)) {
171 // if we have a fully initialized TypeDecl, we can safely read its type now.
172 TD
->setTypeForDecl(Reader
.GetType(TypeIDForTypeDecl
).getTypePtrOrNull());
173 } else if (FunctionDecl
*FD
= dyn_cast
<FunctionDecl
>(D
)) {
174 // FunctionDecl's body was written last after all other Stmts/Exprs.
176 FD
->setLazyBody(GetCurrentCursorOffset());
180 void ASTDeclReader::VisitDecl(Decl
*D
) {
181 D
->setDeclContext(cast_or_null
<DeclContext
>(Reader
.GetDecl(Record
[Idx
++])));
182 D
->setLexicalDeclContext(
183 cast_or_null
<DeclContext
>(Reader
.GetDecl(Record
[Idx
++])));
184 D
->setLocation(ReadSourceLocation(Record
, Idx
));
185 D
->setInvalidDecl(Record
[Idx
++]);
186 if (Record
[Idx
++]) { // hasAttrs
188 Reader
.ReadAttributes(F
, Attrs
, Record
, Idx
);
191 D
->setImplicit(Record
[Idx
++]);
192 D
->setUsed(Record
[Idx
++]);
193 D
->setAccess((AccessSpecifier
)Record
[Idx
++]);
194 D
->setPCHLevel(Record
[Idx
++] + (F
.Type
<= ASTReader::PCH
));
197 void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl
*TU
) {
199 TU
->setAnonymousNamespace(
200 cast_or_null
<NamespaceDecl
>(Reader
.GetDecl(Record
[Idx
++])));
203 void ASTDeclReader::VisitNamedDecl(NamedDecl
*ND
) {
205 ND
->setDeclName(Reader
.ReadDeclarationName(Record
, Idx
));
208 void ASTDeclReader::VisitTypeDecl(TypeDecl
*TD
) {
210 // Delay type reading until after we have fully initialized the decl.
211 TypeIDForTypeDecl
= Record
[Idx
++];
214 void ASTDeclReader::VisitTypedefDecl(TypedefDecl
*TD
) {
216 TD
->setTypeSourceInfo(GetTypeSourceInfo(Record
, Idx
));
219 void ASTDeclReader::VisitTagDecl(TagDecl
*TD
) {
221 VisitRedeclarable(TD
);
222 TD
->IdentifierNamespace
= Record
[Idx
++];
223 TD
->setTagKind((TagDecl::TagKind
)Record
[Idx
++]);
224 TD
->setDefinition(Record
[Idx
++]);
225 TD
->setEmbeddedInDeclarator(Record
[Idx
++]);
226 TD
->setRBraceLoc(ReadSourceLocation(Record
, Idx
));
227 TD
->setTagKeywordLoc(ReadSourceLocation(Record
, Idx
));
228 if (Record
[Idx
++]) { // hasExtInfo
229 TagDecl::ExtInfo
*Info
= new (*Reader
.getContext()) TagDecl::ExtInfo();
230 ReadQualifierInfo(*Info
, Record
, Idx
);
231 TD
->TypedefDeclOrQualifier
= Info
;
233 TD
->setTypedefForAnonDecl(
234 cast_or_null
<TypedefDecl
>(Reader
.GetDecl(Record
[Idx
++])));
237 void ASTDeclReader::VisitEnumDecl(EnumDecl
*ED
) {
239 if (TypeSourceInfo
*TI
= Reader
.GetTypeSourceInfo(F
, Record
, Idx
))
240 ED
->setIntegerTypeSourceInfo(TI
);
242 ED
->setIntegerType(Reader
.GetType(Record
[Idx
++]));
243 ED
->setPromotionType(Reader
.GetType(Record
[Idx
++]));
244 ED
->setNumPositiveBits(Record
[Idx
++]);
245 ED
->setNumNegativeBits(Record
[Idx
++]);
246 ED
->IsScoped
= Record
[Idx
++];
247 ED
->IsScopedUsingClassTag
= Record
[Idx
++];
248 ED
->IsFixed
= Record
[Idx
++];
249 ED
->setInstantiationOfMemberEnum(
250 cast_or_null
<EnumDecl
>(Reader
.GetDecl(Record
[Idx
++])));
253 void ASTDeclReader::VisitRecordDecl(RecordDecl
*RD
) {
255 RD
->setHasFlexibleArrayMember(Record
[Idx
++]);
256 RD
->setAnonymousStructOrUnion(Record
[Idx
++]);
257 RD
->setHasObjectMember(Record
[Idx
++]);
260 void ASTDeclReader::VisitValueDecl(ValueDecl
*VD
) {
262 VD
->setType(Reader
.GetType(Record
[Idx
++]));
265 void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl
*ECD
) {
268 ECD
->setInitExpr(Reader
.ReadExpr(F
));
269 ECD
->setInitVal(Reader
.ReadAPSInt(Record
, Idx
));
272 void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl
*DD
) {
274 if (Record
[Idx
++]) { // hasExtInfo
275 DeclaratorDecl::ExtInfo
*Info
276 = new (*Reader
.getContext()) DeclaratorDecl::ExtInfo();
277 ReadQualifierInfo(*Info
, Record
, Idx
);
278 Info
->TInfo
= GetTypeSourceInfo(Record
, Idx
);
281 DD
->DeclInfo
= GetTypeSourceInfo(Record
, Idx
);
284 void ASTDeclReader::VisitFunctionDecl(FunctionDecl
*FD
) {
285 VisitDeclaratorDecl(FD
);
286 VisitRedeclarable(FD
);
288 ReadDeclarationNameLoc(FD
->DNLoc
, FD
->getDeclName(), Record
, Idx
);
289 FD
->IdentifierNamespace
= Record
[Idx
++];
290 switch ((FunctionDecl::TemplatedKind
)Record
[Idx
++]) {
291 default: assert(false && "Unhandled TemplatedKind!");
293 case FunctionDecl::TK_NonTemplate
:
295 case FunctionDecl::TK_FunctionTemplate
:
296 FD
->setDescribedFunctionTemplate(
297 cast
<FunctionTemplateDecl
>(Reader
.GetDecl(Record
[Idx
++])));
299 case FunctionDecl::TK_MemberSpecialization
: {
300 FunctionDecl
*InstFD
= cast
<FunctionDecl
>(Reader
.GetDecl(Record
[Idx
++]));
301 TemplateSpecializationKind TSK
= (TemplateSpecializationKind
)Record
[Idx
++];
302 SourceLocation POI
= ReadSourceLocation(Record
, Idx
);
303 FD
->setInstantiationOfMemberFunction(*Reader
.getContext(), InstFD
, TSK
);
304 FD
->getMemberSpecializationInfo()->setPointOfInstantiation(POI
);
307 case FunctionDecl::TK_FunctionTemplateSpecialization
: {
308 FunctionTemplateDecl
*Template
309 = cast
<FunctionTemplateDecl
>(Reader
.GetDecl(Record
[Idx
++]));
310 TemplateSpecializationKind TSK
= (TemplateSpecializationKind
)Record
[Idx
++];
312 // Template arguments.
313 llvm::SmallVector
<TemplateArgument
, 8> TemplArgs
;
314 Reader
.ReadTemplateArgumentList(TemplArgs
, F
, Record
, Idx
);
316 // Template args as written.
317 llvm::SmallVector
<TemplateArgumentLoc
, 8> TemplArgLocs
;
318 SourceLocation LAngleLoc
, RAngleLoc
;
319 if (Record
[Idx
++]) { // TemplateArgumentsAsWritten != 0
320 unsigned NumTemplateArgLocs
= Record
[Idx
++];
321 TemplArgLocs
.reserve(NumTemplateArgLocs
);
322 for (unsigned i
=0; i
!= NumTemplateArgLocs
; ++i
)
323 TemplArgLocs
.push_back(
324 Reader
.ReadTemplateArgumentLoc(F
, Record
, Idx
));
326 LAngleLoc
= ReadSourceLocation(Record
, Idx
);
327 RAngleLoc
= ReadSourceLocation(Record
, Idx
);
330 SourceLocation POI
= ReadSourceLocation(Record
, Idx
);
332 ASTContext
&C
= *Reader
.getContext();
333 TemplateArgumentList
*TemplArgList
334 = TemplateArgumentList::CreateCopy(C
, TemplArgs
.data(), TemplArgs
.size());
335 TemplateArgumentListInfo
*TemplArgsInfo
336 = new (C
) TemplateArgumentListInfo(LAngleLoc
, RAngleLoc
);
337 for (unsigned i
=0, e
= TemplArgLocs
.size(); i
!= e
; ++i
)
338 TemplArgsInfo
->addArgument(TemplArgLocs
[i
]);
339 FunctionTemplateSpecializationInfo
*FTInfo
340 = FunctionTemplateSpecializationInfo::Create(C
, FD
, Template
, TSK
,
343 FD
->TemplateOrSpecialization
= FTInfo
;
345 if (FD
->isCanonicalDecl()) { // if canonical add to template's set.
346 // The template that contains the specializations set. It's not safe to
347 // use getCanonicalDecl on Template since it may still be initializing.
348 FunctionTemplateDecl
*CanonTemplate
349 = cast
<FunctionTemplateDecl
>(Reader
.GetDecl(Record
[Idx
++]));
350 // Get the InsertPos by FindNodeOrInsertPos() instead of calling
351 // InsertNode(FTInfo) directly to avoid the getASTContext() call in
352 // FunctionTemplateSpecializationInfo's Profile().
353 // We avoid getASTContext because a decl in the parent hierarchy may
355 llvm::FoldingSetNodeID ID
;
356 FunctionTemplateSpecializationInfo::Profile(ID
, TemplArgs
.data(),
357 TemplArgs
.size(), C
);
359 CanonTemplate
->getSpecializations().FindNodeOrInsertPos(ID
, InsertPos
);
360 assert(InsertPos
&& "Another specialization already inserted!");
361 CanonTemplate
->getSpecializations().InsertNode(FTInfo
, InsertPos
);
365 case FunctionDecl::TK_DependentFunctionTemplateSpecialization
: {
367 UnresolvedSet
<8> TemplDecls
;
368 unsigned NumTemplates
= Record
[Idx
++];
369 while (NumTemplates
--)
370 TemplDecls
.addDecl(cast
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++])));
373 TemplateArgumentListInfo TemplArgs
;
374 unsigned NumArgs
= Record
[Idx
++];
376 TemplArgs
.addArgument(Reader
.ReadTemplateArgumentLoc(F
, Record
, Idx
));
377 TemplArgs
.setLAngleLoc(ReadSourceLocation(Record
, Idx
));
378 TemplArgs
.setRAngleLoc(ReadSourceLocation(Record
, Idx
));
380 FD
->setDependentTemplateSpecialization(*Reader
.getContext(),
381 TemplDecls
, TemplArgs
);
386 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
387 // after everything else is read.
389 FD
->SClass
= (StorageClass
)Record
[Idx
++];
390 FD
->SClassAsWritten
= (StorageClass
)Record
[Idx
++];
391 FD
->IsInline
= Record
[Idx
++];
392 FD
->IsInlineSpecified
= Record
[Idx
++];
393 FD
->IsVirtualAsWritten
= Record
[Idx
++];
394 FD
->IsPure
= Record
[Idx
++];
395 FD
->HasInheritedPrototype
= Record
[Idx
++];
396 FD
->HasWrittenPrototype
= Record
[Idx
++];
397 FD
->IsDeleted
= Record
[Idx
++];
398 FD
->IsTrivial
= Record
[Idx
++];
399 FD
->HasImplicitReturnZero
= Record
[Idx
++];
400 FD
->EndRangeLoc
= ReadSourceLocation(Record
, Idx
);
402 // Read in the parameters.
403 unsigned NumParams
= Record
[Idx
++];
404 llvm::SmallVector
<ParmVarDecl
*, 16> Params
;
405 Params
.reserve(NumParams
);
406 for (unsigned I
= 0; I
!= NumParams
; ++I
)
407 Params
.push_back(cast
<ParmVarDecl
>(Reader
.GetDecl(Record
[Idx
++])));
408 FD
->setParams(*Reader
.getContext(), Params
.data(), NumParams
);
411 void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl
*MD
) {
414 // In practice, this won't be executed (since method definitions
415 // don't occur in header files).
416 MD
->setBody(Reader
.ReadStmt(F
));
417 MD
->setSelfDecl(cast
<ImplicitParamDecl
>(Reader
.GetDecl(Record
[Idx
++])));
418 MD
->setCmdDecl(cast
<ImplicitParamDecl
>(Reader
.GetDecl(Record
[Idx
++])));
420 MD
->setInstanceMethod(Record
[Idx
++]);
421 MD
->setVariadic(Record
[Idx
++]);
422 MD
->setSynthesized(Record
[Idx
++]);
423 MD
->setDefined(Record
[Idx
++]);
424 MD
->setDeclImplementation((ObjCMethodDecl::ImplementationControl
)Record
[Idx
++]);
425 MD
->setObjCDeclQualifier((Decl::ObjCDeclQualifier
)Record
[Idx
++]);
426 MD
->setNumSelectorArgs(unsigned(Record
[Idx
++]));
427 MD
->setResultType(Reader
.GetType(Record
[Idx
++]));
428 MD
->setResultTypeSourceInfo(GetTypeSourceInfo(Record
, Idx
));
429 MD
->setEndLoc(ReadSourceLocation(Record
, Idx
));
430 unsigned NumParams
= Record
[Idx
++];
431 llvm::SmallVector
<ParmVarDecl
*, 16> Params
;
432 Params
.reserve(NumParams
);
433 for (unsigned I
= 0; I
!= NumParams
; ++I
)
434 Params
.push_back(cast
<ParmVarDecl
>(Reader
.GetDecl(Record
[Idx
++])));
435 MD
->setMethodParams(*Reader
.getContext(), Params
.data(), NumParams
,
439 void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl
*CD
) {
441 SourceLocation A
= ReadSourceLocation(Record
, Idx
);
442 SourceLocation B
= ReadSourceLocation(Record
, Idx
);
443 CD
->setAtEndRange(SourceRange(A
, B
));
446 void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl
*ID
) {
447 VisitObjCContainerDecl(ID
);
448 ID
->setTypeForDecl(Reader
.GetType(Record
[Idx
++]).getTypePtrOrNull());
449 ID
->setSuperClass(cast_or_null
<ObjCInterfaceDecl
>
450 (Reader
.GetDecl(Record
[Idx
++])));
452 // Read the directly referenced protocols and their SourceLocations.
453 unsigned NumProtocols
= Record
[Idx
++];
454 llvm::SmallVector
<ObjCProtocolDecl
*, 16> Protocols
;
455 Protocols
.reserve(NumProtocols
);
456 for (unsigned I
= 0; I
!= NumProtocols
; ++I
)
457 Protocols
.push_back(cast
<ObjCProtocolDecl
>(Reader
.GetDecl(Record
[Idx
++])));
458 llvm::SmallVector
<SourceLocation
, 16> ProtoLocs
;
459 ProtoLocs
.reserve(NumProtocols
);
460 for (unsigned I
= 0; I
!= NumProtocols
; ++I
)
461 ProtoLocs
.push_back(ReadSourceLocation(Record
, Idx
));
462 ID
->setProtocolList(Protocols
.data(), NumProtocols
, ProtoLocs
.data(),
463 *Reader
.getContext());
465 // Read the transitive closure of protocols referenced by this class.
466 NumProtocols
= Record
[Idx
++];
468 Protocols
.reserve(NumProtocols
);
469 for (unsigned I
= 0; I
!= NumProtocols
; ++I
)
470 Protocols
.push_back(cast
<ObjCProtocolDecl
>(Reader
.GetDecl(Record
[Idx
++])));
471 ID
->AllReferencedProtocols
.set(Protocols
.data(), NumProtocols
,
472 *Reader
.getContext());
475 unsigned NumIvars
= Record
[Idx
++];
476 llvm::SmallVector
<ObjCIvarDecl
*, 16> IVars
;
477 IVars
.reserve(NumIvars
);
478 for (unsigned I
= 0; I
!= NumIvars
; ++I
)
479 IVars
.push_back(cast
<ObjCIvarDecl
>(Reader
.GetDecl(Record
[Idx
++])));
481 cast_or_null
<ObjCCategoryDecl
>(Reader
.GetDecl(Record
[Idx
++])));
482 // We will rebuild this list lazily.
484 ID
->setForwardDecl(Record
[Idx
++]);
485 ID
->setImplicitInterfaceDecl(Record
[Idx
++]);
486 ID
->setClassLoc(ReadSourceLocation(Record
, Idx
));
487 ID
->setSuperClassLoc(ReadSourceLocation(Record
, Idx
));
488 ID
->setLocEnd(ReadSourceLocation(Record
, Idx
));
491 void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl
*IVD
) {
493 IVD
->setAccessControl((ObjCIvarDecl::AccessControl
)Record
[Idx
++]);
494 // This field will be built lazily.
496 bool synth
= Record
[Idx
++];
497 IVD
->setSynthesize(synth
);
500 void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl
*PD
) {
501 VisitObjCContainerDecl(PD
);
502 PD
->setForwardDecl(Record
[Idx
++]);
503 PD
->setLocEnd(ReadSourceLocation(Record
, Idx
));
504 unsigned NumProtoRefs
= Record
[Idx
++];
505 llvm::SmallVector
<ObjCProtocolDecl
*, 16> ProtoRefs
;
506 ProtoRefs
.reserve(NumProtoRefs
);
507 for (unsigned I
= 0; I
!= NumProtoRefs
; ++I
)
508 ProtoRefs
.push_back(cast
<ObjCProtocolDecl
>(Reader
.GetDecl(Record
[Idx
++])));
509 llvm::SmallVector
<SourceLocation
, 16> ProtoLocs
;
510 ProtoLocs
.reserve(NumProtoRefs
);
511 for (unsigned I
= 0; I
!= NumProtoRefs
; ++I
)
512 ProtoLocs
.push_back(ReadSourceLocation(Record
, Idx
));
513 PD
->setProtocolList(ProtoRefs
.data(), NumProtoRefs
, ProtoLocs
.data(),
514 *Reader
.getContext());
517 void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl
*FD
) {
521 void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl
*CD
) {
523 unsigned NumClassRefs
= Record
[Idx
++];
524 llvm::SmallVector
<ObjCInterfaceDecl
*, 16> ClassRefs
;
525 ClassRefs
.reserve(NumClassRefs
);
526 for (unsigned I
= 0; I
!= NumClassRefs
; ++I
)
527 ClassRefs
.push_back(cast
<ObjCInterfaceDecl
>(Reader
.GetDecl(Record
[Idx
++])));
528 llvm::SmallVector
<SourceLocation
, 16> SLocs
;
529 SLocs
.reserve(NumClassRefs
);
530 for (unsigned I
= 0; I
!= NumClassRefs
; ++I
)
531 SLocs
.push_back(ReadSourceLocation(Record
, Idx
));
532 CD
->setClassList(*Reader
.getContext(), ClassRefs
.data(), SLocs
.data(),
536 void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl
*FPD
) {
538 unsigned NumProtoRefs
= Record
[Idx
++];
539 llvm::SmallVector
<ObjCProtocolDecl
*, 16> ProtoRefs
;
540 ProtoRefs
.reserve(NumProtoRefs
);
541 for (unsigned I
= 0; I
!= NumProtoRefs
; ++I
)
542 ProtoRefs
.push_back(cast
<ObjCProtocolDecl
>(Reader
.GetDecl(Record
[Idx
++])));
543 llvm::SmallVector
<SourceLocation
, 16> ProtoLocs
;
544 ProtoLocs
.reserve(NumProtoRefs
);
545 for (unsigned I
= 0; I
!= NumProtoRefs
; ++I
)
546 ProtoLocs
.push_back(ReadSourceLocation(Record
, Idx
));
547 FPD
->setProtocolList(ProtoRefs
.data(), NumProtoRefs
, ProtoLocs
.data(),
548 *Reader
.getContext());
551 void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl
*CD
) {
552 VisitObjCContainerDecl(CD
);
553 CD
->setClassInterface(cast
<ObjCInterfaceDecl
>(Reader
.GetDecl(Record
[Idx
++])));
554 unsigned NumProtoRefs
= Record
[Idx
++];
555 llvm::SmallVector
<ObjCProtocolDecl
*, 16> ProtoRefs
;
556 ProtoRefs
.reserve(NumProtoRefs
);
557 for (unsigned I
= 0; I
!= NumProtoRefs
; ++I
)
558 ProtoRefs
.push_back(cast
<ObjCProtocolDecl
>(Reader
.GetDecl(Record
[Idx
++])));
559 llvm::SmallVector
<SourceLocation
, 16> ProtoLocs
;
560 ProtoLocs
.reserve(NumProtoRefs
);
561 for (unsigned I
= 0; I
!= NumProtoRefs
; ++I
)
562 ProtoLocs
.push_back(ReadSourceLocation(Record
, Idx
));
563 CD
->setProtocolList(ProtoRefs
.data(), NumProtoRefs
, ProtoLocs
.data(),
564 *Reader
.getContext());
565 CD
->setNextClassCategory(cast_or_null
<ObjCCategoryDecl
>(Reader
.GetDecl(Record
[Idx
++])));
566 CD
->setHasSynthBitfield(Record
[Idx
++]);
567 CD
->setAtLoc(ReadSourceLocation(Record
, Idx
));
568 CD
->setCategoryNameLoc(ReadSourceLocation(Record
, Idx
));
571 void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl
*CAD
) {
573 CAD
->setClassInterface(cast
<ObjCInterfaceDecl
>(Reader
.GetDecl(Record
[Idx
++])));
576 void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl
*D
) {
578 D
->setAtLoc(ReadSourceLocation(Record
, Idx
));
579 D
->setType(GetTypeSourceInfo(Record
, Idx
));
580 // FIXME: stable encoding
581 D
->setPropertyAttributes(
582 (ObjCPropertyDecl::PropertyAttributeKind
)Record
[Idx
++]);
583 D
->setPropertyAttributesAsWritten(
584 (ObjCPropertyDecl::PropertyAttributeKind
)Record
[Idx
++]);
585 // FIXME: stable encoding
586 D
->setPropertyImplementation(
587 (ObjCPropertyDecl::PropertyControl
)Record
[Idx
++]);
588 D
->setGetterName(Reader
.ReadDeclarationName(Record
, Idx
).getObjCSelector());
589 D
->setSetterName(Reader
.ReadDeclarationName(Record
, Idx
).getObjCSelector());
590 D
->setGetterMethodDecl(
591 cast_or_null
<ObjCMethodDecl
>(Reader
.GetDecl(Record
[Idx
++])));
592 D
->setSetterMethodDecl(
593 cast_or_null
<ObjCMethodDecl
>(Reader
.GetDecl(Record
[Idx
++])));
594 D
->setPropertyIvarDecl(
595 cast_or_null
<ObjCIvarDecl
>(Reader
.GetDecl(Record
[Idx
++])));
598 void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl
*D
) {
599 VisitObjCContainerDecl(D
);
600 D
->setClassInterface(
601 cast_or_null
<ObjCInterfaceDecl
>(Reader
.GetDecl(Record
[Idx
++])));
604 void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl
*D
) {
605 VisitObjCImplDecl(D
);
606 D
->setIdentifier(Reader
.GetIdentifierInfo(Record
, Idx
));
609 void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl
*D
) {
610 VisitObjCImplDecl(D
);
612 cast_or_null
<ObjCInterfaceDecl
>(Reader
.GetDecl(Record
[Idx
++])));
613 llvm::tie(D
->IvarInitializers
, D
->NumIvarInitializers
)
614 = Reader
.ReadCXXCtorInitializers(F
, Record
, Idx
);
615 D
->setHasSynthBitfield(Record
[Idx
++]);
619 void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl
*D
) {
621 D
->setAtLoc(ReadSourceLocation(Record
, Idx
));
623 cast_or_null
<ObjCPropertyDecl
>(Reader
.GetDecl(Record
[Idx
++])));
624 D
->PropertyIvarDecl
=
625 cast_or_null
<ObjCIvarDecl
>(Reader
.GetDecl(Record
[Idx
++]));
626 D
->IvarLoc
= ReadSourceLocation(Record
, Idx
);
627 D
->setGetterCXXConstructor(Reader
.ReadExpr(F
));
628 D
->setSetterCXXAssignment(Reader
.ReadExpr(F
));
631 void ASTDeclReader::VisitFieldDecl(FieldDecl
*FD
) {
632 VisitDeclaratorDecl(FD
);
633 FD
->setMutable(Record
[Idx
++]);
635 FD
->setBitWidth(Reader
.ReadExpr(F
));
636 if (!FD
->getDeclName()) {
637 FieldDecl
*Tmpl
= cast_or_null
<FieldDecl
>(Reader
.GetDecl(Record
[Idx
++]));
639 Reader
.getContext()->setInstantiatedFromUnnamedFieldDecl(FD
, Tmpl
);
643 void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl
*FD
) {
646 FD
->ChainingSize
= Record
[Idx
++];
647 assert(FD
->ChainingSize
>= 2 && "Anonymous chaining must be >= 2");
648 FD
->Chaining
= new (*Reader
.getContext())NamedDecl
*[FD
->ChainingSize
];
650 for (unsigned I
= 0; I
!= FD
->ChainingSize
; ++I
)
651 FD
->Chaining
[I
] = cast
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++]));
654 void ASTDeclReader::VisitVarDecl(VarDecl
*VD
) {
655 VisitDeclaratorDecl(VD
);
656 VisitRedeclarable(VD
);
657 VD
->SClass
= (StorageClass
)Record
[Idx
++];
658 VD
->setStorageClassAsWritten((StorageClass
)Record
[Idx
++]);
659 VD
->setThreadSpecified(Record
[Idx
++]);
660 VD
->setCXXDirectInitializer(Record
[Idx
++]);
661 VD
->setExceptionVariable(Record
[Idx
++]);
662 VD
->setNRVOVariable(Record
[Idx
++]);
664 VD
->setInit(Reader
.ReadExpr(F
));
666 if (Record
[Idx
++]) { // HasMemberSpecializationInfo.
667 VarDecl
*Tmpl
= cast
<VarDecl
>(Reader
.GetDecl(Record
[Idx
++]));
668 TemplateSpecializationKind TSK
= (TemplateSpecializationKind
)Record
[Idx
++];
669 SourceLocation POI
= ReadSourceLocation(Record
, Idx
);
670 Reader
.getContext()->setInstantiatedFromStaticDataMember(VD
, Tmpl
, TSK
,POI
);
674 void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl
*PD
) {
678 void ASTDeclReader::VisitParmVarDecl(ParmVarDecl
*PD
) {
680 PD
->setObjCDeclQualifier((Decl::ObjCDeclQualifier
)Record
[Idx
++]);
681 PD
->setHasInheritedDefaultArg(Record
[Idx
++]);
682 if (Record
[Idx
++]) // hasUninstantiatedDefaultArg.
683 PD
->setUninstantiatedDefaultArg(Reader
.ReadExpr(F
));
686 void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl
*AD
) {
688 AD
->setAsmString(cast
<StringLiteral
>(Reader
.ReadExpr(F
)));
691 void ASTDeclReader::VisitBlockDecl(BlockDecl
*BD
) {
693 BD
->setBody(cast_or_null
<CompoundStmt
>(Reader
.ReadStmt(F
)));
694 BD
->setSignatureAsWritten(GetTypeSourceInfo(Record
, Idx
));
695 unsigned NumParams
= Record
[Idx
++];
696 llvm::SmallVector
<ParmVarDecl
*, 16> Params
;
697 Params
.reserve(NumParams
);
698 for (unsigned I
= 0; I
!= NumParams
; ++I
)
699 Params
.push_back(cast
<ParmVarDecl
>(Reader
.GetDecl(Record
[Idx
++])));
700 BD
->setParams(Params
.data(), NumParams
);
702 bool capturesCXXThis
= Record
[Idx
++];
703 unsigned numCaptures
= Record
[Idx
++];
704 llvm::SmallVector
<BlockDecl::Capture
, 16> captures
;
705 captures
.reserve(numCaptures
);
706 for (unsigned i
= 0; i
!= numCaptures
; ++i
) {
707 VarDecl
*decl
= cast
<VarDecl
>(Reader
.GetDecl(Record
[Idx
++]));
708 unsigned flags
= Record
[Idx
++];
709 bool byRef
= (flags
& 1);
710 bool nested
= (flags
& 2);
711 Expr
*copyExpr
= ((flags
& 4) ? Reader
.ReadExpr(F
) : 0);
713 captures
.push_back(BlockDecl::Capture(decl
, byRef
, nested
, copyExpr
));
715 BD
->setCaptures(*Reader
.getContext(), captures
.begin(),
716 captures
.end(), capturesCXXThis
);
719 void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl
*D
) {
721 D
->setLanguage((LinkageSpecDecl::LanguageIDs
)Record
[Idx
++]);
722 D
->setHasBraces(Record
[Idx
++]);
725 void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl
*D
) {
727 D
->IsInline
= Record
[Idx
++];
728 D
->LBracLoc
= ReadSourceLocation(Record
, Idx
);
729 D
->RBracLoc
= ReadSourceLocation(Record
, Idx
);
730 D
->NextNamespace
= Record
[Idx
++];
732 bool IsOriginal
= Record
[Idx
++];
733 D
->OrigOrAnonNamespace
.setInt(IsOriginal
);
734 D
->OrigOrAnonNamespace
.setPointer(
735 cast_or_null
<NamespaceDecl
>(Reader
.GetDecl(Record
[Idx
++])));
738 void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl
*D
) {
740 D
->NamespaceLoc
= ReadSourceLocation(Record
, Idx
);
741 D
->setQualifierRange(ReadSourceRange(Record
, Idx
));
742 D
->setQualifier(Reader
.ReadNestedNameSpecifier(Record
, Idx
));
743 D
->IdentLoc
= ReadSourceLocation(Record
, Idx
);
744 D
->Namespace
= cast
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++]));
747 void ASTDeclReader::VisitUsingDecl(UsingDecl
*D
) {
749 D
->setUsingLocation(ReadSourceLocation(Record
, Idx
));
750 D
->setNestedNameRange(ReadSourceRange(Record
, Idx
));
751 D
->setTargetNestedNameDecl(Reader
.ReadNestedNameSpecifier(Record
, Idx
));
752 ReadDeclarationNameLoc(D
->DNLoc
, D
->getDeclName(), Record
, Idx
);
753 D
->FirstUsingShadow
= cast_or_null
<UsingShadowDecl
>(Reader
.GetDecl(Record
[Idx
++]));
754 D
->setTypeName(Record
[Idx
++]);
755 NamedDecl
*Pattern
= cast_or_null
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++]));
757 Reader
.getContext()->setInstantiatedFromUsingDecl(D
, Pattern
);
760 void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl
*D
) {
762 D
->setTargetDecl(cast
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++])));
763 D
->UsingOrNextShadow
= cast_or_null
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++]));
764 UsingShadowDecl
*Pattern
765 = cast_or_null
<UsingShadowDecl
>(Reader
.GetDecl(Record
[Idx
++]));
767 Reader
.getContext()->setInstantiatedFromUsingShadowDecl(D
, Pattern
);
770 void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl
*D
) {
772 D
->UsingLoc
= ReadSourceLocation(Record
, Idx
);
773 D
->NamespaceLoc
= ReadSourceLocation(Record
, Idx
);
774 D
->QualifierRange
= ReadSourceRange(Record
, Idx
);
775 D
->Qualifier
= Reader
.ReadNestedNameSpecifier(Record
, Idx
);
776 D
->NominatedNamespace
= cast
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++]));
777 D
->CommonAncestor
= cast_or_null
<DeclContext
>(Reader
.GetDecl(Record
[Idx
++]));
780 void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl
*D
) {
782 D
->setTargetNestedNameRange(ReadSourceRange(Record
, Idx
));
783 D
->setUsingLoc(ReadSourceLocation(Record
, Idx
));
784 D
->setTargetNestedNameSpecifier(Reader
.ReadNestedNameSpecifier(Record
, Idx
));
785 ReadDeclarationNameLoc(D
->DNLoc
, D
->getDeclName(), Record
, Idx
);
788 void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
789 UnresolvedUsingTypenameDecl
*D
) {
791 D
->TargetNestedNameRange
= ReadSourceRange(Record
, Idx
);
792 D
->UsingLocation
= ReadSourceLocation(Record
, Idx
);
793 D
->TypenameLocation
= ReadSourceLocation(Record
, Idx
);
794 D
->TargetNestedNameSpecifier
= Reader
.ReadNestedNameSpecifier(Record
, Idx
);
797 void ASTDeclReader::ReadCXXDefinitionData(
798 struct CXXRecordDecl::DefinitionData
&Data
,
799 const RecordData
&Record
, unsigned &Idx
) {
800 Data
.UserDeclaredConstructor
= Record
[Idx
++];
801 Data
.UserDeclaredCopyConstructor
= Record
[Idx
++];
802 Data
.UserDeclaredCopyAssignment
= Record
[Idx
++];
803 Data
.UserDeclaredDestructor
= Record
[Idx
++];
804 Data
.Aggregate
= Record
[Idx
++];
805 Data
.PlainOldData
= Record
[Idx
++];
806 Data
.Empty
= Record
[Idx
++];
807 Data
.Polymorphic
= Record
[Idx
++];
808 Data
.Abstract
= Record
[Idx
++];
809 Data
.HasTrivialConstructor
= Record
[Idx
++];
810 Data
.HasTrivialCopyConstructor
= Record
[Idx
++];
811 Data
.HasTrivialCopyAssignment
= Record
[Idx
++];
812 Data
.HasTrivialDestructor
= Record
[Idx
++];
813 Data
.ComputedVisibleConversions
= Record
[Idx
++];
814 Data
.DeclaredDefaultConstructor
= Record
[Idx
++];
815 Data
.DeclaredCopyConstructor
= Record
[Idx
++];
816 Data
.DeclaredCopyAssignment
= Record
[Idx
++];
817 Data
.DeclaredDestructor
= Record
[Idx
++];
819 Data
.NumBases
= Record
[Idx
++];
821 Data
.Bases
= Reader
.GetCXXBaseSpecifiersOffset(Record
[Idx
++]);
822 Data
.NumVBases
= Record
[Idx
++];
824 Data
.VBases
= Reader
.GetCXXBaseSpecifiersOffset(Record
[Idx
++]);
826 Reader
.ReadUnresolvedSet(Data
.Conversions
, Record
, Idx
);
827 Reader
.ReadUnresolvedSet(Data
.VisibleConversions
, Record
, Idx
);
828 assert(Data
.Definition
&& "Data.Definition should be already set!");
830 = cast_or_null
<FriendDecl
>(Reader
.GetDecl(Record
[Idx
++]));
833 void ASTDeclReader::InitializeCXXDefinitionData(CXXRecordDecl
*D
,
834 CXXRecordDecl
*DefinitionDecl
,
835 const RecordData
&Record
,
837 ASTContext
&C
= *Reader
.getContext();
839 if (D
== DefinitionDecl
) {
840 D
->DefinitionData
= new (C
) struct CXXRecordDecl::DefinitionData(D
);
841 ReadCXXDefinitionData(*D
->DefinitionData
, Record
, Idx
);
842 // We read the definition info. Check if there are pending forward
843 // references that need to point to this DefinitionData pointer.
844 ASTReader::PendingForwardRefsMap::iterator
845 FindI
= Reader
.PendingForwardRefs
.find(D
);
846 if (FindI
!= Reader
.PendingForwardRefs
.end()) {
847 ASTReader::ForwardRefs
&Refs
= FindI
->second
;
848 for (ASTReader::ForwardRefs::iterator
849 I
= Refs
.begin(), E
= Refs
.end(); I
!= E
; ++I
)
850 (*I
)->DefinitionData
= D
->DefinitionData
;
852 // We later check whether PendingForwardRefs is empty to make sure all
853 // pending references were linked.
854 Reader
.PendingForwardRefs
.erase(D
);
857 } else if (DefinitionDecl
) {
858 if (DefinitionDecl
->DefinitionData
) {
859 D
->DefinitionData
= DefinitionDecl
->DefinitionData
;
861 // The definition is still initializing.
862 Reader
.PendingForwardRefs
[DefinitionDecl
].push_back(D
);
867 void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl
*D
) {
870 CXXRecordDecl
*DefinitionDecl
871 = cast_or_null
<CXXRecordDecl
>(Reader
.GetDecl(Record
[Idx
++]));
872 InitializeCXXDefinitionData(D
, DefinitionDecl
, Record
, Idx
);
874 ASTContext
&C
= *Reader
.getContext();
877 CXXRecNotTemplate
= 0, CXXRecTemplate
, CXXRecMemberSpecialization
879 switch ((CXXRecKind
)Record
[Idx
++]) {
881 assert(false && "Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
882 case CXXRecNotTemplate
:
885 D
->TemplateOrInstantiation
886 = cast
<ClassTemplateDecl
>(Reader
.GetDecl(Record
[Idx
++]));
888 case CXXRecMemberSpecialization
: {
889 CXXRecordDecl
*RD
= cast
<CXXRecordDecl
>(Reader
.GetDecl(Record
[Idx
++]));
890 TemplateSpecializationKind TSK
= (TemplateSpecializationKind
)Record
[Idx
++];
891 SourceLocation POI
= ReadSourceLocation(Record
, Idx
);
892 MemberSpecializationInfo
*MSI
= new (C
) MemberSpecializationInfo(RD
, TSK
);
893 MSI
->setPointOfInstantiation(POI
);
894 D
->TemplateOrInstantiation
= MSI
;
899 // Load the key function to avoid deserializing every method so we can
901 if (D
->IsDefinition
) {
903 = cast_or_null
<CXXMethodDecl
>(Reader
.GetDecl(Record
[Idx
++]));
905 C
.KeyFunctions
[D
] = Key
;
909 void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl
*D
) {
910 VisitFunctionDecl(D
);
911 unsigned NumOverridenMethods
= Record
[Idx
++];
912 while (NumOverridenMethods
--) {
913 CXXMethodDecl
*MD
= cast
<CXXMethodDecl
>(Reader
.GetDecl(Record
[Idx
++]));
914 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
915 // MD may be initializing.
916 Reader
.getContext()->addOverriddenMethod(D
, MD
);
920 void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl
*D
) {
921 VisitCXXMethodDecl(D
);
923 D
->IsExplicitSpecified
= Record
[Idx
++];
924 D
->ImplicitlyDefined
= Record
[Idx
++];
925 llvm::tie(D
->CtorInitializers
, D
->NumCtorInitializers
)
926 = Reader
.ReadCXXCtorInitializers(F
, Record
, Idx
);
929 void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl
*D
) {
930 VisitCXXMethodDecl(D
);
932 D
->ImplicitlyDefined
= Record
[Idx
++];
933 D
->OperatorDelete
= cast_or_null
<FunctionDecl
>(Reader
.GetDecl(Record
[Idx
++]));
936 void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl
*D
) {
937 VisitCXXMethodDecl(D
);
938 D
->IsExplicitSpecified
= Record
[Idx
++];
941 void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl
*D
) {
943 D
->setColonLoc(ReadSourceLocation(Record
, Idx
));
946 void ASTDeclReader::VisitFriendDecl(FriendDecl
*D
) {
949 D
->Friend
= GetTypeSourceInfo(Record
, Idx
);
951 D
->Friend
= cast
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++]));
952 D
->NextFriend
= Record
[Idx
++];
953 D
->UnsupportedFriend
= (Record
[Idx
++] != 0);
954 D
->FriendLoc
= ReadSourceLocation(Record
, Idx
);
957 void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl
*D
) {
959 unsigned NumParams
= Record
[Idx
++];
960 D
->NumParams
= NumParams
;
961 D
->Params
= new TemplateParameterList
*[NumParams
];
962 for (unsigned i
= 0; i
!= NumParams
; ++i
)
963 D
->Params
[i
] = Reader
.ReadTemplateParameterList(F
, Record
, Idx
);
964 if (Record
[Idx
++]) // HasFriendDecl
965 D
->Friend
= cast
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++]));
967 D
->Friend
= GetTypeSourceInfo(Record
, Idx
);
968 D
->FriendLoc
= ReadSourceLocation(Record
, Idx
);
971 void ASTDeclReader::VisitTemplateDecl(TemplateDecl
*D
) {
974 NamedDecl
*TemplatedDecl
975 = cast_or_null
<NamedDecl
>(Reader
.GetDecl(Record
[Idx
++]));
976 TemplateParameterList
* TemplateParams
977 = Reader
.ReadTemplateParameterList(F
, Record
, Idx
);
978 D
->init(TemplatedDecl
, TemplateParams
);
981 void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl
*D
) {
982 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
983 // can be used while this is still initializing.
985 assert(D
->CommonOrPrev
.isNull() && "getCommonPtr was called earlier on this");
986 DeclID PreviousDeclID
= Record
[Idx
++];
987 DeclID FirstDeclID
= PreviousDeclID
? Record
[Idx
++] : 0;
988 // We delay loading of the redeclaration chain to avoid deeply nested calls.
989 // We temporarily set the first (canonical) declaration as the previous one
990 // which is the one that matters and mark the real previous DeclID to be
991 // loaded & attached later on.
992 RedeclarableTemplateDecl
*FirstDecl
=
993 cast_or_null
<RedeclarableTemplateDecl
>(Reader
.GetDecl(FirstDeclID
));
994 assert((FirstDecl
== 0 || FirstDecl
->getKind() == D
->getKind()) &&
995 "FirstDecl kind mismatch");
997 D
->CommonOrPrev
= FirstDecl
;
998 // Mark the real previous DeclID to be loaded & attached later on.
999 if (PreviousDeclID
!= FirstDeclID
)
1000 Reader
.PendingPreviousDecls
.push_back(std::make_pair(D
, PreviousDeclID
));
1002 D
->CommonOrPrev
= D
->newCommon(*Reader
.getContext());
1003 if (RedeclarableTemplateDecl
*RTD
1004 = cast_or_null
<RedeclarableTemplateDecl
>(Reader
.GetDecl(Record
[Idx
++]))) {
1005 assert(RTD
->getKind() == D
->getKind() &&
1006 "InstantiatedFromMemberTemplate kind mismatch");
1007 D
->setInstantiatedFromMemberTemplateImpl(RTD
);
1009 D
->setMemberSpecialization();
1012 RedeclarableTemplateDecl
*LatestDecl
=
1013 cast_or_null
<RedeclarableTemplateDecl
>(Reader
.GetDecl(Record
[Idx
++]));
1015 // This decl is a first one and the latest declaration that it points to is
1016 // in the same AST file. However, if this actually needs to point to a
1017 // redeclaration in another AST file, we need to update it by checking
1018 // the FirstLatestDeclIDs map which tracks this kind of decls.
1019 assert(Reader
.GetDecl(ThisDeclID
) == D
&& "Invalid ThisDeclID ?");
1020 ASTReader::FirstLatestDeclIDMap::iterator I
1021 = Reader
.FirstLatestDeclIDs
.find(ThisDeclID
);
1022 if (I
!= Reader
.FirstLatestDeclIDs
.end()) {
1023 Decl
*NewLatest
= Reader
.GetDecl(I
->second
);
1024 assert((LatestDecl
->getLocation().isInvalid() ||
1025 NewLatest
->getLocation().isInvalid() ||
1026 !Reader
.SourceMgr
.isBeforeInTranslationUnit(
1027 NewLatest
->getLocation(),
1028 LatestDecl
->getLocation())) &&
1029 "The new latest is supposed to come after the previous latest");
1030 LatestDecl
= cast
<RedeclarableTemplateDecl
>(NewLatest
);
1033 assert(LatestDecl
->getKind() == D
->getKind() && "Latest kind mismatch");
1034 D
->getCommonPtr()->Latest
= LatestDecl
;
1037 VisitTemplateDecl(D
);
1038 D
->IdentifierNamespace
= Record
[Idx
++];
1041 void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl
*D
) {
1042 VisitRedeclarableTemplateDecl(D
);
1044 if (D
->getPreviousDeclaration() == 0) {
1045 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1046 // the specializations.
1047 llvm::SmallVector
<serialization::DeclID
, 2> SpecIDs
;
1048 SpecIDs
.push_back(0);
1051 unsigned Size
= Record
[Idx
++];
1053 SpecIDs
.append(Record
.begin() + Idx
, Record
.begin() + Idx
+ Size
);
1056 // Partial specializations.
1057 Size
= Record
[Idx
++];
1059 SpecIDs
.append(Record
.begin() + Idx
, Record
.begin() + Idx
+ Size
);
1063 typedef serialization::DeclID DeclID
;
1065 ClassTemplateDecl::Common
*CommonPtr
= D
->getCommonPtr();
1066 CommonPtr
->LazySpecializations
1067 = new (*Reader
.getContext()) DeclID
[SpecIDs
.size()];
1068 memcpy(CommonPtr
->LazySpecializations
, SpecIDs
.data(),
1069 SpecIDs
.size() * sizeof(DeclID
));
1072 // InjectedClassNameType is computed.
1076 void ASTDeclReader::VisitClassTemplateSpecializationDecl(
1077 ClassTemplateSpecializationDecl
*D
) {
1078 VisitCXXRecordDecl(D
);
1080 ASTContext
&C
= *Reader
.getContext();
1081 if (Decl
*InstD
= Reader
.GetDecl(Record
[Idx
++])) {
1082 if (ClassTemplateDecl
*CTD
= dyn_cast
<ClassTemplateDecl
>(InstD
)) {
1083 D
->SpecializedTemplate
= CTD
;
1085 llvm::SmallVector
<TemplateArgument
, 8> TemplArgs
;
1086 Reader
.ReadTemplateArgumentList(TemplArgs
, F
, Record
, Idx
);
1087 TemplateArgumentList
*ArgList
1088 = TemplateArgumentList::CreateCopy(C
, TemplArgs
.data(),
1090 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization
*PS
1091 = new (C
) ClassTemplateSpecializationDecl::
1092 SpecializedPartialSpecialization();
1093 PS
->PartialSpecialization
1094 = cast
<ClassTemplatePartialSpecializationDecl
>(InstD
);
1095 PS
->TemplateArgs
= ArgList
;
1096 D
->SpecializedTemplate
= PS
;
1101 if (TypeSourceInfo
*TyInfo
= GetTypeSourceInfo(Record
, Idx
)) {
1102 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo
*ExplicitInfo
1103 = new (C
) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo
;
1104 ExplicitInfo
->TypeAsWritten
= TyInfo
;
1105 ExplicitInfo
->ExternLoc
= ReadSourceLocation(Record
, Idx
);
1106 ExplicitInfo
->TemplateKeywordLoc
= ReadSourceLocation(Record
, Idx
);
1107 D
->ExplicitInfo
= ExplicitInfo
;
1110 llvm::SmallVector
<TemplateArgument
, 8> TemplArgs
;
1111 Reader
.ReadTemplateArgumentList(TemplArgs
, F
, Record
, Idx
);
1112 D
->TemplateArgs
= TemplateArgumentList::CreateCopy(C
, TemplArgs
.data(),
1114 D
->PointOfInstantiation
= ReadSourceLocation(Record
, Idx
);
1115 D
->SpecializationKind
= (TemplateSpecializationKind
)Record
[Idx
++];
1117 if (D
->isCanonicalDecl()) { // It's kept in the folding set.
1118 ClassTemplateDecl
*CanonPattern
1119 = cast
<ClassTemplateDecl
>(Reader
.GetDecl(Record
[Idx
++]));
1120 if (ClassTemplatePartialSpecializationDecl
*Partial
1121 = dyn_cast
<ClassTemplatePartialSpecializationDecl
>(D
)) {
1122 CanonPattern
->getCommonPtr()->PartialSpecializations
.InsertNode(Partial
);
1124 CanonPattern
->getCommonPtr()->Specializations
.InsertNode(D
);
1129 void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
1130 ClassTemplatePartialSpecializationDecl
*D
) {
1131 VisitClassTemplateSpecializationDecl(D
);
1133 ASTContext
&C
= *Reader
.getContext();
1134 D
->TemplateParams
= Reader
.ReadTemplateParameterList(F
, Record
, Idx
);
1136 unsigned NumArgs
= Record
[Idx
++];
1138 D
->NumArgsAsWritten
= NumArgs
;
1139 D
->ArgsAsWritten
= new (C
) TemplateArgumentLoc
[NumArgs
];
1140 for (unsigned i
=0; i
!= NumArgs
; ++i
)
1141 D
->ArgsAsWritten
[i
] = Reader
.ReadTemplateArgumentLoc(F
, Record
, Idx
);
1144 D
->SequenceNumber
= Record
[Idx
++];
1146 // These are read/set from/to the first declaration.
1147 if (D
->getPreviousDeclaration() == 0) {
1148 D
->InstantiatedFromMember
.setPointer(
1149 cast_or_null
<ClassTemplatePartialSpecializationDecl
>(
1150 Reader
.GetDecl(Record
[Idx
++])));
1151 D
->InstantiatedFromMember
.setInt(Record
[Idx
++]);
1155 void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl
*D
) {
1156 VisitRedeclarableTemplateDecl(D
);
1158 if (D
->getPreviousDeclaration() == 0) {
1159 // This FunctionTemplateDecl owns a CommonPtr; read it.
1161 // Read the function specialization declarations.
1162 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
1163 // when reading the specialized FunctionDecl.
1164 unsigned NumSpecs
= Record
[Idx
++];
1166 Reader
.GetDecl(Record
[Idx
++]);
1170 void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl
*D
) {
1173 D
->setDeclaredWithTypename(Record
[Idx
++]);
1174 D
->setParameterPack(Record
[Idx
++]);
1176 bool Inherited
= Record
[Idx
++];
1177 TypeSourceInfo
*DefArg
= GetTypeSourceInfo(Record
, Idx
);
1178 D
->setDefaultArgument(DefArg
, Inherited
);
1181 void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl
*D
) {
1182 VisitDeclaratorDecl(D
);
1183 // TemplateParmPosition.
1184 D
->setDepth(Record
[Idx
++]);
1185 D
->setPosition(Record
[Idx
++]);
1186 if (D
->isExpandedParameterPack()) {
1187 void **Data
= reinterpret_cast<void **>(D
+ 1);
1188 for (unsigned I
= 0, N
= D
->getNumExpansionTypes(); I
!= N
; ++I
) {
1189 Data
[2*I
] = Reader
.GetType(Record
[Idx
++]).getAsOpaquePtr();
1190 Data
[2*I
+ 1] = GetTypeSourceInfo(Record
, Idx
);
1193 // Rest of NonTypeTemplateParmDecl.
1194 D
->ParameterPack
= Record
[Idx
++];
1195 if (Record
[Idx
++]) {
1196 Expr
*DefArg
= Reader
.ReadExpr(F
);
1197 bool Inherited
= Record
[Idx
++];
1198 D
->setDefaultArgument(DefArg
, Inherited
);
1203 void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl
*D
) {
1204 VisitTemplateDecl(D
);
1205 // TemplateParmPosition.
1206 D
->setDepth(Record
[Idx
++]);
1207 D
->setPosition(Record
[Idx
++]);
1208 // Rest of TemplateTemplateParmDecl.
1209 TemplateArgumentLoc Arg
= Reader
.ReadTemplateArgumentLoc(F
, Record
, Idx
);
1210 bool IsInherited
= Record
[Idx
++];
1211 D
->setDefaultArgument(Arg
, IsInherited
);
1212 D
->ParameterPack
= Record
[Idx
++];
1215 void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl
*D
) {
1217 D
->AssertExpr
= Reader
.ReadExpr(F
);
1218 D
->Message
= cast
<StringLiteral
>(Reader
.ReadExpr(F
));
1221 std::pair
<uint64_t, uint64_t>
1222 ASTDeclReader::VisitDeclContext(DeclContext
*DC
) {
1223 uint64_t LexicalOffset
= Record
[Idx
++];
1224 uint64_t VisibleOffset
= Record
[Idx
++];
1225 return std::make_pair(LexicalOffset
, VisibleOffset
);
1228 template <typename T
>
1229 void ASTDeclReader::VisitRedeclarable(Redeclarable
<T
> *D
) {
1230 enum RedeclKind
{ NoRedeclaration
= 0, PointsToPrevious
, PointsToLatest
};
1231 RedeclKind Kind
= (RedeclKind
)Record
[Idx
++];
1234 assert(0 && "Out of sync with ASTDeclWriter::VisitRedeclarable or messed up"
1236 case NoRedeclaration
:
1238 case PointsToPrevious
: {
1239 DeclID PreviousDeclID
= Record
[Idx
++];
1240 DeclID FirstDeclID
= Record
[Idx
++];
1241 // We delay loading of the redeclaration chain to avoid deeply nested calls.
1242 // We temporarily set the first (canonical) declaration as the previous one
1243 // which is the one that matters and mark the real previous DeclID to be
1244 // loaded & attached later on.
1245 D
->RedeclLink
= typename Redeclarable
<T
>::PreviousDeclLink(
1246 cast_or_null
<T
>(Reader
.GetDecl(FirstDeclID
)));
1247 if (PreviousDeclID
!= FirstDeclID
)
1248 Reader
.PendingPreviousDecls
.push_back(std::make_pair(static_cast<T
*>(D
),
1252 case PointsToLatest
:
1253 D
->RedeclLink
= typename Redeclarable
<T
>::LatestDeclLink(
1254 cast_or_null
<T
>(Reader
.GetDecl(Record
[Idx
++])));
1258 assert(!(Kind
== PointsToPrevious
&&
1259 Reader
.FirstLatestDeclIDs
.find(ThisDeclID
) !=
1260 Reader
.FirstLatestDeclIDs
.end()) &&
1261 "This decl is not first, it should not be in the map");
1262 if (Kind
== PointsToPrevious
)
1265 // This decl is a first one and the latest declaration that it points to is in
1266 // the same AST file. However, if this actually needs to point to a
1267 // redeclaration in another AST file, we need to update it by checking the
1268 // FirstLatestDeclIDs map which tracks this kind of decls.
1269 assert(Reader
.GetDecl(ThisDeclID
) == static_cast<T
*>(D
) &&
1270 "Invalid ThisDeclID ?");
1271 ASTReader::FirstLatestDeclIDMap::iterator I
1272 = Reader
.FirstLatestDeclIDs
.find(ThisDeclID
);
1273 if (I
!= Reader
.FirstLatestDeclIDs
.end()) {
1274 Decl
*NewLatest
= Reader
.GetDecl(I
->second
);
1276 = typename Redeclarable
<T
>::LatestDeclLink(cast_or_null
<T
>(NewLatest
));
1280 //===----------------------------------------------------------------------===//
1281 // Attribute Reading
1282 //===----------------------------------------------------------------------===//
1284 /// \brief Reads attributes from the current stream position.
1285 void ASTReader::ReadAttributes(PerFileData
&F
, AttrVec
&Attrs
,
1286 const RecordData
&Record
, unsigned &Idx
) {
1287 for (unsigned i
= 0, e
= Record
[Idx
++]; i
!= e
; ++i
) {
1289 attr::Kind Kind
= (attr::Kind
)Record
[Idx
++];
1290 SourceLocation Loc
= ReadSourceLocation(F
, Record
, Idx
);
1292 #include "clang/Serialization/AttrPCHRead.inc"
1294 assert(New
&& "Unable to decode attribute?");
1295 Attrs
.push_back(New
);
1299 //===----------------------------------------------------------------------===//
1300 // ASTReader Implementation
1301 //===----------------------------------------------------------------------===//
1303 /// \brief Note that we have loaded the declaration with the given
1306 /// This routine notes that this declaration has already been loaded,
1307 /// so that future GetDecl calls will return this declaration rather
1308 /// than trying to load a new declaration.
1309 inline void ASTReader::LoadedDecl(unsigned Index
, Decl
*D
) {
1310 assert(!DeclsLoaded
[Index
] && "Decl loaded twice?");
1311 DeclsLoaded
[Index
] = D
;
1315 /// \brief Determine whether the consumer will be interested in seeing
1316 /// this declaration (via HandleTopLevelDecl).
1318 /// This routine should return true for anything that might affect
1319 /// code generation, e.g., inline function definitions, Objective-C
1320 /// declarations with metadata, etc.
1321 static bool isConsumerInterestedIn(Decl
*D
) {
1322 if (isa
<FileScopeAsmDecl
>(D
))
1324 if (VarDecl
*Var
= dyn_cast
<VarDecl
>(D
))
1325 return Var
->isFileVarDecl() &&
1326 Var
->isThisDeclarationADefinition() == VarDecl::Definition
;
1327 if (FunctionDecl
*Func
= dyn_cast
<FunctionDecl
>(D
))
1328 return Func
->isThisDeclarationADefinition();
1329 return isa
<ObjCProtocolDecl
>(D
) || isa
<ObjCImplementationDecl
>(D
);
1332 /// \brief Get the correct cursor and offset for loading a type.
1333 ASTReader::RecordLocation
1334 ASTReader::DeclCursorForIndex(unsigned Index
, DeclID ID
) {
1335 // See if there's an override.
1336 DeclReplacementMap::iterator It
= ReplacedDecls
.find(ID
);
1337 if (It
!= ReplacedDecls
.end())
1338 return RecordLocation(It
->second
.first
, It
->second
.second
);
1341 for (unsigned I
= 0, N
= Chain
.size(); I
!= N
; ++I
) {
1342 F
= Chain
[N
- I
- 1];
1343 if (Index
< F
->LocalNumDecls
)
1345 Index
-= F
->LocalNumDecls
;
1347 assert(F
&& F
->LocalNumDecls
> Index
&& "Broken chain");
1348 return RecordLocation(F
, F
->DeclOffsets
[Index
]);
1351 void ASTDeclReader::attachPreviousDecl(Decl
*D
, Decl
*previous
) {
1352 assert(D
&& previous
);
1353 if (TagDecl
*TD
= dyn_cast
<TagDecl
>(D
)) {
1354 TD
->RedeclLink
.setPointer(cast
<TagDecl
>(previous
));
1355 } else if (FunctionDecl
*FD
= dyn_cast
<FunctionDecl
>(D
)) {
1356 FD
->RedeclLink
.setPointer(cast
<FunctionDecl
>(previous
));
1357 } else if (VarDecl
*VD
= dyn_cast
<VarDecl
>(D
)) {
1358 VD
->RedeclLink
.setPointer(cast
<VarDecl
>(previous
));
1360 RedeclarableTemplateDecl
*TD
= cast
<RedeclarableTemplateDecl
>(D
);
1361 TD
->CommonOrPrev
= cast
<RedeclarableTemplateDecl
>(previous
);
1365 void ASTReader::loadAndAttachPreviousDecl(Decl
*D
, serialization::DeclID ID
) {
1366 Decl
*previous
= GetDecl(ID
);
1367 ASTDeclReader::attachPreviousDecl(D
, previous
);
1370 /// \brief Read the declaration at the given offset from the AST file.
1371 Decl
*ASTReader::ReadDeclRecord(unsigned Index
, DeclID ID
) {
1372 RecordLocation Loc
= DeclCursorForIndex(Index
, ID
);
1373 llvm::BitstreamCursor
&DeclsCursor
= Loc
.F
->DeclsCursor
;
1374 // Keep track of where we are in the stream, then jump back there
1375 // after reading this declaration.
1376 SavedStreamPosition
SavedPosition(DeclsCursor
);
1378 ReadingKindTracker
ReadingKind(Read_Decl
, *this);
1380 // Note that we are loading a declaration record.
1381 Deserializing
ADecl(this);
1383 DeclsCursor
.JumpToBit(Loc
.Offset
);
1385 unsigned Code
= DeclsCursor
.ReadCode();
1387 ASTDeclReader
Reader(*this, *Loc
.F
, DeclsCursor
, ID
, Record
, Idx
);
1390 switch ((DeclCode
)DeclsCursor
.ReadRecord(Code
, Record
)) {
1391 case DECL_CONTEXT_LEXICAL
:
1392 case DECL_CONTEXT_VISIBLE
:
1393 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1395 case DECL_TRANSLATION_UNIT
:
1396 assert(Index
== 0 && "Translation unit must be at index 0");
1397 D
= Context
->getTranslationUnitDecl();
1400 D
= TypedefDecl::Create(*Context
, 0, SourceLocation(), 0, 0);
1403 D
= EnumDecl::Create(*Context
, Decl::EmptyShell());
1406 D
= RecordDecl::Create(*Context
, Decl::EmptyShell());
1408 case DECL_ENUM_CONSTANT
:
1409 D
= EnumConstantDecl::Create(*Context
, 0, SourceLocation(), 0, QualType(),
1413 D
= FunctionDecl::Create(*Context
, 0, SourceLocation(), DeclarationName(),
1416 case DECL_LINKAGE_SPEC
:
1417 D
= LinkageSpecDecl::Create(*Context
, 0, SourceLocation(),
1418 (LinkageSpecDecl::LanguageIDs
)0,
1421 case DECL_NAMESPACE
:
1422 D
= NamespaceDecl::Create(*Context
, 0, SourceLocation(), 0);
1424 case DECL_NAMESPACE_ALIAS
:
1425 D
= NamespaceAliasDecl::Create(*Context
, 0, SourceLocation(),
1426 SourceLocation(), 0, SourceRange(), 0,
1427 SourceLocation(), 0);
1430 D
= UsingDecl::Create(*Context
, 0, SourceRange(), SourceLocation(),
1431 0, DeclarationNameInfo(), false);
1433 case DECL_USING_SHADOW
:
1434 D
= UsingShadowDecl::Create(*Context
, 0, SourceLocation(), 0, 0);
1436 case DECL_USING_DIRECTIVE
:
1437 D
= UsingDirectiveDecl::Create(*Context
, 0, SourceLocation(),
1438 SourceLocation(), SourceRange(), 0,
1439 SourceLocation(), 0, 0);
1441 case DECL_UNRESOLVED_USING_VALUE
:
1442 D
= UnresolvedUsingValueDecl::Create(*Context
, 0, SourceLocation(),
1444 DeclarationNameInfo());
1446 case DECL_UNRESOLVED_USING_TYPENAME
:
1447 D
= UnresolvedUsingTypenameDecl::Create(*Context
, 0, SourceLocation(),
1448 SourceLocation(), SourceRange(),
1449 0, SourceLocation(),
1452 case DECL_CXX_RECORD
:
1453 D
= CXXRecordDecl::Create(*Context
, Decl::EmptyShell());
1455 case DECL_CXX_METHOD
:
1456 D
= CXXMethodDecl::Create(*Context
, 0, DeclarationNameInfo(),
1459 case DECL_CXX_CONSTRUCTOR
:
1460 D
= CXXConstructorDecl::Create(*Context
, Decl::EmptyShell());
1462 case DECL_CXX_DESTRUCTOR
:
1463 D
= CXXDestructorDecl::Create(*Context
, Decl::EmptyShell());
1465 case DECL_CXX_CONVERSION
:
1466 D
= CXXConversionDecl::Create(*Context
, Decl::EmptyShell());
1468 case DECL_ACCESS_SPEC
:
1469 D
= AccessSpecDecl::Create(*Context
, Decl::EmptyShell());
1472 D
= FriendDecl::Create(*Context
, Decl::EmptyShell());
1474 case DECL_FRIEND_TEMPLATE
:
1475 D
= FriendTemplateDecl::Create(*Context
, Decl::EmptyShell());
1477 case DECL_CLASS_TEMPLATE
:
1478 D
= ClassTemplateDecl::Create(*Context
, 0, SourceLocation(),
1479 DeclarationName(), 0, 0, 0);
1481 case DECL_CLASS_TEMPLATE_SPECIALIZATION
:
1482 D
= ClassTemplateSpecializationDecl::Create(*Context
, Decl::EmptyShell());
1484 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION
:
1485 D
= ClassTemplatePartialSpecializationDecl::Create(*Context
,
1486 Decl::EmptyShell());
1488 case DECL_FUNCTION_TEMPLATE
:
1489 D
= FunctionTemplateDecl::Create(*Context
, 0, SourceLocation(),
1490 DeclarationName(), 0, 0);
1492 case DECL_TEMPLATE_TYPE_PARM
:
1493 D
= TemplateTypeParmDecl::Create(*Context
, Decl::EmptyShell());
1495 case DECL_NON_TYPE_TEMPLATE_PARM
:
1496 D
= NonTypeTemplateParmDecl::Create(*Context
, 0, SourceLocation(), 0,0,0,
1497 QualType(), false, 0);
1499 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK
:
1500 D
= NonTypeTemplateParmDecl::Create(*Context
, 0, SourceLocation(), 0, 0,
1501 0, QualType(), 0, 0, Record
[Idx
++],
1504 case DECL_TEMPLATE_TEMPLATE_PARM
:
1505 D
= TemplateTemplateParmDecl::Create(*Context
, 0, SourceLocation(), 0, 0,
1508 case DECL_STATIC_ASSERT
:
1509 D
= StaticAssertDecl::Create(*Context
, 0, SourceLocation(), 0, 0);
1512 case DECL_OBJC_METHOD
:
1513 D
= ObjCMethodDecl::Create(*Context
, SourceLocation(), SourceLocation(),
1514 Selector(), QualType(), 0, 0);
1516 case DECL_OBJC_INTERFACE
:
1517 D
= ObjCInterfaceDecl::Create(*Context
, 0, SourceLocation(), 0);
1519 case DECL_OBJC_IVAR
:
1520 D
= ObjCIvarDecl::Create(*Context
, 0, SourceLocation(), 0, QualType(), 0,
1521 ObjCIvarDecl::None
);
1523 case DECL_OBJC_PROTOCOL
:
1524 D
= ObjCProtocolDecl::Create(*Context
, 0, SourceLocation(), 0);
1526 case DECL_OBJC_AT_DEFS_FIELD
:
1527 D
= ObjCAtDefsFieldDecl::Create(*Context
, 0, SourceLocation(), 0,
1530 case DECL_OBJC_CLASS
:
1531 D
= ObjCClassDecl::Create(*Context
, 0, SourceLocation());
1533 case DECL_OBJC_FORWARD_PROTOCOL
:
1534 D
= ObjCForwardProtocolDecl::Create(*Context
, 0, SourceLocation());
1536 case DECL_OBJC_CATEGORY
:
1537 D
= ObjCCategoryDecl::Create(*Context
, 0, SourceLocation(),
1538 SourceLocation(), SourceLocation(), 0);
1540 case DECL_OBJC_CATEGORY_IMPL
:
1541 D
= ObjCCategoryImplDecl::Create(*Context
, 0, SourceLocation(), 0, 0);
1543 case DECL_OBJC_IMPLEMENTATION
:
1544 D
= ObjCImplementationDecl::Create(*Context
, 0, SourceLocation(), 0, 0);
1546 case DECL_OBJC_COMPATIBLE_ALIAS
:
1547 D
= ObjCCompatibleAliasDecl::Create(*Context
, 0, SourceLocation(), 0, 0);
1549 case DECL_OBJC_PROPERTY
:
1550 D
= ObjCPropertyDecl::Create(*Context
, 0, SourceLocation(), 0, SourceLocation(),
1553 case DECL_OBJC_PROPERTY_IMPL
:
1554 D
= ObjCPropertyImplDecl::Create(*Context
, 0, SourceLocation(),
1555 SourceLocation(), 0,
1556 ObjCPropertyImplDecl::Dynamic
, 0,
1560 D
= FieldDecl::Create(*Context
, 0, SourceLocation(), 0, QualType(), 0, 0,
1563 case DECL_INDIRECTFIELD
:
1564 D
= IndirectFieldDecl::Create(*Context
, 0, SourceLocation(), 0, QualType(),
1568 D
= VarDecl::Create(*Context
, 0, SourceLocation(), 0, QualType(), 0,
1572 case DECL_IMPLICIT_PARAM
:
1573 D
= ImplicitParamDecl::Create(*Context
, 0, SourceLocation(), 0, QualType());
1577 D
= ParmVarDecl::Create(*Context
, 0, SourceLocation(), 0, QualType(), 0,
1578 SC_None
, SC_None
, 0);
1580 case DECL_FILE_SCOPE_ASM
:
1581 D
= FileScopeAsmDecl::Create(*Context
, 0, SourceLocation(), 0);
1584 D
= BlockDecl::Create(*Context
, 0, SourceLocation());
1586 case DECL_CXX_BASE_SPECIFIERS
:
1587 Error("attempt to read a C++ base-specifier record as a declaration");
1591 assert(D
&& "Unknown declaration reading AST file");
1592 LoadedDecl(Index
, D
);
1595 // If this declaration is also a declaration context, get the
1596 // offsets for its tables of lexical and visible declarations.
1597 if (DeclContext
*DC
= dyn_cast
<DeclContext
>(D
)) {
1598 std::pair
<uint64_t, uint64_t> Offsets
= Reader
.VisitDeclContext(DC
);
1599 if (Offsets
.first
|| Offsets
.second
) {
1600 DC
->setHasExternalLexicalStorage(Offsets
.first
!= 0);
1601 DC
->setHasExternalVisibleStorage(Offsets
.second
!= 0);
1602 DeclContextInfo Info
;
1603 if (ReadDeclContextStorage(DeclsCursor
, Offsets
, Info
))
1605 DeclContextInfos
&Infos
= DeclContextOffsets
[DC
];
1606 // Reading the TU will happen after reading its lexical update blocks,
1607 // so we need to make sure we insert in front. For all other contexts,
1608 // the vector is empty here anyway, so there's no loss in efficiency.
1609 Infos
.insert(Infos
.begin(), Info
);
1611 // Now add the pending visible updates for this decl context, if it has
1613 DeclContextVisibleUpdatesPending::iterator I
=
1614 PendingVisibleUpdates
.find(ID
);
1615 if (I
!= PendingVisibleUpdates
.end()) {
1616 DeclContextVisibleUpdates
&U
= I
->second
;
1617 Info
.LexicalDecls
= 0;
1618 Info
.NumLexicalDecls
= 0;
1619 for (DeclContextVisibleUpdates::iterator UI
= U
.begin(), UE
= U
.end();
1621 Info
.NameLookupTableData
= *UI
;
1622 Infos
.push_back(Info
);
1624 PendingVisibleUpdates
.erase(I
);
1628 assert(Idx
== Record
.size());
1630 // The declaration may have been modified by files later in the chain.
1631 // If this is the case, read the record containing the updates from each file
1632 // and pass it to ASTDeclReader to make the modifications.
1633 DeclUpdateOffsetsMap::iterator UpdI
= DeclUpdateOffsets
.find(ID
);
1634 if (UpdI
!= DeclUpdateOffsets
.end()) {
1635 FileOffsetsTy
&UpdateOffsets
= UpdI
->second
;
1636 for (FileOffsetsTy::iterator
1637 I
= UpdateOffsets
.begin(), E
= UpdateOffsets
.end(); I
!= E
; ++I
) {
1638 PerFileData
*F
= I
->first
;
1639 uint64_t Offset
= I
->second
;
1640 llvm::BitstreamCursor
&Cursor
= F
->DeclsCursor
;
1641 SavedStreamPosition
SavedPosition(Cursor
);
1642 Cursor
.JumpToBit(Offset
);
1644 unsigned Code
= Cursor
.ReadCode();
1645 unsigned RecCode
= Cursor
.ReadRecord(Code
, Record
);
1647 assert(RecCode
== DECL_UPDATES
&& "Expected DECL_UPDATES record!");
1648 Reader
.UpdateDecl(D
, Record
);
1652 // If we have deserialized a declaration that has a definition the
1653 // AST consumer might need to know about, queue it.
1654 // We don't pass it to the consumer immediately because we may be in recursive
1655 // loading, and some declarations may still be initializing.
1656 if (isConsumerInterestedIn(D
))
1657 InterestingDecls
.push_back(D
);
1662 void ASTDeclReader::UpdateDecl(Decl
*D
, const RecordData
&Record
) {
1664 while (Idx
< Record
.size()) {
1665 switch ((DeclUpdateKind
)Record
[Idx
++]) {
1666 case UPD_CXX_SET_DEFINITIONDATA
: {
1667 CXXRecordDecl
*RD
= cast
<CXXRecordDecl
>(D
);
1669 DefinitionDecl
= cast
<CXXRecordDecl
>(Reader
.GetDecl(Record
[Idx
++]));
1670 assert(!RD
->DefinitionData
&& "DefinitionData is already set!");
1671 InitializeCXXDefinitionData(RD
, DefinitionDecl
, Record
, Idx
);
1675 case UPD_CXX_ADDED_IMPLICIT_MEMBER
:
1676 cast
<CXXRecordDecl
>(D
)->addedMember(Reader
.GetDecl(Record
[Idx
++]));
1679 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION
:
1680 // It will be added to the template's specializations set when loaded.
1681 Reader
.GetDecl(Record
[Idx
++]);