blob: 1fac13e6eec6879b9215c77960fdd17829f8d4f0 [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 Redlfa1f3702011-04-24 16:28:13 +000014#include "ASTCommon.h"
Chris Lattnerca025db2010-05-07 21:43:38 +000015#include "clang/AST/DeclCXX.h"
Argyrios Kyrtzidis3317d982010-10-20 16:22:56 +000016#include "clang/AST/DeclContextInternals.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "clang/AST/DeclTemplate.h"
18#include "clang/AST/DeclVisitor.h"
19#include "clang/AST/Expr.h"
Jordan Rose1e879d82018-03-23 00:07:18 +000020#include "clang/AST/PrettyDeclStackTrace.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"
Mehdi Amini9670f842016-07-18 19:02:11 +000023#include "clang/Serialization/ASTWriter.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> {
Sebastian Redl55c0ad52010-08-18 23:56:21 +000035 ASTWriter &Writer;
Chris Lattner7099dbc2009-04-27 06:16:06 +000036 ASTContext &Context;
Richard Smith69c82bf2016-04-01 22:52:03 +000037 ASTRecordWriter Record;
Chris Lattner7099dbc2009-04-27 06:16:06 +000038
Sebastian Redl539c5062010-08-18 23:57:32 +000039 serialization::DeclCode Code;
Chris Lattner258172e2009-04-27 07:35:58 +000040 unsigned AbbrevToUse;
Chris Lattner7099dbc2009-04-27 06:16:06 +000041
Richard Smith69c82bf2016-04-01 22:52:03 +000042 public:
43 ASTDeclWriter(ASTWriter &Writer, ASTContext &Context,
44 ASTWriter::RecordDataImpl &Record)
45 : Writer(Writer), Context(Context), Record(Writer, Record),
46 Code((serialization::DeclCode)0), AbbrevToUse(0) {}
47
48 uint64_t Emit(Decl *D) {
49 if (!Code)
50 llvm::report_fatal_error(StringRef("unexpected declaration kind '") +
51 D->getDeclKindName() + "'");
Richard Smith645d2cf2016-04-14 00:29:55 +000052 return Record.Emit(Code, AbbrevToUse);
Chris Lattner258172e2009-04-27 07:35:58 +000053 }
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000054
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +000055 void Visit(Decl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000056
57 void VisitDecl(Decl *D);
Nico Weber66220292016-03-02 17:28:48 +000058 void VisitPragmaCommentDecl(PragmaCommentDecl *D);
Nico Webercbbaeb12016-03-02 19:28:54 +000059 void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000060 void VisitTranslationUnitDecl(TranslationUnitDecl *D);
61 void VisitNamedDecl(NamedDecl *D);
Chris Lattnerc8e630e2011-02-17 07:39:24 +000062 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregore31bbd92010-02-21 18:22:14 +000063 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000064 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
65 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000066 void VisitTypeDecl(TypeDecl *D);
Douglas Gregor1f179062011-12-19 14:40:25 +000067 void VisitTypedefNameDecl(TypedefNameDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000068 void VisitTypedefDecl(TypedefDecl *D);
Richard Smithdda56e42011-04-15 14:24:37 +000069 void VisitTypeAliasDecl(TypeAliasDecl *D);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000070 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000071 void VisitTagDecl(TagDecl *D);
72 void VisitEnumDecl(EnumDecl *D);
73 void VisitRecordDecl(RecordDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000074 void VisitCXXRecordDecl(CXXRecordDecl *D);
75 void VisitClassTemplateSpecializationDecl(
76 ClassTemplateSpecializationDecl *D);
77 void VisitClassTemplatePartialSpecializationDecl(
78 ClassTemplatePartialSpecializationDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +000079 void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D);
80 void VisitVarTemplatePartialSpecializationDecl(
81 VarTemplatePartialSpecializationDecl *D);
Fariborz Jahanian3a039e32011-08-27 20:50:59 +000082 void VisitClassScopeFunctionSpecializationDecl(
83 ClassScopeFunctionSpecializationDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000084 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000085 void VisitValueDecl(ValueDecl *D);
86 void VisitEnumConstantDecl(EnumConstantDecl *D);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000087 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +000088 void VisitDeclaratorDecl(DeclaratorDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000089 void VisitFunctionDecl(FunctionDecl *D);
Richard Smithbc491202017-02-17 20:05:37 +000090 void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000091 void VisitCXXMethodDecl(CXXMethodDecl *D);
92 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
93 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
94 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000095 void VisitFieldDecl(FieldDecl *D);
John McCall5e77d762013-04-16 07:28:30 +000096 void VisitMSPropertyDecl(MSPropertyDecl *D);
Francois Pichet783dd6e2010-11-21 06:08:52 +000097 void VisitIndirectFieldDecl(IndirectFieldDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000098 void VisitVarDecl(VarDecl *D);
99 void VisitImplicitParamDecl(ImplicitParamDecl *D);
100 void VisitParmVarDecl(ParmVarDecl *D);
Richard Smith7b76d812016-08-12 02:21:25 +0000101 void VisitDecompositionDecl(DecompositionDecl *D);
102 void VisitBindingDecl(BindingDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000103 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
104 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000105 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000106 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +0000107 void VisitVarTemplateDecl(VarTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000108 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000109 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3f1b5d02011-05-05 21:57:07 +0000110 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000111 void VisitUsingDecl(UsingDecl *D);
Richard Smith151c4562016-12-20 21:35:28 +0000112 void VisitUsingPackDecl(UsingPackDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000113 void VisitUsingShadowDecl(UsingShadowDecl *D);
Richard Smith5179eb72016-06-28 19:03:57 +0000114 void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000115 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Richard Smith8df390f2016-09-08 23:14:54 +0000116 void VisitExportDecl(ExportDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000117 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
Douglas Gregorba345522011-12-02 23:23:56 +0000118 void VisitImportDecl(ImportDecl *D);
Abramo Bagnarad7340582010-06-05 05:09:32 +0000119 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000120 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000121 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
122 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000123 void VisitBlockDecl(BlockDecl *D);
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +0000124 void VisitCapturedDecl(CapturedDecl *D);
Michael Han84324352013-02-22 17:15:32 +0000125 void VisitEmptyDecl(EmptyDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000126
Richard Smithf1c23dc2016-04-13 02:12:03 +0000127 void VisitDeclContext(DeclContext *DC);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000128 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000129
130
Alexis Hunted053252010-05-30 07:21:58 +0000131 // FIXME: Put in the same order is DeclNodes.td?
Chris Lattner7099dbc2009-04-27 06:16:06 +0000132 void VisitObjCMethodDecl(ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000133 void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000134 void VisitObjCContainerDecl(ObjCContainerDecl *D);
135 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
136 void VisitObjCIvarDecl(ObjCIvarDecl *D);
137 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
138 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000139 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
140 void VisitObjCImplDecl(ObjCImplDecl *D);
141 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
142 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
143 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
144 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
145 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
Alexey Bataeva769e072013-03-22 06:34:35 +0000146 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000147 void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
Alexey Bataev4244be22016-02-11 05:35:55 +0000148 void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
Richard Smithd28ac5b2014-03-22 23:33:22 +0000149
Douglas Gregor85f3f952015-07-07 03:57:15 +0000150 /// Add an Objective-C type parameter list to the given record.
151 void AddObjCTypeParamList(ObjCTypeParamList *typeParams) {
152 // Empty type parameter list.
153 if (!typeParams) {
154 Record.push_back(0);
155 return;
156 }
157
158 Record.push_back(typeParams->size());
159 for (auto typeParam : *typeParams) {
Richard Smith69c82bf2016-04-01 22:52:03 +0000160 Record.AddDeclRef(typeParam);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000161 }
Richard Smith69c82bf2016-04-01 22:52:03 +0000162 Record.AddSourceLocation(typeParams->getLAngleLoc());
163 Record.AddSourceLocation(typeParams->getRAngleLoc());
Douglas Gregor85f3f952015-07-07 03:57:15 +0000164 }
165
Richard Smithd8a83712015-08-22 01:47:18 +0000166 /// Add to the record the first declaration from each module file that
167 /// provides a declaration of D. The intent is to provide a sufficient
168 /// set such that reloading this set will load all current redeclarations.
169 void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) {
170 llvm::MapVector<ModuleFile*, const Decl*> Firsts;
171 // FIXME: We can skip entries that we know are implied by others.
Richard Smith5f55d932015-08-27 21:38:25 +0000172 for (const Decl *R = D->getMostRecentDecl(); R; R = R->getPreviousDecl()) {
173 if (R->isFromASTFile())
Richard Smithd8a83712015-08-22 01:47:18 +0000174 Firsts[Writer.Chain->getOwningModuleFile(R)] = R;
Richard Smith5f55d932015-08-27 21:38:25 +0000175 else if (IncludeLocal)
176 Firsts[nullptr] = R;
177 }
Richard Smithd8a83712015-08-22 01:47:18 +0000178 for (const auto &F : Firsts)
Richard Smith69c82bf2016-04-01 22:52:03 +0000179 Record.AddDeclRef(F.second);
Richard Smithd8a83712015-08-22 01:47:18 +0000180 }
181
Richard Smith509fc852015-02-27 23:05:10 +0000182 /// Get the specialization decl from an entry in the specialization list.
183 template <typename EntryType>
184 typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType *
185 getSpecializationDecl(EntryType &T) {
186 return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T);
187 }
188
189 /// Get the list of partial specializations from a template's common ptr.
190 template<typename T>
191 decltype(T::PartialSpecializations) &getPartialSpecializations(T *Common) {
192 return Common->PartialSpecializations;
193 }
194 ArrayRef<Decl> getPartialSpecializations(FunctionTemplateDecl::Common *) {
195 return None;
196 }
197
Richard Smith8ab0cfd2016-02-24 21:59:10 +0000198 template<typename DeclTy>
199 void AddTemplateSpecializations(DeclTy *D) {
Richard Smith509fc852015-02-27 23:05:10 +0000200 auto *Common = D->getCommonPtr();
201
202 // If we have any lazy specializations, and the external AST source is
203 // our chained AST reader, we can just write out the DeclIDs. Otherwise,
204 // we need to resolve them to actual declarations.
205 if (Writer.Chain != Writer.Context->getExternalSource() &&
206 Common->LazySpecializations) {
207 D->LoadLazySpecializations();
208 assert(!Common->LazySpecializations);
209 }
210
Richard Smith509fc852015-02-27 23:05:10 +0000211 ArrayRef<DeclID> LazySpecializations;
212 if (auto *LS = Common->LazySpecializations)
Craig Topper55e39a72015-09-29 04:53:28 +0000213 LazySpecializations = llvm::makeArrayRef(LS + 1, LS[0]);
Richard Smith509fc852015-02-27 23:05:10 +0000214
Richard Smithd8a83712015-08-22 01:47:18 +0000215 // Add a slot to the record for the number of specializations.
216 unsigned I = Record.size();
217 Record.push_back(0);
218
Richard Smith8ab0cfd2016-02-24 21:59:10 +0000219 // AddFirstDeclFromEachModule might trigger deserialization, invalidating
220 // *Specializations iterators.
221 llvm::SmallVector<const Decl*, 16> Specs;
222 for (auto &Entry : Common->Specializations)
223 Specs.push_back(getSpecializationDecl(Entry));
224 for (auto &Entry : getPartialSpecializations(Common))
225 Specs.push_back(getSpecializationDecl(Entry));
226
227 for (auto *D : Specs) {
Richard Smith509fc852015-02-27 23:05:10 +0000228 assert(D->isCanonicalDecl() && "non-canonical decl in set");
Richard Smithd8a83712015-08-22 01:47:18 +0000229 AddFirstDeclFromEachModule(D, /*IncludeLocal*/true);
Richard Smith509fc852015-02-27 23:05:10 +0000230 }
Benjamin Kramerf367dd92015-06-12 15:31:50 +0000231 Record.append(LazySpecializations.begin(), LazySpecializations.end());
Richard Smithd8a83712015-08-22 01:47:18 +0000232
233 // Update the size entry we added earlier.
234 Record[I] = Record.size() - I - 1;
235 }
236
237 /// Ensure that this template specialization is associated with the specified
238 /// template on reload.
239 void RegisterTemplateSpecialization(const Decl *Template,
240 const Decl *Specialization) {
241 Template = Template->getCanonicalDecl();
242
243 // If the canonical template is local, we'll write out this specialization
244 // when we emit it.
245 // FIXME: We can do the same thing if there is any local declaration of
246 // the template, to avoid emitting an update record.
247 if (!Template->isFromASTFile())
248 return;
249
250 // We only need to associate the first local declaration of the
251 // specialization. The other declarations will get pulled in by it.
252 if (Writer.getFirstLocalDecl(Specialization) != Specialization)
253 return;
254
255 Writer.DeclUpdates[Template].push_back(ASTWriter::DeclUpdate(
256 UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION, Specialization));
Richard Smith509fc852015-02-27 23:05:10 +0000257 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000258 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000259}
Chris Lattner7099dbc2009-04-27 06:16:06 +0000260
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000261void ASTDeclWriter::Visit(Decl *D) {
262 DeclVisitor<ASTDeclWriter>::Visit(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000263
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000264 // Source locations require array (variable-length) abbreviations. The
265 // abbreviation infrastructure requires that arrays are encoded last, so
266 // we handle it here in the case of those classes derived from DeclaratorDecl
Nick Lewycky4b81fc872015-10-18 20:32:12 +0000267 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
Richard Smithc23d7342018-06-29 20:46:25 +0000268 if (auto *TInfo = DD->getTypeSourceInfo())
269 Record.AddTypeLoc(TInfo->getTypeLoc());
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000270 }
271
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000272 // Handle FunctionDecl's body here and write it after all other Stmts/Exprs
273 // have been written. We want it last because we will not read it back when
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000274 // retrieving it from the AST, we'll just lazily set the offset.
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000275 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
Alexis Hunt4a8ea102011-05-06 20:44:56 +0000276 Record.push_back(FD->doesThisDeclarationHaveABody());
277 if (FD->doesThisDeclarationHaveABody())
Richard Smith290d8012016-04-06 17:06:00 +0000278 Record.AddFunctionDefinition(FD);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000279 }
Richard Smithf1c23dc2016-04-13 02:12:03 +0000280
281 // If this declaration is also a DeclContext, write blocks for the
282 // declarations that lexically stored inside its context and those
283 // declarations that are visible from its context.
284 if (DeclContext *DC = dyn_cast<DeclContext>(D))
285 VisitDeclContext(DC);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000286}
287
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000288void ASTDeclWriter::VisitDecl(Decl *D) {
Richard Smith69c82bf2016-04-01 22:52:03 +0000289 Record.AddDeclRef(cast_or_null<Decl>(D->getDeclContext()));
Richard Smith8aed4222015-12-11 22:41:00 +0000290 if (D->getDeclContext() != D->getLexicalDeclContext())
Richard Smith69c82bf2016-04-01 22:52:03 +0000291 Record.AddDeclRef(cast_or_null<Decl>(D->getLexicalDeclContext()));
Richard Smith8aed4222015-12-11 22:41:00 +0000292 else
293 Record.push_back(0);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000294 Record.push_back(D->isInvalidDecl());
295 Record.push_back(D->hasAttrs());
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000296 if (D->hasAttrs())
Richard Smith69c82bf2016-04-01 22:52:03 +0000297 Record.AddAttributes(D->getAttrs());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000298 Record.push_back(D->isImplicit());
Douglas Gregorebada0772010-06-17 23:14:26 +0000299 Record.push_back(D->isUsed(false));
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +0000300 Record.push_back(D->isReferenced());
Douglas Gregor781f7132012-01-06 16:59:53 +0000301 Record.push_back(D->isTopLevelDeclInObjCContainer());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000302 Record.push_back(D->getAccess());
Douglas Gregor781f7132012-01-06 16:59:53 +0000303 Record.push_back(D->isModulePrivate());
Richard Smith54f04402017-05-18 02:29:20 +0000304 Record.push_back(Writer.getSubmoduleID(D->getOwningModule()));
Richard Smithc264d352014-03-23 02:30:01 +0000305
306 // If this declaration injected a name into a context different from its
307 // lexical context, and that context is an imported namespace, we need to
308 // update its visible declarations to include this name.
309 //
310 // This happens when we instantiate a class with a friend declaration or a
311 // function with a local extern declaration, for instance.
Richard Smith5fc18a92015-07-12 23:43:21 +0000312 //
313 // FIXME: Can we handle this in AddedVisibleDecl instead?
Richard Smithc264d352014-03-23 02:30:01 +0000314 if (D->isOutOfLine()) {
Richard Smithe3a97022014-03-23 20:41:56 +0000315 auto *DC = D->getDeclContext();
316 while (auto *NS = dyn_cast<NamespaceDecl>(DC->getRedeclContext())) {
317 if (!NS->isFromASTFile())
318 break;
Chandler Carruth8a3d24d2015-03-26 04:27:10 +0000319 Writer.UpdatedDeclContexts.insert(NS->getPrimaryContext());
Richard Smithe3a97022014-03-23 20:41:56 +0000320 if (!NS->isInlineNamespace())
321 break;
322 DC = NS->getParent();
323 }
Richard Smithc264d352014-03-23 02:30:01 +0000324 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000325}
326
Nico Weber66220292016-03-02 17:28:48 +0000327void ASTDeclWriter::VisitPragmaCommentDecl(PragmaCommentDecl *D) {
328 StringRef Arg = D->getArg();
329 Record.push_back(Arg.size());
330 VisitDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000331 Record.AddSourceLocation(D->getLocStart());
Nico Weber66220292016-03-02 17:28:48 +0000332 Record.push_back(D->getCommentKind());
Richard Smith69c82bf2016-04-01 22:52:03 +0000333 Record.AddString(Arg);
Nico Weber66220292016-03-02 17:28:48 +0000334 Code = serialization::DECL_PRAGMA_COMMENT;
335}
336
Nico Webercbbaeb12016-03-02 19:28:54 +0000337void ASTDeclWriter::VisitPragmaDetectMismatchDecl(
338 PragmaDetectMismatchDecl *D) {
339 StringRef Name = D->getName();
340 StringRef Value = D->getValue();
341 Record.push_back(Name.size() + 1 + Value.size());
342 VisitDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000343 Record.AddSourceLocation(D->getLocStart());
344 Record.AddString(Name);
345 Record.AddString(Value);
Nico Webercbbaeb12016-03-02 19:28:54 +0000346 Code = serialization::DECL_PRAGMA_DETECT_MISMATCH;
347}
348
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000349void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
Douglas Gregordab42432011-08-12 00:15:20 +0000350 llvm_unreachable("Translation units aren't directly serialized");
Chris Lattner7099dbc2009-04-27 06:16:06 +0000351}
352
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000353void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000354 VisitDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000355 Record.AddDeclarationName(D->getDeclName());
Richard Smith2b560572015-02-07 03:11:11 +0000356 Record.push_back(needsAnonymousDeclarationNumber(D)
357 ? Writer.getAnonymousDeclarationNumber(D)
358 : 0);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000359}
360
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000361void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000362 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000363 Record.AddSourceLocation(D->getLocStart());
364 Record.AddTypeRef(QualType(D->getTypeForDecl(), 0));
Chris Lattner7099dbc2009-04-27 06:16:06 +0000365}
366
Douglas Gregor1f179062011-12-19 14:40:25 +0000367void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) {
Douglas Gregor05f10352011-12-17 23:38:30 +0000368 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000369 VisitTypeDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000370 Record.AddTypeSourceInfo(D->getTypeSourceInfo());
Enea Zaffanellaa86d88c2013-06-20 12:46:19 +0000371 Record.push_back(D->isModed());
372 if (D->isModed())
Richard Smith69c82bf2016-04-01 22:52:03 +0000373 Record.AddTypeRef(D->getUnderlyingType());
Richard Smithc0ca4c22017-01-26 22:39:55 +0000374 Record.AddDeclRef(D->getAnonDeclWithTypedefName(false));
Douglas Gregor1f179062011-12-19 14:40:25 +0000375}
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000376
Douglas Gregor1f179062011-12-19 14:40:25 +0000377void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) {
378 VisitTypedefNameDecl(D);
Richard Smith8aed4222015-12-11 22:41:00 +0000379 if (D->getDeclContext() == D->getLexicalDeclContext() &&
380 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000381 !D->isImplicit() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000382 D->getFirstDecl() == D->getMostRecentDecl() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000383 !D->isInvalidDecl() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000384 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000385 !D->isModulePrivate() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000386 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000387 D->getDeclName().getNameKind() == DeclarationName::Identifier)
388 AbbrevToUse = Writer.getDeclTypedefAbbrev();
389
Sebastian Redl539c5062010-08-18 23:57:32 +0000390 Code = serialization::DECL_TYPEDEF;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000391}
392
Richard Smithdda56e42011-04-15 14:24:37 +0000393void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) {
Douglas Gregor1f179062011-12-19 14:40:25 +0000394 VisitTypedefNameDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000395 Record.AddDeclRef(D->getDescribedAliasTemplate());
Richard Smithdda56e42011-04-15 14:24:37 +0000396 Code = serialization::DECL_TYPEALIAS;
397}
398
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000399void ASTDeclWriter::VisitTagDecl(TagDecl *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000400 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000401 VisitTypeDecl(D);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000402 Record.push_back(D->getIdentifierNamespace());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000403 Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding
Richard Smith2c381642014-08-27 23:11:59 +0000404 if (!isa<CXXRecordDecl>(D))
405 Record.push_back(D->isCompleteDefinition());
Douglas Gregor5089c762010-02-12 17:40:34 +0000406 Record.push_back(D->isEmbeddedInDeclarator());
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +0000407 Record.push_back(D->isFreeStanding());
David Blaikiea8d23ce2013-07-14 01:07:41 +0000408 Record.push_back(D->isCompleteDefinitionRequired());
Argyrios Kyrtzidisd798c052016-07-15 18:11:33 +0000409 Record.AddSourceRange(D->getBraceRange());
Richard Smith70d58502014-08-30 00:04:23 +0000410
411 if (D->hasExtInfo()) {
412 Record.push_back(1);
Richard Smith69c82bf2016-04-01 22:52:03 +0000413 Record.AddQualifierInfo(*D->getExtInfo());
Richard Smith70d58502014-08-30 00:04:23 +0000414 } else if (auto *TD = D->getTypedefNameForAnonDecl()) {
415 Record.push_back(2);
Richard Smith69c82bf2016-04-01 22:52:03 +0000416 Record.AddDeclRef(TD);
417 Record.AddIdentifierRef(TD->getDeclName().getAsIdentifierInfo());
Richard Smith70d58502014-08-30 00:04:23 +0000418 } else {
419 Record.push_back(0);
420 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000421}
422
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000423void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000424 VisitTagDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000425 Record.AddTypeSourceInfo(D->getIntegerTypeSourceInfo());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000426 if (!D->getIntegerTypeSourceInfo())
Richard Smith69c82bf2016-04-01 22:52:03 +0000427 Record.AddTypeRef(D->getIntegerType());
428 Record.AddTypeRef(D->getPromotionType());
John McCall9aa35be2010-05-06 08:49:23 +0000429 Record.push_back(D->getNumPositiveBits());
430 Record.push_back(D->getNumNegativeBits());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000431 Record.push_back(D->isScoped());
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000432 Record.push_back(D->isScopedUsingClassTag());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000433 Record.push_back(D->isFixed());
Richard Smith4b38ded2012-03-14 23:13:10 +0000434 if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
Richard Smith69c82bf2016-04-01 22:52:03 +0000435 Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
Richard Smith4b38ded2012-03-14 23:13:10 +0000436 Record.push_back(MemberInfo->getTemplateSpecializationKind());
Richard Smith69c82bf2016-04-01 22:52:03 +0000437 Record.AddSourceLocation(MemberInfo->getPointOfInstantiation());
Richard Smith4b38ded2012-03-14 23:13:10 +0000438 } else {
Richard Smith69c82bf2016-04-01 22:52:03 +0000439 Record.AddDeclRef(nullptr);
Richard Smith4b38ded2012-03-14 23:13:10 +0000440 }
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000441
Richard Smith8aed4222015-12-11 22:41:00 +0000442 if (D->getDeclContext() == D->getLexicalDeclContext() &&
443 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000444 !D->isImplicit() &&
445 !D->isUsed(false) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000446 !D->hasExtInfo() &&
Richard Smith70d58502014-08-30 00:04:23 +0000447 !D->getTypedefNameForAnonDecl() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000448 D->getFirstDecl() == D->getMostRecentDecl() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000449 !D->isInvalidDecl() &&
450 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000451 !D->isTopLevelDeclInObjCContainer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000452 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000453 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000454 !CXXRecordDecl::classofKind(D->getKind()) &&
455 !D->getIntegerTypeSourceInfo() &&
Argyrios Kyrtzidisca370b0d2013-03-18 22:23:49 +0000456 !D->getMemberSpecializationInfo() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000457 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000458 D->getDeclName().getNameKind() == DeclarationName::Identifier)
459 AbbrevToUse = Writer.getDeclEnumAbbrev();
460
Sebastian Redl539c5062010-08-18 23:57:32 +0000461 Code = serialization::DECL_ENUM;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000462}
463
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000464void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000465 VisitTagDecl(D);
466 Record.push_back(D->hasFlexibleArrayMember());
467 Record.push_back(D->isAnonymousStructOrUnion());
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000468 Record.push_back(D->hasObjectMember());
Fariborz Jahanian78652202013-01-25 23:57:05 +0000469 Record.push_back(D->hasVolatileMember());
Akira Hatanaka34fb2642018-03-13 18:58:25 +0000470 Record.push_back(D->isNonTrivialToPrimitiveDefaultInitialize());
471 Record.push_back(D->isNonTrivialToPrimitiveCopy());
472 Record.push_back(D->isNonTrivialToPrimitiveDestroy());
Akira Hatanakafcbe17c2018-03-28 21:13:14 +0000473 Record.push_back(D->isParamDestroyedInCallee());
Akira Hatanakae6313ac2018-04-09 22:48:22 +0000474 Record.push_back(D->getArgPassingRestrictions());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000475
Richard Smith8aed4222015-12-11 22:41:00 +0000476 if (D->getDeclContext() == D->getLexicalDeclContext() &&
477 !D->hasAttrs() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000478 !D->isImplicit() &&
479 !D->isUsed(false) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000480 !D->hasExtInfo() &&
Richard Smith70d58502014-08-30 00:04:23 +0000481 !D->getTypedefNameForAnonDecl() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000482 D->getFirstDecl() == D->getMostRecentDecl() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000483 !D->isInvalidDecl() &&
484 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000485 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000486 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000487 !D->isModulePrivate() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000488 !CXXRecordDecl::classofKind(D->getKind()) &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000489 !needsAnonymousDeclarationNumber(D) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000490 D->getDeclName().getNameKind() == DeclarationName::Identifier)
Douglas Gregor03412ba2011-06-03 02:27:19 +0000491 AbbrevToUse = Writer.getDeclRecordAbbrev();
492
Sebastian Redl539c5062010-08-18 23:57:32 +0000493 Code = serialization::DECL_RECORD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000494}
495
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000496void ASTDeclWriter::VisitValueDecl(ValueDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000497 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000498 Record.AddTypeRef(D->getType());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000499}
500
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000501void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000502 VisitValueDecl(D);
503 Record.push_back(D->getInitExpr()? 1 : 0);
504 if (D->getInitExpr())
Richard Smith290d8012016-04-06 17:06:00 +0000505 Record.AddStmt(D->getInitExpr());
Richard Smith69c82bf2016-04-01 22:52:03 +0000506 Record.AddAPSInt(D->getInitVal());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000507
Sebastian Redl539c5062010-08-18 23:57:32 +0000508 Code = serialization::DECL_ENUM_CONSTANT;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000509}
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000510
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000511void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000512 VisitValueDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000513 Record.AddSourceLocation(D->getInnerLocStart());
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000514 Record.push_back(D->hasExtInfo());
515 if (D->hasExtInfo())
Richard Smith69c82bf2016-04-01 22:52:03 +0000516 Record.AddQualifierInfo(*D->getExtInfo());
Richard Smithc23d7342018-06-29 20:46:25 +0000517 // The location information is deferred until the end of the record.
518 Record.AddTypeRef(D->getTypeSourceInfo() ? D->getTypeSourceInfo()->getType()
519 : QualType());
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000520}
Chris Lattner7099dbc2009-04-27 06:16:06 +0000521
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000522void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000523 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000524 VisitDeclaratorDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000525 Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000526 Record.push_back(D->getIdentifierNamespace());
Douglas Gregorb2585692012-01-04 17:13:46 +0000527
528 // FunctionDecl's body is handled last at ASTWriterDecl::Visit,
529 // after everything else is written.
530
Richard Smith72625c22015-02-06 23:20:21 +0000531 Record.push_back((int)D->SClass); // FIXME: stable encoding
Douglas Gregorb2585692012-01-04 17:13:46 +0000532 Record.push_back(D->IsInline);
Richard Smith72625c22015-02-06 23:20:21 +0000533 Record.push_back(D->IsInlineSpecified);
Richard Smith78e3d702017-02-10 01:32:04 +0000534 Record.push_back(D->IsExplicitSpecified);
Richard Smith72625c22015-02-06 23:20:21 +0000535 Record.push_back(D->IsVirtualAsWritten);
536 Record.push_back(D->IsPure);
537 Record.push_back(D->HasInheritedPrototype);
538 Record.push_back(D->HasWrittenPrototype);
539 Record.push_back(D->IsDeleted);
540 Record.push_back(D->IsTrivial);
Akira Hatanaka02914dc2018-02-05 20:23:22 +0000541 Record.push_back(D->IsTrivialForCall);
Richard Smith72625c22015-02-06 23:20:21 +0000542 Record.push_back(D->IsDefaulted);
543 Record.push_back(D->IsExplicitlyDefaulted);
544 Record.push_back(D->HasImplicitReturnZero);
545 Record.push_back(D->IsConstexpr);
Reid Kleckner0d157382017-01-10 21:27:03 +0000546 Record.push_back(D->UsesSEHTry);
Argyrios Kyrtzidis1eb71a12012-12-06 18:59:10 +0000547 Record.push_back(D->HasSkippedBody);
Erich Keane281d20b2018-01-08 21:34:17 +0000548 Record.push_back(D->IsMultiVersion);
Richard Smith72625c22015-02-06 23:20:21 +0000549 Record.push_back(D->IsLateTemplateParsed);
Rafael Espindola3ae00052013-05-13 00:12:11 +0000550 Record.push_back(D->getLinkageInternal());
Richard Smith69c82bf2016-04-01 22:52:03 +0000551 Record.AddSourceLocation(D->getLocEnd());
Douglas Gregorb2585692012-01-04 17:13:46 +0000552
Richard Trieue6caa262017-12-23 00:41:01 +0000553 Record.push_back(D->getODRHash());
554
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000555 Record.push_back(D->getTemplatedKind());
556 switch (D->getTemplatedKind()) {
557 case FunctionDecl::TK_NonTemplate:
558 break;
559 case FunctionDecl::TK_FunctionTemplate:
Richard Smith69c82bf2016-04-01 22:52:03 +0000560 Record.AddDeclRef(D->getDescribedFunctionTemplate());
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000561 break;
562 case FunctionDecl::TK_MemberSpecialization: {
563 MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo();
Richard Smith69c82bf2016-04-01 22:52:03 +0000564 Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000565 Record.push_back(MemberInfo->getTemplateSpecializationKind());
Richard Smith69c82bf2016-04-01 22:52:03 +0000566 Record.AddSourceLocation(MemberInfo->getPointOfInstantiation());
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000567 break;
568 }
569 case FunctionDecl::TK_FunctionTemplateSpecialization: {
570 FunctionTemplateSpecializationInfo *
571 FTSInfo = D->getTemplateSpecializationInfo();
Richard Smithd8a83712015-08-22 01:47:18 +0000572
573 RegisterTemplateSpecialization(FTSInfo->getTemplate(), D);
574
Richard Smith69c82bf2016-04-01 22:52:03 +0000575 Record.AddDeclRef(FTSInfo->getTemplate());
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000576 Record.push_back(FTSInfo->getTemplateSpecializationKind());
577
578 // Template arguments.
Richard Smith69c82bf2016-04-01 22:52:03 +0000579 Record.AddTemplateArgumentList(FTSInfo->TemplateArguments);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000580
581 // Template args as written.
Craig Toppera13603a2014-05-22 05:54:18 +0000582 Record.push_back(FTSInfo->TemplateArgumentsAsWritten != nullptr);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000583 if (FTSInfo->TemplateArgumentsAsWritten) {
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000584 Record.push_back(FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs);
585 for (int i=0, e = FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs;
586 i!=e; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +0000587 Record.AddTemplateArgumentLoc(
588 (*FTSInfo->TemplateArgumentsAsWritten)[i]);
589 Record.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->LAngleLoc);
590 Record.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->RAngleLoc);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000591 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000592
Richard Smith69c82bf2016-04-01 22:52:03 +0000593 Record.AddSourceLocation(FTSInfo->getPointOfInstantiation());
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000594
595 if (D->isCanonicalDecl()) {
596 // Write the template that contains the specializations set. We will
597 // add a FunctionTemplateSpecializationInfo to it when reading.
Richard Smith69c82bf2016-04-01 22:52:03 +0000598 Record.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl());
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000599 }
Argyrios Kyrtzidisdc9ca0a2010-06-25 16:24:51 +0000600 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000601 }
602 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
603 DependentFunctionTemplateSpecializationInfo *
604 DFTSInfo = D->getDependentSpecializationInfo();
605
606 // Templates.
607 Record.push_back(DFTSInfo->getNumTemplates());
608 for (int i=0, e = DFTSInfo->getNumTemplates(); i != e; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +0000609 Record.AddDeclRef(DFTSInfo->getTemplate(i));
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000610
611 // Templates args.
612 Record.push_back(DFTSInfo->getNumTemplateArgs());
613 for (int i=0, e = DFTSInfo->getNumTemplateArgs(); i != e; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +0000614 Record.AddTemplateArgumentLoc(DFTSInfo->getTemplateArg(i));
615 Record.AddSourceLocation(DFTSInfo->getLAngleLoc());
616 Record.AddSourceLocation(DFTSInfo->getRAngleLoc());
Argyrios Kyrtzidisdc9ca0a2010-06-25 16:24:51 +0000617 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000618 }
619 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000620
Chris Lattner7099dbc2009-04-27 06:16:06 +0000621 Record.push_back(D->param_size());
David Majnemer59f77922016-06-24 04:05:48 +0000622 for (auto P : D->parameters())
Richard Smith69c82bf2016-04-01 22:52:03 +0000623 Record.AddDeclRef(P);
Sebastian Redl539c5062010-08-18 23:57:32 +0000624 Code = serialization::DECL_FUNCTION;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000625}
626
Richard Smithbc491202017-02-17 20:05:37 +0000627void ASTDeclWriter::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) {
628 VisitFunctionDecl(D);
Faisal Vali1f3a2af2017-11-11 18:02:29 +0000629 Record.push_back(D->IsCopyDeductionCandidate);
Richard Smithbc491202017-02-17 20:05:37 +0000630 Code = serialization::DECL_CXX_DEDUCTION_GUIDE;
631}
632
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000633void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000634 VisitNamedDecl(D);
635 // FIXME: convert to LazyStmtPtr?
Mike Stump11289f42009-09-09 15:08:12 +0000636 // Unlike C/C++, method bodies will never be in header files.
Craig Toppera13603a2014-05-22 05:54:18 +0000637 bool HasBodyStuff = D->getBody() != nullptr ||
638 D->getSelfDecl() != nullptr || D->getCmdDecl() != nullptr;
Argyrios Kyrtzidisa8607772010-08-09 10:54:37 +0000639 Record.push_back(HasBodyStuff);
640 if (HasBodyStuff) {
Richard Smith290d8012016-04-06 17:06:00 +0000641 Record.AddStmt(D->getBody());
Richard Smith69c82bf2016-04-01 22:52:03 +0000642 Record.AddDeclRef(D->getSelfDecl());
643 Record.AddDeclRef(D->getCmdDecl());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000644 }
645 Record.push_back(D->isInstanceMethod());
646 Record.push_back(D->isVariadic());
Jordan Rosed01e83a2012-10-10 16:42:25 +0000647 Record.push_back(D->isPropertyAccessor());
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000648 Record.push_back(D->isDefined());
Argyrios Kyrtzidis08f96a92012-05-09 16:12:57 +0000649 Record.push_back(D->IsOverriding);
Argyrios Kyrtzidis1eb71a12012-12-06 18:59:10 +0000650 Record.push_back(D->HasSkippedBody);
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000651
652 Record.push_back(D->IsRedeclaration);
653 Record.push_back(D->HasRedeclaration);
654 if (D->HasRedeclaration) {
655 assert(Context.getObjCMethodRedeclaration(D));
Richard Smith69c82bf2016-04-01 22:52:03 +0000656 Record.AddDeclRef(Context.getObjCMethodRedeclaration(D));
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000657 }
658
Chris Lattner7099dbc2009-04-27 06:16:06 +0000659 // FIXME: stable encoding for @required/@optional
Mike Stump11289f42009-09-09 15:08:12 +0000660 Record.push_back(D->getImplementationControl());
Douglas Gregor813a0662015-06-19 18:14:38 +0000661 // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway/nullability
Mike Stump11289f42009-09-09 15:08:12 +0000662 Record.push_back(D->getObjCDeclQualifier());
Douglas Gregor33823722011-06-11 01:09:30 +0000663 Record.push_back(D->hasRelatedResultType());
Richard Smith69c82bf2016-04-01 22:52:03 +0000664 Record.AddTypeRef(D->getReturnType());
665 Record.AddTypeSourceInfo(D->getReturnTypeSourceInfo());
666 Record.AddSourceLocation(D->getLocEnd());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000667 Record.push_back(D->param_size());
David Majnemer59f77922016-06-24 04:05:48 +0000668 for (const auto *P : D->parameters())
Richard Smith69c82bf2016-04-01 22:52:03 +0000669 Record.AddDeclRef(P);
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000670
671 Record.push_back(D->SelLocsKind);
672 unsigned NumStoredSelLocs = D->getNumStoredSelLocs();
673 SourceLocation *SelLocs = D->getStoredSelLocs();
674 Record.push_back(NumStoredSelLocs);
675 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +0000676 Record.AddSourceLocation(SelLocs[i]);
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000677
Sebastian Redl539c5062010-08-18 23:57:32 +0000678 Code = serialization::DECL_OBJC_METHOD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000679}
680
Douglas Gregor85f3f952015-07-07 03:57:15 +0000681void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
682 VisitTypedefNameDecl(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +0000683 Record.push_back(D->Variance);
Douglas Gregore83b9562015-07-07 03:57:53 +0000684 Record.push_back(D->Index);
Richard Smith69c82bf2016-04-01 22:52:03 +0000685 Record.AddSourceLocation(D->VarianceLoc);
686 Record.AddSourceLocation(D->ColonLoc);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000687
688 Code = serialization::DECL_OBJC_TYPE_PARAM;
689}
690
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000691void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000692 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000693 Record.AddSourceLocation(D->getAtStartLoc());
694 Record.AddSourceRange(D->getAtEndRange());
Sebastian Redl539c5062010-08-18 23:57:32 +0000695 // Abstract class (no need to define a stable serialization::DECL code).
Chris Lattner7099dbc2009-04-27 06:16:06 +0000696}
697
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000698void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
Douglas Gregor66b310c2011-12-15 18:03:09 +0000699 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000700 VisitObjCContainerDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000701 Record.AddTypeRef(QualType(D->getTypeForDecl(), 0));
Douglas Gregor85f3f952015-07-07 03:57:15 +0000702 AddObjCTypeParamList(D->TypeParamList);
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000703
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000704 Record.push_back(D->isThisDeclarationADefinition());
705 if (D->isThisDeclarationADefinition()) {
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000706 // Write the DefinitionData
707 ObjCInterfaceDecl::DefinitionData &Data = D->data();
708
Richard Smith69c82bf2016-04-01 22:52:03 +0000709 Record.AddTypeSourceInfo(D->getSuperClassTInfo());
710 Record.AddSourceLocation(D->getEndOfDefinitionLoc());
Argyrios Kyrtzidis9ed9e5f2013-12-03 21:11:30 +0000711 Record.push_back(Data.HasDesignatedInitializers);
Douglas Gregor16408322011-12-15 22:34:59 +0000712
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000713 // Write out the protocols that are directly referenced by the @interface.
714 Record.push_back(Data.ReferencedProtocols.size());
Aaron Ballmana49c5062014-03-13 20:29:09 +0000715 for (const auto *P : D->protocols())
Richard Smith69c82bf2016-04-01 22:52:03 +0000716 Record.AddDeclRef(P);
Aaron Ballmane9378882014-03-13 20:34:24 +0000717 for (const auto &PL : D->protocol_locs())
Richard Smith69c82bf2016-04-01 22:52:03 +0000718 Record.AddSourceLocation(PL);
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000719
720 // Write out the protocols that are transitively referenced.
721 Record.push_back(Data.AllReferencedProtocols.size());
722 for (ObjCList<ObjCProtocolDecl>::iterator
723 P = Data.AllReferencedProtocols.begin(),
724 PEnd = Data.AllReferencedProtocols.end();
725 P != PEnd; ++P)
Richard Smith69c82bf2016-04-01 22:52:03 +0000726 Record.AddDeclRef(*P);
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000727
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000728
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000729 if (ObjCCategoryDecl *Cat = D->getCategoryListRaw()) {
Douglas Gregor404cdde2012-01-27 01:47:08 +0000730 // Ensure that we write out the set of categories for this class.
731 Writer.ObjCClassesWithCategories.insert(D);
732
733 // Make sure that the categories get serialized.
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000734 for (; Cat; Cat = Cat->getNextClassCategoryRaw())
Douglas Gregor404cdde2012-01-27 01:47:08 +0000735 (void)Writer.GetDeclRef(Cat);
736 }
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000737 }
738
Sebastian Redl539c5062010-08-18 23:57:32 +0000739 Code = serialization::DECL_OBJC_INTERFACE;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000740}
741
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000742void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000743 VisitFieldDecl(D);
744 // FIXME: stable encoding for @public/@private/@protected/@package
Mike Stump11289f42009-09-09 15:08:12 +0000745 Record.push_back(D->getAccessControl());
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000746 Record.push_back(D->getSynthesize());
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000747
Richard Smith8aed4222015-12-11 22:41:00 +0000748 if (D->getDeclContext() == D->getLexicalDeclContext() &&
749 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000750 !D->isImplicit() &&
751 !D->isUsed(false) &&
752 !D->isInvalidDecl() &&
753 !D->isReferenced() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000754 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000755 !D->getBitWidth() &&
756 !D->hasExtInfo() &&
757 D->getDeclName())
758 AbbrevToUse = Writer.getDeclObjCIvarAbbrev();
759
Sebastian Redl539c5062010-08-18 23:57:32 +0000760 Code = serialization::DECL_OBJC_IVAR;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000761}
762
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000763void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
Douglas Gregora715bff2012-01-01 19:51:50 +0000764 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000765 VisitObjCContainerDecl(D);
Douglas Gregore6e48b12012-01-01 19:29:29 +0000766
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000767 Record.push_back(D->isThisDeclarationADefinition());
768 if (D->isThisDeclarationADefinition()) {
Douglas Gregore6e48b12012-01-01 19:29:29 +0000769 Record.push_back(D->protocol_size());
Aaron Ballman0f6e64d2014-03-13 22:58:06 +0000770 for (const auto *I : D->protocols())
Richard Smith69c82bf2016-04-01 22:52:03 +0000771 Record.AddDeclRef(I);
Aaron Ballmana964ec12014-03-14 12:38:50 +0000772 for (const auto &PL : D->protocol_locs())
Richard Smith69c82bf2016-04-01 22:52:03 +0000773 Record.AddSourceLocation(PL);
Douglas Gregore6e48b12012-01-01 19:29:29 +0000774 }
775
Sebastian Redl539c5062010-08-18 23:57:32 +0000776 Code = serialization::DECL_OBJC_PROTOCOL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000777}
778
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000779void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000780 VisitFieldDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000781 Code = serialization::DECL_OBJC_AT_DEFS_FIELD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000782}
783
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000784void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000785 VisitObjCContainerDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000786 Record.AddSourceLocation(D->getCategoryNameLoc());
787 Record.AddSourceLocation(D->getIvarLBraceLoc());
788 Record.AddSourceLocation(D->getIvarRBraceLoc());
789 Record.AddDeclRef(D->getClassInterface());
Douglas Gregor85f3f952015-07-07 03:57:15 +0000790 AddObjCTypeParamList(D->TypeParamList);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000791 Record.push_back(D->protocol_size());
Aaron Ballman19a41762014-03-14 12:55:57 +0000792 for (const auto *I : D->protocols())
Richard Smith69c82bf2016-04-01 22:52:03 +0000793 Record.AddDeclRef(I);
Aaron Ballmana73c8572014-03-14 13:03:32 +0000794 for (const auto &PL : D->protocol_locs())
Richard Smith69c82bf2016-04-01 22:52:03 +0000795 Record.AddSourceLocation(PL);
Sebastian Redl539c5062010-08-18 23:57:32 +0000796 Code = serialization::DECL_OBJC_CATEGORY;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000797}
798
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000799void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000800 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000801 Record.AddDeclRef(D->getClassInterface());
Sebastian Redl539c5062010-08-18 23:57:32 +0000802 Code = serialization::DECL_OBJC_COMPATIBLE_ALIAS;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000803}
804
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000805void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000806 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000807 Record.AddSourceLocation(D->getAtLoc());
808 Record.AddSourceLocation(D->getLParenLoc());
809 Record.AddTypeRef(D->getType());
810 Record.AddTypeSourceInfo(D->getTypeSourceInfo());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000811 // FIXME: stable encoding
812 Record.push_back((unsigned)D->getPropertyAttributes());
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000813 Record.push_back((unsigned)D->getPropertyAttributesAsWritten());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000814 // FIXME: stable encoding
815 Record.push_back((unsigned)D->getPropertyImplementation());
Richard Smith69c82bf2016-04-01 22:52:03 +0000816 Record.AddDeclarationName(D->getGetterName());
Argyrios Kyrtzidis194b28e2017-03-16 18:25:40 +0000817 Record.AddSourceLocation(D->getGetterNameLoc());
Richard Smith69c82bf2016-04-01 22:52:03 +0000818 Record.AddDeclarationName(D->getSetterName());
Argyrios Kyrtzidis194b28e2017-03-16 18:25:40 +0000819 Record.AddSourceLocation(D->getSetterNameLoc());
Richard Smith69c82bf2016-04-01 22:52:03 +0000820 Record.AddDeclRef(D->getGetterMethodDecl());
821 Record.AddDeclRef(D->getSetterMethodDecl());
822 Record.AddDeclRef(D->getPropertyIvarDecl());
Sebastian Redl539c5062010-08-18 23:57:32 +0000823 Code = serialization::DECL_OBJC_PROPERTY;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000824}
825
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000826void ASTDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000827 VisitObjCContainerDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000828 Record.AddDeclRef(D->getClassInterface());
Sebastian Redl539c5062010-08-18 23:57:32 +0000829 // Abstract class (no need to define a stable serialization::DECL code).
Chris Lattner7099dbc2009-04-27 06:16:06 +0000830}
831
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000832void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000833 VisitObjCImplDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000834 Record.AddSourceLocation(D->getCategoryNameLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000835 Code = serialization::DECL_OBJC_CATEGORY_IMPL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000836}
837
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000838void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000839 VisitObjCImplDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000840 Record.AddDeclRef(D->getSuperClass());
841 Record.AddSourceLocation(D->getSuperClassLoc());
842 Record.AddSourceLocation(D->getIvarLBraceLoc());
843 Record.AddSourceLocation(D->getIvarRBraceLoc());
John McCall0d54a172012-10-17 04:53:31 +0000844 Record.push_back(D->hasNonZeroConstructors());
845 Record.push_back(D->hasDestructors());
Richard Smithc2bb8182015-03-24 06:36:48 +0000846 Record.push_back(D->NumIvarInitializers);
847 if (D->NumIvarInitializers)
Richard Smithaa165cf2016-04-13 21:57:08 +0000848 Record.AddCXXCtorInitializers(
Richard Smith69c82bf2016-04-01 22:52:03 +0000849 llvm::makeArrayRef(D->init_begin(), D->init_end()));
Sebastian Redl539c5062010-08-18 23:57:32 +0000850 Code = serialization::DECL_OBJC_IMPLEMENTATION;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000851}
852
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000853void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000854 VisitDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000855 Record.AddSourceLocation(D->getLocStart());
856 Record.AddDeclRef(D->getPropertyDecl());
857 Record.AddDeclRef(D->getPropertyIvarDecl());
858 Record.AddSourceLocation(D->getPropertyIvarDeclLoc());
Richard Smith290d8012016-04-06 17:06:00 +0000859 Record.AddStmt(D->getGetterCXXConstructor());
860 Record.AddStmt(D->getSetterCXXAssignment());
Sebastian Redl539c5062010-08-18 23:57:32 +0000861 Code = serialization::DECL_OBJC_PROPERTY_IMPL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000862}
863
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000864void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000865 VisitDeclaratorDecl(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000866 Record.push_back(D->isMutable());
Richard Smith6b8e3c02017-08-28 00:28:14 +0000867
868 FieldDecl::InitStorageKind ISK = D->InitStorage.getInt();
869 Record.push_back(ISK);
870 if (ISK == FieldDecl::ISK_CapturedVLAType)
871 Record.AddTypeRef(QualType(D->getCapturedVLAType(), 0));
872 else if (ISK)
873 Record.AddStmt(D->getInClassInitializer());
874
875 Record.AddStmt(D->getBitWidth());
876
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000877 if (!D->getDeclName())
Richard Smith69c82bf2016-04-01 22:52:03 +0000878 Record.AddDeclRef(Context.getInstantiatedFromUnnamedFieldDecl(D));
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000879
Richard Smith8aed4222015-12-11 22:41:00 +0000880 if (D->getDeclContext() == D->getLexicalDeclContext() &&
881 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000882 !D->isImplicit() &&
883 !D->isUsed(false) &&
884 !D->isInvalidDecl() &&
885 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000886 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000887 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000888 !D->getBitWidth() &&
Richard Smith938f40b2011-06-11 17:19:42 +0000889 !D->hasInClassInitializer() &&
Richard Smith6b8e3c02017-08-28 00:28:14 +0000890 !D->hasCapturedVLAType() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000891 !D->hasExtInfo() &&
892 !ObjCIvarDecl::classofKind(D->getKind()) &&
893 !ObjCAtDefsFieldDecl::classofKind(D->getKind()) &&
894 D->getDeclName())
895 AbbrevToUse = Writer.getDeclFieldAbbrev();
896
Sebastian Redl539c5062010-08-18 23:57:32 +0000897 Code = serialization::DECL_FIELD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000898}
899
John McCall5e77d762013-04-16 07:28:30 +0000900void ASTDeclWriter::VisitMSPropertyDecl(MSPropertyDecl *D) {
901 VisitDeclaratorDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000902 Record.AddIdentifierRef(D->getGetterId());
903 Record.AddIdentifierRef(D->getSetterId());
John McCall5e77d762013-04-16 07:28:30 +0000904 Code = serialization::DECL_MS_PROPERTY;
905}
906
Francois Pichet783dd6e2010-11-21 06:08:52 +0000907void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
908 VisitValueDecl(D);
909 Record.push_back(D->getChainingSize());
910
Aaron Ballman29c94602014-03-07 18:36:15 +0000911 for (const auto *P : D->chain())
Richard Smith69c82bf2016-04-01 22:52:03 +0000912 Record.AddDeclRef(P);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000913 Code = serialization::DECL_INDIRECTFIELD;
914}
915
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000916void ASTDeclWriter::VisitVarDecl(VarDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000917 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000918 VisitDeclaratorDecl(D);
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000919 Record.push_back(D->getStorageClass());
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +0000920 Record.push_back(D->getTSCSpec());
Sebastian Redla9351792012-02-11 23:51:47 +0000921 Record.push_back(D->getInitStyle());
David Majnemerfa7bc782015-05-19 00:57:16 +0000922 if (!isa<ParmVarDecl>(D)) {
Richard Smithedbc6e92016-10-14 21:41:24 +0000923 Record.push_back(D->isThisDeclarationADemotedDefinition());
David Majnemerfa7bc782015-05-19 00:57:16 +0000924 Record.push_back(D->isExceptionVariable());
Taiju Tsuiki3be68e12018-06-19 05:35:30 +0000925 Record.push_back(D->isNRVOVariable());
David Majnemerfa7bc782015-05-19 00:57:16 +0000926 Record.push_back(D->isCXXForRangeDecl());
George Karpenkovec38cf72018-03-29 00:56:24 +0000927 Record.push_back(D->isObjCForDecl());
David Majnemerfa7bc782015-05-19 00:57:16 +0000928 Record.push_back(D->isARCPseudoStrong());
Richard Smith62f19e72016-06-25 00:15:56 +0000929 Record.push_back(D->isInline());
930 Record.push_back(D->isInlineSpecified());
David Majnemerfa7bc782015-05-19 00:57:16 +0000931 Record.push_back(D->isConstexpr());
932 Record.push_back(D->isInitCapture());
933 Record.push_back(D->isPreviousDeclInSameBlockScope());
Alexey Bataev56223232017-06-09 13:40:18 +0000934 if (const auto *IPD = dyn_cast<ImplicitParamDecl>(D))
935 Record.push_back(static_cast<unsigned>(IPD->getParameterKind()));
936 else
937 Record.push_back(0);
David Majnemerfa7bc782015-05-19 00:57:16 +0000938 }
Rafael Espindola3ae00052013-05-13 00:12:11 +0000939 Record.push_back(D->getLinkageInternal());
Douglas Gregor12cda632012-09-20 23:43:29 +0000940
Richard Smithd0b4dd62011-12-19 06:19:21 +0000941 if (D->getInit()) {
942 Record.push_back(!D->isInitKnownICE() ? 1 : (D->isInitICE() ? 3 : 2));
Richard Smith290d8012016-04-06 17:06:00 +0000943 Record.AddStmt(D->getInit());
Richard Smithd0b4dd62011-12-19 06:19:21 +0000944 } else {
945 Record.push_back(0);
946 }
Richard Smitha4653622017-09-06 20:01:14 +0000947
948 if (D->getStorageDuration() == SD_Static) {
949 bool ModulesCodegen = false;
950 if (Writer.WritingModule &&
951 !D->getDescribedVarTemplate() && !D->getMemberSpecializationInfo() &&
952 !isa<VarTemplateSpecializationDecl>(D)) {
953 // When building a C++ Modules TS module interface unit, a strong
954 // definition in the module interface is provided by the compilation of
955 // that module interface unit, not by its users. (Inline variables are
956 // still emitted in module users.)
957 ModulesCodegen =
958 (Writer.WritingModule->Kind == Module::ModuleInterfaceUnit &&
959 Writer.Context->GetGVALinkageForVariable(D) == GVA_StrongExternal);
960 }
961 Record.push_back(ModulesCodegen);
962 if (ModulesCodegen)
963 Writer.ModularCodegenDecls.push_back(Writer.GetDeclRef(D));
964 }
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000965
966 enum {
967 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
968 };
969 if (VarTemplateDecl *TemplD = D->getDescribedVarTemplate()) {
970 Record.push_back(VarTemplate);
Richard Smith69c82bf2016-04-01 22:52:03 +0000971 Record.AddDeclRef(TemplD);
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000972 } else if (MemberSpecializationInfo *SpecInfo
973 = D->getMemberSpecializationInfo()) {
974 Record.push_back(StaticDataMemberSpecialization);
Richard Smith69c82bf2016-04-01 22:52:03 +0000975 Record.AddDeclRef(SpecInfo->getInstantiatedFrom());
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000976 Record.push_back(SpecInfo->getTemplateSpecializationKind());
Richard Smith69c82bf2016-04-01 22:52:03 +0000977 Record.AddSourceLocation(SpecInfo->getPointOfInstantiation());
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000978 } else {
979 Record.push_back(VarNotTemplate);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000980 }
981
Richard Smith8aed4222015-12-11 22:41:00 +0000982 if (D->getDeclContext() == D->getLexicalDeclContext() &&
983 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000984 !D->isImplicit() &&
985 !D->isUsed(false) &&
986 !D->isInvalidDecl() &&
987 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000988 !D->isTopLevelDeclInObjCContainer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000989 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000990 !D->isModulePrivate() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000991 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000992 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
993 !D->hasExtInfo() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000994 D->getFirstDecl() == D->getMostRecentDecl() &&
Richard Smith7b76d812016-08-12 02:21:25 +0000995 D->getKind() == Decl::Var &&
Richard Smith62f19e72016-06-25 00:15:56 +0000996 !D->isInline() &&
Douglas Gregor12cda632012-09-20 23:43:29 +0000997 !D->isConstexpr() &&
Richard Smithbb13c9a2013-09-28 04:02:39 +0000998 !D->isInitCapture() &&
Richard Smith1c34fb72013-08-13 18:18:50 +0000999 !D->isPreviousDeclInSameBlockScope() &&
Richard Smitha4653622017-09-06 20:01:14 +00001000 D->getStorageDuration() != SD_Static &&
Larisse Voufod8dd97c2013-08-14 03:09:19 +00001001 !D->getMemberSpecializationInfo())
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001002 AbbrevToUse = Writer.getDeclVarAbbrev();
1003
Sebastian Redl539c5062010-08-18 23:57:32 +00001004 Code = serialization::DECL_VAR;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001005}
1006
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001007void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001008 VisitVarDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001009 Code = serialization::DECL_IMPLICIT_PARAM;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001010}
1011
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001012void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001013 VisitVarDecl(D);
John McCall82490832011-05-02 00:30:12 +00001014 Record.push_back(D->isObjCMethodParameter());
John McCall8fb0d9d2011-05-01 22:35:37 +00001015 Record.push_back(D->getFunctionScopeDepth());
1016 Record.push_back(D->getFunctionScopeIndex());
Chris Lattner7099dbc2009-04-27 06:16:06 +00001017 Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding
John McCall6a014d52011-03-09 04:22:44 +00001018 Record.push_back(D->isKNRPromoted());
John McCallf3cd6652010-03-12 18:31:32 +00001019 Record.push_back(D->hasInheritedDefaultArg());
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +00001020 Record.push_back(D->hasUninstantiatedDefaultArg());
1021 if (D->hasUninstantiatedDefaultArg())
Richard Smith290d8012016-04-06 17:06:00 +00001022 Record.AddStmt(D->getUninstantiatedDefaultArg());
Sebastian Redl539c5062010-08-18 23:57:32 +00001023 Code = serialization::DECL_PARM_VAR;
Mike Stump11289f42009-09-09 15:08:12 +00001024
John McCalld4631322011-06-17 06:42:21 +00001025 assert(!D->isARCPseudoStrong()); // can be true of ImplicitParamDecl
1026
Chris Lattner258172e2009-04-27 07:35:58 +00001027 // If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here
1028 // we dynamically check for the properties that we optimize for, but don't
1029 // know are true of all PARM_VAR_DECLs.
Richard Smith8aed4222015-12-11 22:41:00 +00001030 if (D->getDeclContext() == D->getLexicalDeclContext() &&
1031 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001032 !D->hasExtInfo() &&
Chris Lattner258172e2009-04-27 07:35:58 +00001033 !D->isImplicit() &&
Douglas Gregorebada0772010-06-17 23:14:26 +00001034 !D->isUsed(false) &&
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001035 !D->isInvalidDecl() &&
Eli Friedmanc09e0552012-01-13 23:41:25 +00001036 !D->isReferenced() &&
Chris Lattner258172e2009-04-27 07:35:58 +00001037 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +00001038 !D->isModulePrivate() &&
Chris Lattner258172e2009-04-27 07:35:58 +00001039 D->getStorageClass() == 0 &&
Sebastian Redla9351792012-02-11 23:51:47 +00001040 D->getInitStyle() == VarDecl::CInit && // Can params have anything else?
John McCall82490832011-05-02 00:30:12 +00001041 D->getFunctionScopeDepth() == 0 &&
John McCallf3cd6652010-03-12 18:31:32 +00001042 D->getObjCDeclQualifier() == 0 &&
John McCall6a014d52011-03-09 04:22:44 +00001043 !D->isKNRPromoted() &&
Chris Lattnere2437f42010-05-09 06:40:08 +00001044 !D->hasInheritedDefaultArg() &&
Craig Toppera13603a2014-05-22 05:54:18 +00001045 D->getInit() == nullptr &&
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +00001046 !D->hasUninstantiatedDefaultArg()) // No default expr.
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001047 AbbrevToUse = Writer.getDeclParmVarAbbrev();
Chris Lattner258172e2009-04-27 07:35:58 +00001048
1049 // Check things we know are true of *every* PARM_VAR_DECL, which is more than
1050 // just us assuming it.
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +00001051 assert(!D->getTSCSpec() && "PARM_VAR_DECL can't use TLS");
Richard Smithedbc6e92016-10-14 21:41:24 +00001052 assert(!D->isThisDeclarationADemotedDefinition()
1053 && "PARM_VAR_DECL can't be demoted definition.");
Chris Lattner258172e2009-04-27 07:35:58 +00001054 assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private");
Douglas Gregor3f324d562010-05-03 18:51:14 +00001055 assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var");
Craig Toppera13603a2014-05-22 05:54:18 +00001056 assert(D->getPreviousDecl() == nullptr && "PARM_VAR_DECL can't be redecl");
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001057 assert(!D->isStaticDataMember() &&
1058 "PARM_VAR_DECL can't be static data member");
Chris Lattner7099dbc2009-04-27 06:16:06 +00001059}
1060
Richard Smith7b76d812016-08-12 02:21:25 +00001061void ASTDeclWriter::VisitDecompositionDecl(DecompositionDecl *D) {
1062 // Record the number of bindings first to simplify deserialization.
1063 Record.push_back(D->bindings().size());
1064
1065 VisitVarDecl(D);
1066 for (auto *B : D->bindings())
1067 Record.AddDeclRef(B);
1068 Code = serialization::DECL_DECOMPOSITION;
1069}
1070
1071void ASTDeclWriter::VisitBindingDecl(BindingDecl *D) {
1072 VisitValueDecl(D);
1073 Record.AddStmt(D->getBinding());
1074 Code = serialization::DECL_BINDING;
1075}
1076
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001077void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001078 VisitDecl(D);
Richard Smith290d8012016-04-06 17:06:00 +00001079 Record.AddStmt(D->getAsmString());
Richard Smith69c82bf2016-04-01 22:52:03 +00001080 Record.AddSourceLocation(D->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001081 Code = serialization::DECL_FILE_SCOPE_ASM;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001082}
1083
Michael Han84324352013-02-22 17:15:32 +00001084void ASTDeclWriter::VisitEmptyDecl(EmptyDecl *D) {
1085 VisitDecl(D);
1086 Code = serialization::DECL_EMPTY;
1087}
1088
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001089void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001090 VisitDecl(D);
Richard Smith290d8012016-04-06 17:06:00 +00001091 Record.AddStmt(D->getBody());
Richard Smith69c82bf2016-04-01 22:52:03 +00001092 Record.AddTypeSourceInfo(D->getSignatureAsWritten());
Chris Lattner7099dbc2009-04-27 06:16:06 +00001093 Record.push_back(D->param_size());
David Majnemera3debed2016-06-24 05:33:44 +00001094 for (ParmVarDecl *P : D->parameters())
1095 Record.AddDeclRef(P);
John McCallcf6ce282012-04-13 17:33:29 +00001096 Record.push_back(D->isVariadic());
1097 Record.push_back(D->blockMissingReturnType());
1098 Record.push_back(D->isConversionFromLambda());
John McCallc63de662011-02-02 13:00:07 +00001099 Record.push_back(D->capturesCXXThis());
John McCall351762c2011-02-07 10:33:21 +00001100 Record.push_back(D->getNumCaptures());
Aaron Ballman9371dd22014-03-14 18:34:04 +00001101 for (const auto &capture : D->captures()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001102 Record.AddDeclRef(capture.getVariable());
John McCall351762c2011-02-07 10:33:21 +00001103
1104 unsigned flags = 0;
1105 if (capture.isByRef()) flags |= 1;
1106 if (capture.isNested()) flags |= 2;
1107 if (capture.hasCopyExpr()) flags |= 4;
1108 Record.push_back(flags);
1109
Richard Smith290d8012016-04-06 17:06:00 +00001110 if (capture.hasCopyExpr()) Record.AddStmt(capture.getCopyExpr());
John McCall351762c2011-02-07 10:33:21 +00001111 }
John McCallc63de662011-02-02 13:00:07 +00001112
Sebastian Redl539c5062010-08-18 23:57:32 +00001113 Code = serialization::DECL_BLOCK;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001114}
1115
Ben Langmuirce914fc2013-05-03 19:20:19 +00001116void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) {
1117 Record.push_back(CD->getNumParams());
1118 VisitDecl(CD);
Alexey Bataev9959db52014-05-06 10:08:46 +00001119 Record.push_back(CD->getContextParamPosition());
1120 Record.push_back(CD->isNothrow() ? 1 : 0);
Ben Langmuirce914fc2013-05-03 19:20:19 +00001121 // Body is stored by VisitCapturedStmt.
Alexey Bataev9959db52014-05-06 10:08:46 +00001122 for (unsigned I = 0; I < CD->getNumParams(); ++I)
Richard Smith69c82bf2016-04-01 22:52:03 +00001123 Record.AddDeclRef(CD->getParam(I));
Ben Langmuirce914fc2013-05-03 19:20:19 +00001124 Code = serialization::DECL_CAPTURED;
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001125}
1126
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001127void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001128 VisitDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001129 Record.push_back(D->getLanguage());
Richard Smith69c82bf2016-04-01 22:52:03 +00001130 Record.AddSourceLocation(D->getExternLoc());
1131 Record.AddSourceLocation(D->getRBraceLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001132 Code = serialization::DECL_LINKAGE_SPEC;
Chris Lattnerca025db2010-05-07 21:43:38 +00001133}
1134
Richard Smith8df390f2016-09-08 23:14:54 +00001135void ASTDeclWriter::VisitExportDecl(ExportDecl *D) {
1136 VisitDecl(D);
1137 Record.AddSourceLocation(D->getRBraceLoc());
1138 Code = serialization::DECL_EXPORT;
1139}
1140
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001141void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) {
1142 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001143 Record.AddSourceLocation(D->getLocStart());
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001144 Code = serialization::DECL_LABEL;
1145}
1146
1147
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001148void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
Douglas Gregore57e7522012-01-07 09:11:48 +00001149 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001150 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +00001151 Record.push_back(D->isInline());
Richard Smith69c82bf2016-04-01 22:52:03 +00001152 Record.AddSourceLocation(D->getLocStart());
1153 Record.AddSourceLocation(D->getRBraceLoc());
Chris Lattnerca025db2010-05-07 21:43:38 +00001154
Chris Lattnerca025db2010-05-07 21:43:38 +00001155 if (D->isOriginalNamespace())
Richard Smith69c82bf2016-04-01 22:52:03 +00001156 Record.AddDeclRef(D->getAnonymousNamespace());
Sebastian Redl539c5062010-08-18 23:57:32 +00001157 Code = serialization::DECL_NAMESPACE;
Sebastian Redlf03cdc52010-08-05 21:22:19 +00001158
Douglas Gregore57e7522012-01-07 09:11:48 +00001159 if (Writer.hasChain() && D->isAnonymousNamespace() &&
Douglas Gregorec9fd132012-01-14 16:38:05 +00001160 D == D->getMostRecentDecl()) {
Sebastian Redl010288f2011-04-24 16:28:21 +00001161 // This is a most recent reopening of the anonymous namespace. If its parent
1162 // is in a previous PCH (or is the TU), mark that parent for update, because
1163 // the original namespace always points to the latest re-opening of its
1164 // anonymous namespace.
1165 Decl *Parent = cast<Decl>(
1166 D->getParent()->getRedeclContext()->getPrimaryContext());
Douglas Gregorb3722e22011-09-09 23:01:35 +00001167 if (Parent->isFromASTFile() || isa<TranslationUnitDecl>(Parent)) {
Richard Smith6ef42932014-03-20 21:02:00 +00001168 Writer.DeclUpdates[Parent].push_back(
Aaron Ballman4f45b712014-03-21 15:22:56 +00001169 ASTWriter::DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, D));
Sebastian Redlfa1f3702011-04-24 16:28:13 +00001170 }
1171 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001172}
1173
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001174void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Richard Smithf4634362014-09-03 23:11:22 +00001175 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001176 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001177 Record.AddSourceLocation(D->getNamespaceLoc());
1178 Record.AddSourceLocation(D->getTargetNameLoc());
1179 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1180 Record.AddDeclRef(D->getNamespace());
Sebastian Redl539c5062010-08-18 23:57:32 +00001181 Code = serialization::DECL_NAMESPACE_ALIAS;
Chris Lattnerca025db2010-05-07 21:43:38 +00001182}
1183
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001184void ASTDeclWriter::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001185 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001186 Record.AddSourceLocation(D->getUsingLoc());
1187 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1188 Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
1189 Record.AddDeclRef(D->FirstUsingShadow.getPointer());
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00001190 Record.push_back(D->hasTypename());
Richard Smith69c82bf2016-04-01 22:52:03 +00001191 Record.AddDeclRef(Context.getInstantiatedFromUsingDecl(D));
Sebastian Redl539c5062010-08-18 23:57:32 +00001192 Code = serialization::DECL_USING;
Chris Lattnerca025db2010-05-07 21:43:38 +00001193}
1194
Richard Smith151c4562016-12-20 21:35:28 +00001195void ASTDeclWriter::VisitUsingPackDecl(UsingPackDecl *D) {
1196 Record.push_back(D->NumExpansions);
1197 VisitNamedDecl(D);
1198 Record.AddDeclRef(D->getInstantiatedFromUsingDecl());
1199 for (auto *E : D->expansions())
1200 Record.AddDeclRef(E);
1201 Code = serialization::DECL_USING_PACK;
1202}
1203
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001204void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) {
Richard Smithfd8634a2013-10-23 02:17:46 +00001205 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001206 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001207 Record.AddDeclRef(D->getTargetDecl());
Richard Smitha263c342018-01-06 01:07:05 +00001208 Record.push_back(D->getIdentifierNamespace());
Richard Smith69c82bf2016-04-01 22:52:03 +00001209 Record.AddDeclRef(D->UsingOrNextShadow);
1210 Record.AddDeclRef(Context.getInstantiatedFromUsingShadowDecl(D));
Sebastian Redl539c5062010-08-18 23:57:32 +00001211 Code = serialization::DECL_USING_SHADOW;
Chris Lattnerca025db2010-05-07 21:43:38 +00001212}
1213
Richard Smith5179eb72016-06-28 19:03:57 +00001214void ASTDeclWriter::VisitConstructorUsingShadowDecl(
1215 ConstructorUsingShadowDecl *D) {
1216 VisitUsingShadowDecl(D);
1217 Record.AddDeclRef(D->NominatedBaseClassShadowDecl);
1218 Record.AddDeclRef(D->ConstructedBaseClassShadowDecl);
1219 Record.push_back(D->IsVirtual);
1220 Code = serialization::DECL_CONSTRUCTOR_USING_SHADOW;
1221}
1222
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001223void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001224 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001225 Record.AddSourceLocation(D->getUsingLoc());
1226 Record.AddSourceLocation(D->getNamespaceKeyLocation());
1227 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1228 Record.AddDeclRef(D->getNominatedNamespace());
1229 Record.AddDeclRef(dyn_cast<Decl>(D->getCommonAncestor()));
Sebastian Redl539c5062010-08-18 23:57:32 +00001230 Code = serialization::DECL_USING_DIRECTIVE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001231}
1232
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001233void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001234 VisitValueDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001235 Record.AddSourceLocation(D->getUsingLoc());
1236 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1237 Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
Richard Smith151c4562016-12-20 21:35:28 +00001238 Record.AddSourceLocation(D->getEllipsisLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001239 Code = serialization::DECL_UNRESOLVED_USING_VALUE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001240}
1241
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001242void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001243 UnresolvedUsingTypenameDecl *D) {
1244 VisitTypeDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001245 Record.AddSourceLocation(D->getTypenameLoc());
1246 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
Richard Smith151c4562016-12-20 21:35:28 +00001247 Record.AddSourceLocation(D->getEllipsisLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001248 Code = serialization::DECL_UNRESOLVED_USING_TYPENAME;
Chris Lattnerca025db2010-05-07 21:43:38 +00001249}
1250
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001251void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001252 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001253
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001254 enum {
1255 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1256 };
1257 if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) {
1258 Record.push_back(CXXRecTemplate);
Richard Smith69c82bf2016-04-01 22:52:03 +00001259 Record.AddDeclRef(TemplD);
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001260 } else if (MemberSpecializationInfo *MSInfo
1261 = D->getMemberSpecializationInfo()) {
1262 Record.push_back(CXXRecMemberSpecialization);
Richard Smith69c82bf2016-04-01 22:52:03 +00001263 Record.AddDeclRef(MSInfo->getInstantiatedFrom());
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001264 Record.push_back(MSInfo->getTemplateSpecializationKind());
Richard Smith69c82bf2016-04-01 22:52:03 +00001265 Record.AddSourceLocation(MSInfo->getPointOfInstantiation());
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001266 } else {
1267 Record.push_back(CXXRecNotTemplate);
1268 }
1269
Richard Smithcd45dbc2014-04-19 03:48:30 +00001270 Record.push_back(D->isThisDeclarationADefinition());
1271 if (D->isThisDeclarationADefinition())
Richard Smith69c82bf2016-04-01 22:52:03 +00001272 Record.AddCXXDefinitionData(D);
Richard Smithcd45dbc2014-04-19 03:48:30 +00001273
John McCall6bd2a892013-01-25 22:31:03 +00001274 // Store (what we currently believe to be) the key function to avoid
1275 // deserializing every method so we can compute it.
John McCallf937c022011-10-07 06:10:15 +00001276 if (D->IsCompleteDefinition)
Richard Smith69c82bf2016-04-01 22:52:03 +00001277 Record.AddDeclRef(Context.getCurrentKeyFunction(D));
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001278
Sebastian Redl539c5062010-08-18 23:57:32 +00001279 Code = serialization::DECL_CXX_RECORD;
Chris Lattnerca025db2010-05-07 21:43:38 +00001280}
1281
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001282void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001283 VisitFunctionDecl(D);
Argyrios Kyrtzidis3b1a7792012-10-12 05:31:40 +00001284 if (D->isCanonicalDecl()) {
1285 Record.push_back(D->size_overridden_methods());
Benjamin Krameracfa3392017-12-17 23:52:45 +00001286 for (const CXXMethodDecl *MD : D->overridden_methods())
1287 Record.AddDeclRef(MD);
Argyrios Kyrtzidis3b1a7792012-10-12 05:31:40 +00001288 } else {
1289 // We only need to record overridden methods once for the canonical decl.
1290 Record.push_back(0);
1291 }
Richard Smith01b2cb42014-07-26 06:37:51 +00001292
Richard Smith8aed4222015-12-11 22:41:00 +00001293 if (D->getDeclContext() == D->getLexicalDeclContext() &&
1294 D->getFirstDecl() == D->getMostRecentDecl() &&
Richard Smith01b2cb42014-07-26 06:37:51 +00001295 !D->isInvalidDecl() &&
1296 !D->hasAttrs() &&
1297 !D->isTopLevelDeclInObjCContainer() &&
1298 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
1299 !D->hasExtInfo() &&
1300 !D->hasInheritedPrototype() &&
1301 D->hasWrittenPrototype())
1302 AbbrevToUse = Writer.getDeclCXXMethodAbbrev();
1303
Sebastian Redl539c5062010-08-18 23:57:32 +00001304 Code = serialization::DECL_CXX_METHOD;
Chris Lattnerca025db2010-05-07 21:43:38 +00001305}
1306
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001307void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Richard Smith5179eb72016-06-28 19:03:57 +00001308 if (auto Inherited = D->getInheritedConstructor()) {
1309 Record.AddDeclRef(Inherited.getShadowDecl());
1310 Record.AddDeclRef(Inherited.getConstructor());
1311 Code = serialization::DECL_CXX_INHERITED_CONSTRUCTOR;
1312 } else {
1313 Code = serialization::DECL_CXX_CONSTRUCTOR;
1314 }
1315
Chris Lattnerca025db2010-05-07 21:43:38 +00001316 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001317
Richard Smith5179eb72016-06-28 19:03:57 +00001318 Code = D->isInheritingConstructor()
1319 ? serialization::DECL_CXX_INHERITED_CONSTRUCTOR
1320 : serialization::DECL_CXX_CONSTRUCTOR;
Chris Lattnerca025db2010-05-07 21:43:38 +00001321}
1322
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001323void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001324 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001325
Richard Smith69c82bf2016-04-01 22:52:03 +00001326 Record.AddDeclRef(D->getOperatorDelete());
Richard Smith5b349582017-10-13 01:55:36 +00001327 if (D->getOperatorDelete())
1328 Record.AddStmt(D->getOperatorDeleteThisArg());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001329
Sebastian Redl539c5062010-08-18 23:57:32 +00001330 Code = serialization::DECL_CXX_DESTRUCTOR;
Chris Lattnerca025db2010-05-07 21:43:38 +00001331}
1332
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001333void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001334 VisitCXXMethodDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001335 Code = serialization::DECL_CXX_CONVERSION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001336}
1337
Douglas Gregorba345522011-12-02 23:23:56 +00001338void ASTDeclWriter::VisitImportDecl(ImportDecl *D) {
1339 VisitDecl(D);
Argyrios Kyrtzidis7b8e5552012-10-03 01:58:45 +00001340 Record.push_back(Writer.getSubmoduleID(D->getImportedModule()));
Douglas Gregorba345522011-12-02 23:23:56 +00001341 ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs();
1342 Record.push_back(!IdentifierLocs.empty());
1343 if (IdentifierLocs.empty()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001344 Record.AddSourceLocation(D->getLocEnd());
Douglas Gregorba345522011-12-02 23:23:56 +00001345 Record.push_back(1);
1346 } else {
1347 for (unsigned I = 0, N = IdentifierLocs.size(); I != N; ++I)
Richard Smith69c82bf2016-04-01 22:52:03 +00001348 Record.AddSourceLocation(IdentifierLocs[I]);
Douglas Gregorba345522011-12-02 23:23:56 +00001349 Record.push_back(IdentifierLocs.size());
1350 }
1351 // Note: the number of source locations must always be the last element in
1352 // the record.
1353 Code = serialization::DECL_IMPORT;
1354}
1355
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001356void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001357 VisitDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001358 Record.AddSourceLocation(D->getColonLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001359 Code = serialization::DECL_ACCESS_SPEC;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001360}
1361
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001362void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) {
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001363 // Record the number of friend type template parameter lists here
1364 // so as to simplify memory allocation during deserialization.
1365 Record.push_back(D->NumTPLists);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001366 VisitDecl(D);
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001367 bool hasFriendDecl = D->Friend.is<NamedDecl*>();
1368 Record.push_back(hasFriendDecl);
1369 if (hasFriendDecl)
Richard Smith69c82bf2016-04-01 22:52:03 +00001370 Record.AddDeclRef(D->getFriendDecl());
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001371 else
Richard Smith69c82bf2016-04-01 22:52:03 +00001372 Record.AddTypeSourceInfo(D->getFriendType());
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001373 for (unsigned i = 0; i < D->NumTPLists; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +00001374 Record.AddTemplateParameterList(D->getFriendTypeTemplateParameterList(i));
1375 Record.AddDeclRef(D->getNextFriend());
John McCall2c2eb122010-10-16 06:59:13 +00001376 Record.push_back(D->UnsupportedFriend);
Richard Smith69c82bf2016-04-01 22:52:03 +00001377 Record.AddSourceLocation(D->FriendLoc);
Sebastian Redl539c5062010-08-18 23:57:32 +00001378 Code = serialization::DECL_FRIEND;
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001379}
1380
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001381void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001382 VisitDecl(D);
1383 Record.push_back(D->getNumTemplateParameters());
1384 for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +00001385 Record.AddTemplateParameterList(D->getTemplateParameterList(i));
Craig Toppera13603a2014-05-22 05:54:18 +00001386 Record.push_back(D->getFriendDecl() != nullptr);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001387 if (D->getFriendDecl())
Richard Smith69c82bf2016-04-01 22:52:03 +00001388 Record.AddDeclRef(D->getFriendDecl());
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001389 else
Richard Smith69c82bf2016-04-01 22:52:03 +00001390 Record.AddTypeSourceInfo(D->getFriendType());
1391 Record.AddSourceLocation(D->getFriendLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001392 Code = serialization::DECL_FRIEND_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001393}
1394
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001395void ASTDeclWriter::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001396 VisitNamedDecl(D);
1397
Richard Smith69c82bf2016-04-01 22:52:03 +00001398 Record.AddDeclRef(D->getTemplatedDecl());
1399 Record.AddTemplateParameterList(D->getTemplateParameters());
Chris Lattnerca025db2010-05-07 21:43:38 +00001400}
1401
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001402void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Douglas Gregor68444de2012-01-14 15:13:49 +00001403 VisitRedeclarable(D);
1404
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001405 // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that
1406 // getCommonPtr() can be used while this is still initializing.
Rafael Espindola8db352d2013-10-17 15:37:26 +00001407 if (D->isFirstDecl()) {
Douglas Gregor074a4092011-12-19 18:19:24 +00001408 // This declaration owns the 'common' pointer, so serialize that data now.
Richard Smith69c82bf2016-04-01 22:52:03 +00001409 Record.AddDeclRef(D->getInstantiatedFromMemberTemplate());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001410 if (D->getInstantiatedFromMemberTemplate())
1411 Record.push_back(D->isMemberSpecialization());
Douglas Gregor074a4092011-12-19 18:19:24 +00001412 }
1413
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001414 VisitTemplateDecl(D);
1415 Record.push_back(D->getIdentifierNamespace());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001416}
1417
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001418void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001419 VisitRedeclarableTemplateDecl(D);
1420
Richard Smith509fc852015-02-27 23:05:10 +00001421 if (D->isFirstDecl())
1422 AddTemplateSpecializations(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001423 Code = serialization::DECL_CLASS_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001424}
1425
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001426void ASTDeclWriter::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001427 ClassTemplateSpecializationDecl *D) {
Richard Smithd8a83712015-08-22 01:47:18 +00001428 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1429
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001430 VisitCXXRecordDecl(D);
1431
1432 llvm::PointerUnion<ClassTemplateDecl *,
1433 ClassTemplatePartialSpecializationDecl *> InstFrom
1434 = D->getSpecializedTemplateOrPartial();
Argyrios Kyrtzidisd5553f12011-08-17 21:35:28 +00001435 if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001436 Record.AddDeclRef(InstFromD);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001437 } else {
Richard Smith69c82bf2016-04-01 22:52:03 +00001438 Record.AddDeclRef(InstFrom.get<ClassTemplatePartialSpecializationDecl *>());
1439 Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001440 }
1441
Richard Smith69c82bf2016-04-01 22:52:03 +00001442 Record.AddTemplateArgumentList(&D->getTemplateArgs());
1443 Record.AddSourceLocation(D->getPointOfInstantiation());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001444 Record.push_back(D->getSpecializationKind());
Axel Naumanna31dee22012-10-01 07:34:47 +00001445 Record.push_back(D->isCanonicalDecl());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001446
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001447 if (D->isCanonicalDecl()) {
1448 // When reading, we'll add it to the folding set of the following template.
Richard Smith69c82bf2016-04-01 22:52:03 +00001449 Record.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl());
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001450 }
1451
Richard Smithd55889a2013-09-09 16:55:27 +00001452 // Explicit info.
Richard Smith69c82bf2016-04-01 22:52:03 +00001453 Record.AddTypeSourceInfo(D->getTypeAsWritten());
Richard Smithd55889a2013-09-09 16:55:27 +00001454 if (D->getTypeAsWritten()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001455 Record.AddSourceLocation(D->getExternLoc());
1456 Record.AddSourceLocation(D->getTemplateKeywordLoc());
Richard Smithd55889a2013-09-09 16:55:27 +00001457 }
1458
Sebastian Redl539c5062010-08-18 23:57:32 +00001459 Code = serialization::DECL_CLASS_TEMPLATE_SPECIALIZATION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001460}
1461
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001462void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001463 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001464 VisitClassTemplateSpecializationDecl(D);
1465
Richard Smith69c82bf2016-04-01 22:52:03 +00001466 Record.AddTemplateParameterList(D->getTemplateParameters());
1467 Record.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001468
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001469 // These are read/set from/to the first declaration.
Craig Toppera13603a2014-05-22 05:54:18 +00001470 if (D->getPreviousDecl() == nullptr) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001471 Record.AddDeclRef(D->getInstantiatedFromMember());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001472 Record.push_back(D->isMemberSpecialization());
1473 }
1474
Sebastian Redl539c5062010-08-18 23:57:32 +00001475 Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001476}
1477
Larisse Voufo39a1e502013-08-06 01:03:05 +00001478void ASTDeclWriter::VisitVarTemplateDecl(VarTemplateDecl *D) {
1479 VisitRedeclarableTemplateDecl(D);
1480
Richard Smith509fc852015-02-27 23:05:10 +00001481 if (D->isFirstDecl())
1482 AddTemplateSpecializations(D);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001483 Code = serialization::DECL_VAR_TEMPLATE;
1484}
1485
1486void ASTDeclWriter::VisitVarTemplateSpecializationDecl(
1487 VarTemplateSpecializationDecl *D) {
Richard Smithd8a83712015-08-22 01:47:18 +00001488 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1489
Larisse Voufo39a1e502013-08-06 01:03:05 +00001490 VisitVarDecl(D);
1491
1492 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
1493 InstFrom = D->getSpecializedTemplateOrPartial();
1494 if (Decl *InstFromD = InstFrom.dyn_cast<VarTemplateDecl *>()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001495 Record.AddDeclRef(InstFromD);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001496 } else {
Richard Smith69c82bf2016-04-01 22:52:03 +00001497 Record.AddDeclRef(InstFrom.get<VarTemplatePartialSpecializationDecl *>());
1498 Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001499 }
1500
1501 // Explicit info.
Richard Smith69c82bf2016-04-01 22:52:03 +00001502 Record.AddTypeSourceInfo(D->getTypeAsWritten());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001503 if (D->getTypeAsWritten()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001504 Record.AddSourceLocation(D->getExternLoc());
1505 Record.AddSourceLocation(D->getTemplateKeywordLoc());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001506 }
1507
Richard Smith69c82bf2016-04-01 22:52:03 +00001508 Record.AddTemplateArgumentList(&D->getTemplateArgs());
1509 Record.AddSourceLocation(D->getPointOfInstantiation());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001510 Record.push_back(D->getSpecializationKind());
Richard Smith435e6472017-12-02 02:48:42 +00001511 Record.push_back(D->IsCompleteDefinition);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001512 Record.push_back(D->isCanonicalDecl());
1513
1514 if (D->isCanonicalDecl()) {
1515 // When reading, we'll add it to the folding set of the following template.
Richard Smith69c82bf2016-04-01 22:52:03 +00001516 Record.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001517 }
1518
1519 Code = serialization::DECL_VAR_TEMPLATE_SPECIALIZATION;
1520}
1521
1522void ASTDeclWriter::VisitVarTemplatePartialSpecializationDecl(
1523 VarTemplatePartialSpecializationDecl *D) {
1524 VisitVarTemplateSpecializationDecl(D);
1525
Richard Smith69c82bf2016-04-01 22:52:03 +00001526 Record.AddTemplateParameterList(D->getTemplateParameters());
1527 Record.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001528
1529 // These are read/set from/to the first declaration.
Craig Toppera13603a2014-05-22 05:54:18 +00001530 if (D->getPreviousDecl() == nullptr) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001531 Record.AddDeclRef(D->getInstantiatedFromMember());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001532 Record.push_back(D->isMemberSpecialization());
1533 }
1534
1535 Code = serialization::DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION;
1536}
1537
Fariborz Jahanian3a039e32011-08-27 20:50:59 +00001538void ASTDeclWriter::VisitClassScopeFunctionSpecializationDecl(
1539 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichet09af8c32011-08-17 01:06:54 +00001540 VisitDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001541 Record.AddDeclRef(D->getSpecialization());
Francois Pichet09af8c32011-08-17 01:06:54 +00001542 Code = serialization::DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION;
1543}
1544
1545
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001546void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001547 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001548
Richard Smith509fc852015-02-27 23:05:10 +00001549 if (D->isFirstDecl())
1550 AddTemplateSpecializations(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001551 Code = serialization::DECL_FUNCTION_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001552}
1553
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001554void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001555 VisitTypeDecl(D);
1556
1557 Record.push_back(D->wasDeclaredWithTypename());
Richard Smith8346e522015-06-10 01:47:58 +00001558
1559 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1560 !D->defaultArgumentWasInherited();
1561 Record.push_back(OwnsDefaultArg);
1562 if (OwnsDefaultArg)
Richard Smith69c82bf2016-04-01 22:52:03 +00001563 Record.AddTypeSourceInfo(D->getDefaultArgumentInfo());
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001564
Sebastian Redl539c5062010-08-18 23:57:32 +00001565 Code = serialization::DECL_TEMPLATE_TYPE_PARM;
Chris Lattnerca025db2010-05-07 21:43:38 +00001566}
1567
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001568void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001569 // For an expanded parameter pack, record the number of expansion types here
Richard Smith1fde8ec2012-09-07 02:06:42 +00001570 // so that it's easier for deserialization to allocate the right amount of
1571 // memory.
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001572 if (D->isExpandedParameterPack())
1573 Record.push_back(D->getNumExpansionTypes());
1574
John McCallf4cd4f92011-02-09 01:13:10 +00001575 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001576 // TemplateParmPosition.
1577 Record.push_back(D->getDepth());
1578 Record.push_back(D->getPosition());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001579
1580 if (D->isExpandedParameterPack()) {
1581 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001582 Record.AddTypeRef(D->getExpansionType(I));
1583 Record.AddTypeSourceInfo(D->getExpansionTypeSourceInfo(I));
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001584 }
1585
1586 Code = serialization::DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK;
1587 } else {
1588 // Rest of NonTypeTemplateParmDecl.
1589 Record.push_back(D->isParameterPack());
Richard Smith8346e522015-06-10 01:47:58 +00001590 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1591 !D->defaultArgumentWasInherited();
1592 Record.push_back(OwnsDefaultArg);
1593 if (OwnsDefaultArg)
Richard Smith290d8012016-04-06 17:06:00 +00001594 Record.AddStmt(D->getDefaultArgument());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001595 Code = serialization::DECL_NON_TYPE_TEMPLATE_PARM;
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001596 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001597}
1598
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001599void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Richard Smith1fde8ec2012-09-07 02:06:42 +00001600 // For an expanded parameter pack, record the number of expansion types here
1601 // so that it's easier for deserialization to allocate the right amount of
1602 // memory.
1603 if (D->isExpandedParameterPack())
1604 Record.push_back(D->getNumExpansionTemplateParameters());
1605
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001606 VisitTemplateDecl(D);
1607 // TemplateParmPosition.
1608 Record.push_back(D->getDepth());
1609 Record.push_back(D->getPosition());
Richard Smith1fde8ec2012-09-07 02:06:42 +00001610
1611 if (D->isExpandedParameterPack()) {
1612 for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
1613 I != N; ++I)
Richard Smith69c82bf2016-04-01 22:52:03 +00001614 Record.AddTemplateParameterList(D->getExpansionTemplateParameters(I));
Richard Smith1fde8ec2012-09-07 02:06:42 +00001615 Code = serialization::DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK;
1616 } else {
1617 // Rest of TemplateTemplateParmDecl.
Richard Smith1fde8ec2012-09-07 02:06:42 +00001618 Record.push_back(D->isParameterPack());
Richard Smith8346e522015-06-10 01:47:58 +00001619 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1620 !D->defaultArgumentWasInherited();
1621 Record.push_back(OwnsDefaultArg);
1622 if (OwnsDefaultArg)
Richard Smith69c82bf2016-04-01 22:52:03 +00001623 Record.AddTemplateArgumentLoc(D->getDefaultArgument());
Richard Smith1fde8ec2012-09-07 02:06:42 +00001624 Code = serialization::DECL_TEMPLATE_TEMPLATE_PARM;
1625 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001626}
1627
Richard Smith3f1b5d02011-05-05 21:57:07 +00001628void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1629 VisitRedeclarableTemplateDecl(D);
1630 Code = serialization::DECL_TYPE_ALIAS_TEMPLATE;
1631}
1632
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001633void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001634 VisitDecl(D);
Richard Smith290d8012016-04-06 17:06:00 +00001635 Record.AddStmt(D->getAssertExpr());
Richard Smithded9c2e2012-07-11 22:37:56 +00001636 Record.push_back(D->isFailed());
Richard Smith290d8012016-04-06 17:06:00 +00001637 Record.AddStmt(D->getMessage());
Richard Smith69c82bf2016-04-01 22:52:03 +00001638 Record.AddSourceLocation(D->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001639 Code = serialization::DECL_STATIC_ASSERT;
Chris Lattnerca025db2010-05-07 21:43:38 +00001640}
1641
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001642/// Emit the DeclContext part of a declaration context decl.
Richard Smithf1c23dc2016-04-13 02:12:03 +00001643void ASTDeclWriter::VisitDeclContext(DeclContext *DC) {
1644 Record.AddOffset(Writer.WriteDeclContextLexicalBlock(Context, DC));
1645 Record.AddOffset(Writer.WriteDeclContextVisibleBlock(Context, DC));
Chris Lattner7099dbc2009-04-27 06:16:06 +00001646}
1647
Richard Smithd8a83712015-08-22 01:47:18 +00001648const Decl *ASTWriter::getFirstLocalDecl(const Decl *D) {
Richard Smith3864be72015-09-11 02:22:03 +00001649 assert(IsLocalDecl(D) && "expected a local declaration");
Richard Smithd8a83712015-08-22 01:47:18 +00001650
1651 const Decl *Canon = D->getCanonicalDecl();
Richard Smith3864be72015-09-11 02:22:03 +00001652 if (IsLocalDecl(Canon))
Richard Smithd8a83712015-08-22 01:47:18 +00001653 return Canon;
1654
1655 const Decl *&CacheEntry = FirstLocalDeclCache[Canon];
1656 if (CacheEntry)
1657 return CacheEntry;
1658
1659 for (const Decl *Redecl = D; Redecl; Redecl = Redecl->getPreviousDecl())
Richard Smith3864be72015-09-11 02:22:03 +00001660 if (IsLocalDecl(Redecl))
Richard Smithd8a83712015-08-22 01:47:18 +00001661 D = Redecl;
1662 return CacheEntry = D;
Richard Smith5fc18a92015-07-12 23:43:21 +00001663}
1664
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001665template <typename T>
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001666void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +00001667 T *First = D->getFirstDecl();
Richard Smith5a4737c2015-02-06 02:42:59 +00001668 T *MostRecent = First->getMostRecentDecl();
Richard Smithd8a83712015-08-22 01:47:18 +00001669 T *DAsT = static_cast<T *>(D);
Richard Smith5a4737c2015-02-06 02:42:59 +00001670 if (MostRecent != First) {
Richard Smithd8a83712015-08-22 01:47:18 +00001671 assert(isRedeclarableDeclKind(DAsT->getKind()) &&
Douglas Gregorfe732d52013-01-21 16:16:40 +00001672 "Not considered redeclarable?");
Richard Smith5a4737c2015-02-06 02:42:59 +00001673
Richard Smith69c82bf2016-04-01 22:52:03 +00001674 Record.AddDeclRef(First);
Richard Smithfe620d22015-03-05 23:24:12 +00001675
Richard Smithd8a83712015-08-22 01:47:18 +00001676 // Write out a list of local redeclarations of this declaration if it's the
1677 // first local declaration in the chain.
1678 const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1679 if (DAsT == FirstLocal) {
Richard Smithd8a83712015-08-22 01:47:18 +00001680 // Emit a list of all imported first declarations so that we can be sure
1681 // that all redeclarations visible to this module are before D in the
1682 // redecl chain.
1683 unsigned I = Record.size();
1684 Record.push_back(0);
1685 if (Writer.Chain)
1686 AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1687 // This is the number of imported first declarations + 1.
1688 Record[I] = Record.size() - I;
Richard Smithd61d4ac2015-08-22 20:13:39 +00001689
1690 // Collect the set of local redeclarations of this declaration, from
1691 // newest to oldest.
Richard Smith69c82bf2016-04-01 22:52:03 +00001692 ASTWriter::RecordData LocalRedecls;
1693 ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls);
Richard Smithd61d4ac2015-08-22 20:13:39 +00001694 for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1695 Prev != FirstLocal; Prev = Prev->getPreviousDecl())
1696 if (!Prev->isFromASTFile())
Richard Smith69c82bf2016-04-01 22:52:03 +00001697 LocalRedeclWriter.AddDeclRef(Prev);
Richard Smithd61d4ac2015-08-22 20:13:39 +00001698
1699 // If we have any redecls, write them now as a separate record preceding
1700 // the declaration itself.
1701 if (LocalRedecls.empty())
1702 Record.push_back(0);
Richard Smithf1c23dc2016-04-13 02:12:03 +00001703 else
1704 Record.AddOffset(LocalRedeclWriter.Emit(LOCAL_REDECLARATIONS));
Richard Smithd8a83712015-08-22 01:47:18 +00001705 } else {
1706 Record.push_back(0);
Richard Smith69c82bf2016-04-01 22:52:03 +00001707 Record.AddDeclRef(FirstLocal);
Richard Smithfe620d22015-03-05 23:24:12 +00001708 }
Douglas Gregor358cd442012-01-15 16:58:34 +00001709
1710 // Make sure that we serialize both the previous and the most-recent
1711 // declarations, which (transitively) ensures that all declarations in the
1712 // chain get serialized.
Richard Smith5a4737c2015-02-06 02:42:59 +00001713 //
1714 // FIXME: This is not correct; when we reach an imported declaration we
1715 // won't emit its previous declaration.
Richard Smith5fc18a92015-07-12 23:43:21 +00001716 (void)Writer.GetDeclRef(D->getPreviousDecl());
Richard Smith5a4737c2015-02-06 02:42:59 +00001717 (void)Writer.GetDeclRef(MostRecent);
Douglas Gregor358cd442012-01-15 16:58:34 +00001718 } else {
1719 // We use the sentinel value 0 to indicate an only declaration.
1720 Record.push_back(0);
Douglas Gregor9f562c82011-12-19 15:27:36 +00001721 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001722}
Chris Lattner7099dbc2009-04-27 06:16:06 +00001723
Alexey Bataeva769e072013-03-22 06:34:35 +00001724void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
1725 Record.push_back(D->varlist_size());
1726 VisitDecl(D);
Aaron Ballman2205d2a2014-03-14 15:55:35 +00001727 for (auto *I : D->varlists())
Richard Smith290d8012016-04-06 17:06:00 +00001728 Record.AddStmt(I);
Alexey Bataeva769e072013-03-22 06:34:35 +00001729 Code = serialization::DECL_OMP_THREADPRIVATE;
1730}
1731
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00001732void ASTDeclWriter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
Alexey Bataevc5b1d322016-03-04 09:22:22 +00001733 VisitValueDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001734 Record.AddSourceLocation(D->getLocStart());
Richard Smith290d8012016-04-06 17:06:00 +00001735 Record.AddStmt(D->getCombiner());
1736 Record.AddStmt(D->getInitializer());
Alexey Bataev070f43a2017-09-06 14:49:58 +00001737 Record.push_back(D->getInitializerKind());
Richard Smith69c82bf2016-04-01 22:52:03 +00001738 Record.AddDeclRef(D->getPrevDeclInScope());
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00001739 Code = serialization::DECL_OMP_DECLARE_REDUCTION;
1740}
1741
Alexey Bataev4244be22016-02-11 05:35:55 +00001742void ASTDeclWriter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
Alexey Bataev90c228f2016-02-08 09:29:13 +00001743 VisitVarDecl(D);
Alexey Bataev4244be22016-02-11 05:35:55 +00001744 Code = serialization::DECL_OMP_CAPTUREDEXPR;
Alexey Bataev90c228f2016-02-08 09:29:13 +00001745}
1746
Chris Lattner7099dbc2009-04-27 06:16:06 +00001747//===----------------------------------------------------------------------===//
Sebastian Redl55c0ad52010-08-18 23:56:21 +00001748// ASTWriter Implementation
Chris Lattner7099dbc2009-04-27 06:16:06 +00001749//===----------------------------------------------------------------------===//
1750
Richard Smith01b2cb42014-07-26 06:37:51 +00001751void ASTWriter::WriteDeclAbbrevs() {
Chris Lattner258172e2009-04-27 07:35:58 +00001752 using namespace llvm;
Chris Lattner258172e2009-04-27 07:35:58 +00001753
David Blaikieb44f0bf2017-01-04 22:36:43 +00001754 std::shared_ptr<BitCodeAbbrev> Abv;
Douglas Gregor03412ba2011-06-03 02:27:19 +00001755
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001756 // Abbreviation for DECL_FIELD
David Blaikieb44f0bf2017-01-04 22:36:43 +00001757 Abv = std::make_shared<BitCodeAbbrev>();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001758 Abv->Add(BitCodeAbbrevOp(serialization::DECL_FIELD));
1759 // Decl
1760 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001761 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001762 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001763 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1764 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1765 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1766 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001767 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001768 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001769 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001770 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001771 // NamedDecl
1772 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1773 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001774 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001775 // ValueDecl
1776 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1777 // DeclaratorDecl
1778 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1779 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Richard Smithc23d7342018-06-29 20:46:25 +00001780 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001781 // FieldDecl
1782 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
Richard Smith6b8e3c02017-08-28 00:28:14 +00001783 Abv->Add(BitCodeAbbrevOp(0)); // InitStyle
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001784 // Type Source Info
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001785 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1786 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
David Blaikieb44f0bf2017-01-04 22:36:43 +00001787 DeclFieldAbbrev = Stream.EmitAbbrev(std::move(Abv));
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001788
1789 // Abbreviation for DECL_OBJC_IVAR
David Blaikieb44f0bf2017-01-04 22:36:43 +00001790 Abv = std::make_shared<BitCodeAbbrev>();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001791 Abv->Add(BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR));
1792 // Decl
1793 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001794 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001795 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001796 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1797 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1798 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1799 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001800 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001801 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001802 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001803 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001804 // NamedDecl
1805 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1806 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001807 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001808 // ValueDecl
1809 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1810 // DeclaratorDecl
1811 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1812 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Richard Smithc23d7342018-06-29 20:46:25 +00001813 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001814 // FieldDecl
1815 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
Richard Smith6b8e3c02017-08-28 00:28:14 +00001816 Abv->Add(BitCodeAbbrevOp(0)); // InitStyle
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001817 // ObjC Ivar
1818 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl
1819 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize
1820 // Type Source Info
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001821 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1822 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
David Blaikieb44f0bf2017-01-04 22:36:43 +00001823 DeclObjCIvarAbbrev = Stream.EmitAbbrev(std::move(Abv));
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001824
1825 // Abbreviation for DECL_ENUM
David Blaikieb44f0bf2017-01-04 22:36:43 +00001826 Abv = std::make_shared<BitCodeAbbrev>();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001827 Abv->Add(BitCodeAbbrevOp(serialization::DECL_ENUM));
Douglas Gregor3e300102011-10-26 17:53:41 +00001828 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001829 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Chris Lattner258172e2009-04-27 07:35:58 +00001830 // Decl
1831 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001832 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001833 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Chris Lattner258172e2009-04-27 07:35:58 +00001834 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1835 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
Douglas Gregorc9c02ed2009-06-19 23:52:42 +00001836 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +00001837 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001838 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Chris Lattner258172e2009-04-27 07:35:58 +00001839 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001840 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001841 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Douglas Gregor03412ba2011-06-03 02:27:19 +00001842 // NamedDecl
1843 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1844 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001845 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001846 // TypeDecl
1847 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1848 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001849 // TagDecl
1850 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
1851 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
John McCallf937c022011-10-07 06:10:15 +00001852 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001853 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +00001854 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
David Blaikiea8d23ce2013-07-14 01:07:41 +00001855 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001856 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Argyrios Kyrtzidisd798c052016-07-15 18:11:33 +00001857 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Richard Smith70d58502014-08-30 00:04:23 +00001858 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001859 // EnumDecl
1860 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddTypeRef
1861 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IntegerType
1862 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getPromotionType
1863 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumPositiveBits
1864 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumNegativeBits
1865 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScoped
1866 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScopedUsingClassTag
1867 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isFixed
1868 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedMembEnum
1869 // DC
1870 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
1871 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
David Blaikieb44f0bf2017-01-04 22:36:43 +00001872 DeclEnumAbbrev = Stream.EmitAbbrev(std::move(Abv));
Mike Stump11289f42009-09-09 15:08:12 +00001873
Douglas Gregor03412ba2011-06-03 02:27:19 +00001874 // Abbreviation for DECL_RECORD
David Blaikieb44f0bf2017-01-04 22:36:43 +00001875 Abv = std::make_shared<BitCodeAbbrev>();
Douglas Gregor03412ba2011-06-03 02:27:19 +00001876 Abv->Add(BitCodeAbbrevOp(serialization::DECL_RECORD));
Douglas Gregor3e300102011-10-26 17:53:41 +00001877 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001878 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Douglas Gregor03412ba2011-06-03 02:27:19 +00001879 // Decl
1880 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001881 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001882 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Douglas Gregor03412ba2011-06-03 02:27:19 +00001883 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1884 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1885 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1886 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001887 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Douglas Gregor03412ba2011-06-03 02:27:19 +00001888 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001889 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001890 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Douglas Gregor03412ba2011-06-03 02:27:19 +00001891 // NamedDecl
1892 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1893 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001894 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Douglas Gregor03412ba2011-06-03 02:27:19 +00001895 // TypeDecl
1896 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1897 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
Douglas Gregor03412ba2011-06-03 02:27:19 +00001898 // TagDecl
1899 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
1900 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
John McCallf937c022011-10-07 06:10:15 +00001901 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
Douglas Gregor03412ba2011-06-03 02:27:19 +00001902 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +00001903 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
David Blaikiea8d23ce2013-07-14 01:07:41 +00001904 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
Douglas Gregor03412ba2011-06-03 02:27:19 +00001905 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Argyrios Kyrtzidisd798c052016-07-15 18:11:33 +00001906 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Richard Smith70d58502014-08-30 00:04:23 +00001907 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
Douglas Gregor03412ba2011-06-03 02:27:19 +00001908 // RecordDecl
1909 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // FlexibleArrayMember
1910 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // AnonymousStructUnion
1911 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasObjectMember
Fariborz Jahanian78652202013-01-25 23:57:05 +00001912 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasVolatileMember
Akira Hatanaka34fb2642018-03-13 18:58:25 +00001913
1914 // isNonTrivialToPrimitiveDefaultInitialize
1915 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
1916 // isNonTrivialToPrimitiveCopy
1917 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
1918 // isNonTrivialToPrimitiveDestroy
1919 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
Akira Hatanakafcbe17c2018-03-28 21:13:14 +00001920 // isParamDestroyedInCallee
1921 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
Akira Hatanakae6313ac2018-04-09 22:48:22 +00001922 // getArgPassingRestrictions
1923 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2));
Akira Hatanaka34fb2642018-03-13 18:58:25 +00001924
Douglas Gregor03412ba2011-06-03 02:27:19 +00001925 // DC
1926 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
1927 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
David Blaikieb44f0bf2017-01-04 22:36:43 +00001928 DeclRecordAbbrev = Stream.EmitAbbrev(std::move(Abv));
Douglas Gregor03412ba2011-06-03 02:27:19 +00001929
1930 // Abbreviation for DECL_PARM_VAR
David Blaikieb44f0bf2017-01-04 22:36:43 +00001931 Abv = std::make_shared<BitCodeAbbrev>();
Douglas Gregor03412ba2011-06-03 02:27:19 +00001932 Abv->Add(BitCodeAbbrevOp(serialization::DECL_PARM_VAR));
Douglas Gregor3e300102011-10-26 17:53:41 +00001933 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001934 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Douglas Gregor03412ba2011-06-03 02:27:19 +00001935 // Decl
1936 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001937 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001938 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Douglas Gregor03412ba2011-06-03 02:27:19 +00001939 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1940 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1941 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1942 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001943 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Douglas Gregor03412ba2011-06-03 02:27:19 +00001944 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001945 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001946 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Chris Lattner258172e2009-04-27 07:35:58 +00001947 // NamedDecl
1948 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1949 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001950 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Chris Lattner258172e2009-04-27 07:35:58 +00001951 // ValueDecl
1952 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +00001953 // DeclaratorDecl
Abramo Bagnaradff19302011-03-08 08:55:46 +00001954 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00001955 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Richard Smithc23d7342018-06-29 20:46:25 +00001956 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
Chris Lattner258172e2009-04-27 07:35:58 +00001957 // VarDecl
Vassil Vassilevd1a88132016-10-06 13:04:54 +00001958 Abv->Add(BitCodeAbbrevOp(0)); // SClass
1959 Abv->Add(BitCodeAbbrevOp(0)); // TSCSpec
1960 Abv->Add(BitCodeAbbrevOp(0)); // InitStyle
Richard Smith88581592013-02-12 05:48:23 +00001961 Abv->Add(BitCodeAbbrevOp(0)); // Linkage
Chris Lattner258172e2009-04-27 07:35:58 +00001962 Abv->Add(BitCodeAbbrevOp(0)); // HasInit
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001963 Abv->Add(BitCodeAbbrevOp(0)); // HasMemberSpecializationInfo
Chris Lattner258172e2009-04-27 07:35:58 +00001964 // ParmVarDecl
John McCall82490832011-05-02 00:30:12 +00001965 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsObjCMethodParameter
John McCall8fb0d9d2011-05-01 22:35:37 +00001966 Abv->Add(BitCodeAbbrevOp(0)); // ScopeDepth
1967 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex
Chris Lattner258172e2009-04-27 07:35:58 +00001968 Abv->Add(BitCodeAbbrevOp(0)); // ObjCDeclQualifier
John McCall6a014d52011-03-09 04:22:44 +00001969 Abv->Add(BitCodeAbbrevOp(0)); // KNRPromoted
John McCallf3cd6652010-03-12 18:31:32 +00001970 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedDefaultArg
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +00001971 Abv->Add(BitCodeAbbrevOp(0)); // HasUninstantiatedDefaultArg
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001972 // Type Source Info
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001973 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1974 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
David Blaikieb44f0bf2017-01-04 22:36:43 +00001975 DeclParmVarAbbrev = Stream.EmitAbbrev(std::move(Abv));
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001976
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00001977 // Abbreviation for DECL_TYPEDEF
David Blaikieb44f0bf2017-01-04 22:36:43 +00001978 Abv = std::make_shared<BitCodeAbbrev>();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001979 Abv->Add(BitCodeAbbrevOp(serialization::DECL_TYPEDEF));
Douglas Gregor05f10352011-12-17 23:38:30 +00001980 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001981 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001982 // Decl
1983 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001984 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001985 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001986 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1987 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
Richard Smith01b2cb42014-07-26 06:37:51 +00001988 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isUsed
1989 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001990 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Richard Smith01b2cb42014-07-26 06:37:51 +00001991 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001992 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001993 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001994 // NamedDecl
1995 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1996 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001997 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001998 // TypeDecl
1999 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2000 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
2001 // TypedefDecl
2002 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2003 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
David Blaikieb44f0bf2017-01-04 22:36:43 +00002004 DeclTypedefAbbrev = Stream.EmitAbbrev(std::move(Abv));
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002005
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00002006 // Abbreviation for DECL_VAR
David Blaikieb44f0bf2017-01-04 22:36:43 +00002007 Abv = std::make_shared<BitCodeAbbrev>();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002008 Abv->Add(BitCodeAbbrevOp(serialization::DECL_VAR));
Douglas Gregor3e300102011-10-26 17:53:41 +00002009 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00002010 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002011 // Decl
2012 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00002013 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00002014 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002015 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
2016 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
2017 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
2018 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00002019 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002020 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00002021 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00002022 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002023 // NamedDecl
2024 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2025 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00002026 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002027 // ValueDecl
2028 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2029 // DeclaratorDecl
2030 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
2031 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Richard Smithc23d7342018-06-29 20:46:25 +00002032 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002033 // VarDecl
Vassil Vassilevd1a88132016-10-06 13:04:54 +00002034 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // SClass
2035 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // TSCSpec
2036 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // InitStyle
Richard Smithedbc6e92016-10-14 21:41:24 +00002037 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsThisDeclarationADemotedDefinition
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002038 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isExceptionVariable
Taiju Tsuiki3be68e12018-06-19 05:35:30 +00002039 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isNRVOVariable
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002040 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCXXForRangeDecl
George Karpenkovec38cf72018-03-29 00:56:24 +00002041 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isObjCForDecl
John McCalld4631322011-06-17 06:42:21 +00002042 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong
Richard Smith62f19e72016-06-25 00:15:56 +00002043 Abv->Add(BitCodeAbbrevOp(0)); // isInline
2044 Abv->Add(BitCodeAbbrevOp(0)); // isInlineSpecified
Douglas Gregor12cda632012-09-20 23:43:29 +00002045 Abv->Add(BitCodeAbbrevOp(0)); // isConstexpr
Richard Smithbb13c9a2013-09-28 04:02:39 +00002046 Abv->Add(BitCodeAbbrevOp(0)); // isInitCapture
Richard Smith1c34fb72013-08-13 18:18:50 +00002047 Abv->Add(BitCodeAbbrevOp(0)); // isPrevDeclInSameScope
Alexey Bataev56223232017-06-09 13:40:18 +00002048 Abv->Add(BitCodeAbbrevOp(0)); // ImplicitParamKind
Rafael Espindola50df3a02013-05-25 17:16:20 +00002049 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
Vassil Vassilevd1a88132016-10-06 13:04:54 +00002050 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // IsInitICE (local)
2051 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // VarKind (local enum)
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002052 // Type Source Info
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002053 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2054 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
David Blaikieb44f0bf2017-01-04 22:36:43 +00002055 DeclVarAbbrev = Stream.EmitAbbrev(std::move(Abv));
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002056
Richard Smith01b2cb42014-07-26 06:37:51 +00002057 // Abbreviation for DECL_CXX_METHOD
David Blaikieb44f0bf2017-01-04 22:36:43 +00002058 Abv = std::make_shared<BitCodeAbbrev>();
Richard Smith01b2cb42014-07-26 06:37:51 +00002059 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CXX_METHOD));
2060 // RedeclarableDecl
2061 Abv->Add(BitCodeAbbrevOp(0)); // CanonicalDecl
2062 // Decl
2063 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00002064 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Richard Smith01b2cb42014-07-26 06:37:51 +00002065 Abv->Add(BitCodeAbbrevOp(0)); // Invalid
2066 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
2067 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Implicit
2068 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Used
2069 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Referenced
2070 Abv->Add(BitCodeAbbrevOp(0)); // InObjCContainer
2071 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Access
2072 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ModulePrivate
2073 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2074 // NamedDecl
2075 Abv->Add(BitCodeAbbrevOp(DeclarationName::Identifier)); // NameKind
2076 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Identifier
Richard Smith2b560572015-02-07 03:11:11 +00002077 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Richard Smith01b2cb42014-07-26 06:37:51 +00002078 // ValueDecl
2079 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2080 // DeclaratorDecl
2081 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerLocStart
2082 Abv->Add(BitCodeAbbrevOp(0)); // HasExtInfo
Richard Smithc23d7342018-06-29 20:46:25 +00002083 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
Richard Smith01b2cb42014-07-26 06:37:51 +00002084 // FunctionDecl
2085 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS
2086 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // StorageClass
2087 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Inline
2088 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InlineSpecified
Richard Smith78e3d702017-02-10 01:32:04 +00002089 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ExplicitSpecified
Richard Smith01b2cb42014-07-26 06:37:51 +00002090 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // VirtualAsWritten
2091 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Pure
2092 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedProto
2093 Abv->Add(BitCodeAbbrevOp(1)); // HasWrittenProto
Richard Smith72625c22015-02-06 23:20:21 +00002094 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Deleted
Richard Smith01b2cb42014-07-26 06:37:51 +00002095 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Trivial
Akira Hatanaka02914dc2018-02-05 20:23:22 +00002096 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // TrivialForCall
Richard Smith01b2cb42014-07-26 06:37:51 +00002097 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Defaulted
2098 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ExplicitlyDefaulted
2099 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ImplicitReturnZero
2100 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Constexpr
Reid Kleckner0d157382017-01-10 21:27:03 +00002101 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // UsesSEHTry
Richard Smith01b2cb42014-07-26 06:37:51 +00002102 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // SkippedBody
Erich Keane281d20b2018-01-08 21:34:17 +00002103 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // MultiVersion
Richard Smith01b2cb42014-07-26 06:37:51 +00002104 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // LateParsed
2105 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
2106 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LocEnd
Richard Trieue6caa262017-12-23 00:41:01 +00002107 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // ODRHash
Richard Smith01b2cb42014-07-26 06:37:51 +00002108 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // TemplateKind
2109 // This Array slurps the rest of the record. Fortunately we want to encode
2110 // (nearly) all the remaining (variable number of) fields in the same way.
2111 //
2112 // This is the function template information if any, then
2113 // NumParams and Params[] from FunctionDecl, and
2114 // NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl.
2115 //
2116 // Add an AbbrevOp for 'size then elements' and use it here.
2117 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2118 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
David Blaikieb44f0bf2017-01-04 22:36:43 +00002119 DeclCXXMethodAbbrev = Stream.EmitAbbrev(std::move(Abv));
Richard Smith01b2cb42014-07-26 06:37:51 +00002120
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00002121 // Abbreviation for EXPR_DECL_REF
David Blaikieb44f0bf2017-01-04 22:36:43 +00002122 Abv = std::make_shared<BitCodeAbbrev>();
Douglas Gregor03412ba2011-06-03 02:27:19 +00002123 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_DECL_REF));
2124 //Stmt
2125 //Expr
2126 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002127 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2128 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2129 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002130 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2131 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2132 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2133 //DeclRefExpr
2134 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HasQualifier
2135 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //GetDeclFound
2136 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ExplicitTemplateArgs
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002137 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HadMultipleCandidates
Alexey Bataev19acc3d2015-01-12 10:17:46 +00002138 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2139 1)); // RefersToEnclosingVariableOrCapture
Douglas Gregor03412ba2011-06-03 02:27:19 +00002140 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef
2141 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
David Blaikieb44f0bf2017-01-04 22:36:43 +00002142 DeclRefExprAbbrev = Stream.EmitAbbrev(std::move(Abv));
Douglas Gregor03412ba2011-06-03 02:27:19 +00002143
2144 // Abbreviation for EXPR_INTEGER_LITERAL
David Blaikieb44f0bf2017-01-04 22:36:43 +00002145 Abv = std::make_shared<BitCodeAbbrev>();
Douglas Gregor03412ba2011-06-03 02:27:19 +00002146 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL));
2147 //Stmt
2148 //Expr
2149 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002150 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2151 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2152 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002153 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2154 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2155 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2156 //Integer Literal
2157 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2158 Abv->Add(BitCodeAbbrevOp(32)); // Bit Width
2159 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value
David Blaikieb44f0bf2017-01-04 22:36:43 +00002160 IntegerLiteralAbbrev = Stream.EmitAbbrev(std::move(Abv));
Douglas Gregor03412ba2011-06-03 02:27:19 +00002161
2162 // Abbreviation for EXPR_CHARACTER_LITERAL
David Blaikieb44f0bf2017-01-04 22:36:43 +00002163 Abv = std::make_shared<BitCodeAbbrev>();
Douglas Gregor03412ba2011-06-03 02:27:19 +00002164 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL));
2165 //Stmt
2166 //Expr
2167 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002168 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2169 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2170 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002171 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2172 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2173 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
Jonathan D. Turnerd09655f2011-06-03 21:46:44 +00002174 //Character Literal
Douglas Gregor03412ba2011-06-03 02:27:19 +00002175 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue
2176 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
Aaron Ballman9a17c852016-01-07 20:59:26 +00002177 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // getKind
David Blaikieb44f0bf2017-01-04 22:36:43 +00002178 CharacterLiteralAbbrev = Stream.EmitAbbrev(std::move(Abv));
Douglas Gregor03412ba2011-06-03 02:27:19 +00002179
Richard Smitha27c26e2014-07-27 04:19:32 +00002180 // Abbreviation for EXPR_IMPLICIT_CAST
David Blaikieb44f0bf2017-01-04 22:36:43 +00002181 Abv = std::make_shared<BitCodeAbbrev>();
Richard Smitha27c26e2014-07-27 04:19:32 +00002182 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_IMPLICIT_CAST));
2183 // Stmt
2184 // Expr
2185 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2186 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2187 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2188 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
2189 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2190 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2191 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2192 // CastExpr
2193 Abv->Add(BitCodeAbbrevOp(0)); // PathSize
2194 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 6)); // CastKind
2195 // ImplicitCastExpr
David Blaikieb44f0bf2017-01-04 22:36:43 +00002196 ExprImplicitCastAbbrev = Stream.EmitAbbrev(std::move(Abv));
Richard Smitha27c26e2014-07-27 04:19:32 +00002197
David Blaikieb44f0bf2017-01-04 22:36:43 +00002198 Abv = std::make_shared<BitCodeAbbrev>();
Sebastian Redl539c5062010-08-18 23:57:32 +00002199 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL));
Sebastian Redl66c5eef2010-07-27 00:17:23 +00002200 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
David Blaikieb44f0bf2017-01-04 22:36:43 +00002201 DeclContextLexicalAbbrev = Stream.EmitAbbrev(std::move(Abv));
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002202
David Blaikieb44f0bf2017-01-04 22:36:43 +00002203 Abv = std::make_shared<BitCodeAbbrev>();
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002204 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE));
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002205 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
David Blaikieb44f0bf2017-01-04 22:36:43 +00002206 DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(std::move(Abv));
Chris Lattner258172e2009-04-27 07:35:58 +00002207}
2208
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002209/// isRequiredDecl - Check if this is a "required" Decl, which must be seen by
2210/// consumers of the AST.
2211///
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002212/// Such decls will always be deserialized from the AST file, so we would like
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002213/// this to be as restrictive as possible. Currently the predicate is driven by
2214/// code generation requirements, if other clients have a different notion of
2215/// what is "required" then we may have to consider an alternate scheme where
2216/// clients can iterate over the top-level decls and get information on them,
2217/// without necessary deserializing them. We could explicitly require such
2218/// clients to use a separate API call to "realize" the decl. This should be
2219/// relatively painless since they would presumably only do it for top-level
2220/// decls.
Richard Smithc52efa72015-08-19 02:30:28 +00002221static bool isRequiredDecl(const Decl *D, ASTContext &Context,
David Blaikiee6b7c282017-04-11 20:46:34 +00002222 bool WritingModule) {
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00002223 // An ObjCMethodDecl is never considered as "required" because its
2224 // implementation container always is.
2225
Dmitry Polukhin0b0da292016-04-06 11:38:59 +00002226 // File scoped assembly or obj-c or OMP declare target implementation must be
2227 // seen.
2228 if (isa<FileScopeAsmDecl>(D) || isa<ObjCImplDecl>(D) ||
2229 D->hasAttr<OMPDeclareTargetDeclAttr>())
Richard Smithc52efa72015-08-19 02:30:28 +00002230 return true;
2231
Richard Smithdc1f0422016-07-20 19:10:16 +00002232 if (WritingModule && (isa<VarDecl>(D) || isa<ImportDecl>(D))) {
2233 // These declarations are part of the module initializer, and are emitted
2234 // if and when the module is imported, rather than being emitted eagerly.
2235 return false;
2236 }
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002237
David Blaikiee6b7c282017-04-11 20:46:34 +00002238 return Context.DeclMustBeEmitted(D);
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002239}
2240
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002241void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) {
Jordan Rose1e879d82018-03-23 00:07:18 +00002242 PrettyDeclStackTraceEntry CrashInfo(Context, D, SourceLocation(),
2243 "serializing");
2244
Douglas Gregorb3163e52012-01-05 22:33:30 +00002245 // Determine the ID for this declaration.
2246 serialization::DeclID ID;
Douglas Gregor7dd37e52015-11-03 01:20:54 +00002247 assert(!D->isFromASTFile() && "should not be emitting imported decl");
2248 serialization::DeclID &IDR = DeclIDs[D];
2249 if (IDR == 0)
2250 IDR = NextDeclID++;
Douglas Gregorb3163e52012-01-05 22:33:30 +00002251
Douglas Gregor7dd37e52015-11-03 01:20:54 +00002252 ID = IDR;
Argyrios Kyrtzidisbf6c3392012-03-22 16:08:04 +00002253
Richard Smith34da7512016-03-27 05:52:25 +00002254 assert(ID >= FirstDeclID && "invalid decl ID");
Douglas Gregorb3163e52012-01-05 22:33:30 +00002255
Richard Smith69c82bf2016-04-01 22:52:03 +00002256 RecordData Record;
2257 ASTDeclWriter W(*this, Context, Record);
2258
Richard Smithd61d4ac2015-08-22 20:13:39 +00002259 // Build a record for this declaration
Richard Smithd61d4ac2015-08-22 20:13:39 +00002260 W.Visit(D);
Richard Smithd61d4ac2015-08-22 20:13:39 +00002261
Richard Smith69c82bf2016-04-01 22:52:03 +00002262 // Emit this declaration to the bitstream.
2263 uint64_t Offset = W.Emit(D);
Douglas Gregor12bfa382009-10-17 00:13:19 +00002264
Richard Smith34da7512016-03-27 05:52:25 +00002265 // Record the offset for this declaration
2266 SourceLocation Loc = D->getLocation();
Richard Smith69c82bf2016-04-01 22:52:03 +00002267 unsigned Index = ID - FirstDeclID;
Richard Smith34da7512016-03-27 05:52:25 +00002268 if (DeclOffsets.size() == Index)
Richard Smith69c82bf2016-04-01 22:52:03 +00002269 DeclOffsets.push_back(DeclOffset(Loc, Offset));
Richard Smith34da7512016-03-27 05:52:25 +00002270 else if (DeclOffsets.size() < Index) {
Richard Smith69c82bf2016-04-01 22:52:03 +00002271 // FIXME: Can/should this happen?
Richard Smith34da7512016-03-27 05:52:25 +00002272 DeclOffsets.resize(Index+1);
2273 DeclOffsets[Index].setLocation(Loc);
Richard Smith69c82bf2016-04-01 22:52:03 +00002274 DeclOffsets[Index].BitOffset = Offset;
2275 } else {
2276 llvm_unreachable("declarations should be emitted in ID order");
Douglas Gregor12bfa382009-10-17 00:13:19 +00002277 }
2278
Richard Smith34da7512016-03-27 05:52:25 +00002279 SourceManager &SM = Context.getSourceManager();
2280 if (Loc.isValid() && SM.isLocalSourceLocation(Loc))
2281 associateDeclWithFile(D, ID);
2282
Ben Langmuir332aafe2014-01-31 01:06:56 +00002283 // Note declarations that should be deserialized eagerly so that we can add
2284 // them to a record in the AST file later.
David Blaikiee6b7c282017-04-11 20:46:34 +00002285 if (isRequiredDecl(D, Context, WritingModule))
Ben Langmuir332aafe2014-01-31 01:06:56 +00002286 EagerlyDeserializedDecls.push_back(ID);
Chris Lattner7099dbc2009-04-27 06:16:06 +00002287}
Richard Smithd28ac5b2014-03-22 23:33:22 +00002288
Richard Smith290d8012016-04-06 17:06:00 +00002289void ASTRecordWriter::AddFunctionDefinition(const FunctionDecl *FD) {
2290 // Switch case IDs are per function body.
2291 Writer->ClearSwitchCaseIDs();
Richard Smithd28ac5b2014-03-22 23:33:22 +00002292
Richard Smith290d8012016-04-06 17:06:00 +00002293 assert(FD->doesThisDeclarationHaveABody());
Richard Smithb51cf112017-07-06 00:30:00 +00002294 bool ModulesCodegen = false;
2295 if (Writer->WritingModule && !FD->isDependentContext()) {
David Blaikie08267292017-11-02 21:55:40 +00002296 Optional<GVALinkage> Linkage;
2297 if (Writer->WritingModule->Kind == Module::ModuleInterfaceUnit) {
2298 // When building a C++ Modules TS module interface unit, a strong
2299 // definition in the module interface is provided by the compilation of
2300 // that module interface unit, not by its users. (Inline functions are
2301 // still emitted in module users.)
2302 Linkage = Writer->Context->GetGVALinkageForFunction(FD);
2303 ModulesCodegen = *Linkage == GVA_StrongExternal;
2304 }
2305 if (Writer->Context->getLangOpts().ModulesCodegen) {
2306 // Under -fmodules-codegen, codegen is performed for all non-internal,
2307 // non-always_inline functions.
David Blaikie1524e672017-11-02 22:28:50 +00002308 if (!FD->hasAttr<AlwaysInlineAttr>()) {
2309 if (!Linkage)
2310 Linkage = Writer->Context->GetGVALinkageForFunction(FD);
2311 ModulesCodegen = *Linkage != GVA_Internal;
2312 }
David Blaikie08267292017-11-02 21:55:40 +00002313 }
Richard Smithb51cf112017-07-06 00:30:00 +00002314 }
David Blaikief63556d2017-04-12 20:58:33 +00002315 Record->push_back(ModulesCodegen);
2316 if (ModulesCodegen)
David Blaikiee6b7c282017-04-11 20:46:34 +00002317 Writer->ModularCodegenDecls.push_back(Writer->GetDeclRef(FD));
Richard Smith290d8012016-04-06 17:06:00 +00002318 if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
2319 Record->push_back(CD->getNumCtorInitializers());
2320 if (CD->getNumCtorInitializers())
Richard Smithaa165cf2016-04-13 21:57:08 +00002321 AddCXXCtorInitializers(
Richard Smith290d8012016-04-06 17:06:00 +00002322 llvm::makeArrayRef(CD->init_begin(), CD->init_end()));
2323 }
2324 AddStmt(FD->getBody());
Richard Smithd28ac5b2014-03-22 23:33:22 +00002325}