blob: cfcd81b3e1e48b4159bb3cfe49ac122507047c86 [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"
Chris Lattnerca025db2010-05-07 21:43:38 +000014#include "clang/AST/DeclCXX.h"
Argyrios Kyrtzidis3317d982010-10-20 16:22:56 +000015#include "clang/AST/DeclContextInternals.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000016#include "clang/AST/DeclTemplate.h"
17#include "clang/AST/DeclVisitor.h"
18#include "clang/AST/Expr.h"
Kelvin Li1408f912018-09-26 04:28:39 +000019#include "clang/AST/OpenMPClause.h"
Jordan Rose1e879d82018-03-23 00:07:18 +000020#include "clang/AST/PrettyDeclStackTrace.h"
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +000021#include "clang/Basic/SourceManager.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000022#include "clang/Serialization/ASTReader.h"
Mehdi Amini9670f842016-07-18 19:02:11 +000023#include "clang/Serialization/ASTWriter.h"
Chris Lattner7099dbc2009-04-27 06:16:06 +000024#include "llvm/Bitcode/BitstreamWriter.h"
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +000025#include "llvm/Support/ErrorHandling.h"
Chris Lattner7099dbc2009-04-27 06:16:06 +000026using namespace clang;
Sebastian Redlfa1f3702011-04-24 16:28:13 +000027using namespace serialization;
Chris Lattner7099dbc2009-04-27 06:16:06 +000028
29//===----------------------------------------------------------------------===//
30// Declaration serialization
31//===----------------------------------------------------------------------===//
32
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000033namespace clang {
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000034 class ASTDeclWriter : public DeclVisitor<ASTDeclWriter, void> {
Sebastian Redl55c0ad52010-08-18 23:56:21 +000035 ASTWriter &Writer;
Chris Lattner7099dbc2009-04-27 06:16:06 +000036 ASTContext &Context;
Richard Smith69c82bf2016-04-01 22:52:03 +000037 ASTRecordWriter Record;
Chris Lattner7099dbc2009-04-27 06:16:06 +000038
Sebastian Redl539c5062010-08-18 23:57:32 +000039 serialization::DeclCode Code;
Chris Lattner258172e2009-04-27 07:35:58 +000040 unsigned AbbrevToUse;
Chris Lattner7099dbc2009-04-27 06:16:06 +000041
Richard Smith69c82bf2016-04-01 22:52:03 +000042 public:
43 ASTDeclWriter(ASTWriter &Writer, ASTContext &Context,
44 ASTWriter::RecordDataImpl &Record)
45 : Writer(Writer), Context(Context), Record(Writer, Record),
46 Code((serialization::DeclCode)0), AbbrevToUse(0) {}
47
48 uint64_t Emit(Decl *D) {
49 if (!Code)
50 llvm::report_fatal_error(StringRef("unexpected declaration kind '") +
51 D->getDeclKindName() + "'");
Richard Smith645d2cf2016-04-14 00:29:55 +000052 return Record.Emit(Code, AbbrevToUse);
Chris Lattner258172e2009-04-27 07:35:58 +000053 }
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000054
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +000055 void Visit(Decl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000056
57 void VisitDecl(Decl *D);
Nico Weber66220292016-03-02 17:28:48 +000058 void VisitPragmaCommentDecl(PragmaCommentDecl *D);
Nico Webercbbaeb12016-03-02 19:28:54 +000059 void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000060 void VisitTranslationUnitDecl(TranslationUnitDecl *D);
61 void VisitNamedDecl(NamedDecl *D);
Chris Lattnerc8e630e2011-02-17 07:39:24 +000062 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregore31bbd92010-02-21 18:22:14 +000063 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000064 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
65 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000066 void VisitTypeDecl(TypeDecl *D);
Douglas Gregor1f179062011-12-19 14:40:25 +000067 void VisitTypedefNameDecl(TypedefNameDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000068 void VisitTypedefDecl(TypedefDecl *D);
Richard Smithdda56e42011-04-15 14:24:37 +000069 void VisitTypeAliasDecl(TypeAliasDecl *D);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000070 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000071 void VisitTagDecl(TagDecl *D);
72 void VisitEnumDecl(EnumDecl *D);
73 void VisitRecordDecl(RecordDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000074 void VisitCXXRecordDecl(CXXRecordDecl *D);
75 void VisitClassTemplateSpecializationDecl(
76 ClassTemplateSpecializationDecl *D);
77 void VisitClassTemplatePartialSpecializationDecl(
78 ClassTemplatePartialSpecializationDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +000079 void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D);
80 void VisitVarTemplatePartialSpecializationDecl(
81 VarTemplatePartialSpecializationDecl *D);
Fariborz Jahanian3a039e32011-08-27 20:50:59 +000082 void VisitClassScopeFunctionSpecializationDecl(
83 ClassScopeFunctionSpecializationDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000084 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000085 void VisitValueDecl(ValueDecl *D);
86 void VisitEnumConstantDecl(EnumConstantDecl *D);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000087 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +000088 void VisitDeclaratorDecl(DeclaratorDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000089 void VisitFunctionDecl(FunctionDecl *D);
Richard Smithbc491202017-02-17 20:05:37 +000090 void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000091 void VisitCXXMethodDecl(CXXMethodDecl *D);
92 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
93 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
94 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000095 void VisitFieldDecl(FieldDecl *D);
John McCall5e77d762013-04-16 07:28:30 +000096 void VisitMSPropertyDecl(MSPropertyDecl *D);
Francois Pichet783dd6e2010-11-21 06:08:52 +000097 void VisitIndirectFieldDecl(IndirectFieldDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000098 void VisitVarDecl(VarDecl *D);
99 void VisitImplicitParamDecl(ImplicitParamDecl *D);
100 void VisitParmVarDecl(ParmVarDecl *D);
Richard Smith7b76d812016-08-12 02:21:25 +0000101 void VisitDecompositionDecl(DecompositionDecl *D);
102 void VisitBindingDecl(BindingDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000103 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
104 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000105 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000106 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +0000107 void VisitVarTemplateDecl(VarTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000108 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000109 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3f1b5d02011-05-05 21:57:07 +0000110 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000111 void VisitUsingDecl(UsingDecl *D);
Richard Smith151c4562016-12-20 21:35:28 +0000112 void VisitUsingPackDecl(UsingPackDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000113 void VisitUsingShadowDecl(UsingShadowDecl *D);
Richard Smith5179eb72016-06-28 19:03:57 +0000114 void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000115 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Richard Smith8df390f2016-09-08 23:14:54 +0000116 void VisitExportDecl(ExportDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000117 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
Douglas Gregorba345522011-12-02 23:23:56 +0000118 void VisitImportDecl(ImportDecl *D);
Abramo Bagnarad7340582010-06-05 05:09:32 +0000119 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000120 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000121 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
122 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000123 void VisitBlockDecl(BlockDecl *D);
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +0000124 void VisitCapturedDecl(CapturedDecl *D);
Michael Han84324352013-02-22 17:15:32 +0000125 void VisitEmptyDecl(EmptyDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000126
Richard Smithf1c23dc2016-04-13 02:12:03 +0000127 void VisitDeclContext(DeclContext *DC);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000128 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000129
130
Alexis Hunted053252010-05-30 07:21:58 +0000131 // FIXME: Put in the same order is DeclNodes.td?
Chris Lattner7099dbc2009-04-27 06:16:06 +0000132 void VisitObjCMethodDecl(ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000133 void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000134 void VisitObjCContainerDecl(ObjCContainerDecl *D);
135 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
136 void VisitObjCIvarDecl(ObjCIvarDecl *D);
137 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
138 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000139 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
140 void VisitObjCImplDecl(ObjCImplDecl *D);
141 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
142 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
143 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
144 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
145 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
Alexey Bataeva769e072013-03-22 06:34:35 +0000146 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
Alexey Bataev25ed0c02019-03-07 17:54:44 +0000147 void VisitOMPAllocateDecl(OMPAllocateDecl *D);
Kelvin Li1408f912018-09-26 04:28:39 +0000148 void VisitOMPRequiresDecl(OMPRequiresDecl *D);
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000149 void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
Michael Kruse251e1482019-02-01 20:25:04 +0000150 void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D);
Alexey Bataev4244be22016-02-11 05:35:55 +0000151 void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
Richard Smithd28ac5b2014-03-22 23:33:22 +0000152
Douglas Gregor85f3f952015-07-07 03:57:15 +0000153 /// Add an Objective-C type parameter list to the given record.
154 void AddObjCTypeParamList(ObjCTypeParamList *typeParams) {
155 // Empty type parameter list.
156 if (!typeParams) {
157 Record.push_back(0);
158 return;
159 }
160
161 Record.push_back(typeParams->size());
162 for (auto typeParam : *typeParams) {
Richard Smith69c82bf2016-04-01 22:52:03 +0000163 Record.AddDeclRef(typeParam);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000164 }
Richard Smith69c82bf2016-04-01 22:52:03 +0000165 Record.AddSourceLocation(typeParams->getLAngleLoc());
166 Record.AddSourceLocation(typeParams->getRAngleLoc());
Douglas Gregor85f3f952015-07-07 03:57:15 +0000167 }
168
Richard Smithd8a83712015-08-22 01:47:18 +0000169 /// Add to the record the first declaration from each module file that
170 /// provides a declaration of D. The intent is to provide a sufficient
171 /// set such that reloading this set will load all current redeclarations.
172 void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) {
173 llvm::MapVector<ModuleFile*, const Decl*> Firsts;
174 // FIXME: We can skip entries that we know are implied by others.
Richard Smith5f55d932015-08-27 21:38:25 +0000175 for (const Decl *R = D->getMostRecentDecl(); R; R = R->getPreviousDecl()) {
176 if (R->isFromASTFile())
Richard Smithd8a83712015-08-22 01:47:18 +0000177 Firsts[Writer.Chain->getOwningModuleFile(R)] = R;
Richard Smith5f55d932015-08-27 21:38:25 +0000178 else if (IncludeLocal)
179 Firsts[nullptr] = R;
180 }
Richard Smithd8a83712015-08-22 01:47:18 +0000181 for (const auto &F : Firsts)
Richard Smith69c82bf2016-04-01 22:52:03 +0000182 Record.AddDeclRef(F.second);
Richard Smithd8a83712015-08-22 01:47:18 +0000183 }
184
Richard Smith509fc852015-02-27 23:05:10 +0000185 /// Get the specialization decl from an entry in the specialization list.
186 template <typename EntryType>
187 typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType *
188 getSpecializationDecl(EntryType &T) {
189 return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T);
190 }
191
192 /// Get the list of partial specializations from a template's common ptr.
193 template<typename T>
194 decltype(T::PartialSpecializations) &getPartialSpecializations(T *Common) {
195 return Common->PartialSpecializations;
196 }
197 ArrayRef<Decl> getPartialSpecializations(FunctionTemplateDecl::Common *) {
198 return None;
199 }
200
Richard Smith8ab0cfd2016-02-24 21:59:10 +0000201 template<typename DeclTy>
202 void AddTemplateSpecializations(DeclTy *D) {
Richard Smith509fc852015-02-27 23:05:10 +0000203 auto *Common = D->getCommonPtr();
204
205 // If we have any lazy specializations, and the external AST source is
206 // our chained AST reader, we can just write out the DeclIDs. Otherwise,
207 // we need to resolve them to actual declarations.
208 if (Writer.Chain != Writer.Context->getExternalSource() &&
209 Common->LazySpecializations) {
210 D->LoadLazySpecializations();
211 assert(!Common->LazySpecializations);
212 }
213
Richard Smith509fc852015-02-27 23:05:10 +0000214 ArrayRef<DeclID> LazySpecializations;
215 if (auto *LS = Common->LazySpecializations)
Craig Topper55e39a72015-09-29 04:53:28 +0000216 LazySpecializations = llvm::makeArrayRef(LS + 1, LS[0]);
Richard Smith509fc852015-02-27 23:05:10 +0000217
Richard Smithd8a83712015-08-22 01:47:18 +0000218 // Add a slot to the record for the number of specializations.
219 unsigned I = Record.size();
220 Record.push_back(0);
221
Richard Smith8ab0cfd2016-02-24 21:59:10 +0000222 // AddFirstDeclFromEachModule might trigger deserialization, invalidating
223 // *Specializations iterators.
224 llvm::SmallVector<const Decl*, 16> Specs;
225 for (auto &Entry : Common->Specializations)
226 Specs.push_back(getSpecializationDecl(Entry));
227 for (auto &Entry : getPartialSpecializations(Common))
228 Specs.push_back(getSpecializationDecl(Entry));
229
230 for (auto *D : Specs) {
Richard Smith509fc852015-02-27 23:05:10 +0000231 assert(D->isCanonicalDecl() && "non-canonical decl in set");
Richard Smithd8a83712015-08-22 01:47:18 +0000232 AddFirstDeclFromEachModule(D, /*IncludeLocal*/true);
Richard Smith509fc852015-02-27 23:05:10 +0000233 }
Benjamin Kramerf367dd92015-06-12 15:31:50 +0000234 Record.append(LazySpecializations.begin(), LazySpecializations.end());
Richard Smithd8a83712015-08-22 01:47:18 +0000235
236 // Update the size entry we added earlier.
237 Record[I] = Record.size() - I - 1;
238 }
239
240 /// Ensure that this template specialization is associated with the specified
241 /// template on reload.
242 void RegisterTemplateSpecialization(const Decl *Template,
243 const Decl *Specialization) {
244 Template = Template->getCanonicalDecl();
245
246 // If the canonical template is local, we'll write out this specialization
247 // when we emit it.
248 // FIXME: We can do the same thing if there is any local declaration of
249 // the template, to avoid emitting an update record.
250 if (!Template->isFromASTFile())
251 return;
252
253 // We only need to associate the first local declaration of the
254 // specialization. The other declarations will get pulled in by it.
255 if (Writer.getFirstLocalDecl(Specialization) != Specialization)
256 return;
257
258 Writer.DeclUpdates[Template].push_back(ASTWriter::DeclUpdate(
259 UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION, Specialization));
Richard Smith509fc852015-02-27 23:05:10 +0000260 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000261 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000262}
Chris Lattner7099dbc2009-04-27 06:16:06 +0000263
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000264void ASTDeclWriter::Visit(Decl *D) {
265 DeclVisitor<ASTDeclWriter>::Visit(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000266
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000267 // Source locations require array (variable-length) abbreviations. The
268 // abbreviation infrastructure requires that arrays are encoded last, so
269 // we handle it here in the case of those classes derived from DeclaratorDecl
Nick Lewycky4b81fc872015-10-18 20:32:12 +0000270 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
Richard Smithc23d7342018-06-29 20:46:25 +0000271 if (auto *TInfo = DD->getTypeSourceInfo())
272 Record.AddTypeLoc(TInfo->getTypeLoc());
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000273 }
274
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000275 // Handle FunctionDecl's body here and write it after all other Stmts/Exprs
276 // have been written. We want it last because we will not read it back when
Fangrui Song6907ce22018-07-30 19:24:48 +0000277 // retrieving it from the AST, we'll just lazily set the offset.
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000278 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
Alexis Hunt4a8ea102011-05-06 20:44:56 +0000279 Record.push_back(FD->doesThisDeclarationHaveABody());
280 if (FD->doesThisDeclarationHaveABody())
Richard Smith290d8012016-04-06 17:06:00 +0000281 Record.AddFunctionDefinition(FD);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000282 }
Richard Smithf1c23dc2016-04-13 02:12:03 +0000283
284 // If this declaration is also a DeclContext, write blocks for the
285 // declarations that lexically stored inside its context and those
286 // declarations that are visible from its context.
287 if (DeclContext *DC = dyn_cast<DeclContext>(D))
288 VisitDeclContext(DC);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000289}
290
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000291void ASTDeclWriter::VisitDecl(Decl *D) {
Richard Smith69c82bf2016-04-01 22:52:03 +0000292 Record.AddDeclRef(cast_or_null<Decl>(D->getDeclContext()));
Richard Smith8aed4222015-12-11 22:41:00 +0000293 if (D->getDeclContext() != D->getLexicalDeclContext())
Richard Smith69c82bf2016-04-01 22:52:03 +0000294 Record.AddDeclRef(cast_or_null<Decl>(D->getLexicalDeclContext()));
Richard Smith8aed4222015-12-11 22:41:00 +0000295 else
296 Record.push_back(0);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000297 Record.push_back(D->isInvalidDecl());
298 Record.push_back(D->hasAttrs());
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000299 if (D->hasAttrs())
Richard Smith69c82bf2016-04-01 22:52:03 +0000300 Record.AddAttributes(D->getAttrs());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000301 Record.push_back(D->isImplicit());
Douglas Gregorebada0772010-06-17 23:14:26 +0000302 Record.push_back(D->isUsed(false));
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +0000303 Record.push_back(D->isReferenced());
Douglas Gregor781f7132012-01-06 16:59:53 +0000304 Record.push_back(D->isTopLevelDeclInObjCContainer());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000305 Record.push_back(D->getAccess());
Douglas Gregor781f7132012-01-06 16:59:53 +0000306 Record.push_back(D->isModulePrivate());
Richard Smith54f04402017-05-18 02:29:20 +0000307 Record.push_back(Writer.getSubmoduleID(D->getOwningModule()));
Richard Smithc264d352014-03-23 02:30:01 +0000308
309 // If this declaration injected a name into a context different from its
310 // lexical context, and that context is an imported namespace, we need to
311 // update its visible declarations to include this name.
312 //
313 // This happens when we instantiate a class with a friend declaration or a
314 // function with a local extern declaration, for instance.
Richard Smith5fc18a92015-07-12 23:43:21 +0000315 //
316 // FIXME: Can we handle this in AddedVisibleDecl instead?
Richard Smithc264d352014-03-23 02:30:01 +0000317 if (D->isOutOfLine()) {
Richard Smithe3a97022014-03-23 20:41:56 +0000318 auto *DC = D->getDeclContext();
319 while (auto *NS = dyn_cast<NamespaceDecl>(DC->getRedeclContext())) {
320 if (!NS->isFromASTFile())
321 break;
Chandler Carruth8a3d24d2015-03-26 04:27:10 +0000322 Writer.UpdatedDeclContexts.insert(NS->getPrimaryContext());
Richard Smithe3a97022014-03-23 20:41:56 +0000323 if (!NS->isInlineNamespace())
324 break;
325 DC = NS->getParent();
326 }
Richard Smithc264d352014-03-23 02:30:01 +0000327 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000328}
329
Nico Weber66220292016-03-02 17:28:48 +0000330void ASTDeclWriter::VisitPragmaCommentDecl(PragmaCommentDecl *D) {
331 StringRef Arg = D->getArg();
332 Record.push_back(Arg.size());
333 VisitDecl(D);
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000334 Record.AddSourceLocation(D->getBeginLoc());
Nico Weber66220292016-03-02 17:28:48 +0000335 Record.push_back(D->getCommentKind());
Richard Smith69c82bf2016-04-01 22:52:03 +0000336 Record.AddString(Arg);
Nico Weber66220292016-03-02 17:28:48 +0000337 Code = serialization::DECL_PRAGMA_COMMENT;
338}
339
Nico Webercbbaeb12016-03-02 19:28:54 +0000340void ASTDeclWriter::VisitPragmaDetectMismatchDecl(
341 PragmaDetectMismatchDecl *D) {
342 StringRef Name = D->getName();
343 StringRef Value = D->getValue();
344 Record.push_back(Name.size() + 1 + Value.size());
345 VisitDecl(D);
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000346 Record.AddSourceLocation(D->getBeginLoc());
Richard Smith69c82bf2016-04-01 22:52:03 +0000347 Record.AddString(Name);
348 Record.AddString(Value);
Nico Webercbbaeb12016-03-02 19:28:54 +0000349 Code = serialization::DECL_PRAGMA_DETECT_MISMATCH;
350}
351
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000352void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
Douglas Gregordab42432011-08-12 00:15:20 +0000353 llvm_unreachable("Translation units aren't directly serialized");
Chris Lattner7099dbc2009-04-27 06:16:06 +0000354}
355
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000356void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000357 VisitDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000358 Record.AddDeclarationName(D->getDeclName());
Richard Smith2b560572015-02-07 03:11:11 +0000359 Record.push_back(needsAnonymousDeclarationNumber(D)
360 ? Writer.getAnonymousDeclarationNumber(D)
361 : 0);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000362}
363
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000364void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000365 VisitNamedDecl(D);
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000366 Record.AddSourceLocation(D->getBeginLoc());
Richard Smith69c82bf2016-04-01 22:52:03 +0000367 Record.AddTypeRef(QualType(D->getTypeForDecl(), 0));
Chris Lattner7099dbc2009-04-27 06:16:06 +0000368}
369
Douglas Gregor1f179062011-12-19 14:40:25 +0000370void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) {
Douglas Gregor05f10352011-12-17 23:38:30 +0000371 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000372 VisitTypeDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000373 Record.AddTypeSourceInfo(D->getTypeSourceInfo());
Enea Zaffanellaa86d88c2013-06-20 12:46:19 +0000374 Record.push_back(D->isModed());
375 if (D->isModed())
Richard Smith69c82bf2016-04-01 22:52:03 +0000376 Record.AddTypeRef(D->getUnderlyingType());
Richard Smithc0ca4c22017-01-26 22:39:55 +0000377 Record.AddDeclRef(D->getAnonDeclWithTypedefName(false));
Douglas Gregor1f179062011-12-19 14:40:25 +0000378}
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000379
Douglas Gregor1f179062011-12-19 14:40:25 +0000380void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) {
381 VisitTypedefNameDecl(D);
Richard Smith8aed4222015-12-11 22:41:00 +0000382 if (D->getDeclContext() == D->getLexicalDeclContext() &&
383 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000384 !D->isImplicit() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000385 D->getFirstDecl() == D->getMostRecentDecl() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000386 !D->isInvalidDecl() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000387 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000388 !D->isModulePrivate() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000389 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000390 D->getDeclName().getNameKind() == DeclarationName::Identifier)
391 AbbrevToUse = Writer.getDeclTypedefAbbrev();
392
Sebastian Redl539c5062010-08-18 23:57:32 +0000393 Code = serialization::DECL_TYPEDEF;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000394}
395
Richard Smithdda56e42011-04-15 14:24:37 +0000396void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) {
Douglas Gregor1f179062011-12-19 14:40:25 +0000397 VisitTypedefNameDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000398 Record.AddDeclRef(D->getDescribedAliasTemplate());
Richard Smithdda56e42011-04-15 14:24:37 +0000399 Code = serialization::DECL_TYPEALIAS;
400}
401
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000402void ASTDeclWriter::VisitTagDecl(TagDecl *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000403 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000404 VisitTypeDecl(D);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000405 Record.push_back(D->getIdentifierNamespace());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000406 Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding
Richard Smith2c381642014-08-27 23:11:59 +0000407 if (!isa<CXXRecordDecl>(D))
408 Record.push_back(D->isCompleteDefinition());
Douglas Gregor5089c762010-02-12 17:40:34 +0000409 Record.push_back(D->isEmbeddedInDeclarator());
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +0000410 Record.push_back(D->isFreeStanding());
David Blaikiea8d23ce2013-07-14 01:07:41 +0000411 Record.push_back(D->isCompleteDefinitionRequired());
Argyrios Kyrtzidisd798c052016-07-15 18:11:33 +0000412 Record.AddSourceRange(D->getBraceRange());
Richard Smith70d58502014-08-30 00:04:23 +0000413
414 if (D->hasExtInfo()) {
415 Record.push_back(1);
Richard Smith69c82bf2016-04-01 22:52:03 +0000416 Record.AddQualifierInfo(*D->getExtInfo());
Richard Smith70d58502014-08-30 00:04:23 +0000417 } else if (auto *TD = D->getTypedefNameForAnonDecl()) {
418 Record.push_back(2);
Richard Smith69c82bf2016-04-01 22:52:03 +0000419 Record.AddDeclRef(TD);
420 Record.AddIdentifierRef(TD->getDeclName().getAsIdentifierInfo());
Richard Smith70d58502014-08-30 00:04:23 +0000421 } else {
422 Record.push_back(0);
423 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000424}
425
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000426void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000427 VisitTagDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000428 Record.AddTypeSourceInfo(D->getIntegerTypeSourceInfo());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000429 if (!D->getIntegerTypeSourceInfo())
Richard Smith69c82bf2016-04-01 22:52:03 +0000430 Record.AddTypeRef(D->getIntegerType());
431 Record.AddTypeRef(D->getPromotionType());
John McCall9aa35be2010-05-06 08:49:23 +0000432 Record.push_back(D->getNumPositiveBits());
433 Record.push_back(D->getNumNegativeBits());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000434 Record.push_back(D->isScoped());
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000435 Record.push_back(D->isScopedUsingClassTag());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000436 Record.push_back(D->isFixed());
Richard Trieuab4d7302018-07-25 22:52:05 +0000437 Record.push_back(D->getODRHash());
438
Richard Smith4b38ded2012-03-14 23:13:10 +0000439 if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
Richard Smith69c82bf2016-04-01 22:52:03 +0000440 Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
Richard Smith4b38ded2012-03-14 23:13:10 +0000441 Record.push_back(MemberInfo->getTemplateSpecializationKind());
Richard Smith69c82bf2016-04-01 22:52:03 +0000442 Record.AddSourceLocation(MemberInfo->getPointOfInstantiation());
Richard Smith4b38ded2012-03-14 23:13:10 +0000443 } else {
Richard Smith69c82bf2016-04-01 22:52:03 +0000444 Record.AddDeclRef(nullptr);
Richard Smith4b38ded2012-03-14 23:13:10 +0000445 }
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000446
Richard Smith8aed4222015-12-11 22:41:00 +0000447 if (D->getDeclContext() == D->getLexicalDeclContext() &&
448 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000449 !D->isImplicit() &&
450 !D->isUsed(false) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000451 !D->hasExtInfo() &&
Richard Smith70d58502014-08-30 00:04:23 +0000452 !D->getTypedefNameForAnonDecl() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000453 D->getFirstDecl() == D->getMostRecentDecl() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000454 !D->isInvalidDecl() &&
455 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000456 !D->isTopLevelDeclInObjCContainer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000457 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000458 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000459 !CXXRecordDecl::classofKind(D->getKind()) &&
460 !D->getIntegerTypeSourceInfo() &&
Argyrios Kyrtzidisca370b0d2013-03-18 22:23:49 +0000461 !D->getMemberSpecializationInfo() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000462 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000463 D->getDeclName().getNameKind() == DeclarationName::Identifier)
464 AbbrevToUse = Writer.getDeclEnumAbbrev();
465
Sebastian Redl539c5062010-08-18 23:57:32 +0000466 Code = serialization::DECL_ENUM;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000467}
468
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000469void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000470 VisitTagDecl(D);
471 Record.push_back(D->hasFlexibleArrayMember());
472 Record.push_back(D->isAnonymousStructOrUnion());
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000473 Record.push_back(D->hasObjectMember());
Fariborz Jahanian78652202013-01-25 23:57:05 +0000474 Record.push_back(D->hasVolatileMember());
Akira Hatanaka34fb2642018-03-13 18:58:25 +0000475 Record.push_back(D->isNonTrivialToPrimitiveDefaultInitialize());
476 Record.push_back(D->isNonTrivialToPrimitiveCopy());
477 Record.push_back(D->isNonTrivialToPrimitiveDestroy());
Akira Hatanakafcbe17c2018-03-28 21:13:14 +0000478 Record.push_back(D->isParamDestroyedInCallee());
Akira Hatanakae6313ac2018-04-09 22:48:22 +0000479 Record.push_back(D->getArgPassingRestrictions());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000480
Richard Smith8aed4222015-12-11 22:41:00 +0000481 if (D->getDeclContext() == D->getLexicalDeclContext() &&
482 !D->hasAttrs() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000483 !D->isImplicit() &&
484 !D->isUsed(false) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000485 !D->hasExtInfo() &&
Richard Smith70d58502014-08-30 00:04:23 +0000486 !D->getTypedefNameForAnonDecl() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000487 D->getFirstDecl() == D->getMostRecentDecl() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000488 !D->isInvalidDecl() &&
489 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000490 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000491 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000492 !D->isModulePrivate() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000493 !CXXRecordDecl::classofKind(D->getKind()) &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000494 !needsAnonymousDeclarationNumber(D) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000495 D->getDeclName().getNameKind() == DeclarationName::Identifier)
Douglas Gregor03412ba2011-06-03 02:27:19 +0000496 AbbrevToUse = Writer.getDeclRecordAbbrev();
497
Sebastian Redl539c5062010-08-18 23:57:32 +0000498 Code = serialization::DECL_RECORD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000499}
500
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000501void ASTDeclWriter::VisitValueDecl(ValueDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000502 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000503 Record.AddTypeRef(D->getType());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000504}
505
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000506void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000507 VisitValueDecl(D);
508 Record.push_back(D->getInitExpr()? 1 : 0);
509 if (D->getInitExpr())
Richard Smith290d8012016-04-06 17:06:00 +0000510 Record.AddStmt(D->getInitExpr());
Richard Smith69c82bf2016-04-01 22:52:03 +0000511 Record.AddAPSInt(D->getInitVal());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000512
Sebastian Redl539c5062010-08-18 23:57:32 +0000513 Code = serialization::DECL_ENUM_CONSTANT;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000514}
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000515
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000516void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000517 VisitValueDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000518 Record.AddSourceLocation(D->getInnerLocStart());
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000519 Record.push_back(D->hasExtInfo());
520 if (D->hasExtInfo())
Richard Smith69c82bf2016-04-01 22:52:03 +0000521 Record.AddQualifierInfo(*D->getExtInfo());
Richard Smithc23d7342018-06-29 20:46:25 +0000522 // The location information is deferred until the end of the record.
523 Record.AddTypeRef(D->getTypeSourceInfo() ? D->getTypeSourceInfo()->getType()
524 : QualType());
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000525}
Chris Lattner7099dbc2009-04-27 06:16:06 +0000526
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000527void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000528 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000529 VisitDeclaratorDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000530 Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000531 Record.push_back(D->getIdentifierNamespace());
Fangrui Song6907ce22018-07-30 19:24:48 +0000532
Douglas Gregorb2585692012-01-04 17:13:46 +0000533 // FunctionDecl's body is handled last at ASTWriterDecl::Visit,
534 // after everything else is written.
Erich Keane9c665062018-08-01 21:02:40 +0000535 Record.push_back(static_cast<int>(D->getStorageClass())); // FIXME: stable encoding
536 Record.push_back(D->isInlineSpecified());
537 Record.push_back(D->isInlined());
538 Record.push_back(D->isExplicitSpecified());
539 Record.push_back(D->isVirtualAsWritten());
540 Record.push_back(D->isPure());
541 Record.push_back(D->hasInheritedPrototype());
542 Record.push_back(D->hasWrittenPrototype());
543 Record.push_back(D->isDeletedBit());
544 Record.push_back(D->isTrivial());
545 Record.push_back(D->isTrivialForCall());
546 Record.push_back(D->isDefaulted());
547 Record.push_back(D->isExplicitlyDefaulted());
548 Record.push_back(D->hasImplicitReturnZero());
549 Record.push_back(D->isConstexpr());
550 Record.push_back(D->usesSEHTry());
551 Record.push_back(D->hasSkippedBody());
552 Record.push_back(D->isMultiVersion());
553 Record.push_back(D->isLateTemplateParsed());
Rafael Espindola3ae00052013-05-13 00:12:11 +0000554 Record.push_back(D->getLinkageInternal());
Stephen Kelly1c301dc2018-08-09 21:09:38 +0000555 Record.AddSourceLocation(D->getEndLoc());
Douglas Gregorb2585692012-01-04 17:13:46 +0000556
Richard Trieue6caa262017-12-23 00:41:01 +0000557 Record.push_back(D->getODRHash());
558
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000559 Record.push_back(D->getTemplatedKind());
560 switch (D->getTemplatedKind()) {
561 case FunctionDecl::TK_NonTemplate:
562 break;
563 case FunctionDecl::TK_FunctionTemplate:
Richard Smith69c82bf2016-04-01 22:52:03 +0000564 Record.AddDeclRef(D->getDescribedFunctionTemplate());
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000565 break;
566 case FunctionDecl::TK_MemberSpecialization: {
567 MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo();
Richard Smith69c82bf2016-04-01 22:52:03 +0000568 Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000569 Record.push_back(MemberInfo->getTemplateSpecializationKind());
Richard Smith69c82bf2016-04-01 22:52:03 +0000570 Record.AddSourceLocation(MemberInfo->getPointOfInstantiation());
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000571 break;
572 }
573 case FunctionDecl::TK_FunctionTemplateSpecialization: {
574 FunctionTemplateSpecializationInfo *
575 FTSInfo = D->getTemplateSpecializationInfo();
Richard Smithd8a83712015-08-22 01:47:18 +0000576
577 RegisterTemplateSpecialization(FTSInfo->getTemplate(), D);
578
Richard Smith69c82bf2016-04-01 22:52:03 +0000579 Record.AddDeclRef(FTSInfo->getTemplate());
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000580 Record.push_back(FTSInfo->getTemplateSpecializationKind());
Fangrui Song6907ce22018-07-30 19:24:48 +0000581
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000582 // Template arguments.
Richard Smith69c82bf2016-04-01 22:52:03 +0000583 Record.AddTemplateArgumentList(FTSInfo->TemplateArguments);
Fangrui Song6907ce22018-07-30 19:24:48 +0000584
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000585 // Template args as written.
Craig Toppera13603a2014-05-22 05:54:18 +0000586 Record.push_back(FTSInfo->TemplateArgumentsAsWritten != nullptr);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000587 if (FTSInfo->TemplateArgumentsAsWritten) {
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000588 Record.push_back(FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs);
589 for (int i=0, e = FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs;
590 i!=e; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +0000591 Record.AddTemplateArgumentLoc(
592 (*FTSInfo->TemplateArgumentsAsWritten)[i]);
593 Record.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->LAngleLoc);
594 Record.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->RAngleLoc);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000595 }
Fangrui Song6907ce22018-07-30 19:24:48 +0000596
Richard Smith69c82bf2016-04-01 22:52:03 +0000597 Record.AddSourceLocation(FTSInfo->getPointOfInstantiation());
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000598
599 if (D->isCanonicalDecl()) {
600 // Write the template that contains the specializations set. We will
601 // add a FunctionTemplateSpecializationInfo to it when reading.
Richard Smith69c82bf2016-04-01 22:52:03 +0000602 Record.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl());
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000603 }
Argyrios Kyrtzidisdc9ca0a2010-06-25 16:24:51 +0000604 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000605 }
606 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
607 DependentFunctionTemplateSpecializationInfo *
608 DFTSInfo = D->getDependentSpecializationInfo();
Fangrui Song6907ce22018-07-30 19:24:48 +0000609
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000610 // Templates.
611 Record.push_back(DFTSInfo->getNumTemplates());
612 for (int i=0, e = DFTSInfo->getNumTemplates(); i != e; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +0000613 Record.AddDeclRef(DFTSInfo->getTemplate(i));
Fangrui Song6907ce22018-07-30 19:24:48 +0000614
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000615 // Templates args.
616 Record.push_back(DFTSInfo->getNumTemplateArgs());
617 for (int i=0, e = DFTSInfo->getNumTemplateArgs(); i != e; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +0000618 Record.AddTemplateArgumentLoc(DFTSInfo->getTemplateArg(i));
619 Record.AddSourceLocation(DFTSInfo->getLAngleLoc());
620 Record.AddSourceLocation(DFTSInfo->getRAngleLoc());
Argyrios Kyrtzidisdc9ca0a2010-06-25 16:24:51 +0000621 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000622 }
623 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000624
Chris Lattner7099dbc2009-04-27 06:16:06 +0000625 Record.push_back(D->param_size());
David Majnemer59f77922016-06-24 04:05:48 +0000626 for (auto P : D->parameters())
Richard Smith69c82bf2016-04-01 22:52:03 +0000627 Record.AddDeclRef(P);
Sebastian Redl539c5062010-08-18 23:57:32 +0000628 Code = serialization::DECL_FUNCTION;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000629}
630
Richard Smithbc491202017-02-17 20:05:37 +0000631void ASTDeclWriter::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) {
632 VisitFunctionDecl(D);
Erich Keane9c665062018-08-01 21:02:40 +0000633 Record.push_back(D->isCopyDeductionCandidate());
Richard Smithbc491202017-02-17 20:05:37 +0000634 Code = serialization::DECL_CXX_DEDUCTION_GUIDE;
635}
636
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000637void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000638 VisitNamedDecl(D);
639 // FIXME: convert to LazyStmtPtr?
Mike Stump11289f42009-09-09 15:08:12 +0000640 // Unlike C/C++, method bodies will never be in header files.
Craig Toppera13603a2014-05-22 05:54:18 +0000641 bool HasBodyStuff = D->getBody() != nullptr ||
642 D->getSelfDecl() != nullptr || D->getCmdDecl() != nullptr;
Argyrios Kyrtzidisa8607772010-08-09 10:54:37 +0000643 Record.push_back(HasBodyStuff);
644 if (HasBodyStuff) {
Richard Smith290d8012016-04-06 17:06:00 +0000645 Record.AddStmt(D->getBody());
Richard Smith69c82bf2016-04-01 22:52:03 +0000646 Record.AddDeclRef(D->getSelfDecl());
647 Record.AddDeclRef(D->getCmdDecl());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000648 }
649 Record.push_back(D->isInstanceMethod());
650 Record.push_back(D->isVariadic());
Jordan Rosed01e83a2012-10-10 16:42:25 +0000651 Record.push_back(D->isPropertyAccessor());
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000652 Record.push_back(D->isDefined());
Erich Keane9b18eca2018-08-01 21:31:08 +0000653 Record.push_back(D->isOverriding());
654 Record.push_back(D->hasSkippedBody());
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000655
Erich Keane9b18eca2018-08-01 21:31:08 +0000656 Record.push_back(D->isRedeclaration());
657 Record.push_back(D->hasRedeclaration());
658 if (D->hasRedeclaration()) {
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000659 assert(Context.getObjCMethodRedeclaration(D));
Richard Smith69c82bf2016-04-01 22:52:03 +0000660 Record.AddDeclRef(Context.getObjCMethodRedeclaration(D));
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000661 }
662
Chris Lattner7099dbc2009-04-27 06:16:06 +0000663 // FIXME: stable encoding for @required/@optional
Mike Stump11289f42009-09-09 15:08:12 +0000664 Record.push_back(D->getImplementationControl());
Douglas Gregor813a0662015-06-19 18:14:38 +0000665 // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway/nullability
Mike Stump11289f42009-09-09 15:08:12 +0000666 Record.push_back(D->getObjCDeclQualifier());
Douglas Gregor33823722011-06-11 01:09:30 +0000667 Record.push_back(D->hasRelatedResultType());
Richard Smith69c82bf2016-04-01 22:52:03 +0000668 Record.AddTypeRef(D->getReturnType());
669 Record.AddTypeSourceInfo(D->getReturnTypeSourceInfo());
Stephen Kelly1c301dc2018-08-09 21:09:38 +0000670 Record.AddSourceLocation(D->getEndLoc());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000671 Record.push_back(D->param_size());
David Majnemer59f77922016-06-24 04:05:48 +0000672 for (const auto *P : D->parameters())
Richard Smith69c82bf2016-04-01 22:52:03 +0000673 Record.AddDeclRef(P);
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000674
Erich Keane9b18eca2018-08-01 21:31:08 +0000675 Record.push_back(D->getSelLocsKind());
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000676 unsigned NumStoredSelLocs = D->getNumStoredSelLocs();
677 SourceLocation *SelLocs = D->getStoredSelLocs();
678 Record.push_back(NumStoredSelLocs);
679 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +0000680 Record.AddSourceLocation(SelLocs[i]);
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000681
Sebastian Redl539c5062010-08-18 23:57:32 +0000682 Code = serialization::DECL_OBJC_METHOD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000683}
684
Douglas Gregor85f3f952015-07-07 03:57:15 +0000685void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
686 VisitTypedefNameDecl(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +0000687 Record.push_back(D->Variance);
Douglas Gregore83b9562015-07-07 03:57:53 +0000688 Record.push_back(D->Index);
Richard Smith69c82bf2016-04-01 22:52:03 +0000689 Record.AddSourceLocation(D->VarianceLoc);
690 Record.AddSourceLocation(D->ColonLoc);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000691
692 Code = serialization::DECL_OBJC_TYPE_PARAM;
693}
694
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000695void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000696 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000697 Record.AddSourceLocation(D->getAtStartLoc());
698 Record.AddSourceRange(D->getAtEndRange());
Sebastian Redl539c5062010-08-18 23:57:32 +0000699 // Abstract class (no need to define a stable serialization::DECL code).
Chris Lattner7099dbc2009-04-27 06:16:06 +0000700}
701
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000702void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
Douglas Gregor66b310c2011-12-15 18:03:09 +0000703 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000704 VisitObjCContainerDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000705 Record.AddTypeRef(QualType(D->getTypeForDecl(), 0));
Douglas Gregor85f3f952015-07-07 03:57:15 +0000706 AddObjCTypeParamList(D->TypeParamList);
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000707
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000708 Record.push_back(D->isThisDeclarationADefinition());
709 if (D->isThisDeclarationADefinition()) {
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000710 // Write the DefinitionData
711 ObjCInterfaceDecl::DefinitionData &Data = D->data();
Fangrui Song6907ce22018-07-30 19:24:48 +0000712
Richard Smith69c82bf2016-04-01 22:52:03 +0000713 Record.AddTypeSourceInfo(D->getSuperClassTInfo());
714 Record.AddSourceLocation(D->getEndOfDefinitionLoc());
Argyrios Kyrtzidis9ed9e5f2013-12-03 21:11:30 +0000715 Record.push_back(Data.HasDesignatedInitializers);
Douglas Gregor16408322011-12-15 22:34:59 +0000716
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000717 // Write out the protocols that are directly referenced by the @interface.
718 Record.push_back(Data.ReferencedProtocols.size());
Aaron Ballmana49c5062014-03-13 20:29:09 +0000719 for (const auto *P : D->protocols())
Richard Smith69c82bf2016-04-01 22:52:03 +0000720 Record.AddDeclRef(P);
Aaron Ballmane9378882014-03-13 20:34:24 +0000721 for (const auto &PL : D->protocol_locs())
Richard Smith69c82bf2016-04-01 22:52:03 +0000722 Record.AddSourceLocation(PL);
Fangrui Song6907ce22018-07-30 19:24:48 +0000723
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000724 // Write out the protocols that are transitively referenced.
725 Record.push_back(Data.AllReferencedProtocols.size());
726 for (ObjCList<ObjCProtocolDecl>::iterator
727 P = Data.AllReferencedProtocols.begin(),
728 PEnd = Data.AllReferencedProtocols.end();
729 P != PEnd; ++P)
Richard Smith69c82bf2016-04-01 22:52:03 +0000730 Record.AddDeclRef(*P);
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000731
Fangrui Song6907ce22018-07-30 19:24:48 +0000732
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000733 if (ObjCCategoryDecl *Cat = D->getCategoryListRaw()) {
Douglas Gregor404cdde2012-01-27 01:47:08 +0000734 // Ensure that we write out the set of categories for this class.
735 Writer.ObjCClassesWithCategories.insert(D);
Fangrui Song6907ce22018-07-30 19:24:48 +0000736
Douglas Gregor404cdde2012-01-27 01:47:08 +0000737 // Make sure that the categories get serialized.
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000738 for (; Cat; Cat = Cat->getNextClassCategoryRaw())
Douglas Gregor404cdde2012-01-27 01:47:08 +0000739 (void)Writer.GetDeclRef(Cat);
740 }
Fangrui Song6907ce22018-07-30 19:24:48 +0000741 }
742
Sebastian Redl539c5062010-08-18 23:57:32 +0000743 Code = serialization::DECL_OBJC_INTERFACE;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000744}
745
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000746void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000747 VisitFieldDecl(D);
748 // FIXME: stable encoding for @public/@private/@protected/@package
Mike Stump11289f42009-09-09 15:08:12 +0000749 Record.push_back(D->getAccessControl());
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000750 Record.push_back(D->getSynthesize());
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000751
Richard Smith8aed4222015-12-11 22:41:00 +0000752 if (D->getDeclContext() == D->getLexicalDeclContext() &&
753 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000754 !D->isImplicit() &&
755 !D->isUsed(false) &&
756 !D->isInvalidDecl() &&
757 !D->isReferenced() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000758 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000759 !D->getBitWidth() &&
760 !D->hasExtInfo() &&
761 D->getDeclName())
762 AbbrevToUse = Writer.getDeclObjCIvarAbbrev();
763
Sebastian Redl539c5062010-08-18 23:57:32 +0000764 Code = serialization::DECL_OBJC_IVAR;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000765}
766
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000767void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
Douglas Gregora715bff2012-01-01 19:51:50 +0000768 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000769 VisitObjCContainerDecl(D);
Fangrui Song6907ce22018-07-30 19:24:48 +0000770
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000771 Record.push_back(D->isThisDeclarationADefinition());
772 if (D->isThisDeclarationADefinition()) {
Douglas Gregore6e48b12012-01-01 19:29:29 +0000773 Record.push_back(D->protocol_size());
Aaron Ballman0f6e64d2014-03-13 22:58:06 +0000774 for (const auto *I : D->protocols())
Richard Smith69c82bf2016-04-01 22:52:03 +0000775 Record.AddDeclRef(I);
Aaron Ballmana964ec12014-03-14 12:38:50 +0000776 for (const auto &PL : D->protocol_locs())
Richard Smith69c82bf2016-04-01 22:52:03 +0000777 Record.AddSourceLocation(PL);
Douglas Gregore6e48b12012-01-01 19:29:29 +0000778 }
Fangrui Song6907ce22018-07-30 19:24:48 +0000779
Sebastian Redl539c5062010-08-18 23:57:32 +0000780 Code = serialization::DECL_OBJC_PROTOCOL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000781}
782
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000783void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000784 VisitFieldDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000785 Code = serialization::DECL_OBJC_AT_DEFS_FIELD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000786}
787
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000788void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000789 VisitObjCContainerDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000790 Record.AddSourceLocation(D->getCategoryNameLoc());
791 Record.AddSourceLocation(D->getIvarLBraceLoc());
792 Record.AddSourceLocation(D->getIvarRBraceLoc());
793 Record.AddDeclRef(D->getClassInterface());
Douglas Gregor85f3f952015-07-07 03:57:15 +0000794 AddObjCTypeParamList(D->TypeParamList);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000795 Record.push_back(D->protocol_size());
Aaron Ballman19a41762014-03-14 12:55:57 +0000796 for (const auto *I : D->protocols())
Richard Smith69c82bf2016-04-01 22:52:03 +0000797 Record.AddDeclRef(I);
Aaron Ballmana73c8572014-03-14 13:03:32 +0000798 for (const auto &PL : D->protocol_locs())
Richard Smith69c82bf2016-04-01 22:52:03 +0000799 Record.AddSourceLocation(PL);
Sebastian Redl539c5062010-08-18 23:57:32 +0000800 Code = serialization::DECL_OBJC_CATEGORY;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000801}
802
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000803void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000804 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000805 Record.AddDeclRef(D->getClassInterface());
Sebastian Redl539c5062010-08-18 23:57:32 +0000806 Code = serialization::DECL_OBJC_COMPATIBLE_ALIAS;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000807}
808
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000809void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000810 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000811 Record.AddSourceLocation(D->getAtLoc());
812 Record.AddSourceLocation(D->getLParenLoc());
813 Record.AddTypeRef(D->getType());
814 Record.AddTypeSourceInfo(D->getTypeSourceInfo());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000815 // FIXME: stable encoding
816 Record.push_back((unsigned)D->getPropertyAttributes());
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000817 Record.push_back((unsigned)D->getPropertyAttributesAsWritten());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000818 // FIXME: stable encoding
819 Record.push_back((unsigned)D->getPropertyImplementation());
Richard Smith69c82bf2016-04-01 22:52:03 +0000820 Record.AddDeclarationName(D->getGetterName());
Argyrios Kyrtzidis194b28e2017-03-16 18:25:40 +0000821 Record.AddSourceLocation(D->getGetterNameLoc());
Richard Smith69c82bf2016-04-01 22:52:03 +0000822 Record.AddDeclarationName(D->getSetterName());
Argyrios Kyrtzidis194b28e2017-03-16 18:25:40 +0000823 Record.AddSourceLocation(D->getSetterNameLoc());
Richard Smith69c82bf2016-04-01 22:52:03 +0000824 Record.AddDeclRef(D->getGetterMethodDecl());
825 Record.AddDeclRef(D->getSetterMethodDecl());
826 Record.AddDeclRef(D->getPropertyIvarDecl());
Sebastian Redl539c5062010-08-18 23:57:32 +0000827 Code = serialization::DECL_OBJC_PROPERTY;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000828}
829
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000830void ASTDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000831 VisitObjCContainerDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000832 Record.AddDeclRef(D->getClassInterface());
Sebastian Redl539c5062010-08-18 23:57:32 +0000833 // Abstract class (no need to define a stable serialization::DECL code).
Chris Lattner7099dbc2009-04-27 06:16:06 +0000834}
835
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000836void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000837 VisitObjCImplDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000838 Record.AddSourceLocation(D->getCategoryNameLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000839 Code = serialization::DECL_OBJC_CATEGORY_IMPL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000840}
841
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000842void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000843 VisitObjCImplDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000844 Record.AddDeclRef(D->getSuperClass());
845 Record.AddSourceLocation(D->getSuperClassLoc());
846 Record.AddSourceLocation(D->getIvarLBraceLoc());
847 Record.AddSourceLocation(D->getIvarRBraceLoc());
John McCall0d54a172012-10-17 04:53:31 +0000848 Record.push_back(D->hasNonZeroConstructors());
849 Record.push_back(D->hasDestructors());
Richard Smithc2bb8182015-03-24 06:36:48 +0000850 Record.push_back(D->NumIvarInitializers);
851 if (D->NumIvarInitializers)
Richard Smithaa165cf2016-04-13 21:57:08 +0000852 Record.AddCXXCtorInitializers(
Richard Smith69c82bf2016-04-01 22:52:03 +0000853 llvm::makeArrayRef(D->init_begin(), D->init_end()));
Sebastian Redl539c5062010-08-18 23:57:32 +0000854 Code = serialization::DECL_OBJC_IMPLEMENTATION;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000855}
856
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000857void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000858 VisitDecl(D);
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000859 Record.AddSourceLocation(D->getBeginLoc());
Richard Smith69c82bf2016-04-01 22:52:03 +0000860 Record.AddDeclRef(D->getPropertyDecl());
861 Record.AddDeclRef(D->getPropertyIvarDecl());
862 Record.AddSourceLocation(D->getPropertyIvarDeclLoc());
Richard Smith290d8012016-04-06 17:06:00 +0000863 Record.AddStmt(D->getGetterCXXConstructor());
864 Record.AddStmt(D->getSetterCXXAssignment());
Sebastian Redl539c5062010-08-18 23:57:32 +0000865 Code = serialization::DECL_OBJC_PROPERTY_IMPL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000866}
867
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000868void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000869 VisitDeclaratorDecl(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000870 Record.push_back(D->isMutable());
Richard Smith6b8e3c02017-08-28 00:28:14 +0000871
872 FieldDecl::InitStorageKind ISK = D->InitStorage.getInt();
873 Record.push_back(ISK);
874 if (ISK == FieldDecl::ISK_CapturedVLAType)
875 Record.AddTypeRef(QualType(D->getCapturedVLAType(), 0));
876 else if (ISK)
877 Record.AddStmt(D->getInClassInitializer());
878
879 Record.AddStmt(D->getBitWidth());
880
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000881 if (!D->getDeclName())
Richard Smith69c82bf2016-04-01 22:52:03 +0000882 Record.AddDeclRef(Context.getInstantiatedFromUnnamedFieldDecl(D));
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000883
Richard Smith8aed4222015-12-11 22:41:00 +0000884 if (D->getDeclContext() == D->getLexicalDeclContext() &&
885 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000886 !D->isImplicit() &&
887 !D->isUsed(false) &&
888 !D->isInvalidDecl() &&
889 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000890 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000891 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000892 !D->getBitWidth() &&
Richard Smith938f40b2011-06-11 17:19:42 +0000893 !D->hasInClassInitializer() &&
Richard Smith6b8e3c02017-08-28 00:28:14 +0000894 !D->hasCapturedVLAType() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000895 !D->hasExtInfo() &&
896 !ObjCIvarDecl::classofKind(D->getKind()) &&
897 !ObjCAtDefsFieldDecl::classofKind(D->getKind()) &&
898 D->getDeclName())
899 AbbrevToUse = Writer.getDeclFieldAbbrev();
900
Sebastian Redl539c5062010-08-18 23:57:32 +0000901 Code = serialization::DECL_FIELD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000902}
903
John McCall5e77d762013-04-16 07:28:30 +0000904void ASTDeclWriter::VisitMSPropertyDecl(MSPropertyDecl *D) {
905 VisitDeclaratorDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000906 Record.AddIdentifierRef(D->getGetterId());
907 Record.AddIdentifierRef(D->getSetterId());
John McCall5e77d762013-04-16 07:28:30 +0000908 Code = serialization::DECL_MS_PROPERTY;
909}
910
Francois Pichet783dd6e2010-11-21 06:08:52 +0000911void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
912 VisitValueDecl(D);
913 Record.push_back(D->getChainingSize());
914
Aaron Ballman29c94602014-03-07 18:36:15 +0000915 for (const auto *P : D->chain())
Richard Smith69c82bf2016-04-01 22:52:03 +0000916 Record.AddDeclRef(P);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000917 Code = serialization::DECL_INDIRECTFIELD;
918}
919
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000920void ASTDeclWriter::VisitVarDecl(VarDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000921 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000922 VisitDeclaratorDecl(D);
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000923 Record.push_back(D->getStorageClass());
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +0000924 Record.push_back(D->getTSCSpec());
Sebastian Redla9351792012-02-11 23:51:47 +0000925 Record.push_back(D->getInitStyle());
Erik Pilkington1e368822019-01-04 18:33:06 +0000926 Record.push_back(D->isARCPseudoStrong());
David Majnemerfa7bc782015-05-19 00:57:16 +0000927 if (!isa<ParmVarDecl>(D)) {
Richard Smithedbc6e92016-10-14 21:41:24 +0000928 Record.push_back(D->isThisDeclarationADemotedDefinition());
David Majnemerfa7bc782015-05-19 00:57:16 +0000929 Record.push_back(D->isExceptionVariable());
Taiju Tsuiki3be68e12018-06-19 05:35:30 +0000930 Record.push_back(D->isNRVOVariable());
David Majnemerfa7bc782015-05-19 00:57:16 +0000931 Record.push_back(D->isCXXForRangeDecl());
George Karpenkovec38cf72018-03-29 00:56:24 +0000932 Record.push_back(D->isObjCForDecl());
Richard Smith62f19e72016-06-25 00:15:56 +0000933 Record.push_back(D->isInline());
934 Record.push_back(D->isInlineSpecified());
David Majnemerfa7bc782015-05-19 00:57:16 +0000935 Record.push_back(D->isConstexpr());
936 Record.push_back(D->isInitCapture());
937 Record.push_back(D->isPreviousDeclInSameBlockScope());
Alexey Bataev56223232017-06-09 13:40:18 +0000938 if (const auto *IPD = dyn_cast<ImplicitParamDecl>(D))
939 Record.push_back(static_cast<unsigned>(IPD->getParameterKind()));
940 else
941 Record.push_back(0);
Akira Hatanaka8e57b072018-10-01 21:51:28 +0000942 Record.push_back(D->isEscapingByref());
David Majnemerfa7bc782015-05-19 00:57:16 +0000943 }
Rafael Espindola3ae00052013-05-13 00:12:11 +0000944 Record.push_back(D->getLinkageInternal());
Douglas Gregor12cda632012-09-20 23:43:29 +0000945
Richard Smithd0b4dd62011-12-19 06:19:21 +0000946 if (D->getInit()) {
947 Record.push_back(!D->isInitKnownICE() ? 1 : (D->isInitICE() ? 3 : 2));
Richard Smith290d8012016-04-06 17:06:00 +0000948 Record.AddStmt(D->getInit());
Richard Smithd0b4dd62011-12-19 06:19:21 +0000949 } else {
950 Record.push_back(0);
951 }
Richard Smitha4653622017-09-06 20:01:14 +0000952
Akira Hatanaka9978da32018-08-10 15:09:24 +0000953 if (D->hasAttr<BlocksAttr>() && D->getType()->getAsCXXRecordDecl()) {
954 ASTContext::BlockVarCopyInit Init = Writer.Context->getBlockVarCopyInit(D);
955 Record.AddStmt(Init.getCopyExpr());
956 if (Init.getCopyExpr())
957 Record.push_back(Init.canThrow());
958 }
959
Richard Smitha4653622017-09-06 20:01:14 +0000960 if (D->getStorageDuration() == SD_Static) {
961 bool ModulesCodegen = false;
962 if (Writer.WritingModule &&
963 !D->getDescribedVarTemplate() && !D->getMemberSpecializationInfo() &&
964 !isa<VarTemplateSpecializationDecl>(D)) {
965 // When building a C++ Modules TS module interface unit, a strong
966 // definition in the module interface is provided by the compilation of
967 // that module interface unit, not by its users. (Inline variables are
968 // still emitted in module users.)
969 ModulesCodegen =
970 (Writer.WritingModule->Kind == Module::ModuleInterfaceUnit &&
971 Writer.Context->GetGVALinkageForVariable(D) == GVA_StrongExternal);
972 }
973 Record.push_back(ModulesCodegen);
974 if (ModulesCodegen)
975 Writer.ModularCodegenDecls.push_back(Writer.GetDeclRef(D));
976 }
Fangrui Song6907ce22018-07-30 19:24:48 +0000977
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000978 enum {
979 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
980 };
981 if (VarTemplateDecl *TemplD = D->getDescribedVarTemplate()) {
982 Record.push_back(VarTemplate);
Richard Smith69c82bf2016-04-01 22:52:03 +0000983 Record.AddDeclRef(TemplD);
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000984 } else if (MemberSpecializationInfo *SpecInfo
985 = D->getMemberSpecializationInfo()) {
986 Record.push_back(StaticDataMemberSpecialization);
Richard Smith69c82bf2016-04-01 22:52:03 +0000987 Record.AddDeclRef(SpecInfo->getInstantiatedFrom());
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000988 Record.push_back(SpecInfo->getTemplateSpecializationKind());
Richard Smith69c82bf2016-04-01 22:52:03 +0000989 Record.AddSourceLocation(SpecInfo->getPointOfInstantiation());
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000990 } else {
991 Record.push_back(VarNotTemplate);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000992 }
993
Richard Smith8aed4222015-12-11 22:41:00 +0000994 if (D->getDeclContext() == D->getLexicalDeclContext() &&
995 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000996 !D->isImplicit() &&
997 !D->isUsed(false) &&
998 !D->isInvalidDecl() &&
999 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +00001000 !D->isTopLevelDeclInObjCContainer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001001 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +00001002 !D->isModulePrivate() &&
Richard Smithd08aeb62014-08-28 01:33:39 +00001003 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001004 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
1005 !D->hasExtInfo() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +00001006 D->getFirstDecl() == D->getMostRecentDecl() &&
Richard Smith7b76d812016-08-12 02:21:25 +00001007 D->getKind() == Decl::Var &&
Richard Smith62f19e72016-06-25 00:15:56 +00001008 !D->isInline() &&
Douglas Gregor12cda632012-09-20 23:43:29 +00001009 !D->isConstexpr() &&
Richard Smithbb13c9a2013-09-28 04:02:39 +00001010 !D->isInitCapture() &&
Richard Smith1c34fb72013-08-13 18:18:50 +00001011 !D->isPreviousDeclInSameBlockScope() &&
Akira Hatanaka9978da32018-08-10 15:09:24 +00001012 !(D->hasAttr<BlocksAttr>() && D->getType()->getAsCXXRecordDecl()) &&
Akira Hatanaka8e57b072018-10-01 21:51:28 +00001013 !D->isEscapingByref() &&
Richard Smitha4653622017-09-06 20:01:14 +00001014 D->getStorageDuration() != SD_Static &&
Larisse Voufod8dd97c2013-08-14 03:09:19 +00001015 !D->getMemberSpecializationInfo())
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001016 AbbrevToUse = Writer.getDeclVarAbbrev();
1017
Sebastian Redl539c5062010-08-18 23:57:32 +00001018 Code = serialization::DECL_VAR;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001019}
1020
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001021void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001022 VisitVarDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001023 Code = serialization::DECL_IMPLICIT_PARAM;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001024}
1025
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001026void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001027 VisitVarDecl(D);
John McCall82490832011-05-02 00:30:12 +00001028 Record.push_back(D->isObjCMethodParameter());
John McCall8fb0d9d2011-05-01 22:35:37 +00001029 Record.push_back(D->getFunctionScopeDepth());
1030 Record.push_back(D->getFunctionScopeIndex());
Chris Lattner7099dbc2009-04-27 06:16:06 +00001031 Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding
John McCall6a014d52011-03-09 04:22:44 +00001032 Record.push_back(D->isKNRPromoted());
John McCallf3cd6652010-03-12 18:31:32 +00001033 Record.push_back(D->hasInheritedDefaultArg());
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +00001034 Record.push_back(D->hasUninstantiatedDefaultArg());
1035 if (D->hasUninstantiatedDefaultArg())
Richard Smith290d8012016-04-06 17:06:00 +00001036 Record.AddStmt(D->getUninstantiatedDefaultArg());
Sebastian Redl539c5062010-08-18 23:57:32 +00001037 Code = serialization::DECL_PARM_VAR;
Mike Stump11289f42009-09-09 15:08:12 +00001038
John McCalld4631322011-06-17 06:42:21 +00001039 assert(!D->isARCPseudoStrong()); // can be true of ImplicitParamDecl
1040
Chris Lattner258172e2009-04-27 07:35:58 +00001041 // If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here
1042 // we dynamically check for the properties that we optimize for, but don't
1043 // know are true of all PARM_VAR_DECLs.
Richard Smith8aed4222015-12-11 22:41:00 +00001044 if (D->getDeclContext() == D->getLexicalDeclContext() &&
1045 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001046 !D->hasExtInfo() &&
Chris Lattner258172e2009-04-27 07:35:58 +00001047 !D->isImplicit() &&
Douglas Gregorebada0772010-06-17 23:14:26 +00001048 !D->isUsed(false) &&
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001049 !D->isInvalidDecl() &&
Eli Friedmanc09e0552012-01-13 23:41:25 +00001050 !D->isReferenced() &&
Chris Lattner258172e2009-04-27 07:35:58 +00001051 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +00001052 !D->isModulePrivate() &&
Chris Lattner258172e2009-04-27 07:35:58 +00001053 D->getStorageClass() == 0 &&
Sebastian Redla9351792012-02-11 23:51:47 +00001054 D->getInitStyle() == VarDecl::CInit && // Can params have anything else?
John McCall82490832011-05-02 00:30:12 +00001055 D->getFunctionScopeDepth() == 0 &&
John McCallf3cd6652010-03-12 18:31:32 +00001056 D->getObjCDeclQualifier() == 0 &&
John McCall6a014d52011-03-09 04:22:44 +00001057 !D->isKNRPromoted() &&
Chris Lattnere2437f42010-05-09 06:40:08 +00001058 !D->hasInheritedDefaultArg() &&
Craig Toppera13603a2014-05-22 05:54:18 +00001059 D->getInit() == nullptr &&
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +00001060 !D->hasUninstantiatedDefaultArg()) // No default expr.
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001061 AbbrevToUse = Writer.getDeclParmVarAbbrev();
Chris Lattner258172e2009-04-27 07:35:58 +00001062
1063 // Check things we know are true of *every* PARM_VAR_DECL, which is more than
1064 // just us assuming it.
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +00001065 assert(!D->getTSCSpec() && "PARM_VAR_DECL can't use TLS");
Richard Smithedbc6e92016-10-14 21:41:24 +00001066 assert(!D->isThisDeclarationADemotedDefinition()
1067 && "PARM_VAR_DECL can't be demoted definition.");
Chris Lattner258172e2009-04-27 07:35:58 +00001068 assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private");
Douglas Gregor3f324d562010-05-03 18:51:14 +00001069 assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var");
Craig Toppera13603a2014-05-22 05:54:18 +00001070 assert(D->getPreviousDecl() == nullptr && "PARM_VAR_DECL can't be redecl");
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001071 assert(!D->isStaticDataMember() &&
1072 "PARM_VAR_DECL can't be static data member");
Chris Lattner7099dbc2009-04-27 06:16:06 +00001073}
1074
Richard Smith7b76d812016-08-12 02:21:25 +00001075void ASTDeclWriter::VisitDecompositionDecl(DecompositionDecl *D) {
1076 // Record the number of bindings first to simplify deserialization.
1077 Record.push_back(D->bindings().size());
1078
1079 VisitVarDecl(D);
1080 for (auto *B : D->bindings())
1081 Record.AddDeclRef(B);
1082 Code = serialization::DECL_DECOMPOSITION;
1083}
1084
1085void ASTDeclWriter::VisitBindingDecl(BindingDecl *D) {
1086 VisitValueDecl(D);
1087 Record.AddStmt(D->getBinding());
1088 Code = serialization::DECL_BINDING;
1089}
1090
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001091void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001092 VisitDecl(D);
Richard Smith290d8012016-04-06 17:06:00 +00001093 Record.AddStmt(D->getAsmString());
Richard Smith69c82bf2016-04-01 22:52:03 +00001094 Record.AddSourceLocation(D->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001095 Code = serialization::DECL_FILE_SCOPE_ASM;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001096}
1097
Michael Han84324352013-02-22 17:15:32 +00001098void ASTDeclWriter::VisitEmptyDecl(EmptyDecl *D) {
1099 VisitDecl(D);
1100 Code = serialization::DECL_EMPTY;
1101}
1102
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001103void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001104 VisitDecl(D);
Richard Smith290d8012016-04-06 17:06:00 +00001105 Record.AddStmt(D->getBody());
Richard Smith69c82bf2016-04-01 22:52:03 +00001106 Record.AddTypeSourceInfo(D->getSignatureAsWritten());
Chris Lattner7099dbc2009-04-27 06:16:06 +00001107 Record.push_back(D->param_size());
David Majnemera3debed2016-06-24 05:33:44 +00001108 for (ParmVarDecl *P : D->parameters())
1109 Record.AddDeclRef(P);
John McCallcf6ce282012-04-13 17:33:29 +00001110 Record.push_back(D->isVariadic());
1111 Record.push_back(D->blockMissingReturnType());
1112 Record.push_back(D->isConversionFromLambda());
Akira Hatanakadb49a1f2018-08-01 23:51:53 +00001113 Record.push_back(D->doesNotEscape());
Akira Hatanakac5792aa2019-02-27 18:17:16 +00001114 Record.push_back(D->canAvoidCopyToHeap());
John McCallc63de662011-02-02 13:00:07 +00001115 Record.push_back(D->capturesCXXThis());
John McCall351762c2011-02-07 10:33:21 +00001116 Record.push_back(D->getNumCaptures());
Aaron Ballman9371dd22014-03-14 18:34:04 +00001117 for (const auto &capture : D->captures()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001118 Record.AddDeclRef(capture.getVariable());
John McCall351762c2011-02-07 10:33:21 +00001119
1120 unsigned flags = 0;
1121 if (capture.isByRef()) flags |= 1;
1122 if (capture.isNested()) flags |= 2;
1123 if (capture.hasCopyExpr()) flags |= 4;
1124 Record.push_back(flags);
1125
Richard Smith290d8012016-04-06 17:06:00 +00001126 if (capture.hasCopyExpr()) Record.AddStmt(capture.getCopyExpr());
John McCall351762c2011-02-07 10:33:21 +00001127 }
John McCallc63de662011-02-02 13:00:07 +00001128
Sebastian Redl539c5062010-08-18 23:57:32 +00001129 Code = serialization::DECL_BLOCK;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001130}
1131
Ben Langmuirce914fc2013-05-03 19:20:19 +00001132void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) {
1133 Record.push_back(CD->getNumParams());
1134 VisitDecl(CD);
Alexey Bataev9959db52014-05-06 10:08:46 +00001135 Record.push_back(CD->getContextParamPosition());
1136 Record.push_back(CD->isNothrow() ? 1 : 0);
Ben Langmuirce914fc2013-05-03 19:20:19 +00001137 // Body is stored by VisitCapturedStmt.
Alexey Bataev9959db52014-05-06 10:08:46 +00001138 for (unsigned I = 0; I < CD->getNumParams(); ++I)
Richard Smith69c82bf2016-04-01 22:52:03 +00001139 Record.AddDeclRef(CD->getParam(I));
Ben Langmuirce914fc2013-05-03 19:20:19 +00001140 Code = serialization::DECL_CAPTURED;
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001141}
1142
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001143void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001144 VisitDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001145 Record.push_back(D->getLanguage());
Richard Smith69c82bf2016-04-01 22:52:03 +00001146 Record.AddSourceLocation(D->getExternLoc());
1147 Record.AddSourceLocation(D->getRBraceLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001148 Code = serialization::DECL_LINKAGE_SPEC;
Chris Lattnerca025db2010-05-07 21:43:38 +00001149}
1150
Richard Smith8df390f2016-09-08 23:14:54 +00001151void ASTDeclWriter::VisitExportDecl(ExportDecl *D) {
1152 VisitDecl(D);
1153 Record.AddSourceLocation(D->getRBraceLoc());
1154 Code = serialization::DECL_EXPORT;
1155}
1156
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001157void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) {
1158 VisitNamedDecl(D);
Stephen Kellyf2ceec42018-08-09 21:08:08 +00001159 Record.AddSourceLocation(D->getBeginLoc());
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001160 Code = serialization::DECL_LABEL;
1161}
1162
1163
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001164void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
Douglas Gregore57e7522012-01-07 09:11:48 +00001165 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001166 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +00001167 Record.push_back(D->isInline());
Stephen Kellyf2ceec42018-08-09 21:08:08 +00001168 Record.AddSourceLocation(D->getBeginLoc());
Richard Smith69c82bf2016-04-01 22:52:03 +00001169 Record.AddSourceLocation(D->getRBraceLoc());
Chris Lattnerca025db2010-05-07 21:43:38 +00001170
Chris Lattnerca025db2010-05-07 21:43:38 +00001171 if (D->isOriginalNamespace())
Richard Smith69c82bf2016-04-01 22:52:03 +00001172 Record.AddDeclRef(D->getAnonymousNamespace());
Sebastian Redl539c5062010-08-18 23:57:32 +00001173 Code = serialization::DECL_NAMESPACE;
Sebastian Redlf03cdc52010-08-05 21:22:19 +00001174
Fangrui Song6907ce22018-07-30 19:24:48 +00001175 if (Writer.hasChain() && D->isAnonymousNamespace() &&
Douglas Gregorec9fd132012-01-14 16:38:05 +00001176 D == D->getMostRecentDecl()) {
Sebastian Redl010288f2011-04-24 16:28:21 +00001177 // This is a most recent reopening of the anonymous namespace. If its parent
1178 // is in a previous PCH (or is the TU), mark that parent for update, because
1179 // the original namespace always points to the latest re-opening of its
1180 // anonymous namespace.
1181 Decl *Parent = cast<Decl>(
1182 D->getParent()->getRedeclContext()->getPrimaryContext());
Douglas Gregorb3722e22011-09-09 23:01:35 +00001183 if (Parent->isFromASTFile() || isa<TranslationUnitDecl>(Parent)) {
Richard Smith6ef42932014-03-20 21:02:00 +00001184 Writer.DeclUpdates[Parent].push_back(
Aaron Ballman4f45b712014-03-21 15:22:56 +00001185 ASTWriter::DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, D));
Sebastian Redlfa1f3702011-04-24 16:28:13 +00001186 }
1187 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001188}
1189
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001190void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Richard Smithf4634362014-09-03 23:11:22 +00001191 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001192 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001193 Record.AddSourceLocation(D->getNamespaceLoc());
1194 Record.AddSourceLocation(D->getTargetNameLoc());
1195 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1196 Record.AddDeclRef(D->getNamespace());
Sebastian Redl539c5062010-08-18 23:57:32 +00001197 Code = serialization::DECL_NAMESPACE_ALIAS;
Chris Lattnerca025db2010-05-07 21:43:38 +00001198}
1199
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001200void ASTDeclWriter::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001201 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001202 Record.AddSourceLocation(D->getUsingLoc());
1203 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1204 Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
1205 Record.AddDeclRef(D->FirstUsingShadow.getPointer());
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00001206 Record.push_back(D->hasTypename());
Richard Smith69c82bf2016-04-01 22:52:03 +00001207 Record.AddDeclRef(Context.getInstantiatedFromUsingDecl(D));
Sebastian Redl539c5062010-08-18 23:57:32 +00001208 Code = serialization::DECL_USING;
Chris Lattnerca025db2010-05-07 21:43:38 +00001209}
1210
Richard Smith151c4562016-12-20 21:35:28 +00001211void ASTDeclWriter::VisitUsingPackDecl(UsingPackDecl *D) {
1212 Record.push_back(D->NumExpansions);
1213 VisitNamedDecl(D);
1214 Record.AddDeclRef(D->getInstantiatedFromUsingDecl());
1215 for (auto *E : D->expansions())
1216 Record.AddDeclRef(E);
1217 Code = serialization::DECL_USING_PACK;
1218}
1219
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001220void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) {
Richard Smithfd8634a2013-10-23 02:17:46 +00001221 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001222 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001223 Record.AddDeclRef(D->getTargetDecl());
Richard Smitha263c342018-01-06 01:07:05 +00001224 Record.push_back(D->getIdentifierNamespace());
Richard Smith69c82bf2016-04-01 22:52:03 +00001225 Record.AddDeclRef(D->UsingOrNextShadow);
1226 Record.AddDeclRef(Context.getInstantiatedFromUsingShadowDecl(D));
Sebastian Redl539c5062010-08-18 23:57:32 +00001227 Code = serialization::DECL_USING_SHADOW;
Chris Lattnerca025db2010-05-07 21:43:38 +00001228}
1229
Richard Smith5179eb72016-06-28 19:03:57 +00001230void ASTDeclWriter::VisitConstructorUsingShadowDecl(
1231 ConstructorUsingShadowDecl *D) {
1232 VisitUsingShadowDecl(D);
1233 Record.AddDeclRef(D->NominatedBaseClassShadowDecl);
1234 Record.AddDeclRef(D->ConstructedBaseClassShadowDecl);
1235 Record.push_back(D->IsVirtual);
1236 Code = serialization::DECL_CONSTRUCTOR_USING_SHADOW;
1237}
1238
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001239void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001240 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001241 Record.AddSourceLocation(D->getUsingLoc());
1242 Record.AddSourceLocation(D->getNamespaceKeyLocation());
1243 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1244 Record.AddDeclRef(D->getNominatedNamespace());
1245 Record.AddDeclRef(dyn_cast<Decl>(D->getCommonAncestor()));
Sebastian Redl539c5062010-08-18 23:57:32 +00001246 Code = serialization::DECL_USING_DIRECTIVE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001247}
1248
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001249void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001250 VisitValueDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001251 Record.AddSourceLocation(D->getUsingLoc());
1252 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1253 Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
Richard Smith151c4562016-12-20 21:35:28 +00001254 Record.AddSourceLocation(D->getEllipsisLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001255 Code = serialization::DECL_UNRESOLVED_USING_VALUE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001256}
1257
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001258void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001259 UnresolvedUsingTypenameDecl *D) {
1260 VisitTypeDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001261 Record.AddSourceLocation(D->getTypenameLoc());
1262 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
Richard Smith151c4562016-12-20 21:35:28 +00001263 Record.AddSourceLocation(D->getEllipsisLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001264 Code = serialization::DECL_UNRESOLVED_USING_TYPENAME;
Chris Lattnerca025db2010-05-07 21:43:38 +00001265}
1266
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001267void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001268 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001269
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001270 enum {
1271 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1272 };
1273 if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) {
1274 Record.push_back(CXXRecTemplate);
Richard Smith69c82bf2016-04-01 22:52:03 +00001275 Record.AddDeclRef(TemplD);
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001276 } else if (MemberSpecializationInfo *MSInfo
1277 = D->getMemberSpecializationInfo()) {
1278 Record.push_back(CXXRecMemberSpecialization);
Richard Smith69c82bf2016-04-01 22:52:03 +00001279 Record.AddDeclRef(MSInfo->getInstantiatedFrom());
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001280 Record.push_back(MSInfo->getTemplateSpecializationKind());
Richard Smith69c82bf2016-04-01 22:52:03 +00001281 Record.AddSourceLocation(MSInfo->getPointOfInstantiation());
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001282 } else {
1283 Record.push_back(CXXRecNotTemplate);
1284 }
1285
Richard Smithcd45dbc2014-04-19 03:48:30 +00001286 Record.push_back(D->isThisDeclarationADefinition());
1287 if (D->isThisDeclarationADefinition())
Richard Smith69c82bf2016-04-01 22:52:03 +00001288 Record.AddCXXDefinitionData(D);
Richard Smithcd45dbc2014-04-19 03:48:30 +00001289
John McCall6bd2a892013-01-25 22:31:03 +00001290 // Store (what we currently believe to be) the key function to avoid
1291 // deserializing every method so we can compute it.
Erich Keanef92f31c2018-08-01 20:48:16 +00001292 if (D->isCompleteDefinition())
Richard Smith69c82bf2016-04-01 22:52:03 +00001293 Record.AddDeclRef(Context.getCurrentKeyFunction(D));
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001294
Sebastian Redl539c5062010-08-18 23:57:32 +00001295 Code = serialization::DECL_CXX_RECORD;
Chris Lattnerca025db2010-05-07 21:43:38 +00001296}
1297
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001298void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001299 VisitFunctionDecl(D);
Argyrios Kyrtzidis3b1a7792012-10-12 05:31:40 +00001300 if (D->isCanonicalDecl()) {
1301 Record.push_back(D->size_overridden_methods());
Benjamin Krameracfa3392017-12-17 23:52:45 +00001302 for (const CXXMethodDecl *MD : D->overridden_methods())
1303 Record.AddDeclRef(MD);
Argyrios Kyrtzidis3b1a7792012-10-12 05:31:40 +00001304 } else {
1305 // We only need to record overridden methods once for the canonical decl.
1306 Record.push_back(0);
1307 }
Richard Smith01b2cb42014-07-26 06:37:51 +00001308
Richard Smith8aed4222015-12-11 22:41:00 +00001309 if (D->getDeclContext() == D->getLexicalDeclContext() &&
1310 D->getFirstDecl() == D->getMostRecentDecl() &&
Richard Smith01b2cb42014-07-26 06:37:51 +00001311 !D->isInvalidDecl() &&
1312 !D->hasAttrs() &&
1313 !D->isTopLevelDeclInObjCContainer() &&
1314 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
1315 !D->hasExtInfo() &&
1316 !D->hasInheritedPrototype() &&
1317 D->hasWrittenPrototype())
1318 AbbrevToUse = Writer.getDeclCXXMethodAbbrev();
1319
Sebastian Redl539c5062010-08-18 23:57:32 +00001320 Code = serialization::DECL_CXX_METHOD;
Chris Lattnerca025db2010-05-07 21:43:38 +00001321}
1322
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001323void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Richard Smith5179eb72016-06-28 19:03:57 +00001324 if (auto Inherited = D->getInheritedConstructor()) {
1325 Record.AddDeclRef(Inherited.getShadowDecl());
1326 Record.AddDeclRef(Inherited.getConstructor());
1327 Code = serialization::DECL_CXX_INHERITED_CONSTRUCTOR;
1328 } else {
1329 Code = serialization::DECL_CXX_CONSTRUCTOR;
1330 }
1331
Chris Lattnerca025db2010-05-07 21:43:38 +00001332 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001333
Richard Smith5179eb72016-06-28 19:03:57 +00001334 Code = D->isInheritingConstructor()
1335 ? serialization::DECL_CXX_INHERITED_CONSTRUCTOR
1336 : serialization::DECL_CXX_CONSTRUCTOR;
Chris Lattnerca025db2010-05-07 21:43:38 +00001337}
1338
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001339void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001340 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001341
Richard Smith69c82bf2016-04-01 22:52:03 +00001342 Record.AddDeclRef(D->getOperatorDelete());
Richard Smith5b349582017-10-13 01:55:36 +00001343 if (D->getOperatorDelete())
1344 Record.AddStmt(D->getOperatorDeleteThisArg());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001345
Sebastian Redl539c5062010-08-18 23:57:32 +00001346 Code = serialization::DECL_CXX_DESTRUCTOR;
Chris Lattnerca025db2010-05-07 21:43:38 +00001347}
1348
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001349void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001350 VisitCXXMethodDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001351 Code = serialization::DECL_CXX_CONVERSION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001352}
1353
Douglas Gregorba345522011-12-02 23:23:56 +00001354void ASTDeclWriter::VisitImportDecl(ImportDecl *D) {
1355 VisitDecl(D);
Argyrios Kyrtzidis7b8e5552012-10-03 01:58:45 +00001356 Record.push_back(Writer.getSubmoduleID(D->getImportedModule()));
Douglas Gregorba345522011-12-02 23:23:56 +00001357 ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs();
1358 Record.push_back(!IdentifierLocs.empty());
1359 if (IdentifierLocs.empty()) {
Stephen Kelly1c301dc2018-08-09 21:09:38 +00001360 Record.AddSourceLocation(D->getEndLoc());
Douglas Gregorba345522011-12-02 23:23:56 +00001361 Record.push_back(1);
1362 } else {
1363 for (unsigned I = 0, N = IdentifierLocs.size(); I != N; ++I)
Richard Smith69c82bf2016-04-01 22:52:03 +00001364 Record.AddSourceLocation(IdentifierLocs[I]);
Douglas Gregorba345522011-12-02 23:23:56 +00001365 Record.push_back(IdentifierLocs.size());
1366 }
1367 // Note: the number of source locations must always be the last element in
1368 // the record.
1369 Code = serialization::DECL_IMPORT;
1370}
1371
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001372void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001373 VisitDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001374 Record.AddSourceLocation(D->getColonLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001375 Code = serialization::DECL_ACCESS_SPEC;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001376}
1377
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001378void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) {
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001379 // Record the number of friend type template parameter lists here
1380 // so as to simplify memory allocation during deserialization.
1381 Record.push_back(D->NumTPLists);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001382 VisitDecl(D);
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001383 bool hasFriendDecl = D->Friend.is<NamedDecl*>();
1384 Record.push_back(hasFriendDecl);
1385 if (hasFriendDecl)
Richard Smith69c82bf2016-04-01 22:52:03 +00001386 Record.AddDeclRef(D->getFriendDecl());
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001387 else
Richard Smith69c82bf2016-04-01 22:52:03 +00001388 Record.AddTypeSourceInfo(D->getFriendType());
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001389 for (unsigned i = 0; i < D->NumTPLists; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +00001390 Record.AddTemplateParameterList(D->getFriendTypeTemplateParameterList(i));
1391 Record.AddDeclRef(D->getNextFriend());
John McCall2c2eb122010-10-16 06:59:13 +00001392 Record.push_back(D->UnsupportedFriend);
Richard Smith69c82bf2016-04-01 22:52:03 +00001393 Record.AddSourceLocation(D->FriendLoc);
Sebastian Redl539c5062010-08-18 23:57:32 +00001394 Code = serialization::DECL_FRIEND;
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001395}
1396
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001397void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001398 VisitDecl(D);
1399 Record.push_back(D->getNumTemplateParameters());
1400 for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +00001401 Record.AddTemplateParameterList(D->getTemplateParameterList(i));
Craig Toppera13603a2014-05-22 05:54:18 +00001402 Record.push_back(D->getFriendDecl() != nullptr);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001403 if (D->getFriendDecl())
Richard Smith69c82bf2016-04-01 22:52:03 +00001404 Record.AddDeclRef(D->getFriendDecl());
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001405 else
Richard Smith69c82bf2016-04-01 22:52:03 +00001406 Record.AddTypeSourceInfo(D->getFriendType());
1407 Record.AddSourceLocation(D->getFriendLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001408 Code = serialization::DECL_FRIEND_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001409}
1410
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001411void ASTDeclWriter::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001412 VisitNamedDecl(D);
1413
Richard Smith69c82bf2016-04-01 22:52:03 +00001414 Record.AddDeclRef(D->getTemplatedDecl());
1415 Record.AddTemplateParameterList(D->getTemplateParameters());
Chris Lattnerca025db2010-05-07 21:43:38 +00001416}
1417
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001418void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Douglas Gregor68444de2012-01-14 15:13:49 +00001419 VisitRedeclarable(D);
1420
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001421 // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that
1422 // getCommonPtr() can be used while this is still initializing.
Rafael Espindola8db352d2013-10-17 15:37:26 +00001423 if (D->isFirstDecl()) {
Douglas Gregor074a4092011-12-19 18:19:24 +00001424 // This declaration owns the 'common' pointer, so serialize that data now.
Richard Smith69c82bf2016-04-01 22:52:03 +00001425 Record.AddDeclRef(D->getInstantiatedFromMemberTemplate());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001426 if (D->getInstantiatedFromMemberTemplate())
1427 Record.push_back(D->isMemberSpecialization());
Douglas Gregor074a4092011-12-19 18:19:24 +00001428 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001429
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001430 VisitTemplateDecl(D);
1431 Record.push_back(D->getIdentifierNamespace());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001432}
1433
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001434void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001435 VisitRedeclarableTemplateDecl(D);
1436
Richard Smith509fc852015-02-27 23:05:10 +00001437 if (D->isFirstDecl())
1438 AddTemplateSpecializations(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001439 Code = serialization::DECL_CLASS_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001440}
1441
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001442void ASTDeclWriter::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001443 ClassTemplateSpecializationDecl *D) {
Richard Smithd8a83712015-08-22 01:47:18 +00001444 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1445
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001446 VisitCXXRecordDecl(D);
1447
1448 llvm::PointerUnion<ClassTemplateDecl *,
1449 ClassTemplatePartialSpecializationDecl *> InstFrom
1450 = D->getSpecializedTemplateOrPartial();
Argyrios Kyrtzidisd5553f12011-08-17 21:35:28 +00001451 if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001452 Record.AddDeclRef(InstFromD);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001453 } else {
Richard Smith69c82bf2016-04-01 22:52:03 +00001454 Record.AddDeclRef(InstFrom.get<ClassTemplatePartialSpecializationDecl *>());
1455 Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001456 }
1457
Richard Smith69c82bf2016-04-01 22:52:03 +00001458 Record.AddTemplateArgumentList(&D->getTemplateArgs());
1459 Record.AddSourceLocation(D->getPointOfInstantiation());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001460 Record.push_back(D->getSpecializationKind());
Axel Naumanna31dee22012-10-01 07:34:47 +00001461 Record.push_back(D->isCanonicalDecl());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001462
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001463 if (D->isCanonicalDecl()) {
Fangrui Song6907ce22018-07-30 19:24:48 +00001464 // When reading, we'll add it to the folding set of the following template.
Richard Smith69c82bf2016-04-01 22:52:03 +00001465 Record.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl());
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001466 }
1467
Richard Smithd55889a2013-09-09 16:55:27 +00001468 // Explicit info.
Richard Smith69c82bf2016-04-01 22:52:03 +00001469 Record.AddTypeSourceInfo(D->getTypeAsWritten());
Richard Smithd55889a2013-09-09 16:55:27 +00001470 if (D->getTypeAsWritten()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001471 Record.AddSourceLocation(D->getExternLoc());
1472 Record.AddSourceLocation(D->getTemplateKeywordLoc());
Richard Smithd55889a2013-09-09 16:55:27 +00001473 }
1474
Sebastian Redl539c5062010-08-18 23:57:32 +00001475 Code = serialization::DECL_CLASS_TEMPLATE_SPECIALIZATION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001476}
1477
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001478void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001479 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001480 VisitClassTemplateSpecializationDecl(D);
1481
Richard Smith69c82bf2016-04-01 22:52:03 +00001482 Record.AddTemplateParameterList(D->getTemplateParameters());
1483 Record.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001484
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001485 // These are read/set from/to the first declaration.
Craig Toppera13603a2014-05-22 05:54:18 +00001486 if (D->getPreviousDecl() == nullptr) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001487 Record.AddDeclRef(D->getInstantiatedFromMember());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001488 Record.push_back(D->isMemberSpecialization());
1489 }
1490
Sebastian Redl539c5062010-08-18 23:57:32 +00001491 Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001492}
1493
Larisse Voufo39a1e502013-08-06 01:03:05 +00001494void ASTDeclWriter::VisitVarTemplateDecl(VarTemplateDecl *D) {
1495 VisitRedeclarableTemplateDecl(D);
1496
Richard Smith509fc852015-02-27 23:05:10 +00001497 if (D->isFirstDecl())
1498 AddTemplateSpecializations(D);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001499 Code = serialization::DECL_VAR_TEMPLATE;
1500}
1501
1502void ASTDeclWriter::VisitVarTemplateSpecializationDecl(
1503 VarTemplateSpecializationDecl *D) {
Richard Smithd8a83712015-08-22 01:47:18 +00001504 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1505
Larisse Voufo39a1e502013-08-06 01:03:05 +00001506 VisitVarDecl(D);
1507
1508 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
1509 InstFrom = D->getSpecializedTemplateOrPartial();
1510 if (Decl *InstFromD = InstFrom.dyn_cast<VarTemplateDecl *>()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001511 Record.AddDeclRef(InstFromD);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001512 } else {
Richard Smith69c82bf2016-04-01 22:52:03 +00001513 Record.AddDeclRef(InstFrom.get<VarTemplatePartialSpecializationDecl *>());
1514 Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001515 }
1516
1517 // Explicit info.
Richard Smith69c82bf2016-04-01 22:52:03 +00001518 Record.AddTypeSourceInfo(D->getTypeAsWritten());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001519 if (D->getTypeAsWritten()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001520 Record.AddSourceLocation(D->getExternLoc());
1521 Record.AddSourceLocation(D->getTemplateKeywordLoc());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001522 }
1523
Richard Smith69c82bf2016-04-01 22:52:03 +00001524 Record.AddTemplateArgumentList(&D->getTemplateArgs());
1525 Record.AddSourceLocation(D->getPointOfInstantiation());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001526 Record.push_back(D->getSpecializationKind());
Richard Smith435e6472017-12-02 02:48:42 +00001527 Record.push_back(D->IsCompleteDefinition);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001528 Record.push_back(D->isCanonicalDecl());
1529
1530 if (D->isCanonicalDecl()) {
1531 // When reading, we'll add it to the folding set of the following template.
Richard Smith69c82bf2016-04-01 22:52:03 +00001532 Record.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001533 }
1534
1535 Code = serialization::DECL_VAR_TEMPLATE_SPECIALIZATION;
1536}
1537
1538void ASTDeclWriter::VisitVarTemplatePartialSpecializationDecl(
1539 VarTemplatePartialSpecializationDecl *D) {
1540 VisitVarTemplateSpecializationDecl(D);
1541
Richard Smith69c82bf2016-04-01 22:52:03 +00001542 Record.AddTemplateParameterList(D->getTemplateParameters());
1543 Record.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001544
1545 // These are read/set from/to the first declaration.
Craig Toppera13603a2014-05-22 05:54:18 +00001546 if (D->getPreviousDecl() == nullptr) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001547 Record.AddDeclRef(D->getInstantiatedFromMember());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001548 Record.push_back(D->isMemberSpecialization());
1549 }
1550
1551 Code = serialization::DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION;
1552}
1553
Fariborz Jahanian3a039e32011-08-27 20:50:59 +00001554void ASTDeclWriter::VisitClassScopeFunctionSpecializationDecl(
1555 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichet09af8c32011-08-17 01:06:54 +00001556 VisitDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001557 Record.AddDeclRef(D->getSpecialization());
Francois Pichet09af8c32011-08-17 01:06:54 +00001558 Code = serialization::DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION;
1559}
1560
1561
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001562void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001563 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001564
Richard Smith509fc852015-02-27 23:05:10 +00001565 if (D->isFirstDecl())
1566 AddTemplateSpecializations(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001567 Code = serialization::DECL_FUNCTION_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001568}
1569
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001570void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001571 VisitTypeDecl(D);
1572
1573 Record.push_back(D->wasDeclaredWithTypename());
Richard Smith8346e522015-06-10 01:47:58 +00001574
1575 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1576 !D->defaultArgumentWasInherited();
1577 Record.push_back(OwnsDefaultArg);
1578 if (OwnsDefaultArg)
Richard Smith69c82bf2016-04-01 22:52:03 +00001579 Record.AddTypeSourceInfo(D->getDefaultArgumentInfo());
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001580
Sebastian Redl539c5062010-08-18 23:57:32 +00001581 Code = serialization::DECL_TEMPLATE_TYPE_PARM;
Chris Lattnerca025db2010-05-07 21:43:38 +00001582}
1583
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001584void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001585 // For an expanded parameter pack, record the number of expansion types here
Richard Smith1fde8ec2012-09-07 02:06:42 +00001586 // so that it's easier for deserialization to allocate the right amount of
1587 // memory.
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001588 if (D->isExpandedParameterPack())
1589 Record.push_back(D->getNumExpansionTypes());
Fangrui Song6907ce22018-07-30 19:24:48 +00001590
John McCallf4cd4f92011-02-09 01:13:10 +00001591 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001592 // TemplateParmPosition.
1593 Record.push_back(D->getDepth());
1594 Record.push_back(D->getPosition());
Fangrui Song6907ce22018-07-30 19:24:48 +00001595
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001596 if (D->isExpandedParameterPack()) {
1597 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001598 Record.AddTypeRef(D->getExpansionType(I));
1599 Record.AddTypeSourceInfo(D->getExpansionTypeSourceInfo(I));
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001600 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001601
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001602 Code = serialization::DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK;
1603 } else {
1604 // Rest of NonTypeTemplateParmDecl.
1605 Record.push_back(D->isParameterPack());
Richard Smith8346e522015-06-10 01:47:58 +00001606 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1607 !D->defaultArgumentWasInherited();
1608 Record.push_back(OwnsDefaultArg);
1609 if (OwnsDefaultArg)
Richard Smith290d8012016-04-06 17:06:00 +00001610 Record.AddStmt(D->getDefaultArgument());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001611 Code = serialization::DECL_NON_TYPE_TEMPLATE_PARM;
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001612 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001613}
1614
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001615void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Richard Smith1fde8ec2012-09-07 02:06:42 +00001616 // For an expanded parameter pack, record the number of expansion types here
1617 // so that it's easier for deserialization to allocate the right amount of
1618 // memory.
1619 if (D->isExpandedParameterPack())
1620 Record.push_back(D->getNumExpansionTemplateParameters());
1621
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001622 VisitTemplateDecl(D);
1623 // TemplateParmPosition.
1624 Record.push_back(D->getDepth());
1625 Record.push_back(D->getPosition());
Richard Smith1fde8ec2012-09-07 02:06:42 +00001626
1627 if (D->isExpandedParameterPack()) {
1628 for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
1629 I != N; ++I)
Richard Smith69c82bf2016-04-01 22:52:03 +00001630 Record.AddTemplateParameterList(D->getExpansionTemplateParameters(I));
Richard Smith1fde8ec2012-09-07 02:06:42 +00001631 Code = serialization::DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK;
1632 } else {
1633 // Rest of TemplateTemplateParmDecl.
Richard Smith1fde8ec2012-09-07 02:06:42 +00001634 Record.push_back(D->isParameterPack());
Richard Smith8346e522015-06-10 01:47:58 +00001635 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1636 !D->defaultArgumentWasInherited();
1637 Record.push_back(OwnsDefaultArg);
1638 if (OwnsDefaultArg)
Richard Smith69c82bf2016-04-01 22:52:03 +00001639 Record.AddTemplateArgumentLoc(D->getDefaultArgument());
Richard Smith1fde8ec2012-09-07 02:06:42 +00001640 Code = serialization::DECL_TEMPLATE_TEMPLATE_PARM;
1641 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001642}
1643
Richard Smith3f1b5d02011-05-05 21:57:07 +00001644void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1645 VisitRedeclarableTemplateDecl(D);
1646 Code = serialization::DECL_TYPE_ALIAS_TEMPLATE;
1647}
1648
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001649void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001650 VisitDecl(D);
Richard Smith290d8012016-04-06 17:06:00 +00001651 Record.AddStmt(D->getAssertExpr());
Richard Smithded9c2e2012-07-11 22:37:56 +00001652 Record.push_back(D->isFailed());
Richard Smith290d8012016-04-06 17:06:00 +00001653 Record.AddStmt(D->getMessage());
Richard Smith69c82bf2016-04-01 22:52:03 +00001654 Record.AddSourceLocation(D->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001655 Code = serialization::DECL_STATIC_ASSERT;
Chris Lattnerca025db2010-05-07 21:43:38 +00001656}
1657
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001658/// Emit the DeclContext part of a declaration context decl.
Richard Smithf1c23dc2016-04-13 02:12:03 +00001659void ASTDeclWriter::VisitDeclContext(DeclContext *DC) {
1660 Record.AddOffset(Writer.WriteDeclContextLexicalBlock(Context, DC));
1661 Record.AddOffset(Writer.WriteDeclContextVisibleBlock(Context, DC));
Chris Lattner7099dbc2009-04-27 06:16:06 +00001662}
1663
Richard Smithd8a83712015-08-22 01:47:18 +00001664const Decl *ASTWriter::getFirstLocalDecl(const Decl *D) {
Richard Smith3864be72015-09-11 02:22:03 +00001665 assert(IsLocalDecl(D) && "expected a local declaration");
Richard Smithd8a83712015-08-22 01:47:18 +00001666
1667 const Decl *Canon = D->getCanonicalDecl();
Richard Smith3864be72015-09-11 02:22:03 +00001668 if (IsLocalDecl(Canon))
Richard Smithd8a83712015-08-22 01:47:18 +00001669 return Canon;
1670
1671 const Decl *&CacheEntry = FirstLocalDeclCache[Canon];
1672 if (CacheEntry)
1673 return CacheEntry;
1674
1675 for (const Decl *Redecl = D; Redecl; Redecl = Redecl->getPreviousDecl())
Richard Smith3864be72015-09-11 02:22:03 +00001676 if (IsLocalDecl(Redecl))
Richard Smithd8a83712015-08-22 01:47:18 +00001677 D = Redecl;
1678 return CacheEntry = D;
Richard Smith5fc18a92015-07-12 23:43:21 +00001679}
1680
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001681template <typename T>
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001682void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +00001683 T *First = D->getFirstDecl();
Richard Smith5a4737c2015-02-06 02:42:59 +00001684 T *MostRecent = First->getMostRecentDecl();
Richard Smithd8a83712015-08-22 01:47:18 +00001685 T *DAsT = static_cast<T *>(D);
Richard Smith5a4737c2015-02-06 02:42:59 +00001686 if (MostRecent != First) {
Richard Smithd8a83712015-08-22 01:47:18 +00001687 assert(isRedeclarableDeclKind(DAsT->getKind()) &&
Douglas Gregorfe732d52013-01-21 16:16:40 +00001688 "Not considered redeclarable?");
Richard Smith5a4737c2015-02-06 02:42:59 +00001689
Richard Smith69c82bf2016-04-01 22:52:03 +00001690 Record.AddDeclRef(First);
Richard Smithfe620d22015-03-05 23:24:12 +00001691
Richard Smithd8a83712015-08-22 01:47:18 +00001692 // Write out a list of local redeclarations of this declaration if it's the
1693 // first local declaration in the chain.
1694 const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1695 if (DAsT == FirstLocal) {
Richard Smithd8a83712015-08-22 01:47:18 +00001696 // Emit a list of all imported first declarations so that we can be sure
1697 // that all redeclarations visible to this module are before D in the
1698 // redecl chain.
1699 unsigned I = Record.size();
1700 Record.push_back(0);
1701 if (Writer.Chain)
1702 AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1703 // This is the number of imported first declarations + 1.
1704 Record[I] = Record.size() - I;
Richard Smithd61d4ac2015-08-22 20:13:39 +00001705
1706 // Collect the set of local redeclarations of this declaration, from
1707 // newest to oldest.
Richard Smith69c82bf2016-04-01 22:52:03 +00001708 ASTWriter::RecordData LocalRedecls;
1709 ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls);
Richard Smithd61d4ac2015-08-22 20:13:39 +00001710 for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1711 Prev != FirstLocal; Prev = Prev->getPreviousDecl())
1712 if (!Prev->isFromASTFile())
Richard Smith69c82bf2016-04-01 22:52:03 +00001713 LocalRedeclWriter.AddDeclRef(Prev);
Richard Smithd61d4ac2015-08-22 20:13:39 +00001714
1715 // If we have any redecls, write them now as a separate record preceding
1716 // the declaration itself.
1717 if (LocalRedecls.empty())
1718 Record.push_back(0);
Richard Smithf1c23dc2016-04-13 02:12:03 +00001719 else
1720 Record.AddOffset(LocalRedeclWriter.Emit(LOCAL_REDECLARATIONS));
Richard Smithd8a83712015-08-22 01:47:18 +00001721 } else {
1722 Record.push_back(0);
Richard Smith69c82bf2016-04-01 22:52:03 +00001723 Record.AddDeclRef(FirstLocal);
Richard Smithfe620d22015-03-05 23:24:12 +00001724 }
Douglas Gregor358cd442012-01-15 16:58:34 +00001725
Fangrui Song6907ce22018-07-30 19:24:48 +00001726 // Make sure that we serialize both the previous and the most-recent
Douglas Gregor358cd442012-01-15 16:58:34 +00001727 // declarations, which (transitively) ensures that all declarations in the
1728 // chain get serialized.
Richard Smith5a4737c2015-02-06 02:42:59 +00001729 //
1730 // FIXME: This is not correct; when we reach an imported declaration we
1731 // won't emit its previous declaration.
Richard Smith5fc18a92015-07-12 23:43:21 +00001732 (void)Writer.GetDeclRef(D->getPreviousDecl());
Richard Smith5a4737c2015-02-06 02:42:59 +00001733 (void)Writer.GetDeclRef(MostRecent);
Douglas Gregor358cd442012-01-15 16:58:34 +00001734 } else {
1735 // We use the sentinel value 0 to indicate an only declaration.
1736 Record.push_back(0);
Douglas Gregor9f562c82011-12-19 15:27:36 +00001737 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001738}
Chris Lattner7099dbc2009-04-27 06:16:06 +00001739
Alexey Bataeva769e072013-03-22 06:34:35 +00001740void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
1741 Record.push_back(D->varlist_size());
1742 VisitDecl(D);
Aaron Ballman2205d2a2014-03-14 15:55:35 +00001743 for (auto *I : D->varlists())
Richard Smith290d8012016-04-06 17:06:00 +00001744 Record.AddStmt(I);
Alexey Bataeva769e072013-03-22 06:34:35 +00001745 Code = serialization::DECL_OMP_THREADPRIVATE;
1746}
1747
Alexey Bataev25ed0c02019-03-07 17:54:44 +00001748void ASTDeclWriter::VisitOMPAllocateDecl(OMPAllocateDecl *D) {
1749 Record.push_back(D->varlist_size());
1750 VisitDecl(D);
1751 for (auto *I : D->varlists())
1752 Record.AddStmt(I);
1753 Code = serialization::DECL_OMP_ALLOCATE;
1754}
1755
Kelvin Li1408f912018-09-26 04:28:39 +00001756void ASTDeclWriter::VisitOMPRequiresDecl(OMPRequiresDecl *D) {
1757 Record.push_back(D->clauselist_size());
1758 VisitDecl(D);
Alexey Bataev25ed0c02019-03-07 17:54:44 +00001759 OMPClauseWriter ClauseWriter(Record);
Kelvin Li1408f912018-09-26 04:28:39 +00001760 for (OMPClause *C : D->clauselists())
1761 ClauseWriter.writeClause(C);
1762 Code = serialization::DECL_OMP_REQUIRES;
1763}
1764
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00001765void ASTDeclWriter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
Alexey Bataevc5b1d322016-03-04 09:22:22 +00001766 VisitValueDecl(D);
Stephen Kellyf2ceec42018-08-09 21:08:08 +00001767 Record.AddSourceLocation(D->getBeginLoc());
Alexey Bataeve6aa4692018-09-13 16:54:05 +00001768 Record.AddStmt(D->getCombinerIn());
1769 Record.AddStmt(D->getCombinerOut());
Richard Smith290d8012016-04-06 17:06:00 +00001770 Record.AddStmt(D->getCombiner());
Alexey Bataeve6aa4692018-09-13 16:54:05 +00001771 Record.AddStmt(D->getInitOrig());
1772 Record.AddStmt(D->getInitPriv());
Richard Smith290d8012016-04-06 17:06:00 +00001773 Record.AddStmt(D->getInitializer());
Alexey Bataev070f43a2017-09-06 14:49:58 +00001774 Record.push_back(D->getInitializerKind());
Richard Smith69c82bf2016-04-01 22:52:03 +00001775 Record.AddDeclRef(D->getPrevDeclInScope());
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00001776 Code = serialization::DECL_OMP_DECLARE_REDUCTION;
1777}
1778
Michael Kruse251e1482019-02-01 20:25:04 +00001779void ASTDeclWriter::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) {
1780 Record.push_back(D->clauselist_size());
1781 VisitValueDecl(D);
1782 Record.AddSourceLocation(D->getBeginLoc());
1783 Record.AddStmt(D->getMapperVarRef());
1784 Record.AddDeclarationName(D->getVarName());
1785 Record.AddDeclRef(D->getPrevDeclInScope());
1786 OMPClauseWriter ClauseWriter(Record);
1787 for (OMPClause *C : D->clauselists())
1788 ClauseWriter.writeClause(C);
1789 Code = serialization::DECL_OMP_DECLARE_MAPPER;
1790}
1791
Alexey Bataev4244be22016-02-11 05:35:55 +00001792void ASTDeclWriter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
Alexey Bataev90c228f2016-02-08 09:29:13 +00001793 VisitVarDecl(D);
Alexey Bataev4244be22016-02-11 05:35:55 +00001794 Code = serialization::DECL_OMP_CAPTUREDEXPR;
Alexey Bataev90c228f2016-02-08 09:29:13 +00001795}
1796
Chris Lattner7099dbc2009-04-27 06:16:06 +00001797//===----------------------------------------------------------------------===//
Sebastian Redl55c0ad52010-08-18 23:56:21 +00001798// ASTWriter Implementation
Chris Lattner7099dbc2009-04-27 06:16:06 +00001799//===----------------------------------------------------------------------===//
1800
Richard Smith01b2cb42014-07-26 06:37:51 +00001801void ASTWriter::WriteDeclAbbrevs() {
Chris Lattner258172e2009-04-27 07:35:58 +00001802 using namespace llvm;
Chris Lattner258172e2009-04-27 07:35:58 +00001803
David Blaikieb44f0bf2017-01-04 22:36:43 +00001804 std::shared_ptr<BitCodeAbbrev> Abv;
Douglas Gregor03412ba2011-06-03 02:27:19 +00001805
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001806 // Abbreviation for DECL_FIELD
David Blaikieb44f0bf2017-01-04 22:36:43 +00001807 Abv = std::make_shared<BitCodeAbbrev>();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001808 Abv->Add(BitCodeAbbrevOp(serialization::DECL_FIELD));
1809 // Decl
1810 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001811 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001812 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001813 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1814 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1815 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1816 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001817 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001818 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001819 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001820 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001821 // NamedDecl
1822 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1823 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001824 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001825 // ValueDecl
1826 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1827 // DeclaratorDecl
1828 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1829 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Richard Smithc23d7342018-06-29 20:46:25 +00001830 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001831 // FieldDecl
1832 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
Richard Smith6b8e3c02017-08-28 00:28:14 +00001833 Abv->Add(BitCodeAbbrevOp(0)); // InitStyle
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001834 // Type Source Info
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001835 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1836 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
David Blaikieb44f0bf2017-01-04 22:36:43 +00001837 DeclFieldAbbrev = Stream.EmitAbbrev(std::move(Abv));
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001838
1839 // Abbreviation for DECL_OBJC_IVAR
David Blaikieb44f0bf2017-01-04 22:36:43 +00001840 Abv = std::make_shared<BitCodeAbbrev>();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001841 Abv->Add(BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR));
1842 // Decl
1843 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001844 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001845 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001846 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1847 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1848 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1849 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001850 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001851 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001852 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001853 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001854 // NamedDecl
1855 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1856 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001857 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001858 // ValueDecl
1859 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1860 // DeclaratorDecl
1861 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1862 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Richard Smithc23d7342018-06-29 20:46:25 +00001863 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001864 // FieldDecl
1865 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
Richard Smith6b8e3c02017-08-28 00:28:14 +00001866 Abv->Add(BitCodeAbbrevOp(0)); // InitStyle
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001867 // ObjC Ivar
1868 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl
1869 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize
1870 // Type Source Info
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001871 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1872 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
David Blaikieb44f0bf2017-01-04 22:36:43 +00001873 DeclObjCIvarAbbrev = Stream.EmitAbbrev(std::move(Abv));
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001874
1875 // Abbreviation for DECL_ENUM
David Blaikieb44f0bf2017-01-04 22:36:43 +00001876 Abv = std::make_shared<BitCodeAbbrev>();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001877 Abv->Add(BitCodeAbbrevOp(serialization::DECL_ENUM));
Douglas Gregor3e300102011-10-26 17:53:41 +00001878 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001879 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Chris Lattner258172e2009-04-27 07:35:58 +00001880 // Decl
1881 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001882 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001883 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Chris Lattner258172e2009-04-27 07:35:58 +00001884 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1885 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
Douglas Gregorc9c02ed2009-06-19 23:52:42 +00001886 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +00001887 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001888 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Chris Lattner258172e2009-04-27 07:35:58 +00001889 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001890 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001891 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Douglas Gregor03412ba2011-06-03 02:27:19 +00001892 // NamedDecl
1893 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1894 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001895 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001896 // TypeDecl
1897 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1898 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001899 // TagDecl
1900 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
1901 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
John McCallf937c022011-10-07 06:10:15 +00001902 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001903 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +00001904 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
David Blaikiea8d23ce2013-07-14 01:07:41 +00001905 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001906 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Argyrios Kyrtzidisd798c052016-07-15 18:11:33 +00001907 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Richard Smith70d58502014-08-30 00:04:23 +00001908 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001909 // EnumDecl
1910 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddTypeRef
1911 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IntegerType
1912 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getPromotionType
1913 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumPositiveBits
1914 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumNegativeBits
1915 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScoped
1916 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScopedUsingClassTag
1917 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isFixed
Richard Trieuab4d7302018-07-25 22:52:05 +00001918 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));// ODRHash
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001919 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedMembEnum
1920 // DC
1921 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
1922 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
David Blaikieb44f0bf2017-01-04 22:36:43 +00001923 DeclEnumAbbrev = Stream.EmitAbbrev(std::move(Abv));
Mike Stump11289f42009-09-09 15:08:12 +00001924
Douglas Gregor03412ba2011-06-03 02:27:19 +00001925 // Abbreviation for DECL_RECORD
David Blaikieb44f0bf2017-01-04 22:36:43 +00001926 Abv = std::make_shared<BitCodeAbbrev>();
Douglas Gregor03412ba2011-06-03 02:27:19 +00001927 Abv->Add(BitCodeAbbrevOp(serialization::DECL_RECORD));
Douglas Gregor3e300102011-10-26 17:53:41 +00001928 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001929 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Douglas Gregor03412ba2011-06-03 02:27:19 +00001930 // Decl
1931 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001932 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001933 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Douglas Gregor03412ba2011-06-03 02:27:19 +00001934 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1935 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1936 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1937 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001938 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Douglas Gregor03412ba2011-06-03 02:27:19 +00001939 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001940 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001941 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Douglas Gregor03412ba2011-06-03 02:27:19 +00001942 // NamedDecl
1943 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1944 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001945 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Douglas Gregor03412ba2011-06-03 02:27:19 +00001946 // TypeDecl
1947 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1948 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
Douglas Gregor03412ba2011-06-03 02:27:19 +00001949 // TagDecl
1950 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
1951 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
John McCallf937c022011-10-07 06:10:15 +00001952 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
Douglas Gregor03412ba2011-06-03 02:27:19 +00001953 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +00001954 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
David Blaikiea8d23ce2013-07-14 01:07:41 +00001955 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
Douglas Gregor03412ba2011-06-03 02:27:19 +00001956 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Argyrios Kyrtzidisd798c052016-07-15 18:11:33 +00001957 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Richard Smith70d58502014-08-30 00:04:23 +00001958 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
Douglas Gregor03412ba2011-06-03 02:27:19 +00001959 // RecordDecl
1960 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // FlexibleArrayMember
1961 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // AnonymousStructUnion
1962 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasObjectMember
Fariborz Jahanian78652202013-01-25 23:57:05 +00001963 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasVolatileMember
Akira Hatanaka34fb2642018-03-13 18:58:25 +00001964
1965 // isNonTrivialToPrimitiveDefaultInitialize
1966 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
1967 // isNonTrivialToPrimitiveCopy
1968 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
1969 // isNonTrivialToPrimitiveDestroy
1970 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
Akira Hatanakafcbe17c2018-03-28 21:13:14 +00001971 // isParamDestroyedInCallee
1972 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
Akira Hatanakae6313ac2018-04-09 22:48:22 +00001973 // getArgPassingRestrictions
1974 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2));
Akira Hatanaka34fb2642018-03-13 18:58:25 +00001975
Douglas Gregor03412ba2011-06-03 02:27:19 +00001976 // DC
1977 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
1978 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
David Blaikieb44f0bf2017-01-04 22:36:43 +00001979 DeclRecordAbbrev = Stream.EmitAbbrev(std::move(Abv));
Douglas Gregor03412ba2011-06-03 02:27:19 +00001980
1981 // Abbreviation for DECL_PARM_VAR
David Blaikieb44f0bf2017-01-04 22:36:43 +00001982 Abv = std::make_shared<BitCodeAbbrev>();
Douglas Gregor03412ba2011-06-03 02:27:19 +00001983 Abv->Add(BitCodeAbbrevOp(serialization::DECL_PARM_VAR));
Douglas Gregor3e300102011-10-26 17:53:41 +00001984 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001985 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Douglas Gregor03412ba2011-06-03 02:27:19 +00001986 // Decl
1987 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001988 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001989 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Douglas Gregor03412ba2011-06-03 02:27:19 +00001990 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1991 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1992 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1993 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001994 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Douglas Gregor03412ba2011-06-03 02:27:19 +00001995 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001996 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001997 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Chris Lattner258172e2009-04-27 07:35:58 +00001998 // NamedDecl
1999 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2000 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00002001 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Chris Lattner258172e2009-04-27 07:35:58 +00002002 // ValueDecl
2003 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +00002004 // DeclaratorDecl
Abramo Bagnaradff19302011-03-08 08:55:46 +00002005 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00002006 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Richard Smithc23d7342018-06-29 20:46:25 +00002007 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
Chris Lattner258172e2009-04-27 07:35:58 +00002008 // VarDecl
Vassil Vassilevd1a88132016-10-06 13:04:54 +00002009 Abv->Add(BitCodeAbbrevOp(0)); // SClass
2010 Abv->Add(BitCodeAbbrevOp(0)); // TSCSpec
2011 Abv->Add(BitCodeAbbrevOp(0)); // InitStyle
Erik Pilkington1e368822019-01-04 18:33:06 +00002012 Abv->Add(BitCodeAbbrevOp(0)); // ARCPseudoStrong
Richard Smith88581592013-02-12 05:48:23 +00002013 Abv->Add(BitCodeAbbrevOp(0)); // Linkage
Chris Lattner258172e2009-04-27 07:35:58 +00002014 Abv->Add(BitCodeAbbrevOp(0)); // HasInit
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00002015 Abv->Add(BitCodeAbbrevOp(0)); // HasMemberSpecializationInfo
Chris Lattner258172e2009-04-27 07:35:58 +00002016 // ParmVarDecl
John McCall82490832011-05-02 00:30:12 +00002017 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsObjCMethodParameter
John McCall8fb0d9d2011-05-01 22:35:37 +00002018 Abv->Add(BitCodeAbbrevOp(0)); // ScopeDepth
2019 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex
Chris Lattner258172e2009-04-27 07:35:58 +00002020 Abv->Add(BitCodeAbbrevOp(0)); // ObjCDeclQualifier
John McCall6a014d52011-03-09 04:22:44 +00002021 Abv->Add(BitCodeAbbrevOp(0)); // KNRPromoted
John McCallf3cd6652010-03-12 18:31:32 +00002022 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedDefaultArg
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +00002023 Abv->Add(BitCodeAbbrevOp(0)); // HasUninstantiatedDefaultArg
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002024 // Type Source Info
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002025 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2026 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
David Blaikieb44f0bf2017-01-04 22:36:43 +00002027 DeclParmVarAbbrev = Stream.EmitAbbrev(std::move(Abv));
Sebastian Redl66c5eef2010-07-27 00:17:23 +00002028
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00002029 // Abbreviation for DECL_TYPEDEF
David Blaikieb44f0bf2017-01-04 22:36:43 +00002030 Abv = std::make_shared<BitCodeAbbrev>();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002031 Abv->Add(BitCodeAbbrevOp(serialization::DECL_TYPEDEF));
Douglas Gregor05f10352011-12-17 23:38:30 +00002032 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00002033 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002034 // Decl
2035 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00002036 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00002037 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002038 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
2039 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
Richard Smith01b2cb42014-07-26 06:37:51 +00002040 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isUsed
2041 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00002042 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Richard Smith01b2cb42014-07-26 06:37:51 +00002043 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00002044 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00002045 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002046 // NamedDecl
2047 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2048 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00002049 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002050 // TypeDecl
2051 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2052 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
2053 // TypedefDecl
2054 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2055 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
David Blaikieb44f0bf2017-01-04 22:36:43 +00002056 DeclTypedefAbbrev = Stream.EmitAbbrev(std::move(Abv));
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002057
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00002058 // Abbreviation for DECL_VAR
David Blaikieb44f0bf2017-01-04 22:36:43 +00002059 Abv = std::make_shared<BitCodeAbbrev>();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002060 Abv->Add(BitCodeAbbrevOp(serialization::DECL_VAR));
Douglas Gregor3e300102011-10-26 17:53:41 +00002061 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00002062 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002063 // Decl
2064 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00002065 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00002066 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002067 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
2068 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
2069 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
2070 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00002071 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002072 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00002073 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00002074 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002075 // NamedDecl
2076 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2077 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00002078 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002079 // ValueDecl
2080 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2081 // DeclaratorDecl
2082 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
2083 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Richard Smithc23d7342018-06-29 20:46:25 +00002084 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002085 // VarDecl
Vassil Vassilevd1a88132016-10-06 13:04:54 +00002086 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // SClass
2087 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // TSCSpec
2088 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // InitStyle
Erik Pilkington1e368822019-01-04 18:33:06 +00002089 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong
Richard Smithedbc6e92016-10-14 21:41:24 +00002090 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsThisDeclarationADemotedDefinition
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002091 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isExceptionVariable
Taiju Tsuiki3be68e12018-06-19 05:35:30 +00002092 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isNRVOVariable
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002093 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCXXForRangeDecl
George Karpenkovec38cf72018-03-29 00:56:24 +00002094 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isObjCForDecl
Richard Smith62f19e72016-06-25 00:15:56 +00002095 Abv->Add(BitCodeAbbrevOp(0)); // isInline
2096 Abv->Add(BitCodeAbbrevOp(0)); // isInlineSpecified
Douglas Gregor12cda632012-09-20 23:43:29 +00002097 Abv->Add(BitCodeAbbrevOp(0)); // isConstexpr
Richard Smithbb13c9a2013-09-28 04:02:39 +00002098 Abv->Add(BitCodeAbbrevOp(0)); // isInitCapture
Richard Smith1c34fb72013-08-13 18:18:50 +00002099 Abv->Add(BitCodeAbbrevOp(0)); // isPrevDeclInSameScope
Alexey Bataev56223232017-06-09 13:40:18 +00002100 Abv->Add(BitCodeAbbrevOp(0)); // ImplicitParamKind
Akira Hatanaka8e57b072018-10-01 21:51:28 +00002101 Abv->Add(BitCodeAbbrevOp(0)); // EscapingByref
Rafael Espindola50df3a02013-05-25 17:16:20 +00002102 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
Vassil Vassilevd1a88132016-10-06 13:04:54 +00002103 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // IsInitICE (local)
2104 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // VarKind (local enum)
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002105 // Type Source Info
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002106 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2107 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
David Blaikieb44f0bf2017-01-04 22:36:43 +00002108 DeclVarAbbrev = Stream.EmitAbbrev(std::move(Abv));
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002109
Richard Smith01b2cb42014-07-26 06:37:51 +00002110 // Abbreviation for DECL_CXX_METHOD
David Blaikieb44f0bf2017-01-04 22:36:43 +00002111 Abv = std::make_shared<BitCodeAbbrev>();
Richard Smith01b2cb42014-07-26 06:37:51 +00002112 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CXX_METHOD));
2113 // RedeclarableDecl
2114 Abv->Add(BitCodeAbbrevOp(0)); // CanonicalDecl
2115 // Decl
2116 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00002117 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Richard Smith01b2cb42014-07-26 06:37:51 +00002118 Abv->Add(BitCodeAbbrevOp(0)); // Invalid
2119 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
2120 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Implicit
2121 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Used
2122 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Referenced
2123 Abv->Add(BitCodeAbbrevOp(0)); // InObjCContainer
2124 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Access
2125 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ModulePrivate
2126 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2127 // NamedDecl
2128 Abv->Add(BitCodeAbbrevOp(DeclarationName::Identifier)); // NameKind
2129 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Identifier
Richard Smith2b560572015-02-07 03:11:11 +00002130 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Richard Smith01b2cb42014-07-26 06:37:51 +00002131 // ValueDecl
2132 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2133 // DeclaratorDecl
2134 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerLocStart
2135 Abv->Add(BitCodeAbbrevOp(0)); // HasExtInfo
Richard Smithc23d7342018-06-29 20:46:25 +00002136 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
Richard Smith01b2cb42014-07-26 06:37:51 +00002137 // FunctionDecl
2138 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS
2139 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // StorageClass
2140 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Inline
2141 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InlineSpecified
Richard Smith78e3d702017-02-10 01:32:04 +00002142 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ExplicitSpecified
Richard Smith01b2cb42014-07-26 06:37:51 +00002143 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // VirtualAsWritten
2144 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Pure
2145 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedProto
2146 Abv->Add(BitCodeAbbrevOp(1)); // HasWrittenProto
Richard Smith72625c22015-02-06 23:20:21 +00002147 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Deleted
Richard Smith01b2cb42014-07-26 06:37:51 +00002148 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Trivial
Akira Hatanaka02914dc2018-02-05 20:23:22 +00002149 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // TrivialForCall
Richard Smith01b2cb42014-07-26 06:37:51 +00002150 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Defaulted
2151 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ExplicitlyDefaulted
2152 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ImplicitReturnZero
2153 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Constexpr
Reid Kleckner0d157382017-01-10 21:27:03 +00002154 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // UsesSEHTry
Richard Smith01b2cb42014-07-26 06:37:51 +00002155 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // SkippedBody
Erich Keane281d20b2018-01-08 21:34:17 +00002156 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // MultiVersion
Richard Smith01b2cb42014-07-26 06:37:51 +00002157 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // LateParsed
2158 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
2159 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LocEnd
Richard Trieue6caa262017-12-23 00:41:01 +00002160 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // ODRHash
Richard Smith01b2cb42014-07-26 06:37:51 +00002161 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // TemplateKind
2162 // This Array slurps the rest of the record. Fortunately we want to encode
2163 // (nearly) all the remaining (variable number of) fields in the same way.
2164 //
2165 // This is the function template information if any, then
2166 // NumParams and Params[] from FunctionDecl, and
2167 // NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl.
2168 //
2169 // Add an AbbrevOp for 'size then elements' and use it here.
2170 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2171 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
David Blaikieb44f0bf2017-01-04 22:36:43 +00002172 DeclCXXMethodAbbrev = Stream.EmitAbbrev(std::move(Abv));
Richard Smith01b2cb42014-07-26 06:37:51 +00002173
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00002174 // Abbreviation for EXPR_DECL_REF
David Blaikieb44f0bf2017-01-04 22:36:43 +00002175 Abv = std::make_shared<BitCodeAbbrev>();
Douglas Gregor03412ba2011-06-03 02:27:19 +00002176 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_DECL_REF));
2177 //Stmt
2178 //Expr
2179 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002180 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2181 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2182 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002183 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2184 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2185 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2186 //DeclRefExpr
2187 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HasQualifier
2188 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //GetDeclFound
2189 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ExplicitTemplateArgs
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002190 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HadMultipleCandidates
Alexey Bataev19acc3d2015-01-12 10:17:46 +00002191 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2192 1)); // RefersToEnclosingVariableOrCapture
Douglas Gregor03412ba2011-06-03 02:27:19 +00002193 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef
2194 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
David Blaikieb44f0bf2017-01-04 22:36:43 +00002195 DeclRefExprAbbrev = Stream.EmitAbbrev(std::move(Abv));
Douglas Gregor03412ba2011-06-03 02:27:19 +00002196
2197 // Abbreviation for EXPR_INTEGER_LITERAL
David Blaikieb44f0bf2017-01-04 22:36:43 +00002198 Abv = std::make_shared<BitCodeAbbrev>();
Douglas Gregor03412ba2011-06-03 02:27:19 +00002199 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL));
2200 //Stmt
2201 //Expr
2202 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002203 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2204 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2205 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002206 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2207 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2208 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2209 //Integer Literal
2210 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2211 Abv->Add(BitCodeAbbrevOp(32)); // Bit Width
2212 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value
David Blaikieb44f0bf2017-01-04 22:36:43 +00002213 IntegerLiteralAbbrev = Stream.EmitAbbrev(std::move(Abv));
Douglas Gregor03412ba2011-06-03 02:27:19 +00002214
2215 // Abbreviation for EXPR_CHARACTER_LITERAL
David Blaikieb44f0bf2017-01-04 22:36:43 +00002216 Abv = std::make_shared<BitCodeAbbrev>();
Douglas Gregor03412ba2011-06-03 02:27:19 +00002217 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL));
2218 //Stmt
2219 //Expr
2220 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002221 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2222 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2223 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002224 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2225 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2226 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
Jonathan D. Turnerd09655f2011-06-03 21:46:44 +00002227 //Character Literal
Douglas Gregor03412ba2011-06-03 02:27:19 +00002228 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue
2229 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
Aaron Ballman9a17c852016-01-07 20:59:26 +00002230 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // getKind
David Blaikieb44f0bf2017-01-04 22:36:43 +00002231 CharacterLiteralAbbrev = Stream.EmitAbbrev(std::move(Abv));
Douglas Gregor03412ba2011-06-03 02:27:19 +00002232
Richard Smitha27c26e2014-07-27 04:19:32 +00002233 // Abbreviation for EXPR_IMPLICIT_CAST
David Blaikieb44f0bf2017-01-04 22:36:43 +00002234 Abv = std::make_shared<BitCodeAbbrev>();
Richard Smitha27c26e2014-07-27 04:19:32 +00002235 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_IMPLICIT_CAST));
2236 // Stmt
2237 // Expr
2238 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2239 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2240 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2241 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
2242 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2243 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2244 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2245 // CastExpr
2246 Abv->Add(BitCodeAbbrevOp(0)); // PathSize
2247 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 6)); // CastKind
Roman Lebedevd55661d2018-07-24 08:16:50 +00002248 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // PartOfExplicitCast
Richard Smitha27c26e2014-07-27 04:19:32 +00002249 // ImplicitCastExpr
David Blaikieb44f0bf2017-01-04 22:36:43 +00002250 ExprImplicitCastAbbrev = Stream.EmitAbbrev(std::move(Abv));
Richard Smitha27c26e2014-07-27 04:19:32 +00002251
David Blaikieb44f0bf2017-01-04 22:36:43 +00002252 Abv = std::make_shared<BitCodeAbbrev>();
Sebastian Redl539c5062010-08-18 23:57:32 +00002253 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL));
Sebastian Redl66c5eef2010-07-27 00:17:23 +00002254 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
David Blaikieb44f0bf2017-01-04 22:36:43 +00002255 DeclContextLexicalAbbrev = Stream.EmitAbbrev(std::move(Abv));
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002256
David Blaikieb44f0bf2017-01-04 22:36:43 +00002257 Abv = std::make_shared<BitCodeAbbrev>();
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002258 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE));
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002259 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
David Blaikieb44f0bf2017-01-04 22:36:43 +00002260 DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(std::move(Abv));
Chris Lattner258172e2009-04-27 07:35:58 +00002261}
2262
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002263/// isRequiredDecl - Check if this is a "required" Decl, which must be seen by
2264/// consumers of the AST.
2265///
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002266/// Such decls will always be deserialized from the AST file, so we would like
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002267/// this to be as restrictive as possible. Currently the predicate is driven by
2268/// code generation requirements, if other clients have a different notion of
2269/// what is "required" then we may have to consider an alternate scheme where
2270/// clients can iterate over the top-level decls and get information on them,
2271/// without necessary deserializing them. We could explicitly require such
2272/// clients to use a separate API call to "realize" the decl. This should be
2273/// relatively painless since they would presumably only do it for top-level
2274/// decls.
Richard Smithc52efa72015-08-19 02:30:28 +00002275static bool isRequiredDecl(const Decl *D, ASTContext &Context,
David Blaikiee6b7c282017-04-11 20:46:34 +00002276 bool WritingModule) {
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00002277 // An ObjCMethodDecl is never considered as "required" because its
2278 // implementation container always is.
2279
Dmitry Polukhin0b0da292016-04-06 11:38:59 +00002280 // File scoped assembly or obj-c or OMP declare target implementation must be
2281 // seen.
Alexey Bataevd01b7492018-08-15 19:45:12 +00002282 if (isa<FileScopeAsmDecl>(D) || isa<ObjCImplDecl>(D))
Richard Smithc52efa72015-08-19 02:30:28 +00002283 return true;
2284
Richard Smith520a37f2019-02-05 23:37:13 +00002285 if (WritingModule && isPartOfPerModuleInitializer(D)) {
Richard Smithdc1f0422016-07-20 19:10:16 +00002286 // These declarations are part of the module initializer, and are emitted
2287 // if and when the module is imported, rather than being emitted eagerly.
2288 return false;
2289 }
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002290
David Blaikiee6b7c282017-04-11 20:46:34 +00002291 return Context.DeclMustBeEmitted(D);
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002292}
2293
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002294void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) {
Jordan Rose1e879d82018-03-23 00:07:18 +00002295 PrettyDeclStackTraceEntry CrashInfo(Context, D, SourceLocation(),
2296 "serializing");
2297
Douglas Gregorb3163e52012-01-05 22:33:30 +00002298 // Determine the ID for this declaration.
2299 serialization::DeclID ID;
Douglas Gregor7dd37e52015-11-03 01:20:54 +00002300 assert(!D->isFromASTFile() && "should not be emitting imported decl");
2301 serialization::DeclID &IDR = DeclIDs[D];
2302 if (IDR == 0)
2303 IDR = NextDeclID++;
Fangrui Song6907ce22018-07-30 19:24:48 +00002304
Douglas Gregor7dd37e52015-11-03 01:20:54 +00002305 ID = IDR;
Argyrios Kyrtzidisbf6c3392012-03-22 16:08:04 +00002306
Richard Smith34da7512016-03-27 05:52:25 +00002307 assert(ID >= FirstDeclID && "invalid decl ID");
Fangrui Song6907ce22018-07-30 19:24:48 +00002308
Richard Smith69c82bf2016-04-01 22:52:03 +00002309 RecordData Record;
2310 ASTDeclWriter W(*this, Context, Record);
2311
Richard Smithd61d4ac2015-08-22 20:13:39 +00002312 // Build a record for this declaration
Richard Smithd61d4ac2015-08-22 20:13:39 +00002313 W.Visit(D);
Richard Smithd61d4ac2015-08-22 20:13:39 +00002314
Richard Smith69c82bf2016-04-01 22:52:03 +00002315 // Emit this declaration to the bitstream.
2316 uint64_t Offset = W.Emit(D);
Douglas Gregor12bfa382009-10-17 00:13:19 +00002317
Richard Smith34da7512016-03-27 05:52:25 +00002318 // Record the offset for this declaration
2319 SourceLocation Loc = D->getLocation();
Richard Smith69c82bf2016-04-01 22:52:03 +00002320 unsigned Index = ID - FirstDeclID;
Richard Smith34da7512016-03-27 05:52:25 +00002321 if (DeclOffsets.size() == Index)
Richard Smith69c82bf2016-04-01 22:52:03 +00002322 DeclOffsets.push_back(DeclOffset(Loc, Offset));
Richard Smith34da7512016-03-27 05:52:25 +00002323 else if (DeclOffsets.size() < Index) {
Richard Smith69c82bf2016-04-01 22:52:03 +00002324 // FIXME: Can/should this happen?
Richard Smith34da7512016-03-27 05:52:25 +00002325 DeclOffsets.resize(Index+1);
2326 DeclOffsets[Index].setLocation(Loc);
Richard Smith69c82bf2016-04-01 22:52:03 +00002327 DeclOffsets[Index].BitOffset = Offset;
2328 } else {
2329 llvm_unreachable("declarations should be emitted in ID order");
Douglas Gregor12bfa382009-10-17 00:13:19 +00002330 }
2331
Richard Smith34da7512016-03-27 05:52:25 +00002332 SourceManager &SM = Context.getSourceManager();
2333 if (Loc.isValid() && SM.isLocalSourceLocation(Loc))
2334 associateDeclWithFile(D, ID);
2335
Ben Langmuir332aafe2014-01-31 01:06:56 +00002336 // Note declarations that should be deserialized eagerly so that we can add
2337 // them to a record in the AST file later.
David Blaikiee6b7c282017-04-11 20:46:34 +00002338 if (isRequiredDecl(D, Context, WritingModule))
Ben Langmuir332aafe2014-01-31 01:06:56 +00002339 EagerlyDeserializedDecls.push_back(ID);
Chris Lattner7099dbc2009-04-27 06:16:06 +00002340}
Richard Smithd28ac5b2014-03-22 23:33:22 +00002341
Richard Smith290d8012016-04-06 17:06:00 +00002342void ASTRecordWriter::AddFunctionDefinition(const FunctionDecl *FD) {
2343 // Switch case IDs are per function body.
2344 Writer->ClearSwitchCaseIDs();
Richard Smithd28ac5b2014-03-22 23:33:22 +00002345
Richard Smith290d8012016-04-06 17:06:00 +00002346 assert(FD->doesThisDeclarationHaveABody());
Richard Smithb51cf112017-07-06 00:30:00 +00002347 bool ModulesCodegen = false;
2348 if (Writer->WritingModule && !FD->isDependentContext()) {
David Blaikie08267292017-11-02 21:55:40 +00002349 Optional<GVALinkage> Linkage;
2350 if (Writer->WritingModule->Kind == Module::ModuleInterfaceUnit) {
2351 // When building a C++ Modules TS module interface unit, a strong
2352 // definition in the module interface is provided by the compilation of
2353 // that module interface unit, not by its users. (Inline functions are
2354 // still emitted in module users.)
2355 Linkage = Writer->Context->GetGVALinkageForFunction(FD);
2356 ModulesCodegen = *Linkage == GVA_StrongExternal;
2357 }
2358 if (Writer->Context->getLangOpts().ModulesCodegen) {
2359 // Under -fmodules-codegen, codegen is performed for all non-internal,
2360 // non-always_inline functions.
David Blaikie1524e672017-11-02 22:28:50 +00002361 if (!FD->hasAttr<AlwaysInlineAttr>()) {
2362 if (!Linkage)
2363 Linkage = Writer->Context->GetGVALinkageForFunction(FD);
2364 ModulesCodegen = *Linkage != GVA_Internal;
2365 }
David Blaikie08267292017-11-02 21:55:40 +00002366 }
Richard Smithb51cf112017-07-06 00:30:00 +00002367 }
David Blaikief63556d2017-04-12 20:58:33 +00002368 Record->push_back(ModulesCodegen);
2369 if (ModulesCodegen)
David Blaikiee6b7c282017-04-11 20:46:34 +00002370 Writer->ModularCodegenDecls.push_back(Writer->GetDeclRef(FD));
Richard Smith290d8012016-04-06 17:06:00 +00002371 if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
2372 Record->push_back(CD->getNumCtorInitializers());
2373 if (CD->getNumCtorInitializers())
Richard Smithaa165cf2016-04-13 21:57:08 +00002374 AddCXXCtorInitializers(
Richard Smith290d8012016-04-06 17:06:00 +00002375 llvm::makeArrayRef(CD->init_begin(), CD->init_end()));
2376 }
2377 AddStmt(FD->getBody());
Richard Smithd28ac5b2014-03-22 23:33:22 +00002378}