blob: fe07217574fc3bc1249b8938d2480342608e0af1 [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 Kyrtzidise262a952010-09-09 11:28:23 +0000283 ASTContext &C = *Reader.getContext();
284 TemplateArgumentList *TemplArgList
285 = new (C) TemplateArgumentList(C, TemplArgs.data(), TemplArgs.size());
286 TemplateArgumentListInfo *TemplArgsInfo
287 = new (C) TemplateArgumentListInfo(LAngleLoc, RAngleLoc);
288 for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
289 TemplArgsInfo->addArgument(TemplArgLocs[i]);
290 FunctionTemplateSpecializationInfo *FTInfo
291 = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK,
292 TemplArgList,
293 TemplArgsInfo, POI);
294 FD->TemplateOrSpecialization = FTInfo;
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000295
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000296 if (FD->isCanonicalDecl()) { // if canonical add to template's set.
297 // Get the InsertPos by FindNodeOrInsertPos() instead of calling
298 // InsertNode(FTInfo) directly to avoid the getASTContext() call in
299 // FunctionTemplateSpecializationInfo's Profile().
300 // We avoid getASTContext because a decl in the parent hierarchy may
301 // be initializing.
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000302 llvm::FoldingSetNodeID ID;
303 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs.data(),
304 TemplArgs.size(), C);
305 void *InsertPos = 0;
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000306 Template->getSpecializations().FindNodeOrInsertPos(ID, InsertPos);
307 assert(InsertPos && "Another specialization already inserted!");
308 Template->getSpecializations().InsertNode(FTInfo, InsertPos);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000309 }
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000310 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000311 }
312 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
313 // Templates.
314 UnresolvedSet<8> TemplDecls;
315 unsigned NumTemplates = Record[Idx++];
316 while (NumTemplates--)
317 TemplDecls.addDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
318
319 // Templates args.
320 TemplateArgumentListInfo TemplArgs;
321 unsigned NumArgs = Record[Idx++];
322 while (NumArgs--)
Sebastian Redlc67764e2010-07-22 22:43:28 +0000323 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Cursor,Record, Idx));
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000324 TemplArgs.setLAngleLoc(Reader.ReadSourceLocation(Record, Idx));
325 TemplArgs.setRAngleLoc(Reader.ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000326
327 FD->setDependentTemplateSpecialization(*Reader.getContext(),
328 TemplDecls, TemplArgs);
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000329 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000330 }
331 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000332
Sebastian Redlb3298c32010-08-18 23:56:48 +0000333 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000334 // after everything else is read.
335
John McCall8e7d6562010-08-26 03:08:43 +0000336 FD->setStorageClass((StorageClass)Record[Idx++]);
337 FD->setStorageClassAsWritten((StorageClass)Record[Idx++]);
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000338 FD->setInlineSpecified(Record[Idx++]);
339 FD->setVirtualAsWritten(Record[Idx++]);
340 FD->setPure(Record[Idx++]);
341 FD->setHasInheritedPrototype(Record[Idx++]);
342 FD->setHasWrittenPrototype(Record[Idx++]);
343 FD->setDeleted(Record[Idx++]);
344 FD->setTrivial(Record[Idx++]);
345 FD->setCopyAssignment(Record[Idx++]);
346 FD->setHasImplicitReturnZero(Record[Idx++]);
347 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
348
Chris Lattnerca025db2010-05-07 21:43:38 +0000349 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000350 unsigned NumParams = Record[Idx++];
351 llvm::SmallVector<ParmVarDecl *, 16> Params;
352 Params.reserve(NumParams);
353 for (unsigned I = 0; I != NumParams; ++I)
354 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000355 FD->setParams(*Reader.getContext(), Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000356}
357
Sebastian Redlb3298c32010-08-18 23:56:48 +0000358void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000359 VisitNamedDecl(MD);
360 if (Record[Idx++]) {
361 // In practice, this won't be executed (since method definitions
362 // don't occur in header files).
Sebastian Redlc67764e2010-07-22 22:43:28 +0000363 MD->setBody(Reader.ReadStmt(Cursor));
Chris Lattner487412d2009-04-27 05:27:42 +0000364 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
365 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
366 }
367 MD->setInstanceMethod(Record[Idx++]);
368 MD->setVariadic(Record[Idx++]);
369 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000370 MD->setDefined(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000371 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
372 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahaniand9235db2010-04-08 21:29:11 +0000373 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000374 MD->setResultType(Reader.GetType(Record[Idx++]));
Sebastian Redlc67764e2010-07-22 22:43:28 +0000375 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000376 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
377 unsigned NumParams = Record[Idx++];
378 llvm::SmallVector<ParmVarDecl *, 16> Params;
379 Params.reserve(NumParams);
380 for (unsigned I = 0; I != NumParams; ++I)
381 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniancdabb312010-04-09 15:40:42 +0000382 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
383 NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000384}
385
Sebastian Redlb3298c32010-08-18 23:56:48 +0000386void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000387 VisitNamedDecl(CD);
Ted Kremenekc7c64312010-01-07 01:20:12 +0000388 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
389 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
390 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner487412d2009-04-27 05:27:42 +0000391}
392
Sebastian Redlb3298c32010-08-18 23:56:48 +0000393void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Chris Lattner487412d2009-04-27 05:27:42 +0000394 VisitObjCContainerDecl(ID);
Douglas Gregor1c283312010-08-11 12:19:30 +0000395 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
Chris Lattner487412d2009-04-27 05:27:42 +0000396 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
397 (Reader.GetDecl(Record[Idx++])));
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000398
399 // Read the directly referenced protocols and their SourceLocations.
Chris Lattner487412d2009-04-27 05:27:42 +0000400 unsigned NumProtocols = Record[Idx++];
401 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
402 Protocols.reserve(NumProtocols);
403 for (unsigned I = 0; I != NumProtocols; ++I)
404 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000405 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
406 ProtoLocs.reserve(NumProtocols);
407 for (unsigned I = 0; I != NumProtocols; ++I)
408 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
409 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
410 *Reader.getContext());
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000411
412 // Read the transitive closure of protocols referenced by this class.
413 NumProtocols = Record[Idx++];
414 Protocols.clear();
415 Protocols.reserve(NumProtocols);
416 for (unsigned I = 0; I != NumProtocols; ++I)
417 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
418 ID->AllReferencedProtocols.set(Protocols.data(), NumProtocols,
419 *Reader.getContext());
420
421 // Read the ivars.
Chris Lattner487412d2009-04-27 05:27:42 +0000422 unsigned NumIvars = Record[Idx++];
423 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
424 IVars.reserve(NumIvars);
425 for (unsigned I = 0; I != NumIvars; ++I)
426 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000427 ID->setCategoryList(
428 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000429 // We will rebuild this list lazily.
430 ID->setIvarList(0);
Douglas Gregor1c283312010-08-11 12:19:30 +0000431 ID->setForwardDecl(Record[Idx++]);
432 ID->setImplicitInterfaceDecl(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000433 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
434 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisea72f422009-07-18 00:33:23 +0000435 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000436}
437
Sebastian Redlb3298c32010-08-18 23:56:48 +0000438void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000439 VisitFieldDecl(IVD);
440 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +0000441 // This field will be built lazily.
442 IVD->setNextIvar(0);
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000443 bool synth = Record[Idx++];
444 IVD->setSynthesize(synth);
Chris Lattner487412d2009-04-27 05:27:42 +0000445}
446
Sebastian Redlb3298c32010-08-18 23:56:48 +0000447void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000448 VisitObjCContainerDecl(PD);
449 PD->setForwardDecl(Record[Idx++]);
450 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
451 unsigned NumProtoRefs = Record[Idx++];
452 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
453 ProtoRefs.reserve(NumProtoRefs);
454 for (unsigned I = 0; I != NumProtoRefs; ++I)
455 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000456 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
457 ProtoLocs.reserve(NumProtoRefs);
458 for (unsigned I = 0; I != NumProtoRefs; ++I)
459 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
460 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
461 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000462}
463
Sebastian Redlb3298c32010-08-18 23:56:48 +0000464void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000465 VisitFieldDecl(FD);
466}
467
Sebastian Redlb3298c32010-08-18 23:56:48 +0000468void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000469 VisitDecl(CD);
470 unsigned NumClassRefs = Record[Idx++];
471 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
472 ClassRefs.reserve(NumClassRefs);
473 for (unsigned I = 0; I != NumClassRefs; ++I)
474 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek9b124e12009-11-18 00:28:11 +0000475 llvm::SmallVector<SourceLocation, 16> SLocs;
476 SLocs.reserve(NumClassRefs);
477 for (unsigned I = 0; I != NumClassRefs; ++I)
478 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
479 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
480 NumClassRefs);
Chris Lattner487412d2009-04-27 05:27:42 +0000481}
482
Sebastian Redlb3298c32010-08-18 23:56:48 +0000483void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000484 VisitDecl(FPD);
485 unsigned NumProtoRefs = Record[Idx++];
486 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
487 ProtoRefs.reserve(NumProtoRefs);
488 for (unsigned I = 0; I != NumProtoRefs; ++I)
489 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000490 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
491 ProtoLocs.reserve(NumProtoRefs);
492 for (unsigned I = 0; I != NumProtoRefs; ++I)
493 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
494 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
495 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000496}
497
Sebastian Redlb3298c32010-08-18 23:56:48 +0000498void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000499 VisitObjCContainerDecl(CD);
500 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
501 unsigned NumProtoRefs = Record[Idx++];
502 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
503 ProtoRefs.reserve(NumProtoRefs);
504 for (unsigned I = 0; I != NumProtoRefs; ++I)
505 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor002b6712010-01-16 15:02:53 +0000506 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
507 ProtoLocs.reserve(NumProtoRefs);
508 for (unsigned I = 0; I != NumProtoRefs; ++I)
509 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
510 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
511 *Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +0000512 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000513 CD->setHasSynthBitfield(Record[Idx++]);
Douglas Gregor071676f2010-01-16 16:38:58 +0000514 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
515 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner487412d2009-04-27 05:27:42 +0000516}
517
Sebastian Redlb3298c32010-08-18 23:56:48 +0000518void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000519 VisitNamedDecl(CAD);
520 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
521}
522
Sebastian Redlb3298c32010-08-18 23:56:48 +0000523void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000524 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000525 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Sebastian Redlc67764e2010-07-22 22:43:28 +0000526 D->setType(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000527 // FIXME: stable encoding
528 D->setPropertyAttributes(
529 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000530 D->setPropertyAttributesAsWritten(
531 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000532 // FIXME: stable encoding
533 D->setPropertyImplementation(
534 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
535 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
536 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
537 D->setGetterMethodDecl(
538 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
539 D->setSetterMethodDecl(
540 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
541 D->setPropertyIvarDecl(
542 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
543}
544
Sebastian Redlb3298c32010-08-18 23:56:48 +0000545void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000546 VisitObjCContainerDecl(D);
Chris Lattner487412d2009-04-27 05:27:42 +0000547 D->setClassInterface(
548 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner487412d2009-04-27 05:27:42 +0000549}
550
Sebastian Redlb3298c32010-08-18 23:56:48 +0000551void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000552 VisitObjCImplDecl(D);
553 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
554}
555
Sebastian Redlb3298c32010-08-18 23:56:48 +0000556void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000557 VisitObjCImplDecl(D);
558 D->setSuperClass(
559 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +0000560 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
561 = Reader.ReadCXXBaseOrMemberInitializers(Cursor, Record, Idx);
Fariborz Jahanianbf9294f2010-08-23 18:51:39 +0000562 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000563}
564
565
Sebastian Redlb3298c32010-08-18 23:56:48 +0000566void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +0000567 VisitDecl(D);
568 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
569 D->setPropertyDecl(
570 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
571 D->setPropertyIvarDecl(
572 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisa8607772010-08-09 10:54:37 +0000573 D->setGetterCXXConstructor(Reader.ReadExpr(Cursor));
574 D->setSetterCXXAssignment(Reader.ReadExpr(Cursor));
Chris Lattner487412d2009-04-27 05:27:42 +0000575}
576
Sebastian Redlb3298c32010-08-18 23:56:48 +0000577void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000578 VisitDeclaratorDecl(FD);
Chris Lattner487412d2009-04-27 05:27:42 +0000579 FD->setMutable(Record[Idx++]);
580 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000581 FD->setBitWidth(Reader.ReadExpr(Cursor));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000582 if (!FD->getDeclName()) {
583 FieldDecl *Tmpl = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
584 if (Tmpl)
585 Reader.getContext()->setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
586 }
Chris Lattner487412d2009-04-27 05:27:42 +0000587}
588
Sebastian Redlb3298c32010-08-18 23:56:48 +0000589void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000590 VisitDeclaratorDecl(VD);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000591 VisitRedeclarable(VD);
John McCall8e7d6562010-08-26 03:08:43 +0000592 VD->setStorageClass((StorageClass)Record[Idx++]);
593 VD->setStorageClassAsWritten((StorageClass)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000594 VD->setThreadSpecified(Record[Idx++]);
595 VD->setCXXDirectInitializer(Record[Idx++]);
Douglas Gregor3f324d562010-05-03 18:51:14 +0000596 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor6fd1b182010-05-15 06:01:05 +0000597 VD->setNRVOVariable(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000598 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000599 VD->setInit(Reader.ReadExpr(Cursor));
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000600
601 if (Record[Idx++]) { // HasMemberSpecializationInfo.
602 VarDecl *Tmpl = cast<VarDecl>(Reader.GetDecl(Record[Idx++]));
603 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
604 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
605 Reader.getContext()->setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
606 }
Chris Lattner487412d2009-04-27 05:27:42 +0000607}
608
Sebastian Redlb3298c32010-08-18 23:56:48 +0000609void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000610 VisitVarDecl(PD);
611}
612
Sebastian Redlb3298c32010-08-18 23:56:48 +0000613void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000614 VisitVarDecl(PD);
615 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallf3cd6652010-03-12 18:31:32 +0000616 PD->setHasInheritedDefaultArg(Record[Idx++]);
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000617 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redlc67764e2010-07-22 22:43:28 +0000618 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(Cursor));
Chris Lattner487412d2009-04-27 05:27:42 +0000619}
620
Sebastian Redlb3298c32010-08-18 23:56:48 +0000621void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000622 VisitDecl(AD);
Sebastian Redlc67764e2010-07-22 22:43:28 +0000623 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(Cursor)));
Chris Lattner487412d2009-04-27 05:27:42 +0000624}
625
Sebastian Redlb3298c32010-08-18 23:56:48 +0000626void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000627 VisitDecl(BD);
Sebastian Redlc67764e2010-07-22 22:43:28 +0000628 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(Cursor)));
629 BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000630 unsigned NumParams = Record[Idx++];
631 llvm::SmallVector<ParmVarDecl *, 16> Params;
632 Params.reserve(NumParams);
633 for (unsigned I = 0; I != NumParams; ++I)
634 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregord5058122010-02-11 01:19:42 +0000635 BD->setParams(Params.data(), NumParams);
Chris Lattner487412d2009-04-27 05:27:42 +0000636}
637
Sebastian Redlb3298c32010-08-18 23:56:48 +0000638void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000639 VisitDecl(D);
640 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
641 D->setHasBraces(Record[Idx++]);
642}
643
Sebastian Redlb3298c32010-08-18 23:56:48 +0000644void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000645 VisitNamedDecl(D);
646 D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx));
647 D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx));
648 D->setNextNamespace(
649 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
650
Chris Lattnerca025db2010-05-07 21:43:38 +0000651 bool IsOriginal = Record[Idx++];
Argyrios Kyrtzidisdae2a162010-07-03 07:57:53 +0000652 D->OrigOrAnonNamespace.setInt(IsOriginal);
653 D->OrigOrAnonNamespace.setPointer(
Chris Lattnerca025db2010-05-07 21:43:38 +0000654 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
655}
656
Sebastian Redlb3298c32010-08-18 23:56:48 +0000657void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000658 VisitNamedDecl(D);
Douglas Gregorf9e43ce2010-09-01 00:08:19 +0000659 D->NamespaceLoc = Reader.ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000660 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
661 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
Douglas Gregorf9e43ce2010-09-01 00:08:19 +0000662 D->IdentLoc = Reader.ReadSourceLocation(Record, Idx);
663 D->Namespace = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000664}
665
Sebastian Redlb3298c32010-08-18 23:56:48 +0000666void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000667 VisitNamedDecl(D);
668 D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
669 D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
670 D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
Abramo Bagnara8de74e92010-08-12 11:46:03 +0000671 // FIXME: read the DNLoc component.
Chris Lattnerca025db2010-05-07 21:43:38 +0000672
673 // FIXME: It would probably be more efficient to read these into a vector
674 // and then re-cosntruct the shadow decl set over that vector since it
675 // would avoid existence checks.
676 unsigned NumShadows = Record[Idx++];
677 for(unsigned I = 0; I != NumShadows; ++I) {
Argyrios Kyrtzidis00dda6a2010-07-08 13:09:41 +0000678 // Avoid invariant checking of UsingDecl::addShadowDecl, the decl may still
679 // be initializing.
680 D->Shadows.insert(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattnerca025db2010-05-07 21:43:38 +0000681 }
682 D->setTypeName(Record[Idx++]);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000683 NamedDecl *Pattern = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
684 if (Pattern)
685 Reader.getContext()->setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000686}
687
Sebastian Redlb3298c32010-08-18 23:56:48 +0000688void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000689 VisitNamedDecl(D);
690 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
691 D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000692 UsingShadowDecl *Pattern
693 = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]));
694 if (Pattern)
695 Reader.getContext()->setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattnerca025db2010-05-07 21:43:38 +0000696}
697
Sebastian Redlb3298c32010-08-18 23:56:48 +0000698void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000699 VisitNamedDecl(D);
Douglas Gregor01a430132010-09-01 03:07:18 +0000700 D->UsingLoc = Reader.ReadSourceLocation(Record, Idx);
701 D->NamespaceLoc = Reader.ReadSourceLocation(Record, Idx);
702 D->QualifierRange = Reader.ReadSourceRange(Record, Idx);
703 D->Qualifier = Reader.ReadNestedNameSpecifier(Record, Idx);
704 D->NominatedNamespace = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
705 D->CommonAncestor = cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000706}
707
Sebastian Redlb3298c32010-08-18 23:56:48 +0000708void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000709 VisitValueDecl(D);
710 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
711 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
712 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
Abramo Bagnara8de74e92010-08-12 11:46:03 +0000713 // FIXME: read the DNLoc component.
Chris Lattnerca025db2010-05-07 21:43:38 +0000714}
715
Sebastian Redlb3298c32010-08-18 23:56:48 +0000716void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000717 UnresolvedUsingTypenameDecl *D) {
718 VisitTypeDecl(D);
Douglas Gregora9aa29c2010-09-01 19:52:22 +0000719 D->TargetNestedNameRange = Reader.ReadSourceRange(Record, Idx);
720 D->UsingLocation = Reader.ReadSourceLocation(Record, Idx);
721 D->TypenameLocation = Reader.ReadSourceLocation(Record, Idx);
722 D->TargetNestedNameSpecifier = Reader.ReadNestedNameSpecifier(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000723}
724
Sebastian Redlb3298c32010-08-18 23:56:48 +0000725void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000726 ASTContext &C = *Reader.getContext();
727
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000728 // We need to allocate the DefinitionData struct ahead of VisitRecordDecl
729 // so that the other CXXRecordDecls can get a pointer even when the owner
730 // is still initializing.
731 bool OwnsDefinitionData = false;
732 enum DataOwnership { Data_NoDefData, Data_Owner, Data_NotOwner };
733 switch ((DataOwnership)Record[Idx++]) {
734 default:
Sebastian Redlb3298c32010-08-18 23:56:48 +0000735 assert(0 && "Out of sync with ASTDeclWriter or messed up reading");
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000736 case Data_NoDefData:
737 break;
738 case Data_Owner:
739 OwnsDefinitionData = true;
740 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
741 break;
742 case Data_NotOwner:
743 D->DefinitionData
744 = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]))->DefinitionData;
745 break;
746 }
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000747
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000748 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000749
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000750 if (OwnsDefinitionData) {
751 assert(D->DefinitionData);
752 struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData;
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000753
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000754 Data.UserDeclaredConstructor = Record[Idx++];
755 Data.UserDeclaredCopyConstructor = Record[Idx++];
756 Data.UserDeclaredCopyAssignment = Record[Idx++];
757 Data.UserDeclaredDestructor = Record[Idx++];
758 Data.Aggregate = Record[Idx++];
759 Data.PlainOldData = Record[Idx++];
760 Data.Empty = Record[Idx++];
761 Data.Polymorphic = Record[Idx++];
762 Data.Abstract = Record[Idx++];
763 Data.HasTrivialConstructor = Record[Idx++];
764 Data.HasTrivialCopyConstructor = Record[Idx++];
765 Data.HasTrivialCopyAssignment = Record[Idx++];
766 Data.HasTrivialDestructor = Record[Idx++];
767 Data.ComputedVisibleConversions = Record[Idx++];
768 Data.DeclaredDefaultConstructor = Record[Idx++];
769 Data.DeclaredCopyConstructor = Record[Idx++];
770 Data.DeclaredCopyAssignment = Record[Idx++];
771 Data.DeclaredDestructor = Record[Idx++];
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000772
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000773 // setBases() is unsuitable since it may try to iterate the bases of an
Nick Lewycky19b9f952010-07-26 16:56:01 +0000774 // uninitialized base.
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000775 Data.NumBases = Record[Idx++];
776 Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases];
777 for (unsigned i = 0; i != Data.NumBases; ++i)
Nick Lewycky19b9f952010-07-26 16:56:01 +0000778 Data.Bases[i] = Reader.ReadCXXBaseSpecifier(Cursor, Record, Idx);
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000779
780 // FIXME: Make VBases lazily computed when needed to avoid storing them.
781 Data.NumVBases = Record[Idx++];
782 Data.VBases = new(C) CXXBaseSpecifier [Data.NumVBases];
783 for (unsigned i = 0; i != Data.NumVBases; ++i)
Nick Lewycky19b9f952010-07-26 16:56:01 +0000784 Data.VBases[i] = Reader.ReadCXXBaseSpecifier(Cursor, Record, Idx);
Argyrios Kyrtzidis181431c2010-07-06 15:36:58 +0000785
786 Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx);
787 Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx);
788 assert(Data.Definition && "Data.Definition should be already set!");
789 Data.FirstFriend
790 = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +0000791 }
792
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000793 enum CXXRecKind {
794 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
795 };
796 switch ((CXXRecKind)Record[Idx++]) {
797 default:
Sebastian Redlb3298c32010-08-18 23:56:48 +0000798 assert(false && "Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000799 case CXXRecNotTemplate:
800 break;
801 case CXXRecTemplate:
Argyrios Kyrtzidiscaf82482010-09-13 11:45:25 +0000802 D->TemplateOrInstantiation
803 = cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000804 break;
805 case CXXRecMemberSpecialization: {
806 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
807 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
808 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidiscaf82482010-09-13 11:45:25 +0000809 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
810 MSI->setPointOfInstantiation(POI);
811 D->TemplateOrInstantiation = MSI;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000812 break;
813 }
814 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000815}
816
Sebastian Redlb3298c32010-08-18 23:56:48 +0000817void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000818 VisitFunctionDecl(D);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000819 unsigned NumOverridenMethods = Record[Idx++];
820 while (NumOverridenMethods--) {
821 CXXMethodDecl *MD = cast<CXXMethodDecl>(Reader.GetDecl(Record[Idx++]));
822 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
823 // MD may be initializing.
824 Reader.getContext()->addOverriddenMethod(D, MD);
825 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000826}
827
Sebastian Redlb3298c32010-08-18 23:56:48 +0000828void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000829 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000830
831 D->IsExplicitSpecified = Record[Idx++];
832 D->ImplicitlyDefined = Record[Idx++];
Argyrios Kyrtzidis5b6a03f2010-08-09 10:54:12 +0000833 llvm::tie(D->BaseOrMemberInitializers, D->NumBaseOrMemberInitializers)
834 = Reader.ReadCXXBaseOrMemberInitializers(Cursor, Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000835}
836
Sebastian Redlb3298c32010-08-18 23:56:48 +0000837void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000838 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000839
840 D->ImplicitlyDefined = Record[Idx++];
841 D->OperatorDelete = cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattnerca025db2010-05-07 21:43:38 +0000842}
843
Sebastian Redlb3298c32010-08-18 23:56:48 +0000844void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000845 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000846 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +0000847}
848
Sebastian Redlb3298c32010-08-18 23:56:48 +0000849void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +0000850 VisitDecl(D);
851 D->setColonLoc(Reader.ReadSourceLocation(Record, Idx));
852}
853
Sebastian Redlb3298c32010-08-18 23:56:48 +0000854void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000855 VisitDecl(D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000856 if (Record[Idx++])
Sebastian Redlc67764e2010-07-22 22:43:28 +0000857 D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000858 else
859 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
860 D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
861 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
862}
863
Sebastian Redlb3298c32010-08-18 23:56:48 +0000864void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +0000865 VisitDecl(D);
866 unsigned NumParams = Record[Idx++];
867 D->NumParams = NumParams;
868 D->Params = new TemplateParameterList*[NumParams];
869 for (unsigned i = 0; i != NumParams; ++i)
870 D->Params[i] = Reader.ReadTemplateParameterList(Record, Idx);
871 if (Record[Idx++]) // HasFriendDecl
872 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
873 else
Sebastian Redlc67764e2010-07-22 22:43:28 +0000874 D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +0000875 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
Chris Lattnerca025db2010-05-07 21:43:38 +0000876}
877
Sebastian Redlb3298c32010-08-18 23:56:48 +0000878void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000879 VisitNamedDecl(D);
880
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +0000881 NamedDecl *TemplatedDecl
882 = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000883 TemplateParameterList* TemplateParams
884 = Reader.ReadTemplateParameterList(Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000885 D->init(TemplatedDecl, TemplateParams);
Chris Lattnerca025db2010-05-07 21:43:38 +0000886}
887
Sebastian Redlb3298c32010-08-18 23:56:48 +0000888void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000889 // Initialize CommonOrPrev before VisitTemplateDecl so that getCommonPtr()
890 // can be used while this is still initializing.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000891
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000892 assert(D->CommonOrPrev.isNull() && "getCommonPtr was called earlier on this");
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000893 RedeclarableTemplateDecl *PrevDecl =
894 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]));
895 assert((PrevDecl == 0 || PrevDecl->getKind() == D->getKind()) &&
896 "PrevDecl kind mismatch");
897 if (PrevDecl)
898 D->CommonOrPrev = PrevDecl;
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000899 if (PrevDecl == 0) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000900 D->CommonOrPrev = D->newCommon(*Reader.getContext());
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000901 if (RedeclarableTemplateDecl *RTD
902 = cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
903 assert(RTD->getKind() == D->getKind() &&
904 "InstantiatedFromMemberTemplate kind mismatch");
905 D->setInstantiatedFromMemberTemplateImpl(RTD);
906 if (Record[Idx++])
907 D->setMemberSpecialization();
908 }
Peter Collingbourne2bf3d242010-07-29 16:12:01 +0000909
910 RedeclarableTemplateDecl *LatestDecl =
911 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000912
913 // This decl is a first one and the latest declaration that it points to is
Sebastian Redld44cd6a2010-08-18 23:57:06 +0000914 // in the same AST file. However, if this actually needs to point to a
915 // redeclaration in another AST file, we need to update it by checking
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000916 // the FirstLatestDeclIDs map which tracks this kind of decls.
917 assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +0000918 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000919 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
920 if (I != Reader.FirstLatestDeclIDs.end()) {
921 Decl *NewLatest = Reader.GetDecl(I->second);
922 assert((LatestDecl->getLocation().isInvalid() ||
923 NewLatest->getLocation().isInvalid() ||
924 Reader.SourceMgr.isBeforeInTranslationUnit(
925 LatestDecl->getLocation(),
926 NewLatest->getLocation())) &&
927 "The new latest is supposed to come after the previous latest");
928 LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
929 }
930
Peter Collingbourne2bf3d242010-07-29 16:12:01 +0000931 assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
932 D->getCommonPtr()->Latest = LatestDecl;
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000933 }
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000934
935 VisitTemplateDecl(D);
936 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000937}
938
Sebastian Redlb3298c32010-08-18 23:56:48 +0000939void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000940 VisitRedeclarableTemplateDecl(D);
941
942 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000943 // This ClassTemplateDecl owns a CommonPtr; read it.
944
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000945 // FoldingSets are filled in VisitClassTemplateSpecializationDecl.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000946 unsigned size = Record[Idx++];
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000947 while (size--)
948 cast<ClassTemplateSpecializationDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000949
950 size = Record[Idx++];
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000951 while (size--)
952 cast<ClassTemplatePartialSpecializationDecl>(
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000953 Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000954
955 // InjectedClassNameType is computed.
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +0000956 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000957}
958
Sebastian Redlb3298c32010-08-18 23:56:48 +0000959void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000960 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000961 VisitCXXRecordDecl(D);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +0000962
963 ASTContext &C = *Reader.getContext();
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000964 if (Decl *InstD = Reader.GetDecl(Record[Idx++])) {
965 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +0000966 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000967 } else {
968 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000969 Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +0000970 TemplateArgumentList *ArgList
971 = new (C) TemplateArgumentList(C, TemplArgs.data(), TemplArgs.size());
972 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
973 = new (C) ClassTemplateSpecializationDecl::
974 SpecializedPartialSpecialization();
975 PS->PartialSpecialization
976 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
977 PS->TemplateArgs = ArgList;
978 D->SpecializedTemplate = PS;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000979 }
980 }
981
982 // Explicit info.
Sebastian Redlc67764e2010-07-22 22:43:28 +0000983 if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +0000984 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
985 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
986 ExplicitInfo->TypeAsWritten = TyInfo;
987 ExplicitInfo->ExternLoc = Reader.ReadSourceLocation(Record, Idx);
988 ExplicitInfo->TemplateKeywordLoc = Reader.ReadSourceLocation(Record, Idx);
989 D->ExplicitInfo = ExplicitInfo;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000990 }
991
992 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000993 Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +0000994 D->TemplateArgs.init(C, TemplArgs.data(), TemplArgs.size());
995 D->PointOfInstantiation = Reader.ReadSourceLocation(Record, Idx);
996 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000997
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +0000998 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +0000999 ClassTemplateDecl *CanonPattern
1000 = cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
1001 if (ClassTemplatePartialSpecializationDecl *Partial
1002 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
Argyrios Kyrtzidisf4cc7dc2010-07-12 21:41:31 +00001003 CanonPattern->getPartialSpecializations().InsertNode(Partial);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001004 } else {
Argyrios Kyrtzidisf4cc7dc2010-07-12 21:41:31 +00001005 CanonPattern->getSpecializations().InsertNode(D);
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001006 }
1007 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001008}
1009
Sebastian Redlb3298c32010-08-18 23:56:48 +00001010void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001011 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001012 VisitClassTemplateSpecializationDecl(D);
1013
1014 D->initTemplateParameters(Reader.ReadTemplateParameterList(Record, Idx));
1015
1016 TemplateArgumentListInfo ArgInfos;
1017 unsigned NumArgs = Record[Idx++];
1018 while (NumArgs--)
Sebastian Redlc67764e2010-07-22 22:43:28 +00001019 ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001020 D->initTemplateArgsAsWritten(ArgInfos);
1021
1022 D->setSequenceNumber(Record[Idx++]);
1023
1024 // These are read/set from/to the first declaration.
1025 if (D->getPreviousDeclaration() == 0) {
1026 D->setInstantiatedFromMember(
1027 cast_or_null<ClassTemplatePartialSpecializationDecl>(
1028 Reader.GetDecl(Record[Idx++])));
1029 if (Record[Idx++])
Argyrios Kyrtzidisdd2061b2010-07-09 21:11:35 +00001030 D->setMemberSpecialization();
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001031 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001032}
1033
Sebastian Redlb3298c32010-08-18 23:56:48 +00001034void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001035 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001036
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001037 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001038 // This FunctionTemplateDecl owns a CommonPtr; read it.
1039
Argyrios Kyrtzidis39fdf812010-07-06 15:37:09 +00001040 // Read the function specialization declarations.
1041 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
1042 // through the specialized FunctionDecl's setFunctionTemplateSpecialization.
1043 unsigned NumSpecs = Record[Idx++];
1044 while (NumSpecs--)
1045 Reader.GetDecl(Record[Idx++]);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001046 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001047}
1048
Sebastian Redlb3298c32010-08-18 23:56:48 +00001049void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001050 VisitTypeDecl(D);
1051
1052 D->setDeclaredWithTypename(Record[Idx++]);
1053 D->setParameterPack(Record[Idx++]);
1054
1055 bool Inherited = Record[Idx++];
Sebastian Redlc67764e2010-07-22 22:43:28 +00001056 TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001057 D->setDefaultArgument(DefArg, Inherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001058}
1059
Sebastian Redlb3298c32010-08-18 23:56:48 +00001060void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001061 VisitVarDecl(D);
1062 // TemplateParmPosition.
1063 D->setDepth(Record[Idx++]);
1064 D->setPosition(Record[Idx++]);
1065 // Rest of NonTypeTemplateParmDecl.
1066 if (Record[Idx++]) {
Sebastian Redlc67764e2010-07-22 22:43:28 +00001067 Expr *DefArg = Reader.ReadExpr(Cursor);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001068 bool Inherited = Record[Idx++];
1069 D->setDefaultArgument(DefArg, Inherited);
1070 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001071}
1072
Sebastian Redlb3298c32010-08-18 23:56:48 +00001073void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001074 VisitTemplateDecl(D);
1075 // TemplateParmPosition.
1076 D->setDepth(Record[Idx++]);
1077 D->setPosition(Record[Idx++]);
1078 // Rest of TemplateTemplateParmDecl.
Sebastian Redlc67764e2010-07-22 22:43:28 +00001079 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx);
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001080 bool IsInherited = Record[Idx++];
1081 D->setDefaultArgument(Arg, IsInherited);
Chris Lattnerca025db2010-05-07 21:43:38 +00001082}
1083
Sebastian Redlb3298c32010-08-18 23:56:48 +00001084void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001085 VisitDecl(D);
Sebastian Redlc67764e2010-07-22 22:43:28 +00001086 D->AssertExpr = Reader.ReadExpr(Cursor);
1087 D->Message = cast<StringLiteral>(Reader.ReadExpr(Cursor));
Chris Lattnerca025db2010-05-07 21:43:38 +00001088}
1089
Mike Stump11289f42009-09-09 15:08:12 +00001090std::pair<uint64_t, uint64_t>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001091ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner487412d2009-04-27 05:27:42 +00001092 uint64_t LexicalOffset = Record[Idx++];
1093 uint64_t VisibleOffset = Record[Idx++];
1094 return std::make_pair(LexicalOffset, VisibleOffset);
1095}
1096
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001097template <typename T>
Sebastian Redlb3298c32010-08-18 23:56:48 +00001098void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001099 enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest };
1100 RedeclKind Kind = (RedeclKind)Record[Idx++];
1101 switch (Kind) {
1102 default:
Sebastian Redlb3298c32010-08-18 23:56:48 +00001103 assert(0 && "Out of sync with ASTDeclWriter::VisitRedeclarable or messed up"
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001104 " reading");
1105 case NoRedeclaration:
1106 break;
1107 case PointsToPrevious:
1108 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(
1109 cast_or_null<T>(Reader.GetDecl(Record[Idx++])));
1110 break;
1111 case PointsToLatest:
1112 D->RedeclLink = typename Redeclarable<T>::LatestDeclLink(
1113 cast_or_null<T>(Reader.GetDecl(Record[Idx++])));
1114 break;
1115 }
1116
1117 assert(!(Kind == PointsToPrevious &&
1118 Reader.FirstLatestDeclIDs.find(ThisDeclID) !=
1119 Reader.FirstLatestDeclIDs.end()) &&
1120 "This decl is not first, it should not be in the map");
1121 if (Kind == PointsToPrevious)
1122 return;
1123
1124 // This decl is a first one and the latest declaration that it points to is in
Sebastian Redld44cd6a2010-08-18 23:57:06 +00001125 // the same AST file. However, if this actually needs to point to a
1126 // redeclaration in another AST file, we need to update it by checking the
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001127 // FirstLatestDeclIDs map which tracks this kind of decls.
1128 assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) &&
1129 "Invalid ThisDeclID ?");
Sebastian Redl2c499f62010-08-18 23:56:43 +00001130 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001131 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1132 if (I != Reader.FirstLatestDeclIDs.end()) {
1133 Decl *NewLatest = Reader.GetDecl(I->second);
1134 assert((D->getMostRecentDeclaration()->getLocation().isInvalid() ||
1135 NewLatest->getLocation().isInvalid() ||
1136 Reader.SourceMgr.isBeforeInTranslationUnit(
1137 D->getMostRecentDeclaration()->getLocation(),
1138 NewLatest->getLocation())) &&
1139 "The new latest is supposed to come after the previous latest");
1140 D->RedeclLink
1141 = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest));
1142 }
1143}
1144
Chris Lattner487412d2009-04-27 05:27:42 +00001145//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00001146// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00001147//===----------------------------------------------------------------------===//
1148
Chris Lattner8f63ab52009-04-27 06:01:06 +00001149/// \brief Reads attributes from the current stream position.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001150void ASTReader::ReadAttributes(llvm::BitstreamCursor &DeclsCursor,
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001151 AttrVec &Attrs) {
Chris Lattner8f63ab52009-04-27 06:01:06 +00001152 unsigned Code = DeclsCursor.ReadCode();
Mike Stump11289f42009-09-09 15:08:12 +00001153 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner8f63ab52009-04-27 06:01:06 +00001154 "Expected unabbreviated record"); (void)Code;
Mike Stump11289f42009-09-09 15:08:12 +00001155
Chris Lattner8f63ab52009-04-27 06:01:06 +00001156 RecordData Record;
1157 unsigned Idx = 0;
1158 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001159 assert(RecCode == DECL_ATTR && "Expected attribute record");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001160 (void)RecCode;
1161
Chris Lattner8f63ab52009-04-27 06:01:06 +00001162 while (Idx < Record.size()) {
1163 Attr *New = 0;
Alexis Hunt344393e2010-06-16 23:43:53 +00001164 attr::Kind Kind = (attr::Kind)Record[Idx++];
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001165 SourceLocation Loc = SourceLocation::getFromRawEncoding(Record[Idx++]);
1166 bool isInherited = Record[Idx++];
Chris Lattner8f63ab52009-04-27 06:01:06 +00001167
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001168#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner8f63ab52009-04-27 06:01:06 +00001169
1170 assert(New && "Unable to decode attribute?");
Alexis Huntdcfba7b2010-08-18 23:23:40 +00001171 New->setInherited(isInherited);
1172 Attrs.push_back(New);
Chris Lattner8f63ab52009-04-27 06:01:06 +00001173 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00001174}
1175
1176//===----------------------------------------------------------------------===//
Sebastian Redl2c499f62010-08-18 23:56:43 +00001177// ASTReader Implementation
Chris Lattner8f63ab52009-04-27 06:01:06 +00001178//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00001179
1180/// \brief Note that we have loaded the declaration with the given
1181/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00001182///
Chris Lattner487412d2009-04-27 05:27:42 +00001183/// This routine notes that this declaration has already been loaded,
1184/// so that future GetDecl calls will return this declaration rather
1185/// than trying to load a new declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001186inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001187 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1188 DeclsLoaded[Index] = D;
1189}
1190
1191
1192/// \brief Determine whether the consumer will be interested in seeing
1193/// this declaration (via HandleTopLevelDecl).
1194///
1195/// This routine should return true for anything that might affect
1196/// code generation, e.g., inline function definitions, Objective-C
1197/// declarations with metadata, etc.
1198static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar865c2a72009-09-17 03:06:44 +00001199 if (isa<FileScopeAsmDecl>(D))
1200 return true;
Chris Lattner487412d2009-04-27 05:27:42 +00001201 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis4ba81b22010-08-05 09:47:59 +00001202 return Var->isFileVarDecl() &&
1203 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner487412d2009-04-27 05:27:42 +00001204 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1205 return Func->isThisDeclarationADefinition();
Argyrios Kyrtzidis13257c52010-08-09 10:54:20 +00001206 return isa<ObjCProtocolDecl>(D) || isa<ObjCImplementationDecl>(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001207}
1208
Sebastian Redl34627792010-07-20 22:46:15 +00001209/// \brief Get the correct cursor and offset for loading a type.
Sebastian Redl2c499f62010-08-18 23:56:43 +00001210ASTReader::RecordLocation
Sebastian Redl539c5062010-08-18 23:57:32 +00001211ASTReader::DeclCursorForIndex(unsigned Index, DeclID ID) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001212 // See if there's an override.
1213 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
1214 if (It != ReplacedDecls.end())
1215 return RecordLocation(&It->second.first->DeclsCursor, It->second.second);
1216
Sebastian Redl34627792010-07-20 22:46:15 +00001217 PerFileData *F = 0;
1218 for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
1219 F = Chain[N - I - 1];
1220 if (Index < F->LocalNumDecls)
1221 break;
1222 Index -= F->LocalNumDecls;
1223 }
1224 assert(F && F->LocalNumDecls > Index && "Broken chain");
Sebastian Redlb2831db2010-07-20 22:55:31 +00001225 return RecordLocation(&F->DeclsCursor, F->DeclOffsets[Index]);
Sebastian Redl34627792010-07-20 22:46:15 +00001226}
1227
Sebastian Redlb3298c32010-08-18 23:56:48 +00001228/// \brief Read the declaration at the given offset from the AST file.
Sebastian Redl539c5062010-08-18 23:57:32 +00001229Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00001230 RecordLocation Loc = DeclCursorForIndex(Index, ID);
Sebastian Redlb2831db2010-07-20 22:55:31 +00001231 llvm::BitstreamCursor &DeclsCursor = *Loc.first;
Chris Lattner487412d2009-04-27 05:27:42 +00001232 // Keep track of where we are in the stream, then jump back there
1233 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00001234 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00001235
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00001236 ReadingKindTracker ReadingKind(Read_Decl, *this);
1237
Douglas Gregor1342e842009-07-06 18:54:52 +00001238 // Note that we are loading a declaration record.
Argyrios Kyrtzidisb24355a2010-07-30 10:03:16 +00001239 Deserializing ADecl(this);
Mike Stump11289f42009-09-09 15:08:12 +00001240
Sebastian Redl34627792010-07-20 22:46:15 +00001241 DeclsCursor.JumpToBit(Loc.second);
Chris Lattner487412d2009-04-27 05:27:42 +00001242 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00001243 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00001244 unsigned Idx = 0;
Sebastian Redlb3298c32010-08-18 23:56:48 +00001245 ASTDeclReader Reader(*this, DeclsCursor, ID, Record, Idx);
Chris Lattner487412d2009-04-27 05:27:42 +00001246
Chris Lattner1de76db2009-04-27 05:58:23 +00001247 Decl *D = 0;
Sebastian Redl539c5062010-08-18 23:57:32 +00001248 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
1249 case DECL_ATTR:
1250 case DECL_CONTEXT_LEXICAL:
1251 case DECL_CONTEXT_VISIBLE:
Chris Lattner487412d2009-04-27 05:27:42 +00001252 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1253 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001254 case DECL_TRANSLATION_UNIT:
Chris Lattner487412d2009-04-27 05:27:42 +00001255 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattner8575daa2009-04-27 21:45:14 +00001256 D = Context->getTranslationUnitDecl();
Chris Lattner487412d2009-04-27 05:27:42 +00001257 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001258 case DECL_TYPEDEF:
John McCall703a3f82009-10-24 08:00:42 +00001259 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001260 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001261 case DECL_ENUM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001262 D = EnumDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001263 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001264 case DECL_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001265 D = RecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner487412d2009-04-27 05:27:42 +00001266 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001267 case DECL_ENUM_CONSTANT:
Chris Lattner8575daa2009-04-27 21:45:14 +00001268 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner487412d2009-04-27 05:27:42 +00001269 0, llvm::APSInt());
1270 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001271 case DECL_FUNCTION:
Mike Stump11289f42009-09-09 15:08:12 +00001272 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001273 QualType(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001274 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001275 case DECL_LINKAGE_SPEC:
Chris Lattnerca025db2010-05-07 21:43:38 +00001276 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
1277 (LinkageSpecDecl::LanguageIDs)0,
1278 false);
1279 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001280 case DECL_NAMESPACE:
Chris Lattnerca025db2010-05-07 21:43:38 +00001281 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
1282 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001283 case DECL_NAMESPACE_ALIAS:
Chris Lattnerca025db2010-05-07 21:43:38 +00001284 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
1285 SourceLocation(), 0, SourceRange(), 0,
1286 SourceLocation(), 0);
1287 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001288 case DECL_USING:
Abramo Bagnara8de74e92010-08-12 11:46:03 +00001289 D = UsingDecl::Create(*Context, 0, SourceRange(), SourceLocation(),
1290 0, DeclarationNameInfo(), false);
Chris Lattnerca025db2010-05-07 21:43:38 +00001291 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001292 case DECL_USING_SHADOW:
Chris Lattnerca025db2010-05-07 21:43:38 +00001293 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1294 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001295 case DECL_USING_DIRECTIVE:
Chris Lattnerca025db2010-05-07 21:43:38 +00001296 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
1297 SourceLocation(), SourceRange(), 0,
1298 SourceLocation(), 0, 0);
1299 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001300 case DECL_UNRESOLVED_USING_VALUE:
Chris Lattnerca025db2010-05-07 21:43:38 +00001301 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
Abramo Bagnara8de74e92010-08-12 11:46:03 +00001302 SourceRange(), 0,
1303 DeclarationNameInfo());
Chris Lattnerca025db2010-05-07 21:43:38 +00001304 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001305 case DECL_UNRESOLVED_USING_TYPENAME:
Chris Lattnerca025db2010-05-07 21:43:38 +00001306 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
1307 SourceLocation(), SourceRange(),
1308 0, SourceLocation(),
1309 DeclarationName());
1310 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001311 case DECL_CXX_RECORD:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001312 D = CXXRecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001313 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001314 case DECL_CXX_METHOD:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001315 D = CXXMethodDecl::Create(*Context, 0, DeclarationNameInfo(),
Chris Lattnerca025db2010-05-07 21:43:38 +00001316 QualType(), 0);
1317 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001318 case DECL_CXX_CONSTRUCTOR:
Chris Lattnerca025db2010-05-07 21:43:38 +00001319 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1320 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001321 case DECL_CXX_DESTRUCTOR:
Chris Lattnerca025db2010-05-07 21:43:38 +00001322 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1323 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001324 case DECL_CXX_CONVERSION:
Chris Lattnerca025db2010-05-07 21:43:38 +00001325 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1326 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001327 case DECL_ACCESS_SPEC:
Argyrios Kyrtzidis260b4a82010-09-08 21:32:35 +00001328 D = AccessSpecDecl::Create(*Context, Decl::EmptyShell());
Abramo Bagnarad7340582010-06-05 05:09:32 +00001329 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001330 case DECL_FRIEND:
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001331 D = FriendDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001332 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001333 case DECL_FRIEND_TEMPLATE:
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001334 D = FriendTemplateDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001335 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001336 case DECL_CLASS_TEMPLATE:
Argyrios Kyrtzidisa35c8e42010-06-21 10:57:41 +00001337 D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(),
1338 DeclarationName(), 0, 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001339 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001340 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001341 D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001342 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001343 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001344 D = ClassTemplatePartialSpecializationDecl::Create(*Context,
1345 Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001346 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001347 case DECL_FUNCTION_TEMPLATE:
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001348 D = FunctionTemplateDecl::Create(*Context, 0, SourceLocation(),
1349 DeclarationName(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001350 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001351 case DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidis39f0e302010-07-02 11:54:55 +00001352 D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell());
Chris Lattnerca025db2010-05-07 21:43:38 +00001353 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001354 case DECL_NON_TYPE_TEMPLATE_PARM:
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001355 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0,
1356 QualType(),0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001357 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001358 case DECL_TEMPLATE_TEMPLATE_PARM:
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001359 D = TemplateTemplateParmDecl::Create(*Context, 0, SourceLocation(),0,0,0,0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001360 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001361 case DECL_STATIC_ASSERT:
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001362 D = StaticAssertDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattnerca025db2010-05-07 21:43:38 +00001363 break;
1364
Sebastian Redl539c5062010-08-18 23:57:32 +00001365 case DECL_OBJC_METHOD:
Mike Stump11289f42009-09-09 15:08:12 +00001366 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor12852d92010-03-08 14:59:44 +00001367 Selector(), QualType(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001368 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001369 case DECL_OBJC_INTERFACE:
Douglas Gregor1c283312010-08-11 12:19:30 +00001370 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001371 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001372 case DECL_OBJC_IVAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001373 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001374 ObjCIvarDecl::None);
1375 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001376 case DECL_OBJC_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001377 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001378 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001379 case DECL_OBJC_AT_DEFS_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001380 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001381 QualType(), 0);
1382 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001383 case DECL_OBJC_CLASS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001384 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001385 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001386 case DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001387 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001388 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001389 case DECL_OBJC_CATEGORY:
Douglas Gregor071676f2010-01-16 16:38:58 +00001390 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1391 SourceLocation(), SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001392 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001393 case DECL_OBJC_CATEGORY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001394 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001395 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001396 case DECL_OBJC_IMPLEMENTATION:
Chris Lattner8575daa2009-04-27 21:45:14 +00001397 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001398 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001399 case DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattner8575daa2009-04-27 21:45:14 +00001400 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001401 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001402 case DECL_OBJC_PROPERTY:
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +00001403 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall339bb662010-06-04 20:50:08 +00001404 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001405 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001406 case DECL_OBJC_PROPERTY_IMPL:
Chris Lattner8575daa2009-04-27 21:45:14 +00001407 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump11289f42009-09-09 15:08:12 +00001408 SourceLocation(), 0,
Chris Lattner487412d2009-04-27 05:27:42 +00001409 ObjCPropertyImplDecl::Dynamic, 0);
1410 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001411 case DECL_FIELD:
Mike Stump11289f42009-09-09 15:08:12 +00001412 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidis6032ef12009-08-21 00:31:54 +00001413 false);
Chris Lattner487412d2009-04-27 05:27:42 +00001414 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001415 case DECL_VAR:
Argyrios Kyrtzidis60ed5602009-08-19 01:27:57 +00001416 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
John McCall8e7d6562010-08-26 03:08:43 +00001417 SC_None, SC_None);
Chris Lattner487412d2009-04-27 05:27:42 +00001418 break;
1419
Sebastian Redl539c5062010-08-18 23:57:32 +00001420 case DECL_IMPLICIT_PARAM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001421 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner487412d2009-04-27 05:27:42 +00001422 break;
1423
Sebastian Redl539c5062010-08-18 23:57:32 +00001424 case DECL_PARM_VAR:
Mike Stump11289f42009-09-09 15:08:12 +00001425 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
John McCall8e7d6562010-08-26 03:08:43 +00001426 SC_None, SC_None, 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001427 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001428 case DECL_FILE_SCOPE_ASM:
Chris Lattner8575daa2009-04-27 21:45:14 +00001429 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner487412d2009-04-27 05:27:42 +00001430 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00001431 case DECL_BLOCK:
Chris Lattner8575daa2009-04-27 21:45:14 +00001432 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001433 break;
1434 }
Chris Lattner487412d2009-04-27 05:27:42 +00001435
Sebastian Redlb3298c32010-08-18 23:56:48 +00001436 assert(D && "Unknown declaration reading AST file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00001437 LoadedDecl(Index, D);
1438 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001439
1440 // If this declaration is also a declaration context, get the
1441 // offsets for its tables of lexical and visible declarations.
1442 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1443 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1444 if (Offsets.first || Offsets.second) {
1445 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1446 DC->setHasExternalVisibleStorage(Offsets.second != 0);
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001447 DeclContextInfo Info;
1448 if (ReadDeclContextStorage(DeclsCursor, Offsets, Info))
1449 return 0;
Sebastian Redl4b1f4902010-07-27 18:24:41 +00001450 DeclContextInfos &Infos = DeclContextOffsets[DC];
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001451 // Reading the TU will happen after reading its lexical update blocks,
1452 // so we need to make sure we insert in front. For all other contexts,
1453 // the vector is empty here anyway, so there's no loss in efficiency.
Sebastian Redl4b1f4902010-07-27 18:24:41 +00001454 Infos.insert(Infos.begin(), Info);
Sebastian Redld7dce0a2010-08-24 00:50:04 +00001455
1456 // Now add the pending visible updates for this decl context, if it has
1457 // any.
1458 DeclContextVisibleUpdatesPending::iterator I =
1459 PendingVisibleUpdates.find(ID);
1460 if (I != PendingVisibleUpdates.end()) {
1461 DeclContextVisibleUpdates &U = I->second;
1462 Info.LexicalDecls = 0;
1463 Info.NumLexicalDecls = 0;
1464 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1465 UI != UE; ++UI) {
1466 Info.NameLookupTableData = *UI;
1467 Infos.push_back(Info);
1468 }
1469 PendingVisibleUpdates.erase(I);
1470 }
Chris Lattner487412d2009-04-27 05:27:42 +00001471 }
1472 }
Sebastian Redlaba202b2010-08-24 22:50:19 +00001473
1474 // If this is a template, read additional specializations that may be in a
1475 // different part of the chain.
1476 if (isa<RedeclarableTemplateDecl>(D)) {
1477 AdditionalTemplateSpecializationsMap::iterator F =
1478 AdditionalTemplateSpecializationsPending.find(ID);
1479 if (F != AdditionalTemplateSpecializationsPending.end()) {
1480 for (AdditionalTemplateSpecializations::iterator I = F->second.begin(),
1481 E = F->second.end();
1482 I != E; ++I)
1483 GetDecl(*I);
1484 AdditionalTemplateSpecializationsPending.erase(F);
1485 }
1486 }
Chris Lattner487412d2009-04-27 05:27:42 +00001487 assert(Idx == Record.size());
1488
1489 // If we have deserialized a declaration that has a definition the
Argyrios Kyrtzidis903ccd62010-07-07 15:46:26 +00001490 // AST consumer might need to know about, queue it.
1491 // We don't pass it to the consumer immediately because we may be in recursive
1492 // loading, and some declarations may still be initializing.
1493 if (isConsumerInterestedIn(D))
1494 InterestingDecls.push_back(D);
Chris Lattner487412d2009-04-27 05:27:42 +00001495
1496 return D;
1497}