blob: f7d89299e140c837923b362fae0369411ed58cab [file] [log] [blame]
Sebastian Redld6522cf2010-08-18 23:56:31 +00001//===--- ASTWriterDecl.cpp - Declaration Serialization --------------------===//
Chris Lattner7099dbc2009-04-27 06:16:06 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Chris Lattner7099dbc2009-04-27 06:16:06 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file implements serialization for Declarations.
10//
11//===----------------------------------------------------------------------===//
12
Sebastian Redlfa1f3702011-04-24 16:28:13 +000013#include "ASTCommon.h"
Reid Kleckner60573ae2019-11-15 17:31:55 -080014#include "clang/AST/Attr.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"
Kelvin Li1408f912018-09-26 04:28:39 +000020#include "clang/AST/OpenMPClause.h"
Jordan Rose1e879d82018-03-23 00:07:18 +000021#include "clang/AST/PrettyDeclStackTrace.h"
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +000022#include "clang/Basic/SourceManager.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000023#include "clang/Serialization/ASTReader.h"
John McCall2ac702a2019-12-14 03:17:03 -050024#include "clang/Serialization/ASTRecordWriter.h"
Francis Visoiu Mistrihe0308272019-07-03 22:40:07 +000025#include "llvm/Bitstream/BitstreamWriter.h"
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +000026#include "llvm/Support/ErrorHandling.h"
Chris Lattner7099dbc2009-04-27 06:16:06 +000027using namespace clang;
Sebastian Redlfa1f3702011-04-24 16:28:13 +000028using namespace serialization;
Chris Lattner7099dbc2009-04-27 06:16:06 +000029
30//===----------------------------------------------------------------------===//
31// Declaration serialization
32//===----------------------------------------------------------------------===//
33
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000034namespace clang {
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000035 class ASTDeclWriter : public DeclVisitor<ASTDeclWriter, void> {
Sebastian Redl55c0ad52010-08-18 23:56:21 +000036 ASTWriter &Writer;
Chris Lattner7099dbc2009-04-27 06:16:06 +000037 ASTContext &Context;
Richard Smith69c82bf2016-04-01 22:52:03 +000038 ASTRecordWriter Record;
Chris Lattner7099dbc2009-04-27 06:16:06 +000039
Sebastian Redl539c5062010-08-18 23:57:32 +000040 serialization::DeclCode Code;
Chris Lattner258172e2009-04-27 07:35:58 +000041 unsigned AbbrevToUse;
Chris Lattner7099dbc2009-04-27 06:16:06 +000042
Richard Smith69c82bf2016-04-01 22:52:03 +000043 public:
44 ASTDeclWriter(ASTWriter &Writer, ASTContext &Context,
45 ASTWriter::RecordDataImpl &Record)
46 : Writer(Writer), Context(Context), Record(Writer, Record),
47 Code((serialization::DeclCode)0), AbbrevToUse(0) {}
48
49 uint64_t Emit(Decl *D) {
50 if (!Code)
51 llvm::report_fatal_error(StringRef("unexpected declaration kind '") +
52 D->getDeclKindName() + "'");
Richard Smith645d2cf2016-04-14 00:29:55 +000053 return Record.Emit(Code, AbbrevToUse);
Chris Lattner258172e2009-04-27 07:35:58 +000054 }
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000055
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +000056 void Visit(Decl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000057
58 void VisitDecl(Decl *D);
Nico Weber66220292016-03-02 17:28:48 +000059 void VisitPragmaCommentDecl(PragmaCommentDecl *D);
Nico Webercbbaeb12016-03-02 19:28:54 +000060 void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000061 void VisitTranslationUnitDecl(TranslationUnitDecl *D);
62 void VisitNamedDecl(NamedDecl *D);
Chris Lattnerc8e630e2011-02-17 07:39:24 +000063 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregore31bbd92010-02-21 18:22:14 +000064 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000065 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
66 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000067 void VisitTypeDecl(TypeDecl *D);
Douglas Gregor1f179062011-12-19 14:40:25 +000068 void VisitTypedefNameDecl(TypedefNameDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000069 void VisitTypedefDecl(TypedefDecl *D);
Richard Smithdda56e42011-04-15 14:24:37 +000070 void VisitTypeAliasDecl(TypeAliasDecl *D);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000071 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000072 void VisitTagDecl(TagDecl *D);
73 void VisitEnumDecl(EnumDecl *D);
74 void VisitRecordDecl(RecordDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000075 void VisitCXXRecordDecl(CXXRecordDecl *D);
76 void VisitClassTemplateSpecializationDecl(
77 ClassTemplateSpecializationDecl *D);
78 void VisitClassTemplatePartialSpecializationDecl(
79 ClassTemplatePartialSpecializationDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +000080 void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D);
81 void VisitVarTemplatePartialSpecializationDecl(
82 VarTemplatePartialSpecializationDecl *D);
Fariborz Jahanian3a039e32011-08-27 20:50:59 +000083 void VisitClassScopeFunctionSpecializationDecl(
84 ClassScopeFunctionSpecializationDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000085 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000086 void VisitValueDecl(ValueDecl *D);
87 void VisitEnumConstantDecl(EnumConstantDecl *D);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000088 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +000089 void VisitDeclaratorDecl(DeclaratorDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000090 void VisitFunctionDecl(FunctionDecl *D);
Richard Smithbc491202017-02-17 20:05:37 +000091 void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000092 void VisitCXXMethodDecl(CXXMethodDecl *D);
93 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
94 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
95 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000096 void VisitFieldDecl(FieldDecl *D);
John McCall5e77d762013-04-16 07:28:30 +000097 void VisitMSPropertyDecl(MSPropertyDecl *D);
Francois Pichet783dd6e2010-11-21 06:08:52 +000098 void VisitIndirectFieldDecl(IndirectFieldDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000099 void VisitVarDecl(VarDecl *D);
100 void VisitImplicitParamDecl(ImplicitParamDecl *D);
101 void VisitParmVarDecl(ParmVarDecl *D);
Richard Smith7b76d812016-08-12 02:21:25 +0000102 void VisitDecompositionDecl(DecompositionDecl *D);
103 void VisitBindingDecl(BindingDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000104 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
105 void VisitTemplateDecl(TemplateDecl *D);
Saar Razd7aae332019-07-10 21:25:49 +0000106 void VisitConceptDecl(ConceptDecl *D);
Saar Raza0f50d72020-01-18 09:11:43 +0200107 void VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000108 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000109 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +0000110 void VisitVarTemplateDecl(VarTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000111 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000112 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3f1b5d02011-05-05 21:57:07 +0000113 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000114 void VisitUsingDecl(UsingDecl *D);
Richard Smith151c4562016-12-20 21:35:28 +0000115 void VisitUsingPackDecl(UsingPackDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000116 void VisitUsingShadowDecl(UsingShadowDecl *D);
Richard Smith5179eb72016-06-28 19:03:57 +0000117 void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000118 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Richard Smith8df390f2016-09-08 23:14:54 +0000119 void VisitExportDecl(ExportDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000120 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
Douglas Gregorba345522011-12-02 23:23:56 +0000121 void VisitImportDecl(ImportDecl *D);
Abramo Bagnarad7340582010-06-05 05:09:32 +0000122 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000123 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000124 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
125 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000126 void VisitBlockDecl(BlockDecl *D);
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +0000127 void VisitCapturedDecl(CapturedDecl *D);
Michael Han84324352013-02-22 17:15:32 +0000128 void VisitEmptyDecl(EmptyDecl *D);
Tykerb0561b32019-11-17 11:41:55 +0100129 void VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000130
Richard Smithf1c23dc2016-04-13 02:12:03 +0000131 void VisitDeclContext(DeclContext *DC);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000132 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000133
134
Alexis Hunted053252010-05-30 07:21:58 +0000135 // FIXME: Put in the same order is DeclNodes.td?
Chris Lattner7099dbc2009-04-27 06:16:06 +0000136 void VisitObjCMethodDecl(ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000137 void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000138 void VisitObjCContainerDecl(ObjCContainerDecl *D);
139 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
140 void VisitObjCIvarDecl(ObjCIvarDecl *D);
141 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
142 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000143 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
144 void VisitObjCImplDecl(ObjCImplDecl *D);
145 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
146 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
147 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
148 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
149 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
Alexey Bataeva769e072013-03-22 06:34:35 +0000150 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
Alexey Bataev25ed0c02019-03-07 17:54:44 +0000151 void VisitOMPAllocateDecl(OMPAllocateDecl *D);
Kelvin Li1408f912018-09-26 04:28:39 +0000152 void VisitOMPRequiresDecl(OMPRequiresDecl *D);
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000153 void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
Michael Kruse251e1482019-02-01 20:25:04 +0000154 void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D);
Alexey Bataev4244be22016-02-11 05:35:55 +0000155 void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
Richard Smithd28ac5b2014-03-22 23:33:22 +0000156
Douglas Gregor85f3f952015-07-07 03:57:15 +0000157 /// Add an Objective-C type parameter list to the given record.
158 void AddObjCTypeParamList(ObjCTypeParamList *typeParams) {
159 // Empty type parameter list.
160 if (!typeParams) {
161 Record.push_back(0);
162 return;
163 }
164
165 Record.push_back(typeParams->size());
166 for (auto typeParam : *typeParams) {
Richard Smith69c82bf2016-04-01 22:52:03 +0000167 Record.AddDeclRef(typeParam);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000168 }
Richard Smith69c82bf2016-04-01 22:52:03 +0000169 Record.AddSourceLocation(typeParams->getLAngleLoc());
170 Record.AddSourceLocation(typeParams->getRAngleLoc());
Douglas Gregor85f3f952015-07-07 03:57:15 +0000171 }
172
Richard Smithd8a83712015-08-22 01:47:18 +0000173 /// Add to the record the first declaration from each module file that
174 /// provides a declaration of D. The intent is to provide a sufficient
175 /// set such that reloading this set will load all current redeclarations.
176 void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) {
177 llvm::MapVector<ModuleFile*, const Decl*> Firsts;
178 // FIXME: We can skip entries that we know are implied by others.
Richard Smith5f55d932015-08-27 21:38:25 +0000179 for (const Decl *R = D->getMostRecentDecl(); R; R = R->getPreviousDecl()) {
180 if (R->isFromASTFile())
Richard Smithd8a83712015-08-22 01:47:18 +0000181 Firsts[Writer.Chain->getOwningModuleFile(R)] = R;
Richard Smith5f55d932015-08-27 21:38:25 +0000182 else if (IncludeLocal)
183 Firsts[nullptr] = R;
184 }
Richard Smithd8a83712015-08-22 01:47:18 +0000185 for (const auto &F : Firsts)
Richard Smith69c82bf2016-04-01 22:52:03 +0000186 Record.AddDeclRef(F.second);
Richard Smithd8a83712015-08-22 01:47:18 +0000187 }
188
Richard Smith509fc852015-02-27 23:05:10 +0000189 /// Get the specialization decl from an entry in the specialization list.
190 template <typename EntryType>
191 typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType *
192 getSpecializationDecl(EntryType &T) {
193 return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T);
194 }
195
196 /// Get the list of partial specializations from a template's common ptr.
197 template<typename T>
198 decltype(T::PartialSpecializations) &getPartialSpecializations(T *Common) {
199 return Common->PartialSpecializations;
200 }
201 ArrayRef<Decl> getPartialSpecializations(FunctionTemplateDecl::Common *) {
202 return None;
203 }
204
Richard Smith8ab0cfd2016-02-24 21:59:10 +0000205 template<typename DeclTy>
206 void AddTemplateSpecializations(DeclTy *D) {
Richard Smith509fc852015-02-27 23:05:10 +0000207 auto *Common = D->getCommonPtr();
208
209 // If we have any lazy specializations, and the external AST source is
210 // our chained AST reader, we can just write out the DeclIDs. Otherwise,
211 // we need to resolve them to actual declarations.
212 if (Writer.Chain != Writer.Context->getExternalSource() &&
213 Common->LazySpecializations) {
214 D->LoadLazySpecializations();
215 assert(!Common->LazySpecializations);
216 }
217
Richard Smith509fc852015-02-27 23:05:10 +0000218 ArrayRef<DeclID> LazySpecializations;
219 if (auto *LS = Common->LazySpecializations)
Craig Topper55e39a72015-09-29 04:53:28 +0000220 LazySpecializations = llvm::makeArrayRef(LS + 1, LS[0]);
Richard Smith509fc852015-02-27 23:05:10 +0000221
Richard Smithd8a83712015-08-22 01:47:18 +0000222 // Add a slot to the record for the number of specializations.
223 unsigned I = Record.size();
224 Record.push_back(0);
225
Richard Smith8ab0cfd2016-02-24 21:59:10 +0000226 // AddFirstDeclFromEachModule might trigger deserialization, invalidating
227 // *Specializations iterators.
228 llvm::SmallVector<const Decl*, 16> Specs;
229 for (auto &Entry : Common->Specializations)
230 Specs.push_back(getSpecializationDecl(Entry));
231 for (auto &Entry : getPartialSpecializations(Common))
232 Specs.push_back(getSpecializationDecl(Entry));
233
234 for (auto *D : Specs) {
Richard Smith509fc852015-02-27 23:05:10 +0000235 assert(D->isCanonicalDecl() && "non-canonical decl in set");
Richard Smithd8a83712015-08-22 01:47:18 +0000236 AddFirstDeclFromEachModule(D, /*IncludeLocal*/true);
Richard Smith509fc852015-02-27 23:05:10 +0000237 }
Benjamin Kramerf367dd92015-06-12 15:31:50 +0000238 Record.append(LazySpecializations.begin(), LazySpecializations.end());
Richard Smithd8a83712015-08-22 01:47:18 +0000239
240 // Update the size entry we added earlier.
241 Record[I] = Record.size() - I - 1;
242 }
243
244 /// Ensure that this template specialization is associated with the specified
245 /// template on reload.
246 void RegisterTemplateSpecialization(const Decl *Template,
247 const Decl *Specialization) {
248 Template = Template->getCanonicalDecl();
249
250 // If the canonical template is local, we'll write out this specialization
251 // when we emit it.
252 // FIXME: We can do the same thing if there is any local declaration of
253 // the template, to avoid emitting an update record.
254 if (!Template->isFromASTFile())
255 return;
256
257 // We only need to associate the first local declaration of the
258 // specialization. The other declarations will get pulled in by it.
259 if (Writer.getFirstLocalDecl(Specialization) != Specialization)
260 return;
261
262 Writer.DeclUpdates[Template].push_back(ASTWriter::DeclUpdate(
263 UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION, Specialization));
Richard Smith509fc852015-02-27 23:05:10 +0000264 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000265 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000266}
Chris Lattner7099dbc2009-04-27 06:16:06 +0000267
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000268void ASTDeclWriter::Visit(Decl *D) {
269 DeclVisitor<ASTDeclWriter>::Visit(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000270
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000271 // Source locations require array (variable-length) abbreviations. The
272 // abbreviation infrastructure requires that arrays are encoded last, so
273 // we handle it here in the case of those classes derived from DeclaratorDecl
Nick Lewycky4b81fc872015-10-18 20:32:12 +0000274 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
Richard Smithc23d7342018-06-29 20:46:25 +0000275 if (auto *TInfo = DD->getTypeSourceInfo())
276 Record.AddTypeLoc(TInfo->getTypeLoc());
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000277 }
278
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000279 // Handle FunctionDecl's body here and write it after all other Stmts/Exprs
280 // have been written. We want it last because we will not read it back when
Fangrui Song6907ce22018-07-30 19:24:48 +0000281 // retrieving it from the AST, we'll just lazily set the offset.
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000282 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
Alexis Hunt4a8ea102011-05-06 20:44:56 +0000283 Record.push_back(FD->doesThisDeclarationHaveABody());
284 if (FD->doesThisDeclarationHaveABody())
Richard Smith290d8012016-04-06 17:06:00 +0000285 Record.AddFunctionDefinition(FD);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000286 }
Richard Smithf1c23dc2016-04-13 02:12:03 +0000287
288 // If this declaration is also a DeclContext, write blocks for the
289 // declarations that lexically stored inside its context and those
290 // declarations that are visible from its context.
291 if (DeclContext *DC = dyn_cast<DeclContext>(D))
292 VisitDeclContext(DC);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000293}
294
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000295void ASTDeclWriter::VisitDecl(Decl *D) {
Richard Smith69c82bf2016-04-01 22:52:03 +0000296 Record.AddDeclRef(cast_or_null<Decl>(D->getDeclContext()));
Richard Smith8aed4222015-12-11 22:41:00 +0000297 if (D->getDeclContext() != D->getLexicalDeclContext())
Richard Smith69c82bf2016-04-01 22:52:03 +0000298 Record.AddDeclRef(cast_or_null<Decl>(D->getLexicalDeclContext()));
Richard Smith8aed4222015-12-11 22:41:00 +0000299 else
300 Record.push_back(0);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000301 Record.push_back(D->isInvalidDecl());
302 Record.push_back(D->hasAttrs());
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000303 if (D->hasAttrs())
Richard Smith69c82bf2016-04-01 22:52:03 +0000304 Record.AddAttributes(D->getAttrs());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000305 Record.push_back(D->isImplicit());
Douglas Gregorebada0772010-06-17 23:14:26 +0000306 Record.push_back(D->isUsed(false));
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +0000307 Record.push_back(D->isReferenced());
Douglas Gregor781f7132012-01-06 16:59:53 +0000308 Record.push_back(D->isTopLevelDeclInObjCContainer());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000309 Record.push_back(D->getAccess());
Douglas Gregor781f7132012-01-06 16:59:53 +0000310 Record.push_back(D->isModulePrivate());
Richard Smith54f04402017-05-18 02:29:20 +0000311 Record.push_back(Writer.getSubmoduleID(D->getOwningModule()));
Richard Smithc264d352014-03-23 02:30:01 +0000312
313 // If this declaration injected a name into a context different from its
314 // lexical context, and that context is an imported namespace, we need to
315 // update its visible declarations to include this name.
316 //
317 // This happens when we instantiate a class with a friend declaration or a
318 // function with a local extern declaration, for instance.
Richard Smith5fc18a92015-07-12 23:43:21 +0000319 //
320 // FIXME: Can we handle this in AddedVisibleDecl instead?
Richard Smithc264d352014-03-23 02:30:01 +0000321 if (D->isOutOfLine()) {
Richard Smithe3a97022014-03-23 20:41:56 +0000322 auto *DC = D->getDeclContext();
323 while (auto *NS = dyn_cast<NamespaceDecl>(DC->getRedeclContext())) {
324 if (!NS->isFromASTFile())
325 break;
Chandler Carruth8a3d24d2015-03-26 04:27:10 +0000326 Writer.UpdatedDeclContexts.insert(NS->getPrimaryContext());
Richard Smithe3a97022014-03-23 20:41:56 +0000327 if (!NS->isInlineNamespace())
328 break;
329 DC = NS->getParent();
330 }
Richard Smithc264d352014-03-23 02:30:01 +0000331 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000332}
333
Nico Weber66220292016-03-02 17:28:48 +0000334void ASTDeclWriter::VisitPragmaCommentDecl(PragmaCommentDecl *D) {
335 StringRef Arg = D->getArg();
336 Record.push_back(Arg.size());
337 VisitDecl(D);
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000338 Record.AddSourceLocation(D->getBeginLoc());
Nico Weber66220292016-03-02 17:28:48 +0000339 Record.push_back(D->getCommentKind());
Richard Smith69c82bf2016-04-01 22:52:03 +0000340 Record.AddString(Arg);
Nico Weber66220292016-03-02 17:28:48 +0000341 Code = serialization::DECL_PRAGMA_COMMENT;
342}
343
Nico Webercbbaeb12016-03-02 19:28:54 +0000344void ASTDeclWriter::VisitPragmaDetectMismatchDecl(
345 PragmaDetectMismatchDecl *D) {
346 StringRef Name = D->getName();
347 StringRef Value = D->getValue();
348 Record.push_back(Name.size() + 1 + Value.size());
349 VisitDecl(D);
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000350 Record.AddSourceLocation(D->getBeginLoc());
Richard Smith69c82bf2016-04-01 22:52:03 +0000351 Record.AddString(Name);
352 Record.AddString(Value);
Nico Webercbbaeb12016-03-02 19:28:54 +0000353 Code = serialization::DECL_PRAGMA_DETECT_MISMATCH;
354}
355
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000356void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
Douglas Gregordab42432011-08-12 00:15:20 +0000357 llvm_unreachable("Translation units aren't directly serialized");
Chris Lattner7099dbc2009-04-27 06:16:06 +0000358}
359
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000360void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000361 VisitDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000362 Record.AddDeclarationName(D->getDeclName());
Richard Smith2b560572015-02-07 03:11:11 +0000363 Record.push_back(needsAnonymousDeclarationNumber(D)
364 ? Writer.getAnonymousDeclarationNumber(D)
365 : 0);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000366}
367
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000368void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000369 VisitNamedDecl(D);
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000370 Record.AddSourceLocation(D->getBeginLoc());
Richard Smith69c82bf2016-04-01 22:52:03 +0000371 Record.AddTypeRef(QualType(D->getTypeForDecl(), 0));
Chris Lattner7099dbc2009-04-27 06:16:06 +0000372}
373
Douglas Gregor1f179062011-12-19 14:40:25 +0000374void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) {
Douglas Gregor05f10352011-12-17 23:38:30 +0000375 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000376 VisitTypeDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000377 Record.AddTypeSourceInfo(D->getTypeSourceInfo());
Enea Zaffanellaa86d88c2013-06-20 12:46:19 +0000378 Record.push_back(D->isModed());
379 if (D->isModed())
Richard Smith69c82bf2016-04-01 22:52:03 +0000380 Record.AddTypeRef(D->getUnderlyingType());
Richard Smithc0ca4c22017-01-26 22:39:55 +0000381 Record.AddDeclRef(D->getAnonDeclWithTypedefName(false));
Douglas Gregor1f179062011-12-19 14:40:25 +0000382}
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000383
Douglas Gregor1f179062011-12-19 14:40:25 +0000384void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) {
385 VisitTypedefNameDecl(D);
Richard Smith8aed4222015-12-11 22:41:00 +0000386 if (D->getDeclContext() == D->getLexicalDeclContext() &&
387 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000388 !D->isImplicit() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000389 D->getFirstDecl() == D->getMostRecentDecl() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000390 !D->isInvalidDecl() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000391 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000392 !D->isModulePrivate() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000393 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000394 D->getDeclName().getNameKind() == DeclarationName::Identifier)
395 AbbrevToUse = Writer.getDeclTypedefAbbrev();
396
Sebastian Redl539c5062010-08-18 23:57:32 +0000397 Code = serialization::DECL_TYPEDEF;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000398}
399
Richard Smithdda56e42011-04-15 14:24:37 +0000400void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) {
Douglas Gregor1f179062011-12-19 14:40:25 +0000401 VisitTypedefNameDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000402 Record.AddDeclRef(D->getDescribedAliasTemplate());
Richard Smithdda56e42011-04-15 14:24:37 +0000403 Code = serialization::DECL_TYPEALIAS;
404}
405
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000406void ASTDeclWriter::VisitTagDecl(TagDecl *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000407 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000408 VisitTypeDecl(D);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000409 Record.push_back(D->getIdentifierNamespace());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000410 Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding
Richard Smith2c381642014-08-27 23:11:59 +0000411 if (!isa<CXXRecordDecl>(D))
412 Record.push_back(D->isCompleteDefinition());
Douglas Gregor5089c762010-02-12 17:40:34 +0000413 Record.push_back(D->isEmbeddedInDeclarator());
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +0000414 Record.push_back(D->isFreeStanding());
David Blaikiea8d23ce2013-07-14 01:07:41 +0000415 Record.push_back(D->isCompleteDefinitionRequired());
Argyrios Kyrtzidisd798c052016-07-15 18:11:33 +0000416 Record.AddSourceRange(D->getBraceRange());
Richard Smith70d58502014-08-30 00:04:23 +0000417
418 if (D->hasExtInfo()) {
419 Record.push_back(1);
Richard Smith69c82bf2016-04-01 22:52:03 +0000420 Record.AddQualifierInfo(*D->getExtInfo());
Richard Smith70d58502014-08-30 00:04:23 +0000421 } else if (auto *TD = D->getTypedefNameForAnonDecl()) {
422 Record.push_back(2);
Richard Smith69c82bf2016-04-01 22:52:03 +0000423 Record.AddDeclRef(TD);
424 Record.AddIdentifierRef(TD->getDeclName().getAsIdentifierInfo());
Richard Smith70d58502014-08-30 00:04:23 +0000425 } else {
426 Record.push_back(0);
427 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000428}
429
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000430void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000431 VisitTagDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000432 Record.AddTypeSourceInfo(D->getIntegerTypeSourceInfo());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000433 if (!D->getIntegerTypeSourceInfo())
Richard Smith69c82bf2016-04-01 22:52:03 +0000434 Record.AddTypeRef(D->getIntegerType());
435 Record.AddTypeRef(D->getPromotionType());
John McCall9aa35be2010-05-06 08:49:23 +0000436 Record.push_back(D->getNumPositiveBits());
437 Record.push_back(D->getNumNegativeBits());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000438 Record.push_back(D->isScoped());
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000439 Record.push_back(D->isScopedUsingClassTag());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000440 Record.push_back(D->isFixed());
Richard Trieuab4d7302018-07-25 22:52:05 +0000441 Record.push_back(D->getODRHash());
442
Richard Smith4b38ded2012-03-14 23:13:10 +0000443 if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
Richard Smith69c82bf2016-04-01 22:52:03 +0000444 Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
Richard Smith4b38ded2012-03-14 23:13:10 +0000445 Record.push_back(MemberInfo->getTemplateSpecializationKind());
Richard Smith69c82bf2016-04-01 22:52:03 +0000446 Record.AddSourceLocation(MemberInfo->getPointOfInstantiation());
Richard Smith4b38ded2012-03-14 23:13:10 +0000447 } else {
Richard Smith69c82bf2016-04-01 22:52:03 +0000448 Record.AddDeclRef(nullptr);
Richard Smith4b38ded2012-03-14 23:13:10 +0000449 }
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000450
Richard Smith8aed4222015-12-11 22:41:00 +0000451 if (D->getDeclContext() == D->getLexicalDeclContext() &&
452 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000453 !D->isImplicit() &&
454 !D->isUsed(false) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000455 !D->hasExtInfo() &&
Richard Smith70d58502014-08-30 00:04:23 +0000456 !D->getTypedefNameForAnonDecl() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000457 D->getFirstDecl() == D->getMostRecentDecl() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000458 !D->isInvalidDecl() &&
459 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000460 !D->isTopLevelDeclInObjCContainer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000461 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000462 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000463 !CXXRecordDecl::classofKind(D->getKind()) &&
464 !D->getIntegerTypeSourceInfo() &&
Argyrios Kyrtzidisca370b0d2013-03-18 22:23:49 +0000465 !D->getMemberSpecializationInfo() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000466 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000467 D->getDeclName().getNameKind() == DeclarationName::Identifier)
468 AbbrevToUse = Writer.getDeclEnumAbbrev();
469
Sebastian Redl539c5062010-08-18 23:57:32 +0000470 Code = serialization::DECL_ENUM;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000471}
472
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000473void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000474 VisitTagDecl(D);
475 Record.push_back(D->hasFlexibleArrayMember());
476 Record.push_back(D->isAnonymousStructOrUnion());
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000477 Record.push_back(D->hasObjectMember());
Fariborz Jahanian78652202013-01-25 23:57:05 +0000478 Record.push_back(D->hasVolatileMember());
Akira Hatanaka34fb2642018-03-13 18:58:25 +0000479 Record.push_back(D->isNonTrivialToPrimitiveDefaultInitialize());
480 Record.push_back(D->isNonTrivialToPrimitiveCopy());
481 Record.push_back(D->isNonTrivialToPrimitiveDestroy());
Akira Hatanaka09051062019-09-07 00:34:43 +0000482 Record.push_back(D->hasNonTrivialToPrimitiveDefaultInitializeCUnion());
483 Record.push_back(D->hasNonTrivialToPrimitiveDestructCUnion());
484 Record.push_back(D->hasNonTrivialToPrimitiveCopyCUnion());
Akira Hatanakafcbe17c2018-03-28 21:13:14 +0000485 Record.push_back(D->isParamDestroyedInCallee());
Akira Hatanakae6313ac2018-04-09 22:48:22 +0000486 Record.push_back(D->getArgPassingRestrictions());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000487
Richard Smith8aed4222015-12-11 22:41:00 +0000488 if (D->getDeclContext() == D->getLexicalDeclContext() &&
489 !D->hasAttrs() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000490 !D->isImplicit() &&
491 !D->isUsed(false) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000492 !D->hasExtInfo() &&
Richard Smith70d58502014-08-30 00:04:23 +0000493 !D->getTypedefNameForAnonDecl() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000494 D->getFirstDecl() == D->getMostRecentDecl() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000495 !D->isInvalidDecl() &&
496 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000497 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000498 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000499 !D->isModulePrivate() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000500 !CXXRecordDecl::classofKind(D->getKind()) &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000501 !needsAnonymousDeclarationNumber(D) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000502 D->getDeclName().getNameKind() == DeclarationName::Identifier)
Douglas Gregor03412ba2011-06-03 02:27:19 +0000503 AbbrevToUse = Writer.getDeclRecordAbbrev();
504
Sebastian Redl539c5062010-08-18 23:57:32 +0000505 Code = serialization::DECL_RECORD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000506}
507
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000508void ASTDeclWriter::VisitValueDecl(ValueDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000509 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000510 Record.AddTypeRef(D->getType());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000511}
512
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000513void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000514 VisitValueDecl(D);
515 Record.push_back(D->getInitExpr()? 1 : 0);
516 if (D->getInitExpr())
Richard Smith290d8012016-04-06 17:06:00 +0000517 Record.AddStmt(D->getInitExpr());
Richard Smith69c82bf2016-04-01 22:52:03 +0000518 Record.AddAPSInt(D->getInitVal());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000519
Sebastian Redl539c5062010-08-18 23:57:32 +0000520 Code = serialization::DECL_ENUM_CONSTANT;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000521}
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000522
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000523void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000524 VisitValueDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000525 Record.AddSourceLocation(D->getInnerLocStart());
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000526 Record.push_back(D->hasExtInfo());
Saar Razb65b1f32020-01-09 15:07:51 +0200527 if (D->hasExtInfo()) {
528 DeclaratorDecl::ExtInfo *Info = D->getExtInfo();
529 Record.AddQualifierInfo(*Info);
530 Record.AddStmt(Info->TrailingRequiresClause);
531 }
Richard Smithc23d7342018-06-29 20:46:25 +0000532 // The location information is deferred until the end of the record.
533 Record.AddTypeRef(D->getTypeSourceInfo() ? D->getTypeSourceInfo()->getType()
534 : QualType());
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000535}
Chris Lattner7099dbc2009-04-27 06:16:06 +0000536
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000537void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000538 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000539 VisitDeclaratorDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000540 Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000541 Record.push_back(D->getIdentifierNamespace());
Fangrui Song6907ce22018-07-30 19:24:48 +0000542
Douglas Gregorb2585692012-01-04 17:13:46 +0000543 // FunctionDecl's body is handled last at ASTWriterDecl::Visit,
544 // after everything else is written.
Erich Keane9c665062018-08-01 21:02:40 +0000545 Record.push_back(static_cast<int>(D->getStorageClass())); // FIXME: stable encoding
546 Record.push_back(D->isInlineSpecified());
547 Record.push_back(D->isInlined());
Erich Keane9c665062018-08-01 21:02:40 +0000548 Record.push_back(D->isVirtualAsWritten());
549 Record.push_back(D->isPure());
550 Record.push_back(D->hasInheritedPrototype());
551 Record.push_back(D->hasWrittenPrototype());
552 Record.push_back(D->isDeletedBit());
553 Record.push_back(D->isTrivial());
554 Record.push_back(D->isTrivialForCall());
555 Record.push_back(D->isDefaulted());
556 Record.push_back(D->isExplicitlyDefaulted());
557 Record.push_back(D->hasImplicitReturnZero());
Gauthier Harnisch796ed032019-06-14 08:56:20 +0000558 Record.push_back(D->getConstexprKind());
Erich Keane9c665062018-08-01 21:02:40 +0000559 Record.push_back(D->usesSEHTry());
560 Record.push_back(D->hasSkippedBody());
561 Record.push_back(D->isMultiVersion());
562 Record.push_back(D->isLateTemplateParsed());
Rafael Espindola3ae00052013-05-13 00:12:11 +0000563 Record.push_back(D->getLinkageInternal());
Stephen Kelly1c301dc2018-08-09 21:09:38 +0000564 Record.AddSourceLocation(D->getEndLoc());
Douglas Gregorb2585692012-01-04 17:13:46 +0000565
Richard Trieue6caa262017-12-23 00:41:01 +0000566 Record.push_back(D->getODRHash());
Melanie Blower7f9b5132019-12-04 12:23:46 -0800567 Record.push_back(D->usesFPIntrin());
Richard Trieue6caa262017-12-23 00:41:01 +0000568
Richard Smith848934c2019-12-05 13:37:35 -0800569 if (D->isDefaulted()) {
570 if (auto *FDI = D->getDefaultedFunctionInfo()) {
571 Record.push_back(FDI->getUnqualifiedLookups().size());
572 for (DeclAccessPair P : FDI->getUnqualifiedLookups()) {
573 Record.AddDeclRef(P.getDecl());
574 Record.push_back(P.getAccess());
575 }
576 } else {
577 Record.push_back(0);
578 }
579 }
580
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000581 Record.push_back(D->getTemplatedKind());
582 switch (D->getTemplatedKind()) {
583 case FunctionDecl::TK_NonTemplate:
584 break;
585 case FunctionDecl::TK_FunctionTemplate:
Richard Smith69c82bf2016-04-01 22:52:03 +0000586 Record.AddDeclRef(D->getDescribedFunctionTemplate());
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000587 break;
588 case FunctionDecl::TK_MemberSpecialization: {
589 MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo();
Richard Smith69c82bf2016-04-01 22:52:03 +0000590 Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000591 Record.push_back(MemberInfo->getTemplateSpecializationKind());
Richard Smith69c82bf2016-04-01 22:52:03 +0000592 Record.AddSourceLocation(MemberInfo->getPointOfInstantiation());
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000593 break;
594 }
595 case FunctionDecl::TK_FunctionTemplateSpecialization: {
596 FunctionTemplateSpecializationInfo *
597 FTSInfo = D->getTemplateSpecializationInfo();
Richard Smithd8a83712015-08-22 01:47:18 +0000598
599 RegisterTemplateSpecialization(FTSInfo->getTemplate(), D);
600
Richard Smith69c82bf2016-04-01 22:52:03 +0000601 Record.AddDeclRef(FTSInfo->getTemplate());
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000602 Record.push_back(FTSInfo->getTemplateSpecializationKind());
Fangrui Song6907ce22018-07-30 19:24:48 +0000603
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000604 // Template arguments.
Richard Smith69c82bf2016-04-01 22:52:03 +0000605 Record.AddTemplateArgumentList(FTSInfo->TemplateArguments);
Fangrui Song6907ce22018-07-30 19:24:48 +0000606
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000607 // Template args as written.
Craig Toppera13603a2014-05-22 05:54:18 +0000608 Record.push_back(FTSInfo->TemplateArgumentsAsWritten != nullptr);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000609 if (FTSInfo->TemplateArgumentsAsWritten) {
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000610 Record.push_back(FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs);
611 for (int i=0, e = FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs;
612 i!=e; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +0000613 Record.AddTemplateArgumentLoc(
614 (*FTSInfo->TemplateArgumentsAsWritten)[i]);
615 Record.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->LAngleLoc);
616 Record.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->RAngleLoc);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000617 }
Fangrui Song6907ce22018-07-30 19:24:48 +0000618
Richard Smith69c82bf2016-04-01 22:52:03 +0000619 Record.AddSourceLocation(FTSInfo->getPointOfInstantiation());
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000620
Richard Smithf19a8b02019-05-02 00:49:14 +0000621 if (MemberSpecializationInfo *MemberInfo =
622 FTSInfo->getMemberSpecializationInfo()) {
623 Record.push_back(1);
624 Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
625 Record.push_back(MemberInfo->getTemplateSpecializationKind());
626 Record.AddSourceLocation(MemberInfo->getPointOfInstantiation());
627 } else {
628 Record.push_back(0);
629 }
630
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000631 if (D->isCanonicalDecl()) {
632 // Write the template that contains the specializations set. We will
633 // add a FunctionTemplateSpecializationInfo to it when reading.
Richard Smith69c82bf2016-04-01 22:52:03 +0000634 Record.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl());
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000635 }
Argyrios Kyrtzidisdc9ca0a2010-06-25 16:24:51 +0000636 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000637 }
638 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
639 DependentFunctionTemplateSpecializationInfo *
640 DFTSInfo = D->getDependentSpecializationInfo();
Fangrui Song6907ce22018-07-30 19:24:48 +0000641
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000642 // Templates.
643 Record.push_back(DFTSInfo->getNumTemplates());
644 for (int i=0, e = DFTSInfo->getNumTemplates(); i != e; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +0000645 Record.AddDeclRef(DFTSInfo->getTemplate(i));
Fangrui Song6907ce22018-07-30 19:24:48 +0000646
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000647 // Templates args.
648 Record.push_back(DFTSInfo->getNumTemplateArgs());
649 for (int i=0, e = DFTSInfo->getNumTemplateArgs(); i != e; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +0000650 Record.AddTemplateArgumentLoc(DFTSInfo->getTemplateArg(i));
651 Record.AddSourceLocation(DFTSInfo->getLAngleLoc());
652 Record.AddSourceLocation(DFTSInfo->getRAngleLoc());
Argyrios Kyrtzidisdc9ca0a2010-06-25 16:24:51 +0000653 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000654 }
655 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000656
Chris Lattner7099dbc2009-04-27 06:16:06 +0000657 Record.push_back(D->param_size());
David Majnemer59f77922016-06-24 04:05:48 +0000658 for (auto P : D->parameters())
Richard Smith69c82bf2016-04-01 22:52:03 +0000659 Record.AddDeclRef(P);
Sebastian Redl539c5062010-08-18 23:57:32 +0000660 Code = serialization::DECL_FUNCTION;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000661}
662
Richard Smith76b90272019-05-09 03:59:21 +0000663static void addExplicitSpecifier(ExplicitSpecifier ES,
664 ASTRecordWriter &Record) {
665 uint64_t Kind = static_cast<uint64_t>(ES.getKind());
666 Kind = Kind << 1 | static_cast<bool>(ES.getExpr());
667 Record.push_back(Kind);
668 if (ES.getExpr()) {
669 Record.AddStmt(ES.getExpr());
670 }
671}
672
Richard Smithbc491202017-02-17 20:05:37 +0000673void ASTDeclWriter::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) {
Richard Smith76b90272019-05-09 03:59:21 +0000674 addExplicitSpecifier(D->getExplicitSpecifier(), Record);
Richard Smithbc491202017-02-17 20:05:37 +0000675 VisitFunctionDecl(D);
Erich Keane9c665062018-08-01 21:02:40 +0000676 Record.push_back(D->isCopyDeductionCandidate());
Richard Smithbc491202017-02-17 20:05:37 +0000677 Code = serialization::DECL_CXX_DEDUCTION_GUIDE;
678}
679
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000680void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000681 VisitNamedDecl(D);
682 // FIXME: convert to LazyStmtPtr?
Mike Stump11289f42009-09-09 15:08:12 +0000683 // Unlike C/C++, method bodies will never be in header files.
Alex Lorenzf3efd692019-12-06 14:24:37 -0800684 bool HasBodyStuff = D->getBody() != nullptr;
Argyrios Kyrtzidisa8607772010-08-09 10:54:37 +0000685 Record.push_back(HasBodyStuff);
686 if (HasBodyStuff) {
Richard Smith290d8012016-04-06 17:06:00 +0000687 Record.AddStmt(D->getBody());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000688 }
Alex Lorenzf3efd692019-12-06 14:24:37 -0800689 Record.AddDeclRef(D->getSelfDecl());
690 Record.AddDeclRef(D->getCmdDecl());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000691 Record.push_back(D->isInstanceMethod());
692 Record.push_back(D->isVariadic());
Jordan Rosed01e83a2012-10-10 16:42:25 +0000693 Record.push_back(D->isPropertyAccessor());
Adrian Prantl2073dd22019-11-04 14:28:14 -0800694 Record.push_back(D->isSynthesizedAccessorStub());
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000695 Record.push_back(D->isDefined());
Erich Keane9b18eca2018-08-01 21:31:08 +0000696 Record.push_back(D->isOverriding());
697 Record.push_back(D->hasSkippedBody());
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000698
Erich Keane9b18eca2018-08-01 21:31:08 +0000699 Record.push_back(D->isRedeclaration());
700 Record.push_back(D->hasRedeclaration());
701 if (D->hasRedeclaration()) {
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000702 assert(Context.getObjCMethodRedeclaration(D));
Richard Smith69c82bf2016-04-01 22:52:03 +0000703 Record.AddDeclRef(Context.getObjCMethodRedeclaration(D));
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000704 }
705
Chris Lattner7099dbc2009-04-27 06:16:06 +0000706 // FIXME: stable encoding for @required/@optional
Mike Stump11289f42009-09-09 15:08:12 +0000707 Record.push_back(D->getImplementationControl());
Douglas Gregor813a0662015-06-19 18:14:38 +0000708 // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway/nullability
Mike Stump11289f42009-09-09 15:08:12 +0000709 Record.push_back(D->getObjCDeclQualifier());
Douglas Gregor33823722011-06-11 01:09:30 +0000710 Record.push_back(D->hasRelatedResultType());
Richard Smith69c82bf2016-04-01 22:52:03 +0000711 Record.AddTypeRef(D->getReturnType());
712 Record.AddTypeSourceInfo(D->getReturnTypeSourceInfo());
Stephen Kelly1c301dc2018-08-09 21:09:38 +0000713 Record.AddSourceLocation(D->getEndLoc());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000714 Record.push_back(D->param_size());
David Majnemer59f77922016-06-24 04:05:48 +0000715 for (const auto *P : D->parameters())
Richard Smith69c82bf2016-04-01 22:52:03 +0000716 Record.AddDeclRef(P);
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000717
Erich Keane9b18eca2018-08-01 21:31:08 +0000718 Record.push_back(D->getSelLocsKind());
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000719 unsigned NumStoredSelLocs = D->getNumStoredSelLocs();
720 SourceLocation *SelLocs = D->getStoredSelLocs();
721 Record.push_back(NumStoredSelLocs);
722 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +0000723 Record.AddSourceLocation(SelLocs[i]);
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000724
Sebastian Redl539c5062010-08-18 23:57:32 +0000725 Code = serialization::DECL_OBJC_METHOD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000726}
727
Douglas Gregor85f3f952015-07-07 03:57:15 +0000728void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
729 VisitTypedefNameDecl(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +0000730 Record.push_back(D->Variance);
Douglas Gregore83b9562015-07-07 03:57:53 +0000731 Record.push_back(D->Index);
Richard Smith69c82bf2016-04-01 22:52:03 +0000732 Record.AddSourceLocation(D->VarianceLoc);
733 Record.AddSourceLocation(D->ColonLoc);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000734
735 Code = serialization::DECL_OBJC_TYPE_PARAM;
736}
737
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000738void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000739 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000740 Record.AddSourceLocation(D->getAtStartLoc());
741 Record.AddSourceRange(D->getAtEndRange());
Sebastian Redl539c5062010-08-18 23:57:32 +0000742 // Abstract class (no need to define a stable serialization::DECL code).
Chris Lattner7099dbc2009-04-27 06:16:06 +0000743}
744
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000745void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
Douglas Gregor66b310c2011-12-15 18:03:09 +0000746 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000747 VisitObjCContainerDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000748 Record.AddTypeRef(QualType(D->getTypeForDecl(), 0));
Douglas Gregor85f3f952015-07-07 03:57:15 +0000749 AddObjCTypeParamList(D->TypeParamList);
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000750
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000751 Record.push_back(D->isThisDeclarationADefinition());
752 if (D->isThisDeclarationADefinition()) {
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000753 // Write the DefinitionData
754 ObjCInterfaceDecl::DefinitionData &Data = D->data();
Fangrui Song6907ce22018-07-30 19:24:48 +0000755
Richard Smith69c82bf2016-04-01 22:52:03 +0000756 Record.AddTypeSourceInfo(D->getSuperClassTInfo());
757 Record.AddSourceLocation(D->getEndOfDefinitionLoc());
Argyrios Kyrtzidis9ed9e5f2013-12-03 21:11:30 +0000758 Record.push_back(Data.HasDesignatedInitializers);
Douglas Gregor16408322011-12-15 22:34:59 +0000759
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000760 // Write out the protocols that are directly referenced by the @interface.
761 Record.push_back(Data.ReferencedProtocols.size());
Aaron Ballmana49c5062014-03-13 20:29:09 +0000762 for (const auto *P : D->protocols())
Richard Smith69c82bf2016-04-01 22:52:03 +0000763 Record.AddDeclRef(P);
Aaron Ballmane9378882014-03-13 20:34:24 +0000764 for (const auto &PL : D->protocol_locs())
Richard Smith69c82bf2016-04-01 22:52:03 +0000765 Record.AddSourceLocation(PL);
Fangrui Song6907ce22018-07-30 19:24:48 +0000766
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000767 // Write out the protocols that are transitively referenced.
768 Record.push_back(Data.AllReferencedProtocols.size());
769 for (ObjCList<ObjCProtocolDecl>::iterator
770 P = Data.AllReferencedProtocols.begin(),
771 PEnd = Data.AllReferencedProtocols.end();
772 P != PEnd; ++P)
Richard Smith69c82bf2016-04-01 22:52:03 +0000773 Record.AddDeclRef(*P);
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000774
Fangrui Song6907ce22018-07-30 19:24:48 +0000775
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000776 if (ObjCCategoryDecl *Cat = D->getCategoryListRaw()) {
Douglas Gregor404cdde2012-01-27 01:47:08 +0000777 // Ensure that we write out the set of categories for this class.
778 Writer.ObjCClassesWithCategories.insert(D);
Fangrui Song6907ce22018-07-30 19:24:48 +0000779
Douglas Gregor404cdde2012-01-27 01:47:08 +0000780 // Make sure that the categories get serialized.
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000781 for (; Cat; Cat = Cat->getNextClassCategoryRaw())
Douglas Gregor404cdde2012-01-27 01:47:08 +0000782 (void)Writer.GetDeclRef(Cat);
783 }
Fangrui Song6907ce22018-07-30 19:24:48 +0000784 }
785
Sebastian Redl539c5062010-08-18 23:57:32 +0000786 Code = serialization::DECL_OBJC_INTERFACE;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000787}
788
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000789void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000790 VisitFieldDecl(D);
791 // FIXME: stable encoding for @public/@private/@protected/@package
Mike Stump11289f42009-09-09 15:08:12 +0000792 Record.push_back(D->getAccessControl());
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000793 Record.push_back(D->getSynthesize());
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000794
Richard Smith8aed4222015-12-11 22:41:00 +0000795 if (D->getDeclContext() == D->getLexicalDeclContext() &&
796 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000797 !D->isImplicit() &&
798 !D->isUsed(false) &&
799 !D->isInvalidDecl() &&
800 !D->isReferenced() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000801 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000802 !D->getBitWidth() &&
803 !D->hasExtInfo() &&
804 D->getDeclName())
805 AbbrevToUse = Writer.getDeclObjCIvarAbbrev();
806
Sebastian Redl539c5062010-08-18 23:57:32 +0000807 Code = serialization::DECL_OBJC_IVAR;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000808}
809
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000810void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
Douglas Gregora715bff2012-01-01 19:51:50 +0000811 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000812 VisitObjCContainerDecl(D);
Fangrui Song6907ce22018-07-30 19:24:48 +0000813
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000814 Record.push_back(D->isThisDeclarationADefinition());
815 if (D->isThisDeclarationADefinition()) {
Douglas Gregore6e48b12012-01-01 19:29:29 +0000816 Record.push_back(D->protocol_size());
Aaron Ballman0f6e64d2014-03-13 22:58:06 +0000817 for (const auto *I : D->protocols())
Richard Smith69c82bf2016-04-01 22:52:03 +0000818 Record.AddDeclRef(I);
Aaron Ballmana964ec12014-03-14 12:38:50 +0000819 for (const auto &PL : D->protocol_locs())
Richard Smith69c82bf2016-04-01 22:52:03 +0000820 Record.AddSourceLocation(PL);
Douglas Gregore6e48b12012-01-01 19:29:29 +0000821 }
Fangrui Song6907ce22018-07-30 19:24:48 +0000822
Sebastian Redl539c5062010-08-18 23:57:32 +0000823 Code = serialization::DECL_OBJC_PROTOCOL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000824}
825
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000826void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000827 VisitFieldDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000828 Code = serialization::DECL_OBJC_AT_DEFS_FIELD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000829}
830
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000831void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000832 VisitObjCContainerDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000833 Record.AddSourceLocation(D->getCategoryNameLoc());
834 Record.AddSourceLocation(D->getIvarLBraceLoc());
835 Record.AddSourceLocation(D->getIvarRBraceLoc());
836 Record.AddDeclRef(D->getClassInterface());
Douglas Gregor85f3f952015-07-07 03:57:15 +0000837 AddObjCTypeParamList(D->TypeParamList);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000838 Record.push_back(D->protocol_size());
Aaron Ballman19a41762014-03-14 12:55:57 +0000839 for (const auto *I : D->protocols())
Richard Smith69c82bf2016-04-01 22:52:03 +0000840 Record.AddDeclRef(I);
Aaron Ballmana73c8572014-03-14 13:03:32 +0000841 for (const auto &PL : D->protocol_locs())
Richard Smith69c82bf2016-04-01 22:52:03 +0000842 Record.AddSourceLocation(PL);
Sebastian Redl539c5062010-08-18 23:57:32 +0000843 Code = serialization::DECL_OBJC_CATEGORY;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000844}
845
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000846void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000847 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000848 Record.AddDeclRef(D->getClassInterface());
Sebastian Redl539c5062010-08-18 23:57:32 +0000849 Code = serialization::DECL_OBJC_COMPATIBLE_ALIAS;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000850}
851
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000852void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000853 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000854 Record.AddSourceLocation(D->getAtLoc());
855 Record.AddSourceLocation(D->getLParenLoc());
856 Record.AddTypeRef(D->getType());
857 Record.AddTypeSourceInfo(D->getTypeSourceInfo());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000858 // FIXME: stable encoding
859 Record.push_back((unsigned)D->getPropertyAttributes());
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000860 Record.push_back((unsigned)D->getPropertyAttributesAsWritten());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000861 // FIXME: stable encoding
862 Record.push_back((unsigned)D->getPropertyImplementation());
Richard Smith69c82bf2016-04-01 22:52:03 +0000863 Record.AddDeclarationName(D->getGetterName());
Argyrios Kyrtzidis194b28e2017-03-16 18:25:40 +0000864 Record.AddSourceLocation(D->getGetterNameLoc());
Richard Smith69c82bf2016-04-01 22:52:03 +0000865 Record.AddDeclarationName(D->getSetterName());
Argyrios Kyrtzidis194b28e2017-03-16 18:25:40 +0000866 Record.AddSourceLocation(D->getSetterNameLoc());
Richard Smith69c82bf2016-04-01 22:52:03 +0000867 Record.AddDeclRef(D->getGetterMethodDecl());
868 Record.AddDeclRef(D->getSetterMethodDecl());
869 Record.AddDeclRef(D->getPropertyIvarDecl());
Sebastian Redl539c5062010-08-18 23:57:32 +0000870 Code = serialization::DECL_OBJC_PROPERTY;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000871}
872
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000873void ASTDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000874 VisitObjCContainerDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000875 Record.AddDeclRef(D->getClassInterface());
Sebastian Redl539c5062010-08-18 23:57:32 +0000876 // Abstract class (no need to define a stable serialization::DECL code).
Chris Lattner7099dbc2009-04-27 06:16:06 +0000877}
878
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000879void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000880 VisitObjCImplDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000881 Record.AddSourceLocation(D->getCategoryNameLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000882 Code = serialization::DECL_OBJC_CATEGORY_IMPL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000883}
884
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000885void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000886 VisitObjCImplDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000887 Record.AddDeclRef(D->getSuperClass());
888 Record.AddSourceLocation(D->getSuperClassLoc());
889 Record.AddSourceLocation(D->getIvarLBraceLoc());
890 Record.AddSourceLocation(D->getIvarRBraceLoc());
John McCall0d54a172012-10-17 04:53:31 +0000891 Record.push_back(D->hasNonZeroConstructors());
892 Record.push_back(D->hasDestructors());
Richard Smithc2bb8182015-03-24 06:36:48 +0000893 Record.push_back(D->NumIvarInitializers);
894 if (D->NumIvarInitializers)
Richard Smithaa165cf2016-04-13 21:57:08 +0000895 Record.AddCXXCtorInitializers(
Richard Smith69c82bf2016-04-01 22:52:03 +0000896 llvm::makeArrayRef(D->init_begin(), D->init_end()));
Sebastian Redl539c5062010-08-18 23:57:32 +0000897 Code = serialization::DECL_OBJC_IMPLEMENTATION;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000898}
899
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000900void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000901 VisitDecl(D);
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000902 Record.AddSourceLocation(D->getBeginLoc());
Richard Smith69c82bf2016-04-01 22:52:03 +0000903 Record.AddDeclRef(D->getPropertyDecl());
904 Record.AddDeclRef(D->getPropertyIvarDecl());
905 Record.AddSourceLocation(D->getPropertyIvarDeclLoc());
Adrian Prantl2073dd22019-11-04 14:28:14 -0800906 Record.AddDeclRef(D->getGetterMethodDecl());
907 Record.AddDeclRef(D->getSetterMethodDecl());
Richard Smith290d8012016-04-06 17:06:00 +0000908 Record.AddStmt(D->getGetterCXXConstructor());
909 Record.AddStmt(D->getSetterCXXAssignment());
Sebastian Redl539c5062010-08-18 23:57:32 +0000910 Code = serialization::DECL_OBJC_PROPERTY_IMPL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000911}
912
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000913void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000914 VisitDeclaratorDecl(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000915 Record.push_back(D->isMutable());
Richard Smith6b8e3c02017-08-28 00:28:14 +0000916
917 FieldDecl::InitStorageKind ISK = D->InitStorage.getInt();
918 Record.push_back(ISK);
919 if (ISK == FieldDecl::ISK_CapturedVLAType)
920 Record.AddTypeRef(QualType(D->getCapturedVLAType(), 0));
921 else if (ISK)
922 Record.AddStmt(D->getInClassInitializer());
923
924 Record.AddStmt(D->getBitWidth());
925
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000926 if (!D->getDeclName())
Richard Smith69c82bf2016-04-01 22:52:03 +0000927 Record.AddDeclRef(Context.getInstantiatedFromUnnamedFieldDecl(D));
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000928
Richard Smith8aed4222015-12-11 22:41:00 +0000929 if (D->getDeclContext() == D->getLexicalDeclContext() &&
930 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000931 !D->isImplicit() &&
932 !D->isUsed(false) &&
933 !D->isInvalidDecl() &&
934 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000935 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000936 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000937 !D->getBitWidth() &&
Richard Smith938f40b2011-06-11 17:19:42 +0000938 !D->hasInClassInitializer() &&
Richard Smith6b8e3c02017-08-28 00:28:14 +0000939 !D->hasCapturedVLAType() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000940 !D->hasExtInfo() &&
941 !ObjCIvarDecl::classofKind(D->getKind()) &&
942 !ObjCAtDefsFieldDecl::classofKind(D->getKind()) &&
943 D->getDeclName())
944 AbbrevToUse = Writer.getDeclFieldAbbrev();
945
Sebastian Redl539c5062010-08-18 23:57:32 +0000946 Code = serialization::DECL_FIELD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000947}
948
John McCall5e77d762013-04-16 07:28:30 +0000949void ASTDeclWriter::VisitMSPropertyDecl(MSPropertyDecl *D) {
950 VisitDeclaratorDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000951 Record.AddIdentifierRef(D->getGetterId());
952 Record.AddIdentifierRef(D->getSetterId());
John McCall5e77d762013-04-16 07:28:30 +0000953 Code = serialization::DECL_MS_PROPERTY;
954}
955
Francois Pichet783dd6e2010-11-21 06:08:52 +0000956void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
957 VisitValueDecl(D);
958 Record.push_back(D->getChainingSize());
959
Aaron Ballman29c94602014-03-07 18:36:15 +0000960 for (const auto *P : D->chain())
Richard Smith69c82bf2016-04-01 22:52:03 +0000961 Record.AddDeclRef(P);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000962 Code = serialization::DECL_INDIRECTFIELD;
963}
964
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000965void ASTDeclWriter::VisitVarDecl(VarDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000966 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000967 VisitDeclaratorDecl(D);
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000968 Record.push_back(D->getStorageClass());
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +0000969 Record.push_back(D->getTSCSpec());
Sebastian Redla9351792012-02-11 23:51:47 +0000970 Record.push_back(D->getInitStyle());
Erik Pilkington1e368822019-01-04 18:33:06 +0000971 Record.push_back(D->isARCPseudoStrong());
David Majnemerfa7bc782015-05-19 00:57:16 +0000972 if (!isa<ParmVarDecl>(D)) {
Richard Smithedbc6e92016-10-14 21:41:24 +0000973 Record.push_back(D->isThisDeclarationADemotedDefinition());
David Majnemerfa7bc782015-05-19 00:57:16 +0000974 Record.push_back(D->isExceptionVariable());
Taiju Tsuiki3be68e12018-06-19 05:35:30 +0000975 Record.push_back(D->isNRVOVariable());
David Majnemerfa7bc782015-05-19 00:57:16 +0000976 Record.push_back(D->isCXXForRangeDecl());
George Karpenkovec38cf72018-03-29 00:56:24 +0000977 Record.push_back(D->isObjCForDecl());
Richard Smith62f19e72016-06-25 00:15:56 +0000978 Record.push_back(D->isInline());
979 Record.push_back(D->isInlineSpecified());
David Majnemerfa7bc782015-05-19 00:57:16 +0000980 Record.push_back(D->isConstexpr());
981 Record.push_back(D->isInitCapture());
982 Record.push_back(D->isPreviousDeclInSameBlockScope());
Alexey Bataev56223232017-06-09 13:40:18 +0000983 if (const auto *IPD = dyn_cast<ImplicitParamDecl>(D))
984 Record.push_back(static_cast<unsigned>(IPD->getParameterKind()));
985 else
986 Record.push_back(0);
Akira Hatanaka8e57b072018-10-01 21:51:28 +0000987 Record.push_back(D->isEscapingByref());
David Majnemerfa7bc782015-05-19 00:57:16 +0000988 }
Rafael Espindola3ae00052013-05-13 00:12:11 +0000989 Record.push_back(D->getLinkageInternal());
Douglas Gregor12cda632012-09-20 23:43:29 +0000990
Richard Smithd0b4dd62011-12-19 06:19:21 +0000991 if (D->getInit()) {
Richard Smith2b4fa532019-09-29 05:08:46 +0000992 if (!D->isInitKnownICE())
993 Record.push_back(1);
994 else {
995 Record.push_back(
996 2 |
997 (D->isInitICE() ? 1 : 0) |
998 (D->ensureEvaluatedStmt()->HasConstantDestruction ? 4 : 0));
999 }
Richard Smith290d8012016-04-06 17:06:00 +00001000 Record.AddStmt(D->getInit());
Richard Smithd0b4dd62011-12-19 06:19:21 +00001001 } else {
1002 Record.push_back(0);
1003 }
Richard Smitha4653622017-09-06 20:01:14 +00001004
Akira Hatanaka9978da32018-08-10 15:09:24 +00001005 if (D->hasAttr<BlocksAttr>() && D->getType()->getAsCXXRecordDecl()) {
Reid Kleckner60573ae2019-11-15 17:31:55 -08001006 BlockVarCopyInit Init = Writer.Context->getBlockVarCopyInit(D);
Akira Hatanaka9978da32018-08-10 15:09:24 +00001007 Record.AddStmt(Init.getCopyExpr());
1008 if (Init.getCopyExpr())
1009 Record.push_back(Init.canThrow());
1010 }
1011
Richard Smitha4653622017-09-06 20:01:14 +00001012 if (D->getStorageDuration() == SD_Static) {
1013 bool ModulesCodegen = false;
Hans Wennborg7ea9a6e2020-02-27 14:33:43 +01001014 if (Writer.WritingModule &&
1015 !D->getDescribedVarTemplate() && !D->getMemberSpecializationInfo() &&
Richard Smitha4653622017-09-06 20:01:14 +00001016 !isa<VarTemplateSpecializationDecl>(D)) {
1017 // When building a C++ Modules TS module interface unit, a strong
1018 // definition in the module interface is provided by the compilation of
1019 // that module interface unit, not by its users. (Inline variables are
1020 // still emitted in module users.)
1021 ModulesCodegen =
Hans Wennborg7ea9a6e2020-02-27 14:33:43 +01001022 (Writer.WritingModule->Kind == Module::ModuleInterfaceUnit &&
Richard Smitha4653622017-09-06 20:01:14 +00001023 Writer.Context->GetGVALinkageForVariable(D) == GVA_StrongExternal);
1024 }
1025 Record.push_back(ModulesCodegen);
1026 if (ModulesCodegen)
1027 Writer.ModularCodegenDecls.push_back(Writer.GetDeclRef(D));
1028 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001029
Larisse Voufod8dd97c2013-08-14 03:09:19 +00001030 enum {
1031 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
1032 };
1033 if (VarTemplateDecl *TemplD = D->getDescribedVarTemplate()) {
1034 Record.push_back(VarTemplate);
Richard Smith69c82bf2016-04-01 22:52:03 +00001035 Record.AddDeclRef(TemplD);
Larisse Voufod8dd97c2013-08-14 03:09:19 +00001036 } else if (MemberSpecializationInfo *SpecInfo
1037 = D->getMemberSpecializationInfo()) {
1038 Record.push_back(StaticDataMemberSpecialization);
Richard Smith69c82bf2016-04-01 22:52:03 +00001039 Record.AddDeclRef(SpecInfo->getInstantiatedFrom());
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001040 Record.push_back(SpecInfo->getTemplateSpecializationKind());
Richard Smith69c82bf2016-04-01 22:52:03 +00001041 Record.AddSourceLocation(SpecInfo->getPointOfInstantiation());
Larisse Voufod8dd97c2013-08-14 03:09:19 +00001042 } else {
1043 Record.push_back(VarNotTemplate);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001044 }
1045
Richard Smith8aed4222015-12-11 22:41:00 +00001046 if (D->getDeclContext() == D->getLexicalDeclContext() &&
1047 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001048 !D->isImplicit() &&
1049 !D->isUsed(false) &&
1050 !D->isInvalidDecl() &&
1051 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +00001052 !D->isTopLevelDeclInObjCContainer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001053 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +00001054 !D->isModulePrivate() &&
Richard Smithd08aeb62014-08-28 01:33:39 +00001055 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001056 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
1057 !D->hasExtInfo() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +00001058 D->getFirstDecl() == D->getMostRecentDecl() &&
Richard Smith7b76d812016-08-12 02:21:25 +00001059 D->getKind() == Decl::Var &&
Richard Smith62f19e72016-06-25 00:15:56 +00001060 !D->isInline() &&
Douglas Gregor12cda632012-09-20 23:43:29 +00001061 !D->isConstexpr() &&
Richard Smithbb13c9a2013-09-28 04:02:39 +00001062 !D->isInitCapture() &&
Richard Smith1c34fb72013-08-13 18:18:50 +00001063 !D->isPreviousDeclInSameBlockScope() &&
Akira Hatanaka9978da32018-08-10 15:09:24 +00001064 !(D->hasAttr<BlocksAttr>() && D->getType()->getAsCXXRecordDecl()) &&
Akira Hatanaka8e57b072018-10-01 21:51:28 +00001065 !D->isEscapingByref() &&
Richard Smitha4653622017-09-06 20:01:14 +00001066 D->getStorageDuration() != SD_Static &&
Larisse Voufod8dd97c2013-08-14 03:09:19 +00001067 !D->getMemberSpecializationInfo())
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001068 AbbrevToUse = Writer.getDeclVarAbbrev();
1069
Sebastian Redl539c5062010-08-18 23:57:32 +00001070 Code = serialization::DECL_VAR;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001071}
1072
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001073void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001074 VisitVarDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001075 Code = serialization::DECL_IMPLICIT_PARAM;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001076}
1077
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001078void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001079 VisitVarDecl(D);
John McCall82490832011-05-02 00:30:12 +00001080 Record.push_back(D->isObjCMethodParameter());
John McCall8fb0d9d2011-05-01 22:35:37 +00001081 Record.push_back(D->getFunctionScopeDepth());
1082 Record.push_back(D->getFunctionScopeIndex());
Chris Lattner7099dbc2009-04-27 06:16:06 +00001083 Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding
John McCall6a014d52011-03-09 04:22:44 +00001084 Record.push_back(D->isKNRPromoted());
John McCallf3cd6652010-03-12 18:31:32 +00001085 Record.push_back(D->hasInheritedDefaultArg());
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +00001086 Record.push_back(D->hasUninstantiatedDefaultArg());
1087 if (D->hasUninstantiatedDefaultArg())
Richard Smith290d8012016-04-06 17:06:00 +00001088 Record.AddStmt(D->getUninstantiatedDefaultArg());
Sebastian Redl539c5062010-08-18 23:57:32 +00001089 Code = serialization::DECL_PARM_VAR;
Mike Stump11289f42009-09-09 15:08:12 +00001090
John McCalld4631322011-06-17 06:42:21 +00001091 assert(!D->isARCPseudoStrong()); // can be true of ImplicitParamDecl
1092
Chris Lattner258172e2009-04-27 07:35:58 +00001093 // If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here
1094 // we dynamically check for the properties that we optimize for, but don't
1095 // know are true of all PARM_VAR_DECLs.
Richard Smith8aed4222015-12-11 22:41:00 +00001096 if (D->getDeclContext() == D->getLexicalDeclContext() &&
1097 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001098 !D->hasExtInfo() &&
Chris Lattner258172e2009-04-27 07:35:58 +00001099 !D->isImplicit() &&
Douglas Gregorebada0772010-06-17 23:14:26 +00001100 !D->isUsed(false) &&
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001101 !D->isInvalidDecl() &&
Eli Friedmanc09e0552012-01-13 23:41:25 +00001102 !D->isReferenced() &&
Chris Lattner258172e2009-04-27 07:35:58 +00001103 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +00001104 !D->isModulePrivate() &&
Chris Lattner258172e2009-04-27 07:35:58 +00001105 D->getStorageClass() == 0 &&
Sebastian Redla9351792012-02-11 23:51:47 +00001106 D->getInitStyle() == VarDecl::CInit && // Can params have anything else?
John McCall82490832011-05-02 00:30:12 +00001107 D->getFunctionScopeDepth() == 0 &&
John McCallf3cd6652010-03-12 18:31:32 +00001108 D->getObjCDeclQualifier() == 0 &&
John McCall6a014d52011-03-09 04:22:44 +00001109 !D->isKNRPromoted() &&
Chris Lattnere2437f42010-05-09 06:40:08 +00001110 !D->hasInheritedDefaultArg() &&
Craig Toppera13603a2014-05-22 05:54:18 +00001111 D->getInit() == nullptr &&
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +00001112 !D->hasUninstantiatedDefaultArg()) // No default expr.
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001113 AbbrevToUse = Writer.getDeclParmVarAbbrev();
Chris Lattner258172e2009-04-27 07:35:58 +00001114
1115 // Check things we know are true of *every* PARM_VAR_DECL, which is more than
1116 // just us assuming it.
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +00001117 assert(!D->getTSCSpec() && "PARM_VAR_DECL can't use TLS");
Richard Smithedbc6e92016-10-14 21:41:24 +00001118 assert(!D->isThisDeclarationADemotedDefinition()
1119 && "PARM_VAR_DECL can't be demoted definition.");
Chris Lattner258172e2009-04-27 07:35:58 +00001120 assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private");
Douglas Gregor3f324d562010-05-03 18:51:14 +00001121 assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var");
Craig Toppera13603a2014-05-22 05:54:18 +00001122 assert(D->getPreviousDecl() == nullptr && "PARM_VAR_DECL can't be redecl");
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001123 assert(!D->isStaticDataMember() &&
1124 "PARM_VAR_DECL can't be static data member");
Chris Lattner7099dbc2009-04-27 06:16:06 +00001125}
1126
Richard Smith7b76d812016-08-12 02:21:25 +00001127void ASTDeclWriter::VisitDecompositionDecl(DecompositionDecl *D) {
1128 // Record the number of bindings first to simplify deserialization.
1129 Record.push_back(D->bindings().size());
1130
1131 VisitVarDecl(D);
1132 for (auto *B : D->bindings())
1133 Record.AddDeclRef(B);
1134 Code = serialization::DECL_DECOMPOSITION;
1135}
1136
1137void ASTDeclWriter::VisitBindingDecl(BindingDecl *D) {
1138 VisitValueDecl(D);
1139 Record.AddStmt(D->getBinding());
1140 Code = serialization::DECL_BINDING;
1141}
1142
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001143void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001144 VisitDecl(D);
Richard Smith290d8012016-04-06 17:06:00 +00001145 Record.AddStmt(D->getAsmString());
Richard Smith69c82bf2016-04-01 22:52:03 +00001146 Record.AddSourceLocation(D->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001147 Code = serialization::DECL_FILE_SCOPE_ASM;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001148}
1149
Michael Han84324352013-02-22 17:15:32 +00001150void ASTDeclWriter::VisitEmptyDecl(EmptyDecl *D) {
1151 VisitDecl(D);
1152 Code = serialization::DECL_EMPTY;
1153}
1154
Tykerb0561b32019-11-17 11:41:55 +01001155void ASTDeclWriter::VisitLifetimeExtendedTemporaryDecl(
1156 LifetimeExtendedTemporaryDecl *D) {
1157 VisitDecl(D);
1158 Record.AddDeclRef(D->getExtendingDecl());
1159 Record.AddStmt(D->getTemporaryExpr());
1160 Record.push_back(static_cast<bool>(D->getValue()));
1161 if (D->getValue())
1162 Record.AddAPValue(*D->getValue());
1163 Record.push_back(D->getManglingNumber());
1164 Code = serialization::DECL_LIFETIME_EXTENDED_TEMPORARY;
1165}
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001166void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001167 VisitDecl(D);
Richard Smith290d8012016-04-06 17:06:00 +00001168 Record.AddStmt(D->getBody());
Richard Smith69c82bf2016-04-01 22:52:03 +00001169 Record.AddTypeSourceInfo(D->getSignatureAsWritten());
Chris Lattner7099dbc2009-04-27 06:16:06 +00001170 Record.push_back(D->param_size());
David Majnemera3debed2016-06-24 05:33:44 +00001171 for (ParmVarDecl *P : D->parameters())
1172 Record.AddDeclRef(P);
John McCallcf6ce282012-04-13 17:33:29 +00001173 Record.push_back(D->isVariadic());
1174 Record.push_back(D->blockMissingReturnType());
1175 Record.push_back(D->isConversionFromLambda());
Akira Hatanakadb49a1f2018-08-01 23:51:53 +00001176 Record.push_back(D->doesNotEscape());
Akira Hatanakac5792aa2019-02-27 18:17:16 +00001177 Record.push_back(D->canAvoidCopyToHeap());
John McCallc63de662011-02-02 13:00:07 +00001178 Record.push_back(D->capturesCXXThis());
John McCall351762c2011-02-07 10:33:21 +00001179 Record.push_back(D->getNumCaptures());
Aaron Ballman9371dd22014-03-14 18:34:04 +00001180 for (const auto &capture : D->captures()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001181 Record.AddDeclRef(capture.getVariable());
John McCall351762c2011-02-07 10:33:21 +00001182
1183 unsigned flags = 0;
1184 if (capture.isByRef()) flags |= 1;
1185 if (capture.isNested()) flags |= 2;
1186 if (capture.hasCopyExpr()) flags |= 4;
1187 Record.push_back(flags);
1188
Richard Smith290d8012016-04-06 17:06:00 +00001189 if (capture.hasCopyExpr()) Record.AddStmt(capture.getCopyExpr());
John McCall351762c2011-02-07 10:33:21 +00001190 }
John McCallc63de662011-02-02 13:00:07 +00001191
Sebastian Redl539c5062010-08-18 23:57:32 +00001192 Code = serialization::DECL_BLOCK;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001193}
1194
Ben Langmuirce914fc2013-05-03 19:20:19 +00001195void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) {
1196 Record.push_back(CD->getNumParams());
1197 VisitDecl(CD);
Alexey Bataev9959db52014-05-06 10:08:46 +00001198 Record.push_back(CD->getContextParamPosition());
1199 Record.push_back(CD->isNothrow() ? 1 : 0);
Ben Langmuirce914fc2013-05-03 19:20:19 +00001200 // Body is stored by VisitCapturedStmt.
Alexey Bataev9959db52014-05-06 10:08:46 +00001201 for (unsigned I = 0; I < CD->getNumParams(); ++I)
Richard Smith69c82bf2016-04-01 22:52:03 +00001202 Record.AddDeclRef(CD->getParam(I));
Ben Langmuirce914fc2013-05-03 19:20:19 +00001203 Code = serialization::DECL_CAPTURED;
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001204}
1205
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001206void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001207 VisitDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001208 Record.push_back(D->getLanguage());
Richard Smith69c82bf2016-04-01 22:52:03 +00001209 Record.AddSourceLocation(D->getExternLoc());
1210 Record.AddSourceLocation(D->getRBraceLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001211 Code = serialization::DECL_LINKAGE_SPEC;
Chris Lattnerca025db2010-05-07 21:43:38 +00001212}
1213
Richard Smith8df390f2016-09-08 23:14:54 +00001214void ASTDeclWriter::VisitExportDecl(ExportDecl *D) {
1215 VisitDecl(D);
1216 Record.AddSourceLocation(D->getRBraceLoc());
1217 Code = serialization::DECL_EXPORT;
1218}
1219
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001220void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) {
1221 VisitNamedDecl(D);
Stephen Kellyf2ceec42018-08-09 21:08:08 +00001222 Record.AddSourceLocation(D->getBeginLoc());
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001223 Code = serialization::DECL_LABEL;
1224}
1225
1226
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001227void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
Douglas Gregore57e7522012-01-07 09:11:48 +00001228 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001229 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +00001230 Record.push_back(D->isInline());
Stephen Kellyf2ceec42018-08-09 21:08:08 +00001231 Record.AddSourceLocation(D->getBeginLoc());
Richard Smith69c82bf2016-04-01 22:52:03 +00001232 Record.AddSourceLocation(D->getRBraceLoc());
Chris Lattnerca025db2010-05-07 21:43:38 +00001233
Chris Lattnerca025db2010-05-07 21:43:38 +00001234 if (D->isOriginalNamespace())
Richard Smith69c82bf2016-04-01 22:52:03 +00001235 Record.AddDeclRef(D->getAnonymousNamespace());
Sebastian Redl539c5062010-08-18 23:57:32 +00001236 Code = serialization::DECL_NAMESPACE;
Sebastian Redlf03cdc52010-08-05 21:22:19 +00001237
Fangrui Song6907ce22018-07-30 19:24:48 +00001238 if (Writer.hasChain() && D->isAnonymousNamespace() &&
Douglas Gregorec9fd132012-01-14 16:38:05 +00001239 D == D->getMostRecentDecl()) {
Sebastian Redl010288f2011-04-24 16:28:21 +00001240 // This is a most recent reopening of the anonymous namespace. If its parent
1241 // is in a previous PCH (or is the TU), mark that parent for update, because
1242 // the original namespace always points to the latest re-opening of its
1243 // anonymous namespace.
1244 Decl *Parent = cast<Decl>(
1245 D->getParent()->getRedeclContext()->getPrimaryContext());
Douglas Gregorb3722e22011-09-09 23:01:35 +00001246 if (Parent->isFromASTFile() || isa<TranslationUnitDecl>(Parent)) {
Richard Smith6ef42932014-03-20 21:02:00 +00001247 Writer.DeclUpdates[Parent].push_back(
Aaron Ballman4f45b712014-03-21 15:22:56 +00001248 ASTWriter::DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, D));
Sebastian Redlfa1f3702011-04-24 16:28:13 +00001249 }
1250 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001251}
1252
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001253void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Richard Smithf4634362014-09-03 23:11:22 +00001254 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001255 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001256 Record.AddSourceLocation(D->getNamespaceLoc());
1257 Record.AddSourceLocation(D->getTargetNameLoc());
1258 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1259 Record.AddDeclRef(D->getNamespace());
Sebastian Redl539c5062010-08-18 23:57:32 +00001260 Code = serialization::DECL_NAMESPACE_ALIAS;
Chris Lattnerca025db2010-05-07 21:43:38 +00001261}
1262
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001263void ASTDeclWriter::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001264 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001265 Record.AddSourceLocation(D->getUsingLoc());
1266 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1267 Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
1268 Record.AddDeclRef(D->FirstUsingShadow.getPointer());
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00001269 Record.push_back(D->hasTypename());
Richard Smith69c82bf2016-04-01 22:52:03 +00001270 Record.AddDeclRef(Context.getInstantiatedFromUsingDecl(D));
Sebastian Redl539c5062010-08-18 23:57:32 +00001271 Code = serialization::DECL_USING;
Chris Lattnerca025db2010-05-07 21:43:38 +00001272}
1273
Richard Smith151c4562016-12-20 21:35:28 +00001274void ASTDeclWriter::VisitUsingPackDecl(UsingPackDecl *D) {
1275 Record.push_back(D->NumExpansions);
1276 VisitNamedDecl(D);
1277 Record.AddDeclRef(D->getInstantiatedFromUsingDecl());
1278 for (auto *E : D->expansions())
1279 Record.AddDeclRef(E);
1280 Code = serialization::DECL_USING_PACK;
1281}
1282
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001283void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) {
Richard Smithfd8634a2013-10-23 02:17:46 +00001284 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001285 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001286 Record.AddDeclRef(D->getTargetDecl());
Richard Smitha263c342018-01-06 01:07:05 +00001287 Record.push_back(D->getIdentifierNamespace());
Richard Smith69c82bf2016-04-01 22:52:03 +00001288 Record.AddDeclRef(D->UsingOrNextShadow);
1289 Record.AddDeclRef(Context.getInstantiatedFromUsingShadowDecl(D));
Sebastian Redl539c5062010-08-18 23:57:32 +00001290 Code = serialization::DECL_USING_SHADOW;
Chris Lattnerca025db2010-05-07 21:43:38 +00001291}
1292
Richard Smith5179eb72016-06-28 19:03:57 +00001293void ASTDeclWriter::VisitConstructorUsingShadowDecl(
1294 ConstructorUsingShadowDecl *D) {
1295 VisitUsingShadowDecl(D);
1296 Record.AddDeclRef(D->NominatedBaseClassShadowDecl);
1297 Record.AddDeclRef(D->ConstructedBaseClassShadowDecl);
1298 Record.push_back(D->IsVirtual);
1299 Code = serialization::DECL_CONSTRUCTOR_USING_SHADOW;
1300}
1301
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001302void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001303 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001304 Record.AddSourceLocation(D->getUsingLoc());
1305 Record.AddSourceLocation(D->getNamespaceKeyLocation());
1306 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1307 Record.AddDeclRef(D->getNominatedNamespace());
1308 Record.AddDeclRef(dyn_cast<Decl>(D->getCommonAncestor()));
Sebastian Redl539c5062010-08-18 23:57:32 +00001309 Code = serialization::DECL_USING_DIRECTIVE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001310}
1311
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001312void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001313 VisitValueDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001314 Record.AddSourceLocation(D->getUsingLoc());
1315 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1316 Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
Richard Smith151c4562016-12-20 21:35:28 +00001317 Record.AddSourceLocation(D->getEllipsisLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001318 Code = serialization::DECL_UNRESOLVED_USING_VALUE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001319}
1320
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001321void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001322 UnresolvedUsingTypenameDecl *D) {
1323 VisitTypeDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001324 Record.AddSourceLocation(D->getTypenameLoc());
1325 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
Richard Smith151c4562016-12-20 21:35:28 +00001326 Record.AddSourceLocation(D->getEllipsisLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001327 Code = serialization::DECL_UNRESOLVED_USING_TYPENAME;
Chris Lattnerca025db2010-05-07 21:43:38 +00001328}
1329
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001330void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001331 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001332
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001333 enum {
1334 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1335 };
1336 if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) {
1337 Record.push_back(CXXRecTemplate);
Richard Smith69c82bf2016-04-01 22:52:03 +00001338 Record.AddDeclRef(TemplD);
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001339 } else if (MemberSpecializationInfo *MSInfo
1340 = D->getMemberSpecializationInfo()) {
1341 Record.push_back(CXXRecMemberSpecialization);
Richard Smith69c82bf2016-04-01 22:52:03 +00001342 Record.AddDeclRef(MSInfo->getInstantiatedFrom());
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001343 Record.push_back(MSInfo->getTemplateSpecializationKind());
Richard Smith69c82bf2016-04-01 22:52:03 +00001344 Record.AddSourceLocation(MSInfo->getPointOfInstantiation());
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001345 } else {
1346 Record.push_back(CXXRecNotTemplate);
1347 }
1348
Richard Smithcd45dbc2014-04-19 03:48:30 +00001349 Record.push_back(D->isThisDeclarationADefinition());
1350 if (D->isThisDeclarationADefinition())
Richard Smith69c82bf2016-04-01 22:52:03 +00001351 Record.AddCXXDefinitionData(D);
Richard Smithcd45dbc2014-04-19 03:48:30 +00001352
John McCall6bd2a892013-01-25 22:31:03 +00001353 // Store (what we currently believe to be) the key function to avoid
1354 // deserializing every method so we can compute it.
Erich Keanef92f31c2018-08-01 20:48:16 +00001355 if (D->isCompleteDefinition())
Richard Smith69c82bf2016-04-01 22:52:03 +00001356 Record.AddDeclRef(Context.getCurrentKeyFunction(D));
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001357
Sebastian Redl539c5062010-08-18 23:57:32 +00001358 Code = serialization::DECL_CXX_RECORD;
Chris Lattnerca025db2010-05-07 21:43:38 +00001359}
1360
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001361void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001362 VisitFunctionDecl(D);
Argyrios Kyrtzidis3b1a7792012-10-12 05:31:40 +00001363 if (D->isCanonicalDecl()) {
1364 Record.push_back(D->size_overridden_methods());
Benjamin Krameracfa3392017-12-17 23:52:45 +00001365 for (const CXXMethodDecl *MD : D->overridden_methods())
1366 Record.AddDeclRef(MD);
Argyrios Kyrtzidis3b1a7792012-10-12 05:31:40 +00001367 } else {
1368 // We only need to record overridden methods once for the canonical decl.
1369 Record.push_back(0);
1370 }
Richard Smith01b2cb42014-07-26 06:37:51 +00001371
Richard Smith8aed4222015-12-11 22:41:00 +00001372 if (D->getDeclContext() == D->getLexicalDeclContext() &&
1373 D->getFirstDecl() == D->getMostRecentDecl() &&
Richard Smith01b2cb42014-07-26 06:37:51 +00001374 !D->isInvalidDecl() &&
1375 !D->hasAttrs() &&
1376 !D->isTopLevelDeclInObjCContainer() &&
1377 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
1378 !D->hasExtInfo() &&
1379 !D->hasInheritedPrototype() &&
1380 D->hasWrittenPrototype())
1381 AbbrevToUse = Writer.getDeclCXXMethodAbbrev();
1382
Sebastian Redl539c5062010-08-18 23:57:32 +00001383 Code = serialization::DECL_CXX_METHOD;
Chris Lattnerca025db2010-05-07 21:43:38 +00001384}
1385
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001386void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Richard Smith76b90272019-05-09 03:59:21 +00001387 Record.push_back(D->getTraillingAllocKind());
1388 addExplicitSpecifier(D->getExplicitSpecifier(), Record);
Richard Smith5179eb72016-06-28 19:03:57 +00001389 if (auto Inherited = D->getInheritedConstructor()) {
1390 Record.AddDeclRef(Inherited.getShadowDecl());
1391 Record.AddDeclRef(Inherited.getConstructor());
Richard Smith5179eb72016-06-28 19:03:57 +00001392 }
1393
Chris Lattnerca025db2010-05-07 21:43:38 +00001394 VisitCXXMethodDecl(D);
Richard Smith76b90272019-05-09 03:59:21 +00001395 Code = serialization::DECL_CXX_CONSTRUCTOR;
Chris Lattnerca025db2010-05-07 21:43:38 +00001396}
1397
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001398void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001399 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001400
Richard Smith69c82bf2016-04-01 22:52:03 +00001401 Record.AddDeclRef(D->getOperatorDelete());
Richard Smith5b349582017-10-13 01:55:36 +00001402 if (D->getOperatorDelete())
1403 Record.AddStmt(D->getOperatorDeleteThisArg());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001404
Sebastian Redl539c5062010-08-18 23:57:32 +00001405 Code = serialization::DECL_CXX_DESTRUCTOR;
Chris Lattnerca025db2010-05-07 21:43:38 +00001406}
1407
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001408void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) {
Richard Smith76b90272019-05-09 03:59:21 +00001409 addExplicitSpecifier(D->getExplicitSpecifier(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001410 VisitCXXMethodDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001411 Code = serialization::DECL_CXX_CONVERSION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001412}
1413
Douglas Gregorba345522011-12-02 23:23:56 +00001414void ASTDeclWriter::VisitImportDecl(ImportDecl *D) {
1415 VisitDecl(D);
Argyrios Kyrtzidis7b8e5552012-10-03 01:58:45 +00001416 Record.push_back(Writer.getSubmoduleID(D->getImportedModule()));
Douglas Gregorba345522011-12-02 23:23:56 +00001417 ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs();
1418 Record.push_back(!IdentifierLocs.empty());
1419 if (IdentifierLocs.empty()) {
Stephen Kelly1c301dc2018-08-09 21:09:38 +00001420 Record.AddSourceLocation(D->getEndLoc());
Douglas Gregorba345522011-12-02 23:23:56 +00001421 Record.push_back(1);
1422 } else {
1423 for (unsigned I = 0, N = IdentifierLocs.size(); I != N; ++I)
Richard Smith69c82bf2016-04-01 22:52:03 +00001424 Record.AddSourceLocation(IdentifierLocs[I]);
Douglas Gregorba345522011-12-02 23:23:56 +00001425 Record.push_back(IdentifierLocs.size());
1426 }
1427 // Note: the number of source locations must always be the last element in
1428 // the record.
1429 Code = serialization::DECL_IMPORT;
1430}
1431
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001432void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001433 VisitDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001434 Record.AddSourceLocation(D->getColonLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001435 Code = serialization::DECL_ACCESS_SPEC;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001436}
1437
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001438void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) {
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001439 // Record the number of friend type template parameter lists here
1440 // so as to simplify memory allocation during deserialization.
1441 Record.push_back(D->NumTPLists);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001442 VisitDecl(D);
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001443 bool hasFriendDecl = D->Friend.is<NamedDecl*>();
1444 Record.push_back(hasFriendDecl);
1445 if (hasFriendDecl)
Richard Smith69c82bf2016-04-01 22:52:03 +00001446 Record.AddDeclRef(D->getFriendDecl());
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001447 else
Richard Smith69c82bf2016-04-01 22:52:03 +00001448 Record.AddTypeSourceInfo(D->getFriendType());
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001449 for (unsigned i = 0; i < D->NumTPLists; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +00001450 Record.AddTemplateParameterList(D->getFriendTypeTemplateParameterList(i));
1451 Record.AddDeclRef(D->getNextFriend());
John McCall2c2eb122010-10-16 06:59:13 +00001452 Record.push_back(D->UnsupportedFriend);
Richard Smith69c82bf2016-04-01 22:52:03 +00001453 Record.AddSourceLocation(D->FriendLoc);
Sebastian Redl539c5062010-08-18 23:57:32 +00001454 Code = serialization::DECL_FRIEND;
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001455}
1456
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001457void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001458 VisitDecl(D);
1459 Record.push_back(D->getNumTemplateParameters());
1460 for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +00001461 Record.AddTemplateParameterList(D->getTemplateParameterList(i));
Craig Toppera13603a2014-05-22 05:54:18 +00001462 Record.push_back(D->getFriendDecl() != nullptr);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001463 if (D->getFriendDecl())
Richard Smith69c82bf2016-04-01 22:52:03 +00001464 Record.AddDeclRef(D->getFriendDecl());
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001465 else
Richard Smith69c82bf2016-04-01 22:52:03 +00001466 Record.AddTypeSourceInfo(D->getFriendType());
1467 Record.AddSourceLocation(D->getFriendLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001468 Code = serialization::DECL_FRIEND_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001469}
1470
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001471void ASTDeclWriter::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001472 VisitNamedDecl(D);
1473
Richard Smith69c82bf2016-04-01 22:52:03 +00001474 Record.AddDeclRef(D->getTemplatedDecl());
1475 Record.AddTemplateParameterList(D->getTemplateParameters());
Chris Lattnerca025db2010-05-07 21:43:38 +00001476}
1477
Saar Razd7aae332019-07-10 21:25:49 +00001478void ASTDeclWriter::VisitConceptDecl(ConceptDecl *D) {
1479 VisitTemplateDecl(D);
1480 Record.AddStmt(D->getConstraintExpr());
1481 Code = serialization::DECL_CONCEPT;
1482}
1483
Saar Raza0f50d72020-01-18 09:11:43 +02001484void ASTDeclWriter::VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D) {
1485 Code = serialization::DECL_REQUIRES_EXPR_BODY;
1486}
1487
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001488void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Douglas Gregor68444de2012-01-14 15:13:49 +00001489 VisitRedeclarable(D);
1490
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001491 // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that
1492 // getCommonPtr() can be used while this is still initializing.
Rafael Espindola8db352d2013-10-17 15:37:26 +00001493 if (D->isFirstDecl()) {
Douglas Gregor074a4092011-12-19 18:19:24 +00001494 // This declaration owns the 'common' pointer, so serialize that data now.
Richard Smith69c82bf2016-04-01 22:52:03 +00001495 Record.AddDeclRef(D->getInstantiatedFromMemberTemplate());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001496 if (D->getInstantiatedFromMemberTemplate())
1497 Record.push_back(D->isMemberSpecialization());
Douglas Gregor074a4092011-12-19 18:19:24 +00001498 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001499
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001500 VisitTemplateDecl(D);
1501 Record.push_back(D->getIdentifierNamespace());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001502}
1503
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001504void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001505 VisitRedeclarableTemplateDecl(D);
1506
Richard Smith509fc852015-02-27 23:05:10 +00001507 if (D->isFirstDecl())
1508 AddTemplateSpecializations(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001509 Code = serialization::DECL_CLASS_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001510}
1511
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001512void ASTDeclWriter::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001513 ClassTemplateSpecializationDecl *D) {
Richard Smithd8a83712015-08-22 01:47:18 +00001514 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1515
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001516 VisitCXXRecordDecl(D);
1517
1518 llvm::PointerUnion<ClassTemplateDecl *,
1519 ClassTemplatePartialSpecializationDecl *> InstFrom
1520 = D->getSpecializedTemplateOrPartial();
Argyrios Kyrtzidisd5553f12011-08-17 21:35:28 +00001521 if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001522 Record.AddDeclRef(InstFromD);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001523 } else {
Richard Smith69c82bf2016-04-01 22:52:03 +00001524 Record.AddDeclRef(InstFrom.get<ClassTemplatePartialSpecializationDecl *>());
1525 Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001526 }
1527
Richard Smith69c82bf2016-04-01 22:52:03 +00001528 Record.AddTemplateArgumentList(&D->getTemplateArgs());
1529 Record.AddSourceLocation(D->getPointOfInstantiation());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001530 Record.push_back(D->getSpecializationKind());
Axel Naumanna31dee22012-10-01 07:34:47 +00001531 Record.push_back(D->isCanonicalDecl());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001532
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001533 if (D->isCanonicalDecl()) {
Fangrui Song6907ce22018-07-30 19:24:48 +00001534 // When reading, we'll add it to the folding set of the following template.
Richard Smith69c82bf2016-04-01 22:52:03 +00001535 Record.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl());
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001536 }
1537
Richard Smithd55889a2013-09-09 16:55:27 +00001538 // Explicit info.
Richard Smith69c82bf2016-04-01 22:52:03 +00001539 Record.AddTypeSourceInfo(D->getTypeAsWritten());
Richard Smithd55889a2013-09-09 16:55:27 +00001540 if (D->getTypeAsWritten()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001541 Record.AddSourceLocation(D->getExternLoc());
1542 Record.AddSourceLocation(D->getTemplateKeywordLoc());
Richard Smithd55889a2013-09-09 16:55:27 +00001543 }
1544
Sebastian Redl539c5062010-08-18 23:57:32 +00001545 Code = serialization::DECL_CLASS_TEMPLATE_SPECIALIZATION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001546}
1547
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001548void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001549 ClassTemplatePartialSpecializationDecl *D) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001550 Record.AddTemplateParameterList(D->getTemplateParameters());
1551 Record.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001552
Saar Razdf061c32019-12-23 08:37:35 +02001553 VisitClassTemplateSpecializationDecl(D);
1554
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001555 // These are read/set from/to the first declaration.
Craig Toppera13603a2014-05-22 05:54:18 +00001556 if (D->getPreviousDecl() == nullptr) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001557 Record.AddDeclRef(D->getInstantiatedFromMember());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001558 Record.push_back(D->isMemberSpecialization());
1559 }
1560
Sebastian Redl539c5062010-08-18 23:57:32 +00001561 Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001562}
1563
Larisse Voufo39a1e502013-08-06 01:03:05 +00001564void ASTDeclWriter::VisitVarTemplateDecl(VarTemplateDecl *D) {
1565 VisitRedeclarableTemplateDecl(D);
1566
Richard Smith509fc852015-02-27 23:05:10 +00001567 if (D->isFirstDecl())
1568 AddTemplateSpecializations(D);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001569 Code = serialization::DECL_VAR_TEMPLATE;
1570}
1571
1572void ASTDeclWriter::VisitVarTemplateSpecializationDecl(
1573 VarTemplateSpecializationDecl *D) {
Richard Smithd8a83712015-08-22 01:47:18 +00001574 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1575
Larisse Voufo39a1e502013-08-06 01:03:05 +00001576 VisitVarDecl(D);
1577
1578 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
1579 InstFrom = D->getSpecializedTemplateOrPartial();
1580 if (Decl *InstFromD = InstFrom.dyn_cast<VarTemplateDecl *>()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001581 Record.AddDeclRef(InstFromD);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001582 } else {
Richard Smith69c82bf2016-04-01 22:52:03 +00001583 Record.AddDeclRef(InstFrom.get<VarTemplatePartialSpecializationDecl *>());
1584 Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001585 }
1586
1587 // Explicit info.
Richard Smith69c82bf2016-04-01 22:52:03 +00001588 Record.AddTypeSourceInfo(D->getTypeAsWritten());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001589 if (D->getTypeAsWritten()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001590 Record.AddSourceLocation(D->getExternLoc());
1591 Record.AddSourceLocation(D->getTemplateKeywordLoc());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001592 }
1593
Richard Smith69c82bf2016-04-01 22:52:03 +00001594 Record.AddTemplateArgumentList(&D->getTemplateArgs());
1595 Record.AddSourceLocation(D->getPointOfInstantiation());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001596 Record.push_back(D->getSpecializationKind());
Richard Smith435e6472017-12-02 02:48:42 +00001597 Record.push_back(D->IsCompleteDefinition);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001598 Record.push_back(D->isCanonicalDecl());
1599
1600 if (D->isCanonicalDecl()) {
1601 // When reading, we'll add it to the folding set of the following template.
Richard Smith69c82bf2016-04-01 22:52:03 +00001602 Record.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001603 }
1604
1605 Code = serialization::DECL_VAR_TEMPLATE_SPECIALIZATION;
1606}
1607
1608void ASTDeclWriter::VisitVarTemplatePartialSpecializationDecl(
1609 VarTemplatePartialSpecializationDecl *D) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001610 Record.AddTemplateParameterList(D->getTemplateParameters());
1611 Record.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001612
Saar Razdf061c32019-12-23 08:37:35 +02001613 VisitVarTemplateSpecializationDecl(D);
1614
Larisse Voufo39a1e502013-08-06 01:03:05 +00001615 // These are read/set from/to the first declaration.
Craig Toppera13603a2014-05-22 05:54:18 +00001616 if (D->getPreviousDecl() == nullptr) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001617 Record.AddDeclRef(D->getInstantiatedFromMember());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001618 Record.push_back(D->isMemberSpecialization());
1619 }
1620
1621 Code = serialization::DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION;
1622}
1623
Fariborz Jahanian3a039e32011-08-27 20:50:59 +00001624void ASTDeclWriter::VisitClassScopeFunctionSpecializationDecl(
1625 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichet09af8c32011-08-17 01:06:54 +00001626 VisitDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001627 Record.AddDeclRef(D->getSpecialization());
Richard Smithf19a8b02019-05-02 00:49:14 +00001628 Record.push_back(D->hasExplicitTemplateArgs());
1629 if (D->hasExplicitTemplateArgs())
1630 Record.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten());
Francois Pichet09af8c32011-08-17 01:06:54 +00001631 Code = serialization::DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION;
1632}
1633
1634
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001635void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001636 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001637
Richard Smith509fc852015-02-27 23:05:10 +00001638 if (D->isFirstDecl())
1639 AddTemplateSpecializations(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001640 Code = serialization::DECL_FUNCTION_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001641}
1642
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001643void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Saar Razff1e0fc2020-01-15 02:48:42 +02001644 Record.push_back(D->hasTypeConstraint());
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001645 VisitTypeDecl(D);
1646
1647 Record.push_back(D->wasDeclaredWithTypename());
Saar Razff1e0fc2020-01-15 02:48:42 +02001648
1649 const TypeConstraint *TC = D->getTypeConstraint();
1650 Record.push_back(TC != nullptr);
1651 if (TC) {
1652 Record.AddNestedNameSpecifierLoc(TC->getNestedNameSpecifierLoc());
1653 Record.AddDeclarationNameInfo(TC->getConceptNameInfo());
1654 Record.AddDeclRef(TC->getNamedConcept());
1655 Record.push_back(TC->getTemplateArgsAsWritten() != nullptr);
1656 if (TC->getTemplateArgsAsWritten())
1657 Record.AddASTTemplateArgumentListInfo(TC->getTemplateArgsAsWritten());
1658 Record.AddStmt(TC->getImmediatelyDeclaredConstraint());
1659 Record.push_back(D->isExpandedParameterPack());
1660 if (D->isExpandedParameterPack())
1661 Record.push_back(D->getNumExpansionParameters());
1662 }
1663
Richard Smith8346e522015-06-10 01:47:58 +00001664 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1665 !D->defaultArgumentWasInherited();
1666 Record.push_back(OwnsDefaultArg);
1667 if (OwnsDefaultArg)
Richard Smith69c82bf2016-04-01 22:52:03 +00001668 Record.AddTypeSourceInfo(D->getDefaultArgumentInfo());
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001669
Sebastian Redl539c5062010-08-18 23:57:32 +00001670 Code = serialization::DECL_TEMPLATE_TYPE_PARM;
Chris Lattnerca025db2010-05-07 21:43:38 +00001671}
1672
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001673void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001674 // For an expanded parameter pack, record the number of expansion types here
Richard Smith1fde8ec2012-09-07 02:06:42 +00001675 // so that it's easier for deserialization to allocate the right amount of
1676 // memory.
Saar Razb481f022020-01-22 02:03:05 +02001677 Expr *TypeConstraint = D->getPlaceholderTypeConstraint();
1678 Record.push_back(!!TypeConstraint);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001679 if (D->isExpandedParameterPack())
1680 Record.push_back(D->getNumExpansionTypes());
Fangrui Song6907ce22018-07-30 19:24:48 +00001681
John McCallf4cd4f92011-02-09 01:13:10 +00001682 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001683 // TemplateParmPosition.
1684 Record.push_back(D->getDepth());
1685 Record.push_back(D->getPosition());
Saar Razb481f022020-01-22 02:03:05 +02001686 if (TypeConstraint)
1687 Record.AddStmt(TypeConstraint);
Fangrui Song6907ce22018-07-30 19:24:48 +00001688
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001689 if (D->isExpandedParameterPack()) {
1690 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001691 Record.AddTypeRef(D->getExpansionType(I));
1692 Record.AddTypeSourceInfo(D->getExpansionTypeSourceInfo(I));
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001693 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001694
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001695 Code = serialization::DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK;
1696 } else {
1697 // Rest of NonTypeTemplateParmDecl.
1698 Record.push_back(D->isParameterPack());
Richard Smith8346e522015-06-10 01:47:58 +00001699 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1700 !D->defaultArgumentWasInherited();
1701 Record.push_back(OwnsDefaultArg);
1702 if (OwnsDefaultArg)
Richard Smith290d8012016-04-06 17:06:00 +00001703 Record.AddStmt(D->getDefaultArgument());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001704 Code = serialization::DECL_NON_TYPE_TEMPLATE_PARM;
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001705 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001706}
1707
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001708void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Richard Smith1fde8ec2012-09-07 02:06:42 +00001709 // For an expanded parameter pack, record the number of expansion types here
1710 // so that it's easier for deserialization to allocate the right amount of
1711 // memory.
1712 if (D->isExpandedParameterPack())
1713 Record.push_back(D->getNumExpansionTemplateParameters());
1714
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001715 VisitTemplateDecl(D);
1716 // TemplateParmPosition.
1717 Record.push_back(D->getDepth());
1718 Record.push_back(D->getPosition());
Richard Smith1fde8ec2012-09-07 02:06:42 +00001719
1720 if (D->isExpandedParameterPack()) {
1721 for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
1722 I != N; ++I)
Richard Smith69c82bf2016-04-01 22:52:03 +00001723 Record.AddTemplateParameterList(D->getExpansionTemplateParameters(I));
Richard Smith1fde8ec2012-09-07 02:06:42 +00001724 Code = serialization::DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK;
1725 } else {
1726 // Rest of TemplateTemplateParmDecl.
Richard Smith1fde8ec2012-09-07 02:06:42 +00001727 Record.push_back(D->isParameterPack());
Richard Smith8346e522015-06-10 01:47:58 +00001728 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1729 !D->defaultArgumentWasInherited();
1730 Record.push_back(OwnsDefaultArg);
1731 if (OwnsDefaultArg)
Richard Smith69c82bf2016-04-01 22:52:03 +00001732 Record.AddTemplateArgumentLoc(D->getDefaultArgument());
Richard Smith1fde8ec2012-09-07 02:06:42 +00001733 Code = serialization::DECL_TEMPLATE_TEMPLATE_PARM;
1734 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001735}
1736
Richard Smith3f1b5d02011-05-05 21:57:07 +00001737void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1738 VisitRedeclarableTemplateDecl(D);
1739 Code = serialization::DECL_TYPE_ALIAS_TEMPLATE;
1740}
1741
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001742void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001743 VisitDecl(D);
Richard Smith290d8012016-04-06 17:06:00 +00001744 Record.AddStmt(D->getAssertExpr());
Richard Smithded9c2e2012-07-11 22:37:56 +00001745 Record.push_back(D->isFailed());
Richard Smith290d8012016-04-06 17:06:00 +00001746 Record.AddStmt(D->getMessage());
Richard Smith69c82bf2016-04-01 22:52:03 +00001747 Record.AddSourceLocation(D->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001748 Code = serialization::DECL_STATIC_ASSERT;
Chris Lattnerca025db2010-05-07 21:43:38 +00001749}
1750
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001751/// Emit the DeclContext part of a declaration context decl.
Richard Smithf1c23dc2016-04-13 02:12:03 +00001752void ASTDeclWriter::VisitDeclContext(DeclContext *DC) {
1753 Record.AddOffset(Writer.WriteDeclContextLexicalBlock(Context, DC));
1754 Record.AddOffset(Writer.WriteDeclContextVisibleBlock(Context, DC));
Chris Lattner7099dbc2009-04-27 06:16:06 +00001755}
1756
Richard Smithd8a83712015-08-22 01:47:18 +00001757const Decl *ASTWriter::getFirstLocalDecl(const Decl *D) {
Richard Smith3864be72015-09-11 02:22:03 +00001758 assert(IsLocalDecl(D) && "expected a local declaration");
Richard Smithd8a83712015-08-22 01:47:18 +00001759
1760 const Decl *Canon = D->getCanonicalDecl();
Richard Smith3864be72015-09-11 02:22:03 +00001761 if (IsLocalDecl(Canon))
Richard Smithd8a83712015-08-22 01:47:18 +00001762 return Canon;
1763
1764 const Decl *&CacheEntry = FirstLocalDeclCache[Canon];
1765 if (CacheEntry)
1766 return CacheEntry;
1767
1768 for (const Decl *Redecl = D; Redecl; Redecl = Redecl->getPreviousDecl())
Richard Smith3864be72015-09-11 02:22:03 +00001769 if (IsLocalDecl(Redecl))
Richard Smithd8a83712015-08-22 01:47:18 +00001770 D = Redecl;
1771 return CacheEntry = D;
Richard Smith5fc18a92015-07-12 23:43:21 +00001772}
1773
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001774template <typename T>
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001775void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +00001776 T *First = D->getFirstDecl();
Richard Smith5a4737c2015-02-06 02:42:59 +00001777 T *MostRecent = First->getMostRecentDecl();
Richard Smithd8a83712015-08-22 01:47:18 +00001778 T *DAsT = static_cast<T *>(D);
Richard Smith5a4737c2015-02-06 02:42:59 +00001779 if (MostRecent != First) {
Richard Smithd8a83712015-08-22 01:47:18 +00001780 assert(isRedeclarableDeclKind(DAsT->getKind()) &&
Douglas Gregorfe732d52013-01-21 16:16:40 +00001781 "Not considered redeclarable?");
Richard Smith5a4737c2015-02-06 02:42:59 +00001782
Richard Smith69c82bf2016-04-01 22:52:03 +00001783 Record.AddDeclRef(First);
Richard Smithfe620d22015-03-05 23:24:12 +00001784
Richard Smithd8a83712015-08-22 01:47:18 +00001785 // Write out a list of local redeclarations of this declaration if it's the
1786 // first local declaration in the chain.
1787 const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1788 if (DAsT == FirstLocal) {
Richard Smithd8a83712015-08-22 01:47:18 +00001789 // Emit a list of all imported first declarations so that we can be sure
1790 // that all redeclarations visible to this module are before D in the
1791 // redecl chain.
1792 unsigned I = Record.size();
1793 Record.push_back(0);
1794 if (Writer.Chain)
1795 AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1796 // This is the number of imported first declarations + 1.
1797 Record[I] = Record.size() - I;
Richard Smithd61d4ac2015-08-22 20:13:39 +00001798
1799 // Collect the set of local redeclarations of this declaration, from
1800 // newest to oldest.
Richard Smith69c82bf2016-04-01 22:52:03 +00001801 ASTWriter::RecordData LocalRedecls;
1802 ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls);
Richard Smithd61d4ac2015-08-22 20:13:39 +00001803 for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1804 Prev != FirstLocal; Prev = Prev->getPreviousDecl())
1805 if (!Prev->isFromASTFile())
Richard Smith69c82bf2016-04-01 22:52:03 +00001806 LocalRedeclWriter.AddDeclRef(Prev);
Richard Smithd61d4ac2015-08-22 20:13:39 +00001807
1808 // If we have any redecls, write them now as a separate record preceding
1809 // the declaration itself.
1810 if (LocalRedecls.empty())
1811 Record.push_back(0);
Richard Smithf1c23dc2016-04-13 02:12:03 +00001812 else
1813 Record.AddOffset(LocalRedeclWriter.Emit(LOCAL_REDECLARATIONS));
Richard Smithd8a83712015-08-22 01:47:18 +00001814 } else {
1815 Record.push_back(0);
Richard Smith69c82bf2016-04-01 22:52:03 +00001816 Record.AddDeclRef(FirstLocal);
Richard Smithfe620d22015-03-05 23:24:12 +00001817 }
Douglas Gregor358cd442012-01-15 16:58:34 +00001818
Fangrui Song6907ce22018-07-30 19:24:48 +00001819 // Make sure that we serialize both the previous and the most-recent
Douglas Gregor358cd442012-01-15 16:58:34 +00001820 // declarations, which (transitively) ensures that all declarations in the
1821 // chain get serialized.
Richard Smith5a4737c2015-02-06 02:42:59 +00001822 //
1823 // FIXME: This is not correct; when we reach an imported declaration we
1824 // won't emit its previous declaration.
Richard Smith5fc18a92015-07-12 23:43:21 +00001825 (void)Writer.GetDeclRef(D->getPreviousDecl());
Richard Smith5a4737c2015-02-06 02:42:59 +00001826 (void)Writer.GetDeclRef(MostRecent);
Douglas Gregor358cd442012-01-15 16:58:34 +00001827 } else {
1828 // We use the sentinel value 0 to indicate an only declaration.
1829 Record.push_back(0);
Douglas Gregor9f562c82011-12-19 15:27:36 +00001830 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001831}
Chris Lattner7099dbc2009-04-27 06:16:06 +00001832
Alexey Bataeva769e072013-03-22 06:34:35 +00001833void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
1834 Record.push_back(D->varlist_size());
1835 VisitDecl(D);
Aaron Ballman2205d2a2014-03-14 15:55:35 +00001836 for (auto *I : D->varlists())
Richard Smith290d8012016-04-06 17:06:00 +00001837 Record.AddStmt(I);
Alexey Bataeva769e072013-03-22 06:34:35 +00001838 Code = serialization::DECL_OMP_THREADPRIVATE;
1839}
1840
Alexey Bataev25ed0c02019-03-07 17:54:44 +00001841void ASTDeclWriter::VisitOMPAllocateDecl(OMPAllocateDecl *D) {
1842 Record.push_back(D->varlist_size());
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001843 Record.push_back(D->clauselist_size());
Alexey Bataev25ed0c02019-03-07 17:54:44 +00001844 VisitDecl(D);
1845 for (auto *I : D->varlists())
1846 Record.AddStmt(I);
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00001847 for (OMPClause *C : D->clauselists())
John McCall2ac702a2019-12-14 03:17:03 -05001848 Record.writeOMPClause(C);
Alexey Bataev25ed0c02019-03-07 17:54:44 +00001849 Code = serialization::DECL_OMP_ALLOCATE;
1850}
1851
Kelvin Li1408f912018-09-26 04:28:39 +00001852void ASTDeclWriter::VisitOMPRequiresDecl(OMPRequiresDecl *D) {
1853 Record.push_back(D->clauselist_size());
1854 VisitDecl(D);
Kelvin Li1408f912018-09-26 04:28:39 +00001855 for (OMPClause *C : D->clauselists())
John McCall2ac702a2019-12-14 03:17:03 -05001856 Record.writeOMPClause(C);
Kelvin Li1408f912018-09-26 04:28:39 +00001857 Code = serialization::DECL_OMP_REQUIRES;
1858}
1859
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00001860void ASTDeclWriter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
Alexey Bataevc5b1d322016-03-04 09:22:22 +00001861 VisitValueDecl(D);
Stephen Kellyf2ceec42018-08-09 21:08:08 +00001862 Record.AddSourceLocation(D->getBeginLoc());
Alexey Bataeve6aa4692018-09-13 16:54:05 +00001863 Record.AddStmt(D->getCombinerIn());
1864 Record.AddStmt(D->getCombinerOut());
Richard Smith290d8012016-04-06 17:06:00 +00001865 Record.AddStmt(D->getCombiner());
Alexey Bataeve6aa4692018-09-13 16:54:05 +00001866 Record.AddStmt(D->getInitOrig());
1867 Record.AddStmt(D->getInitPriv());
Richard Smith290d8012016-04-06 17:06:00 +00001868 Record.AddStmt(D->getInitializer());
Alexey Bataev070f43a2017-09-06 14:49:58 +00001869 Record.push_back(D->getInitializerKind());
Richard Smith69c82bf2016-04-01 22:52:03 +00001870 Record.AddDeclRef(D->getPrevDeclInScope());
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00001871 Code = serialization::DECL_OMP_DECLARE_REDUCTION;
1872}
1873
Michael Kruse251e1482019-02-01 20:25:04 +00001874void ASTDeclWriter::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) {
1875 Record.push_back(D->clauselist_size());
1876 VisitValueDecl(D);
1877 Record.AddSourceLocation(D->getBeginLoc());
1878 Record.AddStmt(D->getMapperVarRef());
1879 Record.AddDeclarationName(D->getVarName());
1880 Record.AddDeclRef(D->getPrevDeclInScope());
Michael Kruse251e1482019-02-01 20:25:04 +00001881 for (OMPClause *C : D->clauselists())
John McCall2ac702a2019-12-14 03:17:03 -05001882 Record.writeOMPClause(C);
Michael Kruse251e1482019-02-01 20:25:04 +00001883 Code = serialization::DECL_OMP_DECLARE_MAPPER;
1884}
1885
Alexey Bataev4244be22016-02-11 05:35:55 +00001886void ASTDeclWriter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
Alexey Bataev90c228f2016-02-08 09:29:13 +00001887 VisitVarDecl(D);
Alexey Bataev4244be22016-02-11 05:35:55 +00001888 Code = serialization::DECL_OMP_CAPTUREDEXPR;
Alexey Bataev90c228f2016-02-08 09:29:13 +00001889}
1890
Chris Lattner7099dbc2009-04-27 06:16:06 +00001891//===----------------------------------------------------------------------===//
Sebastian Redl55c0ad52010-08-18 23:56:21 +00001892// ASTWriter Implementation
Chris Lattner7099dbc2009-04-27 06:16:06 +00001893//===----------------------------------------------------------------------===//
1894
Richard Smith01b2cb42014-07-26 06:37:51 +00001895void ASTWriter::WriteDeclAbbrevs() {
Chris Lattner258172e2009-04-27 07:35:58 +00001896 using namespace llvm;
Chris Lattner258172e2009-04-27 07:35:58 +00001897
David Blaikieb44f0bf2017-01-04 22:36:43 +00001898 std::shared_ptr<BitCodeAbbrev> Abv;
Douglas Gregor03412ba2011-06-03 02:27:19 +00001899
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001900 // Abbreviation for DECL_FIELD
David Blaikieb44f0bf2017-01-04 22:36:43 +00001901 Abv = std::make_shared<BitCodeAbbrev>();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001902 Abv->Add(BitCodeAbbrevOp(serialization::DECL_FIELD));
1903 // Decl
1904 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001905 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001906 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001907 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1908 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1909 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1910 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001911 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001912 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001913 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001914 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001915 // NamedDecl
1916 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1917 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001918 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001919 // ValueDecl
1920 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1921 // DeclaratorDecl
1922 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1923 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Richard Smithc23d7342018-06-29 20:46:25 +00001924 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001925 // FieldDecl
1926 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
Richard Smith6b8e3c02017-08-28 00:28:14 +00001927 Abv->Add(BitCodeAbbrevOp(0)); // InitStyle
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001928 // Type Source Info
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001929 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1930 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
David Blaikieb44f0bf2017-01-04 22:36:43 +00001931 DeclFieldAbbrev = Stream.EmitAbbrev(std::move(Abv));
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001932
1933 // Abbreviation for DECL_OBJC_IVAR
David Blaikieb44f0bf2017-01-04 22:36:43 +00001934 Abv = std::make_shared<BitCodeAbbrev>();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001935 Abv->Add(BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR));
1936 // Decl
1937 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001938 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001939 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001940 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1941 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1942 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1943 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001944 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001945 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001946 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001947 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001948 // NamedDecl
1949 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1950 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001951 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001952 // ValueDecl
1953 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1954 // DeclaratorDecl
1955 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1956 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Richard Smithc23d7342018-06-29 20:46:25 +00001957 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001958 // FieldDecl
1959 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
Richard Smith6b8e3c02017-08-28 00:28:14 +00001960 Abv->Add(BitCodeAbbrevOp(0)); // InitStyle
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001961 // ObjC Ivar
1962 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl
1963 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize
1964 // Type Source Info
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001965 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1966 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
David Blaikieb44f0bf2017-01-04 22:36:43 +00001967 DeclObjCIvarAbbrev = Stream.EmitAbbrev(std::move(Abv));
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001968
1969 // Abbreviation for DECL_ENUM
David Blaikieb44f0bf2017-01-04 22:36:43 +00001970 Abv = std::make_shared<BitCodeAbbrev>();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001971 Abv->Add(BitCodeAbbrevOp(serialization::DECL_ENUM));
Douglas Gregor3e300102011-10-26 17:53:41 +00001972 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001973 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Chris Lattner258172e2009-04-27 07:35:58 +00001974 // Decl
1975 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001976 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001977 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Chris Lattner258172e2009-04-27 07:35:58 +00001978 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1979 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
Douglas Gregorc9c02ed2009-06-19 23:52:42 +00001980 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +00001981 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001982 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Chris Lattner258172e2009-04-27 07:35:58 +00001983 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001984 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001985 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Douglas Gregor03412ba2011-06-03 02:27:19 +00001986 // NamedDecl
1987 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1988 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001989 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001990 // TypeDecl
1991 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1992 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001993 // TagDecl
1994 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
1995 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
John McCallf937c022011-10-07 06:10:15 +00001996 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001997 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +00001998 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
David Blaikiea8d23ce2013-07-14 01:07:41 +00001999 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002000 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Argyrios Kyrtzidisd798c052016-07-15 18:11:33 +00002001 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Richard Smith70d58502014-08-30 00:04:23 +00002002 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002003 // EnumDecl
2004 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddTypeRef
2005 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IntegerType
2006 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getPromotionType
2007 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumPositiveBits
2008 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumNegativeBits
2009 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScoped
2010 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScopedUsingClassTag
2011 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isFixed
Richard Trieuab4d7302018-07-25 22:52:05 +00002012 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));// ODRHash
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002013 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedMembEnum
2014 // DC
2015 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
2016 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
David Blaikieb44f0bf2017-01-04 22:36:43 +00002017 DeclEnumAbbrev = Stream.EmitAbbrev(std::move(Abv));
Mike Stump11289f42009-09-09 15:08:12 +00002018
Douglas Gregor03412ba2011-06-03 02:27:19 +00002019 // Abbreviation for DECL_RECORD
David Blaikieb44f0bf2017-01-04 22:36:43 +00002020 Abv = std::make_shared<BitCodeAbbrev>();
Douglas Gregor03412ba2011-06-03 02:27:19 +00002021 Abv->Add(BitCodeAbbrevOp(serialization::DECL_RECORD));
Douglas Gregor3e300102011-10-26 17:53:41 +00002022 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00002023 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Douglas Gregor03412ba2011-06-03 02:27:19 +00002024 // Decl
2025 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00002026 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00002027 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Douglas Gregor03412ba2011-06-03 02:27:19 +00002028 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
2029 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
2030 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
2031 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00002032 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Douglas Gregor03412ba2011-06-03 02:27:19 +00002033 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00002034 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00002035 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Douglas Gregor03412ba2011-06-03 02:27:19 +00002036 // NamedDecl
2037 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2038 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00002039 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Douglas Gregor03412ba2011-06-03 02:27:19 +00002040 // TypeDecl
2041 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2042 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
Douglas Gregor03412ba2011-06-03 02:27:19 +00002043 // TagDecl
2044 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
2045 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
John McCallf937c022011-10-07 06:10:15 +00002046 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
Douglas Gregor03412ba2011-06-03 02:27:19 +00002047 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +00002048 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
David Blaikiea8d23ce2013-07-14 01:07:41 +00002049 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
Douglas Gregor03412ba2011-06-03 02:27:19 +00002050 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Argyrios Kyrtzidisd798c052016-07-15 18:11:33 +00002051 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Richard Smith70d58502014-08-30 00:04:23 +00002052 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
Douglas Gregor03412ba2011-06-03 02:27:19 +00002053 // RecordDecl
2054 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // FlexibleArrayMember
2055 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // AnonymousStructUnion
2056 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasObjectMember
Fariborz Jahanian78652202013-01-25 23:57:05 +00002057 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasVolatileMember
Akira Hatanaka34fb2642018-03-13 18:58:25 +00002058
2059 // isNonTrivialToPrimitiveDefaultInitialize
2060 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
2061 // isNonTrivialToPrimitiveCopy
2062 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
2063 // isNonTrivialToPrimitiveDestroy
2064 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
Akira Hatanaka09051062019-09-07 00:34:43 +00002065 // hasNonTrivialToPrimitiveDefaultInitializeCUnion
2066 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
2067 // hasNonTrivialToPrimitiveDestructCUnion
2068 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
2069 // hasNonTrivialToPrimitiveCopyCUnion
2070 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
Akira Hatanakafcbe17c2018-03-28 21:13:14 +00002071 // isParamDestroyedInCallee
2072 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
Akira Hatanakae6313ac2018-04-09 22:48:22 +00002073 // getArgPassingRestrictions
2074 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2));
Akira Hatanaka34fb2642018-03-13 18:58:25 +00002075
Douglas Gregor03412ba2011-06-03 02:27:19 +00002076 // DC
2077 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
2078 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
David Blaikieb44f0bf2017-01-04 22:36:43 +00002079 DeclRecordAbbrev = Stream.EmitAbbrev(std::move(Abv));
Douglas Gregor03412ba2011-06-03 02:27:19 +00002080
2081 // Abbreviation for DECL_PARM_VAR
David Blaikieb44f0bf2017-01-04 22:36:43 +00002082 Abv = std::make_shared<BitCodeAbbrev>();
Douglas Gregor03412ba2011-06-03 02:27:19 +00002083 Abv->Add(BitCodeAbbrevOp(serialization::DECL_PARM_VAR));
Douglas Gregor3e300102011-10-26 17:53:41 +00002084 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00002085 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Douglas Gregor03412ba2011-06-03 02:27:19 +00002086 // Decl
2087 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00002088 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00002089 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Douglas Gregor03412ba2011-06-03 02:27:19 +00002090 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
2091 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
2092 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
2093 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00002094 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Douglas Gregor03412ba2011-06-03 02:27:19 +00002095 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00002096 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00002097 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Chris Lattner258172e2009-04-27 07:35:58 +00002098 // NamedDecl
2099 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2100 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00002101 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Chris Lattner258172e2009-04-27 07:35:58 +00002102 // ValueDecl
2103 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +00002104 // DeclaratorDecl
Abramo Bagnaradff19302011-03-08 08:55:46 +00002105 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00002106 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Richard Smithc23d7342018-06-29 20:46:25 +00002107 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
Chris Lattner258172e2009-04-27 07:35:58 +00002108 // VarDecl
Vassil Vassilevd1a88132016-10-06 13:04:54 +00002109 Abv->Add(BitCodeAbbrevOp(0)); // SClass
2110 Abv->Add(BitCodeAbbrevOp(0)); // TSCSpec
2111 Abv->Add(BitCodeAbbrevOp(0)); // InitStyle
Erik Pilkington1e368822019-01-04 18:33:06 +00002112 Abv->Add(BitCodeAbbrevOp(0)); // ARCPseudoStrong
Richard Smith88581592013-02-12 05:48:23 +00002113 Abv->Add(BitCodeAbbrevOp(0)); // Linkage
Chris Lattner258172e2009-04-27 07:35:58 +00002114 Abv->Add(BitCodeAbbrevOp(0)); // HasInit
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00002115 Abv->Add(BitCodeAbbrevOp(0)); // HasMemberSpecializationInfo
Chris Lattner258172e2009-04-27 07:35:58 +00002116 // ParmVarDecl
John McCall82490832011-05-02 00:30:12 +00002117 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsObjCMethodParameter
John McCall8fb0d9d2011-05-01 22:35:37 +00002118 Abv->Add(BitCodeAbbrevOp(0)); // ScopeDepth
2119 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex
Chris Lattner258172e2009-04-27 07:35:58 +00002120 Abv->Add(BitCodeAbbrevOp(0)); // ObjCDeclQualifier
John McCall6a014d52011-03-09 04:22:44 +00002121 Abv->Add(BitCodeAbbrevOp(0)); // KNRPromoted
John McCallf3cd6652010-03-12 18:31:32 +00002122 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedDefaultArg
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +00002123 Abv->Add(BitCodeAbbrevOp(0)); // HasUninstantiatedDefaultArg
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002124 // Type Source Info
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002125 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2126 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
David Blaikieb44f0bf2017-01-04 22:36:43 +00002127 DeclParmVarAbbrev = Stream.EmitAbbrev(std::move(Abv));
Sebastian Redl66c5eef2010-07-27 00:17:23 +00002128
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00002129 // Abbreviation for DECL_TYPEDEF
David Blaikieb44f0bf2017-01-04 22:36:43 +00002130 Abv = std::make_shared<BitCodeAbbrev>();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002131 Abv->Add(BitCodeAbbrevOp(serialization::DECL_TYPEDEF));
Douglas Gregor05f10352011-12-17 23:38:30 +00002132 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00002133 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002134 // Decl
2135 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00002136 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00002137 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002138 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
2139 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
Richard Smith01b2cb42014-07-26 06:37:51 +00002140 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isUsed
2141 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00002142 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Richard Smith01b2cb42014-07-26 06:37:51 +00002143 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00002144 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00002145 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002146 // NamedDecl
2147 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2148 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00002149 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002150 // TypeDecl
2151 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2152 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
2153 // TypedefDecl
2154 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2155 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
David Blaikieb44f0bf2017-01-04 22:36:43 +00002156 DeclTypedefAbbrev = Stream.EmitAbbrev(std::move(Abv));
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002157
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00002158 // Abbreviation for DECL_VAR
David Blaikieb44f0bf2017-01-04 22:36:43 +00002159 Abv = std::make_shared<BitCodeAbbrev>();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002160 Abv->Add(BitCodeAbbrevOp(serialization::DECL_VAR));
Douglas Gregor3e300102011-10-26 17:53:41 +00002161 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00002162 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002163 // Decl
2164 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00002165 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00002166 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002167 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
2168 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
2169 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
2170 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00002171 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002172 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00002173 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00002174 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002175 // NamedDecl
2176 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2177 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00002178 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002179 // ValueDecl
2180 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2181 // DeclaratorDecl
2182 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
2183 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Richard Smithc23d7342018-06-29 20:46:25 +00002184 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002185 // VarDecl
Vassil Vassilevd1a88132016-10-06 13:04:54 +00002186 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // SClass
2187 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // TSCSpec
2188 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // InitStyle
Erik Pilkington1e368822019-01-04 18:33:06 +00002189 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong
Richard Smithedbc6e92016-10-14 21:41:24 +00002190 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsThisDeclarationADemotedDefinition
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002191 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isExceptionVariable
Taiju Tsuiki3be68e12018-06-19 05:35:30 +00002192 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isNRVOVariable
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002193 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCXXForRangeDecl
George Karpenkovec38cf72018-03-29 00:56:24 +00002194 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isObjCForDecl
Richard Smith62f19e72016-06-25 00:15:56 +00002195 Abv->Add(BitCodeAbbrevOp(0)); // isInline
2196 Abv->Add(BitCodeAbbrevOp(0)); // isInlineSpecified
Douglas Gregor12cda632012-09-20 23:43:29 +00002197 Abv->Add(BitCodeAbbrevOp(0)); // isConstexpr
Richard Smithbb13c9a2013-09-28 04:02:39 +00002198 Abv->Add(BitCodeAbbrevOp(0)); // isInitCapture
Richard Smith1c34fb72013-08-13 18:18:50 +00002199 Abv->Add(BitCodeAbbrevOp(0)); // isPrevDeclInSameScope
Alexey Bataev56223232017-06-09 13:40:18 +00002200 Abv->Add(BitCodeAbbrevOp(0)); // ImplicitParamKind
Akira Hatanaka8e57b072018-10-01 21:51:28 +00002201 Abv->Add(BitCodeAbbrevOp(0)); // EscapingByref
Rafael Espindola50df3a02013-05-25 17:16:20 +00002202 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
Richard Smith2b4fa532019-09-29 05:08:46 +00002203 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // IsInitICE (local)
Vassil Vassilevd1a88132016-10-06 13:04:54 +00002204 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // VarKind (local enum)
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002205 // Type Source Info
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002206 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2207 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
David Blaikieb44f0bf2017-01-04 22:36:43 +00002208 DeclVarAbbrev = Stream.EmitAbbrev(std::move(Abv));
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002209
Richard Smith01b2cb42014-07-26 06:37:51 +00002210 // Abbreviation for DECL_CXX_METHOD
David Blaikieb44f0bf2017-01-04 22:36:43 +00002211 Abv = std::make_shared<BitCodeAbbrev>();
Richard Smith01b2cb42014-07-26 06:37:51 +00002212 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CXX_METHOD));
2213 // RedeclarableDecl
2214 Abv->Add(BitCodeAbbrevOp(0)); // CanonicalDecl
2215 // Decl
2216 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00002217 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Richard Smith01b2cb42014-07-26 06:37:51 +00002218 Abv->Add(BitCodeAbbrevOp(0)); // Invalid
2219 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
2220 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Implicit
2221 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Used
2222 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Referenced
2223 Abv->Add(BitCodeAbbrevOp(0)); // InObjCContainer
2224 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Access
2225 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ModulePrivate
2226 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2227 // NamedDecl
2228 Abv->Add(BitCodeAbbrevOp(DeclarationName::Identifier)); // NameKind
2229 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Identifier
Richard Smith2b560572015-02-07 03:11:11 +00002230 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Richard Smith01b2cb42014-07-26 06:37:51 +00002231 // ValueDecl
2232 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2233 // DeclaratorDecl
2234 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerLocStart
2235 Abv->Add(BitCodeAbbrevOp(0)); // HasExtInfo
Richard Smithc23d7342018-06-29 20:46:25 +00002236 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
Richard Smith01b2cb42014-07-26 06:37:51 +00002237 // FunctionDecl
2238 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS
2239 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // StorageClass
2240 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Inline
2241 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InlineSpecified
2242 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // VirtualAsWritten
2243 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Pure
2244 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedProto
2245 Abv->Add(BitCodeAbbrevOp(1)); // HasWrittenProto
Richard Smith72625c22015-02-06 23:20:21 +00002246 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Deleted
Richard Smith01b2cb42014-07-26 06:37:51 +00002247 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Trivial
Akira Hatanaka02914dc2018-02-05 20:23:22 +00002248 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // TrivialForCall
Richard Smith01b2cb42014-07-26 06:37:51 +00002249 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Defaulted
2250 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ExplicitlyDefaulted
2251 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ImplicitReturnZero
2252 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Constexpr
Reid Kleckner0d157382017-01-10 21:27:03 +00002253 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // UsesSEHTry
Richard Smith01b2cb42014-07-26 06:37:51 +00002254 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // SkippedBody
Erich Keane281d20b2018-01-08 21:34:17 +00002255 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // MultiVersion
Richard Smith01b2cb42014-07-26 06:37:51 +00002256 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // LateParsed
2257 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
2258 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LocEnd
Richard Trieue6caa262017-12-23 00:41:01 +00002259 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // ODRHash
Richard Smith01b2cb42014-07-26 06:37:51 +00002260 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // TemplateKind
2261 // This Array slurps the rest of the record. Fortunately we want to encode
2262 // (nearly) all the remaining (variable number of) fields in the same way.
2263 //
2264 // This is the function template information if any, then
2265 // NumParams and Params[] from FunctionDecl, and
2266 // NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl.
2267 //
2268 // Add an AbbrevOp for 'size then elements' and use it here.
2269 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2270 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
David Blaikieb44f0bf2017-01-04 22:36:43 +00002271 DeclCXXMethodAbbrev = Stream.EmitAbbrev(std::move(Abv));
Richard Smith01b2cb42014-07-26 06:37:51 +00002272
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00002273 // Abbreviation for EXPR_DECL_REF
David Blaikieb44f0bf2017-01-04 22:36:43 +00002274 Abv = std::make_shared<BitCodeAbbrev>();
Douglas Gregor03412ba2011-06-03 02:27:19 +00002275 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_DECL_REF));
2276 //Stmt
Roman Lebedevb5700602019-03-20 16:32:36 +00002277 // Expr
Douglas Gregor03412ba2011-06-03 02:27:19 +00002278 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002279 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2280 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2281 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002282 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2283 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2284 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2285 //DeclRefExpr
2286 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HasQualifier
2287 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //GetDeclFound
2288 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ExplicitTemplateArgs
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002289 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HadMultipleCandidates
Richard Smith715f7a12019-06-11 17:50:32 +00002290 Abv->Add(BitCodeAbbrevOp(0)); // RefersToEnclosingVariableOrCapture
2291 Abv->Add(BitCodeAbbrevOp(0)); // NonOdrUseReason
Douglas Gregor03412ba2011-06-03 02:27:19 +00002292 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef
2293 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
David Blaikieb44f0bf2017-01-04 22:36:43 +00002294 DeclRefExprAbbrev = Stream.EmitAbbrev(std::move(Abv));
Douglas Gregor03412ba2011-06-03 02:27:19 +00002295
2296 // Abbreviation for EXPR_INTEGER_LITERAL
David Blaikieb44f0bf2017-01-04 22:36:43 +00002297 Abv = std::make_shared<BitCodeAbbrev>();
Douglas Gregor03412ba2011-06-03 02:27:19 +00002298 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL));
2299 //Stmt
Roman Lebedevb5700602019-03-20 16:32:36 +00002300 // Expr
Douglas Gregor03412ba2011-06-03 02:27:19 +00002301 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002302 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2303 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2304 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002305 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2306 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2307 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2308 //Integer Literal
2309 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2310 Abv->Add(BitCodeAbbrevOp(32)); // Bit Width
2311 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value
David Blaikieb44f0bf2017-01-04 22:36:43 +00002312 IntegerLiteralAbbrev = Stream.EmitAbbrev(std::move(Abv));
Douglas Gregor03412ba2011-06-03 02:27:19 +00002313
2314 // Abbreviation for EXPR_CHARACTER_LITERAL
David Blaikieb44f0bf2017-01-04 22:36:43 +00002315 Abv = std::make_shared<BitCodeAbbrev>();
Douglas Gregor03412ba2011-06-03 02:27:19 +00002316 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL));
2317 //Stmt
Roman Lebedevb5700602019-03-20 16:32:36 +00002318 // Expr
Douglas Gregor03412ba2011-06-03 02:27:19 +00002319 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002320 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2321 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2322 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002323 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2324 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2325 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
Jonathan D. Turnerd09655f2011-06-03 21:46:44 +00002326 //Character Literal
Douglas Gregor03412ba2011-06-03 02:27:19 +00002327 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue
2328 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
Aaron Ballman9a17c852016-01-07 20:59:26 +00002329 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // getKind
David Blaikieb44f0bf2017-01-04 22:36:43 +00002330 CharacterLiteralAbbrev = Stream.EmitAbbrev(std::move(Abv));
Douglas Gregor03412ba2011-06-03 02:27:19 +00002331
Richard Smitha27c26e2014-07-27 04:19:32 +00002332 // Abbreviation for EXPR_IMPLICIT_CAST
David Blaikieb44f0bf2017-01-04 22:36:43 +00002333 Abv = std::make_shared<BitCodeAbbrev>();
Richard Smitha27c26e2014-07-27 04:19:32 +00002334 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_IMPLICIT_CAST));
2335 // Stmt
2336 // Expr
2337 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2338 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2339 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2340 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
2341 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2342 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2343 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2344 // CastExpr
2345 Abv->Add(BitCodeAbbrevOp(0)); // PathSize
2346 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 6)); // CastKind
Roman Lebedevd55661d2018-07-24 08:16:50 +00002347 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // PartOfExplicitCast
Richard Smitha27c26e2014-07-27 04:19:32 +00002348 // ImplicitCastExpr
David Blaikieb44f0bf2017-01-04 22:36:43 +00002349 ExprImplicitCastAbbrev = Stream.EmitAbbrev(std::move(Abv));
Richard Smitha27c26e2014-07-27 04:19:32 +00002350
David Blaikieb44f0bf2017-01-04 22:36:43 +00002351 Abv = std::make_shared<BitCodeAbbrev>();
Sebastian Redl539c5062010-08-18 23:57:32 +00002352 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL));
Sebastian Redl66c5eef2010-07-27 00:17:23 +00002353 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
David Blaikieb44f0bf2017-01-04 22:36:43 +00002354 DeclContextLexicalAbbrev = Stream.EmitAbbrev(std::move(Abv));
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002355
David Blaikieb44f0bf2017-01-04 22:36:43 +00002356 Abv = std::make_shared<BitCodeAbbrev>();
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002357 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE));
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002358 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
David Blaikieb44f0bf2017-01-04 22:36:43 +00002359 DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(std::move(Abv));
Chris Lattner258172e2009-04-27 07:35:58 +00002360}
2361
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002362/// isRequiredDecl - Check if this is a "required" Decl, which must be seen by
2363/// consumers of the AST.
2364///
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002365/// Such decls will always be deserialized from the AST file, so we would like
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002366/// this to be as restrictive as possible. Currently the predicate is driven by
2367/// code generation requirements, if other clients have a different notion of
2368/// what is "required" then we may have to consider an alternate scheme where
2369/// clients can iterate over the top-level decls and get information on them,
2370/// without necessary deserializing them. We could explicitly require such
2371/// clients to use a separate API call to "realize" the decl. This should be
2372/// relatively painless since they would presumably only do it for top-level
2373/// decls.
Richard Smithc52efa72015-08-19 02:30:28 +00002374static bool isRequiredDecl(const Decl *D, ASTContext &Context,
David Blaikiee6b7c282017-04-11 20:46:34 +00002375 bool WritingModule) {
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00002376 // An ObjCMethodDecl is never considered as "required" because its
2377 // implementation container always is.
2378
Dmitry Polukhin0b0da292016-04-06 11:38:59 +00002379 // File scoped assembly or obj-c or OMP declare target implementation must be
2380 // seen.
Alexey Bataevd01b7492018-08-15 19:45:12 +00002381 if (isa<FileScopeAsmDecl>(D) || isa<ObjCImplDecl>(D))
Richard Smithc52efa72015-08-19 02:30:28 +00002382 return true;
2383
Richard Smith520a37f2019-02-05 23:37:13 +00002384 if (WritingModule && isPartOfPerModuleInitializer(D)) {
Richard Smithdc1f0422016-07-20 19:10:16 +00002385 // These declarations are part of the module initializer, and are emitted
2386 // if and when the module is imported, rather than being emitted eagerly.
2387 return false;
2388 }
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002389
David Blaikiee6b7c282017-04-11 20:46:34 +00002390 return Context.DeclMustBeEmitted(D);
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002391}
2392
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002393void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) {
Jordan Rose1e879d82018-03-23 00:07:18 +00002394 PrettyDeclStackTraceEntry CrashInfo(Context, D, SourceLocation(),
2395 "serializing");
2396
Douglas Gregorb3163e52012-01-05 22:33:30 +00002397 // Determine the ID for this declaration.
2398 serialization::DeclID ID;
Douglas Gregor7dd37e52015-11-03 01:20:54 +00002399 assert(!D->isFromASTFile() && "should not be emitting imported decl");
2400 serialization::DeclID &IDR = DeclIDs[D];
2401 if (IDR == 0)
2402 IDR = NextDeclID++;
Fangrui Song6907ce22018-07-30 19:24:48 +00002403
Douglas Gregor7dd37e52015-11-03 01:20:54 +00002404 ID = IDR;
Argyrios Kyrtzidisbf6c3392012-03-22 16:08:04 +00002405
Richard Smith34da7512016-03-27 05:52:25 +00002406 assert(ID >= FirstDeclID && "invalid decl ID");
Fangrui Song6907ce22018-07-30 19:24:48 +00002407
Richard Smith69c82bf2016-04-01 22:52:03 +00002408 RecordData Record;
2409 ASTDeclWriter W(*this, Context, Record);
2410
Richard Smithd61d4ac2015-08-22 20:13:39 +00002411 // Build a record for this declaration
Richard Smithd61d4ac2015-08-22 20:13:39 +00002412 W.Visit(D);
Richard Smithd61d4ac2015-08-22 20:13:39 +00002413
Richard Smith69c82bf2016-04-01 22:52:03 +00002414 // Emit this declaration to the bitstream.
2415 uint64_t Offset = W.Emit(D);
Douglas Gregor12bfa382009-10-17 00:13:19 +00002416
Richard Smith34da7512016-03-27 05:52:25 +00002417 // Record the offset for this declaration
2418 SourceLocation Loc = D->getLocation();
Richard Smith69c82bf2016-04-01 22:52:03 +00002419 unsigned Index = ID - FirstDeclID;
Richard Smith34da7512016-03-27 05:52:25 +00002420 if (DeclOffsets.size() == Index)
Richard Smith69c82bf2016-04-01 22:52:03 +00002421 DeclOffsets.push_back(DeclOffset(Loc, Offset));
Richard Smith34da7512016-03-27 05:52:25 +00002422 else if (DeclOffsets.size() < Index) {
Richard Smith69c82bf2016-04-01 22:52:03 +00002423 // FIXME: Can/should this happen?
Richard Smith34da7512016-03-27 05:52:25 +00002424 DeclOffsets.resize(Index+1);
2425 DeclOffsets[Index].setLocation(Loc);
Richard Smith69c82bf2016-04-01 22:52:03 +00002426 DeclOffsets[Index].BitOffset = Offset;
2427 } else {
2428 llvm_unreachable("declarations should be emitted in ID order");
Douglas Gregor12bfa382009-10-17 00:13:19 +00002429 }
2430
Richard Smith34da7512016-03-27 05:52:25 +00002431 SourceManager &SM = Context.getSourceManager();
2432 if (Loc.isValid() && SM.isLocalSourceLocation(Loc))
2433 associateDeclWithFile(D, ID);
2434
Ben Langmuir332aafe2014-01-31 01:06:56 +00002435 // Note declarations that should be deserialized eagerly so that we can add
2436 // them to a record in the AST file later.
David Blaikiee6b7c282017-04-11 20:46:34 +00002437 if (isRequiredDecl(D, Context, WritingModule))
Ben Langmuir332aafe2014-01-31 01:06:56 +00002438 EagerlyDeserializedDecls.push_back(ID);
Chris Lattner7099dbc2009-04-27 06:16:06 +00002439}
Richard Smithd28ac5b2014-03-22 23:33:22 +00002440
Richard Smith290d8012016-04-06 17:06:00 +00002441void ASTRecordWriter::AddFunctionDefinition(const FunctionDecl *FD) {
2442 // Switch case IDs are per function body.
2443 Writer->ClearSwitchCaseIDs();
Richard Smithd28ac5b2014-03-22 23:33:22 +00002444
Richard Smith290d8012016-04-06 17:06:00 +00002445 assert(FD->doesThisDeclarationHaveABody());
Richard Smithb51cf112017-07-06 00:30:00 +00002446 bool ModulesCodegen = false;
Hans Wennborg7ea9a6e2020-02-27 14:33:43 +01002447 if (Writer->WritingModule && !FD->isDependentContext()) {
David Blaikie08267292017-11-02 21:55:40 +00002448 Optional<GVALinkage> Linkage;
Hans Wennborg7ea9a6e2020-02-27 14:33:43 +01002449 if (Writer->WritingModule->Kind == Module::ModuleInterfaceUnit) {
David Blaikie08267292017-11-02 21:55:40 +00002450 // When building a C++ Modules TS module interface unit, a strong
2451 // definition in the module interface is provided by the compilation of
2452 // that module interface unit, not by its users. (Inline functions are
2453 // still emitted in module users.)
2454 Linkage = Writer->Context->GetGVALinkageForFunction(FD);
2455 ModulesCodegen = *Linkage == GVA_StrongExternal;
2456 }
2457 if (Writer->Context->getLangOpts().ModulesCodegen) {
2458 // Under -fmodules-codegen, codegen is performed for all non-internal,
Luboš Luňák729530f2019-11-03 20:47:40 +01002459 // non-always_inline functions, unless they are available elsewhere.
David Blaikie1524e672017-11-02 22:28:50 +00002460 if (!FD->hasAttr<AlwaysInlineAttr>()) {
2461 if (!Linkage)
2462 Linkage = Writer->Context->GetGVALinkageForFunction(FD);
Luboš Luňák729530f2019-11-03 20:47:40 +01002463 ModulesCodegen =
2464 *Linkage != GVA_Internal && *Linkage != GVA_AvailableExternally;
David Blaikie1524e672017-11-02 22:28:50 +00002465 }
David Blaikie08267292017-11-02 21:55:40 +00002466 }
Richard Smithb51cf112017-07-06 00:30:00 +00002467 }
David Blaikief63556d2017-04-12 20:58:33 +00002468 Record->push_back(ModulesCodegen);
2469 if (ModulesCodegen)
David Blaikiee6b7c282017-04-11 20:46:34 +00002470 Writer->ModularCodegenDecls.push_back(Writer->GetDeclRef(FD));
Richard Smith290d8012016-04-06 17:06:00 +00002471 if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
2472 Record->push_back(CD->getNumCtorInitializers());
2473 if (CD->getNumCtorInitializers())
Richard Smithaa165cf2016-04-13 21:57:08 +00002474 AddCXXCtorInitializers(
Richard Smith290d8012016-04-06 17:06:00 +00002475 llvm::makeArrayRef(CD->init_begin(), CD->init_end()));
2476 }
2477 AddStmt(FD->getBody());
Richard Smithd28ac5b2014-03-22 23:33:22 +00002478}