blob: fd6708dd5c3f7947baaed01a2ed8aee6d7a4eff8 [file] [log] [blame]
Sebastian Redld6522cf2010-08-18 23:56:31 +00001//===--- ASTWriterDecl.cpp - Declaration Serialization --------------------===//
Chris Lattner7099dbc2009-04-27 06:16:06 +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//
10// This file implements serialization for Declarations.
11//
12//===----------------------------------------------------------------------===//
13
Sebastian Redl1914c6f2010-08-18 23:56:37 +000014#include "clang/Serialization/ASTWriter.h"
Sebastian Redlfa1f3702011-04-24 16:28:13 +000015#include "ASTCommon.h"
Chris Lattnerca025db2010-05-07 21:43:38 +000016#include "clang/AST/DeclCXX.h"
Argyrios Kyrtzidis3317d982010-10-20 16:22:56 +000017#include "clang/AST/DeclContextInternals.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000018#include "clang/AST/DeclTemplate.h"
19#include "clang/AST/DeclVisitor.h"
20#include "clang/AST/Expr.h"
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +000021#include "clang/Basic/SourceManager.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000022#include "clang/Serialization/ASTReader.h"
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +000023#include "llvm/ADT/Twine.h"
Chris Lattner7099dbc2009-04-27 06:16:06 +000024#include "llvm/Bitcode/BitstreamWriter.h"
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +000025#include "llvm/Support/ErrorHandling.h"
Chris Lattner7099dbc2009-04-27 06:16:06 +000026using namespace clang;
Sebastian Redlfa1f3702011-04-24 16:28:13 +000027using namespace serialization;
Chris Lattner7099dbc2009-04-27 06:16:06 +000028
29//===----------------------------------------------------------------------===//
30// Declaration serialization
31//===----------------------------------------------------------------------===//
32
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000033namespace clang {
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000034 class ASTDeclWriter : public DeclVisitor<ASTDeclWriter, void> {
Chris Lattner7099dbc2009-04-27 06:16:06 +000035
Sebastian Redl55c0ad52010-08-18 23:56:21 +000036 ASTWriter &Writer;
Chris Lattner7099dbc2009-04-27 06:16:06 +000037 ASTContext &Context;
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000038 typedef ASTWriter::RecordData RecordData;
39 RecordData &Record;
Chris Lattner7099dbc2009-04-27 06:16:06 +000040
41 public:
Sebastian Redl539c5062010-08-18 23:57:32 +000042 serialization::DeclCode Code;
Chris Lattner258172e2009-04-27 07:35:58 +000043 unsigned AbbrevToUse;
Chris Lattner7099dbc2009-04-27 06:16:06 +000044
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000045 ASTDeclWriter(ASTWriter &Writer, ASTContext &Context, RecordData &Record)
Chris Lattner258172e2009-04-27 07:35:58 +000046 : Writer(Writer), Context(Context), Record(Record) {
47 }
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000048
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +000049 void Visit(Decl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000050
51 void VisitDecl(Decl *D);
52 void VisitTranslationUnitDecl(TranslationUnitDecl *D);
53 void VisitNamedDecl(NamedDecl *D);
Chris Lattnerc8e630e2011-02-17 07:39:24 +000054 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregore31bbd92010-02-21 18:22:14 +000055 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000056 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
57 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000058 void VisitTypeDecl(TypeDecl *D);
Douglas Gregor1f179062011-12-19 14:40:25 +000059 void VisitTypedefNameDecl(TypedefNameDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000060 void VisitTypedefDecl(TypedefDecl *D);
Richard Smithdda56e42011-04-15 14:24:37 +000061 void VisitTypeAliasDecl(TypeAliasDecl *D);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000062 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000063 void VisitTagDecl(TagDecl *D);
64 void VisitEnumDecl(EnumDecl *D);
65 void VisitRecordDecl(RecordDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000066 void VisitCXXRecordDecl(CXXRecordDecl *D);
67 void VisitClassTemplateSpecializationDecl(
68 ClassTemplateSpecializationDecl *D);
69 void VisitClassTemplatePartialSpecializationDecl(
70 ClassTemplatePartialSpecializationDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +000071 void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D);
72 void VisitVarTemplatePartialSpecializationDecl(
73 VarTemplatePartialSpecializationDecl *D);
Fariborz Jahanian3a039e32011-08-27 20:50:59 +000074 void VisitClassScopeFunctionSpecializationDecl(
75 ClassScopeFunctionSpecializationDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000076 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000077 void VisitValueDecl(ValueDecl *D);
78 void VisitEnumConstantDecl(EnumConstantDecl *D);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000079 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +000080 void VisitDeclaratorDecl(DeclaratorDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000081 void VisitFunctionDecl(FunctionDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000082 void VisitCXXMethodDecl(CXXMethodDecl *D);
83 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
84 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
85 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000086 void VisitFieldDecl(FieldDecl *D);
John McCall5e77d762013-04-16 07:28:30 +000087 void VisitMSPropertyDecl(MSPropertyDecl *D);
Francois Pichet783dd6e2010-11-21 06:08:52 +000088 void VisitIndirectFieldDecl(IndirectFieldDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000089 void VisitVarDecl(VarDecl *D);
90 void VisitImplicitParamDecl(ImplicitParamDecl *D);
91 void VisitParmVarDecl(ParmVarDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000092 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
93 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +000094 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000095 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +000096 void VisitVarTemplateDecl(VarTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +000097 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000098 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3f1b5d02011-05-05 21:57:07 +000099 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000100 void VisitUsingDecl(UsingDecl *D);
101 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000102 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000103 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
Douglas Gregorba345522011-12-02 23:23:56 +0000104 void VisitImportDecl(ImportDecl *D);
Abramo Bagnarad7340582010-06-05 05:09:32 +0000105 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000106 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000107 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
108 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000109 void VisitBlockDecl(BlockDecl *D);
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +0000110 void VisitCapturedDecl(CapturedDecl *D);
Michael Han84324352013-02-22 17:15:32 +0000111 void VisitEmptyDecl(EmptyDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000112
Mike Stump11289f42009-09-09 15:08:12 +0000113 void VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset,
Chris Lattner7099dbc2009-04-27 06:16:06 +0000114 uint64_t VisibleOffset);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000115 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000116
117
Alexis Hunted053252010-05-30 07:21:58 +0000118 // FIXME: Put in the same order is DeclNodes.td?
Chris Lattner7099dbc2009-04-27 06:16:06 +0000119 void VisitObjCMethodDecl(ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000120 void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000121 void VisitObjCContainerDecl(ObjCContainerDecl *D);
122 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
123 void VisitObjCIvarDecl(ObjCIvarDecl *D);
124 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
125 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000126 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
127 void VisitObjCImplDecl(ObjCImplDecl *D);
128 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
129 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
130 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
131 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
132 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
Alexey Bataeva769e072013-03-22 06:34:35 +0000133 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
Richard Smithd28ac5b2014-03-22 23:33:22 +0000134
Douglas Gregor85f3f952015-07-07 03:57:15 +0000135 /// Add an Objective-C type parameter list to the given record.
136 void AddObjCTypeParamList(ObjCTypeParamList *typeParams) {
137 // Empty type parameter list.
138 if (!typeParams) {
139 Record.push_back(0);
140 return;
141 }
142
143 Record.push_back(typeParams->size());
144 for (auto typeParam : *typeParams) {
145 Writer.AddDeclRef(typeParam, Record);
146 }
147 Writer.AddSourceLocation(typeParams->getLAngleLoc(), Record);
148 Writer.AddSourceLocation(typeParams->getRAngleLoc(), Record);
149 }
150
Richard Smithd28ac5b2014-03-22 23:33:22 +0000151 void AddFunctionDefinition(const FunctionDecl *FD) {
152 assert(FD->doesThisDeclarationHaveABody());
Richard Smithc2bb8182015-03-24 06:36:48 +0000153 if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
154 Record.push_back(CD->NumCtorInitializers);
155 if (CD->NumCtorInitializers)
156 Writer.AddCXXCtorInitializersRef(
157 llvm::makeArrayRef(CD->init_begin(), CD->init_end()), Record);
158 }
Richard Smithd28ac5b2014-03-22 23:33:22 +0000159 Writer.AddStmt(FD->getBody());
160 }
Richard Smith509fc852015-02-27 23:05:10 +0000161
162 /// Get the specialization decl from an entry in the specialization list.
163 template <typename EntryType>
164 typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType *
165 getSpecializationDecl(EntryType &T) {
166 return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T);
167 }
168
169 /// Get the list of partial specializations from a template's common ptr.
170 template<typename T>
171 decltype(T::PartialSpecializations) &getPartialSpecializations(T *Common) {
172 return Common->PartialSpecializations;
173 }
174 ArrayRef<Decl> getPartialSpecializations(FunctionTemplateDecl::Common *) {
175 return None;
176 }
177
178 template<typename Decl>
179 void AddTemplateSpecializations(Decl *D) {
180 auto *Common = D->getCommonPtr();
181
182 // If we have any lazy specializations, and the external AST source is
183 // our chained AST reader, we can just write out the DeclIDs. Otherwise,
184 // we need to resolve them to actual declarations.
185 if (Writer.Chain != Writer.Context->getExternalSource() &&
186 Common->LazySpecializations) {
187 D->LoadLazySpecializations();
188 assert(!Common->LazySpecializations);
189 }
190
191 auto &Specializations = Common->Specializations;
192 auto &&PartialSpecializations = getPartialSpecializations(Common);
193 ArrayRef<DeclID> LazySpecializations;
194 if (auto *LS = Common->LazySpecializations)
195 LazySpecializations = ArrayRef<DeclID>(LS + 1, LS + 1 + LS[0]);
196
197 Record.push_back(Specializations.size() +
198 PartialSpecializations.size() +
199 LazySpecializations.size());
200 for (auto &Entry : Specializations) {
201 auto *D = getSpecializationDecl(Entry);
202 assert(D->isCanonicalDecl() && "non-canonical decl in set");
203 Writer.AddDeclRef(D, Record);
204 }
205 for (auto &Entry : PartialSpecializations) {
206 auto *D = getSpecializationDecl(Entry);
207 assert(D->isCanonicalDecl() && "non-canonical decl in set");
208 Writer.AddDeclRef(D, Record);
209 }
Benjamin Kramerf367dd92015-06-12 15:31:50 +0000210 Record.append(LazySpecializations.begin(), LazySpecializations.end());
Richard Smith509fc852015-02-27 23:05:10 +0000211 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000212 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000213}
Chris Lattner7099dbc2009-04-27 06:16:06 +0000214
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000215void ASTDeclWriter::Visit(Decl *D) {
216 DeclVisitor<ASTDeclWriter>::Visit(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000217
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000218 // Source locations require array (variable-length) abbreviations. The
219 // abbreviation infrastructure requires that arrays are encoded last, so
220 // we handle it here in the case of those classes derived from DeclaratorDecl
221 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)){
222 Writer.AddTypeSourceInfo(DD->getTypeSourceInfo(), Record);
223 }
224
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000225 // Handle FunctionDecl's body here and write it after all other Stmts/Exprs
226 // have been written. We want it last because we will not read it back when
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000227 // retrieving it from the AST, we'll just lazily set the offset.
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000228 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
Alexis Hunt4a8ea102011-05-06 20:44:56 +0000229 Record.push_back(FD->doesThisDeclarationHaveABody());
230 if (FD->doesThisDeclarationHaveABody())
Richard Smithc2bb8182015-03-24 06:36:48 +0000231 AddFunctionDefinition(FD);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000232 }
233}
234
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000235void ASTDeclWriter::VisitDecl(Decl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000236 Writer.AddDeclRef(cast_or_null<Decl>(D->getDeclContext()), Record);
237 Writer.AddDeclRef(cast_or_null<Decl>(D->getLexicalDeclContext()), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000238 Record.push_back(D->isInvalidDecl());
239 Record.push_back(D->hasAttrs());
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000240 if (D->hasAttrs())
Craig Topper8c2a2a02014-08-30 16:55:39 +0000241 Writer.WriteAttributes(llvm::makeArrayRef(D->getAttrs().begin(),
242 D->getAttrs().size()), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000243 Record.push_back(D->isImplicit());
Douglas Gregorebada0772010-06-17 23:14:26 +0000244 Record.push_back(D->isUsed(false));
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +0000245 Record.push_back(D->isReferenced());
Douglas Gregor781f7132012-01-06 16:59:53 +0000246 Record.push_back(D->isTopLevelDeclInObjCContainer());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000247 Record.push_back(D->getAccess());
Douglas Gregor781f7132012-01-06 16:59:53 +0000248 Record.push_back(D->isModulePrivate());
Douglas Gregora28bcdd2011-12-01 02:07:58 +0000249 Record.push_back(Writer.inferSubmoduleIDFromLocation(D->getLocation()));
Richard Smithc264d352014-03-23 02:30:01 +0000250
251 // If this declaration injected a name into a context different from its
252 // lexical context, and that context is an imported namespace, we need to
253 // update its visible declarations to include this name.
254 //
255 // This happens when we instantiate a class with a friend declaration or a
256 // function with a local extern declaration, for instance.
Richard Smith5fc18a92015-07-12 23:43:21 +0000257 //
258 // FIXME: Can we handle this in AddedVisibleDecl instead?
Richard Smithc264d352014-03-23 02:30:01 +0000259 if (D->isOutOfLine()) {
Richard Smithe3a97022014-03-23 20:41:56 +0000260 auto *DC = D->getDeclContext();
261 while (auto *NS = dyn_cast<NamespaceDecl>(DC->getRedeclContext())) {
262 if (!NS->isFromASTFile())
263 break;
Chandler Carruth8a3d24d2015-03-26 04:27:10 +0000264 Writer.UpdatedDeclContexts.insert(NS->getPrimaryContext());
Richard Smithe3a97022014-03-23 20:41:56 +0000265 if (!NS->isInlineNamespace())
266 break;
267 DC = NS->getParent();
268 }
Richard Smithc264d352014-03-23 02:30:01 +0000269 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000270}
271
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000272void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
Douglas Gregordab42432011-08-12 00:15:20 +0000273 llvm_unreachable("Translation units aren't directly serialized");
Chris Lattner7099dbc2009-04-27 06:16:06 +0000274}
275
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000276void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000277 VisitDecl(D);
278 Writer.AddDeclarationName(D->getDeclName(), Record);
Richard Smith2b560572015-02-07 03:11:11 +0000279 Record.push_back(needsAnonymousDeclarationNumber(D)
280 ? Writer.getAnonymousDeclarationNumber(D)
281 : 0);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000282}
283
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000284void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000285 VisitNamedDecl(D);
Abramo Bagnarab3185b02011-03-06 15:48:19 +0000286 Writer.AddSourceLocation(D->getLocStart(), Record);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000287 Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000288}
289
Douglas Gregor1f179062011-12-19 14:40:25 +0000290void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) {
Douglas Gregor05f10352011-12-17 23:38:30 +0000291 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000292 VisitTypeDecl(D);
Enea Zaffanellaa86d88c2013-06-20 12:46:19 +0000293 Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record);
294 Record.push_back(D->isModed());
295 if (D->isModed())
296 Writer.AddTypeRef(D->getUnderlyingType(), Record);
Douglas Gregor1f179062011-12-19 14:40:25 +0000297}
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000298
Douglas Gregor1f179062011-12-19 14:40:25 +0000299void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) {
300 VisitTypedefNameDecl(D);
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000301 if (!D->hasAttrs() &&
302 !D->isImplicit() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000303 D->getFirstDecl() == D->getMostRecentDecl() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000304 !D->isInvalidDecl() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000305 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000306 !D->isModulePrivate() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000307 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000308 D->getDeclName().getNameKind() == DeclarationName::Identifier)
309 AbbrevToUse = Writer.getDeclTypedefAbbrev();
310
Sebastian Redl539c5062010-08-18 23:57:32 +0000311 Code = serialization::DECL_TYPEDEF;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000312}
313
Richard Smithdda56e42011-04-15 14:24:37 +0000314void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) {
Douglas Gregor1f179062011-12-19 14:40:25 +0000315 VisitTypedefNameDecl(D);
Richard Smith43ccec8e2014-08-26 03:52:16 +0000316 Writer.AddDeclRef(D->getDescribedAliasTemplate(), Record);
Richard Smithdda56e42011-04-15 14:24:37 +0000317 Code = serialization::DECL_TYPEALIAS;
318}
319
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000320void ASTDeclWriter::VisitTagDecl(TagDecl *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000321 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000322 VisitTypeDecl(D);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000323 Record.push_back(D->getIdentifierNamespace());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000324 Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding
Richard Smith2c381642014-08-27 23:11:59 +0000325 if (!isa<CXXRecordDecl>(D))
326 Record.push_back(D->isCompleteDefinition());
Douglas Gregor5089c762010-02-12 17:40:34 +0000327 Record.push_back(D->isEmbeddedInDeclarator());
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +0000328 Record.push_back(D->isFreeStanding());
David Blaikiea8d23ce2013-07-14 01:07:41 +0000329 Record.push_back(D->isCompleteDefinitionRequired());
Argyrios Kyrtzidis664b6902009-07-14 03:18:02 +0000330 Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Richard Smith70d58502014-08-30 00:04:23 +0000331
332 if (D->hasExtInfo()) {
333 Record.push_back(1);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000334 Writer.AddQualifierInfo(*D->getExtInfo(), Record);
Richard Smith70d58502014-08-30 00:04:23 +0000335 } else if (auto *TD = D->getTypedefNameForAnonDecl()) {
336 Record.push_back(2);
337 Writer.AddDeclRef(TD, Record);
338 Writer.AddIdentifierRef(TD->getDeclName().getAsIdentifierInfo(), Record);
339 } else if (auto *DD = D->getDeclaratorForAnonDecl()) {
340 Record.push_back(3);
341 Writer.AddDeclRef(DD, Record);
342 } else {
343 Record.push_back(0);
344 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000345}
346
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000347void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000348 VisitTagDecl(D);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000349 Writer.AddTypeSourceInfo(D->getIntegerTypeSourceInfo(), Record);
350 if (!D->getIntegerTypeSourceInfo())
351 Writer.AddTypeRef(D->getIntegerType(), Record);
John McCall56774992009-12-09 09:09:27 +0000352 Writer.AddTypeRef(D->getPromotionType(), Record);
John McCall9aa35be2010-05-06 08:49:23 +0000353 Record.push_back(D->getNumPositiveBits());
354 Record.push_back(D->getNumNegativeBits());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000355 Record.push_back(D->isScoped());
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000356 Record.push_back(D->isScopedUsingClassTag());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000357 Record.push_back(D->isFixed());
Richard Smith4b38ded2012-03-14 23:13:10 +0000358 if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
359 Writer.AddDeclRef(MemberInfo->getInstantiatedFrom(), Record);
360 Record.push_back(MemberInfo->getTemplateSpecializationKind());
361 Writer.AddSourceLocation(MemberInfo->getPointOfInstantiation(), Record);
362 } else {
Craig Toppera13603a2014-05-22 05:54:18 +0000363 Writer.AddDeclRef(nullptr, Record);
Richard Smith4b38ded2012-03-14 23:13:10 +0000364 }
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000365
366 if (!D->hasAttrs() &&
367 !D->isImplicit() &&
368 !D->isUsed(false) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000369 !D->hasExtInfo() &&
Richard Smith70d58502014-08-30 00:04:23 +0000370 !D->getTypedefNameForAnonDecl() &&
371 !D->getDeclaratorForAnonDecl() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000372 D->getFirstDecl() == D->getMostRecentDecl() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000373 !D->isInvalidDecl() &&
374 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000375 !D->isTopLevelDeclInObjCContainer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000376 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000377 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000378 !CXXRecordDecl::classofKind(D->getKind()) &&
379 !D->getIntegerTypeSourceInfo() &&
Argyrios Kyrtzidisca370b0d2013-03-18 22:23:49 +0000380 !D->getMemberSpecializationInfo() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000381 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000382 D->getDeclName().getNameKind() == DeclarationName::Identifier)
383 AbbrevToUse = Writer.getDeclEnumAbbrev();
384
Sebastian Redl539c5062010-08-18 23:57:32 +0000385 Code = serialization::DECL_ENUM;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000386}
387
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000388void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000389 VisitTagDecl(D);
390 Record.push_back(D->hasFlexibleArrayMember());
391 Record.push_back(D->isAnonymousStructOrUnion());
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000392 Record.push_back(D->hasObjectMember());
Fariborz Jahanian78652202013-01-25 23:57:05 +0000393 Record.push_back(D->hasVolatileMember());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000394
395 if (!D->hasAttrs() &&
396 !D->isImplicit() &&
397 !D->isUsed(false) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000398 !D->hasExtInfo() &&
Richard Smith70d58502014-08-30 00:04:23 +0000399 !D->getTypedefNameForAnonDecl() &&
400 !D->getDeclaratorForAnonDecl() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000401 D->getFirstDecl() == D->getMostRecentDecl() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000402 !D->isInvalidDecl() &&
403 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000404 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000405 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000406 !D->isModulePrivate() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000407 !CXXRecordDecl::classofKind(D->getKind()) &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000408 !needsAnonymousDeclarationNumber(D) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000409 D->getDeclName().getNameKind() == DeclarationName::Identifier)
Douglas Gregor03412ba2011-06-03 02:27:19 +0000410 AbbrevToUse = Writer.getDeclRecordAbbrev();
411
Sebastian Redl539c5062010-08-18 23:57:32 +0000412 Code = serialization::DECL_RECORD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000413}
414
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000415void ASTDeclWriter::VisitValueDecl(ValueDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000416 VisitNamedDecl(D);
417 Writer.AddTypeRef(D->getType(), Record);
418}
419
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000420void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000421 VisitValueDecl(D);
422 Record.push_back(D->getInitExpr()? 1 : 0);
423 if (D->getInitExpr())
424 Writer.AddStmt(D->getInitExpr());
425 Writer.AddAPSInt(D->getInitVal(), Record);
Douglas Gregor03412ba2011-06-03 02:27:19 +0000426
Sebastian Redl539c5062010-08-18 23:57:32 +0000427 Code = serialization::DECL_ENUM_CONSTANT;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000428}
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000429
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000430void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000431 VisitValueDecl(D);
Abramo Bagnaradff19302011-03-08 08:55:46 +0000432 Writer.AddSourceLocation(D->getInnerLocStart(), Record);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000433 Record.push_back(D->hasExtInfo());
434 if (D->hasExtInfo())
435 Writer.AddQualifierInfo(*D->getExtInfo(), Record);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000436}
Chris Lattner7099dbc2009-04-27 06:16:06 +0000437
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000438void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000439 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000440 VisitDeclaratorDecl(D);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000441 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000442 Record.push_back(D->getIdentifierNamespace());
Douglas Gregorb2585692012-01-04 17:13:46 +0000443
444 // FunctionDecl's body is handled last at ASTWriterDecl::Visit,
445 // after everything else is written.
446
Richard Smith72625c22015-02-06 23:20:21 +0000447 Record.push_back((int)D->SClass); // FIXME: stable encoding
Douglas Gregorb2585692012-01-04 17:13:46 +0000448 Record.push_back(D->IsInline);
Richard Smith72625c22015-02-06 23:20:21 +0000449 Record.push_back(D->IsInlineSpecified);
450 Record.push_back(D->IsVirtualAsWritten);
451 Record.push_back(D->IsPure);
452 Record.push_back(D->HasInheritedPrototype);
453 Record.push_back(D->HasWrittenPrototype);
454 Record.push_back(D->IsDeleted);
455 Record.push_back(D->IsTrivial);
456 Record.push_back(D->IsDefaulted);
457 Record.push_back(D->IsExplicitlyDefaulted);
458 Record.push_back(D->HasImplicitReturnZero);
459 Record.push_back(D->IsConstexpr);
Argyrios Kyrtzidis1eb71a12012-12-06 18:59:10 +0000460 Record.push_back(D->HasSkippedBody);
Richard Smith72625c22015-02-06 23:20:21 +0000461 Record.push_back(D->IsLateTemplateParsed);
Rafael Espindola3ae00052013-05-13 00:12:11 +0000462 Record.push_back(D->getLinkageInternal());
Douglas Gregorb2585692012-01-04 17:13:46 +0000463 Writer.AddSourceLocation(D->getLocEnd(), Record);
464
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000465 Record.push_back(D->getTemplatedKind());
466 switch (D->getTemplatedKind()) {
467 case FunctionDecl::TK_NonTemplate:
468 break;
469 case FunctionDecl::TK_FunctionTemplate:
470 Writer.AddDeclRef(D->getDescribedFunctionTemplate(), Record);
471 break;
472 case FunctionDecl::TK_MemberSpecialization: {
473 MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo();
474 Writer.AddDeclRef(MemberInfo->getInstantiatedFrom(), Record);
475 Record.push_back(MemberInfo->getTemplateSpecializationKind());
476 Writer.AddSourceLocation(MemberInfo->getPointOfInstantiation(), Record);
477 break;
478 }
479 case FunctionDecl::TK_FunctionTemplateSpecialization: {
480 FunctionTemplateSpecializationInfo *
481 FTSInfo = D->getTemplateSpecializationInfo();
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000482 Writer.AddDeclRef(FTSInfo->getTemplate(), Record);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000483 Record.push_back(FTSInfo->getTemplateSpecializationKind());
484
485 // Template arguments.
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000486 Writer.AddTemplateArgumentList(FTSInfo->TemplateArguments, Record);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000487
488 // Template args as written.
Craig Toppera13603a2014-05-22 05:54:18 +0000489 Record.push_back(FTSInfo->TemplateArgumentsAsWritten != nullptr);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000490 if (FTSInfo->TemplateArgumentsAsWritten) {
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000491 Record.push_back(FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs);
492 for (int i=0, e = FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs;
493 i!=e; ++i)
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000494 Writer.AddTemplateArgumentLoc((*FTSInfo->TemplateArgumentsAsWritten)[i],
495 Record);
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000496 Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->LAngleLoc,
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000497 Record);
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000498 Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->RAngleLoc,
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000499 Record);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000500 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000501
502 Writer.AddSourceLocation(FTSInfo->getPointOfInstantiation(), Record);
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000503
504 if (D->isCanonicalDecl()) {
505 // Write the template that contains the specializations set. We will
506 // add a FunctionTemplateSpecializationInfo to it when reading.
507 Writer.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl(), Record);
508 }
Argyrios Kyrtzidisdc9ca0a2010-06-25 16:24:51 +0000509 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000510 }
511 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
512 DependentFunctionTemplateSpecializationInfo *
513 DFTSInfo = D->getDependentSpecializationInfo();
514
515 // Templates.
516 Record.push_back(DFTSInfo->getNumTemplates());
517 for (int i=0, e = DFTSInfo->getNumTemplates(); i != e; ++i)
518 Writer.AddDeclRef(DFTSInfo->getTemplate(i), Record);
519
520 // Templates args.
521 Record.push_back(DFTSInfo->getNumTemplateArgs());
522 for (int i=0, e = DFTSInfo->getNumTemplateArgs(); i != e; ++i)
523 Writer.AddTemplateArgumentLoc(DFTSInfo->getTemplateArg(i), Record);
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000524 Writer.AddSourceLocation(DFTSInfo->getLAngleLoc(), Record);
525 Writer.AddSourceLocation(DFTSInfo->getRAngleLoc(), Record);
Argyrios Kyrtzidisdc9ca0a2010-06-25 16:24:51 +0000526 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000527 }
528 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000529
Chris Lattner7099dbc2009-04-27 06:16:06 +0000530 Record.push_back(D->param_size());
Aaron Ballmanf6bf62e2014-03-07 15:12:56 +0000531 for (auto P : D->params())
532 Writer.AddDeclRef(P, Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000533 Code = serialization::DECL_FUNCTION;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000534}
535
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000536void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000537 VisitNamedDecl(D);
538 // FIXME: convert to LazyStmtPtr?
Mike Stump11289f42009-09-09 15:08:12 +0000539 // Unlike C/C++, method bodies will never be in header files.
Craig Toppera13603a2014-05-22 05:54:18 +0000540 bool HasBodyStuff = D->getBody() != nullptr ||
541 D->getSelfDecl() != nullptr || D->getCmdDecl() != nullptr;
Argyrios Kyrtzidisa8607772010-08-09 10:54:37 +0000542 Record.push_back(HasBodyStuff);
543 if (HasBodyStuff) {
Argyrios Kyrtzidisddcd1322009-06-30 02:35:26 +0000544 Writer.AddStmt(D->getBody());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000545 Writer.AddDeclRef(D->getSelfDecl(), Record);
546 Writer.AddDeclRef(D->getCmdDecl(), Record);
547 }
548 Record.push_back(D->isInstanceMethod());
549 Record.push_back(D->isVariadic());
Jordan Rosed01e83a2012-10-10 16:42:25 +0000550 Record.push_back(D->isPropertyAccessor());
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000551 Record.push_back(D->isDefined());
Argyrios Kyrtzidis08f96a92012-05-09 16:12:57 +0000552 Record.push_back(D->IsOverriding);
Argyrios Kyrtzidis1eb71a12012-12-06 18:59:10 +0000553 Record.push_back(D->HasSkippedBody);
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000554
555 Record.push_back(D->IsRedeclaration);
556 Record.push_back(D->HasRedeclaration);
557 if (D->HasRedeclaration) {
558 assert(Context.getObjCMethodRedeclaration(D));
559 Writer.AddDeclRef(Context.getObjCMethodRedeclaration(D), Record);
560 }
561
Chris Lattner7099dbc2009-04-27 06:16:06 +0000562 // FIXME: stable encoding for @required/@optional
Mike Stump11289f42009-09-09 15:08:12 +0000563 Record.push_back(D->getImplementationControl());
Douglas Gregor813a0662015-06-19 18:14:38 +0000564 // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway/nullability
Mike Stump11289f42009-09-09 15:08:12 +0000565 Record.push_back(D->getObjCDeclQualifier());
Douglas Gregor33823722011-06-11 01:09:30 +0000566 Record.push_back(D->hasRelatedResultType());
Alp Toker314cc812014-01-25 16:55:45 +0000567 Writer.AddTypeRef(D->getReturnType(), Record);
568 Writer.AddTypeSourceInfo(D->getReturnTypeSourceInfo(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000569 Writer.AddSourceLocation(D->getLocEnd(), Record);
570 Record.push_back(D->param_size());
Aaron Ballman43b68be2014-03-07 17:50:17 +0000571 for (const auto *P : D->params())
572 Writer.AddDeclRef(P, Record);
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000573
574 Record.push_back(D->SelLocsKind);
575 unsigned NumStoredSelLocs = D->getNumStoredSelLocs();
576 SourceLocation *SelLocs = D->getStoredSelLocs();
577 Record.push_back(NumStoredSelLocs);
578 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
579 Writer.AddSourceLocation(SelLocs[i], Record);
580
Sebastian Redl539c5062010-08-18 23:57:32 +0000581 Code = serialization::DECL_OBJC_METHOD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000582}
583
Douglas Gregor85f3f952015-07-07 03:57:15 +0000584void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
585 VisitTypedefNameDecl(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +0000586 Record.push_back(D->Variance);
Douglas Gregore83b9562015-07-07 03:57:53 +0000587 Record.push_back(D->Index);
Douglas Gregor1ac1b632015-07-07 03:58:54 +0000588 Writer.AddSourceLocation(D->VarianceLoc, Record);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000589 Writer.AddSourceLocation(D->ColonLoc, Record);
590
591 Code = serialization::DECL_OBJC_TYPE_PARAM;
592}
593
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000594void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000595 VisitNamedDecl(D);
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +0000596 Writer.AddSourceLocation(D->getAtStartLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +0000597 Writer.AddSourceRange(D->getAtEndRange(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000598 // Abstract class (no need to define a stable serialization::DECL code).
Chris Lattner7099dbc2009-04-27 06:16:06 +0000599}
600
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000601void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
Douglas Gregor66b310c2011-12-15 18:03:09 +0000602 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000603 VisitObjCContainerDecl(D);
604 Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000605 AddObjCTypeParamList(D->TypeParamList);
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000606
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000607 Record.push_back(D->isThisDeclarationADefinition());
608 if (D->isThisDeclarationADefinition()) {
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000609 // Write the DefinitionData
610 ObjCInterfaceDecl::DefinitionData &Data = D->data();
611
Douglas Gregore9d95f12015-07-07 03:57:35 +0000612 Writer.AddTypeSourceInfo(D->getSuperClassTInfo(), Record);
Douglas Gregor16408322011-12-15 22:34:59 +0000613 Writer.AddSourceLocation(D->getEndOfDefinitionLoc(), Record);
Argyrios Kyrtzidis9ed9e5f2013-12-03 21:11:30 +0000614 Record.push_back(Data.HasDesignatedInitializers);
Douglas Gregor16408322011-12-15 22:34:59 +0000615
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000616 // Write out the protocols that are directly referenced by the @interface.
617 Record.push_back(Data.ReferencedProtocols.size());
Aaron Ballmana49c5062014-03-13 20:29:09 +0000618 for (const auto *P : D->protocols())
619 Writer.AddDeclRef(P, Record);
Aaron Ballmane9378882014-03-13 20:34:24 +0000620 for (const auto &PL : D->protocol_locs())
621 Writer.AddSourceLocation(PL, Record);
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000622
623 // Write out the protocols that are transitively referenced.
624 Record.push_back(Data.AllReferencedProtocols.size());
625 for (ObjCList<ObjCProtocolDecl>::iterator
626 P = Data.AllReferencedProtocols.begin(),
627 PEnd = Data.AllReferencedProtocols.end();
628 P != PEnd; ++P)
629 Writer.AddDeclRef(*P, Record);
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000630
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000631
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000632 if (ObjCCategoryDecl *Cat = D->getCategoryListRaw()) {
Douglas Gregor404cdde2012-01-27 01:47:08 +0000633 // Ensure that we write out the set of categories for this class.
634 Writer.ObjCClassesWithCategories.insert(D);
635
636 // Make sure that the categories get serialized.
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000637 for (; Cat; Cat = Cat->getNextClassCategoryRaw())
Douglas Gregor404cdde2012-01-27 01:47:08 +0000638 (void)Writer.GetDeclRef(Cat);
639 }
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000640 }
641
Sebastian Redl539c5062010-08-18 23:57:32 +0000642 Code = serialization::DECL_OBJC_INTERFACE;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000643}
644
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000645void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000646 VisitFieldDecl(D);
647 // FIXME: stable encoding for @public/@private/@protected/@package
Mike Stump11289f42009-09-09 15:08:12 +0000648 Record.push_back(D->getAccessControl());
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000649 Record.push_back(D->getSynthesize());
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000650
651 if (!D->hasAttrs() &&
652 !D->isImplicit() &&
653 !D->isUsed(false) &&
654 !D->isInvalidDecl() &&
655 !D->isReferenced() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000656 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000657 !D->getBitWidth() &&
658 !D->hasExtInfo() &&
659 D->getDeclName())
660 AbbrevToUse = Writer.getDeclObjCIvarAbbrev();
661
Sebastian Redl539c5062010-08-18 23:57:32 +0000662 Code = serialization::DECL_OBJC_IVAR;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000663}
664
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000665void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
Douglas Gregora715bff2012-01-01 19:51:50 +0000666 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000667 VisitObjCContainerDecl(D);
Douglas Gregore6e48b12012-01-01 19:29:29 +0000668
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000669 Record.push_back(D->isThisDeclarationADefinition());
670 if (D->isThisDeclarationADefinition()) {
Douglas Gregore6e48b12012-01-01 19:29:29 +0000671 Record.push_back(D->protocol_size());
Aaron Ballman0f6e64d2014-03-13 22:58:06 +0000672 for (const auto *I : D->protocols())
673 Writer.AddDeclRef(I, Record);
Aaron Ballmana964ec12014-03-14 12:38:50 +0000674 for (const auto &PL : D->protocol_locs())
675 Writer.AddSourceLocation(PL, Record);
Douglas Gregore6e48b12012-01-01 19:29:29 +0000676 }
677
Sebastian Redl539c5062010-08-18 23:57:32 +0000678 Code = serialization::DECL_OBJC_PROTOCOL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000679}
680
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000681void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000682 VisitFieldDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000683 Code = serialization::DECL_OBJC_AT_DEFS_FIELD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000684}
685
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000686void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000687 VisitObjCContainerDecl(D);
Douglas Gregor404cdde2012-01-27 01:47:08 +0000688 Writer.AddSourceLocation(D->getCategoryNameLoc(), Record);
Fariborz Jahaniana7765fe2012-02-20 20:09:20 +0000689 Writer.AddSourceLocation(D->getIvarLBraceLoc(), Record);
690 Writer.AddSourceLocation(D->getIvarRBraceLoc(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000691 Writer.AddDeclRef(D->getClassInterface(), Record);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000692 AddObjCTypeParamList(D->TypeParamList);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000693 Record.push_back(D->protocol_size());
Aaron Ballman19a41762014-03-14 12:55:57 +0000694 for (const auto *I : D->protocols())
695 Writer.AddDeclRef(I, Record);
Aaron Ballmana73c8572014-03-14 13:03:32 +0000696 for (const auto &PL : D->protocol_locs())
697 Writer.AddSourceLocation(PL, Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000698 Code = serialization::DECL_OBJC_CATEGORY;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000699}
700
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000701void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000702 VisitNamedDecl(D);
703 Writer.AddDeclRef(D->getClassInterface(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000704 Code = serialization::DECL_OBJC_COMPATIBLE_ALIAS;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000705}
706
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000707void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000708 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000709 Writer.AddSourceLocation(D->getAtLoc(), Record);
Fariborz Jahanian86c2f5c2012-02-29 22:18:55 +0000710 Writer.AddSourceLocation(D->getLParenLoc(), Record);
Douglas Gregor813a0662015-06-19 18:14:38 +0000711 Writer.AddTypeRef(D->getType(), Record);
John McCall339bb662010-06-04 20:50:08 +0000712 Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000713 // FIXME: stable encoding
714 Record.push_back((unsigned)D->getPropertyAttributes());
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000715 Record.push_back((unsigned)D->getPropertyAttributesAsWritten());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000716 // FIXME: stable encoding
717 Record.push_back((unsigned)D->getPropertyImplementation());
718 Writer.AddDeclarationName(D->getGetterName(), Record);
719 Writer.AddDeclarationName(D->getSetterName(), Record);
720 Writer.AddDeclRef(D->getGetterMethodDecl(), Record);
721 Writer.AddDeclRef(D->getSetterMethodDecl(), Record);
722 Writer.AddDeclRef(D->getPropertyIvarDecl(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000723 Code = serialization::DECL_OBJC_PROPERTY;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000724}
725
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000726void ASTDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000727 VisitObjCContainerDecl(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000728 Writer.AddDeclRef(D->getClassInterface(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000729 // Abstract class (no need to define a stable serialization::DECL code).
Chris Lattner7099dbc2009-04-27 06:16:06 +0000730}
731
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000732void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000733 VisitObjCImplDecl(D);
734 Writer.AddIdentifierRef(D->getIdentifier(), Record);
Argyrios Kyrtzidis4996f5f2011-12-09 00:31:40 +0000735 Writer.AddSourceLocation(D->getCategoryNameLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000736 Code = serialization::DECL_OBJC_CATEGORY_IMPL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000737}
738
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000739void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000740 VisitObjCImplDecl(D);
741 Writer.AddDeclRef(D->getSuperClass(), Record);
Argyrios Kyrtzidis5d2ce842013-05-03 22:31:26 +0000742 Writer.AddSourceLocation(D->getSuperClassLoc(), Record);
Fariborz Jahaniana7765fe2012-02-20 20:09:20 +0000743 Writer.AddSourceLocation(D->getIvarLBraceLoc(), Record);
744 Writer.AddSourceLocation(D->getIvarRBraceLoc(), Record);
John McCall0d54a172012-10-17 04:53:31 +0000745 Record.push_back(D->hasNonZeroConstructors());
746 Record.push_back(D->hasDestructors());
Richard Smithc2bb8182015-03-24 06:36:48 +0000747 Record.push_back(D->NumIvarInitializers);
748 if (D->NumIvarInitializers)
749 Writer.AddCXXCtorInitializersRef(
750 llvm::makeArrayRef(D->init_begin(), D->init_end()), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000751 Code = serialization::DECL_OBJC_IMPLEMENTATION;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000752}
753
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000754void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000755 VisitDecl(D);
756 Writer.AddSourceLocation(D->getLocStart(), Record);
757 Writer.AddDeclRef(D->getPropertyDecl(), Record);
758 Writer.AddDeclRef(D->getPropertyIvarDecl(), Record);
Douglas Gregorb1b71e52010-11-17 01:03:52 +0000759 Writer.AddSourceLocation(D->getPropertyIvarDeclLoc(), Record);
Argyrios Kyrtzidisa8607772010-08-09 10:54:37 +0000760 Writer.AddStmt(D->getGetterCXXConstructor());
761 Writer.AddStmt(D->getSetterCXXAssignment());
Sebastian Redl539c5062010-08-18 23:57:32 +0000762 Code = serialization::DECL_OBJC_PROPERTY_IMPL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000763}
764
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000765void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000766 VisitDeclaratorDecl(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000767 Record.push_back(D->isMutable());
John McCallc90c1492014-10-10 18:44:34 +0000768 if (D->InitStorage.getInt() == FieldDecl::ISK_BitWidthOrNothing &&
769 D->InitStorage.getPointer() == nullptr) {
770 Record.push_back(0);
771 } else if (D->InitStorage.getInt() == FieldDecl::ISK_CapturedVLAType) {
772 Record.push_back(D->InitStorage.getInt() + 1);
Alexey Bataev39c81e22014-08-28 04:28:19 +0000773 Writer.AddTypeRef(
John McCallc90c1492014-10-10 18:44:34 +0000774 QualType(static_cast<Type *>(D->InitStorage.getPointer()), 0),
Alexey Bataev39c81e22014-08-28 04:28:19 +0000775 Record);
Richard Smith2b013182012-06-10 03:12:00 +0000776 } else {
John McCallc90c1492014-10-10 18:44:34 +0000777 Record.push_back(D->InitStorage.getInt() + 1);
778 Writer.AddStmt(static_cast<Expr *>(D->InitStorage.getPointer()));
Richard Smith2b013182012-06-10 03:12:00 +0000779 }
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000780 if (!D->getDeclName())
781 Writer.AddDeclRef(Context.getInstantiatedFromUnnamedFieldDecl(D), Record);
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000782
783 if (!D->hasAttrs() &&
784 !D->isImplicit() &&
785 !D->isUsed(false) &&
786 !D->isInvalidDecl() &&
787 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000788 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000789 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000790 !D->getBitWidth() &&
Richard Smith938f40b2011-06-11 17:19:42 +0000791 !D->hasInClassInitializer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000792 !D->hasExtInfo() &&
793 !ObjCIvarDecl::classofKind(D->getKind()) &&
794 !ObjCAtDefsFieldDecl::classofKind(D->getKind()) &&
795 D->getDeclName())
796 AbbrevToUse = Writer.getDeclFieldAbbrev();
797
Sebastian Redl539c5062010-08-18 23:57:32 +0000798 Code = serialization::DECL_FIELD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000799}
800
John McCall5e77d762013-04-16 07:28:30 +0000801void ASTDeclWriter::VisitMSPropertyDecl(MSPropertyDecl *D) {
802 VisitDeclaratorDecl(D);
803 Writer.AddIdentifierRef(D->getGetterId(), Record);
804 Writer.AddIdentifierRef(D->getSetterId(), Record);
805 Code = serialization::DECL_MS_PROPERTY;
806}
807
Francois Pichet783dd6e2010-11-21 06:08:52 +0000808void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
809 VisitValueDecl(D);
810 Record.push_back(D->getChainingSize());
811
Aaron Ballman29c94602014-03-07 18:36:15 +0000812 for (const auto *P : D->chain())
Aaron Ballman13916082014-03-07 18:11:58 +0000813 Writer.AddDeclRef(P, Record);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000814 Code = serialization::DECL_INDIRECTFIELD;
815}
816
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000817void ASTDeclWriter::VisitVarDecl(VarDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000818 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000819 VisitDeclaratorDecl(D);
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000820 Record.push_back(D->getStorageClass());
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +0000821 Record.push_back(D->getTSCSpec());
Sebastian Redla9351792012-02-11 23:51:47 +0000822 Record.push_back(D->getInitStyle());
David Majnemerfa7bc782015-05-19 00:57:16 +0000823 if (!isa<ParmVarDecl>(D)) {
824 Record.push_back(D->isExceptionVariable());
825 Record.push_back(D->isNRVOVariable());
826 Record.push_back(D->isCXXForRangeDecl());
827 Record.push_back(D->isARCPseudoStrong());
828 Record.push_back(D->isConstexpr());
829 Record.push_back(D->isInitCapture());
830 Record.push_back(D->isPreviousDeclInSameBlockScope());
831 }
Rafael Espindola3ae00052013-05-13 00:12:11 +0000832 Record.push_back(D->getLinkageInternal());
Douglas Gregor12cda632012-09-20 23:43:29 +0000833
Richard Smithd0b4dd62011-12-19 06:19:21 +0000834 if (D->getInit()) {
835 Record.push_back(!D->isInitKnownICE() ? 1 : (D->isInitICE() ? 3 : 2));
Chris Lattner7099dbc2009-04-27 06:16:06 +0000836 Writer.AddStmt(D->getInit());
Richard Smithd0b4dd62011-12-19 06:19:21 +0000837 } else {
838 Record.push_back(0);
839 }
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000840
841 enum {
842 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
843 };
844 if (VarTemplateDecl *TemplD = D->getDescribedVarTemplate()) {
845 Record.push_back(VarTemplate);
846 Writer.AddDeclRef(TemplD, Record);
847 } else if (MemberSpecializationInfo *SpecInfo
848 = D->getMemberSpecializationInfo()) {
849 Record.push_back(StaticDataMemberSpecialization);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000850 Writer.AddDeclRef(SpecInfo->getInstantiatedFrom(), Record);
851 Record.push_back(SpecInfo->getTemplateSpecializationKind());
852 Writer.AddSourceLocation(SpecInfo->getPointOfInstantiation(), Record);
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000853 } else {
854 Record.push_back(VarNotTemplate);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000855 }
856
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000857 if (!D->hasAttrs() &&
858 !D->isImplicit() &&
859 !D->isUsed(false) &&
860 !D->isInvalidDecl() &&
861 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000862 !D->isTopLevelDeclInObjCContainer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000863 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000864 !D->isModulePrivate() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000865 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000866 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
867 !D->hasExtInfo() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000868 D->getFirstDecl() == D->getMostRecentDecl() &&
Sebastian Redla9351792012-02-11 23:51:47 +0000869 D->getInitStyle() == VarDecl::CInit &&
Craig Toppera13603a2014-05-22 05:54:18 +0000870 D->getInit() == nullptr &&
John McCalld4631322011-06-17 06:42:21 +0000871 !isa<ParmVarDecl>(D) &&
Larisse Voufoa11bd8a2013-08-13 02:02:26 +0000872 !isa<VarTemplateSpecializationDecl>(D) &&
Douglas Gregor12cda632012-09-20 23:43:29 +0000873 !D->isConstexpr() &&
Richard Smithbb13c9a2013-09-28 04:02:39 +0000874 !D->isInitCapture() &&
Richard Smith1c34fb72013-08-13 18:18:50 +0000875 !D->isPreviousDeclInSameBlockScope() &&
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000876 !D->getMemberSpecializationInfo())
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000877 AbbrevToUse = Writer.getDeclVarAbbrev();
878
Sebastian Redl539c5062010-08-18 23:57:32 +0000879 Code = serialization::DECL_VAR;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000880}
881
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000882void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000883 VisitVarDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000884 Code = serialization::DECL_IMPLICIT_PARAM;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000885}
886
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000887void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000888 VisitVarDecl(D);
John McCall82490832011-05-02 00:30:12 +0000889 Record.push_back(D->isObjCMethodParameter());
John McCall8fb0d9d2011-05-01 22:35:37 +0000890 Record.push_back(D->getFunctionScopeDepth());
891 Record.push_back(D->getFunctionScopeIndex());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000892 Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding
John McCall6a014d52011-03-09 04:22:44 +0000893 Record.push_back(D->isKNRPromoted());
John McCallf3cd6652010-03-12 18:31:32 +0000894 Record.push_back(D->hasInheritedDefaultArg());
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000895 Record.push_back(D->hasUninstantiatedDefaultArg());
896 if (D->hasUninstantiatedDefaultArg())
897 Writer.AddStmt(D->getUninstantiatedDefaultArg());
Sebastian Redl539c5062010-08-18 23:57:32 +0000898 Code = serialization::DECL_PARM_VAR;
Mike Stump11289f42009-09-09 15:08:12 +0000899
John McCalld4631322011-06-17 06:42:21 +0000900 assert(!D->isARCPseudoStrong()); // can be true of ImplicitParamDecl
901
Chris Lattner258172e2009-04-27 07:35:58 +0000902 // If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here
903 // we dynamically check for the properties that we optimize for, but don't
904 // know are true of all PARM_VAR_DECLs.
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000905 if (!D->hasAttrs() &&
906 !D->hasExtInfo() &&
Chris Lattner258172e2009-04-27 07:35:58 +0000907 !D->isImplicit() &&
Douglas Gregorebada0772010-06-17 23:14:26 +0000908 !D->isUsed(false) &&
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +0000909 !D->isInvalidDecl() &&
Eli Friedmanc09e0552012-01-13 23:41:25 +0000910 !D->isReferenced() &&
Chris Lattner258172e2009-04-27 07:35:58 +0000911 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000912 !D->isModulePrivate() &&
Chris Lattner258172e2009-04-27 07:35:58 +0000913 D->getStorageClass() == 0 &&
Sebastian Redla9351792012-02-11 23:51:47 +0000914 D->getInitStyle() == VarDecl::CInit && // Can params have anything else?
John McCall82490832011-05-02 00:30:12 +0000915 D->getFunctionScopeDepth() == 0 &&
John McCallf3cd6652010-03-12 18:31:32 +0000916 D->getObjCDeclQualifier() == 0 &&
John McCall6a014d52011-03-09 04:22:44 +0000917 !D->isKNRPromoted() &&
Chris Lattnere2437f42010-05-09 06:40:08 +0000918 !D->hasInheritedDefaultArg() &&
Craig Toppera13603a2014-05-22 05:54:18 +0000919 D->getInit() == nullptr &&
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000920 !D->hasUninstantiatedDefaultArg()) // No default expr.
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000921 AbbrevToUse = Writer.getDeclParmVarAbbrev();
Chris Lattner258172e2009-04-27 07:35:58 +0000922
923 // Check things we know are true of *every* PARM_VAR_DECL, which is more than
924 // just us assuming it.
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +0000925 assert(!D->getTSCSpec() && "PARM_VAR_DECL can't use TLS");
Chris Lattner258172e2009-04-27 07:35:58 +0000926 assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private");
Douglas Gregor3f324d562010-05-03 18:51:14 +0000927 assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var");
Craig Toppera13603a2014-05-22 05:54:18 +0000928 assert(D->getPreviousDecl() == nullptr && "PARM_VAR_DECL can't be redecl");
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000929 assert(!D->isStaticDataMember() &&
930 "PARM_VAR_DECL can't be static data member");
Chris Lattner7099dbc2009-04-27 06:16:06 +0000931}
932
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000933void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000934 VisitDecl(D);
935 Writer.AddStmt(D->getAsmString());
Abramo Bagnara348823a2011-03-03 14:20:18 +0000936 Writer.AddSourceLocation(D->getRParenLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000937 Code = serialization::DECL_FILE_SCOPE_ASM;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000938}
939
Michael Han84324352013-02-22 17:15:32 +0000940void ASTDeclWriter::VisitEmptyDecl(EmptyDecl *D) {
941 VisitDecl(D);
942 Code = serialization::DECL_EMPTY;
943}
944
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000945void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000946 VisitDecl(D);
947 Writer.AddStmt(D->getBody());
John McCalla3ccba02010-06-04 11:21:44 +0000948 Writer.AddTypeSourceInfo(D->getSignatureAsWritten(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000949 Record.push_back(D->param_size());
950 for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end();
951 P != PEnd; ++P)
952 Writer.AddDeclRef(*P, Record);
John McCallcf6ce282012-04-13 17:33:29 +0000953 Record.push_back(D->isVariadic());
954 Record.push_back(D->blockMissingReturnType());
955 Record.push_back(D->isConversionFromLambda());
John McCallc63de662011-02-02 13:00:07 +0000956 Record.push_back(D->capturesCXXThis());
John McCall351762c2011-02-07 10:33:21 +0000957 Record.push_back(D->getNumCaptures());
Aaron Ballman9371dd22014-03-14 18:34:04 +0000958 for (const auto &capture : D->captures()) {
John McCall351762c2011-02-07 10:33:21 +0000959 Writer.AddDeclRef(capture.getVariable(), Record);
960
961 unsigned flags = 0;
962 if (capture.isByRef()) flags |= 1;
963 if (capture.isNested()) flags |= 2;
964 if (capture.hasCopyExpr()) flags |= 4;
965 Record.push_back(flags);
966
967 if (capture.hasCopyExpr()) Writer.AddStmt(capture.getCopyExpr());
968 }
John McCallc63de662011-02-02 13:00:07 +0000969
Sebastian Redl539c5062010-08-18 23:57:32 +0000970 Code = serialization::DECL_BLOCK;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000971}
972
Ben Langmuirce914fc2013-05-03 19:20:19 +0000973void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) {
974 Record.push_back(CD->getNumParams());
975 VisitDecl(CD);
Alexey Bataev9959db52014-05-06 10:08:46 +0000976 Record.push_back(CD->getContextParamPosition());
977 Record.push_back(CD->isNothrow() ? 1 : 0);
Ben Langmuirce914fc2013-05-03 19:20:19 +0000978 // Body is stored by VisitCapturedStmt.
Alexey Bataev9959db52014-05-06 10:08:46 +0000979 for (unsigned I = 0; I < CD->getNumParams(); ++I)
980 Writer.AddDeclRef(CD->getParam(I), Record);
Ben Langmuirce914fc2013-05-03 19:20:19 +0000981 Code = serialization::DECL_CAPTURED;
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +0000982}
983
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000984void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +0000985 VisitDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000986 Record.push_back(D->getLanguage());
Abramo Bagnaraea947882011-03-08 16:41:52 +0000987 Writer.AddSourceLocation(D->getExternLoc(), Record);
Abramo Bagnara4a8cda82011-03-03 14:52:38 +0000988 Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000989 Code = serialization::DECL_LINKAGE_SPEC;
Chris Lattnerca025db2010-05-07 21:43:38 +0000990}
991
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000992void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) {
993 VisitNamedDecl(D);
Abramo Bagnara1c3af962011-03-05 18:21:20 +0000994 Writer.AddSourceLocation(D->getLocStart(), Record);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000995 Code = serialization::DECL_LABEL;
996}
997
998
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000999void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
Douglas Gregore57e7522012-01-07 09:11:48 +00001000 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001001 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +00001002 Record.push_back(D->isInline());
Abramo Bagnarab5545be2011-03-08 12:38:20 +00001003 Writer.AddSourceLocation(D->getLocStart(), Record);
1004 Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001005
Chris Lattnerca025db2010-05-07 21:43:38 +00001006 if (D->isOriginalNamespace())
1007 Writer.AddDeclRef(D->getAnonymousNamespace(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001008 Code = serialization::DECL_NAMESPACE;
Sebastian Redlf03cdc52010-08-05 21:22:19 +00001009
Douglas Gregore57e7522012-01-07 09:11:48 +00001010 if (Writer.hasChain() && D->isAnonymousNamespace() &&
Douglas Gregorec9fd132012-01-14 16:38:05 +00001011 D == D->getMostRecentDecl()) {
Sebastian Redl010288f2011-04-24 16:28:21 +00001012 // This is a most recent reopening of the anonymous namespace. If its parent
1013 // is in a previous PCH (or is the TU), mark that parent for update, because
1014 // the original namespace always points to the latest re-opening of its
1015 // anonymous namespace.
1016 Decl *Parent = cast<Decl>(
1017 D->getParent()->getRedeclContext()->getPrimaryContext());
Douglas Gregorb3722e22011-09-09 23:01:35 +00001018 if (Parent->isFromASTFile() || isa<TranslationUnitDecl>(Parent)) {
Richard Smith6ef42932014-03-20 21:02:00 +00001019 Writer.DeclUpdates[Parent].push_back(
Aaron Ballman4f45b712014-03-21 15:22:56 +00001020 ASTWriter::DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, D));
Sebastian Redlfa1f3702011-04-24 16:28:13 +00001021 }
1022 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001023}
1024
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001025void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Richard Smithf4634362014-09-03 23:11:22 +00001026 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001027 VisitNamedDecl(D);
Douglas Gregorf9e43ce2010-09-01 00:08:19 +00001028 Writer.AddSourceLocation(D->getNamespaceLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001029 Writer.AddSourceLocation(D->getTargetNameLoc(), Record);
Douglas Gregorc05ba2e2011-02-25 17:08:07 +00001030 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001031 Writer.AddDeclRef(D->getNamespace(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001032 Code = serialization::DECL_NAMESPACE_ALIAS;
Chris Lattnerca025db2010-05-07 21:43:38 +00001033}
1034
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001035void ASTDeclWriter::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001036 VisitNamedDecl(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00001037 Writer.AddSourceLocation(D->getUsingLoc(), Record);
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001038 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00001039 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
Benjamin Kramere78f8ee2012-01-07 19:09:05 +00001040 Writer.AddDeclRef(D->FirstUsingShadow.getPointer(), Record);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00001041 Record.push_back(D->hasTypename());
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001042 Writer.AddDeclRef(Context.getInstantiatedFromUsingDecl(D), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001043 Code = serialization::DECL_USING;
Chris Lattnerca025db2010-05-07 21:43:38 +00001044}
1045
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001046void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) {
Richard Smithfd8634a2013-10-23 02:17:46 +00001047 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001048 VisitNamedDecl(D);
1049 Writer.AddDeclRef(D->getTargetDecl(), Record);
Argyrios Kyrtzidis2703beb2010-11-10 05:40:41 +00001050 Writer.AddDeclRef(D->UsingOrNextShadow, Record);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001051 Writer.AddDeclRef(Context.getInstantiatedFromUsingShadowDecl(D), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001052 Code = serialization::DECL_USING_SHADOW;
Chris Lattnerca025db2010-05-07 21:43:38 +00001053}
1054
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001055void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001056 VisitNamedDecl(D);
Douglas Gregor01a430132010-09-01 03:07:18 +00001057 Writer.AddSourceLocation(D->getUsingLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001058 Writer.AddSourceLocation(D->getNamespaceKeyLocation(), Record);
Douglas Gregor12441b32011-02-25 16:33:46 +00001059 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001060 Writer.AddDeclRef(D->getNominatedNamespace(), Record);
1061 Writer.AddDeclRef(dyn_cast<Decl>(D->getCommonAncestor()), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001062 Code = serialization::DECL_USING_DIRECTIVE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001063}
1064
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001065void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001066 VisitValueDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001067 Writer.AddSourceLocation(D->getUsingLoc(), Record);
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001068 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00001069 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001070 Code = serialization::DECL_UNRESOLVED_USING_VALUE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001071}
1072
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001073void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001074 UnresolvedUsingTypenameDecl *D) {
1075 VisitTypeDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001076 Writer.AddSourceLocation(D->getTypenameLoc(), Record);
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001077 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001078 Code = serialization::DECL_UNRESOLVED_USING_TYPENAME;
Chris Lattnerca025db2010-05-07 21:43:38 +00001079}
1080
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001081void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001082 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001083
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001084 enum {
1085 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1086 };
1087 if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) {
1088 Record.push_back(CXXRecTemplate);
1089 Writer.AddDeclRef(TemplD, Record);
1090 } else if (MemberSpecializationInfo *MSInfo
1091 = D->getMemberSpecializationInfo()) {
1092 Record.push_back(CXXRecMemberSpecialization);
1093 Writer.AddDeclRef(MSInfo->getInstantiatedFrom(), Record);
1094 Record.push_back(MSInfo->getTemplateSpecializationKind());
1095 Writer.AddSourceLocation(MSInfo->getPointOfInstantiation(), Record);
1096 } else {
1097 Record.push_back(CXXRecNotTemplate);
1098 }
1099
Richard Smithcd45dbc2014-04-19 03:48:30 +00001100 Record.push_back(D->isThisDeclarationADefinition());
1101 if (D->isThisDeclarationADefinition())
1102 Writer.AddCXXDefinitionData(D, Record);
1103
John McCall6bd2a892013-01-25 22:31:03 +00001104 // Store (what we currently believe to be) the key function to avoid
1105 // deserializing every method so we can compute it.
John McCallf937c022011-10-07 06:10:15 +00001106 if (D->IsCompleteDefinition)
John McCall6bd2a892013-01-25 22:31:03 +00001107 Writer.AddDeclRef(Context.getCurrentKeyFunction(D), Record);
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001108
Sebastian Redl539c5062010-08-18 23:57:32 +00001109 Code = serialization::DECL_CXX_RECORD;
Chris Lattnerca025db2010-05-07 21:43:38 +00001110}
1111
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001112void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001113 VisitFunctionDecl(D);
Argyrios Kyrtzidis3b1a7792012-10-12 05:31:40 +00001114 if (D->isCanonicalDecl()) {
1115 Record.push_back(D->size_overridden_methods());
1116 for (CXXMethodDecl::method_iterator
1117 I = D->begin_overridden_methods(), E = D->end_overridden_methods();
1118 I != E; ++I)
1119 Writer.AddDeclRef(*I, Record);
1120 } else {
1121 // We only need to record overridden methods once for the canonical decl.
1122 Record.push_back(0);
1123 }
Richard Smith01b2cb42014-07-26 06:37:51 +00001124
1125 if (D->getFirstDecl() == D->getMostRecentDecl() &&
1126 !D->isInvalidDecl() &&
1127 !D->hasAttrs() &&
1128 !D->isTopLevelDeclInObjCContainer() &&
1129 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
1130 !D->hasExtInfo() &&
1131 !D->hasInheritedPrototype() &&
1132 D->hasWrittenPrototype())
1133 AbbrevToUse = Writer.getDeclCXXMethodAbbrev();
1134
Sebastian Redl539c5062010-08-18 23:57:32 +00001135 Code = serialization::DECL_CXX_METHOD;
Chris Lattnerca025db2010-05-07 21:43:38 +00001136}
1137
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001138void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001139 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001140
Stephan Tolksdorfa6a08632014-03-27 19:22:19 +00001141 Writer.AddDeclRef(D->getInheritedConstructor(), Record);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001142 Record.push_back(D->IsExplicitSpecified);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001143
Sebastian Redl539c5062010-08-18 23:57:32 +00001144 Code = serialization::DECL_CXX_CONSTRUCTOR;
Chris Lattnerca025db2010-05-07 21:43:38 +00001145}
1146
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001147void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001148 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001149
Richard Smithf8134002015-03-10 01:41:22 +00001150 Writer.AddDeclRef(D->getOperatorDelete(), Record);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001151
Sebastian Redl539c5062010-08-18 23:57:32 +00001152 Code = serialization::DECL_CXX_DESTRUCTOR;
Chris Lattnerca025db2010-05-07 21:43:38 +00001153}
1154
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001155void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001156 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001157 Record.push_back(D->IsExplicitSpecified);
Sebastian Redl539c5062010-08-18 23:57:32 +00001158 Code = serialization::DECL_CXX_CONVERSION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001159}
1160
Douglas Gregorba345522011-12-02 23:23:56 +00001161void ASTDeclWriter::VisitImportDecl(ImportDecl *D) {
1162 VisitDecl(D);
Argyrios Kyrtzidis7b8e5552012-10-03 01:58:45 +00001163 Record.push_back(Writer.getSubmoduleID(D->getImportedModule()));
Douglas Gregorba345522011-12-02 23:23:56 +00001164 ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs();
1165 Record.push_back(!IdentifierLocs.empty());
1166 if (IdentifierLocs.empty()) {
1167 Writer.AddSourceLocation(D->getLocEnd(), Record);
1168 Record.push_back(1);
1169 } else {
1170 for (unsigned I = 0, N = IdentifierLocs.size(); I != N; ++I)
1171 Writer.AddSourceLocation(IdentifierLocs[I], Record);
1172 Record.push_back(IdentifierLocs.size());
1173 }
1174 // Note: the number of source locations must always be the last element in
1175 // the record.
1176 Code = serialization::DECL_IMPORT;
1177}
1178
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001179void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001180 VisitDecl(D);
1181 Writer.AddSourceLocation(D->getColonLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001182 Code = serialization::DECL_ACCESS_SPEC;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001183}
1184
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001185void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) {
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001186 // Record the number of friend type template parameter lists here
1187 // so as to simplify memory allocation during deserialization.
1188 Record.push_back(D->NumTPLists);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001189 VisitDecl(D);
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001190 bool hasFriendDecl = D->Friend.is<NamedDecl*>();
1191 Record.push_back(hasFriendDecl);
1192 if (hasFriendDecl)
1193 Writer.AddDeclRef(D->getFriendDecl(), Record);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001194 else
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001195 Writer.AddTypeSourceInfo(D->getFriendType(), Record);
1196 for (unsigned i = 0; i < D->NumTPLists; ++i)
1197 Writer.AddTemplateParameterList(D->getFriendTypeTemplateParameterList(i),
1198 Record);
Douglas Gregore0fb32c2010-10-27 20:23:41 +00001199 Writer.AddDeclRef(D->getNextFriend(), Record);
John McCall2c2eb122010-10-16 06:59:13 +00001200 Record.push_back(D->UnsupportedFriend);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001201 Writer.AddSourceLocation(D->FriendLoc, Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001202 Code = serialization::DECL_FRIEND;
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001203}
1204
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001205void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001206 VisitDecl(D);
1207 Record.push_back(D->getNumTemplateParameters());
1208 for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i)
1209 Writer.AddTemplateParameterList(D->getTemplateParameterList(i), Record);
Craig Toppera13603a2014-05-22 05:54:18 +00001210 Record.push_back(D->getFriendDecl() != nullptr);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001211 if (D->getFriendDecl())
1212 Writer.AddDeclRef(D->getFriendDecl(), Record);
1213 else
1214 Writer.AddTypeSourceInfo(D->getFriendType(), Record);
1215 Writer.AddSourceLocation(D->getFriendLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001216 Code = serialization::DECL_FRIEND_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001217}
1218
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001219void ASTDeclWriter::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001220 VisitNamedDecl(D);
1221
1222 Writer.AddDeclRef(D->getTemplatedDecl(), Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001223 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001224}
1225
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001226void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Douglas Gregor68444de2012-01-14 15:13:49 +00001227 VisitRedeclarable(D);
1228
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001229 // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that
1230 // getCommonPtr() can be used while this is still initializing.
Rafael Espindola8db352d2013-10-17 15:37:26 +00001231 if (D->isFirstDecl()) {
Douglas Gregor074a4092011-12-19 18:19:24 +00001232 // This declaration owns the 'common' pointer, so serialize that data now.
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001233 Writer.AddDeclRef(D->getInstantiatedFromMemberTemplate(), Record);
1234 if (D->getInstantiatedFromMemberTemplate())
1235 Record.push_back(D->isMemberSpecialization());
Douglas Gregor074a4092011-12-19 18:19:24 +00001236 }
1237
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001238 VisitTemplateDecl(D);
1239 Record.push_back(D->getIdentifierNamespace());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001240}
1241
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001242void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001243 VisitRedeclarableTemplateDecl(D);
1244
Richard Smith509fc852015-02-27 23:05:10 +00001245 if (D->isFirstDecl())
1246 AddTemplateSpecializations(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001247 Code = serialization::DECL_CLASS_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001248}
1249
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001250void ASTDeclWriter::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001251 ClassTemplateSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001252 VisitCXXRecordDecl(D);
1253
1254 llvm::PointerUnion<ClassTemplateDecl *,
1255 ClassTemplatePartialSpecializationDecl *> InstFrom
1256 = D->getSpecializedTemplateOrPartial();
Argyrios Kyrtzidisd5553f12011-08-17 21:35:28 +00001257 if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) {
Sebastian Redl401b39a2010-08-24 22:50:24 +00001258 Writer.AddDeclRef(InstFromD, Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001259 } else {
Argyrios Kyrtzidisd5553f12011-08-17 21:35:28 +00001260 Writer.AddDeclRef(InstFrom.get<ClassTemplatePartialSpecializationDecl *>(),
1261 Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001262 Writer.AddTemplateArgumentList(&D->getTemplateInstantiationArgs(), Record);
1263 }
1264
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001265 Writer.AddTemplateArgumentList(&D->getTemplateArgs(), Record);
1266 Writer.AddSourceLocation(D->getPointOfInstantiation(), Record);
1267 Record.push_back(D->getSpecializationKind());
Axel Naumanna31dee22012-10-01 07:34:47 +00001268 Record.push_back(D->isCanonicalDecl());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001269
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001270 if (D->isCanonicalDecl()) {
1271 // When reading, we'll add it to the folding set of the following template.
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001272 Writer.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl(), Record);
1273 }
1274
Richard Smithd55889a2013-09-09 16:55:27 +00001275 // Explicit info.
1276 Writer.AddTypeSourceInfo(D->getTypeAsWritten(), Record);
1277 if (D->getTypeAsWritten()) {
1278 Writer.AddSourceLocation(D->getExternLoc(), Record);
1279 Writer.AddSourceLocation(D->getTemplateKeywordLoc(), Record);
1280 }
1281
Sebastian Redl539c5062010-08-18 23:57:32 +00001282 Code = serialization::DECL_CLASS_TEMPLATE_SPECIALIZATION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001283}
1284
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001285void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001286 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001287 VisitClassTemplateSpecializationDecl(D);
1288
1289 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
Enea Zaffanella6dbe1872013-08-10 07:24:53 +00001290 Writer.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten(), Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001291
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001292 // These are read/set from/to the first declaration.
Craig Toppera13603a2014-05-22 05:54:18 +00001293 if (D->getPreviousDecl() == nullptr) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001294 Writer.AddDeclRef(D->getInstantiatedFromMember(), Record);
1295 Record.push_back(D->isMemberSpecialization());
1296 }
1297
Sebastian Redl539c5062010-08-18 23:57:32 +00001298 Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001299}
1300
Larisse Voufo39a1e502013-08-06 01:03:05 +00001301void ASTDeclWriter::VisitVarTemplateDecl(VarTemplateDecl *D) {
1302 VisitRedeclarableTemplateDecl(D);
1303
Richard Smith509fc852015-02-27 23:05:10 +00001304 if (D->isFirstDecl())
1305 AddTemplateSpecializations(D);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001306 Code = serialization::DECL_VAR_TEMPLATE;
1307}
1308
1309void ASTDeclWriter::VisitVarTemplateSpecializationDecl(
1310 VarTemplateSpecializationDecl *D) {
1311 VisitVarDecl(D);
1312
1313 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
1314 InstFrom = D->getSpecializedTemplateOrPartial();
1315 if (Decl *InstFromD = InstFrom.dyn_cast<VarTemplateDecl *>()) {
1316 Writer.AddDeclRef(InstFromD, Record);
1317 } else {
1318 Writer.AddDeclRef(InstFrom.get<VarTemplatePartialSpecializationDecl *>(),
1319 Record);
1320 Writer.AddTemplateArgumentList(&D->getTemplateInstantiationArgs(), Record);
1321 }
1322
1323 // Explicit info.
1324 Writer.AddTypeSourceInfo(D->getTypeAsWritten(), Record);
1325 if (D->getTypeAsWritten()) {
1326 Writer.AddSourceLocation(D->getExternLoc(), Record);
1327 Writer.AddSourceLocation(D->getTemplateKeywordLoc(), Record);
1328 }
1329
1330 Writer.AddTemplateArgumentList(&D->getTemplateArgs(), Record);
1331 Writer.AddSourceLocation(D->getPointOfInstantiation(), Record);
1332 Record.push_back(D->getSpecializationKind());
1333 Record.push_back(D->isCanonicalDecl());
1334
1335 if (D->isCanonicalDecl()) {
1336 // When reading, we'll add it to the folding set of the following template.
1337 Writer.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl(), Record);
1338 }
1339
1340 Code = serialization::DECL_VAR_TEMPLATE_SPECIALIZATION;
1341}
1342
1343void ASTDeclWriter::VisitVarTemplatePartialSpecializationDecl(
1344 VarTemplatePartialSpecializationDecl *D) {
1345 VisitVarTemplateSpecializationDecl(D);
1346
1347 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
Enea Zaffanella6dbe1872013-08-10 07:24:53 +00001348 Writer.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten(), Record);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001349
1350 // These are read/set from/to the first declaration.
Craig Toppera13603a2014-05-22 05:54:18 +00001351 if (D->getPreviousDecl() == nullptr) {
Larisse Voufo39a1e502013-08-06 01:03:05 +00001352 Writer.AddDeclRef(D->getInstantiatedFromMember(), Record);
1353 Record.push_back(D->isMemberSpecialization());
1354 }
1355
1356 Code = serialization::DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION;
1357}
1358
Fariborz Jahanian3a039e32011-08-27 20:50:59 +00001359void ASTDeclWriter::VisitClassScopeFunctionSpecializationDecl(
1360 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichet09af8c32011-08-17 01:06:54 +00001361 VisitDecl(D);
1362 Writer.AddDeclRef(D->getSpecialization(), Record);
1363 Code = serialization::DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION;
1364}
1365
1366
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001367void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001368 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001369
Richard Smith509fc852015-02-27 23:05:10 +00001370 if (D->isFirstDecl())
1371 AddTemplateSpecializations(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001372 Code = serialization::DECL_FUNCTION_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001373}
1374
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001375void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001376 VisitTypeDecl(D);
1377
1378 Record.push_back(D->wasDeclaredWithTypename());
Richard Smith8346e522015-06-10 01:47:58 +00001379
1380 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1381 !D->defaultArgumentWasInherited();
1382 Record.push_back(OwnsDefaultArg);
1383 if (OwnsDefaultArg)
Richard Smith1469b912015-06-10 00:29:03 +00001384 Writer.AddTypeSourceInfo(D->getDefaultArgumentInfo(), Record);
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001385
Sebastian Redl539c5062010-08-18 23:57:32 +00001386 Code = serialization::DECL_TEMPLATE_TYPE_PARM;
Chris Lattnerca025db2010-05-07 21:43:38 +00001387}
1388
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001389void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001390 // For an expanded parameter pack, record the number of expansion types here
Richard Smith1fde8ec2012-09-07 02:06:42 +00001391 // so that it's easier for deserialization to allocate the right amount of
1392 // memory.
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001393 if (D->isExpandedParameterPack())
1394 Record.push_back(D->getNumExpansionTypes());
1395
John McCallf4cd4f92011-02-09 01:13:10 +00001396 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001397 // TemplateParmPosition.
1398 Record.push_back(D->getDepth());
1399 Record.push_back(D->getPosition());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001400
1401 if (D->isExpandedParameterPack()) {
1402 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
1403 Writer.AddTypeRef(D->getExpansionType(I), Record);
1404 Writer.AddTypeSourceInfo(D->getExpansionTypeSourceInfo(I), Record);
1405 }
1406
1407 Code = serialization::DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK;
1408 } else {
1409 // Rest of NonTypeTemplateParmDecl.
1410 Record.push_back(D->isParameterPack());
Richard Smith8346e522015-06-10 01:47:58 +00001411 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1412 !D->defaultArgumentWasInherited();
1413 Record.push_back(OwnsDefaultArg);
1414 if (OwnsDefaultArg)
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001415 Writer.AddStmt(D->getDefaultArgument());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001416 Code = serialization::DECL_NON_TYPE_TEMPLATE_PARM;
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001417 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001418}
1419
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001420void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Richard Smith1fde8ec2012-09-07 02:06:42 +00001421 // For an expanded parameter pack, record the number of expansion types here
1422 // so that it's easier for deserialization to allocate the right amount of
1423 // memory.
1424 if (D->isExpandedParameterPack())
1425 Record.push_back(D->getNumExpansionTemplateParameters());
1426
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001427 VisitTemplateDecl(D);
1428 // TemplateParmPosition.
1429 Record.push_back(D->getDepth());
1430 Record.push_back(D->getPosition());
Richard Smith1fde8ec2012-09-07 02:06:42 +00001431
1432 if (D->isExpandedParameterPack()) {
1433 for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
1434 I != N; ++I)
1435 Writer.AddTemplateParameterList(D->getExpansionTemplateParameters(I),
1436 Record);
1437 Code = serialization::DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK;
1438 } else {
1439 // Rest of TemplateTemplateParmDecl.
Richard Smith1fde8ec2012-09-07 02:06:42 +00001440 Record.push_back(D->isParameterPack());
Richard Smith8346e522015-06-10 01:47:58 +00001441 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1442 !D->defaultArgumentWasInherited();
1443 Record.push_back(OwnsDefaultArg);
1444 if (OwnsDefaultArg)
Richard Smith1469b912015-06-10 00:29:03 +00001445 Writer.AddTemplateArgumentLoc(D->getDefaultArgument(), Record);
Richard Smith1fde8ec2012-09-07 02:06:42 +00001446 Code = serialization::DECL_TEMPLATE_TEMPLATE_PARM;
1447 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001448}
1449
Richard Smith3f1b5d02011-05-05 21:57:07 +00001450void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1451 VisitRedeclarableTemplateDecl(D);
1452 Code = serialization::DECL_TYPE_ALIAS_TEMPLATE;
1453}
1454
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001455void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001456 VisitDecl(D);
1457 Writer.AddStmt(D->getAssertExpr());
Richard Smithded9c2e2012-07-11 22:37:56 +00001458 Record.push_back(D->isFailed());
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001459 Writer.AddStmt(D->getMessage());
Abramo Bagnaraea947882011-03-08 16:41:52 +00001460 Writer.AddSourceLocation(D->getRParenLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001461 Code = serialization::DECL_STATIC_ASSERT;
Chris Lattnerca025db2010-05-07 21:43:38 +00001462}
1463
Chris Lattner7099dbc2009-04-27 06:16:06 +00001464/// \brief Emit the DeclContext part of a declaration context decl.
1465///
1466/// \param LexicalOffset the offset at which the DECL_CONTEXT_LEXICAL
1467/// block for this declaration context is stored. May be 0 to indicate
1468/// that there are no declarations stored within this context.
1469///
1470/// \param VisibleOffset the offset at which the DECL_CONTEXT_VISIBLE
1471/// block for this declaration context is stored. May be 0 to indicate
1472/// that there are no declarations visible from this context. Note
1473/// that this value will not be emitted for non-primary declaration
1474/// contexts.
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001475void ASTDeclWriter::VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset,
Chris Lattner7099dbc2009-04-27 06:16:06 +00001476 uint64_t VisibleOffset) {
1477 Record.push_back(LexicalOffset);
1478 Record.push_back(VisibleOffset);
1479}
1480
Richard Smith5fc18a92015-07-12 23:43:21 +00001481/// Determine whether D is the first declaration in its redeclaration chain that
1482/// is not from an AST file.
1483template <typename T>
1484static bool isFirstLocalDecl(Redeclarable<T> *D) {
1485 assert(D && !static_cast<T*>(D)->isFromASTFile());
1486 do
1487 D = D->getPreviousDecl();
1488 while (D && static_cast<T*>(D)->isFromASTFile());
1489 return !D;
1490}
1491
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001492template <typename T>
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001493void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +00001494 T *First = D->getFirstDecl();
Richard Smith5a4737c2015-02-06 02:42:59 +00001495 T *MostRecent = First->getMostRecentDecl();
1496 if (MostRecent != First) {
Douglas Gregorfe732d52013-01-21 16:16:40 +00001497 assert(isRedeclarableDeclKind(static_cast<T *>(D)->getKind()) &&
1498 "Not considered redeclarable?");
Richard Smith5a4737c2015-02-06 02:42:59 +00001499
Richard Smithfe620d22015-03-05 23:24:12 +00001500 Writer.AddDeclRef(First, Record);
Richard Smithfe620d22015-03-05 23:24:12 +00001501
Richard Smith5fc18a92015-07-12 23:43:21 +00001502 // In a modules build, emit a list of all imported key declarations
1503 // (excluding First, if it was imported), so that we can be sure that all
1504 // redeclarations visible to this module are before D in the redecl chain.
1505 unsigned I = Record.size();
1506 Record.push_back(0);
Richard Smithfe620d22015-03-05 23:24:12 +00001507 if (Context.getLangOpts().Modules && Writer.Chain) {
Richard Smith5fc18a92015-07-12 23:43:21 +00001508 if (isFirstLocalDecl(D)) {
1509 Writer.Chain->forEachImportedKeyDecl(First, [&](const Decl *D) {
1510 if (D != First)
1511 Writer.AddDeclRef(D, Record);
1512 });
1513 Record[I] = Record.size() - I - 1;
1514
1515 // Write a redeclaration chain, attached to the first key decl.
1516 Writer.Redeclarations.push_back(Writer.Chain->getKeyDeclaration(First));
1517 }
1518 } else if (D == First || D->getPreviousDecl()->isFromASTFile()) {
1519 assert(isFirstLocalDecl(D) && "imported decl after local decl");
1520
1521 // Write a redeclaration chain attached to the first decl.
1522 Writer.Redeclarations.push_back(First);
Richard Smithfe620d22015-03-05 23:24:12 +00001523 }
Douglas Gregor358cd442012-01-15 16:58:34 +00001524
1525 // Make sure that we serialize both the previous and the most-recent
1526 // declarations, which (transitively) ensures that all declarations in the
1527 // chain get serialized.
Richard Smith5a4737c2015-02-06 02:42:59 +00001528 //
1529 // FIXME: This is not correct; when we reach an imported declaration we
1530 // won't emit its previous declaration.
Richard Smith5fc18a92015-07-12 23:43:21 +00001531 (void)Writer.GetDeclRef(D->getPreviousDecl());
Richard Smith5a4737c2015-02-06 02:42:59 +00001532 (void)Writer.GetDeclRef(MostRecent);
Douglas Gregor358cd442012-01-15 16:58:34 +00001533 } else {
1534 // We use the sentinel value 0 to indicate an only declaration.
1535 Record.push_back(0);
Douglas Gregor9f562c82011-12-19 15:27:36 +00001536 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001537}
Chris Lattner7099dbc2009-04-27 06:16:06 +00001538
Alexey Bataeva769e072013-03-22 06:34:35 +00001539void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
1540 Record.push_back(D->varlist_size());
1541 VisitDecl(D);
Aaron Ballman2205d2a2014-03-14 15:55:35 +00001542 for (auto *I : D->varlists())
1543 Writer.AddStmt(I);
Alexey Bataeva769e072013-03-22 06:34:35 +00001544 Code = serialization::DECL_OMP_THREADPRIVATE;
1545}
1546
Chris Lattner7099dbc2009-04-27 06:16:06 +00001547//===----------------------------------------------------------------------===//
Sebastian Redl55c0ad52010-08-18 23:56:21 +00001548// ASTWriter Implementation
Chris Lattner7099dbc2009-04-27 06:16:06 +00001549//===----------------------------------------------------------------------===//
1550
Richard Smith01b2cb42014-07-26 06:37:51 +00001551void ASTWriter::WriteDeclAbbrevs() {
Chris Lattner258172e2009-04-27 07:35:58 +00001552 using namespace llvm;
Chris Lattner258172e2009-04-27 07:35:58 +00001553
Douglas Gregor03412ba2011-06-03 02:27:19 +00001554 BitCodeAbbrev *Abv;
1555
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001556 // Abbreviation for DECL_FIELD
1557 Abv = new BitCodeAbbrev();
1558 Abv->Add(BitCodeAbbrevOp(serialization::DECL_FIELD));
1559 // Decl
1560 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
1561 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001562 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001563 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1564 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1565 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1566 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001567 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001568 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001569 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001570 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001571 // NamedDecl
1572 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1573 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001574 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001575 // ValueDecl
1576 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1577 // DeclaratorDecl
1578 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1579 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
1580 // FieldDecl
1581 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
1582 Abv->Add(BitCodeAbbrevOp(0)); //getBitWidth
1583 // Type Source Info
1584 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1585 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1586 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1587 DeclFieldAbbrev = Stream.EmitAbbrev(Abv);
1588
1589 // Abbreviation for DECL_OBJC_IVAR
1590 Abv = new BitCodeAbbrev();
1591 Abv->Add(BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR));
1592 // Decl
1593 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
1594 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001595 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001596 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1597 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1598 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1599 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001600 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001601 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001602 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001603 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001604 // NamedDecl
1605 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1606 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001607 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001608 // ValueDecl
1609 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1610 // DeclaratorDecl
1611 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1612 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
1613 // FieldDecl
1614 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
1615 Abv->Add(BitCodeAbbrevOp(0)); //getBitWidth
1616 // ObjC Ivar
1617 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl
1618 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize
1619 // Type Source Info
1620 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1621 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1622 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1623 DeclObjCIvarAbbrev = Stream.EmitAbbrev(Abv);
1624
1625 // Abbreviation for DECL_ENUM
1626 Abv = new BitCodeAbbrev();
1627 Abv->Add(BitCodeAbbrevOp(serialization::DECL_ENUM));
Douglas Gregor3e300102011-10-26 17:53:41 +00001628 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001629 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Chris Lattner258172e2009-04-27 07:35:58 +00001630 // Decl
1631 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
1632 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001633 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Chris Lattner258172e2009-04-27 07:35:58 +00001634 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1635 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
Douglas Gregorc9c02ed2009-06-19 23:52:42 +00001636 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +00001637 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001638 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Chris Lattner258172e2009-04-27 07:35:58 +00001639 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001640 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001641 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Douglas Gregor03412ba2011-06-03 02:27:19 +00001642 // NamedDecl
1643 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1644 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001645 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001646 // TypeDecl
1647 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1648 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001649 // TagDecl
1650 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
1651 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
John McCallf937c022011-10-07 06:10:15 +00001652 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001653 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +00001654 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
David Blaikiea8d23ce2013-07-14 01:07:41 +00001655 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001656 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Richard Smith70d58502014-08-30 00:04:23 +00001657 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001658 // EnumDecl
1659 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddTypeRef
1660 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IntegerType
1661 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getPromotionType
1662 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumPositiveBits
1663 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumNegativeBits
1664 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScoped
1665 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScopedUsingClassTag
1666 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isFixed
1667 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedMembEnum
1668 // DC
1669 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
1670 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
1671 DeclEnumAbbrev = Stream.EmitAbbrev(Abv);
Mike Stump11289f42009-09-09 15:08:12 +00001672
Douglas Gregor03412ba2011-06-03 02:27:19 +00001673 // Abbreviation for DECL_RECORD
1674 Abv = new BitCodeAbbrev();
1675 Abv->Add(BitCodeAbbrevOp(serialization::DECL_RECORD));
Douglas Gregor3e300102011-10-26 17:53:41 +00001676 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001677 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Douglas Gregor03412ba2011-06-03 02:27:19 +00001678 // Decl
1679 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
1680 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001681 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Douglas Gregor03412ba2011-06-03 02:27:19 +00001682 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1683 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1684 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1685 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001686 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Douglas Gregor03412ba2011-06-03 02:27:19 +00001687 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001688 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001689 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Douglas Gregor03412ba2011-06-03 02:27:19 +00001690 // NamedDecl
1691 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1692 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001693 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Douglas Gregor03412ba2011-06-03 02:27:19 +00001694 // TypeDecl
1695 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1696 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
Douglas Gregor03412ba2011-06-03 02:27:19 +00001697 // TagDecl
1698 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
1699 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
John McCallf937c022011-10-07 06:10:15 +00001700 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
Douglas Gregor03412ba2011-06-03 02:27:19 +00001701 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +00001702 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
David Blaikiea8d23ce2013-07-14 01:07:41 +00001703 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
Douglas Gregor03412ba2011-06-03 02:27:19 +00001704 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Richard Smith70d58502014-08-30 00:04:23 +00001705 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
Douglas Gregor03412ba2011-06-03 02:27:19 +00001706 // RecordDecl
1707 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // FlexibleArrayMember
1708 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // AnonymousStructUnion
1709 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasObjectMember
Fariborz Jahanian78652202013-01-25 23:57:05 +00001710 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasVolatileMember
Douglas Gregor03412ba2011-06-03 02:27:19 +00001711 // DC
1712 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
1713 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
1714 DeclRecordAbbrev = Stream.EmitAbbrev(Abv);
1715
1716 // Abbreviation for DECL_PARM_VAR
1717 Abv = new BitCodeAbbrev();
1718 Abv->Add(BitCodeAbbrevOp(serialization::DECL_PARM_VAR));
Douglas Gregor3e300102011-10-26 17:53:41 +00001719 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001720 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Douglas Gregor03412ba2011-06-03 02:27:19 +00001721 // Decl
1722 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
1723 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001724 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Douglas Gregor03412ba2011-06-03 02:27:19 +00001725 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1726 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1727 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1728 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001729 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Douglas Gregor03412ba2011-06-03 02:27:19 +00001730 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001731 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001732 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Chris Lattner258172e2009-04-27 07:35:58 +00001733 // NamedDecl
1734 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1735 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001736 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Chris Lattner258172e2009-04-27 07:35:58 +00001737 // ValueDecl
1738 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +00001739 // DeclaratorDecl
Abramo Bagnaradff19302011-03-08 08:55:46 +00001740 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00001741 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Chris Lattner258172e2009-04-27 07:35:58 +00001742 // VarDecl
1743 Abv->Add(BitCodeAbbrevOp(0)); // StorageClass
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +00001744 Abv->Add(BitCodeAbbrevOp(0)); // getTSCSpec
Chris Lattner258172e2009-04-27 07:35:58 +00001745 Abv->Add(BitCodeAbbrevOp(0)); // hasCXXDirectInitializer
Richard Smith88581592013-02-12 05:48:23 +00001746 Abv->Add(BitCodeAbbrevOp(0)); // Linkage
Chris Lattner258172e2009-04-27 07:35:58 +00001747 Abv->Add(BitCodeAbbrevOp(0)); // HasInit
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001748 Abv->Add(BitCodeAbbrevOp(0)); // HasMemberSpecializationInfo
Chris Lattner258172e2009-04-27 07:35:58 +00001749 // ParmVarDecl
John McCall82490832011-05-02 00:30:12 +00001750 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsObjCMethodParameter
John McCall8fb0d9d2011-05-01 22:35:37 +00001751 Abv->Add(BitCodeAbbrevOp(0)); // ScopeDepth
1752 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex
Chris Lattner258172e2009-04-27 07:35:58 +00001753 Abv->Add(BitCodeAbbrevOp(0)); // ObjCDeclQualifier
John McCall6a014d52011-03-09 04:22:44 +00001754 Abv->Add(BitCodeAbbrevOp(0)); // KNRPromoted
John McCallf3cd6652010-03-12 18:31:32 +00001755 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedDefaultArg
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +00001756 Abv->Add(BitCodeAbbrevOp(0)); // HasUninstantiatedDefaultArg
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001757 // Type Source Info
1758 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1759 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1760 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1761 DeclParmVarAbbrev = Stream.EmitAbbrev(Abv);
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001762
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00001763 // Abbreviation for DECL_TYPEDEF
Douglas Gregor03412ba2011-06-03 02:27:19 +00001764 Abv = new BitCodeAbbrev();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001765 Abv->Add(BitCodeAbbrevOp(serialization::DECL_TYPEDEF));
Douglas Gregor05f10352011-12-17 23:38:30 +00001766 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001767 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001768 // Decl
1769 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
1770 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001771 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001772 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1773 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
Richard Smith01b2cb42014-07-26 06:37:51 +00001774 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isUsed
1775 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001776 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Richard Smith01b2cb42014-07-26 06:37:51 +00001777 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001778 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001779 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001780 // NamedDecl
1781 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1782 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001783 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001784 // TypeDecl
1785 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1786 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
1787 // TypedefDecl
1788 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1789 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1790 DeclTypedefAbbrev = Stream.EmitAbbrev(Abv);
1791
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00001792 // Abbreviation for DECL_VAR
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001793 Abv = new BitCodeAbbrev();
1794 Abv->Add(BitCodeAbbrevOp(serialization::DECL_VAR));
Douglas Gregor3e300102011-10-26 17:53:41 +00001795 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001796 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001797 // Decl
1798 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
1799 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001800 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001801 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1802 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1803 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1804 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001805 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001806 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001807 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001808 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001809 // NamedDecl
1810 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1811 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001812 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001813 // ValueDecl
1814 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1815 // DeclaratorDecl
1816 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1817 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
1818 // VarDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001819 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // StorageClass
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +00001820 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // getTSCSpec
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001821 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // CXXDirectInitializer
1822 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isExceptionVariable
1823 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isNRVOVariable
1824 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCXXForRangeDecl
John McCalld4631322011-06-17 06:42:21 +00001825 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong
Douglas Gregor12cda632012-09-20 23:43:29 +00001826 Abv->Add(BitCodeAbbrevOp(0)); // isConstexpr
Richard Smithbb13c9a2013-09-28 04:02:39 +00001827 Abv->Add(BitCodeAbbrevOp(0)); // isInitCapture
Richard Smith1c34fb72013-08-13 18:18:50 +00001828 Abv->Add(BitCodeAbbrevOp(0)); // isPrevDeclInSameScope
Rafael Espindola50df3a02013-05-25 17:16:20 +00001829 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001830 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasInit
1831 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasMemberSpecInfo
1832 // Type Source Info
1833 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1834 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1835 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1836 DeclVarAbbrev = Stream.EmitAbbrev(Abv);
1837
Richard Smith01b2cb42014-07-26 06:37:51 +00001838 // Abbreviation for DECL_CXX_METHOD
1839 Abv = new BitCodeAbbrev();
1840 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CXX_METHOD));
1841 // RedeclarableDecl
1842 Abv->Add(BitCodeAbbrevOp(0)); // CanonicalDecl
1843 // Decl
1844 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
1845 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
1846 Abv->Add(BitCodeAbbrevOp(0)); // Invalid
1847 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1848 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Implicit
1849 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Used
1850 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Referenced
1851 Abv->Add(BitCodeAbbrevOp(0)); // InObjCContainer
1852 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Access
1853 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ModulePrivate
1854 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
1855 // NamedDecl
1856 Abv->Add(BitCodeAbbrevOp(DeclarationName::Identifier)); // NameKind
1857 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Identifier
Richard Smith2b560572015-02-07 03:11:11 +00001858 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Richard Smith01b2cb42014-07-26 06:37:51 +00001859 // ValueDecl
1860 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1861 // DeclaratorDecl
1862 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerLocStart
1863 Abv->Add(BitCodeAbbrevOp(0)); // HasExtInfo
1864 // FunctionDecl
1865 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS
1866 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // StorageClass
1867 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Inline
1868 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InlineSpecified
1869 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // VirtualAsWritten
1870 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Pure
1871 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedProto
1872 Abv->Add(BitCodeAbbrevOp(1)); // HasWrittenProto
Richard Smith72625c22015-02-06 23:20:21 +00001873 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Deleted
Richard Smith01b2cb42014-07-26 06:37:51 +00001874 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Trivial
1875 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Defaulted
1876 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ExplicitlyDefaulted
1877 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ImplicitReturnZero
1878 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Constexpr
1879 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // SkippedBody
1880 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // LateParsed
1881 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
1882 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LocEnd
1883 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // TemplateKind
1884 // This Array slurps the rest of the record. Fortunately we want to encode
1885 // (nearly) all the remaining (variable number of) fields in the same way.
1886 //
1887 // This is the function template information if any, then
1888 // NumParams and Params[] from FunctionDecl, and
1889 // NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl.
1890 //
1891 // Add an AbbrevOp for 'size then elements' and use it here.
1892 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1893 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1894 DeclCXXMethodAbbrev = Stream.EmitAbbrev(Abv);
1895
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00001896 // Abbreviation for EXPR_DECL_REF
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001897 Abv = new BitCodeAbbrev();
Douglas Gregor03412ba2011-06-03 02:27:19 +00001898 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_DECL_REF));
1899 //Stmt
1900 //Expr
1901 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00001902 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
1903 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
1904 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00001905 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
1906 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
1907 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
1908 //DeclRefExpr
1909 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HasQualifier
1910 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //GetDeclFound
1911 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ExplicitTemplateArgs
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00001912 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HadMultipleCandidates
Alexey Bataev19acc3d2015-01-12 10:17:46 +00001913 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
1914 1)); // RefersToEnclosingVariableOrCapture
Douglas Gregor03412ba2011-06-03 02:27:19 +00001915 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef
1916 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
1917 DeclRefExprAbbrev = Stream.EmitAbbrev(Abv);
1918
1919 // Abbreviation for EXPR_INTEGER_LITERAL
1920 Abv = new BitCodeAbbrev();
1921 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL));
1922 //Stmt
1923 //Expr
1924 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00001925 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
1926 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
1927 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00001928 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
1929 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
1930 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
1931 //Integer Literal
1932 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
1933 Abv->Add(BitCodeAbbrevOp(32)); // Bit Width
1934 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value
1935 IntegerLiteralAbbrev = Stream.EmitAbbrev(Abv);
1936
1937 // Abbreviation for EXPR_CHARACTER_LITERAL
1938 Abv = new BitCodeAbbrev();
1939 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL));
1940 //Stmt
1941 //Expr
1942 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00001943 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
1944 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
1945 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00001946 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
1947 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
1948 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
Jonathan D. Turnerd09655f2011-06-03 21:46:44 +00001949 //Character Literal
Douglas Gregor03412ba2011-06-03 02:27:19 +00001950 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue
1951 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
Eli Friedman21530f72012-09-14 00:51:36 +00001952 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // getKind
Douglas Gregor03412ba2011-06-03 02:27:19 +00001953 CharacterLiteralAbbrev = Stream.EmitAbbrev(Abv);
1954
Richard Smitha27c26e2014-07-27 04:19:32 +00001955 // Abbreviation for EXPR_IMPLICIT_CAST
1956 Abv = new BitCodeAbbrev();
1957 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_IMPLICIT_CAST));
1958 // Stmt
1959 // Expr
1960 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1961 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
1962 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
1963 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
1964 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
1965 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
1966 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
1967 // CastExpr
1968 Abv->Add(BitCodeAbbrevOp(0)); // PathSize
1969 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 6)); // CastKind
1970 // ImplicitCastExpr
1971 ExprImplicitCastAbbrev = Stream.EmitAbbrev(Abv);
1972
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001973 Abv = new BitCodeAbbrev();
Sebastian Redl539c5062010-08-18 23:57:32 +00001974 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL));
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001975 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
1976 DeclContextLexicalAbbrev = Stream.EmitAbbrev(Abv);
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00001977
1978 Abv = new BitCodeAbbrev();
1979 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE));
1980 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
1981 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
1982 DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(Abv);
Chris Lattner258172e2009-04-27 07:35:58 +00001983}
1984
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00001985/// isRequiredDecl - Check if this is a "required" Decl, which must be seen by
1986/// consumers of the AST.
1987///
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001988/// Such decls will always be deserialized from the AST file, so we would like
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00001989/// this to be as restrictive as possible. Currently the predicate is driven by
1990/// code generation requirements, if other clients have a different notion of
1991/// what is "required" then we may have to consider an alternate scheme where
1992/// clients can iterate over the top-level decls and get information on them,
1993/// without necessary deserializing them. We could explicitly require such
1994/// clients to use a separate API call to "realize" the decl. This should be
1995/// relatively painless since they would presumably only do it for top-level
1996/// decls.
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00001997static bool isRequiredDecl(const Decl *D, ASTContext &Context) {
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00001998 // An ObjCMethodDecl is never considered as "required" because its
1999 // implementation container always is.
2000
Ben Langmuir332aafe2014-01-31 01:06:56 +00002001 // File scoped assembly or obj-c implementation must be seen. ImportDecl is
2002 // used by codegen to determine the set of imported modules to search for
2003 // inputs for automatic linking.
2004 if (isa<FileScopeAsmDecl>(D) || isa<ObjCImplDecl>(D) || isa<ImportDecl>(D))
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002005 return true;
2006
Argyrios Kyrtzidisc9049332010-07-29 20:08:05 +00002007 return Context.DeclMustBeEmitted(D);
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002008}
2009
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002010void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) {
Argyrios Kyrtzidisd9f526f2010-10-28 09:29:32 +00002011 // Switch case IDs are per Decl.
2012 ClearSwitchCaseIDs();
2013
Chris Lattner7099dbc2009-04-27 06:16:06 +00002014 RecordData Record;
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002015 ASTDeclWriter W(*this, Context, Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +00002016
Douglas Gregorb3163e52012-01-05 22:33:30 +00002017 // Determine the ID for this declaration.
2018 serialization::DeclID ID;
Richard Smith5a4737c2015-02-06 02:42:59 +00002019 if (D->isFromASTFile()) {
2020 assert(isRewritten(D) && "should not be emitting imported decl");
Douglas Gregorb3163e52012-01-05 22:33:30 +00002021 ID = getDeclID(D);
Richard Smith5a4737c2015-02-06 02:42:59 +00002022 } else {
Douglas Gregorb3163e52012-01-05 22:33:30 +00002023 serialization::DeclID &IDR = DeclIDs[D];
2024 if (IDR == 0)
2025 IDR = NextDeclID++;
2026
2027 ID= IDR;
2028 }
Argyrios Kyrtzidisbf6c3392012-03-22 16:08:04 +00002029
2030 bool isReplacingADecl = ID < FirstDeclID;
2031
2032 // If this declaration is also a DeclContext, write blocks for the
2033 // declarations that lexically stored inside its context and those
2034 // declarations that are visible from its context. These blocks
2035 // are written before the declaration itself so that we can put
2036 // their offsets into the record for the declaration.
2037 uint64_t LexicalOffset = 0;
2038 uint64_t VisibleOffset = 0;
2039 DeclContext *DC = dyn_cast<DeclContext>(D);
2040 if (DC) {
2041 if (isReplacingADecl) {
2042 // It is replacing a decl from a chained PCH; make sure that the
2043 // DeclContext is fully loaded.
2044 if (DC->hasExternalLexicalStorage())
2045 DC->LoadLexicalDeclsFromExternalStorage();
2046 if (DC->hasExternalVisibleStorage())
2047 Chain->completeVisibleDeclsMap(DC);
2048 }
2049 LexicalOffset = WriteDeclContextLexicalBlock(Context, DC);
2050 VisibleOffset = WriteDeclContextVisibleBlock(Context, DC);
2051 }
Douglas Gregorb3163e52012-01-05 22:33:30 +00002052
Argyrios Kyrtzidisbf6c3392012-03-22 16:08:04 +00002053 if (isReplacingADecl) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002054 // We're replacing a decl in a previous file.
Argyrios Kyrtzidis6fb60032011-10-31 07:20:15 +00002055 ReplacedDecls.push_back(ReplacedDeclInfo(ID, Stream.GetCurrentBitNo(),
2056 D->getLocation()));
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002057 } else {
2058 unsigned Index = ID - FirstDeclID;
Douglas Gregor12bfa382009-10-17 00:13:19 +00002059
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002060 // Record the offset for this declaration
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +00002061 SourceLocation Loc = D->getLocation();
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002062 if (DeclOffsets.size() == Index)
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +00002063 DeclOffsets.push_back(DeclOffset(Loc, Stream.GetCurrentBitNo()));
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002064 else if (DeclOffsets.size() < Index) {
2065 DeclOffsets.resize(Index+1);
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +00002066 DeclOffsets[Index].setLocation(Loc);
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00002067 DeclOffsets[Index].BitOffset = Stream.GetCurrentBitNo();
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002068 }
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +00002069
2070 SourceManager &SM = Context.getSourceManager();
Argyrios Kyrtzidisdf53da82011-10-28 23:57:43 +00002071 if (Loc.isValid() && SM.isLocalSourceLocation(Loc))
2072 associateDeclWithFile(D, ID);
Douglas Gregor12bfa382009-10-17 00:13:19 +00002073 }
2074
2075 // Build and emit a record for this declaration
2076 Record.clear();
Sebastian Redl539c5062010-08-18 23:57:32 +00002077 W.Code = (serialization::DeclCode)0;
Douglas Gregor12bfa382009-10-17 00:13:19 +00002078 W.AbbrevToUse = 0;
2079 W.Visit(D);
2080 if (DC) W.VisitDeclContext(DC, LexicalOffset, VisibleOffset);
2081
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +00002082 if (!W.Code)
Chris Lattner0e62c1c2011-07-23 10:55:15 +00002083 llvm::report_fatal_error(StringRef("unexpected declaration kind '") +
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +00002084 D->getDeclKindName() + "'");
Douglas Gregor12bfa382009-10-17 00:13:19 +00002085 Stream.EmitRecord(W.Code, Record, W.AbbrevToUse);
2086
Richard Smithc2bb8182015-03-24 06:36:48 +00002087 // Flush any expressions, base specifiers, and ctor initializers that
2088 // were written as part of this declaration.
2089 FlushPendingAfterDecl();
2090
Ben Langmuir332aafe2014-01-31 01:06:56 +00002091 // Note declarations that should be deserialized eagerly so that we can add
2092 // them to a record in the AST file later.
Douglas Gregor12bfa382009-10-17 00:13:19 +00002093 if (isRequiredDecl(D, Context))
Ben Langmuir332aafe2014-01-31 01:06:56 +00002094 EagerlyDeserializedDecls.push_back(ID);
Chris Lattner7099dbc2009-04-27 06:16:06 +00002095}
Richard Smithd28ac5b2014-03-22 23:33:22 +00002096
2097void ASTWriter::AddFunctionDefinition(const FunctionDecl *FD,
2098 RecordData &Record) {
2099 ClearSwitchCaseIDs();
2100
2101 ASTDeclWriter W(*this, FD->getASTContext(), Record);
2102 W.AddFunctionDefinition(FD);
2103}