blob: cb6f29a0770224ff88b73ef4a8f4a20556dd21d2 [file] [log] [blame]
Sebastian Redl904c9c82010-08-18 23:57:11 +00001//===--- ASTReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
Chris Lattner698f9252009-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 Redlc43b54c2010-08-18 23:56:43 +000010// This file implements the ASTReader::ReadDeclRecord method, which is the
Chris Lattner698f9252009-04-27 05:27:42 +000011// entrypoint for loading a decl.
12//
13//===----------------------------------------------------------------------===//
14
Sebastian Redl6ab7cd82010-08-18 23:57:17 +000015#include "clang/Serialization/ASTReader.h"
Chris Lattner698f9252009-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 Lattner6ad9ac02010-05-07 21:43:38 +000020#include "clang/AST/DeclCXX.h"
21#include "clang/AST/DeclTemplate.h"
Chris Lattner698f9252009-04-27 05:27:42 +000022#include "clang/AST/Expr.h"
23using namespace clang;
Sebastian Redl8538e8d2010-08-18 23:57:32 +000024using namespace clang::serialization;
Chris Lattner698f9252009-04-27 05:27:42 +000025
26//===----------------------------------------------------------------------===//
27// Declaration deserialization
28//===----------------------------------------------------------------------===//
29
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +000030namespace clang {
Sebastian Redld527cc02010-08-18 23:56:48 +000031 class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> {
Sebastian Redlc43b54c2010-08-18 23:56:43 +000032 ASTReader &Reader;
Sebastian Redl577d4792010-07-22 22:43:28 +000033 llvm::BitstreamCursor &Cursor;
Sebastian Redl8538e8d2010-08-18 23:57:32 +000034 const DeclID ThisDeclID;
Sebastian Redlc43b54c2010-08-18 23:56:43 +000035 const ASTReader::RecordData &Record;
Chris Lattner698f9252009-04-27 05:27:42 +000036 unsigned &Idx;
Sebastian Redl8538e8d2010-08-18 23:57:32 +000037 TypeID TypeIDForTypeDecl;
Chris Lattner698f9252009-04-27 05:27:42 +000038
Sebastian Redl577d4792010-07-22 22:43:28 +000039 uint64_t GetCurrentCursorOffset();
40
Chris Lattner698f9252009-04-27 05:27:42 +000041 public:
Sebastian Redld527cc02010-08-18 23:56:48 +000042 ASTDeclReader(ASTReader &Reader, llvm::BitstreamCursor &Cursor,
Sebastian Redl8538e8d2010-08-18 23:57:32 +000043 DeclID thisDeclID, const ASTReader::RecordData &Record,
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +000044 unsigned &Idx)
45 : Reader(Reader), Cursor(Cursor), ThisDeclID(thisDeclID), Record(Record),
Douglas Gregordeacbdc2010-08-11 12:19:30 +000046 Idx(Idx), TypeIDForTypeDecl(0) { }
Chris Lattner698f9252009-04-27 05:27:42 +000047
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +000048 void Visit(Decl *D);
49
Chris Lattner698f9252009-04-27 05:27:42 +000050 void VisitDecl(Decl *D);
51 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
52 void VisitNamedDecl(NamedDecl *ND);
Douglas Gregor0cef4832010-02-21 18:22:14 +000053 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000054 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
55 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000056 void VisitTypeDecl(TypeDecl *TD);
57 void VisitTypedefDecl(TypedefDecl *TD);
Argyrios Kyrtzidis8f4eae92010-06-30 08:49:30 +000058 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000059 void VisitTagDecl(TagDecl *TD);
60 void VisitEnumDecl(EnumDecl *ED);
61 void VisitRecordDecl(RecordDecl *RD);
Chris Lattner6ad9ac02010-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 Lattner698f9252009-04-27 05:27:42 +000068 void VisitValueDecl(ValueDecl *VD);
69 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidis8f4eae92010-06-30 08:49:30 +000070 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +000071 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner698f9252009-04-27 05:27:42 +000072 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattner6ad9ac02010-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 Lattner698f9252009-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 Lattner6ad9ac02010-05-07 21:43:38 +000081 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
82 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne9eabeba2010-07-29 16:11:51 +000083 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000084 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +000085 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000086 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Argyrios Kyrtzidisb01a5522010-06-20 14:40:59 +000087 void VisitUsingDecl(UsingDecl *D);
88 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000089 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000090 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Abramo Bagnara6206d532010-06-05 05:09:32 +000091 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +000092 void VisitFriendDecl(FriendDecl *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000093 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
94 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner698f9252009-04-27 05:27:42 +000095 void VisitBlockDecl(BlockDecl *BD);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000096
Chris Lattner698f9252009-04-27 05:27:42 +000097 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +000098 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattner6ad9ac02010-05-07 21:43:38 +000099
Sean Hunt9a555912010-05-30 07:21:58 +0000100 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner698f9252009-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 Redld527cc02010-08-18 23:56:48 +0000119uint64_t ASTDeclReader::GetCurrentCursorOffset() {
Sebastian Redl577d4792010-07-22 22:43:28 +0000120 uint64_t Off = 0;
121 for (unsigned I = 0, N = Reader.Chain.size(); I != N; ++I) {
Sebastian Redlc43b54c2010-08-18 23:56:43 +0000122 ASTReader::PerFileData &F = *Reader.Chain[N - I - 1];
Sebastian Redl577d4792010-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 Redld527cc02010-08-18 23:56:48 +0000132void ASTDeclReader::Visit(Decl *D) {
133 DeclVisitor<ASTDeclReader, void>::Visit(D);
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000134
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000135 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
Douglas Gregordeacbdc2010-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 Kyrtzidis91468322010-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 Redl577d4792010-07-22 22:43:28 +0000141 FD->setLazyBody(GetCurrentCursorOffset());
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000142 }
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000143}
144
Sebastian Redld527cc02010-08-18 23:56:48 +0000145void ASTDeclReader::VisitDecl(Decl *D) {
Chris Lattner698f9252009-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++]);
Sean Huntcf807c42010-08-18 23:23:40 +0000151 if (Record[Idx++]) {
152 AttrVec Attrs;
153 Reader.ReadAttributes(Cursor, Attrs);
154 D->setAttrs(Attrs);
155 }
Chris Lattner698f9252009-04-27 05:27:42 +0000156 D->setImplicit(Record[Idx++]);
Douglas Gregore0762c92009-06-19 23:52:42 +0000157 D->setUsed(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000158 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor7d1d49d2009-10-16 20:01:17 +0000159 D->setPCHLevel(Record[Idx++] + 1);
Chris Lattner698f9252009-04-27 05:27:42 +0000160}
161
Sebastian Redld527cc02010-08-18 23:56:48 +0000162void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
Chris Lattner698f9252009-04-27 05:27:42 +0000163 VisitDecl(TU);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000164 TU->setAnonymousNamespace(
165 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000166}
167
Sebastian Redld527cc02010-08-18 23:56:48 +0000168void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) {
Chris Lattner698f9252009-04-27 05:27:42 +0000169 VisitDecl(ND);
Mike Stump1eb44332009-09-09 15:08:12 +0000170 ND->setDeclName(Reader.ReadDeclarationName(Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000171}
172
Sebastian Redld527cc02010-08-18 23:56:48 +0000173void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000174 VisitNamedDecl(TD);
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000175 // Delay type reading until after we have fully initialized the decl.
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000176 TypeIDForTypeDecl = Record[Idx++];
Chris Lattner698f9252009-04-27 05:27:42 +0000177}
178
Sebastian Redld527cc02010-08-18 23:56:48 +0000179void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Argyrios Kyrtzidisd8a0c6f2010-07-02 11:55:01 +0000180 VisitTypeDecl(TD);
Sebastian Redl577d4792010-07-22 22:43:28 +0000181 TD->setTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000182}
183
Sebastian Redld527cc02010-08-18 23:56:48 +0000184void ASTDeclReader::VisitTagDecl(TagDecl *TD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000185 VisitTypeDecl(TD);
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +0000186 TD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +0000187 VisitRedeclarable(TD);
Chris Lattner698f9252009-04-27 05:27:42 +0000188 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
189 TD->setDefinition(Record[Idx++]);
Douglas Gregorb37b6482010-02-12 17:40:34 +0000190 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidisad93a742009-07-14 03:18:02 +0000191 TD->setRBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Douglas Gregor741dd9a2009-07-21 14:46:17 +0000192 TD->setTagKeywordLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
John McCallb6217662010-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 Lattner698f9252009-04-27 05:27:42 +0000196}
197
Sebastian Redld527cc02010-08-18 23:56:48 +0000198void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
Chris Lattner698f9252009-04-27 05:27:42 +0000199 VisitTagDecl(ED);
200 ED->setIntegerType(Reader.GetType(Record[Idx++]));
John McCall842aef82009-12-09 09:09:27 +0000201 ED->setPromotionType(Reader.GetType(Record[Idx++]));
John McCall1b5a6182010-05-06 08:49:23 +0000202 ED->setNumPositiveBits(Record[Idx++]);
203 ED->setNumNegativeBits(Record[Idx++]);
Argyrios Kyrtzidis74228272010-07-06 15:36:48 +0000204 ED->setInstantiationOfMemberEnum(
205 cast_or_null<EnumDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000206}
207
Sebastian Redld527cc02010-08-18 23:56:48 +0000208void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000209 VisitTagDecl(RD);
210 RD->setHasFlexibleArrayMember(Record[Idx++]);
211 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian643b7df2009-07-08 16:37:44 +0000212 RD->setHasObjectMember(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000213}
214
Sebastian Redld527cc02010-08-18 23:56:48 +0000215void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000216 VisitNamedDecl(VD);
217 VD->setType(Reader.GetType(Record[Idx++]));
218}
219
Sebastian Redld527cc02010-08-18 23:56:48 +0000220void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000221 VisitValueDecl(ECD);
222 if (Record[Idx++])
Sebastian Redl577d4792010-07-22 22:43:28 +0000223 ECD->setInitExpr(Reader.ReadExpr(Cursor));
Chris Lattner698f9252009-04-27 05:27:42 +0000224 ECD->setInitVal(Reader.ReadAPSInt(Record, Idx));
225}
226
Sebastian Redld527cc02010-08-18 23:56:48 +0000227void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000228 VisitValueDecl(DD);
Sebastian Redl577d4792010-07-22 22:43:28 +0000229 TypeSourceInfo *TInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
John McCalla93c9342009-12-07 02:54:59 +0000230 if (TInfo)
231 DD->setTypeSourceInfo(TInfo);
John McCallb6217662010-03-15 10:12:16 +0000232 // FIXME: read optional qualifier and its range.
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000233}
234
Sebastian Redld527cc02010-08-18 23:56:48 +0000235void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000236 VisitDeclaratorDecl(FD);
Abramo Bagnara25777432010-08-11 22:01:17 +0000237 // FIXME: read DeclarationNameLoc.
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000238
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +0000239 FD->IdentifierNamespace = Record[Idx++];
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000240 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000241 default: assert(false && "Unhandled TemplatedKind!");
242 break;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000243 case FunctionDecl::TK_NonTemplate:
244 break;
245 case FunctionDecl::TK_FunctionTemplate:
246 FD->setDescribedFunctionTemplate(
247 cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++])));
248 break;
249 case FunctionDecl::TK_MemberSpecialization: {
250 FunctionDecl *InstFD = cast<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
251 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
252 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
253 FD->setInstantiationOfMemberFunction(InstFD, TSK);
254 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
255 break;
256 }
257 case FunctionDecl::TK_FunctionTemplateSpecialization: {
258 FunctionTemplateDecl *Template
259 = cast<FunctionTemplateDecl>(Reader.GetDecl(Record[Idx++]));
260 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
261
262 // Template arguments.
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000263 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl577d4792010-07-22 22:43:28 +0000264 Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000265
266 // Template args as written.
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000267 llvm::SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000268 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000269 if (Record[Idx++]) { // TemplateArgumentsAsWritten != 0
270 unsigned NumTemplateArgLocs = Record[Idx++];
271 TemplArgLocs.reserve(NumTemplateArgLocs);
272 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
Sebastian Redl577d4792010-07-22 22:43:28 +0000273 TemplArgLocs.push_back(
274 Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx));
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000275
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000276 LAngleLoc = Reader.ReadSourceLocation(Record, Idx);
277 RAngleLoc = Reader.ReadSourceLocation(Record, Idx);
278 }
Argyrios Kyrtzidis7b081c82010-07-05 10:37:55 +0000279
280 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000281
Argyrios Kyrtzidis2c853e42010-07-20 13:59:58 +0000282 if (FD->isCanonicalDecl()) // if canonical add to template's set.
283 FD->setFunctionTemplateSpecialization(Template, TemplArgs.size(),
284 TemplArgs.data(), TSK,
285 TemplArgLocs.size(),
286 TemplArgLocs.data(),
287 LAngleLoc, RAngleLoc, POI);
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000288 break;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000289 }
290 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
291 // Templates.
292 UnresolvedSet<8> TemplDecls;
293 unsigned NumTemplates = Record[Idx++];
294 while (NumTemplates--)
295 TemplDecls.addDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
296
297 // Templates args.
298 TemplateArgumentListInfo TemplArgs;
299 unsigned NumArgs = Record[Idx++];
300 while (NumArgs--)
Sebastian Redl577d4792010-07-22 22:43:28 +0000301 TemplArgs.addArgument(Reader.ReadTemplateArgumentLoc(Cursor,Record, Idx));
Argyrios Kyrtzidis7b081c82010-07-05 10:37:55 +0000302 TemplArgs.setLAngleLoc(Reader.ReadSourceLocation(Record, Idx));
303 TemplArgs.setRAngleLoc(Reader.ReadSourceLocation(Record, Idx));
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000304
305 FD->setDependentTemplateSpecialization(*Reader.getContext(),
306 TemplDecls, TemplArgs);
Argyrios Kyrtzidisdc767e32010-06-28 09:31:34 +0000307 break;
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +0000308 }
309 }
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000310
Sebastian Redld527cc02010-08-18 23:56:48 +0000311 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000312 // after everything else is read.
313
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +0000314 VisitRedeclarable(FD);
John McCalld931b082010-08-26 03:08:43 +0000315 FD->setStorageClass((StorageClass)Record[Idx++]);
316 FD->setStorageClassAsWritten((StorageClass)Record[Idx++]);
Argyrios Kyrtzidis5efb06f2010-07-02 11:55:40 +0000317 FD->setInlineSpecified(Record[Idx++]);
318 FD->setVirtualAsWritten(Record[Idx++]);
319 FD->setPure(Record[Idx++]);
320 FD->setHasInheritedPrototype(Record[Idx++]);
321 FD->setHasWrittenPrototype(Record[Idx++]);
322 FD->setDeleted(Record[Idx++]);
323 FD->setTrivial(Record[Idx++]);
324 FD->setCopyAssignment(Record[Idx++]);
325 FD->setHasImplicitReturnZero(Record[Idx++]);
326 FD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
327
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000328 // Read in the parameters.
Chris Lattner698f9252009-04-27 05:27:42 +0000329 unsigned NumParams = Record[Idx++];
330 llvm::SmallVector<ParmVarDecl *, 16> Params;
331 Params.reserve(NumParams);
332 for (unsigned I = 0; I != NumParams; ++I)
333 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor838db382010-02-11 01:19:42 +0000334 FD->setParams(Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000335}
336
Sebastian Redld527cc02010-08-18 23:56:48 +0000337void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000338 VisitNamedDecl(MD);
339 if (Record[Idx++]) {
340 // In practice, this won't be executed (since method definitions
341 // don't occur in header files).
Sebastian Redl577d4792010-07-22 22:43:28 +0000342 MD->setBody(Reader.ReadStmt(Cursor));
Chris Lattner698f9252009-04-27 05:27:42 +0000343 MD->setSelfDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
344 MD->setCmdDecl(cast<ImplicitParamDecl>(Reader.GetDecl(Record[Idx++])));
345 }
346 MD->setInstanceMethod(Record[Idx++]);
347 MD->setVariadic(Record[Idx++]);
348 MD->setSynthesized(Record[Idx++]);
Fariborz Jahanian3fe10412010-07-22 18:24:20 +0000349 MD->setDefined(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000350 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
351 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Fariborz Jahanian7732cc92010-04-08 21:29:11 +0000352 MD->setNumSelectorArgs(unsigned(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000353 MD->setResultType(Reader.GetType(Record[Idx++]));
Sebastian Redl577d4792010-07-22 22:43:28 +0000354 MD->setResultTypeSourceInfo(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000355 MD->setEndLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
356 unsigned NumParams = Record[Idx++];
357 llvm::SmallVector<ParmVarDecl *, 16> Params;
358 Params.reserve(NumParams);
359 for (unsigned I = 0; I != NumParams; ++I)
360 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanian4ecb25f2010-04-09 15:40:42 +0000361 MD->setMethodParams(*Reader.getContext(), Params.data(), NumParams,
362 NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000363}
364
Sebastian Redld527cc02010-08-18 23:56:48 +0000365void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000366 VisitNamedDecl(CD);
Ted Kremenek782f2f52010-01-07 01:20:12 +0000367 SourceLocation A = SourceLocation::getFromRawEncoding(Record[Idx++]);
368 SourceLocation B = SourceLocation::getFromRawEncoding(Record[Idx++]);
369 CD->setAtEndRange(SourceRange(A, B));
Chris Lattner698f9252009-04-27 05:27:42 +0000370}
371
Sebastian Redld527cc02010-08-18 23:56:48 +0000372void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Chris Lattner698f9252009-04-27 05:27:42 +0000373 VisitObjCContainerDecl(ID);
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000374 ID->setTypeForDecl(Reader.GetType(Record[Idx++]).getTypePtr());
Chris Lattner698f9252009-04-27 05:27:42 +0000375 ID->setSuperClass(cast_or_null<ObjCInterfaceDecl>
376 (Reader.GetDecl(Record[Idx++])));
Ted Kremenek53b94412010-09-01 01:21:15 +0000377
378 // Read the directly referenced protocols and their SourceLocations.
Chris Lattner698f9252009-04-27 05:27:42 +0000379 unsigned NumProtocols = Record[Idx++];
380 llvm::SmallVector<ObjCProtocolDecl *, 16> Protocols;
381 Protocols.reserve(NumProtocols);
382 for (unsigned I = 0; I != NumProtocols; ++I)
383 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000384 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
385 ProtoLocs.reserve(NumProtocols);
386 for (unsigned I = 0; I != NumProtocols; ++I)
387 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
388 ID->setProtocolList(Protocols.data(), NumProtocols, ProtoLocs.data(),
389 *Reader.getContext());
Ted Kremenek53b94412010-09-01 01:21:15 +0000390
391 // Read the transitive closure of protocols referenced by this class.
392 NumProtocols = Record[Idx++];
393 Protocols.clear();
394 Protocols.reserve(NumProtocols);
395 for (unsigned I = 0; I != NumProtocols; ++I)
396 Protocols.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
397 ID->AllReferencedProtocols.set(Protocols.data(), NumProtocols,
398 *Reader.getContext());
399
400 // Read the ivars.
Chris Lattner698f9252009-04-27 05:27:42 +0000401 unsigned NumIvars = Record[Idx++];
402 llvm::SmallVector<ObjCIvarDecl *, 16> IVars;
403 IVars.reserve(NumIvars);
404 for (unsigned I = 0; I != NumIvars; ++I)
405 IVars.push_back(cast<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000406 ID->setCategoryList(
407 cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +0000408 // We will rebuild this list lazily.
409 ID->setIvarList(0);
Douglas Gregordeacbdc2010-08-11 12:19:30 +0000410 ID->setForwardDecl(Record[Idx++]);
411 ID->setImplicitInterfaceDecl(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000412 ID->setClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
413 ID->setSuperClassLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Argyrios Kyrtzidisc999f1f2009-07-18 00:33:23 +0000414 ID->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000415}
416
Sebastian Redld527cc02010-08-18 23:56:48 +0000417void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000418 VisitFieldDecl(IVD);
419 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahanian2c18bb72010-08-20 21:21:08 +0000420 // This field will be built lazily.
421 IVD->setNextIvar(0);
Fariborz Jahanianac0021b2010-07-17 18:35:47 +0000422 bool synth = Record[Idx++];
423 IVD->setSynthesize(synth);
Chris Lattner698f9252009-04-27 05:27:42 +0000424}
425
Sebastian Redld527cc02010-08-18 23:56:48 +0000426void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000427 VisitObjCContainerDecl(PD);
428 PD->setForwardDecl(Record[Idx++]);
429 PD->setLocEnd(SourceLocation::getFromRawEncoding(Record[Idx++]));
430 unsigned NumProtoRefs = Record[Idx++];
431 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
432 ProtoRefs.reserve(NumProtoRefs);
433 for (unsigned I = 0; I != NumProtoRefs; ++I)
434 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000435 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
436 ProtoLocs.reserve(NumProtoRefs);
437 for (unsigned I = 0; I != NumProtoRefs; ++I)
438 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
439 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
440 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000441}
442
Sebastian Redld527cc02010-08-18 23:56:48 +0000443void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000444 VisitFieldDecl(FD);
445}
446
Sebastian Redld527cc02010-08-18 23:56:48 +0000447void ASTDeclReader::VisitObjCClassDecl(ObjCClassDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000448 VisitDecl(CD);
449 unsigned NumClassRefs = Record[Idx++];
450 llvm::SmallVector<ObjCInterfaceDecl *, 16> ClassRefs;
451 ClassRefs.reserve(NumClassRefs);
452 for (unsigned I = 0; I != NumClassRefs; ++I)
453 ClassRefs.push_back(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Ted Kremenek321c22f2009-11-18 00:28:11 +0000454 llvm::SmallVector<SourceLocation, 16> SLocs;
455 SLocs.reserve(NumClassRefs);
456 for (unsigned I = 0; I != NumClassRefs; ++I)
457 SLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
458 CD->setClassList(*Reader.getContext(), ClassRefs.data(), SLocs.data(),
459 NumClassRefs);
Chris Lattner698f9252009-04-27 05:27:42 +0000460}
461
Sebastian Redld527cc02010-08-18 23:56:48 +0000462void ASTDeclReader::VisitObjCForwardProtocolDecl(ObjCForwardProtocolDecl *FPD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000463 VisitDecl(FPD);
464 unsigned NumProtoRefs = Record[Idx++];
465 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
466 ProtoRefs.reserve(NumProtoRefs);
467 for (unsigned I = 0; I != NumProtoRefs; ++I)
468 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000469 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
470 ProtoLocs.reserve(NumProtoRefs);
471 for (unsigned I = 0; I != NumProtoRefs; ++I)
472 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
473 FPD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
474 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000475}
476
Sebastian Redld527cc02010-08-18 23:56:48 +0000477void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000478 VisitObjCContainerDecl(CD);
479 CD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
480 unsigned NumProtoRefs = Record[Idx++];
481 llvm::SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
482 ProtoRefs.reserve(NumProtoRefs);
483 for (unsigned I = 0; I != NumProtoRefs; ++I)
484 ProtoRefs.push_back(cast<ObjCProtocolDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor18df52b2010-01-16 15:02:53 +0000485 llvm::SmallVector<SourceLocation, 16> ProtoLocs;
486 ProtoLocs.reserve(NumProtoRefs);
487 for (unsigned I = 0; I != NumProtoRefs; ++I)
488 ProtoLocs.push_back(SourceLocation::getFromRawEncoding(Record[Idx++]));
489 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
490 *Reader.getContext());
Chris Lattner698f9252009-04-27 05:27:42 +0000491 CD->setNextClassCategory(cast_or_null<ObjCCategoryDecl>(Reader.GetDecl(Record[Idx++])));
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000492 CD->setHasSynthBitfield(Record[Idx++]);
Douglas Gregor3db211b2010-01-16 16:38:58 +0000493 CD->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
494 CD->setCategoryNameLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Chris Lattner698f9252009-04-27 05:27:42 +0000495}
496
Sebastian Redld527cc02010-08-18 23:56:48 +0000497void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000498 VisitNamedDecl(CAD);
499 CAD->setClassInterface(cast<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
500}
501
Sebastian Redld527cc02010-08-18 23:56:48 +0000502void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000503 VisitNamedDecl(D);
Fariborz Jahaniand0502402010-01-21 17:36:00 +0000504 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
Sebastian Redl577d4792010-07-22 22:43:28 +0000505 D->setType(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000506 // FIXME: stable encoding
507 D->setPropertyAttributes(
508 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian80aa1cd2010-06-22 23:20:40 +0000509 D->setPropertyAttributesAsWritten(
510 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000511 // FIXME: stable encoding
512 D->setPropertyImplementation(
513 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
514 D->setGetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
515 D->setSetterName(Reader.ReadDeclarationName(Record, Idx).getObjCSelector());
516 D->setGetterMethodDecl(
517 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
518 D->setSetterMethodDecl(
519 cast_or_null<ObjCMethodDecl>(Reader.GetDecl(Record[Idx++])));
520 D->setPropertyIvarDecl(
521 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
522}
523
Sebastian Redld527cc02010-08-18 23:56:48 +0000524void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidisaecae622009-07-27 19:04:32 +0000525 VisitObjCContainerDecl(D);
Chris Lattner698f9252009-04-27 05:27:42 +0000526 D->setClassInterface(
527 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner698f9252009-04-27 05:27:42 +0000528}
529
Sebastian Redld527cc02010-08-18 23:56:48 +0000530void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000531 VisitObjCImplDecl(D);
532 D->setIdentifier(Reader.GetIdentifierInfo(Record, Idx));
533}
534
Sebastian Redld527cc02010-08-18 23:56:48 +0000535void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000536 VisitObjCImplDecl(D);
537 D->setSuperClass(
538 cast_or_null<ObjCInterfaceDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis9d50c062010-08-09 10:54:20 +0000539 llvm::tie(D->IvarInitializers, D->NumIvarInitializers)
540 = Reader.ReadCXXBaseOrMemberInitializers(Cursor, Record, Idx);
Fariborz Jahanian000835d2010-08-23 18:51:39 +0000541 D->setHasSynthBitfield(Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000542}
543
544
Sebastian Redld527cc02010-08-18 23:56:48 +0000545void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +0000546 VisitDecl(D);
547 D->setAtLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
548 D->setPropertyDecl(
549 cast_or_null<ObjCPropertyDecl>(Reader.GetDecl(Record[Idx++])));
550 D->setPropertyIvarDecl(
551 cast_or_null<ObjCIvarDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidis2f922302010-08-09 10:54:37 +0000552 D->setGetterCXXConstructor(Reader.ReadExpr(Cursor));
553 D->setSetterCXXAssignment(Reader.ReadExpr(Cursor));
Chris Lattner698f9252009-04-27 05:27:42 +0000554}
555
Sebastian Redld527cc02010-08-18 23:56:48 +0000556void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000557 VisitDeclaratorDecl(FD);
Chris Lattner698f9252009-04-27 05:27:42 +0000558 FD->setMutable(Record[Idx++]);
559 if (Record[Idx++])
Sebastian Redl577d4792010-07-22 22:43:28 +0000560 FD->setBitWidth(Reader.ReadExpr(Cursor));
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000561 if (!FD->getDeclName()) {
562 FieldDecl *Tmpl = cast_or_null<FieldDecl>(Reader.GetDecl(Record[Idx++]));
563 if (Tmpl)
564 Reader.getContext()->setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
565 }
Chris Lattner698f9252009-04-27 05:27:42 +0000566}
567
Sebastian Redld527cc02010-08-18 23:56:48 +0000568void ASTDeclReader::VisitVarDecl(VarDecl *VD) {
Argyrios Kyrtzidisd4a7e542009-08-19 01:28:35 +0000569 VisitDeclaratorDecl(VD);
John McCalld931b082010-08-26 03:08:43 +0000570 VD->setStorageClass((StorageClass)Record[Idx++]);
571 VD->setStorageClassAsWritten((StorageClass)Record[Idx++]);
Chris Lattner698f9252009-04-27 05:27:42 +0000572 VD->setThreadSpecified(Record[Idx++]);
573 VD->setCXXDirectInitializer(Record[Idx++]);
Douglas Gregor324b54d2010-05-03 18:51:14 +0000574 VD->setExceptionVariable(Record[Idx++]);
Douglas Gregor5077c382010-05-15 06:01:05 +0000575 VD->setNRVOVariable(Record[Idx++]);
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +0000576 VisitRedeclarable(VD);
Chris Lattner698f9252009-04-27 05:27:42 +0000577 if (Record[Idx++])
Sebastian Redl577d4792010-07-22 22:43:28 +0000578 VD->setInit(Reader.ReadExpr(Cursor));
Argyrios Kyrtzidis9421adc2010-07-04 21:44:00 +0000579
580 if (Record[Idx++]) { // HasMemberSpecializationInfo.
581 VarDecl *Tmpl = cast<VarDecl>(Reader.GetDecl(Record[Idx++]));
582 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
583 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
584 Reader.getContext()->setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
585 }
Chris Lattner698f9252009-04-27 05:27:42 +0000586}
587
Sebastian Redld527cc02010-08-18 23:56:48 +0000588void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000589 VisitVarDecl(PD);
590}
591
Sebastian Redld527cc02010-08-18 23:56:48 +0000592void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000593 VisitVarDecl(PD);
594 PD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
John McCallbf73b352010-03-12 18:31:32 +0000595 PD->setHasInheritedDefaultArg(Record[Idx++]);
Argyrios Kyrtzidis691d77f2010-07-04 21:44:07 +0000596 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
Sebastian Redl577d4792010-07-22 22:43:28 +0000597 PD->setUninstantiatedDefaultArg(Reader.ReadExpr(Cursor));
Chris Lattner698f9252009-04-27 05:27:42 +0000598}
599
Sebastian Redld527cc02010-08-18 23:56:48 +0000600void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000601 VisitDecl(AD);
Sebastian Redl577d4792010-07-22 22:43:28 +0000602 AD->setAsmString(cast<StringLiteral>(Reader.ReadExpr(Cursor)));
Chris Lattner698f9252009-04-27 05:27:42 +0000603}
604
Sebastian Redld527cc02010-08-18 23:56:48 +0000605void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner698f9252009-04-27 05:27:42 +0000606 VisitDecl(BD);
Sebastian Redl577d4792010-07-22 22:43:28 +0000607 BD->setBody(cast_or_null<CompoundStmt>(Reader.ReadStmt(Cursor)));
608 BD->setSignatureAsWritten(Reader.GetTypeSourceInfo(Cursor, Record, Idx));
Chris Lattner698f9252009-04-27 05:27:42 +0000609 unsigned NumParams = Record[Idx++];
610 llvm::SmallVector<ParmVarDecl *, 16> Params;
611 Params.reserve(NumParams);
612 for (unsigned I = 0; I != NumParams; ++I)
613 Params.push_back(cast<ParmVarDecl>(Reader.GetDecl(Record[Idx++])));
Douglas Gregor838db382010-02-11 01:19:42 +0000614 BD->setParams(Params.data(), NumParams);
Chris Lattner698f9252009-04-27 05:27:42 +0000615}
616
Sebastian Redld527cc02010-08-18 23:56:48 +0000617void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000618 VisitDecl(D);
619 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
620 D->setHasBraces(Record[Idx++]);
621}
622
Sebastian Redld527cc02010-08-18 23:56:48 +0000623void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000624 VisitNamedDecl(D);
625 D->setLBracLoc(Reader.ReadSourceLocation(Record, Idx));
626 D->setRBracLoc(Reader.ReadSourceLocation(Record, Idx));
627 D->setNextNamespace(
628 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
629
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000630 bool IsOriginal = Record[Idx++];
Argyrios Kyrtzidisa038c1d2010-07-03 07:57:53 +0000631 D->OrigOrAnonNamespace.setInt(IsOriginal);
632 D->OrigOrAnonNamespace.setPointer(
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000633 cast_or_null<NamespaceDecl>(Reader.GetDecl(Record[Idx++])));
634}
635
Sebastian Redld527cc02010-08-18 23:56:48 +0000636void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000637 VisitNamedDecl(D);
Douglas Gregor8ea5b9d2010-09-01 00:08:19 +0000638 D->NamespaceLoc = Reader.ReadSourceLocation(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000639 D->setQualifierRange(Reader.ReadSourceRange(Record, Idx));
640 D->setQualifier(Reader.ReadNestedNameSpecifier(Record, Idx));
Douglas Gregor8ea5b9d2010-09-01 00:08:19 +0000641 D->IdentLoc = Reader.ReadSourceLocation(Record, Idx);
642 D->Namespace = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000643}
644
Sebastian Redld527cc02010-08-18 23:56:48 +0000645void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000646 VisitNamedDecl(D);
647 D->setUsingLocation(Reader.ReadSourceLocation(Record, Idx));
648 D->setNestedNameRange(Reader.ReadSourceRange(Record, Idx));
649 D->setTargetNestedNameDecl(Reader.ReadNestedNameSpecifier(Record, Idx));
Abramo Bagnaraef3dce82010-08-12 11:46:03 +0000650 // FIXME: read the DNLoc component.
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000651
652 // FIXME: It would probably be more efficient to read these into a vector
653 // and then re-cosntruct the shadow decl set over that vector since it
654 // would avoid existence checks.
655 unsigned NumShadows = Record[Idx++];
656 for(unsigned I = 0; I != NumShadows; ++I) {
Argyrios Kyrtzidis82f8e792010-07-08 13:09:41 +0000657 // Avoid invariant checking of UsingDecl::addShadowDecl, the decl may still
658 // be initializing.
659 D->Shadows.insert(cast<UsingShadowDecl>(Reader.GetDecl(Record[Idx++])));
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000660 }
661 D->setTypeName(Record[Idx++]);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000662 NamedDecl *Pattern = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
663 if (Pattern)
664 Reader.getContext()->setInstantiatedFromUsingDecl(D, Pattern);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000665}
666
Sebastian Redld527cc02010-08-18 23:56:48 +0000667void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000668 VisitNamedDecl(D);
669 D->setTargetDecl(cast<NamedDecl>(Reader.GetDecl(Record[Idx++])));
670 D->setUsingDecl(cast<UsingDecl>(Reader.GetDecl(Record[Idx++])));
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000671 UsingShadowDecl *Pattern
672 = cast_or_null<UsingShadowDecl>(Reader.GetDecl(Record[Idx++]));
673 if (Pattern)
674 Reader.getContext()->setInstantiatedFromUsingShadowDecl(D, Pattern);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000675}
676
Sebastian Redld527cc02010-08-18 23:56:48 +0000677void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000678 VisitNamedDecl(D);
Douglas Gregor0a35bce2010-09-01 03:07:18 +0000679 D->UsingLoc = Reader.ReadSourceLocation(Record, Idx);
680 D->NamespaceLoc = Reader.ReadSourceLocation(Record, Idx);
681 D->QualifierRange = Reader.ReadSourceRange(Record, Idx);
682 D->Qualifier = Reader.ReadNestedNameSpecifier(Record, Idx);
683 D->NominatedNamespace = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
684 D->CommonAncestor = cast_or_null<DeclContext>(Reader.GetDecl(Record[Idx++]));
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000685}
686
Sebastian Redld527cc02010-08-18 23:56:48 +0000687void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000688 VisitValueDecl(D);
689 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
690 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
691 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
Abramo Bagnaraef3dce82010-08-12 11:46:03 +0000692 // FIXME: read the DNLoc component.
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000693}
694
Sebastian Redld527cc02010-08-18 23:56:48 +0000695void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000696 UnresolvedUsingTypenameDecl *D) {
697 VisitTypeDecl(D);
698 D->setTargetNestedNameRange(Reader.ReadSourceRange(Record, Idx));
699 D->setUsingLoc(Reader.ReadSourceLocation(Record, Idx));
700 D->setTypenameLoc(Reader.ReadSourceLocation(Record, Idx));
701 D->setTargetNestedNameSpecifier(Reader.ReadNestedNameSpecifier(Record, Idx));
702}
703
Sebastian Redld527cc02010-08-18 23:56:48 +0000704void ASTDeclReader::VisitCXXRecordDecl(CXXRecordDecl *D) {
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000705 ASTContext &C = *Reader.getContext();
706
Argyrios Kyrtzidis0f47bb92010-07-06 15:36:58 +0000707 // We need to allocate the DefinitionData struct ahead of VisitRecordDecl
708 // so that the other CXXRecordDecls can get a pointer even when the owner
709 // is still initializing.
710 bool OwnsDefinitionData = false;
711 enum DataOwnership { Data_NoDefData, Data_Owner, Data_NotOwner };
712 switch ((DataOwnership)Record[Idx++]) {
713 default:
Sebastian Redld527cc02010-08-18 23:56:48 +0000714 assert(0 && "Out of sync with ASTDeclWriter or messed up reading");
Argyrios Kyrtzidis0f47bb92010-07-06 15:36:58 +0000715 case Data_NoDefData:
716 break;
717 case Data_Owner:
718 OwnsDefinitionData = true;
719 D->DefinitionData = new (C) struct CXXRecordDecl::DefinitionData(D);
720 break;
721 case Data_NotOwner:
722 D->DefinitionData
723 = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]))->DefinitionData;
724 break;
725 }
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000726
Argyrios Kyrtzidis0f47bb92010-07-06 15:36:58 +0000727 VisitRecordDecl(D);
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000728
Argyrios Kyrtzidis0f47bb92010-07-06 15:36:58 +0000729 if (OwnsDefinitionData) {
730 assert(D->DefinitionData);
731 struct CXXRecordDecl::DefinitionData &Data = *D->DefinitionData;
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000732
Argyrios Kyrtzidis0f47bb92010-07-06 15:36:58 +0000733 Data.UserDeclaredConstructor = Record[Idx++];
734 Data.UserDeclaredCopyConstructor = Record[Idx++];
735 Data.UserDeclaredCopyAssignment = Record[Idx++];
736 Data.UserDeclaredDestructor = Record[Idx++];
737 Data.Aggregate = Record[Idx++];
738 Data.PlainOldData = Record[Idx++];
739 Data.Empty = Record[Idx++];
740 Data.Polymorphic = Record[Idx++];
741 Data.Abstract = Record[Idx++];
742 Data.HasTrivialConstructor = Record[Idx++];
743 Data.HasTrivialCopyConstructor = Record[Idx++];
744 Data.HasTrivialCopyAssignment = Record[Idx++];
745 Data.HasTrivialDestructor = Record[Idx++];
746 Data.ComputedVisibleConversions = Record[Idx++];
747 Data.DeclaredDefaultConstructor = Record[Idx++];
748 Data.DeclaredCopyConstructor = Record[Idx++];
749 Data.DeclaredCopyAssignment = Record[Idx++];
750 Data.DeclaredDestructor = Record[Idx++];
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000751
Argyrios Kyrtzidis0f47bb92010-07-06 15:36:58 +0000752 // setBases() is unsuitable since it may try to iterate the bases of an
Nick Lewycky56062202010-07-26 16:56:01 +0000753 // uninitialized base.
Argyrios Kyrtzidis0f47bb92010-07-06 15:36:58 +0000754 Data.NumBases = Record[Idx++];
755 Data.Bases = new(C) CXXBaseSpecifier [Data.NumBases];
756 for (unsigned i = 0; i != Data.NumBases; ++i)
Nick Lewycky56062202010-07-26 16:56:01 +0000757 Data.Bases[i] = Reader.ReadCXXBaseSpecifier(Cursor, Record, Idx);
Argyrios Kyrtzidis0f47bb92010-07-06 15:36:58 +0000758
759 // FIXME: Make VBases lazily computed when needed to avoid storing them.
760 Data.NumVBases = Record[Idx++];
761 Data.VBases = new(C) CXXBaseSpecifier [Data.NumVBases];
762 for (unsigned i = 0; i != Data.NumVBases; ++i)
Nick Lewycky56062202010-07-26 16:56:01 +0000763 Data.VBases[i] = Reader.ReadCXXBaseSpecifier(Cursor, Record, Idx);
Argyrios Kyrtzidis0f47bb92010-07-06 15:36:58 +0000764
765 Reader.ReadUnresolvedSet(Data.Conversions, Record, Idx);
766 Reader.ReadUnresolvedSet(Data.VisibleConversions, Record, Idx);
767 assert(Data.Definition && "Data.Definition should be already set!");
768 Data.FirstFriend
769 = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis37ffed32010-07-02 11:55:32 +0000770 }
771
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000772 enum CXXRecKind {
773 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
774 };
775 switch ((CXXRecKind)Record[Idx++]) {
776 default:
Sebastian Redld527cc02010-08-18 23:56:48 +0000777 assert(false && "Out of sync with ASTDeclWriter::VisitCXXRecordDecl?");
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000778 case CXXRecNotTemplate:
779 break;
780 case CXXRecTemplate:
781 D->setDescribedClassTemplate(
782 cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++])));
783 break;
784 case CXXRecMemberSpecialization: {
785 CXXRecordDecl *RD = cast<CXXRecordDecl>(Reader.GetDecl(Record[Idx++]));
786 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
787 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
788 D->setInstantiationOfMemberClass(RD, TSK);
789 D->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
790 break;
791 }
792 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000793}
794
Sebastian Redld527cc02010-08-18 23:56:48 +0000795void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000796 VisitFunctionDecl(D);
Argyrios Kyrtzidisc91e9f42010-07-04 21:44:35 +0000797 unsigned NumOverridenMethods = Record[Idx++];
798 while (NumOverridenMethods--) {
799 CXXMethodDecl *MD = cast<CXXMethodDecl>(Reader.GetDecl(Record[Idx++]));
800 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
801 // MD may be initializing.
802 Reader.getContext()->addOverriddenMethod(D, MD);
803 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000804}
805
Sebastian Redld527cc02010-08-18 23:56:48 +0000806void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000807 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000808
809 D->IsExplicitSpecified = Record[Idx++];
810 D->ImplicitlyDefined = Record[Idx++];
Argyrios Kyrtzidis8e706f42010-08-09 10:54:12 +0000811 llvm::tie(D->BaseOrMemberInitializers, D->NumBaseOrMemberInitializers)
812 = Reader.ReadCXXBaseOrMemberInitializers(Cursor, Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000813}
814
Sebastian Redld527cc02010-08-18 23:56:48 +0000815void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000816 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000817
818 D->ImplicitlyDefined = Record[Idx++];
819 D->OperatorDelete = cast_or_null<FunctionDecl>(Reader.GetDecl(Record[Idx++]));
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000820}
821
Sebastian Redld527cc02010-08-18 23:56:48 +0000822void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000823 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis91468322010-07-02 15:58:43 +0000824 D->IsExplicitSpecified = Record[Idx++];
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000825}
826
Sebastian Redld527cc02010-08-18 23:56:48 +0000827void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnara6206d532010-06-05 05:09:32 +0000828 VisitDecl(D);
829 D->setColonLoc(Reader.ReadSourceLocation(Record, Idx));
830}
831
Sebastian Redld527cc02010-08-18 23:56:48 +0000832void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +0000833 VisitDecl(D);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +0000834 if (Record[Idx++])
Sebastian Redl577d4792010-07-22 22:43:28 +0000835 D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +0000836 else
837 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
838 D->NextFriend = cast_or_null<FriendDecl>(Reader.GetDecl(Record[Idx++]));
839 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
840}
841
Sebastian Redld527cc02010-08-18 23:56:48 +0000842void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +0000843 VisitDecl(D);
844 unsigned NumParams = Record[Idx++];
845 D->NumParams = NumParams;
846 D->Params = new TemplateParameterList*[NumParams];
847 for (unsigned i = 0; i != NumParams; ++i)
848 D->Params[i] = Reader.ReadTemplateParameterList(Record, Idx);
849 if (Record[Idx++]) // HasFriendDecl
850 D->Friend = cast<NamedDecl>(Reader.GetDecl(Record[Idx++]));
851 else
Sebastian Redl577d4792010-07-22 22:43:28 +0000852 D->Friend = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +0000853 D->FriendLoc = Reader.ReadSourceLocation(Record, Idx);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000854}
855
Sebastian Redld527cc02010-08-18 23:56:48 +0000856void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000857 VisitNamedDecl(D);
858
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +0000859 NamedDecl *TemplatedDecl
860 = cast_or_null<NamedDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000861 TemplateParameterList* TemplateParams
862 = Reader.ReadTemplateParameterList(Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000863 D->init(TemplatedDecl, TemplateParams);
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000864}
865
Sebastian Redld527cc02010-08-18 23:56:48 +0000866void ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000867 VisitTemplateDecl(D);
868
Argyrios Kyrtzidisc8f9af22010-07-05 10:38:01 +0000869 D->IdentifierNamespace = Record[Idx++];
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000870 RedeclarableTemplateDecl *PrevDecl =
871 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]));
872 assert((PrevDecl == 0 || PrevDecl->getKind() == D->getKind()) &&
873 "PrevDecl kind mismatch");
874 if (PrevDecl)
875 D->CommonOrPrev = PrevDecl;
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000876 if (PrevDecl == 0) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000877 if (RedeclarableTemplateDecl *RTD
878 = cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]))) {
879 assert(RTD->getKind() == D->getKind() &&
880 "InstantiatedFromMemberTemplate kind mismatch");
881 D->setInstantiatedFromMemberTemplateImpl(RTD);
882 if (Record[Idx++])
883 D->setMemberSpecialization();
884 }
Peter Collingbourne8a798a72010-07-29 16:12:01 +0000885
886 RedeclarableTemplateDecl *LatestDecl =
887 cast_or_null<RedeclarableTemplateDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +0000888
889 // This decl is a first one and the latest declaration that it points to is
Sebastian Redl3c7f4132010-08-18 23:57:06 +0000890 // in the same AST file. However, if this actually needs to point to a
891 // redeclaration in another AST file, we need to update it by checking
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +0000892 // the FirstLatestDeclIDs map which tracks this kind of decls.
893 assert(Reader.GetDecl(ThisDeclID) == D && "Invalid ThisDeclID ?");
Sebastian Redlc43b54c2010-08-18 23:56:43 +0000894 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +0000895 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
896 if (I != Reader.FirstLatestDeclIDs.end()) {
897 Decl *NewLatest = Reader.GetDecl(I->second);
898 assert((LatestDecl->getLocation().isInvalid() ||
899 NewLatest->getLocation().isInvalid() ||
900 Reader.SourceMgr.isBeforeInTranslationUnit(
901 LatestDecl->getLocation(),
902 NewLatest->getLocation())) &&
903 "The new latest is supposed to come after the previous latest");
904 LatestDecl = cast<RedeclarableTemplateDecl>(NewLatest);
905 }
906
Peter Collingbourne8a798a72010-07-29 16:12:01 +0000907 assert(LatestDecl->getKind() == D->getKind() && "Latest kind mismatch");
908 D->getCommonPtr()->Latest = LatestDecl;
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000909 }
910}
911
Sebastian Redld527cc02010-08-18 23:56:48 +0000912void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000913 VisitRedeclarableTemplateDecl(D);
914
915 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000916 // This ClassTemplateDecl owns a CommonPtr; read it.
917
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +0000918 // FoldingSets are filled in VisitClassTemplateSpecializationDecl.
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000919 unsigned size = Record[Idx++];
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +0000920 while (size--)
921 cast<ClassTemplateSpecializationDecl>(Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000922
923 size = Record[Idx++];
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +0000924 while (size--)
925 cast<ClassTemplatePartialSpecializationDecl>(
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000926 Reader.GetDecl(Record[Idx++]));
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000927
928 // InjectedClassNameType is computed.
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +0000929 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000930}
931
Sebastian Redld527cc02010-08-18 23:56:48 +0000932void ASTDeclReader::VisitClassTemplateSpecializationDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000933 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000934 VisitCXXRecordDecl(D);
935
936 if (Decl *InstD = Reader.GetDecl(Record[Idx++])) {
937 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
938 D->setInstantiationOf(CTD);
939 } else {
940 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl577d4792010-07-22 22:43:28 +0000941 Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000942 D->setInstantiationOf(cast<ClassTemplatePartialSpecializationDecl>(InstD),
943 TemplArgs.data(), TemplArgs.size());
944 }
945 }
946
947 // Explicit info.
Sebastian Redl577d4792010-07-22 22:43:28 +0000948 if (TypeSourceInfo *TyInfo = Reader.GetTypeSourceInfo(Cursor, Record, Idx)) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000949 D->setTypeAsWritten(TyInfo);
950 D->setExternLoc(Reader.ReadSourceLocation(Record, Idx));
951 D->setTemplateKeywordLoc(Reader.ReadSourceLocation(Record, Idx));
952 }
953
954 llvm::SmallVector<TemplateArgument, 8> TemplArgs;
Sebastian Redl577d4792010-07-22 22:43:28 +0000955 Reader.ReadTemplateArgumentList(TemplArgs, Cursor, Record, Idx);
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000956 D->initTemplateArgs(TemplArgs.data(), TemplArgs.size());
957 SourceLocation POI = Reader.ReadSourceLocation(Record, Idx);
958 if (POI.isValid())
959 D->setPointOfInstantiation(POI);
960 D->setSpecializationKind((TemplateSpecializationKind)Record[Idx++]);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +0000961
Argyrios Kyrtzidisbc5ab7c2010-07-20 13:59:40 +0000962 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +0000963 ClassTemplateDecl *CanonPattern
964 = cast<ClassTemplateDecl>(Reader.GetDecl(Record[Idx++]));
965 if (ClassTemplatePartialSpecializationDecl *Partial
966 = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
Argyrios Kyrtzidis0a67edd2010-07-12 21:41:31 +0000967 CanonPattern->getPartialSpecializations().InsertNode(Partial);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +0000968 } else {
Argyrios Kyrtzidis0a67edd2010-07-12 21:41:31 +0000969 CanonPattern->getSpecializations().InsertNode(D);
Argyrios Kyrtzidisecf966e2010-07-09 21:11:43 +0000970 }
971 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000972}
973
Sebastian Redld527cc02010-08-18 23:56:48 +0000974void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000975 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000976 VisitClassTemplateSpecializationDecl(D);
977
978 D->initTemplateParameters(Reader.ReadTemplateParameterList(Record, Idx));
979
980 TemplateArgumentListInfo ArgInfos;
981 unsigned NumArgs = Record[Idx++];
982 while (NumArgs--)
Sebastian Redl577d4792010-07-22 22:43:28 +0000983 ArgInfos.addArgument(Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx));
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000984 D->initTemplateArgsAsWritten(ArgInfos);
985
986 D->setSequenceNumber(Record[Idx++]);
987
988 // These are read/set from/to the first declaration.
989 if (D->getPreviousDeclaration() == 0) {
990 D->setInstantiatedFromMember(
991 cast_or_null<ClassTemplatePartialSpecializationDecl>(
992 Reader.GetDecl(Record[Idx++])));
993 if (Record[Idx++])
Argyrios Kyrtzidis64a5e2c2010-07-09 21:11:35 +0000994 D->setMemberSpecialization();
Argyrios Kyrtzidisdd41c142010-06-23 13:48:30 +0000995 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +0000996}
997
Sebastian Redld527cc02010-08-18 23:56:48 +0000998void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne9eabeba2010-07-29 16:11:51 +0000999 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001000
Peter Collingbourne9eabeba2010-07-29 16:11:51 +00001001 if (D->getPreviousDeclaration() == 0) {
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001002 // This FunctionTemplateDecl owns a CommonPtr; read it.
1003
Argyrios Kyrtzidis057d9af2010-07-06 15:37:09 +00001004 // Read the function specialization declarations.
1005 // FunctionTemplateDecl's FunctionTemplateSpecializationInfos are filled
1006 // through the specialized FunctionDecl's setFunctionTemplateSpecialization.
1007 unsigned NumSpecs = Record[Idx++];
1008 while (NumSpecs--)
1009 Reader.GetDecl(Record[Idx++]);
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001010 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001011}
1012
Sebastian Redld527cc02010-08-18 23:56:48 +00001013void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001014 VisitTypeDecl(D);
1015
1016 D->setDeclaredWithTypename(Record[Idx++]);
1017 D->setParameterPack(Record[Idx++]);
1018
1019 bool Inherited = Record[Idx++];
Sebastian Redl577d4792010-07-22 22:43:28 +00001020 TypeSourceInfo *DefArg = Reader.GetTypeSourceInfo(Cursor, Record, Idx);
Argyrios Kyrtzidis8731ca72010-06-19 19:29:09 +00001021 D->setDefaultArgument(DefArg, Inherited);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001022}
1023
Sebastian Redld527cc02010-08-18 23:56:48 +00001024void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Argyrios Kyrtzidisb24e1992010-06-25 16:25:09 +00001025 VisitVarDecl(D);
1026 // TemplateParmPosition.
1027 D->setDepth(Record[Idx++]);
1028 D->setPosition(Record[Idx++]);
1029 // Rest of NonTypeTemplateParmDecl.
1030 if (Record[Idx++]) {
Sebastian Redl577d4792010-07-22 22:43:28 +00001031 Expr *DefArg = Reader.ReadExpr(Cursor);
Argyrios Kyrtzidisb24e1992010-06-25 16:25:09 +00001032 bool Inherited = Record[Idx++];
1033 D->setDefaultArgument(DefArg, Inherited);
1034 }
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001035}
1036
Sebastian Redld527cc02010-08-18 23:56:48 +00001037void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001038 VisitTemplateDecl(D);
1039 // TemplateParmPosition.
1040 D->setDepth(Record[Idx++]);
1041 D->setPosition(Record[Idx++]);
1042 // Rest of TemplateTemplateParmDecl.
Sebastian Redl577d4792010-07-22 22:43:28 +00001043 TemplateArgumentLoc Arg = Reader.ReadTemplateArgumentLoc(Cursor, Record, Idx);
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001044 bool IsInherited = Record[Idx++];
1045 D->setDefaultArgument(Arg, IsInherited);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001046}
1047
Sebastian Redld527cc02010-08-18 23:56:48 +00001048void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis0d396892010-07-22 17:28:12 +00001049 VisitDecl(D);
Sebastian Redl577d4792010-07-22 22:43:28 +00001050 D->AssertExpr = Reader.ReadExpr(Cursor);
1051 D->Message = cast<StringLiteral>(Reader.ReadExpr(Cursor));
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001052}
1053
Mike Stump1eb44332009-09-09 15:08:12 +00001054std::pair<uint64_t, uint64_t>
Sebastian Redld527cc02010-08-18 23:56:48 +00001055ASTDeclReader::VisitDeclContext(DeclContext *DC) {
Chris Lattner698f9252009-04-27 05:27:42 +00001056 uint64_t LexicalOffset = Record[Idx++];
1057 uint64_t VisibleOffset = Record[Idx++];
1058 return std::make_pair(LexicalOffset, VisibleOffset);
1059}
1060
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001061template <typename T>
Sebastian Redld527cc02010-08-18 23:56:48 +00001062void ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001063 enum RedeclKind { NoRedeclaration = 0, PointsToPrevious, PointsToLatest };
1064 RedeclKind Kind = (RedeclKind)Record[Idx++];
1065 switch (Kind) {
1066 default:
Sebastian Redld527cc02010-08-18 23:56:48 +00001067 assert(0 && "Out of sync with ASTDeclWriter::VisitRedeclarable or messed up"
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001068 " reading");
1069 case NoRedeclaration:
1070 break;
1071 case PointsToPrevious:
1072 D->RedeclLink = typename Redeclarable<T>::PreviousDeclLink(
1073 cast_or_null<T>(Reader.GetDecl(Record[Idx++])));
1074 break;
1075 case PointsToLatest:
1076 D->RedeclLink = typename Redeclarable<T>::LatestDeclLink(
1077 cast_or_null<T>(Reader.GetDecl(Record[Idx++])));
1078 break;
1079 }
1080
1081 assert(!(Kind == PointsToPrevious &&
1082 Reader.FirstLatestDeclIDs.find(ThisDeclID) !=
1083 Reader.FirstLatestDeclIDs.end()) &&
1084 "This decl is not first, it should not be in the map");
1085 if (Kind == PointsToPrevious)
1086 return;
1087
1088 // This decl is a first one and the latest declaration that it points to is in
Sebastian Redl3c7f4132010-08-18 23:57:06 +00001089 // the same AST file. However, if this actually needs to point to a
1090 // redeclaration in another AST file, we need to update it by checking the
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001091 // FirstLatestDeclIDs map which tracks this kind of decls.
1092 assert(Reader.GetDecl(ThisDeclID) == static_cast<T*>(D) &&
1093 "Invalid ThisDeclID ?");
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001094 ASTReader::FirstLatestDeclIDMap::iterator I
Argyrios Kyrtzidisa8650052010-08-03 17:30:10 +00001095 = Reader.FirstLatestDeclIDs.find(ThisDeclID);
1096 if (I != Reader.FirstLatestDeclIDs.end()) {
1097 Decl *NewLatest = Reader.GetDecl(I->second);
1098 assert((D->getMostRecentDeclaration()->getLocation().isInvalid() ||
1099 NewLatest->getLocation().isInvalid() ||
1100 Reader.SourceMgr.isBeforeInTranslationUnit(
1101 D->getMostRecentDeclaration()->getLocation(),
1102 NewLatest->getLocation())) &&
1103 "The new latest is supposed to come after the previous latest");
1104 D->RedeclLink
1105 = typename Redeclarable<T>::LatestDeclLink(cast_or_null<T>(NewLatest));
1106 }
1107}
1108
Chris Lattner698f9252009-04-27 05:27:42 +00001109//===----------------------------------------------------------------------===//
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001110// Attribute Reading
Chris Lattner698f9252009-04-27 05:27:42 +00001111//===----------------------------------------------------------------------===//
1112
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001113/// \brief Reads attributes from the current stream position.
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001114void ASTReader::ReadAttributes(llvm::BitstreamCursor &DeclsCursor,
Sean Huntcf807c42010-08-18 23:23:40 +00001115 AttrVec &Attrs) {
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001116 unsigned Code = DeclsCursor.ReadCode();
Mike Stump1eb44332009-09-09 15:08:12 +00001117 assert(Code == llvm::bitc::UNABBREV_RECORD &&
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001118 "Expected unabbreviated record"); (void)Code;
Mike Stump1eb44332009-09-09 15:08:12 +00001119
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001120 RecordData Record;
1121 unsigned Idx = 0;
1122 unsigned RecCode = DeclsCursor.ReadRecord(Code, Record);
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001123 assert(RecCode == DECL_ATTR && "Expected attribute record");
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001124 (void)RecCode;
1125
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001126 while (Idx < Record.size()) {
1127 Attr *New = 0;
Sean Hunt387475d2010-06-16 23:43:53 +00001128 attr::Kind Kind = (attr::Kind)Record[Idx++];
Sean Huntcf807c42010-08-18 23:23:40 +00001129 SourceLocation Loc = SourceLocation::getFromRawEncoding(Record[Idx++]);
1130 bool isInherited = Record[Idx++];
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001131
Sean Huntcf807c42010-08-18 23:23:40 +00001132#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001133
1134 assert(New && "Unable to decode attribute?");
Sean Huntcf807c42010-08-18 23:23:40 +00001135 New->setInherited(isInherited);
1136 Attrs.push_back(New);
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001137 }
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001138}
1139
1140//===----------------------------------------------------------------------===//
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001141// ASTReader Implementation
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001142//===----------------------------------------------------------------------===//
Chris Lattner698f9252009-04-27 05:27:42 +00001143
1144/// \brief Note that we have loaded the declaration with the given
1145/// Index.
Mike Stump1eb44332009-09-09 15:08:12 +00001146///
Chris Lattner698f9252009-04-27 05:27:42 +00001147/// This routine notes that this declaration has already been loaded,
1148/// so that future GetDecl calls will return this declaration rather
1149/// than trying to load a new declaration.
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001150inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner698f9252009-04-27 05:27:42 +00001151 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
1152 DeclsLoaded[Index] = D;
1153}
1154
1155
1156/// \brief Determine whether the consumer will be interested in seeing
1157/// this declaration (via HandleTopLevelDecl).
1158///
1159/// This routine should return true for anything that might affect
1160/// code generation, e.g., inline function definitions, Objective-C
1161/// declarations with metadata, etc.
1162static bool isConsumerInterestedIn(Decl *D) {
Daniel Dunbar04a0b502009-09-17 03:06:44 +00001163 if (isa<FileScopeAsmDecl>(D))
1164 return true;
Chris Lattner698f9252009-04-27 05:27:42 +00001165 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis3f954772010-08-05 09:47:59 +00001166 return Var->isFileVarDecl() &&
1167 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner698f9252009-04-27 05:27:42 +00001168 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
1169 return Func->isThisDeclarationADefinition();
Argyrios Kyrtzidis9d50c062010-08-09 10:54:20 +00001170 return isa<ObjCProtocolDecl>(D) || isa<ObjCImplementationDecl>(D);
Chris Lattner698f9252009-04-27 05:27:42 +00001171}
1172
Sebastian Redlcb526aa2010-07-20 22:46:15 +00001173/// \brief Get the correct cursor and offset for loading a type.
Sebastian Redlc43b54c2010-08-18 23:56:43 +00001174ASTReader::RecordLocation
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001175ASTReader::DeclCursorForIndex(unsigned Index, DeclID ID) {
Sebastian Redl0b17c612010-08-13 00:28:03 +00001176 // See if there's an override.
1177 DeclReplacementMap::iterator It = ReplacedDecls.find(ID);
1178 if (It != ReplacedDecls.end())
1179 return RecordLocation(&It->second.first->DeclsCursor, It->second.second);
1180
Sebastian Redlcb526aa2010-07-20 22:46:15 +00001181 PerFileData *F = 0;
1182 for (unsigned I = 0, N = Chain.size(); I != N; ++I) {
1183 F = Chain[N - I - 1];
1184 if (Index < F->LocalNumDecls)
1185 break;
1186 Index -= F->LocalNumDecls;
1187 }
1188 assert(F && F->LocalNumDecls > Index && "Broken chain");
Sebastian Redl971dd442010-07-20 22:55:31 +00001189 return RecordLocation(&F->DeclsCursor, F->DeclOffsets[Index]);
Sebastian Redlcb526aa2010-07-20 22:46:15 +00001190}
1191
Sebastian Redld527cc02010-08-18 23:56:48 +00001192/// \brief Read the declaration at the given offset from the AST file.
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001193Decl *ASTReader::ReadDeclRecord(unsigned Index, DeclID ID) {
Sebastian Redl0b17c612010-08-13 00:28:03 +00001194 RecordLocation Loc = DeclCursorForIndex(Index, ID);
Sebastian Redl971dd442010-07-20 22:55:31 +00001195 llvm::BitstreamCursor &DeclsCursor = *Loc.first;
Chris Lattner698f9252009-04-27 05:27:42 +00001196 // Keep track of where we are in the stream, then jump back there
1197 // after reading this declaration.
Chris Lattnerda930612009-04-27 05:58:23 +00001198 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner698f9252009-04-27 05:27:42 +00001199
Argyrios Kyrtzidis919e6932010-06-28 22:28:35 +00001200 ReadingKindTracker ReadingKind(Read_Decl, *this);
1201
Douglas Gregord89275b2009-07-06 18:54:52 +00001202 // Note that we are loading a declaration record.
Argyrios Kyrtzidis29ee3a22010-07-30 10:03:16 +00001203 Deserializing ADecl(this);
Mike Stump1eb44332009-09-09 15:08:12 +00001204
Sebastian Redlcb526aa2010-07-20 22:46:15 +00001205 DeclsCursor.JumpToBit(Loc.second);
Chris Lattner698f9252009-04-27 05:27:42 +00001206 RecordData Record;
Chris Lattnerda930612009-04-27 05:58:23 +00001207 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner698f9252009-04-27 05:27:42 +00001208 unsigned Idx = 0;
Sebastian Redld527cc02010-08-18 23:56:48 +00001209 ASTDeclReader Reader(*this, DeclsCursor, ID, Record, Idx);
Chris Lattner698f9252009-04-27 05:27:42 +00001210
Chris Lattnerda930612009-04-27 05:58:23 +00001211 Decl *D = 0;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001212 switch ((DeclCode)DeclsCursor.ReadRecord(Code, Record)) {
1213 case DECL_ATTR:
1214 case DECL_CONTEXT_LEXICAL:
1215 case DECL_CONTEXT_VISIBLE:
Chris Lattner698f9252009-04-27 05:27:42 +00001216 assert(false && "Record cannot be de-serialized with ReadDeclRecord");
1217 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001218 case DECL_TRANSLATION_UNIT:
Chris Lattner698f9252009-04-27 05:27:42 +00001219 assert(Index == 0 && "Translation unit must be at index 0");
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001220 D = Context->getTranslationUnitDecl();
Chris Lattner698f9252009-04-27 05:27:42 +00001221 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001222 case DECL_TYPEDEF:
John McCallba6a9bd2009-10-24 08:00:42 +00001223 D = TypedefDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001224 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001225 case DECL_ENUM:
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +00001226 D = EnumDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001227 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001228 case DECL_RECORD:
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +00001229 D = RecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner698f9252009-04-27 05:27:42 +00001230 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001231 case DECL_ENUM_CONSTANT:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001232 D = EnumConstantDecl::Create(*Context, 0, SourceLocation(), 0, QualType(),
Chris Lattner698f9252009-04-27 05:27:42 +00001233 0, llvm::APSInt());
1234 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001235 case DECL_FUNCTION:
Mike Stump1eb44332009-09-09 15:08:12 +00001236 D = FunctionDecl::Create(*Context, 0, SourceLocation(), DeclarationName(),
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +00001237 QualType(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001238 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001239 case DECL_LINKAGE_SPEC:
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001240 D = LinkageSpecDecl::Create(*Context, 0, SourceLocation(),
1241 (LinkageSpecDecl::LanguageIDs)0,
1242 false);
1243 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001244 case DECL_NAMESPACE:
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001245 D = NamespaceDecl::Create(*Context, 0, SourceLocation(), 0);
1246 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001247 case DECL_NAMESPACE_ALIAS:
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001248 D = NamespaceAliasDecl::Create(*Context, 0, SourceLocation(),
1249 SourceLocation(), 0, SourceRange(), 0,
1250 SourceLocation(), 0);
1251 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001252 case DECL_USING:
Abramo Bagnaraef3dce82010-08-12 11:46:03 +00001253 D = UsingDecl::Create(*Context, 0, SourceRange(), SourceLocation(),
1254 0, DeclarationNameInfo(), false);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001255 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001256 case DECL_USING_SHADOW:
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001257 D = UsingShadowDecl::Create(*Context, 0, SourceLocation(), 0, 0);
1258 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001259 case DECL_USING_DIRECTIVE:
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001260 D = UsingDirectiveDecl::Create(*Context, 0, SourceLocation(),
1261 SourceLocation(), SourceRange(), 0,
1262 SourceLocation(), 0, 0);
1263 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001264 case DECL_UNRESOLVED_USING_VALUE:
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001265 D = UnresolvedUsingValueDecl::Create(*Context, 0, SourceLocation(),
Abramo Bagnaraef3dce82010-08-12 11:46:03 +00001266 SourceRange(), 0,
1267 DeclarationNameInfo());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001268 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001269 case DECL_UNRESOLVED_USING_TYPENAME:
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001270 D = UnresolvedUsingTypenameDecl::Create(*Context, 0, SourceLocation(),
1271 SourceLocation(), SourceRange(),
1272 0, SourceLocation(),
1273 DeclarationName());
1274 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001275 case DECL_CXX_RECORD:
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +00001276 D = CXXRecordDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001277 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001278 case DECL_CXX_METHOD:
Abramo Bagnara25777432010-08-11 22:01:17 +00001279 D = CXXMethodDecl::Create(*Context, 0, DeclarationNameInfo(),
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001280 QualType(), 0);
1281 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001282 case DECL_CXX_CONSTRUCTOR:
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001283 D = CXXConstructorDecl::Create(*Context, Decl::EmptyShell());
1284 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001285 case DECL_CXX_DESTRUCTOR:
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001286 D = CXXDestructorDecl::Create(*Context, Decl::EmptyShell());
1287 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001288 case DECL_CXX_CONVERSION:
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001289 D = CXXConversionDecl::Create(*Context, Decl::EmptyShell());
1290 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001291 case DECL_ACCESS_SPEC:
Abramo Bagnara6206d532010-06-05 05:09:32 +00001292 D = AccessSpecDecl::Create(*Context, AS_none, 0, SourceLocation(),
1293 SourceLocation());
1294 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001295 case DECL_FRIEND:
Argyrios Kyrtzidis67643342010-06-29 22:47:00 +00001296 D = FriendDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001297 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001298 case DECL_FRIEND_TEMPLATE:
Argyrios Kyrtzidis554e6aa2010-07-22 16:04:10 +00001299 D = FriendTemplateDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001300 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001301 case DECL_CLASS_TEMPLATE:
Argyrios Kyrtzidis5bf1bdc2010-06-21 10:57:41 +00001302 D = ClassTemplateDecl::Create(*Context, 0, SourceLocation(),
1303 DeclarationName(), 0, 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001304 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001305 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +00001306 D = ClassTemplateSpecializationDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001307 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001308 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +00001309 D = ClassTemplatePartialSpecializationDecl::Create(*Context,
1310 Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001311 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001312 case DECL_FUNCTION_TEMPLATE:
Argyrios Kyrtzidisf511ba62010-06-22 09:55:07 +00001313 D = FunctionTemplateDecl::Create(*Context, 0, SourceLocation(),
1314 DeclarationName(), 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001315 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001316 case DECL_TEMPLATE_TYPE_PARM:
Argyrios Kyrtzidisb8b03e62010-07-02 11:54:55 +00001317 D = TemplateTypeParmDecl::Create(*Context, Decl::EmptyShell());
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001318 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001319 case DECL_NON_TYPE_TEMPLATE_PARM:
Argyrios Kyrtzidisb24e1992010-06-25 16:25:09 +00001320 D = NonTypeTemplateParmDecl::Create(*Context, 0, SourceLocation(), 0,0,0,
1321 QualType(),0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001322 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001323 case DECL_TEMPLATE_TEMPLATE_PARM:
Argyrios Kyrtzidisbfcc92c2010-07-08 17:12:57 +00001324 D = TemplateTemplateParmDecl::Create(*Context, 0, SourceLocation(),0,0,0,0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001325 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001326 case DECL_STATIC_ASSERT:
Argyrios Kyrtzidis0d396892010-07-22 17:28:12 +00001327 D = StaticAssertDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner6ad9ac02010-05-07 21:43:38 +00001328 break;
1329
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001330 case DECL_OBJC_METHOD:
Mike Stump1eb44332009-09-09 15:08:12 +00001331 D = ObjCMethodDecl::Create(*Context, SourceLocation(), SourceLocation(),
Douglas Gregor4bc1cb62010-03-08 14:59:44 +00001332 Selector(), QualType(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001333 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001334 case DECL_OBJC_INTERFACE:
Douglas Gregordeacbdc2010-08-11 12:19:30 +00001335 D = ObjCInterfaceDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001336 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001337 case DECL_OBJC_IVAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +00001338 D = ObjCIvarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +00001339 ObjCIvarDecl::None);
1340 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001341 case DECL_OBJC_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001342 D = ObjCProtocolDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001343 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001344 case DECL_OBJC_AT_DEFS_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +00001345 D = ObjCAtDefsFieldDecl::Create(*Context, 0, SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +00001346 QualType(), 0);
1347 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001348 case DECL_OBJC_CLASS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001349 D = ObjCClassDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001350 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001351 case DECL_OBJC_FORWARD_PROTOCOL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001352 D = ObjCForwardProtocolDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001353 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001354 case DECL_OBJC_CATEGORY:
Douglas Gregor3db211b2010-01-16 16:38:58 +00001355 D = ObjCCategoryDecl::Create(*Context, 0, SourceLocation(),
1356 SourceLocation(), SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001357 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001358 case DECL_OBJC_CATEGORY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001359 D = ObjCCategoryImplDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001360 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001361 case DECL_OBJC_IMPLEMENTATION:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001362 D = ObjCImplementationDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001363 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001364 case DECL_OBJC_COMPATIBLE_ALIAS:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001365 D = ObjCCompatibleAliasDecl::Create(*Context, 0, SourceLocation(), 0, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001366 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001367 case DECL_OBJC_PROPERTY:
Fariborz Jahaniand0502402010-01-21 17:36:00 +00001368 D = ObjCPropertyDecl::Create(*Context, 0, SourceLocation(), 0, SourceLocation(),
John McCall83a230c2010-06-04 20:50:08 +00001369 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001370 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001371 case DECL_OBJC_PROPERTY_IMPL:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001372 D = ObjCPropertyImplDecl::Create(*Context, 0, SourceLocation(),
Mike Stump1eb44332009-09-09 15:08:12 +00001373 SourceLocation(), 0,
Chris Lattner698f9252009-04-27 05:27:42 +00001374 ObjCPropertyImplDecl::Dynamic, 0);
1375 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001376 case DECL_FIELD:
Mike Stump1eb44332009-09-09 15:08:12 +00001377 D = FieldDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0, 0,
Argyrios Kyrtzidisa5d82002009-08-21 00:31:54 +00001378 false);
Chris Lattner698f9252009-04-27 05:27:42 +00001379 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001380 case DECL_VAR:
Argyrios Kyrtzidisa1d56622009-08-19 01:27:57 +00001381 D = VarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
John McCalld931b082010-08-26 03:08:43 +00001382 SC_None, SC_None);
Chris Lattner698f9252009-04-27 05:27:42 +00001383 break;
1384
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001385 case DECL_IMPLICIT_PARAM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001386 D = ImplicitParamDecl::Create(*Context, 0, SourceLocation(), 0, QualType());
Chris Lattner698f9252009-04-27 05:27:42 +00001387 break;
1388
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001389 case DECL_PARM_VAR:
Mike Stump1eb44332009-09-09 15:08:12 +00001390 D = ParmVarDecl::Create(*Context, 0, SourceLocation(), 0, QualType(), 0,
John McCalld931b082010-08-26 03:08:43 +00001391 SC_None, SC_None, 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001392 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001393 case DECL_FILE_SCOPE_ASM:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001394 D = FileScopeAsmDecl::Create(*Context, 0, SourceLocation(), 0);
Chris Lattner698f9252009-04-27 05:27:42 +00001395 break;
Sebastian Redl8538e8d2010-08-18 23:57:32 +00001396 case DECL_BLOCK:
Chris Lattnerd1d64a02009-04-27 21:45:14 +00001397 D = BlockDecl::Create(*Context, 0, SourceLocation());
Chris Lattner698f9252009-04-27 05:27:42 +00001398 break;
1399 }
Chris Lattner698f9252009-04-27 05:27:42 +00001400
Sebastian Redld527cc02010-08-18 23:56:48 +00001401 assert(D && "Unknown declaration reading AST file");
Chris Lattner4e3fcc82009-04-27 06:01:06 +00001402 LoadedDecl(Index, D);
1403 Reader.Visit(D);
Chris Lattner698f9252009-04-27 05:27:42 +00001404
1405 // If this declaration is also a declaration context, get the
1406 // offsets for its tables of lexical and visible declarations.
1407 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
1408 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
1409 if (Offsets.first || Offsets.second) {
1410 DC->setHasExternalLexicalStorage(Offsets.first != 0);
1411 DC->setHasExternalVisibleStorage(Offsets.second != 0);
Sebastian Redl681d7232010-07-27 00:17:23 +00001412 DeclContextInfo Info;
1413 if (ReadDeclContextStorage(DeclsCursor, Offsets, Info))
1414 return 0;
Sebastian Redld692af72010-07-27 18:24:41 +00001415 DeclContextInfos &Infos = DeclContextOffsets[DC];
Sebastian Redle1dde812010-08-24 00:50:04 +00001416 // Reading the TU will happen after reading its lexical update blocks,
1417 // so we need to make sure we insert in front. For all other contexts,
1418 // the vector is empty here anyway, so there's no loss in efficiency.
Sebastian Redld692af72010-07-27 18:24:41 +00001419 Infos.insert(Infos.begin(), Info);
Sebastian Redle1dde812010-08-24 00:50:04 +00001420
1421 // Now add the pending visible updates for this decl context, if it has
1422 // any.
1423 DeclContextVisibleUpdatesPending::iterator I =
1424 PendingVisibleUpdates.find(ID);
1425 if (I != PendingVisibleUpdates.end()) {
1426 DeclContextVisibleUpdates &U = I->second;
1427 Info.LexicalDecls = 0;
1428 Info.NumLexicalDecls = 0;
1429 for (DeclContextVisibleUpdates::iterator UI = U.begin(), UE = U.end();
1430 UI != UE; ++UI) {
1431 Info.NameLookupTableData = *UI;
1432 Infos.push_back(Info);
1433 }
1434 PendingVisibleUpdates.erase(I);
1435 }
Chris Lattner698f9252009-04-27 05:27:42 +00001436 }
1437 }
Sebastian Redl6e50e002010-08-24 22:50:19 +00001438
1439 // If this is a template, read additional specializations that may be in a
1440 // different part of the chain.
1441 if (isa<RedeclarableTemplateDecl>(D)) {
1442 AdditionalTemplateSpecializationsMap::iterator F =
1443 AdditionalTemplateSpecializationsPending.find(ID);
1444 if (F != AdditionalTemplateSpecializationsPending.end()) {
1445 for (AdditionalTemplateSpecializations::iterator I = F->second.begin(),
1446 E = F->second.end();
1447 I != E; ++I)
1448 GetDecl(*I);
1449 AdditionalTemplateSpecializationsPending.erase(F);
1450 }
1451 }
Chris Lattner698f9252009-04-27 05:27:42 +00001452 assert(Idx == Record.size());
1453
1454 // If we have deserialized a declaration that has a definition the
Argyrios Kyrtzidisbb80a8e2010-07-07 15:46:26 +00001455 // AST consumer might need to know about, queue it.
1456 // We don't pass it to the consumer immediately because we may be in recursive
1457 // loading, and some declarations may still be initializing.
1458 if (isConsumerInterestedIn(D))
1459 InterestingDecls.push_back(D);
Chris Lattner698f9252009-04-27 05:27:42 +00001460
1461 return D;
1462}