blob: b615fab245efbd64e337035bd46f66d8d7ab23a7 [file] [log] [blame]
Sebastian Redld6522cf2010-08-18 23:56:31 +00001//===--- ASTWriterDecl.cpp - Declaration Serialization --------------------===//
Chris Lattner7099dbc2009-04-27 06:16:06 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements serialization for Declarations.
11//
12//===----------------------------------------------------------------------===//
13
Sebastian Redlfa1f3702011-04-24 16:28:13 +000014#include "ASTCommon.h"
Chris Lattnerca025db2010-05-07 21:43:38 +000015#include "clang/AST/DeclCXX.h"
Argyrios Kyrtzidis3317d982010-10-20 16:22:56 +000016#include "clang/AST/DeclContextInternals.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "clang/AST/DeclTemplate.h"
18#include "clang/AST/DeclVisitor.h"
19#include "clang/AST/Expr.h"
Jordan Rose1e879d82018-03-23 00:07:18 +000020#include "clang/AST/PrettyDeclStackTrace.h"
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +000021#include "clang/Basic/SourceManager.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000022#include "clang/Serialization/ASTReader.h"
Mehdi Amini9670f842016-07-18 19:02:11 +000023#include "clang/Serialization/ASTWriter.h"
Chris Lattner7099dbc2009-04-27 06:16:06 +000024#include "llvm/Bitcode/BitstreamWriter.h"
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +000025#include "llvm/Support/ErrorHandling.h"
Chris Lattner7099dbc2009-04-27 06:16:06 +000026using namespace clang;
Sebastian Redlfa1f3702011-04-24 16:28:13 +000027using namespace serialization;
Chris Lattner7099dbc2009-04-27 06:16:06 +000028
29//===----------------------------------------------------------------------===//
30// Declaration serialization
31//===----------------------------------------------------------------------===//
32
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000033namespace clang {
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000034 class ASTDeclWriter : public DeclVisitor<ASTDeclWriter, void> {
Sebastian Redl55c0ad52010-08-18 23:56:21 +000035 ASTWriter &Writer;
Chris Lattner7099dbc2009-04-27 06:16:06 +000036 ASTContext &Context;
Richard Smith69c82bf2016-04-01 22:52:03 +000037 ASTRecordWriter Record;
Chris Lattner7099dbc2009-04-27 06:16:06 +000038
Sebastian Redl539c5062010-08-18 23:57:32 +000039 serialization::DeclCode Code;
Chris Lattner258172e2009-04-27 07:35:58 +000040 unsigned AbbrevToUse;
Chris Lattner7099dbc2009-04-27 06:16:06 +000041
Richard Smith69c82bf2016-04-01 22:52:03 +000042 public:
43 ASTDeclWriter(ASTWriter &Writer, ASTContext &Context,
44 ASTWriter::RecordDataImpl &Record)
45 : Writer(Writer), Context(Context), Record(Writer, Record),
46 Code((serialization::DeclCode)0), AbbrevToUse(0) {}
47
48 uint64_t Emit(Decl *D) {
49 if (!Code)
50 llvm::report_fatal_error(StringRef("unexpected declaration kind '") +
51 D->getDeclKindName() + "'");
Richard Smith645d2cf2016-04-14 00:29:55 +000052 return Record.Emit(Code, AbbrevToUse);
Chris Lattner258172e2009-04-27 07:35:58 +000053 }
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000054
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +000055 void Visit(Decl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000056
57 void VisitDecl(Decl *D);
Nico Weber66220292016-03-02 17:28:48 +000058 void VisitPragmaCommentDecl(PragmaCommentDecl *D);
Nico Webercbbaeb12016-03-02 19:28:54 +000059 void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000060 void VisitTranslationUnitDecl(TranslationUnitDecl *D);
61 void VisitNamedDecl(NamedDecl *D);
Chris Lattnerc8e630e2011-02-17 07:39:24 +000062 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregore31bbd92010-02-21 18:22:14 +000063 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000064 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
65 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000066 void VisitTypeDecl(TypeDecl *D);
Douglas Gregor1f179062011-12-19 14:40:25 +000067 void VisitTypedefNameDecl(TypedefNameDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000068 void VisitTypedefDecl(TypedefDecl *D);
Richard Smithdda56e42011-04-15 14:24:37 +000069 void VisitTypeAliasDecl(TypeAliasDecl *D);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000070 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000071 void VisitTagDecl(TagDecl *D);
72 void VisitEnumDecl(EnumDecl *D);
73 void VisitRecordDecl(RecordDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000074 void VisitCXXRecordDecl(CXXRecordDecl *D);
75 void VisitClassTemplateSpecializationDecl(
76 ClassTemplateSpecializationDecl *D);
77 void VisitClassTemplatePartialSpecializationDecl(
78 ClassTemplatePartialSpecializationDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +000079 void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D);
80 void VisitVarTemplatePartialSpecializationDecl(
81 VarTemplatePartialSpecializationDecl *D);
Fariborz Jahanian3a039e32011-08-27 20:50:59 +000082 void VisitClassScopeFunctionSpecializationDecl(
83 ClassScopeFunctionSpecializationDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000084 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000085 void VisitValueDecl(ValueDecl *D);
86 void VisitEnumConstantDecl(EnumConstantDecl *D);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000087 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +000088 void VisitDeclaratorDecl(DeclaratorDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000089 void VisitFunctionDecl(FunctionDecl *D);
Richard Smithbc491202017-02-17 20:05:37 +000090 void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000091 void VisitCXXMethodDecl(CXXMethodDecl *D);
92 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
93 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
94 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000095 void VisitFieldDecl(FieldDecl *D);
John McCall5e77d762013-04-16 07:28:30 +000096 void VisitMSPropertyDecl(MSPropertyDecl *D);
Francois Pichet783dd6e2010-11-21 06:08:52 +000097 void VisitIndirectFieldDecl(IndirectFieldDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000098 void VisitVarDecl(VarDecl *D);
99 void VisitImplicitParamDecl(ImplicitParamDecl *D);
100 void VisitParmVarDecl(ParmVarDecl *D);
Richard Smith7b76d812016-08-12 02:21:25 +0000101 void VisitDecompositionDecl(DecompositionDecl *D);
102 void VisitBindingDecl(BindingDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000103 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
104 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +0000105 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000106 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +0000107 void VisitVarTemplateDecl(VarTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000108 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000109 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3f1b5d02011-05-05 21:57:07 +0000110 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000111 void VisitUsingDecl(UsingDecl *D);
Richard Smith151c4562016-12-20 21:35:28 +0000112 void VisitUsingPackDecl(UsingPackDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000113 void VisitUsingShadowDecl(UsingShadowDecl *D);
Richard Smith5179eb72016-06-28 19:03:57 +0000114 void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000115 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Richard Smith8df390f2016-09-08 23:14:54 +0000116 void VisitExportDecl(ExportDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000117 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
Douglas Gregorba345522011-12-02 23:23:56 +0000118 void VisitImportDecl(ImportDecl *D);
Abramo Bagnarad7340582010-06-05 05:09:32 +0000119 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000120 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000121 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
122 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000123 void VisitBlockDecl(BlockDecl *D);
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +0000124 void VisitCapturedDecl(CapturedDecl *D);
Michael Han84324352013-02-22 17:15:32 +0000125 void VisitEmptyDecl(EmptyDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000126
Richard Smithf1c23dc2016-04-13 02:12:03 +0000127 void VisitDeclContext(DeclContext *DC);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000128 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000129
130
Alexis Hunted053252010-05-30 07:21:58 +0000131 // FIXME: Put in the same order is DeclNodes.td?
Chris Lattner7099dbc2009-04-27 06:16:06 +0000132 void VisitObjCMethodDecl(ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000133 void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000134 void VisitObjCContainerDecl(ObjCContainerDecl *D);
135 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
136 void VisitObjCIvarDecl(ObjCIvarDecl *D);
137 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
138 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000139 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
140 void VisitObjCImplDecl(ObjCImplDecl *D);
141 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
142 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
143 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
144 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
145 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
Alexey Bataeva769e072013-03-22 06:34:35 +0000146 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000147 void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
Alexey Bataev4244be22016-02-11 05:35:55 +0000148 void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
Richard Smithd28ac5b2014-03-22 23:33:22 +0000149
Douglas Gregor85f3f952015-07-07 03:57:15 +0000150 /// Add an Objective-C type parameter list to the given record.
151 void AddObjCTypeParamList(ObjCTypeParamList *typeParams) {
152 // Empty type parameter list.
153 if (!typeParams) {
154 Record.push_back(0);
155 return;
156 }
157
158 Record.push_back(typeParams->size());
159 for (auto typeParam : *typeParams) {
Richard Smith69c82bf2016-04-01 22:52:03 +0000160 Record.AddDeclRef(typeParam);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000161 }
Richard Smith69c82bf2016-04-01 22:52:03 +0000162 Record.AddSourceLocation(typeParams->getLAngleLoc());
163 Record.AddSourceLocation(typeParams->getRAngleLoc());
Douglas Gregor85f3f952015-07-07 03:57:15 +0000164 }
165
Richard Smithd8a83712015-08-22 01:47:18 +0000166 /// Add to the record the first declaration from each module file that
167 /// provides a declaration of D. The intent is to provide a sufficient
168 /// set such that reloading this set will load all current redeclarations.
169 void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) {
170 llvm::MapVector<ModuleFile*, const Decl*> Firsts;
171 // FIXME: We can skip entries that we know are implied by others.
Richard Smith5f55d932015-08-27 21:38:25 +0000172 for (const Decl *R = D->getMostRecentDecl(); R; R = R->getPreviousDecl()) {
173 if (R->isFromASTFile())
Richard Smithd8a83712015-08-22 01:47:18 +0000174 Firsts[Writer.Chain->getOwningModuleFile(R)] = R;
Richard Smith5f55d932015-08-27 21:38:25 +0000175 else if (IncludeLocal)
176 Firsts[nullptr] = R;
177 }
Richard Smithd8a83712015-08-22 01:47:18 +0000178 for (const auto &F : Firsts)
Richard Smith69c82bf2016-04-01 22:52:03 +0000179 Record.AddDeclRef(F.second);
Richard Smithd8a83712015-08-22 01:47:18 +0000180 }
181
Richard Smith509fc852015-02-27 23:05:10 +0000182 /// Get the specialization decl from an entry in the specialization list.
183 template <typename EntryType>
184 typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType *
185 getSpecializationDecl(EntryType &T) {
186 return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T);
187 }
188
189 /// Get the list of partial specializations from a template's common ptr.
190 template<typename T>
191 decltype(T::PartialSpecializations) &getPartialSpecializations(T *Common) {
192 return Common->PartialSpecializations;
193 }
194 ArrayRef<Decl> getPartialSpecializations(FunctionTemplateDecl::Common *) {
195 return None;
196 }
197
Richard Smith8ab0cfd2016-02-24 21:59:10 +0000198 template<typename DeclTy>
199 void AddTemplateSpecializations(DeclTy *D) {
Richard Smith509fc852015-02-27 23:05:10 +0000200 auto *Common = D->getCommonPtr();
201
202 // If we have any lazy specializations, and the external AST source is
203 // our chained AST reader, we can just write out the DeclIDs. Otherwise,
204 // we need to resolve them to actual declarations.
205 if (Writer.Chain != Writer.Context->getExternalSource() &&
206 Common->LazySpecializations) {
207 D->LoadLazySpecializations();
208 assert(!Common->LazySpecializations);
209 }
210
Richard Smith509fc852015-02-27 23:05:10 +0000211 ArrayRef<DeclID> LazySpecializations;
212 if (auto *LS = Common->LazySpecializations)
Craig Topper55e39a72015-09-29 04:53:28 +0000213 LazySpecializations = llvm::makeArrayRef(LS + 1, LS[0]);
Richard Smith509fc852015-02-27 23:05:10 +0000214
Richard Smithd8a83712015-08-22 01:47:18 +0000215 // Add a slot to the record for the number of specializations.
216 unsigned I = Record.size();
217 Record.push_back(0);
218
Richard Smith8ab0cfd2016-02-24 21:59:10 +0000219 // AddFirstDeclFromEachModule might trigger deserialization, invalidating
220 // *Specializations iterators.
221 llvm::SmallVector<const Decl*, 16> Specs;
222 for (auto &Entry : Common->Specializations)
223 Specs.push_back(getSpecializationDecl(Entry));
224 for (auto &Entry : getPartialSpecializations(Common))
225 Specs.push_back(getSpecializationDecl(Entry));
226
227 for (auto *D : Specs) {
Richard Smith509fc852015-02-27 23:05:10 +0000228 assert(D->isCanonicalDecl() && "non-canonical decl in set");
Richard Smithd8a83712015-08-22 01:47:18 +0000229 AddFirstDeclFromEachModule(D, /*IncludeLocal*/true);
Richard Smith509fc852015-02-27 23:05:10 +0000230 }
Benjamin Kramerf367dd92015-06-12 15:31:50 +0000231 Record.append(LazySpecializations.begin(), LazySpecializations.end());
Richard Smithd8a83712015-08-22 01:47:18 +0000232
233 // Update the size entry we added earlier.
234 Record[I] = Record.size() - I - 1;
235 }
236
237 /// Ensure that this template specialization is associated with the specified
238 /// template on reload.
239 void RegisterTemplateSpecialization(const Decl *Template,
240 const Decl *Specialization) {
241 Template = Template->getCanonicalDecl();
242
243 // If the canonical template is local, we'll write out this specialization
244 // when we emit it.
245 // FIXME: We can do the same thing if there is any local declaration of
246 // the template, to avoid emitting an update record.
247 if (!Template->isFromASTFile())
248 return;
249
250 // We only need to associate the first local declaration of the
251 // specialization. The other declarations will get pulled in by it.
252 if (Writer.getFirstLocalDecl(Specialization) != Specialization)
253 return;
254
255 Writer.DeclUpdates[Template].push_back(ASTWriter::DeclUpdate(
256 UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION, Specialization));
Richard Smith509fc852015-02-27 23:05:10 +0000257 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000258 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000259}
Chris Lattner7099dbc2009-04-27 06:16:06 +0000260
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000261void ASTDeclWriter::Visit(Decl *D) {
262 DeclVisitor<ASTDeclWriter>::Visit(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000263
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000264 // Source locations require array (variable-length) abbreviations. The
265 // abbreviation infrastructure requires that arrays are encoded last, so
266 // we handle it here in the case of those classes derived from DeclaratorDecl
Nick Lewycky4b81fc872015-10-18 20:32:12 +0000267 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
Richard Smithc23d7342018-06-29 20:46:25 +0000268 if (auto *TInfo = DD->getTypeSourceInfo())
269 Record.AddTypeLoc(TInfo->getTypeLoc());
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000270 }
271
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000272 // Handle FunctionDecl's body here and write it after all other Stmts/Exprs
273 // have been written. We want it last because we will not read it back when
Fangrui Song6907ce22018-07-30 19:24:48 +0000274 // retrieving it from the AST, we'll just lazily set the offset.
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000275 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
Alexis Hunt4a8ea102011-05-06 20:44:56 +0000276 Record.push_back(FD->doesThisDeclarationHaveABody());
277 if (FD->doesThisDeclarationHaveABody())
Richard Smith290d8012016-04-06 17:06:00 +0000278 Record.AddFunctionDefinition(FD);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000279 }
Richard Smithf1c23dc2016-04-13 02:12:03 +0000280
281 // If this declaration is also a DeclContext, write blocks for the
282 // declarations that lexically stored inside its context and those
283 // declarations that are visible from its context.
284 if (DeclContext *DC = dyn_cast<DeclContext>(D))
285 VisitDeclContext(DC);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000286}
287
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000288void ASTDeclWriter::VisitDecl(Decl *D) {
Richard Smith69c82bf2016-04-01 22:52:03 +0000289 Record.AddDeclRef(cast_or_null<Decl>(D->getDeclContext()));
Richard Smith8aed4222015-12-11 22:41:00 +0000290 if (D->getDeclContext() != D->getLexicalDeclContext())
Richard Smith69c82bf2016-04-01 22:52:03 +0000291 Record.AddDeclRef(cast_or_null<Decl>(D->getLexicalDeclContext()));
Richard Smith8aed4222015-12-11 22:41:00 +0000292 else
293 Record.push_back(0);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000294 Record.push_back(D->isInvalidDecl());
295 Record.push_back(D->hasAttrs());
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000296 if (D->hasAttrs())
Richard Smith69c82bf2016-04-01 22:52:03 +0000297 Record.AddAttributes(D->getAttrs());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000298 Record.push_back(D->isImplicit());
Douglas Gregorebada0772010-06-17 23:14:26 +0000299 Record.push_back(D->isUsed(false));
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +0000300 Record.push_back(D->isReferenced());
Douglas Gregor781f7132012-01-06 16:59:53 +0000301 Record.push_back(D->isTopLevelDeclInObjCContainer());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000302 Record.push_back(D->getAccess());
Douglas Gregor781f7132012-01-06 16:59:53 +0000303 Record.push_back(D->isModulePrivate());
Richard Smith54f04402017-05-18 02:29:20 +0000304 Record.push_back(Writer.getSubmoduleID(D->getOwningModule()));
Richard Smithc264d352014-03-23 02:30:01 +0000305
306 // If this declaration injected a name into a context different from its
307 // lexical context, and that context is an imported namespace, we need to
308 // update its visible declarations to include this name.
309 //
310 // This happens when we instantiate a class with a friend declaration or a
311 // function with a local extern declaration, for instance.
Richard Smith5fc18a92015-07-12 23:43:21 +0000312 //
313 // FIXME: Can we handle this in AddedVisibleDecl instead?
Richard Smithc264d352014-03-23 02:30:01 +0000314 if (D->isOutOfLine()) {
Richard Smithe3a97022014-03-23 20:41:56 +0000315 auto *DC = D->getDeclContext();
316 while (auto *NS = dyn_cast<NamespaceDecl>(DC->getRedeclContext())) {
317 if (!NS->isFromASTFile())
318 break;
Chandler Carruth8a3d24d2015-03-26 04:27:10 +0000319 Writer.UpdatedDeclContexts.insert(NS->getPrimaryContext());
Richard Smithe3a97022014-03-23 20:41:56 +0000320 if (!NS->isInlineNamespace())
321 break;
322 DC = NS->getParent();
323 }
Richard Smithc264d352014-03-23 02:30:01 +0000324 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000325}
326
Nico Weber66220292016-03-02 17:28:48 +0000327void ASTDeclWriter::VisitPragmaCommentDecl(PragmaCommentDecl *D) {
328 StringRef Arg = D->getArg();
329 Record.push_back(Arg.size());
330 VisitDecl(D);
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000331 Record.AddSourceLocation(D->getBeginLoc());
Nico Weber66220292016-03-02 17:28:48 +0000332 Record.push_back(D->getCommentKind());
Richard Smith69c82bf2016-04-01 22:52:03 +0000333 Record.AddString(Arg);
Nico Weber66220292016-03-02 17:28:48 +0000334 Code = serialization::DECL_PRAGMA_COMMENT;
335}
336
Nico Webercbbaeb12016-03-02 19:28:54 +0000337void ASTDeclWriter::VisitPragmaDetectMismatchDecl(
338 PragmaDetectMismatchDecl *D) {
339 StringRef Name = D->getName();
340 StringRef Value = D->getValue();
341 Record.push_back(Name.size() + 1 + Value.size());
342 VisitDecl(D);
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000343 Record.AddSourceLocation(D->getBeginLoc());
Richard Smith69c82bf2016-04-01 22:52:03 +0000344 Record.AddString(Name);
345 Record.AddString(Value);
Nico Webercbbaeb12016-03-02 19:28:54 +0000346 Code = serialization::DECL_PRAGMA_DETECT_MISMATCH;
347}
348
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000349void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
Douglas Gregordab42432011-08-12 00:15:20 +0000350 llvm_unreachable("Translation units aren't directly serialized");
Chris Lattner7099dbc2009-04-27 06:16:06 +0000351}
352
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000353void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000354 VisitDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000355 Record.AddDeclarationName(D->getDeclName());
Richard Smith2b560572015-02-07 03:11:11 +0000356 Record.push_back(needsAnonymousDeclarationNumber(D)
357 ? Writer.getAnonymousDeclarationNumber(D)
358 : 0);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000359}
360
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000361void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000362 VisitNamedDecl(D);
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000363 Record.AddSourceLocation(D->getBeginLoc());
Richard Smith69c82bf2016-04-01 22:52:03 +0000364 Record.AddTypeRef(QualType(D->getTypeForDecl(), 0));
Chris Lattner7099dbc2009-04-27 06:16:06 +0000365}
366
Douglas Gregor1f179062011-12-19 14:40:25 +0000367void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) {
Douglas Gregor05f10352011-12-17 23:38:30 +0000368 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000369 VisitTypeDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000370 Record.AddTypeSourceInfo(D->getTypeSourceInfo());
Enea Zaffanellaa86d88c2013-06-20 12:46:19 +0000371 Record.push_back(D->isModed());
372 if (D->isModed())
Richard Smith69c82bf2016-04-01 22:52:03 +0000373 Record.AddTypeRef(D->getUnderlyingType());
Richard Smithc0ca4c22017-01-26 22:39:55 +0000374 Record.AddDeclRef(D->getAnonDeclWithTypedefName(false));
Douglas Gregor1f179062011-12-19 14:40:25 +0000375}
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000376
Douglas Gregor1f179062011-12-19 14:40:25 +0000377void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) {
378 VisitTypedefNameDecl(D);
Richard Smith8aed4222015-12-11 22:41:00 +0000379 if (D->getDeclContext() == D->getLexicalDeclContext() &&
380 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000381 !D->isImplicit() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000382 D->getFirstDecl() == D->getMostRecentDecl() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000383 !D->isInvalidDecl() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000384 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000385 !D->isModulePrivate() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000386 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000387 D->getDeclName().getNameKind() == DeclarationName::Identifier)
388 AbbrevToUse = Writer.getDeclTypedefAbbrev();
389
Sebastian Redl539c5062010-08-18 23:57:32 +0000390 Code = serialization::DECL_TYPEDEF;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000391}
392
Richard Smithdda56e42011-04-15 14:24:37 +0000393void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) {
Douglas Gregor1f179062011-12-19 14:40:25 +0000394 VisitTypedefNameDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000395 Record.AddDeclRef(D->getDescribedAliasTemplate());
Richard Smithdda56e42011-04-15 14:24:37 +0000396 Code = serialization::DECL_TYPEALIAS;
397}
398
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000399void ASTDeclWriter::VisitTagDecl(TagDecl *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000400 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000401 VisitTypeDecl(D);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000402 Record.push_back(D->getIdentifierNamespace());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000403 Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding
Richard Smith2c381642014-08-27 23:11:59 +0000404 if (!isa<CXXRecordDecl>(D))
405 Record.push_back(D->isCompleteDefinition());
Douglas Gregor5089c762010-02-12 17:40:34 +0000406 Record.push_back(D->isEmbeddedInDeclarator());
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +0000407 Record.push_back(D->isFreeStanding());
David Blaikiea8d23ce2013-07-14 01:07:41 +0000408 Record.push_back(D->isCompleteDefinitionRequired());
Argyrios Kyrtzidisd798c052016-07-15 18:11:33 +0000409 Record.AddSourceRange(D->getBraceRange());
Richard Smith70d58502014-08-30 00:04:23 +0000410
411 if (D->hasExtInfo()) {
412 Record.push_back(1);
Richard Smith69c82bf2016-04-01 22:52:03 +0000413 Record.AddQualifierInfo(*D->getExtInfo());
Richard Smith70d58502014-08-30 00:04:23 +0000414 } else if (auto *TD = D->getTypedefNameForAnonDecl()) {
415 Record.push_back(2);
Richard Smith69c82bf2016-04-01 22:52:03 +0000416 Record.AddDeclRef(TD);
417 Record.AddIdentifierRef(TD->getDeclName().getAsIdentifierInfo());
Richard Smith70d58502014-08-30 00:04:23 +0000418 } else {
419 Record.push_back(0);
420 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000421}
422
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000423void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000424 VisitTagDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000425 Record.AddTypeSourceInfo(D->getIntegerTypeSourceInfo());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000426 if (!D->getIntegerTypeSourceInfo())
Richard Smith69c82bf2016-04-01 22:52:03 +0000427 Record.AddTypeRef(D->getIntegerType());
428 Record.AddTypeRef(D->getPromotionType());
John McCall9aa35be2010-05-06 08:49:23 +0000429 Record.push_back(D->getNumPositiveBits());
430 Record.push_back(D->getNumNegativeBits());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000431 Record.push_back(D->isScoped());
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000432 Record.push_back(D->isScopedUsingClassTag());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000433 Record.push_back(D->isFixed());
Richard Trieuab4d7302018-07-25 22:52:05 +0000434 Record.push_back(D->getODRHash());
435
Richard Smith4b38ded2012-03-14 23:13:10 +0000436 if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
Richard Smith69c82bf2016-04-01 22:52:03 +0000437 Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
Richard Smith4b38ded2012-03-14 23:13:10 +0000438 Record.push_back(MemberInfo->getTemplateSpecializationKind());
Richard Smith69c82bf2016-04-01 22:52:03 +0000439 Record.AddSourceLocation(MemberInfo->getPointOfInstantiation());
Richard Smith4b38ded2012-03-14 23:13:10 +0000440 } else {
Richard Smith69c82bf2016-04-01 22:52:03 +0000441 Record.AddDeclRef(nullptr);
Richard Smith4b38ded2012-03-14 23:13:10 +0000442 }
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000443
Richard Smith8aed4222015-12-11 22:41:00 +0000444 if (D->getDeclContext() == D->getLexicalDeclContext() &&
445 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000446 !D->isImplicit() &&
447 !D->isUsed(false) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000448 !D->hasExtInfo() &&
Richard Smith70d58502014-08-30 00:04:23 +0000449 !D->getTypedefNameForAnonDecl() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000450 D->getFirstDecl() == D->getMostRecentDecl() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000451 !D->isInvalidDecl() &&
452 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000453 !D->isTopLevelDeclInObjCContainer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000454 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000455 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000456 !CXXRecordDecl::classofKind(D->getKind()) &&
457 !D->getIntegerTypeSourceInfo() &&
Argyrios Kyrtzidisca370b0d2013-03-18 22:23:49 +0000458 !D->getMemberSpecializationInfo() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000459 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000460 D->getDeclName().getNameKind() == DeclarationName::Identifier)
461 AbbrevToUse = Writer.getDeclEnumAbbrev();
462
Sebastian Redl539c5062010-08-18 23:57:32 +0000463 Code = serialization::DECL_ENUM;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000464}
465
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000466void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000467 VisitTagDecl(D);
468 Record.push_back(D->hasFlexibleArrayMember());
469 Record.push_back(D->isAnonymousStructOrUnion());
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000470 Record.push_back(D->hasObjectMember());
Fariborz Jahanian78652202013-01-25 23:57:05 +0000471 Record.push_back(D->hasVolatileMember());
Akira Hatanaka34fb2642018-03-13 18:58:25 +0000472 Record.push_back(D->isNonTrivialToPrimitiveDefaultInitialize());
473 Record.push_back(D->isNonTrivialToPrimitiveCopy());
474 Record.push_back(D->isNonTrivialToPrimitiveDestroy());
Akira Hatanakafcbe17c2018-03-28 21:13:14 +0000475 Record.push_back(D->isParamDestroyedInCallee());
Akira Hatanakae6313ac2018-04-09 22:48:22 +0000476 Record.push_back(D->getArgPassingRestrictions());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000477
Richard Smith8aed4222015-12-11 22:41:00 +0000478 if (D->getDeclContext() == D->getLexicalDeclContext() &&
479 !D->hasAttrs() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000480 !D->isImplicit() &&
481 !D->isUsed(false) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000482 !D->hasExtInfo() &&
Richard Smith70d58502014-08-30 00:04:23 +0000483 !D->getTypedefNameForAnonDecl() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000484 D->getFirstDecl() == D->getMostRecentDecl() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000485 !D->isInvalidDecl() &&
486 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000487 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000488 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000489 !D->isModulePrivate() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000490 !CXXRecordDecl::classofKind(D->getKind()) &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000491 !needsAnonymousDeclarationNumber(D) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000492 D->getDeclName().getNameKind() == DeclarationName::Identifier)
Douglas Gregor03412ba2011-06-03 02:27:19 +0000493 AbbrevToUse = Writer.getDeclRecordAbbrev();
494
Sebastian Redl539c5062010-08-18 23:57:32 +0000495 Code = serialization::DECL_RECORD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000496}
497
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000498void ASTDeclWriter::VisitValueDecl(ValueDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000499 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000500 Record.AddTypeRef(D->getType());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000501}
502
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000503void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000504 VisitValueDecl(D);
505 Record.push_back(D->getInitExpr()? 1 : 0);
506 if (D->getInitExpr())
Richard Smith290d8012016-04-06 17:06:00 +0000507 Record.AddStmt(D->getInitExpr());
Richard Smith69c82bf2016-04-01 22:52:03 +0000508 Record.AddAPSInt(D->getInitVal());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000509
Sebastian Redl539c5062010-08-18 23:57:32 +0000510 Code = serialization::DECL_ENUM_CONSTANT;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000511}
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000512
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000513void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000514 VisitValueDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000515 Record.AddSourceLocation(D->getInnerLocStart());
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000516 Record.push_back(D->hasExtInfo());
517 if (D->hasExtInfo())
Richard Smith69c82bf2016-04-01 22:52:03 +0000518 Record.AddQualifierInfo(*D->getExtInfo());
Richard Smithc23d7342018-06-29 20:46:25 +0000519 // The location information is deferred until the end of the record.
520 Record.AddTypeRef(D->getTypeSourceInfo() ? D->getTypeSourceInfo()->getType()
521 : QualType());
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000522}
Chris Lattner7099dbc2009-04-27 06:16:06 +0000523
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000524void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000525 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000526 VisitDeclaratorDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000527 Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000528 Record.push_back(D->getIdentifierNamespace());
Fangrui Song6907ce22018-07-30 19:24:48 +0000529
Douglas Gregorb2585692012-01-04 17:13:46 +0000530 // FunctionDecl's body is handled last at ASTWriterDecl::Visit,
531 // after everything else is written.
Erich Keane9c665062018-08-01 21:02:40 +0000532 Record.push_back(static_cast<int>(D->getStorageClass())); // FIXME: stable encoding
533 Record.push_back(D->isInlineSpecified());
534 Record.push_back(D->isInlined());
535 Record.push_back(D->isExplicitSpecified());
536 Record.push_back(D->isVirtualAsWritten());
537 Record.push_back(D->isPure());
538 Record.push_back(D->hasInheritedPrototype());
539 Record.push_back(D->hasWrittenPrototype());
540 Record.push_back(D->isDeletedBit());
541 Record.push_back(D->isTrivial());
542 Record.push_back(D->isTrivialForCall());
543 Record.push_back(D->isDefaulted());
544 Record.push_back(D->isExplicitlyDefaulted());
545 Record.push_back(D->hasImplicitReturnZero());
546 Record.push_back(D->isConstexpr());
547 Record.push_back(D->usesSEHTry());
548 Record.push_back(D->hasSkippedBody());
549 Record.push_back(D->isMultiVersion());
550 Record.push_back(D->isLateTemplateParsed());
Rafael Espindola3ae00052013-05-13 00:12:11 +0000551 Record.push_back(D->getLinkageInternal());
Richard Smith69c82bf2016-04-01 22:52:03 +0000552 Record.AddSourceLocation(D->getLocEnd());
Douglas Gregorb2585692012-01-04 17:13:46 +0000553
Richard Trieue6caa262017-12-23 00:41:01 +0000554 Record.push_back(D->getODRHash());
555
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000556 Record.push_back(D->getTemplatedKind());
557 switch (D->getTemplatedKind()) {
558 case FunctionDecl::TK_NonTemplate:
559 break;
560 case FunctionDecl::TK_FunctionTemplate:
Richard Smith69c82bf2016-04-01 22:52:03 +0000561 Record.AddDeclRef(D->getDescribedFunctionTemplate());
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000562 break;
563 case FunctionDecl::TK_MemberSpecialization: {
564 MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo();
Richard Smith69c82bf2016-04-01 22:52:03 +0000565 Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000566 Record.push_back(MemberInfo->getTemplateSpecializationKind());
Richard Smith69c82bf2016-04-01 22:52:03 +0000567 Record.AddSourceLocation(MemberInfo->getPointOfInstantiation());
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000568 break;
569 }
570 case FunctionDecl::TK_FunctionTemplateSpecialization: {
571 FunctionTemplateSpecializationInfo *
572 FTSInfo = D->getTemplateSpecializationInfo();
Richard Smithd8a83712015-08-22 01:47:18 +0000573
574 RegisterTemplateSpecialization(FTSInfo->getTemplate(), D);
575
Richard Smith69c82bf2016-04-01 22:52:03 +0000576 Record.AddDeclRef(FTSInfo->getTemplate());
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000577 Record.push_back(FTSInfo->getTemplateSpecializationKind());
Fangrui Song6907ce22018-07-30 19:24:48 +0000578
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000579 // Template arguments.
Richard Smith69c82bf2016-04-01 22:52:03 +0000580 Record.AddTemplateArgumentList(FTSInfo->TemplateArguments);
Fangrui Song6907ce22018-07-30 19:24:48 +0000581
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000582 // Template args as written.
Craig Toppera13603a2014-05-22 05:54:18 +0000583 Record.push_back(FTSInfo->TemplateArgumentsAsWritten != nullptr);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000584 if (FTSInfo->TemplateArgumentsAsWritten) {
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000585 Record.push_back(FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs);
586 for (int i=0, e = FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs;
587 i!=e; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +0000588 Record.AddTemplateArgumentLoc(
589 (*FTSInfo->TemplateArgumentsAsWritten)[i]);
590 Record.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->LAngleLoc);
591 Record.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->RAngleLoc);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000592 }
Fangrui Song6907ce22018-07-30 19:24:48 +0000593
Richard Smith69c82bf2016-04-01 22:52:03 +0000594 Record.AddSourceLocation(FTSInfo->getPointOfInstantiation());
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000595
596 if (D->isCanonicalDecl()) {
597 // Write the template that contains the specializations set. We will
598 // add a FunctionTemplateSpecializationInfo to it when reading.
Richard Smith69c82bf2016-04-01 22:52:03 +0000599 Record.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl());
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000600 }
Argyrios Kyrtzidisdc9ca0a2010-06-25 16:24:51 +0000601 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000602 }
603 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
604 DependentFunctionTemplateSpecializationInfo *
605 DFTSInfo = D->getDependentSpecializationInfo();
Fangrui Song6907ce22018-07-30 19:24:48 +0000606
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000607 // Templates.
608 Record.push_back(DFTSInfo->getNumTemplates());
609 for (int i=0, e = DFTSInfo->getNumTemplates(); i != e; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +0000610 Record.AddDeclRef(DFTSInfo->getTemplate(i));
Fangrui Song6907ce22018-07-30 19:24:48 +0000611
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000612 // Templates args.
613 Record.push_back(DFTSInfo->getNumTemplateArgs());
614 for (int i=0, e = DFTSInfo->getNumTemplateArgs(); i != e; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +0000615 Record.AddTemplateArgumentLoc(DFTSInfo->getTemplateArg(i));
616 Record.AddSourceLocation(DFTSInfo->getLAngleLoc());
617 Record.AddSourceLocation(DFTSInfo->getRAngleLoc());
Argyrios Kyrtzidisdc9ca0a2010-06-25 16:24:51 +0000618 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000619 }
620 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000621
Chris Lattner7099dbc2009-04-27 06:16:06 +0000622 Record.push_back(D->param_size());
David Majnemer59f77922016-06-24 04:05:48 +0000623 for (auto P : D->parameters())
Richard Smith69c82bf2016-04-01 22:52:03 +0000624 Record.AddDeclRef(P);
Sebastian Redl539c5062010-08-18 23:57:32 +0000625 Code = serialization::DECL_FUNCTION;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000626}
627
Richard Smithbc491202017-02-17 20:05:37 +0000628void ASTDeclWriter::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) {
629 VisitFunctionDecl(D);
Erich Keane9c665062018-08-01 21:02:40 +0000630 Record.push_back(D->isCopyDeductionCandidate());
Richard Smithbc491202017-02-17 20:05:37 +0000631 Code = serialization::DECL_CXX_DEDUCTION_GUIDE;
632}
633
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000634void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000635 VisitNamedDecl(D);
636 // FIXME: convert to LazyStmtPtr?
Mike Stump11289f42009-09-09 15:08:12 +0000637 // Unlike C/C++, method bodies will never be in header files.
Craig Toppera13603a2014-05-22 05:54:18 +0000638 bool HasBodyStuff = D->getBody() != nullptr ||
639 D->getSelfDecl() != nullptr || D->getCmdDecl() != nullptr;
Argyrios Kyrtzidisa8607772010-08-09 10:54:37 +0000640 Record.push_back(HasBodyStuff);
641 if (HasBodyStuff) {
Richard Smith290d8012016-04-06 17:06:00 +0000642 Record.AddStmt(D->getBody());
Richard Smith69c82bf2016-04-01 22:52:03 +0000643 Record.AddDeclRef(D->getSelfDecl());
644 Record.AddDeclRef(D->getCmdDecl());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000645 }
646 Record.push_back(D->isInstanceMethod());
647 Record.push_back(D->isVariadic());
Jordan Rosed01e83a2012-10-10 16:42:25 +0000648 Record.push_back(D->isPropertyAccessor());
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000649 Record.push_back(D->isDefined());
Erich Keane9b18eca2018-08-01 21:31:08 +0000650 Record.push_back(D->isOverriding());
651 Record.push_back(D->hasSkippedBody());
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000652
Erich Keane9b18eca2018-08-01 21:31:08 +0000653 Record.push_back(D->isRedeclaration());
654 Record.push_back(D->hasRedeclaration());
655 if (D->hasRedeclaration()) {
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000656 assert(Context.getObjCMethodRedeclaration(D));
Richard Smith69c82bf2016-04-01 22:52:03 +0000657 Record.AddDeclRef(Context.getObjCMethodRedeclaration(D));
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000658 }
659
Chris Lattner7099dbc2009-04-27 06:16:06 +0000660 // FIXME: stable encoding for @required/@optional
Mike Stump11289f42009-09-09 15:08:12 +0000661 Record.push_back(D->getImplementationControl());
Douglas Gregor813a0662015-06-19 18:14:38 +0000662 // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway/nullability
Mike Stump11289f42009-09-09 15:08:12 +0000663 Record.push_back(D->getObjCDeclQualifier());
Douglas Gregor33823722011-06-11 01:09:30 +0000664 Record.push_back(D->hasRelatedResultType());
Richard Smith69c82bf2016-04-01 22:52:03 +0000665 Record.AddTypeRef(D->getReturnType());
666 Record.AddTypeSourceInfo(D->getReturnTypeSourceInfo());
667 Record.AddSourceLocation(D->getLocEnd());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000668 Record.push_back(D->param_size());
David Majnemer59f77922016-06-24 04:05:48 +0000669 for (const auto *P : D->parameters())
Richard Smith69c82bf2016-04-01 22:52:03 +0000670 Record.AddDeclRef(P);
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000671
Erich Keane9b18eca2018-08-01 21:31:08 +0000672 Record.push_back(D->getSelLocsKind());
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000673 unsigned NumStoredSelLocs = D->getNumStoredSelLocs();
674 SourceLocation *SelLocs = D->getStoredSelLocs();
675 Record.push_back(NumStoredSelLocs);
676 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +0000677 Record.AddSourceLocation(SelLocs[i]);
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000678
Sebastian Redl539c5062010-08-18 23:57:32 +0000679 Code = serialization::DECL_OBJC_METHOD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000680}
681
Douglas Gregor85f3f952015-07-07 03:57:15 +0000682void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
683 VisitTypedefNameDecl(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +0000684 Record.push_back(D->Variance);
Douglas Gregore83b9562015-07-07 03:57:53 +0000685 Record.push_back(D->Index);
Richard Smith69c82bf2016-04-01 22:52:03 +0000686 Record.AddSourceLocation(D->VarianceLoc);
687 Record.AddSourceLocation(D->ColonLoc);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000688
689 Code = serialization::DECL_OBJC_TYPE_PARAM;
690}
691
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000692void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000693 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000694 Record.AddSourceLocation(D->getAtStartLoc());
695 Record.AddSourceRange(D->getAtEndRange());
Sebastian Redl539c5062010-08-18 23:57:32 +0000696 // Abstract class (no need to define a stable serialization::DECL code).
Chris Lattner7099dbc2009-04-27 06:16:06 +0000697}
698
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000699void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
Douglas Gregor66b310c2011-12-15 18:03:09 +0000700 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000701 VisitObjCContainerDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000702 Record.AddTypeRef(QualType(D->getTypeForDecl(), 0));
Douglas Gregor85f3f952015-07-07 03:57:15 +0000703 AddObjCTypeParamList(D->TypeParamList);
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000704
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000705 Record.push_back(D->isThisDeclarationADefinition());
706 if (D->isThisDeclarationADefinition()) {
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000707 // Write the DefinitionData
708 ObjCInterfaceDecl::DefinitionData &Data = D->data();
Fangrui Song6907ce22018-07-30 19:24:48 +0000709
Richard Smith69c82bf2016-04-01 22:52:03 +0000710 Record.AddTypeSourceInfo(D->getSuperClassTInfo());
711 Record.AddSourceLocation(D->getEndOfDefinitionLoc());
Argyrios Kyrtzidis9ed9e5f2013-12-03 21:11:30 +0000712 Record.push_back(Data.HasDesignatedInitializers);
Douglas Gregor16408322011-12-15 22:34:59 +0000713
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000714 // Write out the protocols that are directly referenced by the @interface.
715 Record.push_back(Data.ReferencedProtocols.size());
Aaron Ballmana49c5062014-03-13 20:29:09 +0000716 for (const auto *P : D->protocols())
Richard Smith69c82bf2016-04-01 22:52:03 +0000717 Record.AddDeclRef(P);
Aaron Ballmane9378882014-03-13 20:34:24 +0000718 for (const auto &PL : D->protocol_locs())
Richard Smith69c82bf2016-04-01 22:52:03 +0000719 Record.AddSourceLocation(PL);
Fangrui Song6907ce22018-07-30 19:24:48 +0000720
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000721 // Write out the protocols that are transitively referenced.
722 Record.push_back(Data.AllReferencedProtocols.size());
723 for (ObjCList<ObjCProtocolDecl>::iterator
724 P = Data.AllReferencedProtocols.begin(),
725 PEnd = Data.AllReferencedProtocols.end();
726 P != PEnd; ++P)
Richard Smith69c82bf2016-04-01 22:52:03 +0000727 Record.AddDeclRef(*P);
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000728
Fangrui Song6907ce22018-07-30 19:24:48 +0000729
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000730 if (ObjCCategoryDecl *Cat = D->getCategoryListRaw()) {
Douglas Gregor404cdde2012-01-27 01:47:08 +0000731 // Ensure that we write out the set of categories for this class.
732 Writer.ObjCClassesWithCategories.insert(D);
Fangrui Song6907ce22018-07-30 19:24:48 +0000733
Douglas Gregor404cdde2012-01-27 01:47:08 +0000734 // Make sure that the categories get serialized.
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000735 for (; Cat; Cat = Cat->getNextClassCategoryRaw())
Douglas Gregor404cdde2012-01-27 01:47:08 +0000736 (void)Writer.GetDeclRef(Cat);
737 }
Fangrui Song6907ce22018-07-30 19:24:48 +0000738 }
739
Sebastian Redl539c5062010-08-18 23:57:32 +0000740 Code = serialization::DECL_OBJC_INTERFACE;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000741}
742
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000743void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000744 VisitFieldDecl(D);
745 // FIXME: stable encoding for @public/@private/@protected/@package
Mike Stump11289f42009-09-09 15:08:12 +0000746 Record.push_back(D->getAccessControl());
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000747 Record.push_back(D->getSynthesize());
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000748
Richard Smith8aed4222015-12-11 22:41:00 +0000749 if (D->getDeclContext() == D->getLexicalDeclContext() &&
750 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000751 !D->isImplicit() &&
752 !D->isUsed(false) &&
753 !D->isInvalidDecl() &&
754 !D->isReferenced() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000755 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000756 !D->getBitWidth() &&
757 !D->hasExtInfo() &&
758 D->getDeclName())
759 AbbrevToUse = Writer.getDeclObjCIvarAbbrev();
760
Sebastian Redl539c5062010-08-18 23:57:32 +0000761 Code = serialization::DECL_OBJC_IVAR;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000762}
763
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000764void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
Douglas Gregora715bff2012-01-01 19:51:50 +0000765 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000766 VisitObjCContainerDecl(D);
Fangrui Song6907ce22018-07-30 19:24:48 +0000767
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000768 Record.push_back(D->isThisDeclarationADefinition());
769 if (D->isThisDeclarationADefinition()) {
Douglas Gregore6e48b12012-01-01 19:29:29 +0000770 Record.push_back(D->protocol_size());
Aaron Ballman0f6e64d2014-03-13 22:58:06 +0000771 for (const auto *I : D->protocols())
Richard Smith69c82bf2016-04-01 22:52:03 +0000772 Record.AddDeclRef(I);
Aaron Ballmana964ec12014-03-14 12:38:50 +0000773 for (const auto &PL : D->protocol_locs())
Richard Smith69c82bf2016-04-01 22:52:03 +0000774 Record.AddSourceLocation(PL);
Douglas Gregore6e48b12012-01-01 19:29:29 +0000775 }
Fangrui Song6907ce22018-07-30 19:24:48 +0000776
Sebastian Redl539c5062010-08-18 23:57:32 +0000777 Code = serialization::DECL_OBJC_PROTOCOL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000778}
779
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000780void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000781 VisitFieldDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000782 Code = serialization::DECL_OBJC_AT_DEFS_FIELD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000783}
784
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000785void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000786 VisitObjCContainerDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000787 Record.AddSourceLocation(D->getCategoryNameLoc());
788 Record.AddSourceLocation(D->getIvarLBraceLoc());
789 Record.AddSourceLocation(D->getIvarRBraceLoc());
790 Record.AddDeclRef(D->getClassInterface());
Douglas Gregor85f3f952015-07-07 03:57:15 +0000791 AddObjCTypeParamList(D->TypeParamList);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000792 Record.push_back(D->protocol_size());
Aaron Ballman19a41762014-03-14 12:55:57 +0000793 for (const auto *I : D->protocols())
Richard Smith69c82bf2016-04-01 22:52:03 +0000794 Record.AddDeclRef(I);
Aaron Ballmana73c8572014-03-14 13:03:32 +0000795 for (const auto &PL : D->protocol_locs())
Richard Smith69c82bf2016-04-01 22:52:03 +0000796 Record.AddSourceLocation(PL);
Sebastian Redl539c5062010-08-18 23:57:32 +0000797 Code = serialization::DECL_OBJC_CATEGORY;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000798}
799
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000800void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000801 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000802 Record.AddDeclRef(D->getClassInterface());
Sebastian Redl539c5062010-08-18 23:57:32 +0000803 Code = serialization::DECL_OBJC_COMPATIBLE_ALIAS;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000804}
805
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000806void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000807 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000808 Record.AddSourceLocation(D->getAtLoc());
809 Record.AddSourceLocation(D->getLParenLoc());
810 Record.AddTypeRef(D->getType());
811 Record.AddTypeSourceInfo(D->getTypeSourceInfo());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000812 // FIXME: stable encoding
813 Record.push_back((unsigned)D->getPropertyAttributes());
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000814 Record.push_back((unsigned)D->getPropertyAttributesAsWritten());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000815 // FIXME: stable encoding
816 Record.push_back((unsigned)D->getPropertyImplementation());
Richard Smith69c82bf2016-04-01 22:52:03 +0000817 Record.AddDeclarationName(D->getGetterName());
Argyrios Kyrtzidis194b28e2017-03-16 18:25:40 +0000818 Record.AddSourceLocation(D->getGetterNameLoc());
Richard Smith69c82bf2016-04-01 22:52:03 +0000819 Record.AddDeclarationName(D->getSetterName());
Argyrios Kyrtzidis194b28e2017-03-16 18:25:40 +0000820 Record.AddSourceLocation(D->getSetterNameLoc());
Richard Smith69c82bf2016-04-01 22:52:03 +0000821 Record.AddDeclRef(D->getGetterMethodDecl());
822 Record.AddDeclRef(D->getSetterMethodDecl());
823 Record.AddDeclRef(D->getPropertyIvarDecl());
Sebastian Redl539c5062010-08-18 23:57:32 +0000824 Code = serialization::DECL_OBJC_PROPERTY;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000825}
826
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000827void ASTDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000828 VisitObjCContainerDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000829 Record.AddDeclRef(D->getClassInterface());
Sebastian Redl539c5062010-08-18 23:57:32 +0000830 // Abstract class (no need to define a stable serialization::DECL code).
Chris Lattner7099dbc2009-04-27 06:16:06 +0000831}
832
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000833void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000834 VisitObjCImplDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000835 Record.AddSourceLocation(D->getCategoryNameLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +0000836 Code = serialization::DECL_OBJC_CATEGORY_IMPL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000837}
838
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000839void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000840 VisitObjCImplDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000841 Record.AddDeclRef(D->getSuperClass());
842 Record.AddSourceLocation(D->getSuperClassLoc());
843 Record.AddSourceLocation(D->getIvarLBraceLoc());
844 Record.AddSourceLocation(D->getIvarRBraceLoc());
John McCall0d54a172012-10-17 04:53:31 +0000845 Record.push_back(D->hasNonZeroConstructors());
846 Record.push_back(D->hasDestructors());
Richard Smithc2bb8182015-03-24 06:36:48 +0000847 Record.push_back(D->NumIvarInitializers);
848 if (D->NumIvarInitializers)
Richard Smithaa165cf2016-04-13 21:57:08 +0000849 Record.AddCXXCtorInitializers(
Richard Smith69c82bf2016-04-01 22:52:03 +0000850 llvm::makeArrayRef(D->init_begin(), D->init_end()));
Sebastian Redl539c5062010-08-18 23:57:32 +0000851 Code = serialization::DECL_OBJC_IMPLEMENTATION;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000852}
853
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000854void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000855 VisitDecl(D);
Stephen Kellyf2ceec42018-08-09 21:08:08 +0000856 Record.AddSourceLocation(D->getBeginLoc());
Richard Smith69c82bf2016-04-01 22:52:03 +0000857 Record.AddDeclRef(D->getPropertyDecl());
858 Record.AddDeclRef(D->getPropertyIvarDecl());
859 Record.AddSourceLocation(D->getPropertyIvarDeclLoc());
Richard Smith290d8012016-04-06 17:06:00 +0000860 Record.AddStmt(D->getGetterCXXConstructor());
861 Record.AddStmt(D->getSetterCXXAssignment());
Sebastian Redl539c5062010-08-18 23:57:32 +0000862 Code = serialization::DECL_OBJC_PROPERTY_IMPL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000863}
864
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000865void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000866 VisitDeclaratorDecl(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000867 Record.push_back(D->isMutable());
Richard Smith6b8e3c02017-08-28 00:28:14 +0000868
869 FieldDecl::InitStorageKind ISK = D->InitStorage.getInt();
870 Record.push_back(ISK);
871 if (ISK == FieldDecl::ISK_CapturedVLAType)
872 Record.AddTypeRef(QualType(D->getCapturedVLAType(), 0));
873 else if (ISK)
874 Record.AddStmt(D->getInClassInitializer());
875
876 Record.AddStmt(D->getBitWidth());
877
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000878 if (!D->getDeclName())
Richard Smith69c82bf2016-04-01 22:52:03 +0000879 Record.AddDeclRef(Context.getInstantiatedFromUnnamedFieldDecl(D));
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000880
Richard Smith8aed4222015-12-11 22:41:00 +0000881 if (D->getDeclContext() == D->getLexicalDeclContext() &&
882 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000883 !D->isImplicit() &&
884 !D->isUsed(false) &&
885 !D->isInvalidDecl() &&
886 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000887 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000888 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000889 !D->getBitWidth() &&
Richard Smith938f40b2011-06-11 17:19:42 +0000890 !D->hasInClassInitializer() &&
Richard Smith6b8e3c02017-08-28 00:28:14 +0000891 !D->hasCapturedVLAType() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000892 !D->hasExtInfo() &&
893 !ObjCIvarDecl::classofKind(D->getKind()) &&
894 !ObjCAtDefsFieldDecl::classofKind(D->getKind()) &&
895 D->getDeclName())
896 AbbrevToUse = Writer.getDeclFieldAbbrev();
897
Sebastian Redl539c5062010-08-18 23:57:32 +0000898 Code = serialization::DECL_FIELD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000899}
900
John McCall5e77d762013-04-16 07:28:30 +0000901void ASTDeclWriter::VisitMSPropertyDecl(MSPropertyDecl *D) {
902 VisitDeclaratorDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +0000903 Record.AddIdentifierRef(D->getGetterId());
904 Record.AddIdentifierRef(D->getSetterId());
John McCall5e77d762013-04-16 07:28:30 +0000905 Code = serialization::DECL_MS_PROPERTY;
906}
907
Francois Pichet783dd6e2010-11-21 06:08:52 +0000908void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
909 VisitValueDecl(D);
910 Record.push_back(D->getChainingSize());
911
Aaron Ballman29c94602014-03-07 18:36:15 +0000912 for (const auto *P : D->chain())
Richard Smith69c82bf2016-04-01 22:52:03 +0000913 Record.AddDeclRef(P);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000914 Code = serialization::DECL_INDIRECTFIELD;
915}
916
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000917void ASTDeclWriter::VisitVarDecl(VarDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000918 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000919 VisitDeclaratorDecl(D);
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000920 Record.push_back(D->getStorageClass());
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +0000921 Record.push_back(D->getTSCSpec());
Sebastian Redla9351792012-02-11 23:51:47 +0000922 Record.push_back(D->getInitStyle());
David Majnemerfa7bc782015-05-19 00:57:16 +0000923 if (!isa<ParmVarDecl>(D)) {
Richard Smithedbc6e92016-10-14 21:41:24 +0000924 Record.push_back(D->isThisDeclarationADemotedDefinition());
David Majnemerfa7bc782015-05-19 00:57:16 +0000925 Record.push_back(D->isExceptionVariable());
Taiju Tsuiki3be68e12018-06-19 05:35:30 +0000926 Record.push_back(D->isNRVOVariable());
David Majnemerfa7bc782015-05-19 00:57:16 +0000927 Record.push_back(D->isCXXForRangeDecl());
George Karpenkovec38cf72018-03-29 00:56:24 +0000928 Record.push_back(D->isObjCForDecl());
David Majnemerfa7bc782015-05-19 00:57:16 +0000929 Record.push_back(D->isARCPseudoStrong());
Richard Smith62f19e72016-06-25 00:15:56 +0000930 Record.push_back(D->isInline());
931 Record.push_back(D->isInlineSpecified());
David Majnemerfa7bc782015-05-19 00:57:16 +0000932 Record.push_back(D->isConstexpr());
933 Record.push_back(D->isInitCapture());
934 Record.push_back(D->isPreviousDeclInSameBlockScope());
Alexey Bataev56223232017-06-09 13:40:18 +0000935 if (const auto *IPD = dyn_cast<ImplicitParamDecl>(D))
936 Record.push_back(static_cast<unsigned>(IPD->getParameterKind()));
937 else
938 Record.push_back(0);
David Majnemerfa7bc782015-05-19 00:57:16 +0000939 }
Rafael Espindola3ae00052013-05-13 00:12:11 +0000940 Record.push_back(D->getLinkageInternal());
Douglas Gregor12cda632012-09-20 23:43:29 +0000941
Richard Smithd0b4dd62011-12-19 06:19:21 +0000942 if (D->getInit()) {
943 Record.push_back(!D->isInitKnownICE() ? 1 : (D->isInitICE() ? 3 : 2));
Richard Smith290d8012016-04-06 17:06:00 +0000944 Record.AddStmt(D->getInit());
Richard Smithd0b4dd62011-12-19 06:19:21 +0000945 } else {
946 Record.push_back(0);
947 }
Richard Smitha4653622017-09-06 20:01:14 +0000948
949 if (D->getStorageDuration() == SD_Static) {
950 bool ModulesCodegen = false;
951 if (Writer.WritingModule &&
952 !D->getDescribedVarTemplate() && !D->getMemberSpecializationInfo() &&
953 !isa<VarTemplateSpecializationDecl>(D)) {
954 // When building a C++ Modules TS module interface unit, a strong
955 // definition in the module interface is provided by the compilation of
956 // that module interface unit, not by its users. (Inline variables are
957 // still emitted in module users.)
958 ModulesCodegen =
959 (Writer.WritingModule->Kind == Module::ModuleInterfaceUnit &&
960 Writer.Context->GetGVALinkageForVariable(D) == GVA_StrongExternal);
961 }
962 Record.push_back(ModulesCodegen);
963 if (ModulesCodegen)
964 Writer.ModularCodegenDecls.push_back(Writer.GetDeclRef(D));
965 }
Fangrui Song6907ce22018-07-30 19:24:48 +0000966
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000967 enum {
968 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
969 };
970 if (VarTemplateDecl *TemplD = D->getDescribedVarTemplate()) {
971 Record.push_back(VarTemplate);
Richard Smith69c82bf2016-04-01 22:52:03 +0000972 Record.AddDeclRef(TemplD);
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000973 } else if (MemberSpecializationInfo *SpecInfo
974 = D->getMemberSpecializationInfo()) {
975 Record.push_back(StaticDataMemberSpecialization);
Richard Smith69c82bf2016-04-01 22:52:03 +0000976 Record.AddDeclRef(SpecInfo->getInstantiatedFrom());
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000977 Record.push_back(SpecInfo->getTemplateSpecializationKind());
Richard Smith69c82bf2016-04-01 22:52:03 +0000978 Record.AddSourceLocation(SpecInfo->getPointOfInstantiation());
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000979 } else {
980 Record.push_back(VarNotTemplate);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000981 }
982
Richard Smith8aed4222015-12-11 22:41:00 +0000983 if (D->getDeclContext() == D->getLexicalDeclContext() &&
984 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000985 !D->isImplicit() &&
986 !D->isUsed(false) &&
987 !D->isInvalidDecl() &&
988 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000989 !D->isTopLevelDeclInObjCContainer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000990 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000991 !D->isModulePrivate() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000992 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000993 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
994 !D->hasExtInfo() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000995 D->getFirstDecl() == D->getMostRecentDecl() &&
Richard Smith7b76d812016-08-12 02:21:25 +0000996 D->getKind() == Decl::Var &&
Richard Smith62f19e72016-06-25 00:15:56 +0000997 !D->isInline() &&
Douglas Gregor12cda632012-09-20 23:43:29 +0000998 !D->isConstexpr() &&
Richard Smithbb13c9a2013-09-28 04:02:39 +0000999 !D->isInitCapture() &&
Richard Smith1c34fb72013-08-13 18:18:50 +00001000 !D->isPreviousDeclInSameBlockScope() &&
Richard Smitha4653622017-09-06 20:01:14 +00001001 D->getStorageDuration() != SD_Static &&
Larisse Voufod8dd97c2013-08-14 03:09:19 +00001002 !D->getMemberSpecializationInfo())
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001003 AbbrevToUse = Writer.getDeclVarAbbrev();
1004
Sebastian Redl539c5062010-08-18 23:57:32 +00001005 Code = serialization::DECL_VAR;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001006}
1007
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001008void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001009 VisitVarDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001010 Code = serialization::DECL_IMPLICIT_PARAM;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001011}
1012
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001013void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001014 VisitVarDecl(D);
John McCall82490832011-05-02 00:30:12 +00001015 Record.push_back(D->isObjCMethodParameter());
John McCall8fb0d9d2011-05-01 22:35:37 +00001016 Record.push_back(D->getFunctionScopeDepth());
1017 Record.push_back(D->getFunctionScopeIndex());
Chris Lattner7099dbc2009-04-27 06:16:06 +00001018 Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding
John McCall6a014d52011-03-09 04:22:44 +00001019 Record.push_back(D->isKNRPromoted());
John McCallf3cd6652010-03-12 18:31:32 +00001020 Record.push_back(D->hasInheritedDefaultArg());
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +00001021 Record.push_back(D->hasUninstantiatedDefaultArg());
1022 if (D->hasUninstantiatedDefaultArg())
Richard Smith290d8012016-04-06 17:06:00 +00001023 Record.AddStmt(D->getUninstantiatedDefaultArg());
Sebastian Redl539c5062010-08-18 23:57:32 +00001024 Code = serialization::DECL_PARM_VAR;
Mike Stump11289f42009-09-09 15:08:12 +00001025
John McCalld4631322011-06-17 06:42:21 +00001026 assert(!D->isARCPseudoStrong()); // can be true of ImplicitParamDecl
1027
Chris Lattner258172e2009-04-27 07:35:58 +00001028 // If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here
1029 // we dynamically check for the properties that we optimize for, but don't
1030 // know are true of all PARM_VAR_DECLs.
Richard Smith8aed4222015-12-11 22:41:00 +00001031 if (D->getDeclContext() == D->getLexicalDeclContext() &&
1032 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001033 !D->hasExtInfo() &&
Chris Lattner258172e2009-04-27 07:35:58 +00001034 !D->isImplicit() &&
Douglas Gregorebada0772010-06-17 23:14:26 +00001035 !D->isUsed(false) &&
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001036 !D->isInvalidDecl() &&
Eli Friedmanc09e0552012-01-13 23:41:25 +00001037 !D->isReferenced() &&
Chris Lattner258172e2009-04-27 07:35:58 +00001038 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +00001039 !D->isModulePrivate() &&
Chris Lattner258172e2009-04-27 07:35:58 +00001040 D->getStorageClass() == 0 &&
Sebastian Redla9351792012-02-11 23:51:47 +00001041 D->getInitStyle() == VarDecl::CInit && // Can params have anything else?
John McCall82490832011-05-02 00:30:12 +00001042 D->getFunctionScopeDepth() == 0 &&
John McCallf3cd6652010-03-12 18:31:32 +00001043 D->getObjCDeclQualifier() == 0 &&
John McCall6a014d52011-03-09 04:22:44 +00001044 !D->isKNRPromoted() &&
Chris Lattnere2437f42010-05-09 06:40:08 +00001045 !D->hasInheritedDefaultArg() &&
Craig Toppera13603a2014-05-22 05:54:18 +00001046 D->getInit() == nullptr &&
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +00001047 !D->hasUninstantiatedDefaultArg()) // No default expr.
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001048 AbbrevToUse = Writer.getDeclParmVarAbbrev();
Chris Lattner258172e2009-04-27 07:35:58 +00001049
1050 // Check things we know are true of *every* PARM_VAR_DECL, which is more than
1051 // just us assuming it.
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +00001052 assert(!D->getTSCSpec() && "PARM_VAR_DECL can't use TLS");
Richard Smithedbc6e92016-10-14 21:41:24 +00001053 assert(!D->isThisDeclarationADemotedDefinition()
1054 && "PARM_VAR_DECL can't be demoted definition.");
Chris Lattner258172e2009-04-27 07:35:58 +00001055 assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private");
Douglas Gregor3f324d562010-05-03 18:51:14 +00001056 assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var");
Craig Toppera13603a2014-05-22 05:54:18 +00001057 assert(D->getPreviousDecl() == nullptr && "PARM_VAR_DECL can't be redecl");
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001058 assert(!D->isStaticDataMember() &&
1059 "PARM_VAR_DECL can't be static data member");
Chris Lattner7099dbc2009-04-27 06:16:06 +00001060}
1061
Richard Smith7b76d812016-08-12 02:21:25 +00001062void ASTDeclWriter::VisitDecompositionDecl(DecompositionDecl *D) {
1063 // Record the number of bindings first to simplify deserialization.
1064 Record.push_back(D->bindings().size());
1065
1066 VisitVarDecl(D);
1067 for (auto *B : D->bindings())
1068 Record.AddDeclRef(B);
1069 Code = serialization::DECL_DECOMPOSITION;
1070}
1071
1072void ASTDeclWriter::VisitBindingDecl(BindingDecl *D) {
1073 VisitValueDecl(D);
1074 Record.AddStmt(D->getBinding());
1075 Code = serialization::DECL_BINDING;
1076}
1077
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001078void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001079 VisitDecl(D);
Richard Smith290d8012016-04-06 17:06:00 +00001080 Record.AddStmt(D->getAsmString());
Richard Smith69c82bf2016-04-01 22:52:03 +00001081 Record.AddSourceLocation(D->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001082 Code = serialization::DECL_FILE_SCOPE_ASM;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001083}
1084
Michael Han84324352013-02-22 17:15:32 +00001085void ASTDeclWriter::VisitEmptyDecl(EmptyDecl *D) {
1086 VisitDecl(D);
1087 Code = serialization::DECL_EMPTY;
1088}
1089
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001090void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001091 VisitDecl(D);
Richard Smith290d8012016-04-06 17:06:00 +00001092 Record.AddStmt(D->getBody());
Richard Smith69c82bf2016-04-01 22:52:03 +00001093 Record.AddTypeSourceInfo(D->getSignatureAsWritten());
Chris Lattner7099dbc2009-04-27 06:16:06 +00001094 Record.push_back(D->param_size());
David Majnemera3debed2016-06-24 05:33:44 +00001095 for (ParmVarDecl *P : D->parameters())
1096 Record.AddDeclRef(P);
John McCallcf6ce282012-04-13 17:33:29 +00001097 Record.push_back(D->isVariadic());
1098 Record.push_back(D->blockMissingReturnType());
1099 Record.push_back(D->isConversionFromLambda());
Akira Hatanakadb49a1f2018-08-01 23:51:53 +00001100 Record.push_back(D->doesNotEscape());
John McCallc63de662011-02-02 13:00:07 +00001101 Record.push_back(D->capturesCXXThis());
John McCall351762c2011-02-07 10:33:21 +00001102 Record.push_back(D->getNumCaptures());
Aaron Ballman9371dd22014-03-14 18:34:04 +00001103 for (const auto &capture : D->captures()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001104 Record.AddDeclRef(capture.getVariable());
John McCall351762c2011-02-07 10:33:21 +00001105
1106 unsigned flags = 0;
1107 if (capture.isByRef()) flags |= 1;
1108 if (capture.isNested()) flags |= 2;
1109 if (capture.hasCopyExpr()) flags |= 4;
1110 Record.push_back(flags);
1111
Richard Smith290d8012016-04-06 17:06:00 +00001112 if (capture.hasCopyExpr()) Record.AddStmt(capture.getCopyExpr());
John McCall351762c2011-02-07 10:33:21 +00001113 }
John McCallc63de662011-02-02 13:00:07 +00001114
Sebastian Redl539c5062010-08-18 23:57:32 +00001115 Code = serialization::DECL_BLOCK;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001116}
1117
Ben Langmuirce914fc2013-05-03 19:20:19 +00001118void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) {
1119 Record.push_back(CD->getNumParams());
1120 VisitDecl(CD);
Alexey Bataev9959db52014-05-06 10:08:46 +00001121 Record.push_back(CD->getContextParamPosition());
1122 Record.push_back(CD->isNothrow() ? 1 : 0);
Ben Langmuirce914fc2013-05-03 19:20:19 +00001123 // Body is stored by VisitCapturedStmt.
Alexey Bataev9959db52014-05-06 10:08:46 +00001124 for (unsigned I = 0; I < CD->getNumParams(); ++I)
Richard Smith69c82bf2016-04-01 22:52:03 +00001125 Record.AddDeclRef(CD->getParam(I));
Ben Langmuirce914fc2013-05-03 19:20:19 +00001126 Code = serialization::DECL_CAPTURED;
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001127}
1128
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001129void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001130 VisitDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001131 Record.push_back(D->getLanguage());
Richard Smith69c82bf2016-04-01 22:52:03 +00001132 Record.AddSourceLocation(D->getExternLoc());
1133 Record.AddSourceLocation(D->getRBraceLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001134 Code = serialization::DECL_LINKAGE_SPEC;
Chris Lattnerca025db2010-05-07 21:43:38 +00001135}
1136
Richard Smith8df390f2016-09-08 23:14:54 +00001137void ASTDeclWriter::VisitExportDecl(ExportDecl *D) {
1138 VisitDecl(D);
1139 Record.AddSourceLocation(D->getRBraceLoc());
1140 Code = serialization::DECL_EXPORT;
1141}
1142
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001143void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) {
1144 VisitNamedDecl(D);
Stephen Kellyf2ceec42018-08-09 21:08:08 +00001145 Record.AddSourceLocation(D->getBeginLoc());
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001146 Code = serialization::DECL_LABEL;
1147}
1148
1149
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001150void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
Douglas Gregore57e7522012-01-07 09:11:48 +00001151 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001152 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +00001153 Record.push_back(D->isInline());
Stephen Kellyf2ceec42018-08-09 21:08:08 +00001154 Record.AddSourceLocation(D->getBeginLoc());
Richard Smith69c82bf2016-04-01 22:52:03 +00001155 Record.AddSourceLocation(D->getRBraceLoc());
Chris Lattnerca025db2010-05-07 21:43:38 +00001156
Chris Lattnerca025db2010-05-07 21:43:38 +00001157 if (D->isOriginalNamespace())
Richard Smith69c82bf2016-04-01 22:52:03 +00001158 Record.AddDeclRef(D->getAnonymousNamespace());
Sebastian Redl539c5062010-08-18 23:57:32 +00001159 Code = serialization::DECL_NAMESPACE;
Sebastian Redlf03cdc52010-08-05 21:22:19 +00001160
Fangrui Song6907ce22018-07-30 19:24:48 +00001161 if (Writer.hasChain() && D->isAnonymousNamespace() &&
Douglas Gregorec9fd132012-01-14 16:38:05 +00001162 D == D->getMostRecentDecl()) {
Sebastian Redl010288f2011-04-24 16:28:21 +00001163 // This is a most recent reopening of the anonymous namespace. If its parent
1164 // is in a previous PCH (or is the TU), mark that parent for update, because
1165 // the original namespace always points to the latest re-opening of its
1166 // anonymous namespace.
1167 Decl *Parent = cast<Decl>(
1168 D->getParent()->getRedeclContext()->getPrimaryContext());
Douglas Gregorb3722e22011-09-09 23:01:35 +00001169 if (Parent->isFromASTFile() || isa<TranslationUnitDecl>(Parent)) {
Richard Smith6ef42932014-03-20 21:02:00 +00001170 Writer.DeclUpdates[Parent].push_back(
Aaron Ballman4f45b712014-03-21 15:22:56 +00001171 ASTWriter::DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, D));
Sebastian Redlfa1f3702011-04-24 16:28:13 +00001172 }
1173 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001174}
1175
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001176void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Richard Smithf4634362014-09-03 23:11:22 +00001177 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001178 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001179 Record.AddSourceLocation(D->getNamespaceLoc());
1180 Record.AddSourceLocation(D->getTargetNameLoc());
1181 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1182 Record.AddDeclRef(D->getNamespace());
Sebastian Redl539c5062010-08-18 23:57:32 +00001183 Code = serialization::DECL_NAMESPACE_ALIAS;
Chris Lattnerca025db2010-05-07 21:43:38 +00001184}
1185
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001186void ASTDeclWriter::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001187 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001188 Record.AddSourceLocation(D->getUsingLoc());
1189 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1190 Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
1191 Record.AddDeclRef(D->FirstUsingShadow.getPointer());
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00001192 Record.push_back(D->hasTypename());
Richard Smith69c82bf2016-04-01 22:52:03 +00001193 Record.AddDeclRef(Context.getInstantiatedFromUsingDecl(D));
Sebastian Redl539c5062010-08-18 23:57:32 +00001194 Code = serialization::DECL_USING;
Chris Lattnerca025db2010-05-07 21:43:38 +00001195}
1196
Richard Smith151c4562016-12-20 21:35:28 +00001197void ASTDeclWriter::VisitUsingPackDecl(UsingPackDecl *D) {
1198 Record.push_back(D->NumExpansions);
1199 VisitNamedDecl(D);
1200 Record.AddDeclRef(D->getInstantiatedFromUsingDecl());
1201 for (auto *E : D->expansions())
1202 Record.AddDeclRef(E);
1203 Code = serialization::DECL_USING_PACK;
1204}
1205
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001206void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) {
Richard Smithfd8634a2013-10-23 02:17:46 +00001207 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001208 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001209 Record.AddDeclRef(D->getTargetDecl());
Richard Smitha263c342018-01-06 01:07:05 +00001210 Record.push_back(D->getIdentifierNamespace());
Richard Smith69c82bf2016-04-01 22:52:03 +00001211 Record.AddDeclRef(D->UsingOrNextShadow);
1212 Record.AddDeclRef(Context.getInstantiatedFromUsingShadowDecl(D));
Sebastian Redl539c5062010-08-18 23:57:32 +00001213 Code = serialization::DECL_USING_SHADOW;
Chris Lattnerca025db2010-05-07 21:43:38 +00001214}
1215
Richard Smith5179eb72016-06-28 19:03:57 +00001216void ASTDeclWriter::VisitConstructorUsingShadowDecl(
1217 ConstructorUsingShadowDecl *D) {
1218 VisitUsingShadowDecl(D);
1219 Record.AddDeclRef(D->NominatedBaseClassShadowDecl);
1220 Record.AddDeclRef(D->ConstructedBaseClassShadowDecl);
1221 Record.push_back(D->IsVirtual);
1222 Code = serialization::DECL_CONSTRUCTOR_USING_SHADOW;
1223}
1224
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001225void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001226 VisitNamedDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001227 Record.AddSourceLocation(D->getUsingLoc());
1228 Record.AddSourceLocation(D->getNamespaceKeyLocation());
1229 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1230 Record.AddDeclRef(D->getNominatedNamespace());
1231 Record.AddDeclRef(dyn_cast<Decl>(D->getCommonAncestor()));
Sebastian Redl539c5062010-08-18 23:57:32 +00001232 Code = serialization::DECL_USING_DIRECTIVE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001233}
1234
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001235void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001236 VisitValueDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001237 Record.AddSourceLocation(D->getUsingLoc());
1238 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1239 Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
Richard Smith151c4562016-12-20 21:35:28 +00001240 Record.AddSourceLocation(D->getEllipsisLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001241 Code = serialization::DECL_UNRESOLVED_USING_VALUE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001242}
1243
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001244void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001245 UnresolvedUsingTypenameDecl *D) {
1246 VisitTypeDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001247 Record.AddSourceLocation(D->getTypenameLoc());
1248 Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
Richard Smith151c4562016-12-20 21:35:28 +00001249 Record.AddSourceLocation(D->getEllipsisLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001250 Code = serialization::DECL_UNRESOLVED_USING_TYPENAME;
Chris Lattnerca025db2010-05-07 21:43:38 +00001251}
1252
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001253void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001254 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001255
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001256 enum {
1257 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1258 };
1259 if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) {
1260 Record.push_back(CXXRecTemplate);
Richard Smith69c82bf2016-04-01 22:52:03 +00001261 Record.AddDeclRef(TemplD);
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001262 } else if (MemberSpecializationInfo *MSInfo
1263 = D->getMemberSpecializationInfo()) {
1264 Record.push_back(CXXRecMemberSpecialization);
Richard Smith69c82bf2016-04-01 22:52:03 +00001265 Record.AddDeclRef(MSInfo->getInstantiatedFrom());
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001266 Record.push_back(MSInfo->getTemplateSpecializationKind());
Richard Smith69c82bf2016-04-01 22:52:03 +00001267 Record.AddSourceLocation(MSInfo->getPointOfInstantiation());
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001268 } else {
1269 Record.push_back(CXXRecNotTemplate);
1270 }
1271
Richard Smithcd45dbc2014-04-19 03:48:30 +00001272 Record.push_back(D->isThisDeclarationADefinition());
1273 if (D->isThisDeclarationADefinition())
Richard Smith69c82bf2016-04-01 22:52:03 +00001274 Record.AddCXXDefinitionData(D);
Richard Smithcd45dbc2014-04-19 03:48:30 +00001275
John McCall6bd2a892013-01-25 22:31:03 +00001276 // Store (what we currently believe to be) the key function to avoid
1277 // deserializing every method so we can compute it.
Erich Keanef92f31c2018-08-01 20:48:16 +00001278 if (D->isCompleteDefinition())
Richard Smith69c82bf2016-04-01 22:52:03 +00001279 Record.AddDeclRef(Context.getCurrentKeyFunction(D));
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001280
Sebastian Redl539c5062010-08-18 23:57:32 +00001281 Code = serialization::DECL_CXX_RECORD;
Chris Lattnerca025db2010-05-07 21:43:38 +00001282}
1283
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001284void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001285 VisitFunctionDecl(D);
Argyrios Kyrtzidis3b1a7792012-10-12 05:31:40 +00001286 if (D->isCanonicalDecl()) {
1287 Record.push_back(D->size_overridden_methods());
Benjamin Krameracfa3392017-12-17 23:52:45 +00001288 for (const CXXMethodDecl *MD : D->overridden_methods())
1289 Record.AddDeclRef(MD);
Argyrios Kyrtzidis3b1a7792012-10-12 05:31:40 +00001290 } else {
1291 // We only need to record overridden methods once for the canonical decl.
1292 Record.push_back(0);
1293 }
Richard Smith01b2cb42014-07-26 06:37:51 +00001294
Richard Smith8aed4222015-12-11 22:41:00 +00001295 if (D->getDeclContext() == D->getLexicalDeclContext() &&
1296 D->getFirstDecl() == D->getMostRecentDecl() &&
Richard Smith01b2cb42014-07-26 06:37:51 +00001297 !D->isInvalidDecl() &&
1298 !D->hasAttrs() &&
1299 !D->isTopLevelDeclInObjCContainer() &&
1300 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
1301 !D->hasExtInfo() &&
1302 !D->hasInheritedPrototype() &&
1303 D->hasWrittenPrototype())
1304 AbbrevToUse = Writer.getDeclCXXMethodAbbrev();
1305
Sebastian Redl539c5062010-08-18 23:57:32 +00001306 Code = serialization::DECL_CXX_METHOD;
Chris Lattnerca025db2010-05-07 21:43:38 +00001307}
1308
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001309void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Richard Smith5179eb72016-06-28 19:03:57 +00001310 if (auto Inherited = D->getInheritedConstructor()) {
1311 Record.AddDeclRef(Inherited.getShadowDecl());
1312 Record.AddDeclRef(Inherited.getConstructor());
1313 Code = serialization::DECL_CXX_INHERITED_CONSTRUCTOR;
1314 } else {
1315 Code = serialization::DECL_CXX_CONSTRUCTOR;
1316 }
1317
Chris Lattnerca025db2010-05-07 21:43:38 +00001318 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001319
Richard Smith5179eb72016-06-28 19:03:57 +00001320 Code = D->isInheritingConstructor()
1321 ? serialization::DECL_CXX_INHERITED_CONSTRUCTOR
1322 : serialization::DECL_CXX_CONSTRUCTOR;
Chris Lattnerca025db2010-05-07 21:43:38 +00001323}
1324
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001325void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001326 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001327
Richard Smith69c82bf2016-04-01 22:52:03 +00001328 Record.AddDeclRef(D->getOperatorDelete());
Richard Smith5b349582017-10-13 01:55:36 +00001329 if (D->getOperatorDelete())
1330 Record.AddStmt(D->getOperatorDeleteThisArg());
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001331
Sebastian Redl539c5062010-08-18 23:57:32 +00001332 Code = serialization::DECL_CXX_DESTRUCTOR;
Chris Lattnerca025db2010-05-07 21:43:38 +00001333}
1334
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001335void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001336 VisitCXXMethodDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001337 Code = serialization::DECL_CXX_CONVERSION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001338}
1339
Douglas Gregorba345522011-12-02 23:23:56 +00001340void ASTDeclWriter::VisitImportDecl(ImportDecl *D) {
1341 VisitDecl(D);
Argyrios Kyrtzidis7b8e5552012-10-03 01:58:45 +00001342 Record.push_back(Writer.getSubmoduleID(D->getImportedModule()));
Douglas Gregorba345522011-12-02 23:23:56 +00001343 ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs();
1344 Record.push_back(!IdentifierLocs.empty());
1345 if (IdentifierLocs.empty()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001346 Record.AddSourceLocation(D->getLocEnd());
Douglas Gregorba345522011-12-02 23:23:56 +00001347 Record.push_back(1);
1348 } else {
1349 for (unsigned I = 0, N = IdentifierLocs.size(); I != N; ++I)
Richard Smith69c82bf2016-04-01 22:52:03 +00001350 Record.AddSourceLocation(IdentifierLocs[I]);
Douglas Gregorba345522011-12-02 23:23:56 +00001351 Record.push_back(IdentifierLocs.size());
1352 }
1353 // Note: the number of source locations must always be the last element in
1354 // the record.
1355 Code = serialization::DECL_IMPORT;
1356}
1357
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001358void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001359 VisitDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001360 Record.AddSourceLocation(D->getColonLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001361 Code = serialization::DECL_ACCESS_SPEC;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001362}
1363
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001364void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) {
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001365 // Record the number of friend type template parameter lists here
1366 // so as to simplify memory allocation during deserialization.
1367 Record.push_back(D->NumTPLists);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001368 VisitDecl(D);
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001369 bool hasFriendDecl = D->Friend.is<NamedDecl*>();
1370 Record.push_back(hasFriendDecl);
1371 if (hasFriendDecl)
Richard Smith69c82bf2016-04-01 22:52:03 +00001372 Record.AddDeclRef(D->getFriendDecl());
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001373 else
Richard Smith69c82bf2016-04-01 22:52:03 +00001374 Record.AddTypeSourceInfo(D->getFriendType());
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001375 for (unsigned i = 0; i < D->NumTPLists; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +00001376 Record.AddTemplateParameterList(D->getFriendTypeTemplateParameterList(i));
1377 Record.AddDeclRef(D->getNextFriend());
John McCall2c2eb122010-10-16 06:59:13 +00001378 Record.push_back(D->UnsupportedFriend);
Richard Smith69c82bf2016-04-01 22:52:03 +00001379 Record.AddSourceLocation(D->FriendLoc);
Sebastian Redl539c5062010-08-18 23:57:32 +00001380 Code = serialization::DECL_FRIEND;
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001381}
1382
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001383void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001384 VisitDecl(D);
1385 Record.push_back(D->getNumTemplateParameters());
1386 for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i)
Richard Smith69c82bf2016-04-01 22:52:03 +00001387 Record.AddTemplateParameterList(D->getTemplateParameterList(i));
Craig Toppera13603a2014-05-22 05:54:18 +00001388 Record.push_back(D->getFriendDecl() != nullptr);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001389 if (D->getFriendDecl())
Richard Smith69c82bf2016-04-01 22:52:03 +00001390 Record.AddDeclRef(D->getFriendDecl());
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001391 else
Richard Smith69c82bf2016-04-01 22:52:03 +00001392 Record.AddTypeSourceInfo(D->getFriendType());
1393 Record.AddSourceLocation(D->getFriendLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001394 Code = serialization::DECL_FRIEND_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001395}
1396
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001397void ASTDeclWriter::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001398 VisitNamedDecl(D);
1399
Richard Smith69c82bf2016-04-01 22:52:03 +00001400 Record.AddDeclRef(D->getTemplatedDecl());
1401 Record.AddTemplateParameterList(D->getTemplateParameters());
Chris Lattnerca025db2010-05-07 21:43:38 +00001402}
1403
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001404void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Douglas Gregor68444de2012-01-14 15:13:49 +00001405 VisitRedeclarable(D);
1406
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001407 // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that
1408 // getCommonPtr() can be used while this is still initializing.
Rafael Espindola8db352d2013-10-17 15:37:26 +00001409 if (D->isFirstDecl()) {
Douglas Gregor074a4092011-12-19 18:19:24 +00001410 // This declaration owns the 'common' pointer, so serialize that data now.
Richard Smith69c82bf2016-04-01 22:52:03 +00001411 Record.AddDeclRef(D->getInstantiatedFromMemberTemplate());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001412 if (D->getInstantiatedFromMemberTemplate())
1413 Record.push_back(D->isMemberSpecialization());
Douglas Gregor074a4092011-12-19 18:19:24 +00001414 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001415
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001416 VisitTemplateDecl(D);
1417 Record.push_back(D->getIdentifierNamespace());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001418}
1419
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001420void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001421 VisitRedeclarableTemplateDecl(D);
1422
Richard Smith509fc852015-02-27 23:05:10 +00001423 if (D->isFirstDecl())
1424 AddTemplateSpecializations(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001425 Code = serialization::DECL_CLASS_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001426}
1427
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001428void ASTDeclWriter::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001429 ClassTemplateSpecializationDecl *D) {
Richard Smithd8a83712015-08-22 01:47:18 +00001430 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1431
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001432 VisitCXXRecordDecl(D);
1433
1434 llvm::PointerUnion<ClassTemplateDecl *,
1435 ClassTemplatePartialSpecializationDecl *> InstFrom
1436 = D->getSpecializedTemplateOrPartial();
Argyrios Kyrtzidisd5553f12011-08-17 21:35:28 +00001437 if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001438 Record.AddDeclRef(InstFromD);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001439 } else {
Richard Smith69c82bf2016-04-01 22:52:03 +00001440 Record.AddDeclRef(InstFrom.get<ClassTemplatePartialSpecializationDecl *>());
1441 Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001442 }
1443
Richard Smith69c82bf2016-04-01 22:52:03 +00001444 Record.AddTemplateArgumentList(&D->getTemplateArgs());
1445 Record.AddSourceLocation(D->getPointOfInstantiation());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001446 Record.push_back(D->getSpecializationKind());
Axel Naumanna31dee22012-10-01 07:34:47 +00001447 Record.push_back(D->isCanonicalDecl());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001448
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001449 if (D->isCanonicalDecl()) {
Fangrui Song6907ce22018-07-30 19:24:48 +00001450 // When reading, we'll add it to the folding set of the following template.
Richard Smith69c82bf2016-04-01 22:52:03 +00001451 Record.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl());
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001452 }
1453
Richard Smithd55889a2013-09-09 16:55:27 +00001454 // Explicit info.
Richard Smith69c82bf2016-04-01 22:52:03 +00001455 Record.AddTypeSourceInfo(D->getTypeAsWritten());
Richard Smithd55889a2013-09-09 16:55:27 +00001456 if (D->getTypeAsWritten()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001457 Record.AddSourceLocation(D->getExternLoc());
1458 Record.AddSourceLocation(D->getTemplateKeywordLoc());
Richard Smithd55889a2013-09-09 16:55:27 +00001459 }
1460
Sebastian Redl539c5062010-08-18 23:57:32 +00001461 Code = serialization::DECL_CLASS_TEMPLATE_SPECIALIZATION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001462}
1463
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001464void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001465 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001466 VisitClassTemplateSpecializationDecl(D);
1467
Richard Smith69c82bf2016-04-01 22:52:03 +00001468 Record.AddTemplateParameterList(D->getTemplateParameters());
1469 Record.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001470
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001471 // These are read/set from/to the first declaration.
Craig Toppera13603a2014-05-22 05:54:18 +00001472 if (D->getPreviousDecl() == nullptr) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001473 Record.AddDeclRef(D->getInstantiatedFromMember());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001474 Record.push_back(D->isMemberSpecialization());
1475 }
1476
Sebastian Redl539c5062010-08-18 23:57:32 +00001477 Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001478}
1479
Larisse Voufo39a1e502013-08-06 01:03:05 +00001480void ASTDeclWriter::VisitVarTemplateDecl(VarTemplateDecl *D) {
1481 VisitRedeclarableTemplateDecl(D);
1482
Richard Smith509fc852015-02-27 23:05:10 +00001483 if (D->isFirstDecl())
1484 AddTemplateSpecializations(D);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001485 Code = serialization::DECL_VAR_TEMPLATE;
1486}
1487
1488void ASTDeclWriter::VisitVarTemplateSpecializationDecl(
1489 VarTemplateSpecializationDecl *D) {
Richard Smithd8a83712015-08-22 01:47:18 +00001490 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1491
Larisse Voufo39a1e502013-08-06 01:03:05 +00001492 VisitVarDecl(D);
1493
1494 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
1495 InstFrom = D->getSpecializedTemplateOrPartial();
1496 if (Decl *InstFromD = InstFrom.dyn_cast<VarTemplateDecl *>()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001497 Record.AddDeclRef(InstFromD);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001498 } else {
Richard Smith69c82bf2016-04-01 22:52:03 +00001499 Record.AddDeclRef(InstFrom.get<VarTemplatePartialSpecializationDecl *>());
1500 Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001501 }
1502
1503 // Explicit info.
Richard Smith69c82bf2016-04-01 22:52:03 +00001504 Record.AddTypeSourceInfo(D->getTypeAsWritten());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001505 if (D->getTypeAsWritten()) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001506 Record.AddSourceLocation(D->getExternLoc());
1507 Record.AddSourceLocation(D->getTemplateKeywordLoc());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001508 }
1509
Richard Smith69c82bf2016-04-01 22:52:03 +00001510 Record.AddTemplateArgumentList(&D->getTemplateArgs());
1511 Record.AddSourceLocation(D->getPointOfInstantiation());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001512 Record.push_back(D->getSpecializationKind());
Richard Smith435e6472017-12-02 02:48:42 +00001513 Record.push_back(D->IsCompleteDefinition);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001514 Record.push_back(D->isCanonicalDecl());
1515
1516 if (D->isCanonicalDecl()) {
1517 // When reading, we'll add it to the folding set of the following template.
Richard Smith69c82bf2016-04-01 22:52:03 +00001518 Record.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001519 }
1520
1521 Code = serialization::DECL_VAR_TEMPLATE_SPECIALIZATION;
1522}
1523
1524void ASTDeclWriter::VisitVarTemplatePartialSpecializationDecl(
1525 VarTemplatePartialSpecializationDecl *D) {
1526 VisitVarTemplateSpecializationDecl(D);
1527
Richard Smith69c82bf2016-04-01 22:52:03 +00001528 Record.AddTemplateParameterList(D->getTemplateParameters());
1529 Record.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001530
1531 // These are read/set from/to the first declaration.
Craig Toppera13603a2014-05-22 05:54:18 +00001532 if (D->getPreviousDecl() == nullptr) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001533 Record.AddDeclRef(D->getInstantiatedFromMember());
Larisse Voufo39a1e502013-08-06 01:03:05 +00001534 Record.push_back(D->isMemberSpecialization());
1535 }
1536
1537 Code = serialization::DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION;
1538}
1539
Fariborz Jahanian3a039e32011-08-27 20:50:59 +00001540void ASTDeclWriter::VisitClassScopeFunctionSpecializationDecl(
1541 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichet09af8c32011-08-17 01:06:54 +00001542 VisitDecl(D);
Richard Smith69c82bf2016-04-01 22:52:03 +00001543 Record.AddDeclRef(D->getSpecialization());
Francois Pichet09af8c32011-08-17 01:06:54 +00001544 Code = serialization::DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION;
1545}
1546
1547
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001548void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001549 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001550
Richard Smith509fc852015-02-27 23:05:10 +00001551 if (D->isFirstDecl())
1552 AddTemplateSpecializations(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001553 Code = serialization::DECL_FUNCTION_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001554}
1555
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001556void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001557 VisitTypeDecl(D);
1558
1559 Record.push_back(D->wasDeclaredWithTypename());
Richard Smith8346e522015-06-10 01:47:58 +00001560
1561 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1562 !D->defaultArgumentWasInherited();
1563 Record.push_back(OwnsDefaultArg);
1564 if (OwnsDefaultArg)
Richard Smith69c82bf2016-04-01 22:52:03 +00001565 Record.AddTypeSourceInfo(D->getDefaultArgumentInfo());
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001566
Sebastian Redl539c5062010-08-18 23:57:32 +00001567 Code = serialization::DECL_TEMPLATE_TYPE_PARM;
Chris Lattnerca025db2010-05-07 21:43:38 +00001568}
1569
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001570void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001571 // For an expanded parameter pack, record the number of expansion types here
Richard Smith1fde8ec2012-09-07 02:06:42 +00001572 // so that it's easier for deserialization to allocate the right amount of
1573 // memory.
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001574 if (D->isExpandedParameterPack())
1575 Record.push_back(D->getNumExpansionTypes());
Fangrui Song6907ce22018-07-30 19:24:48 +00001576
John McCallf4cd4f92011-02-09 01:13:10 +00001577 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001578 // TemplateParmPosition.
1579 Record.push_back(D->getDepth());
1580 Record.push_back(D->getPosition());
Fangrui Song6907ce22018-07-30 19:24:48 +00001581
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001582 if (D->isExpandedParameterPack()) {
1583 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
Richard Smith69c82bf2016-04-01 22:52:03 +00001584 Record.AddTypeRef(D->getExpansionType(I));
1585 Record.AddTypeSourceInfo(D->getExpansionTypeSourceInfo(I));
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001586 }
Fangrui Song6907ce22018-07-30 19:24:48 +00001587
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001588 Code = serialization::DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK;
1589 } else {
1590 // Rest of NonTypeTemplateParmDecl.
1591 Record.push_back(D->isParameterPack());
Richard Smith8346e522015-06-10 01:47:58 +00001592 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1593 !D->defaultArgumentWasInherited();
1594 Record.push_back(OwnsDefaultArg);
1595 if (OwnsDefaultArg)
Richard Smith290d8012016-04-06 17:06:00 +00001596 Record.AddStmt(D->getDefaultArgument());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001597 Code = serialization::DECL_NON_TYPE_TEMPLATE_PARM;
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001598 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001599}
1600
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001601void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Richard Smith1fde8ec2012-09-07 02:06:42 +00001602 // For an expanded parameter pack, record the number of expansion types here
1603 // so that it's easier for deserialization to allocate the right amount of
1604 // memory.
1605 if (D->isExpandedParameterPack())
1606 Record.push_back(D->getNumExpansionTemplateParameters());
1607
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001608 VisitTemplateDecl(D);
1609 // TemplateParmPosition.
1610 Record.push_back(D->getDepth());
1611 Record.push_back(D->getPosition());
Richard Smith1fde8ec2012-09-07 02:06:42 +00001612
1613 if (D->isExpandedParameterPack()) {
1614 for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
1615 I != N; ++I)
Richard Smith69c82bf2016-04-01 22:52:03 +00001616 Record.AddTemplateParameterList(D->getExpansionTemplateParameters(I));
Richard Smith1fde8ec2012-09-07 02:06:42 +00001617 Code = serialization::DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK;
1618 } else {
1619 // Rest of TemplateTemplateParmDecl.
Richard Smith1fde8ec2012-09-07 02:06:42 +00001620 Record.push_back(D->isParameterPack());
Richard Smith8346e522015-06-10 01:47:58 +00001621 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1622 !D->defaultArgumentWasInherited();
1623 Record.push_back(OwnsDefaultArg);
1624 if (OwnsDefaultArg)
Richard Smith69c82bf2016-04-01 22:52:03 +00001625 Record.AddTemplateArgumentLoc(D->getDefaultArgument());
Richard Smith1fde8ec2012-09-07 02:06:42 +00001626 Code = serialization::DECL_TEMPLATE_TEMPLATE_PARM;
1627 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001628}
1629
Richard Smith3f1b5d02011-05-05 21:57:07 +00001630void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1631 VisitRedeclarableTemplateDecl(D);
1632 Code = serialization::DECL_TYPE_ALIAS_TEMPLATE;
1633}
1634
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001635void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001636 VisitDecl(D);
Richard Smith290d8012016-04-06 17:06:00 +00001637 Record.AddStmt(D->getAssertExpr());
Richard Smithded9c2e2012-07-11 22:37:56 +00001638 Record.push_back(D->isFailed());
Richard Smith290d8012016-04-06 17:06:00 +00001639 Record.AddStmt(D->getMessage());
Richard Smith69c82bf2016-04-01 22:52:03 +00001640 Record.AddSourceLocation(D->getRParenLoc());
Sebastian Redl539c5062010-08-18 23:57:32 +00001641 Code = serialization::DECL_STATIC_ASSERT;
Chris Lattnerca025db2010-05-07 21:43:38 +00001642}
1643
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00001644/// Emit the DeclContext part of a declaration context decl.
Richard Smithf1c23dc2016-04-13 02:12:03 +00001645void ASTDeclWriter::VisitDeclContext(DeclContext *DC) {
1646 Record.AddOffset(Writer.WriteDeclContextLexicalBlock(Context, DC));
1647 Record.AddOffset(Writer.WriteDeclContextVisibleBlock(Context, DC));
Chris Lattner7099dbc2009-04-27 06:16:06 +00001648}
1649
Richard Smithd8a83712015-08-22 01:47:18 +00001650const Decl *ASTWriter::getFirstLocalDecl(const Decl *D) {
Richard Smith3864be72015-09-11 02:22:03 +00001651 assert(IsLocalDecl(D) && "expected a local declaration");
Richard Smithd8a83712015-08-22 01:47:18 +00001652
1653 const Decl *Canon = D->getCanonicalDecl();
Richard Smith3864be72015-09-11 02:22:03 +00001654 if (IsLocalDecl(Canon))
Richard Smithd8a83712015-08-22 01:47:18 +00001655 return Canon;
1656
1657 const Decl *&CacheEntry = FirstLocalDeclCache[Canon];
1658 if (CacheEntry)
1659 return CacheEntry;
1660
1661 for (const Decl *Redecl = D; Redecl; Redecl = Redecl->getPreviousDecl())
Richard Smith3864be72015-09-11 02:22:03 +00001662 if (IsLocalDecl(Redecl))
Richard Smithd8a83712015-08-22 01:47:18 +00001663 D = Redecl;
1664 return CacheEntry = D;
Richard Smith5fc18a92015-07-12 23:43:21 +00001665}
1666
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001667template <typename T>
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001668void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +00001669 T *First = D->getFirstDecl();
Richard Smith5a4737c2015-02-06 02:42:59 +00001670 T *MostRecent = First->getMostRecentDecl();
Richard Smithd8a83712015-08-22 01:47:18 +00001671 T *DAsT = static_cast<T *>(D);
Richard Smith5a4737c2015-02-06 02:42:59 +00001672 if (MostRecent != First) {
Richard Smithd8a83712015-08-22 01:47:18 +00001673 assert(isRedeclarableDeclKind(DAsT->getKind()) &&
Douglas Gregorfe732d52013-01-21 16:16:40 +00001674 "Not considered redeclarable?");
Richard Smith5a4737c2015-02-06 02:42:59 +00001675
Richard Smith69c82bf2016-04-01 22:52:03 +00001676 Record.AddDeclRef(First);
Richard Smithfe620d22015-03-05 23:24:12 +00001677
Richard Smithd8a83712015-08-22 01:47:18 +00001678 // Write out a list of local redeclarations of this declaration if it's the
1679 // first local declaration in the chain.
1680 const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1681 if (DAsT == FirstLocal) {
Richard Smithd8a83712015-08-22 01:47:18 +00001682 // Emit a list of all imported first declarations so that we can be sure
1683 // that all redeclarations visible to this module are before D in the
1684 // redecl chain.
1685 unsigned I = Record.size();
1686 Record.push_back(0);
1687 if (Writer.Chain)
1688 AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1689 // This is the number of imported first declarations + 1.
1690 Record[I] = Record.size() - I;
Richard Smithd61d4ac2015-08-22 20:13:39 +00001691
1692 // Collect the set of local redeclarations of this declaration, from
1693 // newest to oldest.
Richard Smith69c82bf2016-04-01 22:52:03 +00001694 ASTWriter::RecordData LocalRedecls;
1695 ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls);
Richard Smithd61d4ac2015-08-22 20:13:39 +00001696 for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1697 Prev != FirstLocal; Prev = Prev->getPreviousDecl())
1698 if (!Prev->isFromASTFile())
Richard Smith69c82bf2016-04-01 22:52:03 +00001699 LocalRedeclWriter.AddDeclRef(Prev);
Richard Smithd61d4ac2015-08-22 20:13:39 +00001700
1701 // If we have any redecls, write them now as a separate record preceding
1702 // the declaration itself.
1703 if (LocalRedecls.empty())
1704 Record.push_back(0);
Richard Smithf1c23dc2016-04-13 02:12:03 +00001705 else
1706 Record.AddOffset(LocalRedeclWriter.Emit(LOCAL_REDECLARATIONS));
Richard Smithd8a83712015-08-22 01:47:18 +00001707 } else {
1708 Record.push_back(0);
Richard Smith69c82bf2016-04-01 22:52:03 +00001709 Record.AddDeclRef(FirstLocal);
Richard Smithfe620d22015-03-05 23:24:12 +00001710 }
Douglas Gregor358cd442012-01-15 16:58:34 +00001711
Fangrui Song6907ce22018-07-30 19:24:48 +00001712 // Make sure that we serialize both the previous and the most-recent
Douglas Gregor358cd442012-01-15 16:58:34 +00001713 // declarations, which (transitively) ensures that all declarations in the
1714 // chain get serialized.
Richard Smith5a4737c2015-02-06 02:42:59 +00001715 //
1716 // FIXME: This is not correct; when we reach an imported declaration we
1717 // won't emit its previous declaration.
Richard Smith5fc18a92015-07-12 23:43:21 +00001718 (void)Writer.GetDeclRef(D->getPreviousDecl());
Richard Smith5a4737c2015-02-06 02:42:59 +00001719 (void)Writer.GetDeclRef(MostRecent);
Douglas Gregor358cd442012-01-15 16:58:34 +00001720 } else {
1721 // We use the sentinel value 0 to indicate an only declaration.
1722 Record.push_back(0);
Douglas Gregor9f562c82011-12-19 15:27:36 +00001723 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001724}
Chris Lattner7099dbc2009-04-27 06:16:06 +00001725
Alexey Bataeva769e072013-03-22 06:34:35 +00001726void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
1727 Record.push_back(D->varlist_size());
1728 VisitDecl(D);
Aaron Ballman2205d2a2014-03-14 15:55:35 +00001729 for (auto *I : D->varlists())
Richard Smith290d8012016-04-06 17:06:00 +00001730 Record.AddStmt(I);
Alexey Bataeva769e072013-03-22 06:34:35 +00001731 Code = serialization::DECL_OMP_THREADPRIVATE;
1732}
1733
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00001734void ASTDeclWriter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
Alexey Bataevc5b1d322016-03-04 09:22:22 +00001735 VisitValueDecl(D);
Stephen Kellyf2ceec42018-08-09 21:08:08 +00001736 Record.AddSourceLocation(D->getBeginLoc());
Richard Smith290d8012016-04-06 17:06:00 +00001737 Record.AddStmt(D->getCombiner());
1738 Record.AddStmt(D->getInitializer());
Alexey Bataev070f43a2017-09-06 14:49:58 +00001739 Record.push_back(D->getInitializerKind());
Richard Smith69c82bf2016-04-01 22:52:03 +00001740 Record.AddDeclRef(D->getPrevDeclInScope());
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00001741 Code = serialization::DECL_OMP_DECLARE_REDUCTION;
1742}
1743
Alexey Bataev4244be22016-02-11 05:35:55 +00001744void ASTDeclWriter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
Alexey Bataev90c228f2016-02-08 09:29:13 +00001745 VisitVarDecl(D);
Alexey Bataev4244be22016-02-11 05:35:55 +00001746 Code = serialization::DECL_OMP_CAPTUREDEXPR;
Alexey Bataev90c228f2016-02-08 09:29:13 +00001747}
1748
Chris Lattner7099dbc2009-04-27 06:16:06 +00001749//===----------------------------------------------------------------------===//
Sebastian Redl55c0ad52010-08-18 23:56:21 +00001750// ASTWriter Implementation
Chris Lattner7099dbc2009-04-27 06:16:06 +00001751//===----------------------------------------------------------------------===//
1752
Richard Smith01b2cb42014-07-26 06:37:51 +00001753void ASTWriter::WriteDeclAbbrevs() {
Chris Lattner258172e2009-04-27 07:35:58 +00001754 using namespace llvm;
Chris Lattner258172e2009-04-27 07:35:58 +00001755
David Blaikieb44f0bf2017-01-04 22:36:43 +00001756 std::shared_ptr<BitCodeAbbrev> Abv;
Douglas Gregor03412ba2011-06-03 02:27:19 +00001757
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001758 // Abbreviation for DECL_FIELD
David Blaikieb44f0bf2017-01-04 22:36:43 +00001759 Abv = std::make_shared<BitCodeAbbrev>();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001760 Abv->Add(BitCodeAbbrevOp(serialization::DECL_FIELD));
1761 // Decl
1762 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001763 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001764 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001765 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1766 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1767 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1768 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001769 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001770 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001771 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001772 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001773 // NamedDecl
1774 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1775 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001776 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001777 // ValueDecl
1778 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1779 // DeclaratorDecl
1780 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1781 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Richard Smithc23d7342018-06-29 20:46:25 +00001782 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001783 // FieldDecl
1784 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
Richard Smith6b8e3c02017-08-28 00:28:14 +00001785 Abv->Add(BitCodeAbbrevOp(0)); // InitStyle
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001786 // Type Source Info
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001787 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1788 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
David Blaikieb44f0bf2017-01-04 22:36:43 +00001789 DeclFieldAbbrev = Stream.EmitAbbrev(std::move(Abv));
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001790
1791 // Abbreviation for DECL_OBJC_IVAR
David Blaikieb44f0bf2017-01-04 22:36:43 +00001792 Abv = std::make_shared<BitCodeAbbrev>();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001793 Abv->Add(BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR));
1794 // Decl
1795 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001796 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001797 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001798 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1799 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1800 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1801 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001802 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001803 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001804 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001805 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001806 // NamedDecl
1807 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1808 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001809 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001810 // ValueDecl
1811 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1812 // DeclaratorDecl
1813 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1814 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Richard Smithc23d7342018-06-29 20:46:25 +00001815 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001816 // FieldDecl
1817 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
Richard Smith6b8e3c02017-08-28 00:28:14 +00001818 Abv->Add(BitCodeAbbrevOp(0)); // InitStyle
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001819 // ObjC Ivar
1820 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl
1821 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize
1822 // Type Source Info
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001823 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1824 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
David Blaikieb44f0bf2017-01-04 22:36:43 +00001825 DeclObjCIvarAbbrev = Stream.EmitAbbrev(std::move(Abv));
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001826
1827 // Abbreviation for DECL_ENUM
David Blaikieb44f0bf2017-01-04 22:36:43 +00001828 Abv = std::make_shared<BitCodeAbbrev>();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001829 Abv->Add(BitCodeAbbrevOp(serialization::DECL_ENUM));
Douglas Gregor3e300102011-10-26 17:53:41 +00001830 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001831 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Chris Lattner258172e2009-04-27 07:35:58 +00001832 // Decl
1833 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001834 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001835 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Chris Lattner258172e2009-04-27 07:35:58 +00001836 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1837 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
Douglas Gregorc9c02ed2009-06-19 23:52:42 +00001838 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +00001839 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001840 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Chris Lattner258172e2009-04-27 07:35:58 +00001841 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001842 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001843 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Douglas Gregor03412ba2011-06-03 02:27:19 +00001844 // NamedDecl
1845 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1846 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001847 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001848 // TypeDecl
1849 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1850 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001851 // TagDecl
1852 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
1853 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
John McCallf937c022011-10-07 06:10:15 +00001854 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001855 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +00001856 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
David Blaikiea8d23ce2013-07-14 01:07:41 +00001857 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001858 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Argyrios Kyrtzidisd798c052016-07-15 18:11:33 +00001859 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Richard Smith70d58502014-08-30 00:04:23 +00001860 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001861 // EnumDecl
1862 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddTypeRef
1863 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IntegerType
1864 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getPromotionType
1865 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumPositiveBits
1866 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumNegativeBits
1867 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScoped
1868 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScopedUsingClassTag
1869 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isFixed
Richard Trieuab4d7302018-07-25 22:52:05 +00001870 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));// ODRHash
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001871 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedMembEnum
1872 // DC
1873 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
1874 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
David Blaikieb44f0bf2017-01-04 22:36:43 +00001875 DeclEnumAbbrev = Stream.EmitAbbrev(std::move(Abv));
Mike Stump11289f42009-09-09 15:08:12 +00001876
Douglas Gregor03412ba2011-06-03 02:27:19 +00001877 // Abbreviation for DECL_RECORD
David Blaikieb44f0bf2017-01-04 22:36:43 +00001878 Abv = std::make_shared<BitCodeAbbrev>();
Douglas Gregor03412ba2011-06-03 02:27:19 +00001879 Abv->Add(BitCodeAbbrevOp(serialization::DECL_RECORD));
Douglas Gregor3e300102011-10-26 17:53:41 +00001880 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001881 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Douglas Gregor03412ba2011-06-03 02:27:19 +00001882 // Decl
1883 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001884 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001885 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Douglas Gregor03412ba2011-06-03 02:27:19 +00001886 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1887 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1888 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1889 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001890 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Douglas Gregor03412ba2011-06-03 02:27:19 +00001891 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001892 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001893 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Douglas Gregor03412ba2011-06-03 02:27:19 +00001894 // NamedDecl
1895 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1896 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001897 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Douglas Gregor03412ba2011-06-03 02:27:19 +00001898 // TypeDecl
1899 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1900 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
Douglas Gregor03412ba2011-06-03 02:27:19 +00001901 // TagDecl
1902 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
1903 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
John McCallf937c022011-10-07 06:10:15 +00001904 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
Douglas Gregor03412ba2011-06-03 02:27:19 +00001905 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +00001906 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
David Blaikiea8d23ce2013-07-14 01:07:41 +00001907 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
Douglas Gregor03412ba2011-06-03 02:27:19 +00001908 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Argyrios Kyrtzidisd798c052016-07-15 18:11:33 +00001909 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Richard Smith70d58502014-08-30 00:04:23 +00001910 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
Douglas Gregor03412ba2011-06-03 02:27:19 +00001911 // RecordDecl
1912 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // FlexibleArrayMember
1913 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // AnonymousStructUnion
1914 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasObjectMember
Fariborz Jahanian78652202013-01-25 23:57:05 +00001915 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasVolatileMember
Akira Hatanaka34fb2642018-03-13 18:58:25 +00001916
1917 // isNonTrivialToPrimitiveDefaultInitialize
1918 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
1919 // isNonTrivialToPrimitiveCopy
1920 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
1921 // isNonTrivialToPrimitiveDestroy
1922 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
Akira Hatanakafcbe17c2018-03-28 21:13:14 +00001923 // isParamDestroyedInCallee
1924 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
Akira Hatanakae6313ac2018-04-09 22:48:22 +00001925 // getArgPassingRestrictions
1926 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2));
Akira Hatanaka34fb2642018-03-13 18:58:25 +00001927
Douglas Gregor03412ba2011-06-03 02:27:19 +00001928 // DC
1929 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
1930 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
David Blaikieb44f0bf2017-01-04 22:36:43 +00001931 DeclRecordAbbrev = Stream.EmitAbbrev(std::move(Abv));
Douglas Gregor03412ba2011-06-03 02:27:19 +00001932
1933 // Abbreviation for DECL_PARM_VAR
David Blaikieb44f0bf2017-01-04 22:36:43 +00001934 Abv = std::make_shared<BitCodeAbbrev>();
Douglas Gregor03412ba2011-06-03 02:27:19 +00001935 Abv->Add(BitCodeAbbrevOp(serialization::DECL_PARM_VAR));
Douglas Gregor3e300102011-10-26 17:53:41 +00001936 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001937 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Douglas Gregor03412ba2011-06-03 02:27:19 +00001938 // Decl
1939 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001940 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001941 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Douglas Gregor03412ba2011-06-03 02:27:19 +00001942 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1943 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1944 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1945 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001946 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Douglas Gregor03412ba2011-06-03 02:27:19 +00001947 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001948 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001949 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Chris Lattner258172e2009-04-27 07:35:58 +00001950 // NamedDecl
1951 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1952 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001953 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Chris Lattner258172e2009-04-27 07:35:58 +00001954 // ValueDecl
1955 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +00001956 // DeclaratorDecl
Abramo Bagnaradff19302011-03-08 08:55:46 +00001957 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00001958 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Richard Smithc23d7342018-06-29 20:46:25 +00001959 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
Chris Lattner258172e2009-04-27 07:35:58 +00001960 // VarDecl
Vassil Vassilevd1a88132016-10-06 13:04:54 +00001961 Abv->Add(BitCodeAbbrevOp(0)); // SClass
1962 Abv->Add(BitCodeAbbrevOp(0)); // TSCSpec
1963 Abv->Add(BitCodeAbbrevOp(0)); // InitStyle
Richard Smith88581592013-02-12 05:48:23 +00001964 Abv->Add(BitCodeAbbrevOp(0)); // Linkage
Chris Lattner258172e2009-04-27 07:35:58 +00001965 Abv->Add(BitCodeAbbrevOp(0)); // HasInit
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001966 Abv->Add(BitCodeAbbrevOp(0)); // HasMemberSpecializationInfo
Chris Lattner258172e2009-04-27 07:35:58 +00001967 // ParmVarDecl
John McCall82490832011-05-02 00:30:12 +00001968 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsObjCMethodParameter
John McCall8fb0d9d2011-05-01 22:35:37 +00001969 Abv->Add(BitCodeAbbrevOp(0)); // ScopeDepth
1970 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex
Chris Lattner258172e2009-04-27 07:35:58 +00001971 Abv->Add(BitCodeAbbrevOp(0)); // ObjCDeclQualifier
John McCall6a014d52011-03-09 04:22:44 +00001972 Abv->Add(BitCodeAbbrevOp(0)); // KNRPromoted
John McCallf3cd6652010-03-12 18:31:32 +00001973 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedDefaultArg
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +00001974 Abv->Add(BitCodeAbbrevOp(0)); // HasUninstantiatedDefaultArg
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001975 // Type Source Info
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001976 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1977 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
David Blaikieb44f0bf2017-01-04 22:36:43 +00001978 DeclParmVarAbbrev = Stream.EmitAbbrev(std::move(Abv));
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001979
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00001980 // Abbreviation for DECL_TYPEDEF
David Blaikieb44f0bf2017-01-04 22:36:43 +00001981 Abv = std::make_shared<BitCodeAbbrev>();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001982 Abv->Add(BitCodeAbbrevOp(serialization::DECL_TYPEDEF));
Douglas Gregor05f10352011-12-17 23:38:30 +00001983 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001984 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001985 // Decl
1986 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001987 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001988 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001989 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1990 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
Richard Smith01b2cb42014-07-26 06:37:51 +00001991 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isUsed
1992 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001993 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Richard Smith01b2cb42014-07-26 06:37:51 +00001994 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001995 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001996 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001997 // NamedDecl
1998 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1999 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00002000 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002001 // TypeDecl
2002 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2003 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
2004 // TypedefDecl
2005 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2006 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
David Blaikieb44f0bf2017-01-04 22:36:43 +00002007 DeclTypedefAbbrev = Stream.EmitAbbrev(std::move(Abv));
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002008
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00002009 // Abbreviation for DECL_VAR
David Blaikieb44f0bf2017-01-04 22:36:43 +00002010 Abv = std::make_shared<BitCodeAbbrev>();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002011 Abv->Add(BitCodeAbbrevOp(serialization::DECL_VAR));
Douglas Gregor3e300102011-10-26 17:53:41 +00002012 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00002013 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002014 // Decl
2015 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00002016 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00002017 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002018 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
2019 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
2020 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
2021 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00002022 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002023 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00002024 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00002025 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002026 // NamedDecl
2027 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2028 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00002029 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002030 // ValueDecl
2031 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2032 // DeclaratorDecl
2033 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
2034 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Richard Smithc23d7342018-06-29 20:46:25 +00002035 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002036 // VarDecl
Vassil Vassilevd1a88132016-10-06 13:04:54 +00002037 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // SClass
2038 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // TSCSpec
2039 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // InitStyle
Richard Smithedbc6e92016-10-14 21:41:24 +00002040 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsThisDeclarationADemotedDefinition
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002041 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isExceptionVariable
Taiju Tsuiki3be68e12018-06-19 05:35:30 +00002042 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isNRVOVariable
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002043 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCXXForRangeDecl
George Karpenkovec38cf72018-03-29 00:56:24 +00002044 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isObjCForDecl
John McCalld4631322011-06-17 06:42:21 +00002045 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong
Richard Smith62f19e72016-06-25 00:15:56 +00002046 Abv->Add(BitCodeAbbrevOp(0)); // isInline
2047 Abv->Add(BitCodeAbbrevOp(0)); // isInlineSpecified
Douglas Gregor12cda632012-09-20 23:43:29 +00002048 Abv->Add(BitCodeAbbrevOp(0)); // isConstexpr
Richard Smithbb13c9a2013-09-28 04:02:39 +00002049 Abv->Add(BitCodeAbbrevOp(0)); // isInitCapture
Richard Smith1c34fb72013-08-13 18:18:50 +00002050 Abv->Add(BitCodeAbbrevOp(0)); // isPrevDeclInSameScope
Alexey Bataev56223232017-06-09 13:40:18 +00002051 Abv->Add(BitCodeAbbrevOp(0)); // ImplicitParamKind
Rafael Espindola50df3a02013-05-25 17:16:20 +00002052 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
Vassil Vassilevd1a88132016-10-06 13:04:54 +00002053 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // IsInitICE (local)
2054 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // VarKind (local enum)
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002055 // Type Source Info
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002056 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2057 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
David Blaikieb44f0bf2017-01-04 22:36:43 +00002058 DeclVarAbbrev = Stream.EmitAbbrev(std::move(Abv));
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002059
Richard Smith01b2cb42014-07-26 06:37:51 +00002060 // Abbreviation for DECL_CXX_METHOD
David Blaikieb44f0bf2017-01-04 22:36:43 +00002061 Abv = std::make_shared<BitCodeAbbrev>();
Richard Smith01b2cb42014-07-26 06:37:51 +00002062 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CXX_METHOD));
2063 // RedeclarableDecl
2064 Abv->Add(BitCodeAbbrevOp(0)); // CanonicalDecl
2065 // Decl
2066 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00002067 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Richard Smith01b2cb42014-07-26 06:37:51 +00002068 Abv->Add(BitCodeAbbrevOp(0)); // Invalid
2069 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
2070 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Implicit
2071 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Used
2072 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Referenced
2073 Abv->Add(BitCodeAbbrevOp(0)); // InObjCContainer
2074 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Access
2075 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ModulePrivate
2076 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2077 // NamedDecl
2078 Abv->Add(BitCodeAbbrevOp(DeclarationName::Identifier)); // NameKind
2079 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Identifier
Richard Smith2b560572015-02-07 03:11:11 +00002080 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Richard Smith01b2cb42014-07-26 06:37:51 +00002081 // ValueDecl
2082 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2083 // DeclaratorDecl
2084 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerLocStart
2085 Abv->Add(BitCodeAbbrevOp(0)); // HasExtInfo
Richard Smithc23d7342018-06-29 20:46:25 +00002086 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
Richard Smith01b2cb42014-07-26 06:37:51 +00002087 // FunctionDecl
2088 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS
2089 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // StorageClass
2090 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Inline
2091 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InlineSpecified
Richard Smith78e3d702017-02-10 01:32:04 +00002092 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ExplicitSpecified
Richard Smith01b2cb42014-07-26 06:37:51 +00002093 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // VirtualAsWritten
2094 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Pure
2095 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedProto
2096 Abv->Add(BitCodeAbbrevOp(1)); // HasWrittenProto
Richard Smith72625c22015-02-06 23:20:21 +00002097 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Deleted
Richard Smith01b2cb42014-07-26 06:37:51 +00002098 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Trivial
Akira Hatanaka02914dc2018-02-05 20:23:22 +00002099 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // TrivialForCall
Richard Smith01b2cb42014-07-26 06:37:51 +00002100 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Defaulted
2101 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ExplicitlyDefaulted
2102 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ImplicitReturnZero
2103 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Constexpr
Reid Kleckner0d157382017-01-10 21:27:03 +00002104 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // UsesSEHTry
Richard Smith01b2cb42014-07-26 06:37:51 +00002105 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // SkippedBody
Erich Keane281d20b2018-01-08 21:34:17 +00002106 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // MultiVersion
Richard Smith01b2cb42014-07-26 06:37:51 +00002107 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // LateParsed
2108 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
2109 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LocEnd
Richard Trieue6caa262017-12-23 00:41:01 +00002110 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // ODRHash
Richard Smith01b2cb42014-07-26 06:37:51 +00002111 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // TemplateKind
2112 // This Array slurps the rest of the record. Fortunately we want to encode
2113 // (nearly) all the remaining (variable number of) fields in the same way.
2114 //
2115 // This is the function template information if any, then
2116 // NumParams and Params[] from FunctionDecl, and
2117 // NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl.
2118 //
2119 // Add an AbbrevOp for 'size then elements' and use it here.
2120 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2121 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
David Blaikieb44f0bf2017-01-04 22:36:43 +00002122 DeclCXXMethodAbbrev = Stream.EmitAbbrev(std::move(Abv));
Richard Smith01b2cb42014-07-26 06:37:51 +00002123
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00002124 // Abbreviation for EXPR_DECL_REF
David Blaikieb44f0bf2017-01-04 22:36:43 +00002125 Abv = std::make_shared<BitCodeAbbrev>();
Douglas Gregor03412ba2011-06-03 02:27:19 +00002126 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_DECL_REF));
2127 //Stmt
2128 //Expr
2129 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002130 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2131 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2132 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002133 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2134 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2135 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2136 //DeclRefExpr
2137 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HasQualifier
2138 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //GetDeclFound
2139 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ExplicitTemplateArgs
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002140 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HadMultipleCandidates
Alexey Bataev19acc3d2015-01-12 10:17:46 +00002141 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2142 1)); // RefersToEnclosingVariableOrCapture
Douglas Gregor03412ba2011-06-03 02:27:19 +00002143 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef
2144 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
David Blaikieb44f0bf2017-01-04 22:36:43 +00002145 DeclRefExprAbbrev = Stream.EmitAbbrev(std::move(Abv));
Douglas Gregor03412ba2011-06-03 02:27:19 +00002146
2147 // Abbreviation for EXPR_INTEGER_LITERAL
David Blaikieb44f0bf2017-01-04 22:36:43 +00002148 Abv = std::make_shared<BitCodeAbbrev>();
Douglas Gregor03412ba2011-06-03 02:27:19 +00002149 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL));
2150 //Stmt
2151 //Expr
2152 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002153 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2154 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2155 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002156 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2157 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2158 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2159 //Integer Literal
2160 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2161 Abv->Add(BitCodeAbbrevOp(32)); // Bit Width
2162 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value
David Blaikieb44f0bf2017-01-04 22:36:43 +00002163 IntegerLiteralAbbrev = Stream.EmitAbbrev(std::move(Abv));
Douglas Gregor03412ba2011-06-03 02:27:19 +00002164
2165 // Abbreviation for EXPR_CHARACTER_LITERAL
David Blaikieb44f0bf2017-01-04 22:36:43 +00002166 Abv = std::make_shared<BitCodeAbbrev>();
Douglas Gregor03412ba2011-06-03 02:27:19 +00002167 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL));
2168 //Stmt
2169 //Expr
2170 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002171 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2172 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2173 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002174 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2175 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2176 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
Jonathan D. Turnerd09655f2011-06-03 21:46:44 +00002177 //Character Literal
Douglas Gregor03412ba2011-06-03 02:27:19 +00002178 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue
2179 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
Aaron Ballman9a17c852016-01-07 20:59:26 +00002180 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // getKind
David Blaikieb44f0bf2017-01-04 22:36:43 +00002181 CharacterLiteralAbbrev = Stream.EmitAbbrev(std::move(Abv));
Douglas Gregor03412ba2011-06-03 02:27:19 +00002182
Richard Smitha27c26e2014-07-27 04:19:32 +00002183 // Abbreviation for EXPR_IMPLICIT_CAST
David Blaikieb44f0bf2017-01-04 22:36:43 +00002184 Abv = std::make_shared<BitCodeAbbrev>();
Richard Smitha27c26e2014-07-27 04:19:32 +00002185 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_IMPLICIT_CAST));
2186 // Stmt
2187 // Expr
2188 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2189 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2190 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2191 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
2192 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2193 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2194 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2195 // CastExpr
2196 Abv->Add(BitCodeAbbrevOp(0)); // PathSize
2197 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 6)); // CastKind
Roman Lebedevd55661d2018-07-24 08:16:50 +00002198 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // PartOfExplicitCast
Richard Smitha27c26e2014-07-27 04:19:32 +00002199 // ImplicitCastExpr
David Blaikieb44f0bf2017-01-04 22:36:43 +00002200 ExprImplicitCastAbbrev = Stream.EmitAbbrev(std::move(Abv));
Richard Smitha27c26e2014-07-27 04:19:32 +00002201
David Blaikieb44f0bf2017-01-04 22:36:43 +00002202 Abv = std::make_shared<BitCodeAbbrev>();
Sebastian Redl539c5062010-08-18 23:57:32 +00002203 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL));
Sebastian Redl66c5eef2010-07-27 00:17:23 +00002204 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
David Blaikieb44f0bf2017-01-04 22:36:43 +00002205 DeclContextLexicalAbbrev = Stream.EmitAbbrev(std::move(Abv));
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002206
David Blaikieb44f0bf2017-01-04 22:36:43 +00002207 Abv = std::make_shared<BitCodeAbbrev>();
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002208 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE));
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002209 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
David Blaikieb44f0bf2017-01-04 22:36:43 +00002210 DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(std::move(Abv));
Chris Lattner258172e2009-04-27 07:35:58 +00002211}
2212
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002213/// isRequiredDecl - Check if this is a "required" Decl, which must be seen by
2214/// consumers of the AST.
2215///
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002216/// Such decls will always be deserialized from the AST file, so we would like
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002217/// this to be as restrictive as possible. Currently the predicate is driven by
2218/// code generation requirements, if other clients have a different notion of
2219/// what is "required" then we may have to consider an alternate scheme where
2220/// clients can iterate over the top-level decls and get information on them,
2221/// without necessary deserializing them. We could explicitly require such
2222/// clients to use a separate API call to "realize" the decl. This should be
2223/// relatively painless since they would presumably only do it for top-level
2224/// decls.
Richard Smithc52efa72015-08-19 02:30:28 +00002225static bool isRequiredDecl(const Decl *D, ASTContext &Context,
David Blaikiee6b7c282017-04-11 20:46:34 +00002226 bool WritingModule) {
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00002227 // An ObjCMethodDecl is never considered as "required" because its
2228 // implementation container always is.
2229
Dmitry Polukhin0b0da292016-04-06 11:38:59 +00002230 // File scoped assembly or obj-c or OMP declare target implementation must be
2231 // seen.
2232 if (isa<FileScopeAsmDecl>(D) || isa<ObjCImplDecl>(D) ||
2233 D->hasAttr<OMPDeclareTargetDeclAttr>())
Richard Smithc52efa72015-08-19 02:30:28 +00002234 return true;
2235
Richard Smithdc1f0422016-07-20 19:10:16 +00002236 if (WritingModule && (isa<VarDecl>(D) || isa<ImportDecl>(D))) {
2237 // These declarations are part of the module initializer, and are emitted
2238 // if and when the module is imported, rather than being emitted eagerly.
2239 return false;
2240 }
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002241
David Blaikiee6b7c282017-04-11 20:46:34 +00002242 return Context.DeclMustBeEmitted(D);
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002243}
2244
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002245void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) {
Jordan Rose1e879d82018-03-23 00:07:18 +00002246 PrettyDeclStackTraceEntry CrashInfo(Context, D, SourceLocation(),
2247 "serializing");
2248
Douglas Gregorb3163e52012-01-05 22:33:30 +00002249 // Determine the ID for this declaration.
2250 serialization::DeclID ID;
Douglas Gregor7dd37e52015-11-03 01:20:54 +00002251 assert(!D->isFromASTFile() && "should not be emitting imported decl");
2252 serialization::DeclID &IDR = DeclIDs[D];
2253 if (IDR == 0)
2254 IDR = NextDeclID++;
Fangrui Song6907ce22018-07-30 19:24:48 +00002255
Douglas Gregor7dd37e52015-11-03 01:20:54 +00002256 ID = IDR;
Argyrios Kyrtzidisbf6c3392012-03-22 16:08:04 +00002257
Richard Smith34da7512016-03-27 05:52:25 +00002258 assert(ID >= FirstDeclID && "invalid decl ID");
Fangrui Song6907ce22018-07-30 19:24:48 +00002259
Richard Smith69c82bf2016-04-01 22:52:03 +00002260 RecordData Record;
2261 ASTDeclWriter W(*this, Context, Record);
2262
Richard Smithd61d4ac2015-08-22 20:13:39 +00002263 // Build a record for this declaration
Richard Smithd61d4ac2015-08-22 20:13:39 +00002264 W.Visit(D);
Richard Smithd61d4ac2015-08-22 20:13:39 +00002265
Richard Smith69c82bf2016-04-01 22:52:03 +00002266 // Emit this declaration to the bitstream.
2267 uint64_t Offset = W.Emit(D);
Douglas Gregor12bfa382009-10-17 00:13:19 +00002268
Richard Smith34da7512016-03-27 05:52:25 +00002269 // Record the offset for this declaration
2270 SourceLocation Loc = D->getLocation();
Richard Smith69c82bf2016-04-01 22:52:03 +00002271 unsigned Index = ID - FirstDeclID;
Richard Smith34da7512016-03-27 05:52:25 +00002272 if (DeclOffsets.size() == Index)
Richard Smith69c82bf2016-04-01 22:52:03 +00002273 DeclOffsets.push_back(DeclOffset(Loc, Offset));
Richard Smith34da7512016-03-27 05:52:25 +00002274 else if (DeclOffsets.size() < Index) {
Richard Smith69c82bf2016-04-01 22:52:03 +00002275 // FIXME: Can/should this happen?
Richard Smith34da7512016-03-27 05:52:25 +00002276 DeclOffsets.resize(Index+1);
2277 DeclOffsets[Index].setLocation(Loc);
Richard Smith69c82bf2016-04-01 22:52:03 +00002278 DeclOffsets[Index].BitOffset = Offset;
2279 } else {
2280 llvm_unreachable("declarations should be emitted in ID order");
Douglas Gregor12bfa382009-10-17 00:13:19 +00002281 }
2282
Richard Smith34da7512016-03-27 05:52:25 +00002283 SourceManager &SM = Context.getSourceManager();
2284 if (Loc.isValid() && SM.isLocalSourceLocation(Loc))
2285 associateDeclWithFile(D, ID);
2286
Ben Langmuir332aafe2014-01-31 01:06:56 +00002287 // Note declarations that should be deserialized eagerly so that we can add
2288 // them to a record in the AST file later.
David Blaikiee6b7c282017-04-11 20:46:34 +00002289 if (isRequiredDecl(D, Context, WritingModule))
Ben Langmuir332aafe2014-01-31 01:06:56 +00002290 EagerlyDeserializedDecls.push_back(ID);
Chris Lattner7099dbc2009-04-27 06:16:06 +00002291}
Richard Smithd28ac5b2014-03-22 23:33:22 +00002292
Richard Smith290d8012016-04-06 17:06:00 +00002293void ASTRecordWriter::AddFunctionDefinition(const FunctionDecl *FD) {
2294 // Switch case IDs are per function body.
2295 Writer->ClearSwitchCaseIDs();
Richard Smithd28ac5b2014-03-22 23:33:22 +00002296
Richard Smith290d8012016-04-06 17:06:00 +00002297 assert(FD->doesThisDeclarationHaveABody());
Richard Smithb51cf112017-07-06 00:30:00 +00002298 bool ModulesCodegen = false;
2299 if (Writer->WritingModule && !FD->isDependentContext()) {
David Blaikie08267292017-11-02 21:55:40 +00002300 Optional<GVALinkage> Linkage;
2301 if (Writer->WritingModule->Kind == Module::ModuleInterfaceUnit) {
2302 // When building a C++ Modules TS module interface unit, a strong
2303 // definition in the module interface is provided by the compilation of
2304 // that module interface unit, not by its users. (Inline functions are
2305 // still emitted in module users.)
2306 Linkage = Writer->Context->GetGVALinkageForFunction(FD);
2307 ModulesCodegen = *Linkage == GVA_StrongExternal;
2308 }
2309 if (Writer->Context->getLangOpts().ModulesCodegen) {
2310 // Under -fmodules-codegen, codegen is performed for all non-internal,
2311 // non-always_inline functions.
David Blaikie1524e672017-11-02 22:28:50 +00002312 if (!FD->hasAttr<AlwaysInlineAttr>()) {
2313 if (!Linkage)
2314 Linkage = Writer->Context->GetGVALinkageForFunction(FD);
2315 ModulesCodegen = *Linkage != GVA_Internal;
2316 }
David Blaikie08267292017-11-02 21:55:40 +00002317 }
Richard Smithb51cf112017-07-06 00:30:00 +00002318 }
David Blaikief63556d2017-04-12 20:58:33 +00002319 Record->push_back(ModulesCodegen);
2320 if (ModulesCodegen)
David Blaikiee6b7c282017-04-11 20:46:34 +00002321 Writer->ModularCodegenDecls.push_back(Writer->GetDeclRef(FD));
Richard Smith290d8012016-04-06 17:06:00 +00002322 if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
2323 Record->push_back(CD->getNumCtorInitializers());
2324 if (CD->getNumCtorInitializers())
Richard Smithaa165cf2016-04-13 21:57:08 +00002325 AddCXXCtorInitializers(
Richard Smith290d8012016-04-06 17:06:00 +00002326 llvm::makeArrayRef(CD->init_begin(), CD->init_end()));
2327 }
2328 AddStmt(FD->getBody());
Richard Smithd28ac5b2014-03-22 23:33:22 +00002329}