blob: 995139830d44948c35ea71014e58e3dce03557c2 [file] [log] [blame]
Sebastian Redl3b3c8742010-08-18 23:57:11 +00001//===--- ASTReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
Chris Lattner487412d2009-04-27 05:27:42 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Sebastian Redl2c499f62010-08-18 23:56:43 +000010// This file implements the ASTReader::ReadDeclRecord method, which is the
Chris Lattner487412d2009-04-27 05:27:42 +000011// entrypoint for loading a decl.
12//
13//===----------------------------------------------------------------------===//
14
Sebastian Redlf5b13462010-08-18 23:57:17 +000015#include "clang/Serialization/ASTReader.h"
Chris Lattner487412d2009-04-27 05:27:42 +000016#include "clang/AST/ASTConsumer.h"
17#include "clang/AST/ASTContext.h"
18#include "clang/AST/DeclVisitor.h"
19#include "clang/AST/DeclGroup.h"
Chris Lattnerca025db2010-05-07 21:43:38 +000020#include "clang/AST/DeclCXX.h"
21#include "clang/AST/DeclTemplate.h"
Chris Lattner487412d2009-04-27 05:27:42 +000022#include "clang/AST/Expr.h"
23using namespace clang;
Sebastian Redl539c5062010-08-18 23:57:32 +000024using namespace clang::serialization;
Chris Lattner487412d2009-04-27 05:27:42 +000025
26//===----------------------------------------------------------------------===//
27// Declaration deserialization
28//===----------------------------------------------------------------------===//
29
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000030namespace clang {
Sebastian Redlb3298c32010-08-18 23:56:48 +000031 class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> {
Sebastian Redl2c499f62010-08-18 23:56:43 +000032 ASTReader &Reader;
Sebastian Redlc67764e2010-07-22 22:43:28 +000033 llvm::BitstreamCursor &Cursor;
Sebastian Redl539c5062010-08-18 23:57:32 +000034 const DeclID ThisDeclID;
Sebastian Redl2c499f62010-08-18 23:56:43 +000035 const ASTReader::RecordData &Record;
Chris Lattner487412d2009-04-27 05:27:42 +000036 unsigned &Idx;
Sebastian Redl539c5062010-08-18 23:57:32 +000037 TypeID TypeIDForTypeDecl;
Chris Lattner487412d2009-04-27 05:27:42 +000038
Sebastian Redlc67764e2010-07-22 22:43:28 +000039 uint64_t GetCurrentCursorOffset();
40
Chris Lattner487412d2009-04-27 05:27:42 +000041 public:
Sebastian Redlb3298c32010-08-18 23:56:48 +000042 ASTDeclReader(ASTReader &Reader, llvm::BitstreamCursor &Cursor,
Sebastian Redl539c5062010-08-18 23:57:32 +000043 DeclID thisDeclID, const ASTReader::RecordData &Record,
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +000044 unsigned &Idx)
45 : Reader(Reader), Cursor(Cursor), ThisDeclID(thisDeclID), Record(Record),
Douglas Gregor1c283312010-08-11 12:19:30 +000046 Idx(Idx), TypeIDForTypeDecl(0) { }
Chris Lattner487412d2009-04-27 05:27:42 +000047
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +000048 void Visit(Decl *D);
49
Chris Lattner487412d2009-04-27 05:27:42 +000050 void VisitDecl(Decl *D);
51 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
52 void VisitNamedDecl(NamedDecl *ND);
Douglas Gregore31bbd92010-02-21 18:22:14 +000053 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000054 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
55 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000056 void VisitTypeDecl(TypeDecl *TD);
57 void VisitTypedefDecl(TypedefDecl *TD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000058 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000059 void VisitTagDecl(TagDecl *TD);
60 void VisitEnumDecl(EnumDecl *ED);
61 void VisitRecordDecl(RecordDecl *RD);
Chris Lattnerca025db2010-05-07 21:43:38 +000062 void VisitCXXRecordDecl(CXXRecordDecl *D);
63 void VisitClassTemplateSpecializationDecl(
64 ClassTemplateSpecializationDecl *D);
65 void VisitClassTemplatePartialSpecializationDecl(
66 ClassTemplatePartialSpecializationDecl *D);
67 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000068 void VisitValueDecl(ValueDecl *VD);
69 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000070 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +000071 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +000072 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattnerca025db2010-05-07 21:43:38 +000073 void VisitCXXMethodDecl(CXXMethodDecl *D);
74 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
75 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
76 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000077 void VisitFieldDecl(FieldDecl *FD);
78 void VisitVarDecl(VarDecl *VD);
79 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
80 void VisitParmVarDecl(ParmVarDecl *PD);
Chris Lattnerca025db2010-05-07 21:43:38 +000081 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
82 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +000083 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000084 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +000085 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000086 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +000087 void VisitUsingDecl(UsingDecl *D);
88 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000089 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000090 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Abramo Bagnarad7340582010-06-05 05:09:32 +000091 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000092 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000093 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
94 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +000095 void VisitBlockDecl(BlockDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +000096
Chris Lattner487412d2009-04-27 05:27:42 +000097 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +000098 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000099
Alexis Hunted053252010-05-30 07:21:58 +0000100 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-04-27 05:27:42 +0000101 void VisitObjCMethodDecl(ObjCMethodDecl *D);
102 void VisitObjCContainerDecl(ObjCContainerDecl *D);
103 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
104 void VisitObjCIvarDecl(ObjCIvarDecl *D);
105 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
106 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
107 void VisitObjCClassDecl(ObjCClassDecl *D);
108 void VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *D);
109 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
110 void VisitObjCImplDecl(ObjCImplDecl *D);
111 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
112 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
113 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
114 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
115 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
116 };
117}
118
Sebastian Redlb3298c32010-08-18 23:56:48 +0000119uint64_t ASTDeclReader::GetCurrentCursorOffset() {
Sebastian Redlc67764e2010-07-22 22:43:28 +0000120 uint64_t Off = 0;
121 for (unsigned I = 0, N = Reader.Chain.size(); I != N; ++I) {
Sebastian Redl2c499f62010-08-18 23:56:43 +0000122 ASTReader::PerFileData &F = *Reader.Chain[N - I - 1];
Sebastian Redlc67764e2010-07-22 22:43:28 +0000123 if (&Cursor == &F.DeclsCursor) {
124 Off += F.DeclsCursor.GetCurrentBitNo();
125 break;
126 }
127 Off += F.SizeInBits;
128 }
129 return Off;
130}
131
Sebastian Redlb3298c32010-08-18 23:56:48 +0000132void ASTDeclReader::Visit(Decl *D) {
133 DeclVisitor<ASTDeclReader, void>::Visit(D);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000134
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000135 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
Douglas Gregor1c283312010-08-11 12:19:30 +0000136 // if we have a fully initialized TypeDecl, we can safely read its type now.
137 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtr());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000138 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
139 // FunctionDecl's body was written last after all other Stmts/Exprs.
140 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000141 FD->setLazyBody(GetCurrentCursorOffset());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000142 }
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000143}
144
Sebastian Redlb3298c32010-08-18 23:56:48 +0000145void ASTDeclReader::VisitDecl(Decl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000146 D->setDeclContext(cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
147 D->setLexicalDeclContext(
148 cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++])));
149 D->setLocation(SourceLocation::getFromRawEncoding(Record[Idx++]));
150 D->setInvalidDecl(Record[Idx++]);
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000151 if (Record[Idx++]) {
152 AttrVec Attrs;
153 Reader.ReadAttributes(Cursor, Attrs);
154 D->setAttrs(Attrs);
155 }
Chris Lattner487412d2009-04-27 05:27:42 +0000156 D->setImplicit(Record[Idx++]);
Douglas Gregorc9c02ed2009-06-19 23:52:42 +0000157 D->setUsed(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000158 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor16bef852009-10-16 20:01:17 +0000159 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner487412d2009-04-27 05:27:42 +0000160}
161
Sebastian Redlb3298c32010-08-18 23:56:48 +0000162void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
Chris Lattner487412d2009-04-27 05:27:42 +0000163 VisitDecl(TU);
Chris Lattnerca025db2010-05-07 21:43:38 +0000164 TU->setAnonymousNamespace(
165 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000166}
167
Sebastian Redlb3298c32010-08-18 23:56:48 +0000168void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) {
Chris Lattner487412d2009-04-27 05:27:42 +0000169 VisitDecl(ND);
Mike Stump11289f42009-09-09 15:08:12 +0000170 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000171}
172
Sebastian Redlb3298c32010-08-18 23:56:48 +0000173void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000174 VisitNamedDecl(TD);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000175 // Delay type reading until after we have fully initialized the decl.
Douglas Gregor1c283312010-08-11 12:19:30 +0000176 TypeIDForTypeDecl = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000177}
178
Sebastian Redlb3298c32010-08-18 23:56:48 +0000179void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000180 VisitTypeDecl(TD);
Sebastian Redlc67764e2010-07-22 22:43:28 +0000181 TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000182}
183
Sebastian Redlb3298c32010-08-18 23:56:48 +0000184void ASTDeclReader::VisitTagDecl(TagDecl *TD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000185 VisitTypeDecl(TD);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000186 VisitRedeclarable(TD);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000187 TD->IdentifierNamespace = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000188 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
189 TD->setDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000190 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis664b6902009-07-14 03:18:02 +0000191 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor82fe3e32009-07-21 14:46:17 +0000192 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCall3e11ebe2010-03-15 10:12:16 +0000193 // FIXME: maybe read optional qualifier and its range.
194 TD->setTypedefForAnonDecl(
195 cast_or_null<TypedefDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000196}
197
Sebastian Redlb3298c32010-08-18 23:56:48 +0000198void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
Chris Lattner487412d2009-04-27 05:27:42 +0000199 VisitTagDecl(ED);
200 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall56774992009-12-09 09:09:27 +0000201 ED->setPromotionType(Reader.GetType(Record[Idx++]));
John McCall9aa35be2010-05-06 08:49:23 +0000202 ED->setNumPositiveBits(Record[Idx++]);
203 ED->setNumNegativeBits(Record[Idx++]);
Argyrios Kyrtzidis282b36b2010-07-06 15:36:48 +0000204 ED->setInstantiationOfMemberEnum(
205 cast_or_null<EnumDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000206}
207
Sebastian Redlb3298c32010-08-18 23:56:48 +0000208void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000209 VisitTagDecl(RD);
210 RD->setHasFlexibleArrayMember(Record[Idx++]);
211 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000212 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000213}
214
Sebastian Redlb3298c32010-08-18 23:56:48 +0000215void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000216 VisitNamedDecl(VD);
217 VD->setType(Reader.GetType(Record[Idx++]));
218}
219
Sebastian Redlb3298c32010-08-18 23:56:48 +0000220void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000221 VisitValueDecl(ECD);
222 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000223 ECD->setInitExpr(Reader.ReadExpr(Cursor));
Chris Lattner487412d2009-04-27 05:27:42 +0000224 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
225}
226
Sebastian Redlb3298c32010-08-18 23:56:48 +0000227void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000228 VisitValueDecl(DD);
Sebastian Redlc67764e2010-07-22 22:43:28 +0000229 TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
John McCallbcd03502009-12-07 02:54:59 +0000230 if (TInfo)
231 DD->setTypeSourceInfo(TInfo);
John McCall3e11ebe2010-03-15 10:12:16 +0000232 // FIXME: read optional qualifier and its range.
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000233}
234
Sebastian Redlb3298c32010-08-18 23:56:48 +0000235void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000236 VisitDeclaratorDecl(FD);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000237 VisitRedeclarable(FD);
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000238 // FIXME: read DeclarationNameLoc.
Chris Lattnerca025db2010-05-07 21:43:38 +0000239
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000240 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000241 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000242 default: assert(false && "Unhandled TemplatedKind!");
243 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000244 case FunctionDecl::TK_NonTemplate:
245 break;
246 case FunctionDecl::TK_FunctionTemplate:
247 FD->setDescribedFunctionTemplate(
248 cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++])));
249 break;
250 case FunctionDecl::TK_MemberSpecialization: {
251 FunctionDecl *InstFD = cast<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
252 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
253 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000254 FD->setInstantiationOfMemberFunction(*Reader.getContext(), InstFD, TSK);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000255 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
256 break;
257 }
258 case FunctionDecl::TK_FunctionTemplateSpecialization: {
259 FunctionTemplateDecl *Template
260 = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
261 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
262
263 // Template arguments.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000264 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000265 Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000266
267 // Template args as written.
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000268 llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000269 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000270 if (Record[Idx++]) { // TemplateArgumentsAsWritten != 0
271 unsigned NumTemplateArgLocs = Record[Idx++];
272 TemplArgLocs.reserve(NumTemplateArgLocs);
273 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000274 TemplArgLocs.push_back(
275 Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx));
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000276
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000277 LAngleLoc = Reader.ReadSourceLocation(Record, Idx);
278 RAngleLoc = Reader.ReadSourceLocation(Record, Idx);
279 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000280
281 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000282
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000283 if (FD->isCanonicalDecl()) { // if canonical add to template's set.
284 ASTContext &C = *Reader.getContext();
285 TemplateArgumentList *TemplArgList
286 = new (C) TemplateArgumentList(C, TemplArgs.data(), TemplArgs.size());
287 TemplateArgumentListInfo *TemplArgsInfo
288 = new (C) TemplateArgumentListInfo(LAngleLoc, RAngleLoc);
289 for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
290 TemplArgsInfo->addArgument(TemplArgLocs[i]);
291
292 llvm::FoldingSetNodeID ID;
293 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(),
294 TemplArgs.size(), C);
295 void *InsertPos = 0;
296 FunctionTemplateSpecializationInfo *PrevFTInfo =
297 Template->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
298 (void)PrevFTInfo;
299 assert(!PrevFTInfo && "Another specialization already inserted!");
300 FD->setFunctionTemplateSpecialization(C, Template, TemplArgList, InsertPos,
301 TSK, TemplArgsInfo, POI);
302 }
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000303 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000304 }
305 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
306 // Templates.
307 UnresolvedSet<8> TemplDecls;
308 unsigned NumTemplates = Record[Idx++];
309 while (NumTemplates--)
310 TemplDecls.addDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
311
312 // Templates args.
313 TemplateArgumentListInfo TemplArgs;
314 unsigned NumArgs = Record[Idx++];
315 while (NumArgs--)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000316 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Cursor,Record, Idx));
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000317 TemplArgs.setLAngleLoc(Reader.ReadSourceLocation(Record, Idx));
318 TemplArgs.setRAngleLoc(Reader.ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000319
320 FD->setDependentTemplateSpecialization(*Reader.getContext(),
321 TemplDecls, TemplArgs);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000322 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000323 }
324 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000325
Sebastian Redlb3298c32010-08-18 23:56:48 +0000326 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000327 // after everything else is read.
328
John McCall8e7d6562010-08-26 03:08:43 +0000329 FD->setStorageClass((StorageClass)Record[Idx++]);
330 FD->setStorageClassAsWritten((StorageClass)Record[Idx++]);
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000331 FD->setInlineSpecified(Record[Idx++]);
332 FD->setVirtualAsWritten(Record[Idx++]);
333 FD->setPure(Record[Idx++]);
334 FD->setHasInheritedPrototype(Record[Idx++]);
335 FD->setHasWrittenPrototype(Record[Idx++]);
336 FD->setDeleted(Record[Idx++]);
337 FD->setTrivial(Record[Idx++]);
338 FD->setCopyAssignment(Record[Idx++]);
339 FD->setHasImplicitReturnZero(Record[Idx++]);
340 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
341
Chris Lattnerca025db2010-05-07 21:43:38 +0000342 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000343 unsigned NumParams = Record[Idx++];
344 llvm::SmallVector<ParmVarDecl *, 16> Params;
345 Params.reserve(NumParams);
346 for (unsigned I = 0; I != NumParams; ++I)
347 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000348 FD->setParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000349}
350
Sebastian Redlb3298c32010-08-18 23:56:48 +0000351void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000352 VisitNamedDecl(MD);
353 if (Record[Idx++]) {
354 // In practice, this won't be executed (since method definitions
355 // don't occur in header files).
Sebastian Redlc67764e2010-07-22 22:43:28 +0000356 MD->setBody(Reader.ReadStmt(Cursor));
Chris Lattner487412d2009-04-27 05:27:42 +0000357 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
358 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
359 }
360 MD->setInstanceMethod(Record[Idx++]);
361 MD->setVariadic(Record[Idx++]);
362 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000363 MD->setDefined(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000364 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
365 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahaniand9235db2010-04-08 21:29:11 +0000366 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000367 MD->setResultType(Reader.GetType(Record[Idx++]));
Sebastian Redlc67764e2010-07-22 22:43:28 +0000368 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000369 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
370 unsigned NumParams = Record[Idx++];
371 llvm::SmallVector<ParmVarDecl *, 16> Params;
372 Params.reserve(NumParams);
373 for (unsigned I = 0; I != NumParams; ++I)
374 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniancdabb312010-04-09 15:40:42 +0000375 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
376 NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000377}
378
Sebastian Redlb3298c32010-08-18 23:56:48 +0000379void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000380 VisitNamedDecl(CD);
Ted Kremenekc7c64312010-01-07 01:20:12 +0000381 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
382 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
383 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner487412d2009-04-27 05:27:42 +0000384}
385
Sebastian Redlb3298c32010-08-18 23:56:48 +0000386void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Chris Lattner487412d2009-04-27 05:27:42 +0000387 VisitObjCContainerDecl(ID);
Douglas Gregor1c283312010-08-11 12:19:30 +0000388 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
Chris Lattner487412d2009-04-27 05:27:42 +0000389 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
390 (Reader.GetDecl(Record[Idx++])));
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000391
392 // Read the directly referenced protocols and their SourceLocations.
Chris Lattner487412d2009-04-27 05:27:42 +0000393 unsigned NumProtocols = Record[Idx++];
394 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
395 Protocols.reserve(NumProtocols);
396 for (unsigned I = 0; I != NumProtocols; ++I)
397 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000398 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
399 ProtoLocs.reserve(NumProtocols);
400 for (unsigned I = 0; I != NumProtocols; ++I)
401 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
402 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
403 *Reader.getContext());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000404
405 // Read the transitive closure of protocols referenced by this class.
406 NumProtocols = Record[Idx++];
407 Protocols.clear();
408 Protocols.reserve(NumProtocols);
409 for (unsigned I = 0; I != NumProtocols; ++I)
410 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
411 ID->AllReferencedProtocols.set(Protocols.data(), NumProtocols,
412 *Reader.getContext());
413
414 // Read the ivars.
Chris Lattner487412d2009-04-27 05:27:42 +0000415 unsigned NumIvars = Record[Idx++];
416 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
417 IVars.reserve(NumIvars);
418 for (unsigned I = 0; I != NumIvars; ++I)
419 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000420 ID->setCategoryList(
421 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000422 // We will rebuild this list lazily.
423 ID->setIvarList(0);
Douglas Gregor1c283312010-08-11 12:19:30 +0000424 ID->setForwardDecl(Record[Idx++]);
425 ID->setImplicitInterfaceDecl(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000426 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
427 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisea72f422009-07-18 00:33:23 +0000428 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000429}
430
Sebastian Redlb3298c32010-08-18 23:56:48 +0000431void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000432 VisitFieldDecl(IVD);
433 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000434 // This field will be built lazily.
435 IVD->setNextIvar(0);
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000436 bool synth = Record[Idx++];
437 IVD->setSynthesize(synth);
Chris Lattner487412d2009-04-27 05:27:42 +0000438}
439
Sebastian Redlb3298c32010-08-18 23:56:48 +0000440void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000441 VisitObjCContainerDecl(PD);
442 PD->setForwardDecl(Record[Idx++]);
443 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
444 unsigned NumProtoRefs = Record[Idx++];
445 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
446 ProtoRefs.reserve(NumProtoRefs);
447 for (unsigned I = 0; I != NumProtoRefs; ++I)
448 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000449 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
450 ProtoLocs.reserve(NumProtoRefs);
451 for (unsigned I = 0; I != NumProtoRefs; ++I)
452 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
453 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
454 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000455}
456
Sebastian Redlb3298c32010-08-18 23:56:48 +0000457void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000458 VisitFieldDecl(FD);
459}
460
Sebastian Redlb3298c32010-08-18 23:56:48 +0000461void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000462 VisitDecl(CD);
463 unsigned NumClassRefs = Record[Idx++];
464 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
465 ClassRefs.reserve(NumClassRefs);
466 for (unsigned I = 0; I != NumClassRefs; ++I)
467 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000468 llvm::SmallVector<SourceLocation, 16> SLocs;
469 SLocs.reserve(NumClassRefs);
470 for (unsigned I = 0; I != NumClassRefs; ++I)
471 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
472 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
473 NumClassRefs);
Chris Lattner487412d2009-04-27 05:27:42 +0000474}
475
Sebastian Redlb3298c32010-08-18 23:56:48 +0000476void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000477 VisitDecl(FPD);
478 unsigned NumProtoRefs = Record[Idx++];
479 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
480 ProtoRefs.reserve(NumProtoRefs);
481 for (unsigned I = 0; I != NumProtoRefs; ++I)
482 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000483 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
484 ProtoLocs.reserve(NumProtoRefs);
485 for (unsigned I = 0; I != NumProtoRefs; ++I)
486 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
487 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
488 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000489}
490
Sebastian Redlb3298c32010-08-18 23:56:48 +0000491void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000492 VisitObjCContainerDecl(CD);
493 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
494 unsigned NumProtoRefs = Record[Idx++];
495 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
496 ProtoRefs.reserve(NumProtoRefs);
497 for (unsigned I = 0; I != NumProtoRefs; ++I)
498 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000499 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
500 ProtoLocs.reserve(NumProtoRefs);
501 for (unsigned I = 0; I != NumProtoRefs; ++I)
502 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
503 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
504 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000505 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000506 CD->setHasSynthBitfield(Record[Idx++]);
Douglas Gregor071676f2010-01-16 16:38:58 +0000507 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
508 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000509}
510
Sebastian Redlb3298c32010-08-18 23:56:48 +0000511void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000512 VisitNamedDecl(CAD);
513 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
514}
515
Sebastian Redlb3298c32010-08-18 23:56:48 +0000516void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000517 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000518 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Sebastian Redlc67764e2010-07-22 22:43:28 +0000519 D->setType(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000520 // FIXME: stable encoding
521 D->setPropertyAttributes(
522 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000523 D->setPropertyAttributesAsWritten(
524 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000525 // FIXME: stable encoding
526 D->setPropertyImplementation(
527 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
528 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
529 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
530 D->setGetterMethodDecl(
531 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
532 D->setSetterMethodDecl(
533 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
534 D->setPropertyIvarDecl(
535 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
536}
537
Sebastian Redlb3298c32010-08-18 23:56:48 +0000538void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000539 VisitObjCContainerDecl(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000540 D->setClassInterface(
541 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000542}
543
Sebastian Redlb3298c32010-08-18 23:56:48 +0000544void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000545 VisitObjCImplDecl(D);
546 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
547}
548
Sebastian Redlb3298c32010-08-18 23:56:48 +0000549void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000550 VisitObjCImplDecl(D);
551 D->setSuperClass(
552 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +0000553 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
554 = Reader.ReadCXXBaseOrMemberInitializers(Cursor, Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000555 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000556}
557
558
Sebastian Redlb3298c32010-08-18 23:56:48 +0000559void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000560 VisitDecl(D);
561 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
562 D->setPropertyDecl(
563 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
564 D->setPropertyIvarDecl(
565 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisa8607772010-08-09 10:54:37 +0000566 D->setGetterCXXConstructor(Reader.ReadExpr(Cursor));
567 D->setSetterCXXAssignment(Reader.ReadExpr(Cursor));
Chris Lattner487412d2009-04-27 05:27:42 +0000568}
569
Sebastian Redlb3298c32010-08-18 23:56:48 +0000570void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000571 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000572 FD->setMutable(Record[Idx++]);
573 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000574 FD->setBitWidth(Reader.ReadExpr(Cursor));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000575 if (!FD->getDeclName()) {
576 FieldDecl *Tmpl = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
577 if (Tmpl)
578 Reader.getContext()->setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
579 }
Chris Lattner487412d2009-04-27 05:27:42 +0000580}
581
Sebastian Redlb3298c32010-08-18 23:56:48 +0000582void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000583 VisitDeclaratorDecl(VD);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000584 VisitRedeclarable(VD);
John McCall8e7d6562010-08-26 03:08:43 +0000585 VD->setStorageClass((StorageClass)Record[Idx++]);
586 VD->setStorageClassAsWritten((StorageClass)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000587 VD->setThreadSpecified(Record[Idx++]);
588 VD->setCXXDirectInitializer(Record[Idx++]);
Douglas Gregor3f324d562010-05-03 18:51:14 +0000589 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor6fd1b182010-05-15 06:01:05 +0000590 VD->setNRVOVariable(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000591 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000592 VD->setInit(Reader.ReadExpr(Cursor));
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000593
594 if (Record[Idx++]) { // HasMemberSpecializationInfo.
595 VarDecl *Tmpl = cast<VarDecl>(Reader.GetDecl(Record[Idx++]));
596 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
597 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
598 Reader.getContext()->setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
599 }
Chris Lattner487412d2009-04-27 05:27:42 +0000600}
601
Sebastian Redlb3298c32010-08-18 23:56:48 +0000602void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000603 VisitVarDecl(PD);
604}
605
Sebastian Redlb3298c32010-08-18 23:56:48 +0000606void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000607 VisitVarDecl(PD);
608 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallf3cd6652010-03-12 18:31:32 +0000609 PD->setHasInheritedDefaultArg(Record[Idx++]);
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000610 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redlc67764e2010-07-22 22:43:28 +0000611 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(Cursor));
Chris Lattner487412d2009-04-27 05:27:42 +0000612}
613
Sebastian Redlb3298c32010-08-18 23:56:48 +0000614void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000615 VisitDecl(AD);
Sebastian Redlc67764e2010-07-22 22:43:28 +0000616 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(Cursor)));
Chris Lattner487412d2009-04-27 05:27:42 +0000617}
618
Sebastian Redlb3298c32010-08-18 23:56:48 +0000619void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000620 VisitDecl(BD);
Sebastian Redlc67764e2010-07-22 22:43:28 +0000621 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(Cursor)));
622 BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000623 unsigned NumParams = Record[Idx++];
624 llvm::SmallVector<ParmVarDecl *, 16> Params;
625 Params.reserve(NumParams);
626 for (unsigned I = 0; I != NumParams; ++I)
627 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000628 BD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000629}
630
Sebastian Redlb3298c32010-08-18 23:56:48 +0000631void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000632 VisitDecl(D);
633 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
634 D->setHasBraces(Record[Idx++]);
635}
636
Sebastian Redlb3298c32010-08-18 23:56:48 +0000637void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000638 VisitNamedDecl(D);
639 D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx));
640 D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx));
641 D->setNextNamespace(
642 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
643
Chris Lattnerca025db2010-05-07 21:43:38 +0000644 bool IsOriginal = Record[Idx++];
Argyrios Kyrtzidisdae2a162010-07-03 07:57:53 +0000645 D->OrigOrAnonNamespace.setInt(IsOriginal);
646 D->OrigOrAnonNamespace.setPointer(
Chris Lattnerca025db2010-05-07 21:43:38 +0000647 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
648}
649
Sebastian Redlb3298c32010-08-18 23:56:48 +0000650void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000651 VisitNamedDecl(D);
Douglas Gregorf9e43ce2010-09-01 00:08:19 +0000652 D->NamespaceLoc = Reader.ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000653 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
654 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
Douglas Gregorf9e43ce2010-09-01 00:08:19 +0000655 D->IdentLoc = Reader.ReadSourceLocation(Record, Idx);
656 D->Namespace = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000657}
658
Sebastian Redlb3298c32010-08-18 23:56:48 +0000659void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000660 VisitNamedDecl(D);
661 D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
662 D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
663 D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
Abramo Bagnara8de74e92010-08-12 11:46:03 +0000664 // FIXME: read the DNLoc component.
Chris Lattnerca025db2010-05-07 21:43:38 +0000665
666 // FIXME: It would probably be more efficient to read these into a vector
667 // and then re-cosntruct the shadow decl set over that vector since it
668 // would avoid existence checks.
669 unsigned NumShadows = Record[Idx++];
670 for(unsigned I = 0; I != NumShadows; ++I) {
Argyrios Kyrtzidis00dda6a2010-07-08 13:09:41 +0000671 // Avoid invariant checking of UsingDecl::addShadowDecl, the decl may still
672 // be initializing.
673 D->Shadows.insert(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattnerca025db2010-05-07 21:43:38 +0000674 }
675 D->setTypeName(Record[Idx++]);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000676 NamedDecl *Pattern = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
677 if (Pattern)
678 Reader.getContext()->setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000679}
680
Sebastian Redlb3298c32010-08-18 23:56:48 +0000681void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000682 VisitNamedDecl(D);
683 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
684 D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000685 UsingShadowDecl *Pattern
686 = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]));
687 if (Pattern)
688 Reader.getContext()->setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000689}
690
Sebastian Redlb3298c32010-08-18 23:56:48 +0000691void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000692 VisitNamedDecl(D);
Douglas Gregor01a430132010-09-01 03:07:18 +0000693 D->UsingLoc = Reader.ReadSourceLocation(Record, Idx);
694 D->NamespaceLoc = Reader.ReadSourceLocation(Record, Idx);
695 D->QualifierRange = Reader.ReadSourceRange(Record, Idx);
696 D->Qualifier = Reader.ReadNestedNameSpecifier(Record, Idx);
697 D->NominatedNamespace = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
698 D->CommonAncestor = cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000699}
700
Sebastian Redlb3298c32010-08-18 23:56:48 +0000701void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000702 VisitValueDecl(D);
703 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
704 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
705 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
Abramo Bagnara8de74e92010-08-12 11:46:03 +0000706 // FIXME: read the DNLoc component.
Chris Lattnerca025db2010-05-07 21:43:38 +0000707}
708
Sebastian Redlb3298c32010-08-18 23:56:48 +0000709void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000710 UnresolvedUsingTypenameDecl *D) {
711 VisitTypeDecl(D);
Douglas Gregora9aa29c2010-09-01 19:52:22 +0000712 D->TargetNestedNameRange = Reader.ReadSourceRange(Record, Idx);
713 D->UsingLocation = Reader.ReadSourceLocation(Record, Idx);
714 D->TypenameLocation = Reader.ReadSourceLocation(Record, Idx);
715 D->TargetNestedNameSpecifier = Reader.ReadNestedNameSpecifier(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000716}
717
Sebastian Redlb3298c32010-08-18 23:56:48 +0000718void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000719 ASTContext &C = *Reader.getContext();
720
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000721 // We need to allocate the DefinitionData struct ahead of VisitRecordDecl
722 // so that the other CXXRecordDecls can get a pointer even when the owner
723 // is still initializing.
724 bool OwnsDefinitionData = false;
725 enum DataOwnership { Data_NoDefData, Data_Owner, Data_NotOwner };
726 switch ((DataOwnership)Record[Idx++]) {
727 default:
Sebastian Redlb3298c32010-08-18 23:56:48 +0000728 assert(0 && "Out of sync with ASTDeclWriter or messed up reading");
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000729 case Data_NoDefData:
730 break;
731 case Data_Owner:
732 OwnsDefinitionData = true;
733 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
734 break;
735 case Data_NotOwner:
736 D->DefinitionData
737 = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]))->DefinitionData;
738 break;
739 }
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000740
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000741 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000742
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000743 if (OwnsDefinitionData) {
744 assert(D->DefinitionData);
745 struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData;
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000746
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000747 Data.UserDeclaredConstructor = Record[Idx++];
748 Data.UserDeclaredCopyConstructor = Record[Idx++];
749 Data.UserDeclaredCopyAssignment = Record[Idx++];
750 Data.UserDeclaredDestructor = Record[Idx++];
751 Data.Aggregate = Record[Idx++];
752 Data.PlainOldData = Record[Idx++];
753 Data.Empty = Record[Idx++];
754 Data.Polymorphic = Record[Idx++];
755 Data.Abstract = Record[Idx++];
756 Data.HasTrivialConstructor = Record[Idx++];
757 Data.HasTrivialCopyConstructor = Record[Idx++];
758 Data.HasTrivialCopyAssignment = Record[Idx++];
759 Data.HasTrivialDestructor = Record[Idx++];
760 Data.ComputedVisibleConversions = Record[Idx++];
761 Data.DeclaredDefaultConstructor = Record[Idx++];
762 Data.DeclaredCopyConstructor = Record[Idx++];
763 Data.DeclaredCopyAssignment = Record[Idx++];
764 Data.DeclaredDestructor = Record[Idx++];
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000765
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000766 // setBases() is unsuitable since it may try to iterate the bases of an
Nick Lewycky19b9f952010-07-26 16:56:01 +0000767 // uninitialized base.
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000768 Data.NumBases = Record[Idx++];
769 Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases];
770 for (unsigned i = 0; i != Data.NumBases; ++i)
Nick Lewycky19b9f952010-07-26 16:56:01 +0000771 Data.Bases[i] = Reader.ReadCXXBaseSpecifier(Cursor, Record, Idx);
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000772
773 // FIXME: Make VBases lazily computed when needed to avoid storing them.
774 Data.NumVBases = Record[Idx++];
775 Data.VBases = new(C) CXXBaseSpecifier [Data.NumVBases];
776 for (unsigned i = 0; i != Data.NumVBases; ++i)
Nick Lewycky19b9f952010-07-26 16:56:01 +0000777 Data.VBases[i] = Reader.ReadCXXBaseSpecifier(Cursor, Record, Idx);
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000778
779 Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx);
780 Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx);
781 assert(Data.Definition && "Data.Definition should be already set!");
782 Data.FirstFriend
783 = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000784 }
785
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000786 enum CXXRecKind {
787 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
788 };
789 switch ((CXXRecKind)Record[Idx++]) {
790 default:
Sebastian Redlb3298c32010-08-18 23:56:48 +0000791 assert(false && "Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000792 case CXXRecNotTemplate:
793 break;
794 case CXXRecTemplate:
795 D->setDescribedClassTemplate(
796 cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++])));
797 break;
798 case CXXRecMemberSpecialization: {
799 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
800 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
801 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
802 D->setInstantiationOfMemberClass(RD, TSK);
803 D->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
804 break;
805 }
806 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000807}
808
Sebastian Redlb3298c32010-08-18 23:56:48 +0000809void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000810 VisitFunctionDecl(D);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000811 unsigned NumOverridenMethods = Record[Idx++];
812 while (NumOverridenMethods--) {
813 CXXMethodDecl *MD = cast<CXXMethodDecl>(Reader.GetDecl(Record[Idx++]));
814 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
815 // MD may be initializing.
816 Reader.getContext()->addOverriddenMethod(D, MD);
817 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000818}
819
Sebastian Redlb3298c32010-08-18 23:56:48 +0000820void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000821 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000822
823 D->IsExplicitSpecified = Record[Idx++];
824 D->ImplicitlyDefined = Record[Idx++];
Argyrios Kyrtzidis5b6a03f2010-08-09 10:54:12 +0000825 llvm::tie(D->BaseOrMemberInitializers, D->NumBaseOrMemberInitializers)
826 = Reader.ReadCXXBaseOrMemberInitializers(Cursor, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000827}
828
Sebastian Redlb3298c32010-08-18 23:56:48 +0000829void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000830 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000831
832 D->ImplicitlyDefined = Record[Idx++];
833 D->OperatorDelete = cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000834}
835
Sebastian Redlb3298c32010-08-18 23:56:48 +0000836void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000837 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000838 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000839}
840
Sebastian Redlb3298c32010-08-18 23:56:48 +0000841void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +0000842 VisitDecl(D);
843 D->setColonLoc(Reader.ReadSourceLocation(Record, Idx));
844}
845
Sebastian Redlb3298c32010-08-18 23:56:48 +0000846void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000847 VisitDecl(D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000848 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000849 D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000850 else
851 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
852 D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
853 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
854}
855
Sebastian Redlb3298c32010-08-18 23:56:48 +0000856void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +0000857 VisitDecl(D);
858 unsigned NumParams = Record[Idx++];
859 D->NumParams = NumParams;
860 D->Params = new TemplateParameterList*[NumParams];
861 for (unsigned i = 0; i != NumParams; ++i)
862 D->Params[i] = Reader.ReadTemplateParameterList(Record, Idx);
863 if (Record[Idx++]) // HasFriendDecl
864 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
865 else
Sebastian Redlc67764e2010-07-22 22:43:28 +0000866 D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +0000867 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000868}
869
Sebastian Redlb3298c32010-08-18 23:56:48 +0000870void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000871 VisitNamedDecl(D);
872
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +0000873 NamedDecl *TemplatedDecl
874 = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000875 TemplateParameterList* TemplateParams
876 = Reader.ReadTemplateParameterList(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000877 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +0000878}
879
Sebastian Redlb3298c32010-08-18 23:56:48 +0000880void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000881 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
882 // can be used while this is still initializing.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000883
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000884 assert(D->CommonOrPrev.isNull() && "getCommonPtr was called earlier on this");
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000885 RedeclarableTemplateDecl *PrevDecl =
886 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]));
887 assert((PrevDecl == 0 || PrevDecl->getKind() == D->getKind()) &&
888 "PrevDecl kind mismatch");
889 if (PrevDecl)
890 D->CommonOrPrev = PrevDecl;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000891 if (PrevDecl == 0) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000892 D->CommonOrPrev = D->newCommon(*Reader.getContext());
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000893 if (RedeclarableTemplateDecl *RTD
894 = cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
895 assert(RTD->getKind() == D->getKind() &&
896 "InstantiatedFromMemberTemplate kind mismatch");
897 D->setInstantiatedFromMemberTemplateImpl(RTD);
898 if (Record[Idx++])
899 D->setMemberSpecialization();
900 }
Peter Collingbourne2bf3d242010-07-29 16:12:01 +0000901
902 RedeclarableTemplateDecl *LatestDecl =
903 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000904
905 // This decl is a first one and the latest declaration that it points to is
Sebastian Redld44cd6a2010-08-18 23:57:06 +0000906 // in the same AST file. However, if this actually needs to point to a
907 // redeclaration in another AST file, we need to update it by checking
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000908 // the FirstLatestDeclIDs map which tracks this kind of decls.
909 assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +0000910 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000911 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
912 if (I != Reader.FirstLatestDeclIDs.end()) {
913 Decl *NewLatest = Reader.GetDecl(I->second);
914 assert((LatestDecl->getLocation().isInvalid() ||
915 NewLatest->getLocation().isInvalid() ||
916 Reader.SourceMgr.isBeforeInTranslationUnit(
917 LatestDecl->getLocation(),
918 NewLatest->getLocation())) &&
919 "The new latest is supposed to come after the previous latest");
920 LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
921 }
922
Peter Collingbourne2bf3d242010-07-29 16:12:01 +0000923 assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
924 D->getCommonPtr()->Latest = LatestDecl;
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000925 }
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000926
927 VisitTemplateDecl(D);
928 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000929}
930
Sebastian Redlb3298c32010-08-18 23:56:48 +0000931void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000932 VisitRedeclarableTemplateDecl(D);
933
934 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000935 // This ClassTemplateDecl owns a CommonPtr; read it.
936
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000937 // FoldingSets are filled in VisitClassTemplateSpecializationDecl.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000938 unsigned size = Record[Idx++];
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000939 while (size--)
940 cast<ClassTemplateSpecializationDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000941
942 size = Record[Idx++];
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000943 while (size--)
944 cast<ClassTemplatePartialSpecializationDecl>(
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000945 Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000946
947 // InjectedClassNameType is computed.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000948 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000949}
950
Sebastian Redlb3298c32010-08-18 23:56:48 +0000951void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000952 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000953 VisitCXXRecordDecl(D);
954
955 if (Decl *InstD = Reader.GetDecl(Record[Idx++])) {
956 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
957 D->setInstantiationOf(CTD);
958 } else {
959 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000960 Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000961 D->setInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(InstD),
962 TemplArgs.data(), TemplArgs.size());
963 }
964 }
965
966 // Explicit info.
Sebastian Redlc67764e2010-07-22 22:43:28 +0000967 if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx)) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000968 D->setTypeAsWritten(TyInfo);
969 D->setExternLoc(Reader.ReadSourceLocation(Record, Idx));
970 D->setTemplateKeywordLoc(Reader.ReadSourceLocation(Record, Idx));
971 }
972
973 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000974 Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000975 D->initTemplateArgs(TemplArgs.data(), TemplArgs.size());
976 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
977 if (POI.isValid())
978 D->setPointOfInstantiation(POI);
979 D->setSpecializationKind((TemplateSpecializationKind)Record[Idx++]);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000980
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +0000981 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000982 ClassTemplateDecl *CanonPattern
983 = cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
984 if (ClassTemplatePartialSpecializationDecl *Partial
985 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
Argyrios Kyrtzidisf4cc7dc2010-07-12 21:41:31 +0000986 CanonPattern->getPartialSpecializations().InsertNode(Partial);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000987 } else {
Argyrios Kyrtzidisf4cc7dc2010-07-12 21:41:31 +0000988 CanonPattern->getSpecializations().InsertNode(D);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000989 }
990 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000991}
992
Sebastian Redlb3298c32010-08-18 23:56:48 +0000993void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000994 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000995 VisitClassTemplateSpecializationDecl(D);
996
997 D->initTemplateParameters(Reader.ReadTemplateParameterList(Record, Idx));
998
999 TemplateArgumentListInfo ArgInfos;
1000 unsigned NumArgs = Record[Idx++];
1001 while (NumArgs--)
Sebastian Redlc67764e2010-07-22 22:43:28 +00001002 ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001003 D->initTemplateArgsAsWritten(ArgInfos);
1004
1005 D->setSequenceNumber(Record[Idx++]);
1006
1007 // These are read/set from/to the first declaration.
1008 if (D->getPreviousDeclaration() == 0) {
1009 D->setInstantiatedFromMember(
1010 cast_or_null<ClassTemplatePartialSpecializationDecl>(
1011 Reader.GetDecl(Record[Idx++])));
1012 if (Record[Idx++])
Argyrios Kyrtzidisdd2061b2010-07-09 21:11:35 +00001013 D->setMemberSpecialization();
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001014 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001015}
1016
Sebastian Redlb3298c32010-08-18 23:56:48 +00001017void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001018 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001019
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001020 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001021 // This FunctionTemplateDecl owns a CommonPtr; read it.
1022
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001023 // Read the function specialization declarations.
1024 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
1025 // through the specialized FunctionDecl's setFunctionTemplateSpecialization.
1026 unsigned NumSpecs = Record[Idx++];
1027 while (NumSpecs--)
1028 Reader.GetDecl(Record[Idx++]);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001029 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001030}
1031
Sebastian Redlb3298c32010-08-18 23:56:48 +00001032void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001033 VisitTypeDecl(D);
1034
1035 D->setDeclaredWithTypename(Record[Idx++]);
1036 D->setParameterPack(Record[Idx++]);
1037
1038 bool Inherited = Record[Idx++];
Sebastian Redlc67764e2010-07-22 22:43:28 +00001039 TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001040 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001041}
1042
Sebastian Redlb3298c32010-08-18 23:56:48 +00001043void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001044 VisitVarDecl(D);
1045 // TemplateParmPosition.
1046 D->setDepth(Record[Idx++]);
1047 D->setPosition(Record[Idx++]);
1048 // Rest of NonTypeTemplateParmDecl.
1049 if (Record[Idx++]) {
Sebastian Redlc67764e2010-07-22 22:43:28 +00001050 Expr *DefArg = Reader.ReadExpr(Cursor);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001051 bool Inherited = Record[Idx++];
1052 D->setDefaultArgument(DefArg, Inherited);
1053 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001054}
1055
Sebastian Redlb3298c32010-08-18 23:56:48 +00001056void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001057 VisitTemplateDecl(D);
1058 // TemplateParmPosition.
1059 D->setDepth(Record[Idx++]);
1060 D->setPosition(Record[Idx++]);
1061 // Rest of TemplateTemplateParmDecl.
Sebastian Redlc67764e2010-07-22 22:43:28 +00001062 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx);
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001063 bool IsInherited = Record[Idx++];
1064 D->setDefaultArgument(Arg, IsInherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001065}
1066
Sebastian Redlb3298c32010-08-18 23:56:48 +00001067void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001068 VisitDecl(D);
Sebastian Redlc67764e2010-07-22 22:43:28 +00001069 D->AssertExpr = Reader.ReadExpr(Cursor);
1070 D->Message = cast<StringLiteral>(Reader.ReadExpr(Cursor));
Chris Lattnerca025db2010-05-07 21:43:38 +00001071}
1072
Mike Stump11289f42009-09-09 15:08:12 +00001073std::pair<uint64_t, uint64_t>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001074ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner487412d2009-04-27 05:27:42 +00001075 uint64_t LexicalOffset = Record[Idx++];
1076 uint64_t VisibleOffset = Record[Idx++];
1077 return std::make_pair(LexicalOffset, VisibleOffset);
1078}
1079
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001080template <typename T>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001081void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001082 enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest };
1083 RedeclKind Kind = (RedeclKind)Record[Idx++];
1084 switch (Kind) {
1085 default:
Sebastian Redlb3298c32010-08-18 23:56:48 +00001086 assert(0 && "Out of sync with ASTDeclWriter::VisitRedeclarable or messed up"
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001087 " reading");
1088 case NoRedeclaration:
1089 break;
1090 case PointsToPrevious:
1091 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(
1092 cast_or_null<T>(Reader.GetDecl(Record[Idx++])));
1093 break;
1094 case PointsToLatest:
1095 D->RedeclLink = typename Redeclarable<T>::LatestDeclLink(
1096 cast_or_null<T>(Reader.GetDecl(Record[Idx++])));
1097 break;
1098 }
1099
1100 assert(!(Kind == PointsToPrevious &&
1101 Reader.FirstLatestDeclIDs.find(ThisDeclID) !=
1102 Reader.FirstLatestDeclIDs.end()) &&
1103 "This decl is not first, it should not be in the map");
1104 if (Kind == PointsToPrevious)
1105 return;
1106
1107 // This decl is a first one and the latest declaration that it points to is in
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001108 // the same AST file. However, if this actually needs to point to a
1109 // redeclaration in another AST file, we need to update it by checking the
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001110 // FirstLatestDeclIDs map which tracks this kind of decls.
1111 assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) &&
1112 "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001113 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001114 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1115 if (I != Reader.FirstLatestDeclIDs.end()) {
1116 Decl *NewLatest = Reader.GetDecl(I->second);
1117 assert((D->getMostRecentDeclaration()->getLocation().isInvalid() ||
1118 NewLatest->getLocation().isInvalid() ||
1119 Reader.SourceMgr.isBeforeInTranslationUnit(
1120 D->getMostRecentDeclaration()->getLocation(),
1121 NewLatest->getLocation())) &&
1122 "The new latest is supposed to come after the previous latest");
1123 D->RedeclLink
1124 = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest));
1125 }
1126}
1127
Chris Lattner487412d2009-04-27 05:27:42 +00001128//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00001129// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00001130//===----------------------------------------------------------------------===//
1131
Chris Lattner8f63ab52009-04-27 06:01:06 +00001132/// \brief Reads attributes from the current stream position.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001133void ASTReader::ReadAttributes(llvm::BitstreamCursor &DeclsCursor,
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001134 AttrVec &Attrs) {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001135 unsigned Code = DeclsCursor.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +00001136 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner8f63ab52009-04-27 06:01:06 +00001137 "Expected unabbreviated record"); (void)Code;
Mike Stump11289f42009-09-09 15:08:12 +00001138
Chris Lattner8f63ab52009-04-27 06:01:06 +00001139 RecordData Record;
1140 unsigned Idx = 0;
1141 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001142 assert(RecCode == DECL_ATTR && "Expected attribute record");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001143 (void)RecCode;
1144
Chris Lattner8f63ab52009-04-27 06:01:06 +00001145 while (Idx < Record.size()) {
1146 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001147 attr::Kind Kind = (attr::Kind)Record[Idx++];
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001148 SourceLocation Loc = SourceLocation::getFromRawEncoding(Record[Idx++]);
1149 bool isInherited = Record[Idx++];
Chris Lattner8f63ab52009-04-27 06:01:06 +00001150
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001151#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner8f63ab52009-04-27 06:01:06 +00001152
1153 assert(New && "Unable to decode attribute?");
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001154 New->setInherited(isInherited);
1155 Attrs.push_back(New);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001156 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001157}
1158
1159//===----------------------------------------------------------------------===//
Sebastian Redl2c499f62010-08-18 23:56:43 +00001160// ASTReader Implementation
Chris Lattner8f63ab52009-04-27 06:01:06 +00001161//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001162
1163/// \brief Note that we have loaded the declaration with the given
1164/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001165///
Chris Lattner487412d2009-04-27 05:27:42 +00001166/// This routine notes that this declaration has already been loaded,
1167/// so that future GetDecl calls will return this declaration rather
1168/// than trying to load a new declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001169inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001170 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1171 DeclsLoaded[Index] = D;
1172}
1173
1174
1175/// \brief Determine whether the consumer will be interested in seeing
1176/// this declaration (via HandleTopLevelDecl).
1177///
1178/// This routine should return true for anything that might affect
1179/// code generation, e.g., inline function definitions, Objective-C
1180/// declarations with metadata, etc.
1181static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001182 if (isa<FileScopeAsmDecl>(D))
1183 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001184 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis4ba81b22010-08-05 09:47:59 +00001185 return Var->isFileVarDecl() &&
1186 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner487412d2009-04-27 05:27:42 +00001187 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1188 return Func->isThisDeclarationADefinition();
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +00001189 return isa<ObjCProtocolDecl>(D) || isa<ObjCImplementationDecl>(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001190}
1191
Sebastian Redl34627792010-07-20 22:46:15 +00001192/// \brief Get the correct cursor and offset for loading a type.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001193ASTReader::RecordLocation
Sebastian Redl539c5062010-08-18 23:57:32 +00001194ASTReader::DeclCursorForIndex(unsigned Index, DeclID ID) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001195 // See if there's an override.
1196 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
1197 if (It != ReplacedDecls.end())
1198 return RecordLocation(&It->second.first->DeclsCursor, It->second.second);
1199
Sebastian Redl34627792010-07-20 22:46:15 +00001200 PerFileData *F = 0;
1201 for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
1202 F = Chain[N - I - 1];
1203 if (Index < F->LocalNumDecls)
1204 break;
1205 Index -= F->LocalNumDecls;
1206 }
1207 assert(F && F->LocalNumDecls > Index && "Broken chain");
Sebastian Redlb2831db2010-07-20 22:55:31 +00001208 return RecordLocation(&F->DeclsCursor, F->DeclOffsets[Index]);
Sebastian Redl34627792010-07-20 22:46:15 +00001209}
1210
Sebastian Redlb3298c32010-08-18 23:56:48 +00001211/// \brief Read the declaration at the given offset from the AST file.
Sebastian Redl539c5062010-08-18 23:57:32 +00001212Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001213 RecordLocation Loc = DeclCursorForIndex(Index, ID);
Sebastian Redlb2831db2010-07-20 22:55:31 +00001214 llvm::BitstreamCursor &DeclsCursor = *Loc.first;
Chris Lattner487412d2009-04-27 05:27:42 +00001215 // Keep track of where we are in the stream, then jump back there
1216 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001217 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001218
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001219 ReadingKindTracker ReadingKind(Read_Decl, *this);
1220
Douglas Gregor1342e842009-07-06 18:54:52 +00001221 // Note that we are loading a declaration record.
Argyrios Kyrtzidisb24355a2010-07-30 10:03:16 +00001222 Deserializing ADecl(this);
Mike Stump11289f42009-09-09 15:08:12 +00001223
Sebastian Redl34627792010-07-20 22:46:15 +00001224 DeclsCursor.JumpToBit(Loc.second);
Chris Lattner487412d2009-04-27 05:27:42 +00001225 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001226 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001227 unsigned Idx = 0;
Sebastian Redlb3298c32010-08-18 23:56:48 +00001228 ASTDeclReader Reader(*this, DeclsCursor, ID, Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +00001229
Chris Lattner1de76db2009-04-27 05:58:23 +00001230 Decl *D = 0;
Sebastian Redl539c5062010-08-18 23:57:32 +00001231 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
1232 case DECL_ATTR:
1233 case DECL_CONTEXT_LEXICAL:
1234 case DECL_CONTEXT_VISIBLE:
Chris Lattner487412d2009-04-27 05:27:42 +00001235 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1236 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001237 case DECL_TRANSLATION_UNIT:
Chris Lattner487412d2009-04-27 05:27:42 +00001238 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +00001239 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +00001240 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001241 case DECL_TYPEDEF:
John McCall703a3f82009-10-24 08:00:42 +00001242 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001243 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001244 case DECL_ENUM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001245 D = EnumDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001246 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001247 case DECL_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001248 D = RecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001249 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001250 case DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +00001251 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001252 0, llvm::APSInt());
1253 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001254 case DECL_FUNCTION:
Mike Stump11289f42009-09-09 15:08:12 +00001255 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001256 QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001257 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001258 case DECL_LINKAGE_SPEC:
Chris Lattnerca025db2010-05-07 21:43:38 +00001259 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
1260 (LinkageSpecDecl::LanguageIDs)0,
1261 false);
1262 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001263 case DECL_NAMESPACE:
Chris Lattnerca025db2010-05-07 21:43:38 +00001264 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
1265 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001266 case DECL_NAMESPACE_ALIAS:
Chris Lattnerca025db2010-05-07 21:43:38 +00001267 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
1268 SourceLocation(), 0, SourceRange(), 0,
1269 SourceLocation(), 0);
1270 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001271 case DECL_USING:
Abramo Bagnara8de74e92010-08-12 11:46:03 +00001272 D = UsingDecl::Create(*Context, 0, SourceRange(), SourceLocation(),
1273 0, DeclarationNameInfo(), false);
Chris Lattnerca025db2010-05-07 21:43:38 +00001274 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001275 case DECL_USING_SHADOW:
Chris Lattnerca025db2010-05-07 21:43:38 +00001276 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1277 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001278 case DECL_USING_DIRECTIVE:
Chris Lattnerca025db2010-05-07 21:43:38 +00001279 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
1280 SourceLocation(), SourceRange(), 0,
1281 SourceLocation(), 0, 0);
1282 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001283 case DECL_UNRESOLVED_USING_VALUE:
Chris Lattnerca025db2010-05-07 21:43:38 +00001284 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
Abramo Bagnara8de74e92010-08-12 11:46:03 +00001285 SourceRange(), 0,
1286 DeclarationNameInfo());
Chris Lattnerca025db2010-05-07 21:43:38 +00001287 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001288 case DECL_UNRESOLVED_USING_TYPENAME:
Chris Lattnerca025db2010-05-07 21:43:38 +00001289 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
1290 SourceLocation(), SourceRange(),
1291 0, SourceLocation(),
1292 DeclarationName());
1293 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001294 case DECL_CXX_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001295 D = CXXRecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001296 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001297 case DECL_CXX_METHOD:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001298 D = CXXMethodDecl::Create(*Context, 0, DeclarationNameInfo(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001299 QualType(), 0);
1300 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001301 case DECL_CXX_CONSTRUCTOR:
Chris Lattnerca025db2010-05-07 21:43:38 +00001302 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1303 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001304 case DECL_CXX_DESTRUCTOR:
Chris Lattnerca025db2010-05-07 21:43:38 +00001305 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1306 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001307 case DECL_CXX_CONVERSION:
Chris Lattnerca025db2010-05-07 21:43:38 +00001308 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1309 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001310 case DECL_ACCESS_SPEC:
Argyrios Kyrtzidis260b4a82010-09-08 21:32:35 +00001311 D = AccessSpecDecl::Create(*Context, Decl::EmptyShell());
Abramo Bagnarad7340582010-06-05 05:09:32 +00001312 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001313 case DECL_FRIEND:
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001314 D = FriendDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001315 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001316 case DECL_FRIEND_TEMPLATE:
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001317 D = FriendTemplateDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001318 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001319 case DECL_CLASS_TEMPLATE:
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +00001320 D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(),
1321 DeclarationName(), 0, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001322 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001323 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001324 D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001325 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001326 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001327 D = ClassTemplatePartialSpecializationDecl::Create(*Context,
1328 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001329 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001330 case DECL_FUNCTION_TEMPLATE:
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001331 D = FunctionTemplateDecl::Create(*Context, 0, SourceLocation(),
1332 DeclarationName(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001333 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001334 case DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001335 D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001336 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001337 case DECL_NON_TYPE_TEMPLATE_PARM:
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001338 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0,
1339 QualType(),0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001340 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001341 case DECL_TEMPLATE_TEMPLATE_PARM:
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001342 D = TemplateTemplateParmDecl::Create(*Context, 0, SourceLocation(),0,0,0,0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001343 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001344 case DECL_STATIC_ASSERT:
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001345 D = StaticAssertDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001346 break;
1347
Sebastian Redl539c5062010-08-18 23:57:32 +00001348 case DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +00001349 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001350 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001351 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001352 case DECL_OBJC_INTERFACE:
Douglas Gregor1c283312010-08-11 12:19:30 +00001353 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001354 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001355 case DECL_OBJC_IVAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001356 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001357 ObjCIvarDecl::None);
1358 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001359 case DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001360 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001361 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001362 case DECL_OBJC_AT_DEFS_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001363 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001364 QualType(), 0);
1365 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001366 case DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001367 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001368 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001369 case DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001370 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001371 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001372 case DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +00001373 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1374 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001375 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001376 case DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001377 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001378 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001379 case DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +00001380 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001381 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001382 case DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001383 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001384 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001385 case DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001386 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001387 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001388 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001389 case DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001390 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001391 SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001392 ObjCPropertyImplDecl::Dynamic, 0);
1393 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001394 case DECL_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001395 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +00001396 false);
Chris Lattner487412d2009-04-27 05:27:42 +00001397 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001398 case DECL_VAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001399 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
John McCall8e7d6562010-08-26 03:08:43 +00001400 SC_None, SC_None);
Chris Lattner487412d2009-04-27 05:27:42 +00001401 break;
1402
Sebastian Redl539c5062010-08-18 23:57:32 +00001403 case DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001404 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001405 break;
1406
Sebastian Redl539c5062010-08-18 23:57:32 +00001407 case DECL_PARM_VAR:
Mike Stump11289f42009-09-09 15:08:12 +00001408 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
John McCall8e7d6562010-08-26 03:08:43 +00001409 SC_None, SC_None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001410 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001411 case DECL_FILE_SCOPE_ASM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001412 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001413 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001414 case DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +00001415 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001416 break;
1417 }
Chris Lattner487412d2009-04-27 05:27:42 +00001418
Sebastian Redlb3298c32010-08-18 23:56:48 +00001419 assert(D && "Unknown declaration reading AST file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001420 LoadedDecl(Index, D);
1421 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001422
1423 // If this declaration is also a declaration context, get the
1424 // offsets for its tables of lexical and visible declarations.
1425 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1426 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1427 if (Offsets.first || Offsets.second) {
1428 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1429 DC->setHasExternalVisibleStorage(Offsets.second != 0);
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001430 DeclContextInfo Info;
1431 if (ReadDeclContextStorage(DeclsCursor, Offsets, Info))
1432 return 0;
Sebastian Redl4b1f4902010-07-27 18:24:41 +00001433 DeclContextInfos &Infos = DeclContextOffsets[DC];
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001434 // Reading the TU will happen after reading its lexical update blocks,
1435 // so we need to make sure we insert in front. For all other contexts,
1436 // the vector is empty here anyway, so there's no loss in efficiency.
Sebastian Redl4b1f4902010-07-27 18:24:41 +00001437 Infos.insert(Infos.begin(), Info);
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001438
1439 // Now add the pending visible updates for this decl context, if it has
1440 // any.
1441 DeclContextVisibleUpdatesPending::iterator I =
1442 PendingVisibleUpdates.find(ID);
1443 if (I != PendingVisibleUpdates.end()) {
1444 DeclContextVisibleUpdates &U = I->second;
1445 Info.LexicalDecls = 0;
1446 Info.NumLexicalDecls = 0;
1447 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1448 UI != UE; ++UI) {
1449 Info.NameLookupTableData = *UI;
1450 Infos.push_back(Info);
1451 }
1452 PendingVisibleUpdates.erase(I);
1453 }
Chris Lattner487412d2009-04-27 05:27:42 +00001454 }
1455 }
Sebastian Redlaba202b2010-08-24 22:50:19 +00001456
1457 // If this is a template, read additional specializations that may be in a
1458 // different part of the chain.
1459 if (isa<RedeclarableTemplateDecl>(D)) {
1460 AdditionalTemplateSpecializationsMap::iterator F =
1461 AdditionalTemplateSpecializationsPending.find(ID);
1462 if (F != AdditionalTemplateSpecializationsPending.end()) {
1463 for (AdditionalTemplateSpecializations::iterator I = F->second.begin(),
1464 E = F->second.end();
1465 I != E; ++I)
1466 GetDecl(*I);
1467 AdditionalTemplateSpecializationsPending.erase(F);
1468 }
1469 }
Chris Lattner487412d2009-04-27 05:27:42 +00001470 assert(Idx == Record.size());
1471
1472 // If we have deserialized a declaration that has a definition the
Argyrios Kyrtzidis903ccd62010-07-07 15:46:26 +00001473 // AST consumer might need to know about, queue it.
1474 // We don't pass it to the consumer immediately because we may be in recursive
1475 // loading, and some declarations may still be initializing.
1476 if (isConsumerInterestedIn(D))
1477 InterestingDecls.push_back(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001478
1479 return D;
1480}