1d6522cfcSSebastian Redl //===--- ASTWriterDecl.cpp - Declaration Serialization --------------------===//
2d6522cfcSSebastian Redl //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6d6522cfcSSebastian Redl //
7d6522cfcSSebastian Redl //===----------------------------------------------------------------------===//
8d6522cfcSSebastian Redl //
9d6522cfcSSebastian Redl // This file implements serialization for Declarations.
10d6522cfcSSebastian Redl //
11d6522cfcSSebastian Redl //===----------------------------------------------------------------------===//
12d6522cfcSSebastian Redl
13fa1f370bSSebastian Redl #include "ASTCommon.h"
1460573ae6SReid Kleckner #include "clang/AST/Attr.h"
15d6522cfcSSebastian Redl #include "clang/AST/DeclCXX.h"
163a02247dSChandler Carruth #include "clang/AST/DeclTemplate.h"
173a02247dSChandler Carruth #include "clang/AST/DeclVisitor.h"
183a02247dSChandler Carruth #include "clang/AST/Expr.h"
191408f91aSKelvin Li #include "clang/AST/OpenMPClause.h"
201e879d8bSJordan Rose #include "clang/AST/PrettyDeclStackTrace.h"
215fc727a0SArgyrios Kyrtzidis #include "clang/Basic/SourceManager.h"
223a02247dSChandler Carruth #include "clang/Serialization/ASTReader.h"
232ac702aaSJohn McCall #include "clang/Serialization/ASTRecordWriter.h"
24e0308279SFrancis Visoiu Mistrih #include "llvm/Bitstream/BitstreamWriter.h"
25d6522cfcSSebastian Redl #include "llvm/Support/ErrorHandling.h"
26d6522cfcSSebastian Redl using namespace clang;
27fa1f370bSSebastian Redl using namespace serialization;
28d6522cfcSSebastian Redl
29d6522cfcSSebastian Redl //===----------------------------------------------------------------------===//
30d6522cfcSSebastian Redl // Declaration serialization
31d6522cfcSSebastian Redl //===----------------------------------------------------------------------===//
32d6522cfcSSebastian Redl
33d6522cfcSSebastian Redl namespace clang {
34d6522cfcSSebastian Redl class ASTDeclWriter : public DeclVisitor<ASTDeclWriter, void> {
35d6522cfcSSebastian Redl ASTWriter &Writer;
36d6522cfcSSebastian Redl ASTContext &Context;
3769c82bfaSRichard Smith ASTRecordWriter Record;
38d6522cfcSSebastian Redl
39539c5061SSebastian Redl serialization::DeclCode Code;
40d6522cfcSSebastian Redl unsigned AbbrevToUse;
41d6522cfcSSebastian Redl
4269c82bfaSRichard Smith public:
ASTDeclWriter(ASTWriter & Writer,ASTContext & Context,ASTWriter::RecordDataImpl & Record)4369c82bfaSRichard Smith ASTDeclWriter(ASTWriter &Writer, ASTContext &Context,
4469c82bfaSRichard Smith ASTWriter::RecordDataImpl &Record)
4569c82bfaSRichard Smith : Writer(Writer), Context(Context), Record(Writer, Record),
4669c82bfaSRichard Smith Code((serialization::DeclCode)0), AbbrevToUse(0) {}
4769c82bfaSRichard Smith
Emit(Decl * D)4869c82bfaSRichard Smith uint64_t Emit(Decl *D) {
4969c82bfaSRichard Smith if (!Code)
5069c82bfaSRichard Smith llvm::report_fatal_error(StringRef("unexpected declaration kind '") +
5169c82bfaSRichard Smith D->getDeclKindName() + "'");
52645d2cfdSRichard Smith return Record.Emit(Code, AbbrevToUse);
53d6522cfcSSebastian Redl }
54d6522cfcSSebastian Redl
55d6522cfcSSebastian Redl void Visit(Decl *D);
56d6522cfcSSebastian Redl
57d6522cfcSSebastian Redl void VisitDecl(Decl *D);
586622029dSNico Weber void VisitPragmaCommentDecl(PragmaCommentDecl *D);
59cbbaeb13SNico Weber void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D);
60d6522cfcSSebastian Redl void VisitTranslationUnitDecl(TranslationUnitDecl *D);
61d6522cfcSSebastian Redl void VisitNamedDecl(NamedDecl *D);
62c8e630e4SChris Lattner void VisitLabelDecl(LabelDecl *LD);
63d6522cfcSSebastian Redl void VisitNamespaceDecl(NamespaceDecl *D);
64d6522cfcSSebastian Redl void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
65d6522cfcSSebastian Redl void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
66d6522cfcSSebastian Redl void VisitTypeDecl(TypeDecl *D);
671f179064SDouglas Gregor void VisitTypedefNameDecl(TypedefNameDecl *D);
68d6522cfcSSebastian Redl void VisitTypedefDecl(TypedefDecl *D);
69dda56e4bSRichard Smith void VisitTypeAliasDecl(TypeAliasDecl *D);
70d6522cfcSSebastian Redl void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
71369c6483SErik Pilkington void VisitUnresolvedUsingIfExistsDecl(UnresolvedUsingIfExistsDecl *D);
72d6522cfcSSebastian Redl void VisitTagDecl(TagDecl *D);
73d6522cfcSSebastian Redl void VisitEnumDecl(EnumDecl *D);
74d6522cfcSSebastian Redl void VisitRecordDecl(RecordDecl *D);
75d6522cfcSSebastian Redl void VisitCXXRecordDecl(CXXRecordDecl *D);
76d6522cfcSSebastian Redl void VisitClassTemplateSpecializationDecl(
77d6522cfcSSebastian Redl ClassTemplateSpecializationDecl *D);
78d6522cfcSSebastian Redl void VisitClassTemplatePartialSpecializationDecl(
79d6522cfcSSebastian Redl ClassTemplatePartialSpecializationDecl *D);
8039a1e507SLarisse Voufo void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D);
8139a1e507SLarisse Voufo void VisitVarTemplatePartialSpecializationDecl(
8239a1e507SLarisse Voufo VarTemplatePartialSpecializationDecl *D);
8309af8c36SFrancois Pichet void VisitClassScopeFunctionSpecializationDecl(
8409af8c36SFrancois Pichet ClassScopeFunctionSpecializationDecl *D);
85d6522cfcSSebastian Redl void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
86d6522cfcSSebastian Redl void VisitValueDecl(ValueDecl *D);
87d6522cfcSSebastian Redl void VisitEnumConstantDecl(EnumConstantDecl *D);
88d6522cfcSSebastian Redl void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
89d6522cfcSSebastian Redl void VisitDeclaratorDecl(DeclaratorDecl *D);
90d6522cfcSSebastian Redl void VisitFunctionDecl(FunctionDecl *D);
91bc491203SRichard Smith void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D);
92d6522cfcSSebastian Redl void VisitCXXMethodDecl(CXXMethodDecl *D);
93d6522cfcSSebastian Redl void VisitCXXConstructorDecl(CXXConstructorDecl *D);
94d6522cfcSSebastian Redl void VisitCXXDestructorDecl(CXXDestructorDecl *D);
95d6522cfcSSebastian Redl void VisitCXXConversionDecl(CXXConversionDecl *D);
96d6522cfcSSebastian Redl void VisitFieldDecl(FieldDecl *D);
975e77d76cSJohn McCall void VisitMSPropertyDecl(MSPropertyDecl *D);
98bab6df86SRichard Smith void VisitMSGuidDecl(MSGuidDecl *D);
99d6148749SJames Y Knight void VisitUnnamedGlobalConstantDecl(UnnamedGlobalConstantDecl *D);
100ba4768c9SRichard Smith void VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D);
101783dd6ecSFrancois Pichet void VisitIndirectFieldDecl(IndirectFieldDecl *D);
102d6522cfcSSebastian Redl void VisitVarDecl(VarDecl *D);
103d6522cfcSSebastian Redl void VisitImplicitParamDecl(ImplicitParamDecl *D);
104d6522cfcSSebastian Redl void VisitParmVarDecl(ParmVarDecl *D);
1057b76d81bSRichard Smith void VisitDecompositionDecl(DecompositionDecl *D);
1067b76d81bSRichard Smith void VisitBindingDecl(BindingDecl *D);
107d6522cfcSSebastian Redl void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
108d6522cfcSSebastian Redl void VisitTemplateDecl(TemplateDecl *D);
109d7aae33aSSaar Raz void VisitConceptDecl(ConceptDecl *D);
110a0f50d73SSaar Raz void VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D);
111d6522cfcSSebastian Redl void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
112d6522cfcSSebastian Redl void VisitClassTemplateDecl(ClassTemplateDecl *D);
11339a1e507SLarisse Voufo void VisitVarTemplateDecl(VarTemplateDecl *D);
114d6522cfcSSebastian Redl void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
115d6522cfcSSebastian Redl void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
1163f1b5d07SRichard Smith void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
117d6522cfcSSebastian Redl void VisitUsingDecl(UsingDecl *D);
118b2d0c16eSNathan Sidwell void VisitUsingEnumDecl(UsingEnumDecl *D);
119151c4568SRichard Smith void VisitUsingPackDecl(UsingPackDecl *D);
120d6522cfcSSebastian Redl void VisitUsingShadowDecl(UsingShadowDecl *D);
1215179eb78SRichard Smith void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D);
122d6522cfcSSebastian Redl void VisitLinkageSpecDecl(LinkageSpecDecl *D);
1238df390f9SRichard Smith void VisitExportDecl(ExportDecl *D);
124d6522cfcSSebastian Redl void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
125ba34552eSDouglas Gregor void VisitImportDecl(ImportDecl *D);
126d6522cfcSSebastian Redl void VisitAccessSpecDecl(AccessSpecDecl *D);
127d6522cfcSSebastian Redl void VisitFriendDecl(FriendDecl *D);
128d6522cfcSSebastian Redl void VisitFriendTemplateDecl(FriendTemplateDecl *D);
129d6522cfcSSebastian Redl void VisitStaticAssertDecl(StaticAssertDecl *D);
130d6522cfcSSebastian Redl void VisitBlockDecl(BlockDecl *D);
1316dfa25a1STareq A. Siraj void VisitCapturedDecl(CapturedDecl *D);
13284324357SMichael Han void VisitEmptyDecl(EmptyDecl *D);
133b0561b33STyker void VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D);
134d6522cfcSSebastian Redl
135f1c23dc4SRichard Smith void VisitDeclContext(DeclContext *DC);
136d6522cfcSSebastian Redl template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
137d6522cfcSSebastian Redl
138d6522cfcSSebastian Redl
139d6522cfcSSebastian Redl // FIXME: Put in the same order is DeclNodes.td?
140d6522cfcSSebastian Redl void VisitObjCMethodDecl(ObjCMethodDecl *D);
14185f3f951SDouglas Gregor void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
142d6522cfcSSebastian Redl void VisitObjCContainerDecl(ObjCContainerDecl *D);
143d6522cfcSSebastian Redl void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
144d6522cfcSSebastian Redl void VisitObjCIvarDecl(ObjCIvarDecl *D);
145d6522cfcSSebastian Redl void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
146d6522cfcSSebastian Redl void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
147d6522cfcSSebastian Redl void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
148d6522cfcSSebastian Redl void VisitObjCImplDecl(ObjCImplDecl *D);
149d6522cfcSSebastian Redl void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
150d6522cfcSSebastian Redl void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
151d6522cfcSSebastian Redl void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
152d6522cfcSSebastian Redl void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
153d6522cfcSSebastian Redl void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
154a769e072SAlexey Bataev void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
15525ed0c07SAlexey Bataev void VisitOMPAllocateDecl(OMPAllocateDecl *D);
1561408f91aSKelvin Li void VisitOMPRequiresDecl(OMPRequiresDecl *D);
15794a4f0cbSAlexey Bataev void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
158251e1488SMichael Kruse void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D);
1594244be25SAlexey Bataev void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
160d28ac5b9SRichard Smith
16185f3f951SDouglas Gregor /// Add an Objective-C type parameter list to the given record.
AddObjCTypeParamList(ObjCTypeParamList * typeParams)16285f3f951SDouglas Gregor void AddObjCTypeParamList(ObjCTypeParamList *typeParams) {
16385f3f951SDouglas Gregor // Empty type parameter list.
16485f3f951SDouglas Gregor if (!typeParams) {
16585f3f951SDouglas Gregor Record.push_back(0);
16685f3f951SDouglas Gregor return;
16785f3f951SDouglas Gregor }
16885f3f951SDouglas Gregor
16985f3f951SDouglas Gregor Record.push_back(typeParams->size());
17085f3f951SDouglas Gregor for (auto typeParam : *typeParams) {
17169c82bfaSRichard Smith Record.AddDeclRef(typeParam);
17285f3f951SDouglas Gregor }
17369c82bfaSRichard Smith Record.AddSourceLocation(typeParams->getLAngleLoc());
17469c82bfaSRichard Smith Record.AddSourceLocation(typeParams->getRAngleLoc());
17585f3f951SDouglas Gregor }
17685f3f951SDouglas Gregor
177d8a83718SRichard Smith /// Add to the record the first declaration from each module file that
178d8a83718SRichard Smith /// provides a declaration of D. The intent is to provide a sufficient
179d8a83718SRichard Smith /// set such that reloading this set will load all current redeclarations.
AddFirstDeclFromEachModule(const Decl * D,bool IncludeLocal)180d8a83718SRichard Smith void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) {
181d8a83718SRichard Smith llvm::MapVector<ModuleFile*, const Decl*> Firsts;
182d8a83718SRichard Smith // FIXME: We can skip entries that we know are implied by others.
1835f55d93cSRichard Smith for (const Decl *R = D->getMostRecentDecl(); R; R = R->getPreviousDecl()) {
1845f55d93cSRichard Smith if (R->isFromASTFile())
185d8a83718SRichard Smith Firsts[Writer.Chain->getOwningModuleFile(R)] = R;
1865f55d93cSRichard Smith else if (IncludeLocal)
1875f55d93cSRichard Smith Firsts[nullptr] = R;
1885f55d93cSRichard Smith }
189d8a83718SRichard Smith for (const auto &F : Firsts)
19069c82bfaSRichard Smith Record.AddDeclRef(F.second);
191d8a83718SRichard Smith }
192d8a83718SRichard Smith
193509fc85bSRichard Smith /// Get the specialization decl from an entry in the specialization list.
194509fc85bSRichard Smith template <typename EntryType>
195509fc85bSRichard Smith typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType *
getSpecializationDecl(EntryType & T)196509fc85bSRichard Smith getSpecializationDecl(EntryType &T) {
197509fc85bSRichard Smith return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T);
198509fc85bSRichard Smith }
199509fc85bSRichard Smith
200509fc85bSRichard Smith /// Get the list of partial specializations from a template's common ptr.
201509fc85bSRichard Smith template<typename T>
getPartialSpecializations(T * Common)202509fc85bSRichard Smith decltype(T::PartialSpecializations) &getPartialSpecializations(T *Common) {
203509fc85bSRichard Smith return Common->PartialSpecializations;
204509fc85bSRichard Smith }
getPartialSpecializations(FunctionTemplateDecl::Common *)205509fc85bSRichard Smith ArrayRef<Decl> getPartialSpecializations(FunctionTemplateDecl::Common *) {
206509fc85bSRichard Smith return None;
207509fc85bSRichard Smith }
208509fc85bSRichard Smith
2098ab0cfd5SRichard Smith template<typename DeclTy>
AddTemplateSpecializations(DeclTy * D)2108ab0cfd5SRichard Smith void AddTemplateSpecializations(DeclTy *D) {
211509fc85bSRichard Smith auto *Common = D->getCommonPtr();
212509fc85bSRichard Smith
213509fc85bSRichard Smith // If we have any lazy specializations, and the external AST source is
214509fc85bSRichard Smith // our chained AST reader, we can just write out the DeclIDs. Otherwise,
215509fc85bSRichard Smith // we need to resolve them to actual declarations.
216509fc85bSRichard Smith if (Writer.Chain != Writer.Context->getExternalSource() &&
217509fc85bSRichard Smith Common->LazySpecializations) {
218509fc85bSRichard Smith D->LoadLazySpecializations();
219509fc85bSRichard Smith assert(!Common->LazySpecializations);
220509fc85bSRichard Smith }
221509fc85bSRichard Smith
222509fc85bSRichard Smith ArrayRef<DeclID> LazySpecializations;
223509fc85bSRichard Smith if (auto *LS = Common->LazySpecializations)
22455e39a7cSCraig Topper LazySpecializations = llvm::makeArrayRef(LS + 1, LS[0]);
225509fc85bSRichard Smith
226d8a83718SRichard Smith // Add a slot to the record for the number of specializations.
227d8a83718SRichard Smith unsigned I = Record.size();
228d8a83718SRichard Smith Record.push_back(0);
229d8a83718SRichard Smith
2308ab0cfd5SRichard Smith // AddFirstDeclFromEachModule might trigger deserialization, invalidating
2318ab0cfd5SRichard Smith // *Specializations iterators.
2328ab0cfd5SRichard Smith llvm::SmallVector<const Decl*, 16> Specs;
2338ab0cfd5SRichard Smith for (auto &Entry : Common->Specializations)
2348ab0cfd5SRichard Smith Specs.push_back(getSpecializationDecl(Entry));
2358ab0cfd5SRichard Smith for (auto &Entry : getPartialSpecializations(Common))
2368ab0cfd5SRichard Smith Specs.push_back(getSpecializationDecl(Entry));
2378ab0cfd5SRichard Smith
2388ab0cfd5SRichard Smith for (auto *D : Specs) {
239509fc85bSRichard Smith assert(D->isCanonicalDecl() && "non-canonical decl in set");
240d8a83718SRichard Smith AddFirstDeclFromEachModule(D, /*IncludeLocal*/true);
241509fc85bSRichard Smith }
242f367dd90SBenjamin Kramer Record.append(LazySpecializations.begin(), LazySpecializations.end());
243d8a83718SRichard Smith
244d8a83718SRichard Smith // Update the size entry we added earlier.
245d8a83718SRichard Smith Record[I] = Record.size() - I - 1;
246d8a83718SRichard Smith }
247d8a83718SRichard Smith
248d8a83718SRichard Smith /// Ensure that this template specialization is associated with the specified
249d8a83718SRichard Smith /// template on reload.
RegisterTemplateSpecialization(const Decl * Template,const Decl * Specialization)250d8a83718SRichard Smith void RegisterTemplateSpecialization(const Decl *Template,
251d8a83718SRichard Smith const Decl *Specialization) {
252d8a83718SRichard Smith Template = Template->getCanonicalDecl();
253d8a83718SRichard Smith
254d8a83718SRichard Smith // If the canonical template is local, we'll write out this specialization
255d8a83718SRichard Smith // when we emit it.
256d8a83718SRichard Smith // FIXME: We can do the same thing if there is any local declaration of
257d8a83718SRichard Smith // the template, to avoid emitting an update record.
258d8a83718SRichard Smith if (!Template->isFromASTFile())
259d8a83718SRichard Smith return;
260d8a83718SRichard Smith
261d8a83718SRichard Smith // We only need to associate the first local declaration of the
262d8a83718SRichard Smith // specialization. The other declarations will get pulled in by it.
263d8a83718SRichard Smith if (Writer.getFirstLocalDecl(Specialization) != Specialization)
264d8a83718SRichard Smith return;
265d8a83718SRichard Smith
266d8a83718SRichard Smith Writer.DeclUpdates[Template].push_back(ASTWriter::DeclUpdate(
267d8a83718SRichard Smith UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION, Specialization));
268509fc85bSRichard Smith }
269d6522cfcSSebastian Redl };
270ab9db510SAlexander Kornienko }
271d6522cfcSSebastian Redl
Visit(Decl * D)272d6522cfcSSebastian Redl void ASTDeclWriter::Visit(Decl *D) {
273d6522cfcSSebastian Redl DeclVisitor<ASTDeclWriter>::Visit(D);
274d6522cfcSSebastian Redl
275205c7d55SJonathan D. Turner // Source locations require array (variable-length) abbreviations. The
276205c7d55SJonathan D. Turner // abbreviation infrastructure requires that arrays are encoded last, so
277205c7d55SJonathan D. Turner // we handle it here in the case of those classes derived from DeclaratorDecl
278205c7d55SJonathan D. Turner if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
279c23d734dSRichard Smith if (auto *TInfo = DD->getTypeSourceInfo())
280c23d734dSRichard Smith Record.AddTypeLoc(TInfo->getTypeLoc());
281205c7d55SJonathan D. Turner }
282205c7d55SJonathan D. Turner
283d6522cfcSSebastian Redl // Handle FunctionDecl's body here and write it after all other Stmts/Exprs
284d6522cfcSSebastian Redl // have been written. We want it last because we will not read it back when
285d6522cfcSSebastian Redl // retrieving it from the AST, we'll just lazily set the offset.
286d6522cfcSSebastian Redl if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
2874a8ea109SAlexis Hunt Record.push_back(FD->doesThisDeclarationHaveABody());
2884a8ea109SAlexis Hunt if (FD->doesThisDeclarationHaveABody())
289290d8019SRichard Smith Record.AddFunctionDefinition(FD);
290d6522cfcSSebastian Redl }
291f1c23dc4SRichard Smith
292f1c23dc4SRichard Smith // If this declaration is also a DeclContext, write blocks for the
293f1c23dc4SRichard Smith // declarations that lexically stored inside its context and those
294f1c23dc4SRichard Smith // declarations that are visible from its context.
295f1c23dc4SRichard Smith if (DeclContext *DC = dyn_cast<DeclContext>(D))
296f1c23dc4SRichard Smith VisitDeclContext(DC);
297d6522cfcSSebastian Redl }
298d6522cfcSSebastian Redl
VisitDecl(Decl * D)299d6522cfcSSebastian Redl void ASTDeclWriter::VisitDecl(Decl *D) {
30069c82bfaSRichard Smith Record.AddDeclRef(cast_or_null<Decl>(D->getDeclContext()));
3018aed4222SRichard Smith if (D->getDeclContext() != D->getLexicalDeclContext())
30269c82bfaSRichard Smith Record.AddDeclRef(cast_or_null<Decl>(D->getLexicalDeclContext()));
3038aed4222SRichard Smith else
3048aed4222SRichard Smith Record.push_back(0);
305d6522cfcSSebastian Redl Record.push_back(D->isInvalidDecl());
306d6522cfcSSebastian Redl Record.push_back(D->hasAttrs());
3079beef8e5SArgyrios Kyrtzidis if (D->hasAttrs())
30869c82bfaSRichard Smith Record.AddAttributes(D->getAttrs());
309d6522cfcSSebastian Redl Record.push_back(D->isImplicit());
310d6522cfcSSebastian Redl Record.push_back(D->isUsed(false));
31116180230SArgyrios Kyrtzidis Record.push_back(D->isReferenced());
312781f713dSDouglas Gregor Record.push_back(D->isTopLevelDeclInObjCContainer());
313d6522cfcSSebastian Redl Record.push_back(D->getAccess());
3149c04851cSChuanqi Xu Record.push_back((uint64_t)D->getModuleOwnershipKind());
31554f0440cSRichard Smith Record.push_back(Writer.getSubmoduleID(D->getOwningModule()));
316c264d35aSRichard Smith
317c264d35aSRichard Smith // If this declaration injected a name into a context different from its
318c264d35aSRichard Smith // lexical context, and that context is an imported namespace, we need to
319c264d35aSRichard Smith // update its visible declarations to include this name.
320c264d35aSRichard Smith //
321c264d35aSRichard Smith // This happens when we instantiate a class with a friend declaration or a
322c264d35aSRichard Smith // function with a local extern declaration, for instance.
3235fc18a9aSRichard Smith //
3245fc18a9aSRichard Smith // FIXME: Can we handle this in AddedVisibleDecl instead?
325c264d35aSRichard Smith if (D->isOutOfLine()) {
326e3a97029SRichard Smith auto *DC = D->getDeclContext();
327e3a97029SRichard Smith while (auto *NS = dyn_cast<NamespaceDecl>(DC->getRedeclContext())) {
328e3a97029SRichard Smith if (!NS->isFromASTFile())
329e3a97029SRichard Smith break;
3308a3d24dcSChandler Carruth Writer.UpdatedDeclContexts.insert(NS->getPrimaryContext());
331e3a97029SRichard Smith if (!NS->isInlineNamespace())
332e3a97029SRichard Smith break;
333e3a97029SRichard Smith DC = NS->getParent();
334e3a97029SRichard Smith }
335c264d35aSRichard Smith }
336d6522cfcSSebastian Redl }
337d6522cfcSSebastian Redl
VisitPragmaCommentDecl(PragmaCommentDecl * D)3386622029dSNico Weber void ASTDeclWriter::VisitPragmaCommentDecl(PragmaCommentDecl *D) {
3396622029dSNico Weber StringRef Arg = D->getArg();
3406622029dSNico Weber Record.push_back(Arg.size());
3416622029dSNico Weber VisitDecl(D);
342f2ceec48SStephen Kelly Record.AddSourceLocation(D->getBeginLoc());
3436622029dSNico Weber Record.push_back(D->getCommentKind());
34469c82bfaSRichard Smith Record.AddString(Arg);
3456622029dSNico Weber Code = serialization::DECL_PRAGMA_COMMENT;
3466622029dSNico Weber }
3476622029dSNico Weber
VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl * D)348cbbaeb13SNico Weber void ASTDeclWriter::VisitPragmaDetectMismatchDecl(
349cbbaeb13SNico Weber PragmaDetectMismatchDecl *D) {
350cbbaeb13SNico Weber StringRef Name = D->getName();
351cbbaeb13SNico Weber StringRef Value = D->getValue();
352cbbaeb13SNico Weber Record.push_back(Name.size() + 1 + Value.size());
353cbbaeb13SNico Weber VisitDecl(D);
354f2ceec48SStephen Kelly Record.AddSourceLocation(D->getBeginLoc());
35569c82bfaSRichard Smith Record.AddString(Name);
35669c82bfaSRichard Smith Record.AddString(Value);
357cbbaeb13SNico Weber Code = serialization::DECL_PRAGMA_DETECT_MISMATCH;
358cbbaeb13SNico Weber }
359cbbaeb13SNico Weber
VisitTranslationUnitDecl(TranslationUnitDecl * D)360d6522cfcSSebastian Redl void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
361dab42432SDouglas Gregor llvm_unreachable("Translation units aren't directly serialized");
362d6522cfcSSebastian Redl }
363d6522cfcSSebastian Redl
VisitNamedDecl(NamedDecl * D)364d6522cfcSSebastian Redl void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) {
365d6522cfcSSebastian Redl VisitDecl(D);
36669c82bfaSRichard Smith Record.AddDeclarationName(D->getDeclName());
3672b560575SRichard Smith Record.push_back(needsAnonymousDeclarationNumber(D)
3682b560575SRichard Smith ? Writer.getAnonymousDeclarationNumber(D)
3692b560575SRichard Smith : 0);
370d6522cfcSSebastian Redl }
371d6522cfcSSebastian Redl
VisitTypeDecl(TypeDecl * D)372d6522cfcSSebastian Redl void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) {
373d6522cfcSSebastian Redl VisitNamedDecl(D);
374f2ceec48SStephen Kelly Record.AddSourceLocation(D->getBeginLoc());
37569c82bfaSRichard Smith Record.AddTypeRef(QualType(D->getTypeForDecl(), 0));
376d6522cfcSSebastian Redl }
377d6522cfcSSebastian Redl
VisitTypedefNameDecl(TypedefNameDecl * D)3781f179064SDouglas Gregor void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) {
37905f10357SDouglas Gregor VisitRedeclarable(D);
380d6522cfcSSebastian Redl VisitTypeDecl(D);
38169c82bfaSRichard Smith Record.AddTypeSourceInfo(D->getTypeSourceInfo());
382a86d88c7SEnea Zaffanella Record.push_back(D->isModed());
383a86d88c7SEnea Zaffanella if (D->isModed())
38469c82bfaSRichard Smith Record.AddTypeRef(D->getUnderlyingType());
385c0ca4c2cSRichard Smith Record.AddDeclRef(D->getAnonDeclWithTypedefName(false));
3861f179064SDouglas Gregor }
387205c7d55SJonathan D. Turner
VisitTypedefDecl(TypedefDecl * D)3881f179064SDouglas Gregor void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) {
3891f179064SDouglas Gregor VisitTypedefNameDecl(D);
3908aed4222SRichard Smith if (D->getDeclContext() == D->getLexicalDeclContext() &&
3918aed4222SRichard Smith !D->hasAttrs() &&
392205c7d55SJonathan D. Turner !D->isImplicit() &&
3938db352d5SRafael Espindola D->getFirstDecl() == D->getMostRecentDecl() &&
394205c7d55SJonathan D. Turner !D->isInvalidDecl() &&
395a7245005SArgyrios Kyrtzidis !D->isTopLevelDeclInObjCContainer() &&
39626701a43SDouglas Gregor !D->isModulePrivate() &&
397d08aeb6bSRichard Smith !needsAnonymousDeclarationNumber(D) &&
398205c7d55SJonathan D. Turner D->getDeclName().getNameKind() == DeclarationName::Identifier)
399205c7d55SJonathan D. Turner AbbrevToUse = Writer.getDeclTypedefAbbrev();
400205c7d55SJonathan D. Turner
401539c5061SSebastian Redl Code = serialization::DECL_TYPEDEF;
402d6522cfcSSebastian Redl }
403d6522cfcSSebastian Redl
VisitTypeAliasDecl(TypeAliasDecl * D)404dda56e4bSRichard Smith void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) {
4051f179064SDouglas Gregor VisitTypedefNameDecl(D);
40669c82bfaSRichard Smith Record.AddDeclRef(D->getDescribedAliasTemplate());
407dda56e4bSRichard Smith Code = serialization::DECL_TYPEALIAS;
408dda56e4bSRichard Smith }
409dda56e4bSRichard Smith
VisitTagDecl(TagDecl * D)410d6522cfcSSebastian Redl void ASTDeclWriter::VisitTagDecl(TagDecl *D) {
411d6522cfcSSebastian Redl VisitRedeclarable(D);
4123e30010dSDouglas Gregor VisitTypeDecl(D);
413f4bc0d87SArgyrios Kyrtzidis Record.push_back(D->getIdentifierNamespace());
414d6522cfcSSebastian Redl Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding
4152c381647SRichard Smith if (!isa<CXXRecordDecl>(D))
416f937c023SJohn McCall Record.push_back(D->isCompleteDefinition());
417d6522cfcSSebastian Redl Record.push_back(D->isEmbeddedInDeclarator());
418201d3771SArgyrios Kyrtzidis Record.push_back(D->isFreeStanding());
419a8d23ce8SDavid Blaikie Record.push_back(D->isCompleteDefinitionRequired());
420d798c055SArgyrios Kyrtzidis Record.AddSourceRange(D->getBraceRange());
42170d58509SRichard Smith
42270d58509SRichard Smith if (D->hasExtInfo()) {
42370d58509SRichard Smith Record.push_back(1);
42469c82bfaSRichard Smith Record.AddQualifierInfo(*D->getExtInfo());
42570d58509SRichard Smith } else if (auto *TD = D->getTypedefNameForAnonDecl()) {
42670d58509SRichard Smith Record.push_back(2);
42769c82bfaSRichard Smith Record.AddDeclRef(TD);
42869c82bfaSRichard Smith Record.AddIdentifierRef(TD->getDeclName().getAsIdentifierInfo());
42970d58509SRichard Smith } else {
43070d58509SRichard Smith Record.push_back(0);
43170d58509SRichard Smith }
432d6522cfcSSebastian Redl }
433d6522cfcSSebastian Redl
VisitEnumDecl(EnumDecl * D)434d6522cfcSSebastian Redl void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
435d6522cfcSSebastian Redl VisitTagDecl(D);
43669c82bfaSRichard Smith Record.AddTypeSourceInfo(D->getIntegerTypeSourceInfo());
4370bf31404SDouglas Gregor if (!D->getIntegerTypeSourceInfo())
43869c82bfaSRichard Smith Record.AddTypeRef(D->getIntegerType());
43969c82bfaSRichard Smith Record.AddTypeRef(D->getPromotionType());
440d6522cfcSSebastian Redl Record.push_back(D->getNumPositiveBits());
441d6522cfcSSebastian Redl Record.push_back(D->getNumNegativeBits());
4420bf31404SDouglas Gregor Record.push_back(D->isScoped());
4430e05e24eSAbramo Bagnara Record.push_back(D->isScopedUsingClassTag());
4440bf31404SDouglas Gregor Record.push_back(D->isFixed());
445ab4d730fSRichard Trieu Record.push_back(D->getODRHash());
446ab4d730fSRichard Trieu
4474b38ded6SRichard Smith if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
44869c82bfaSRichard Smith Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
4494b38ded6SRichard Smith Record.push_back(MemberInfo->getTemplateSpecializationKind());
45069c82bfaSRichard Smith Record.AddSourceLocation(MemberInfo->getPointOfInstantiation());
4514b38ded6SRichard Smith } else {
45269c82bfaSRichard Smith Record.AddDeclRef(nullptr);
4534b38ded6SRichard Smith }
454205c7d55SJonathan D. Turner
4558aed4222SRichard Smith if (D->getDeclContext() == D->getLexicalDeclContext() &&
4568aed4222SRichard Smith !D->hasAttrs() &&
457205c7d55SJonathan D. Turner !D->isImplicit() &&
458205c7d55SJonathan D. Turner !D->isUsed(false) &&
459205c7d55SJonathan D. Turner !D->hasExtInfo() &&
46070d58509SRichard Smith !D->getTypedefNameForAnonDecl() &&
4618db352d5SRafael Espindola D->getFirstDecl() == D->getMostRecentDecl() &&
462205c7d55SJonathan D. Turner !D->isInvalidDecl() &&
463205c7d55SJonathan D. Turner !D->isReferenced() &&
464a7245005SArgyrios Kyrtzidis !D->isTopLevelDeclInObjCContainer() &&
465205c7d55SJonathan D. Turner D->getAccess() == AS_none &&
46626701a43SDouglas Gregor !D->isModulePrivate() &&
467205c7d55SJonathan D. Turner !CXXRecordDecl::classofKind(D->getKind()) &&
468205c7d55SJonathan D. Turner !D->getIntegerTypeSourceInfo() &&
469ca370b0dSArgyrios Kyrtzidis !D->getMemberSpecializationInfo() &&
470d08aeb6bSRichard Smith !needsAnonymousDeclarationNumber(D) &&
471205c7d55SJonathan D. Turner D->getDeclName().getNameKind() == DeclarationName::Identifier)
472205c7d55SJonathan D. Turner AbbrevToUse = Writer.getDeclEnumAbbrev();
473205c7d55SJonathan D. Turner
474539c5061SSebastian Redl Code = serialization::DECL_ENUM;
475d6522cfcSSebastian Redl }
476d6522cfcSSebastian Redl
VisitRecordDecl(RecordDecl * D)477d6522cfcSSebastian Redl void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) {
478d6522cfcSSebastian Redl VisitTagDecl(D);
479d6522cfcSSebastian Redl Record.push_back(D->hasFlexibleArrayMember());
480d6522cfcSSebastian Redl Record.push_back(D->isAnonymousStructOrUnion());
481d6522cfcSSebastian Redl Record.push_back(D->hasObjectMember());
4827865220dSFariborz Jahanian Record.push_back(D->hasVolatileMember());
48334fb2645SAkira Hatanaka Record.push_back(D->isNonTrivialToPrimitiveDefaultInitialize());
48434fb2645SAkira Hatanaka Record.push_back(D->isNonTrivialToPrimitiveCopy());
48534fb2645SAkira Hatanaka Record.push_back(D->isNonTrivialToPrimitiveDestroy());
48609051060SAkira Hatanaka Record.push_back(D->hasNonTrivialToPrimitiveDefaultInitializeCUnion());
48709051060SAkira Hatanaka Record.push_back(D->hasNonTrivialToPrimitiveDestructCUnion());
48809051060SAkira Hatanaka Record.push_back(D->hasNonTrivialToPrimitiveCopyCUnion());
489fcbe17c6SAkira Hatanaka Record.push_back(D->isParamDestroyedInCallee());
490e6313aceSAkira Hatanaka Record.push_back(D->getArgPassingRestrictions());
49103412ba0SDouglas Gregor
4928aed4222SRichard Smith if (D->getDeclContext() == D->getLexicalDeclContext() &&
4938aed4222SRichard Smith !D->hasAttrs() &&
49403412ba0SDouglas Gregor !D->isImplicit() &&
49503412ba0SDouglas Gregor !D->isUsed(false) &&
49603412ba0SDouglas Gregor !D->hasExtInfo() &&
49770d58509SRichard Smith !D->getTypedefNameForAnonDecl() &&
4988db352d5SRafael Espindola D->getFirstDecl() == D->getMostRecentDecl() &&
49903412ba0SDouglas Gregor !D->isInvalidDecl() &&
50003412ba0SDouglas Gregor !D->isReferenced() &&
501a7245005SArgyrios Kyrtzidis !D->isTopLevelDeclInObjCContainer() &&
50203412ba0SDouglas Gregor D->getAccess() == AS_none &&
50326701a43SDouglas Gregor !D->isModulePrivate() &&
50403412ba0SDouglas Gregor !CXXRecordDecl::classofKind(D->getKind()) &&
505d08aeb6bSRichard Smith !needsAnonymousDeclarationNumber(D) &&
50603412ba0SDouglas Gregor D->getDeclName().getNameKind() == DeclarationName::Identifier)
50703412ba0SDouglas Gregor AbbrevToUse = Writer.getDeclRecordAbbrev();
50803412ba0SDouglas Gregor
509539c5061SSebastian Redl Code = serialization::DECL_RECORD;
510d6522cfcSSebastian Redl }
511d6522cfcSSebastian Redl
VisitValueDecl(ValueDecl * D)512d6522cfcSSebastian Redl void ASTDeclWriter::VisitValueDecl(ValueDecl *D) {
513d6522cfcSSebastian Redl VisitNamedDecl(D);
51469c82bfaSRichard Smith Record.AddTypeRef(D->getType());
515d6522cfcSSebastian Redl }
516d6522cfcSSebastian Redl
VisitEnumConstantDecl(EnumConstantDecl * D)517d6522cfcSSebastian Redl void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) {
518d6522cfcSSebastian Redl VisitValueDecl(D);
519d6522cfcSSebastian Redl Record.push_back(D->getInitExpr()? 1 : 0);
520d6522cfcSSebastian Redl if (D->getInitExpr())
521290d8019SRichard Smith Record.AddStmt(D->getInitExpr());
52269c82bfaSRichard Smith Record.AddAPSInt(D->getInitVal());
52303412ba0SDouglas Gregor
524539c5061SSebastian Redl Code = serialization::DECL_ENUM_CONSTANT;
525d6522cfcSSebastian Redl }
526d6522cfcSSebastian Redl
VisitDeclaratorDecl(DeclaratorDecl * D)527d6522cfcSSebastian Redl void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
528d6522cfcSSebastian Redl VisitValueDecl(D);
52969c82bfaSRichard Smith Record.AddSourceLocation(D->getInnerLocStart());
530434383d7SArgyrios Kyrtzidis Record.push_back(D->hasExtInfo());
531b65b1f32SSaar Raz if (D->hasExtInfo()) {
532b65b1f32SSaar Raz DeclaratorDecl::ExtInfo *Info = D->getExtInfo();
533b65b1f32SSaar Raz Record.AddQualifierInfo(*Info);
534b65b1f32SSaar Raz Record.AddStmt(Info->TrailingRequiresClause);
535b65b1f32SSaar Raz }
536c23d734dSRichard Smith // The location information is deferred until the end of the record.
537c23d734dSRichard Smith Record.AddTypeRef(D->getTypeSourceInfo() ? D->getTypeSourceInfo()->getType()
538c23d734dSRichard Smith : QualType());
539d6522cfcSSebastian Redl }
540d6522cfcSSebastian Redl
VisitFunctionDecl(FunctionDecl * D)541d6522cfcSSebastian Redl void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
542f4bc0d87SArgyrios Kyrtzidis VisitRedeclarable(D);
5433e30010dSDouglas Gregor VisitDeclaratorDecl(D);
54469c82bfaSRichard Smith Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
545d6522cfcSSebastian Redl Record.push_back(D->getIdentifierNamespace());
546b2585694SDouglas Gregor
547b2585694SDouglas Gregor // FunctionDecl's body is handled last at ASTWriterDecl::Visit,
548b2585694SDouglas Gregor // after everything else is written.
5499c665066SErich Keane Record.push_back(static_cast<int>(D->getStorageClass())); // FIXME: stable encoding
5509c665066SErich Keane Record.push_back(D->isInlineSpecified());
5519c665066SErich Keane Record.push_back(D->isInlined());
5529c665066SErich Keane Record.push_back(D->isVirtualAsWritten());
5539c665066SErich Keane Record.push_back(D->isPure());
5549c665066SErich Keane Record.push_back(D->hasInheritedPrototype());
5559c665066SErich Keane Record.push_back(D->hasWrittenPrototype());
5569c665066SErich Keane Record.push_back(D->isDeletedBit());
5579c665066SErich Keane Record.push_back(D->isTrivial());
5589c665066SErich Keane Record.push_back(D->isTrivialForCall());
5599c665066SErich Keane Record.push_back(D->isDefaulted());
5609c665066SErich Keane Record.push_back(D->isExplicitlyDefaulted());
5619c665066SErich Keane Record.push_back(D->hasImplicitReturnZero());
56241b65f16SThorsten Record.push_back(static_cast<uint64_t>(D->getConstexprKind()));
5639c665066SErich Keane Record.push_back(D->usesSEHTry());
5649c665066SErich Keane Record.push_back(D->hasSkippedBody());
5659c665066SErich Keane Record.push_back(D->isMultiVersion());
5669c665066SErich Keane Record.push_back(D->isLateTemplateParsed());
5673ae00052SRafael Espindola Record.push_back(D->getLinkageInternal());
5681c301dcbSStephen Kelly Record.AddSourceLocation(D->getEndLoc());
569b2585694SDouglas Gregor
570e6caa26eSRichard Trieu Record.push_back(D->getODRHash());
571e6caa26eSRichard Trieu
572848934c6SRichard Smith if (D->isDefaulted()) {
573848934c6SRichard Smith if (auto *FDI = D->getDefaultedFunctionInfo()) {
574848934c6SRichard Smith Record.push_back(FDI->getUnqualifiedLookups().size());
575848934c6SRichard Smith for (DeclAccessPair P : FDI->getUnqualifiedLookups()) {
576848934c6SRichard Smith Record.AddDeclRef(P.getDecl());
577848934c6SRichard Smith Record.push_back(P.getAccess());
578848934c6SRichard Smith }
579848934c6SRichard Smith } else {
580848934c6SRichard Smith Record.push_back(0);
581848934c6SRichard Smith }
582848934c6SRichard Smith }
583848934c6SRichard Smith
584d6522cfcSSebastian Redl Record.push_back(D->getTemplatedKind());
585d6522cfcSSebastian Redl switch (D->getTemplatedKind()) {
586d6522cfcSSebastian Redl case FunctionDecl::TK_NonTemplate:
587d6522cfcSSebastian Redl break;
588*3ff86f96SErich Keane case FunctionDecl::TK_DependentNonTemplate:
589*3ff86f96SErich Keane Record.AddDeclRef(D->getInstantiatedFromDecl());
590*3ff86f96SErich Keane break;
591d6522cfcSSebastian Redl case FunctionDecl::TK_FunctionTemplate:
59269c82bfaSRichard Smith Record.AddDeclRef(D->getDescribedFunctionTemplate());
593d6522cfcSSebastian Redl break;
594d6522cfcSSebastian Redl case FunctionDecl::TK_MemberSpecialization: {
595d6522cfcSSebastian Redl MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo();
59669c82bfaSRichard Smith Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
597d6522cfcSSebastian Redl Record.push_back(MemberInfo->getTemplateSpecializationKind());
59869c82bfaSRichard Smith Record.AddSourceLocation(MemberInfo->getPointOfInstantiation());
599d6522cfcSSebastian Redl break;
600d6522cfcSSebastian Redl }
601d6522cfcSSebastian Redl case FunctionDecl::TK_FunctionTemplateSpecialization: {
602d6522cfcSSebastian Redl FunctionTemplateSpecializationInfo *
603d6522cfcSSebastian Redl FTSInfo = D->getTemplateSpecializationInfo();
604d8a83718SRichard Smith
605d8a83718SRichard Smith RegisterTemplateSpecialization(FTSInfo->getTemplate(), D);
606d8a83718SRichard Smith
60769c82bfaSRichard Smith Record.AddDeclRef(FTSInfo->getTemplate());
608d6522cfcSSebastian Redl Record.push_back(FTSInfo->getTemplateSpecializationKind());
609d6522cfcSSebastian Redl
610d6522cfcSSebastian Redl // Template arguments.
61169c82bfaSRichard Smith Record.AddTemplateArgumentList(FTSInfo->TemplateArguments);
612d6522cfcSSebastian Redl
613d6522cfcSSebastian Redl // Template args as written.
614a13603a2SCraig Topper Record.push_back(FTSInfo->TemplateArgumentsAsWritten != nullptr);
615d6522cfcSSebastian Redl if (FTSInfo->TemplateArgumentsAsWritten) {
616e9a24435SArgyrios Kyrtzidis Record.push_back(FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs);
617e9a24435SArgyrios Kyrtzidis for (int i=0, e = FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs;
618e9a24435SArgyrios Kyrtzidis i!=e; ++i)
61969c82bfaSRichard Smith Record.AddTemplateArgumentLoc(
62069c82bfaSRichard Smith (*FTSInfo->TemplateArgumentsAsWritten)[i]);
62169c82bfaSRichard Smith Record.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->LAngleLoc);
62269c82bfaSRichard Smith Record.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->RAngleLoc);
623d6522cfcSSebastian Redl }
624d6522cfcSSebastian Redl
62569c82bfaSRichard Smith Record.AddSourceLocation(FTSInfo->getPointOfInstantiation());
626f24d569fSArgyrios Kyrtzidis
627f19a8b05SRichard Smith if (MemberSpecializationInfo *MemberInfo =
628f19a8b05SRichard Smith FTSInfo->getMemberSpecializationInfo()) {
629f19a8b05SRichard Smith Record.push_back(1);
630f19a8b05SRichard Smith Record.AddDeclRef(MemberInfo->getInstantiatedFrom());
631f19a8b05SRichard Smith Record.push_back(MemberInfo->getTemplateSpecializationKind());
632f19a8b05SRichard Smith Record.AddSourceLocation(MemberInfo->getPointOfInstantiation());
633f19a8b05SRichard Smith } else {
634f19a8b05SRichard Smith Record.push_back(0);
635f19a8b05SRichard Smith }
636f19a8b05SRichard Smith
637f24d569fSArgyrios Kyrtzidis if (D->isCanonicalDecl()) {
638f24d569fSArgyrios Kyrtzidis // Write the template that contains the specializations set. We will
639f24d569fSArgyrios Kyrtzidis // add a FunctionTemplateSpecializationInfo to it when reading.
64069c82bfaSRichard Smith Record.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl());
641f24d569fSArgyrios Kyrtzidis }
642d6522cfcSSebastian Redl break;
643d6522cfcSSebastian Redl }
644d6522cfcSSebastian Redl case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
645d6522cfcSSebastian Redl DependentFunctionTemplateSpecializationInfo *
646d6522cfcSSebastian Redl DFTSInfo = D->getDependentSpecializationInfo();
647d6522cfcSSebastian Redl
648d6522cfcSSebastian Redl // Templates.
649d6522cfcSSebastian Redl Record.push_back(DFTSInfo->getNumTemplates());
650d6522cfcSSebastian Redl for (int i=0, e = DFTSInfo->getNumTemplates(); i != e; ++i)
65169c82bfaSRichard Smith Record.AddDeclRef(DFTSInfo->getTemplate(i));
652d6522cfcSSebastian Redl
653d6522cfcSSebastian Redl // Templates args.
654d6522cfcSSebastian Redl Record.push_back(DFTSInfo->getNumTemplateArgs());
655d6522cfcSSebastian Redl for (int i=0, e = DFTSInfo->getNumTemplateArgs(); i != e; ++i)
65669c82bfaSRichard Smith Record.AddTemplateArgumentLoc(DFTSInfo->getTemplateArg(i));
65769c82bfaSRichard Smith Record.AddSourceLocation(DFTSInfo->getLAngleLoc());
65869c82bfaSRichard Smith Record.AddSourceLocation(DFTSInfo->getRAngleLoc());
659d6522cfcSSebastian Redl break;
660d6522cfcSSebastian Redl }
661d6522cfcSSebastian Redl }
662d6522cfcSSebastian Redl
663d6522cfcSSebastian Redl Record.push_back(D->param_size());
66459f77921SDavid Majnemer for (auto P : D->parameters())
66569c82bfaSRichard Smith Record.AddDeclRef(P);
666539c5061SSebastian Redl Code = serialization::DECL_FUNCTION;
667d6522cfcSSebastian Redl }
668d6522cfcSSebastian Redl
addExplicitSpecifier(ExplicitSpecifier ES,ASTRecordWriter & Record)66976b9027fSRichard Smith static void addExplicitSpecifier(ExplicitSpecifier ES,
67076b9027fSRichard Smith ASTRecordWriter &Record) {
67176b9027fSRichard Smith uint64_t Kind = static_cast<uint64_t>(ES.getKind());
67276b9027fSRichard Smith Kind = Kind << 1 | static_cast<bool>(ES.getExpr());
67376b9027fSRichard Smith Record.push_back(Kind);
67476b9027fSRichard Smith if (ES.getExpr()) {
67576b9027fSRichard Smith Record.AddStmt(ES.getExpr());
67676b9027fSRichard Smith }
67776b9027fSRichard Smith }
67876b9027fSRichard Smith
VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl * D)679bc491203SRichard Smith void ASTDeclWriter::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) {
68076b9027fSRichard Smith addExplicitSpecifier(D->getExplicitSpecifier(), Record);
681d38057f3SRichard Smith Record.AddDeclRef(D->Ctor);
682bc491203SRichard Smith VisitFunctionDecl(D);
6839c665066SErich Keane Record.push_back(D->isCopyDeductionCandidate());
684bc491203SRichard Smith Code = serialization::DECL_CXX_DEDUCTION_GUIDE;
685bc491203SRichard Smith }
686bc491203SRichard Smith
VisitObjCMethodDecl(ObjCMethodDecl * D)687d6522cfcSSebastian Redl void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
688d6522cfcSSebastian Redl VisitNamedDecl(D);
689d6522cfcSSebastian Redl // FIXME: convert to LazyStmtPtr?
690d6522cfcSSebastian Redl // Unlike C/C++, method bodies will never be in header files.
691f3efd695SAlex Lorenz bool HasBodyStuff = D->getBody() != nullptr;
692d6522cfcSSebastian Redl Record.push_back(HasBodyStuff);
693d6522cfcSSebastian Redl if (HasBodyStuff) {
694290d8019SRichard Smith Record.AddStmt(D->getBody());
695f3efd695SAlex Lorenz }
69669c82bfaSRichard Smith Record.AddDeclRef(D->getSelfDecl());
69769c82bfaSRichard Smith Record.AddDeclRef(D->getCmdDecl());
698d6522cfcSSebastian Redl Record.push_back(D->isInstanceMethod());
699d6522cfcSSebastian Redl Record.push_back(D->isVariadic());
700d01e83abSJordan Rose Record.push_back(D->isPropertyAccessor());
7012073dd2dSAdrian Prantl Record.push_back(D->isSynthesizedAccessorStub());
702d6522cfcSSebastian Redl Record.push_back(D->isDefined());
7039b18eca3SErich Keane Record.push_back(D->isOverriding());
7049b18eca3SErich Keane Record.push_back(D->hasSkippedBody());
705db215964SArgyrios Kyrtzidis
7069b18eca3SErich Keane Record.push_back(D->isRedeclaration());
7079b18eca3SErich Keane Record.push_back(D->hasRedeclaration());
7089b18eca3SErich Keane if (D->hasRedeclaration()) {
709db215964SArgyrios Kyrtzidis assert(Context.getObjCMethodRedeclaration(D));
71069c82bfaSRichard Smith Record.AddDeclRef(Context.getObjCMethodRedeclaration(D));
711db215964SArgyrios Kyrtzidis }
712db215964SArgyrios Kyrtzidis
713d6522cfcSSebastian Redl // FIXME: stable encoding for @required/@optional
714d6522cfcSSebastian Redl Record.push_back(D->getImplementationControl());
715813a066fSDouglas Gregor // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway/nullability
716d6522cfcSSebastian Redl Record.push_back(D->getObjCDeclQualifier());
71733823727SDouglas Gregor Record.push_back(D->hasRelatedResultType());
71869c82bfaSRichard Smith Record.AddTypeRef(D->getReturnType());
71969c82bfaSRichard Smith Record.AddTypeSourceInfo(D->getReturnTypeSourceInfo());
7201c301dcbSStephen Kelly Record.AddSourceLocation(D->getEndLoc());
721d6522cfcSSebastian Redl Record.push_back(D->param_size());
72259f77921SDavid Majnemer for (const auto *P : D->parameters())
72369c82bfaSRichard Smith Record.AddDeclRef(P);
724b8c3aaf4SArgyrios Kyrtzidis
7259b18eca3SErich Keane Record.push_back(D->getSelLocsKind());
726b8c3aaf4SArgyrios Kyrtzidis unsigned NumStoredSelLocs = D->getNumStoredSelLocs();
727b8c3aaf4SArgyrios Kyrtzidis SourceLocation *SelLocs = D->getStoredSelLocs();
728b8c3aaf4SArgyrios Kyrtzidis Record.push_back(NumStoredSelLocs);
729b8c3aaf4SArgyrios Kyrtzidis for (unsigned i = 0; i != NumStoredSelLocs; ++i)
73069c82bfaSRichard Smith Record.AddSourceLocation(SelLocs[i]);
731b8c3aaf4SArgyrios Kyrtzidis
732539c5061SSebastian Redl Code = serialization::DECL_OBJC_METHOD;
733d6522cfcSSebastian Redl }
734d6522cfcSSebastian Redl
VisitObjCTypeParamDecl(ObjCTypeParamDecl * D)73585f3f951SDouglas Gregor void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
73685f3f951SDouglas Gregor VisitTypedefNameDecl(D);
7371ac1b63cSDouglas Gregor Record.push_back(D->Variance);
738e83b9564SDouglas Gregor Record.push_back(D->Index);
73969c82bfaSRichard Smith Record.AddSourceLocation(D->VarianceLoc);
74069c82bfaSRichard Smith Record.AddSourceLocation(D->ColonLoc);
74185f3f951SDouglas Gregor
74285f3f951SDouglas Gregor Code = serialization::DECL_OBJC_TYPE_PARAM;
74385f3f951SDouglas Gregor }
74485f3f951SDouglas Gregor
VisitObjCContainerDecl(ObjCContainerDecl * D)745d6522cfcSSebastian Redl void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) {
746d6522cfcSSebastian Redl VisitNamedDecl(D);
74769c82bfaSRichard Smith Record.AddSourceLocation(D->getAtStartLoc());
74869c82bfaSRichard Smith Record.AddSourceRange(D->getAtEndRange());
749539c5061SSebastian Redl // Abstract class (no need to define a stable serialization::DECL code).
750d6522cfcSSebastian Redl }
751d6522cfcSSebastian Redl
VisitObjCInterfaceDecl(ObjCInterfaceDecl * D)752d6522cfcSSebastian Redl void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
75366b310c6SDouglas Gregor VisitRedeclarable(D);
754d6522cfcSSebastian Redl VisitObjCContainerDecl(D);
75569c82bfaSRichard Smith Record.AddTypeRef(QualType(D->getTypeForDecl(), 0));
75685f3f951SDouglas Gregor AddObjCTypeParamList(D->TypeParamList);
757c0ac7d68SDouglas Gregor
7583a5ae564SDouglas Gregor Record.push_back(D->isThisDeclarationADefinition());
7593a5ae564SDouglas Gregor if (D->isThisDeclarationADefinition()) {
760c0ac7d68SDouglas Gregor // Write the DefinitionData
761c0ac7d68SDouglas Gregor ObjCInterfaceDecl::DefinitionData &Data = D->data();
762c0ac7d68SDouglas Gregor
76369c82bfaSRichard Smith Record.AddTypeSourceInfo(D->getSuperClassTInfo());
76469c82bfaSRichard Smith Record.AddSourceLocation(D->getEndOfDefinitionLoc());
7659ed9e5f3SArgyrios Kyrtzidis Record.push_back(Data.HasDesignatedInitializers);
7660ef508d3STed Kremenek
7670ef508d3STed Kremenek // Write out the protocols that are directly referenced by the @interface.
768c0ac7d68SDouglas Gregor Record.push_back(Data.ReferencedProtocols.size());
769a49c5064SAaron Ballman for (const auto *P : D->protocols())
77069c82bfaSRichard Smith Record.AddDeclRef(P);
771e937888eSAaron Ballman for (const auto &PL : D->protocol_locs())
77269c82bfaSRichard Smith Record.AddSourceLocation(PL);
7730ef508d3STed Kremenek
7740ef508d3STed Kremenek // Write out the protocols that are transitively referenced.
775c0ac7d68SDouglas Gregor Record.push_back(Data.AllReferencedProtocols.size());
7760ef508d3STed Kremenek for (ObjCList<ObjCProtocolDecl>::iterator
777c0ac7d68SDouglas Gregor P = Data.AllReferencedProtocols.begin(),
778c0ac7d68SDouglas Gregor PEnd = Data.AllReferencedProtocols.end();
7790ef508d3STed Kremenek P != PEnd; ++P)
78069c82bfaSRichard Smith Record.AddDeclRef(*P);
7810ef508d3STed Kremenek
782048fbfa3SDouglas Gregor
783048fbfa3SDouglas Gregor if (ObjCCategoryDecl *Cat = D->getCategoryListRaw()) {
784404cddecSDouglas Gregor // Ensure that we write out the set of categories for this class.
785404cddecSDouglas Gregor Writer.ObjCClassesWithCategories.insert(D);
786404cddecSDouglas Gregor
787404cddecSDouglas Gregor // Make sure that the categories get serialized.
788048fbfa3SDouglas Gregor for (; Cat; Cat = Cat->getNextClassCategoryRaw())
789404cddecSDouglas Gregor (void)Writer.GetDeclRef(Cat);
790404cddecSDouglas Gregor }
791c0ac7d68SDouglas Gregor }
792c0ac7d68SDouglas Gregor
793539c5061SSebastian Redl Code = serialization::DECL_OBJC_INTERFACE;
794d6522cfcSSebastian Redl }
795d6522cfcSSebastian Redl
VisitObjCIvarDecl(ObjCIvarDecl * D)796d6522cfcSSebastian Redl void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
797d6522cfcSSebastian Redl VisitFieldDecl(D);
798d6522cfcSSebastian Redl // FIXME: stable encoding for @public/@private/@protected/@package
799d6522cfcSSebastian Redl Record.push_back(D->getAccessControl());
800d6522cfcSSebastian Redl Record.push_back(D->getSynthesize());
801205c7d55SJonathan D. Turner
8028aed4222SRichard Smith if (D->getDeclContext() == D->getLexicalDeclContext() &&
8038aed4222SRichard Smith !D->hasAttrs() &&
804205c7d55SJonathan D. Turner !D->isImplicit() &&
805205c7d55SJonathan D. Turner !D->isUsed(false) &&
806205c7d55SJonathan D. Turner !D->isInvalidDecl() &&
807205c7d55SJonathan D. Turner !D->isReferenced() &&
80826701a43SDouglas Gregor !D->isModulePrivate() &&
809205c7d55SJonathan D. Turner !D->getBitWidth() &&
810205c7d55SJonathan D. Turner !D->hasExtInfo() &&
811205c7d55SJonathan D. Turner D->getDeclName())
812205c7d55SJonathan D. Turner AbbrevToUse = Writer.getDeclObjCIvarAbbrev();
813205c7d55SJonathan D. Turner
814539c5061SSebastian Redl Code = serialization::DECL_OBJC_IVAR;
815d6522cfcSSebastian Redl }
816d6522cfcSSebastian Redl
VisitObjCProtocolDecl(ObjCProtocolDecl * D)817d6522cfcSSebastian Redl void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
818a715bfffSDouglas Gregor VisitRedeclarable(D);
819d6522cfcSSebastian Redl VisitObjCContainerDecl(D);
820e6e48b14SDouglas Gregor
8213a5ae564SDouglas Gregor Record.push_back(D->isThisDeclarationADefinition());
8223a5ae564SDouglas Gregor if (D->isThisDeclarationADefinition()) {
823d6522cfcSSebastian Redl Record.push_back(D->protocol_size());
8240f6e64d5SAaron Ballman for (const auto *I : D->protocols())
82569c82bfaSRichard Smith Record.AddDeclRef(I);
826a964ec1fSAaron Ballman for (const auto &PL : D->protocol_locs())
82769c82bfaSRichard Smith Record.AddSourceLocation(PL);
828e6e48b14SDouglas Gregor }
829e6e48b14SDouglas Gregor
830539c5061SSebastian Redl Code = serialization::DECL_OBJC_PROTOCOL;
831d6522cfcSSebastian Redl }
832d6522cfcSSebastian Redl
VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl * D)833d6522cfcSSebastian Redl void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) {
834d6522cfcSSebastian Redl VisitFieldDecl(D);
835539c5061SSebastian Redl Code = serialization::DECL_OBJC_AT_DEFS_FIELD;
836d6522cfcSSebastian Redl }
837d6522cfcSSebastian Redl
VisitObjCCategoryDecl(ObjCCategoryDecl * D)838d6522cfcSSebastian Redl void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
839d6522cfcSSebastian Redl VisitObjCContainerDecl(D);
84069c82bfaSRichard Smith Record.AddSourceLocation(D->getCategoryNameLoc());
84169c82bfaSRichard Smith Record.AddSourceLocation(D->getIvarLBraceLoc());
84269c82bfaSRichard Smith Record.AddSourceLocation(D->getIvarRBraceLoc());
84369c82bfaSRichard Smith Record.AddDeclRef(D->getClassInterface());
84485f3f951SDouglas Gregor AddObjCTypeParamList(D->TypeParamList);
845d6522cfcSSebastian Redl Record.push_back(D->protocol_size());
84619a41769SAaron Ballman for (const auto *I : D->protocols())
84769c82bfaSRichard Smith Record.AddDeclRef(I);
848a73c8573SAaron Ballman for (const auto &PL : D->protocol_locs())
84969c82bfaSRichard Smith Record.AddSourceLocation(PL);
850539c5061SSebastian Redl Code = serialization::DECL_OBJC_CATEGORY;
851d6522cfcSSebastian Redl }
852d6522cfcSSebastian Redl
VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl * D)853d6522cfcSSebastian Redl void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) {
854d6522cfcSSebastian Redl VisitNamedDecl(D);
85569c82bfaSRichard Smith Record.AddDeclRef(D->getClassInterface());
856539c5061SSebastian Redl Code = serialization::DECL_OBJC_COMPATIBLE_ALIAS;
857d6522cfcSSebastian Redl }
858d6522cfcSSebastian Redl
VisitObjCPropertyDecl(ObjCPropertyDecl * D)859d6522cfcSSebastian Redl void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
860d6522cfcSSebastian Redl VisitNamedDecl(D);
86169c82bfaSRichard Smith Record.AddSourceLocation(D->getAtLoc());
86269c82bfaSRichard Smith Record.AddSourceLocation(D->getLParenLoc());
86369c82bfaSRichard Smith Record.AddTypeRef(D->getType());
86469c82bfaSRichard Smith Record.AddTypeSourceInfo(D->getTypeSourceInfo());
865d6522cfcSSebastian Redl // FIXME: stable encoding
866d6522cfcSSebastian Redl Record.push_back((unsigned)D->getPropertyAttributes());
867d6522cfcSSebastian Redl Record.push_back((unsigned)D->getPropertyAttributesAsWritten());
868d6522cfcSSebastian Redl // FIXME: stable encoding
869d6522cfcSSebastian Redl Record.push_back((unsigned)D->getPropertyImplementation());
87069c82bfaSRichard Smith Record.AddDeclarationName(D->getGetterName());
871194b28ebSArgyrios Kyrtzidis Record.AddSourceLocation(D->getGetterNameLoc());
87269c82bfaSRichard Smith Record.AddDeclarationName(D->getSetterName());
873194b28ebSArgyrios Kyrtzidis Record.AddSourceLocation(D->getSetterNameLoc());
87469c82bfaSRichard Smith Record.AddDeclRef(D->getGetterMethodDecl());
87569c82bfaSRichard Smith Record.AddDeclRef(D->getSetterMethodDecl());
87669c82bfaSRichard Smith Record.AddDeclRef(D->getPropertyIvarDecl());
877539c5061SSebastian Redl Code = serialization::DECL_OBJC_PROPERTY;
878d6522cfcSSebastian Redl }
879d6522cfcSSebastian Redl
VisitObjCImplDecl(ObjCImplDecl * D)880d6522cfcSSebastian Redl void ASTDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) {
881d6522cfcSSebastian Redl VisitObjCContainerDecl(D);
88269c82bfaSRichard Smith Record.AddDeclRef(D->getClassInterface());
883539c5061SSebastian Redl // Abstract class (no need to define a stable serialization::DECL code).
884d6522cfcSSebastian Redl }
885d6522cfcSSebastian Redl
VisitObjCCategoryImplDecl(ObjCCategoryImplDecl * D)886d6522cfcSSebastian Redl void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
887d6522cfcSSebastian Redl VisitObjCImplDecl(D);
88869c82bfaSRichard Smith Record.AddSourceLocation(D->getCategoryNameLoc());
889539c5061SSebastian Redl Code = serialization::DECL_OBJC_CATEGORY_IMPL;
890d6522cfcSSebastian Redl }
891d6522cfcSSebastian Redl
VisitObjCImplementationDecl(ObjCImplementationDecl * D)892d6522cfcSSebastian Redl void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
893d6522cfcSSebastian Redl VisitObjCImplDecl(D);
89469c82bfaSRichard Smith Record.AddDeclRef(D->getSuperClass());
89569c82bfaSRichard Smith Record.AddSourceLocation(D->getSuperClassLoc());
89669c82bfaSRichard Smith Record.AddSourceLocation(D->getIvarLBraceLoc());
89769c82bfaSRichard Smith Record.AddSourceLocation(D->getIvarRBraceLoc());
8980d54a17bSJohn McCall Record.push_back(D->hasNonZeroConstructors());
8990d54a17bSJohn McCall Record.push_back(D->hasDestructors());
900c2bb8186SRichard Smith Record.push_back(D->NumIvarInitializers);
901c2bb8186SRichard Smith if (D->NumIvarInitializers)
902aa165cf7SRichard Smith Record.AddCXXCtorInitializers(
90369c82bfaSRichard Smith llvm::makeArrayRef(D->init_begin(), D->init_end()));
904539c5061SSebastian Redl Code = serialization::DECL_OBJC_IMPLEMENTATION;
905d6522cfcSSebastian Redl }
906d6522cfcSSebastian Redl
VisitObjCPropertyImplDecl(ObjCPropertyImplDecl * D)907d6522cfcSSebastian Redl void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
908d6522cfcSSebastian Redl VisitDecl(D);
909f2ceec48SStephen Kelly Record.AddSourceLocation(D->getBeginLoc());
91069c82bfaSRichard Smith Record.AddDeclRef(D->getPropertyDecl());
91169c82bfaSRichard Smith Record.AddDeclRef(D->getPropertyIvarDecl());
91269c82bfaSRichard Smith Record.AddSourceLocation(D->getPropertyIvarDeclLoc());
9132073dd2dSAdrian Prantl Record.AddDeclRef(D->getGetterMethodDecl());
9142073dd2dSAdrian Prantl Record.AddDeclRef(D->getSetterMethodDecl());
915290d8019SRichard Smith Record.AddStmt(D->getGetterCXXConstructor());
916290d8019SRichard Smith Record.AddStmt(D->getSetterCXXAssignment());
917539c5061SSebastian Redl Code = serialization::DECL_OBJC_PROPERTY_IMPL;
918d6522cfcSSebastian Redl }
919d6522cfcSSebastian Redl
VisitFieldDecl(FieldDecl * D)920d6522cfcSSebastian Redl void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) {
921d6522cfcSSebastian Redl VisitDeclaratorDecl(D);
922d6522cfcSSebastian Redl Record.push_back(D->isMutable());
9236b8e3c02SRichard Smith
9246b8e3c02SRichard Smith FieldDecl::InitStorageKind ISK = D->InitStorage.getInt();
9256b8e3c02SRichard Smith Record.push_back(ISK);
9266b8e3c02SRichard Smith if (ISK == FieldDecl::ISK_CapturedVLAType)
9276b8e3c02SRichard Smith Record.AddTypeRef(QualType(D->getCapturedVLAType(), 0));
9286b8e3c02SRichard Smith else if (ISK)
9296b8e3c02SRichard Smith Record.AddStmt(D->getInClassInitializer());
9306b8e3c02SRichard Smith
9316b8e3c02SRichard Smith Record.AddStmt(D->getBitWidth());
9326b8e3c02SRichard Smith
933d6522cfcSSebastian Redl if (!D->getDeclName())
93469c82bfaSRichard Smith Record.AddDeclRef(Context.getInstantiatedFromUnnamedFieldDecl(D));
935205c7d55SJonathan D. Turner
9368aed4222SRichard Smith if (D->getDeclContext() == D->getLexicalDeclContext() &&
9378aed4222SRichard Smith !D->hasAttrs() &&
938205c7d55SJonathan D. Turner !D->isImplicit() &&
939205c7d55SJonathan D. Turner !D->isUsed(false) &&
940205c7d55SJonathan D. Turner !D->isInvalidDecl() &&
941205c7d55SJonathan D. Turner !D->isReferenced() &&
942a7245005SArgyrios Kyrtzidis !D->isTopLevelDeclInObjCContainer() &&
94326701a43SDouglas Gregor !D->isModulePrivate() &&
944205c7d55SJonathan D. Turner !D->getBitWidth() &&
945938f40b5SRichard Smith !D->hasInClassInitializer() &&
9466b8e3c02SRichard Smith !D->hasCapturedVLAType() &&
947205c7d55SJonathan D. Turner !D->hasExtInfo() &&
948205c7d55SJonathan D. Turner !ObjCIvarDecl::classofKind(D->getKind()) &&
949205c7d55SJonathan D. Turner !ObjCAtDefsFieldDecl::classofKind(D->getKind()) &&
950205c7d55SJonathan D. Turner D->getDeclName())
951205c7d55SJonathan D. Turner AbbrevToUse = Writer.getDeclFieldAbbrev();
952205c7d55SJonathan D. Turner
953539c5061SSebastian Redl Code = serialization::DECL_FIELD;
954d6522cfcSSebastian Redl }
955d6522cfcSSebastian Redl
VisitMSPropertyDecl(MSPropertyDecl * D)9565e77d76cSJohn McCall void ASTDeclWriter::VisitMSPropertyDecl(MSPropertyDecl *D) {
9575e77d76cSJohn McCall VisitDeclaratorDecl(D);
95869c82bfaSRichard Smith Record.AddIdentifierRef(D->getGetterId());
95969c82bfaSRichard Smith Record.AddIdentifierRef(D->getSetterId());
9605e77d76cSJohn McCall Code = serialization::DECL_MS_PROPERTY;
9615e77d76cSJohn McCall }
9625e77d76cSJohn McCall
VisitMSGuidDecl(MSGuidDecl * D)963bab6df86SRichard Smith void ASTDeclWriter::VisitMSGuidDecl(MSGuidDecl *D) {
964bab6df86SRichard Smith VisitValueDecl(D);
965bab6df86SRichard Smith MSGuidDecl::Parts Parts = D->getParts();
966bab6df86SRichard Smith Record.push_back(Parts.Part1);
967bab6df86SRichard Smith Record.push_back(Parts.Part2);
968bab6df86SRichard Smith Record.push_back(Parts.Part3);
9695d2ce766SBenjamin Kramer Record.append(std::begin(Parts.Part4And5), std::end(Parts.Part4And5));
970bab6df86SRichard Smith Code = serialization::DECL_MS_GUID;
971bab6df86SRichard Smith }
972bab6df86SRichard Smith
VisitUnnamedGlobalConstantDecl(UnnamedGlobalConstantDecl * D)973d6148749SJames Y Knight void ASTDeclWriter::VisitUnnamedGlobalConstantDecl(
974d6148749SJames Y Knight UnnamedGlobalConstantDecl *D) {
975d6148749SJames Y Knight VisitValueDecl(D);
976d6148749SJames Y Knight Record.AddAPValue(D->getValue());
977d6148749SJames Y Knight Code = serialization::DECL_UNNAMED_GLOBAL_CONSTANT;
978d6148749SJames Y Knight }
979d6148749SJames Y Knight
VisitTemplateParamObjectDecl(TemplateParamObjectDecl * D)980ba4768c9SRichard Smith void ASTDeclWriter::VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D) {
981ba4768c9SRichard Smith VisitValueDecl(D);
982ba4768c9SRichard Smith Record.AddAPValue(D->getValue());
983ba4768c9SRichard Smith Code = serialization::DECL_TEMPLATE_PARAM_OBJECT;
984ba4768c9SRichard Smith }
985ba4768c9SRichard Smith
VisitIndirectFieldDecl(IndirectFieldDecl * D)986783dd6ecSFrancois Pichet void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
987783dd6ecSFrancois Pichet VisitValueDecl(D);
988783dd6ecSFrancois Pichet Record.push_back(D->getChainingSize());
989783dd6ecSFrancois Pichet
99029c9460dSAaron Ballman for (const auto *P : D->chain())
99169c82bfaSRichard Smith Record.AddDeclRef(P);
992783dd6ecSFrancois Pichet Code = serialization::DECL_INDIRECTFIELD;
993783dd6ecSFrancois Pichet }
994783dd6ecSFrancois Pichet
VisitVarDecl(VarDecl * D)995d6522cfcSSebastian Redl void ASTDeclWriter::VisitVarDecl(VarDecl *D) {
996f4bc0d87SArgyrios Kyrtzidis VisitRedeclarable(D);
9973e30010dSDouglas Gregor VisitDeclaratorDecl(D);
9982fd11e0bSThorsten Schütt Record.push_back(D->getStorageClass());
999acb8ecd6SEnea Zaffanella Record.push_back(D->getTSCSpec());
1000a935179aSSebastian Redl Record.push_back(D->getInitStyle());
10011e36882bSErik Pilkington Record.push_back(D->isARCPseudoStrong());
1002fa7bc78eSDavid Majnemer if (!isa<ParmVarDecl>(D)) {
1003edbc6e93SRichard Smith Record.push_back(D->isThisDeclarationADemotedDefinition());
1004d6522cfcSSebastian Redl Record.push_back(D->isExceptionVariable());
10053be68e16STaiju Tsuiki Record.push_back(D->isNRVOVariable());
100602e85f3bSRichard Smith Record.push_back(D->isCXXForRangeDecl());
1007ec38cf7aSGeorge Karpenkov Record.push_back(D->isObjCForDecl());
100862f19e70SRichard Smith Record.push_back(D->isInline());
100962f19e70SRichard Smith Record.push_back(D->isInlineSpecified());
101012cda633SDouglas Gregor Record.push_back(D->isConstexpr());
1011bb13c9a4SRichard Smith Record.push_back(D->isInitCapture());
10121c34fb78SRichard Smith Record.push_back(D->isPreviousDeclInSameBlockScope());
101356223237SAlexey Bataev if (const auto *IPD = dyn_cast<ImplicitParamDecl>(D))
101456223237SAlexey Bataev Record.push_back(static_cast<unsigned>(IPD->getParameterKind()));
101556223237SAlexey Bataev else
101656223237SAlexey Bataev Record.push_back(0);
10178e57b07fSAkira Hatanaka Record.push_back(D->isEscapingByref());
1018fa7bc78eSDavid Majnemer }
10193ae00052SRafael Espindola Record.push_back(D->getLinkageInternal());
102012cda633SDouglas Gregor
1021e56e7bd4SZequan Wu Record.AddVarDeclInit(D);
1022d6522cfcSSebastian Redl
10239978da36SAkira Hatanaka if (D->hasAttr<BlocksAttr>() && D->getType()->getAsCXXRecordDecl()) {
102460573ae6SReid Kleckner BlockVarCopyInit Init = Writer.Context->getBlockVarCopyInit(D);
10259978da36SAkira Hatanaka Record.AddStmt(Init.getCopyExpr());
10269978da36SAkira Hatanaka if (Init.getCopyExpr())
10279978da36SAkira Hatanaka Record.push_back(Init.canThrow());
10289978da36SAkira Hatanaka }
10299978da36SAkira Hatanaka
1030a465362dSRichard Smith if (D->getStorageDuration() == SD_Static) {
1031a465362dSRichard Smith bool ModulesCodegen = false;
10327ea9a6e0SHans Wennborg if (Writer.WritingModule &&
10337ea9a6e0SHans Wennborg !D->getDescribedVarTemplate() && !D->getMemberSpecializationInfo() &&
1034a465362dSRichard Smith !isa<VarTemplateSpecializationDecl>(D)) {
10353cec39b9SChuanqi Xu // When building a C++20 module interface unit or a partition unit, a
10363cec39b9SChuanqi Xu // strong definition in the module interface is provided by the
10373cec39b9SChuanqi Xu // compilation of that unit, not by its users. (Inline variables are still
10383cec39b9SChuanqi Xu // emitted in module users.)
1039a465362dSRichard Smith ModulesCodegen =
10403cec39b9SChuanqi Xu (Writer.WritingModule->isInterfaceOrPartition() ||
1041b198de67SDavid Blaikie (D->hasAttr<DLLExportAttr>() &&
1042b198de67SDavid Blaikie Writer.Context->getLangOpts().BuildingPCHWithObjectFile)) &&
1043b198de67SDavid Blaikie Writer.Context->GetGVALinkageForVariable(D) == GVA_StrongExternal;
1044a465362dSRichard Smith }
1045a465362dSRichard Smith Record.push_back(ModulesCodegen);
1046a465362dSRichard Smith if (ModulesCodegen)
1047a465362dSRichard Smith Writer.ModularCodegenDecls.push_back(Writer.GetDeclRef(D));
1048a465362dSRichard Smith }
1049a465362dSRichard Smith
1050d8dd97c0SLarisse Voufo enum {
1051d8dd97c0SLarisse Voufo VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
1052d8dd97c0SLarisse Voufo };
1053d8dd97c0SLarisse Voufo if (VarTemplateDecl *TemplD = D->getDescribedVarTemplate()) {
1054d8dd97c0SLarisse Voufo Record.push_back(VarTemplate);
105569c82bfaSRichard Smith Record.AddDeclRef(TemplD);
1056d8dd97c0SLarisse Voufo } else if (MemberSpecializationInfo *SpecInfo
1057d8dd97c0SLarisse Voufo = D->getMemberSpecializationInfo()) {
1058d8dd97c0SLarisse Voufo Record.push_back(StaticDataMemberSpecialization);
105969c82bfaSRichard Smith Record.AddDeclRef(SpecInfo->getInstantiatedFrom());
1060d6522cfcSSebastian Redl Record.push_back(SpecInfo->getTemplateSpecializationKind());
106169c82bfaSRichard Smith Record.AddSourceLocation(SpecInfo->getPointOfInstantiation());
1062d8dd97c0SLarisse Voufo } else {
1063d8dd97c0SLarisse Voufo Record.push_back(VarNotTemplate);
1064d6522cfcSSebastian Redl }
1065d6522cfcSSebastian Redl
10668aed4222SRichard Smith if (D->getDeclContext() == D->getLexicalDeclContext() &&
10678aed4222SRichard Smith !D->hasAttrs() &&
1068205c7d55SJonathan D. Turner !D->isImplicit() &&
1069205c7d55SJonathan D. Turner !D->isUsed(false) &&
1070205c7d55SJonathan D. Turner !D->isInvalidDecl() &&
1071205c7d55SJonathan D. Turner !D->isReferenced() &&
1072a7245005SArgyrios Kyrtzidis !D->isTopLevelDeclInObjCContainer() &&
1073205c7d55SJonathan D. Turner D->getAccess() == AS_none &&
107426701a43SDouglas Gregor !D->isModulePrivate() &&
1075d08aeb6bSRichard Smith !needsAnonymousDeclarationNumber(D) &&
1076205c7d55SJonathan D. Turner D->getDeclName().getNameKind() == DeclarationName::Identifier &&
1077205c7d55SJonathan D. Turner !D->hasExtInfo() &&
10788db352d5SRafael Espindola D->getFirstDecl() == D->getMostRecentDecl() &&
10797b76d81bSRichard Smith D->getKind() == Decl::Var &&
108062f19e70SRichard Smith !D->isInline() &&
108112cda633SDouglas Gregor !D->isConstexpr() &&
1082bb13c9a4SRichard Smith !D->isInitCapture() &&
10831c34fb78SRichard Smith !D->isPreviousDeclInSameBlockScope() &&
10849978da36SAkira Hatanaka !(D->hasAttr<BlocksAttr>() && D->getType()->getAsCXXRecordDecl()) &&
10858e57b07fSAkira Hatanaka !D->isEscapingByref() &&
1086a465362dSRichard Smith D->getStorageDuration() != SD_Static &&
1087d8dd97c0SLarisse Voufo !D->getMemberSpecializationInfo())
1088205c7d55SJonathan D. Turner AbbrevToUse = Writer.getDeclVarAbbrev();
1089205c7d55SJonathan D. Turner
1090539c5061SSebastian Redl Code = serialization::DECL_VAR;
1091d6522cfcSSebastian Redl }
1092d6522cfcSSebastian Redl
VisitImplicitParamDecl(ImplicitParamDecl * D)1093d6522cfcSSebastian Redl void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) {
1094d6522cfcSSebastian Redl VisitVarDecl(D);
1095539c5061SSebastian Redl Code = serialization::DECL_IMPLICIT_PARAM;
1096d6522cfcSSebastian Redl }
1097d6522cfcSSebastian Redl
VisitParmVarDecl(ParmVarDecl * D)1098d6522cfcSSebastian Redl void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
1099d6522cfcSSebastian Redl VisitVarDecl(D);
110082490837SJohn McCall Record.push_back(D->isObjCMethodParameter());
11018fb0d9d2SJohn McCall Record.push_back(D->getFunctionScopeDepth());
11028fb0d9d2SJohn McCall Record.push_back(D->getFunctionScopeIndex());
1103d6522cfcSSebastian Redl Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding
11046a014d5cSJohn McCall Record.push_back(D->isKNRPromoted());
1105d6522cfcSSebastian Redl Record.push_back(D->hasInheritedDefaultArg());
1106d6522cfcSSebastian Redl Record.push_back(D->hasUninstantiatedDefaultArg());
1107d6522cfcSSebastian Redl if (D->hasUninstantiatedDefaultArg())
1108290d8019SRichard Smith Record.AddStmt(D->getUninstantiatedDefaultArg());
1109539c5061SSebastian Redl Code = serialization::DECL_PARM_VAR;
1110d6522cfcSSebastian Redl
1111d6522cfcSSebastian Redl // If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here
1112d6522cfcSSebastian Redl // we dynamically check for the properties that we optimize for, but don't
1113d6522cfcSSebastian Redl // know are true of all PARM_VAR_DECLs.
11142fd11e0bSThorsten Schütt if (D->getDeclContext() == D->getLexicalDeclContext() &&
11152fd11e0bSThorsten Schütt !D->hasAttrs() &&
11162fd11e0bSThorsten Schütt !D->hasExtInfo() &&
11172fd11e0bSThorsten Schütt !D->isImplicit() &&
11182fd11e0bSThorsten Schütt !D->isUsed(false) &&
11192fd11e0bSThorsten Schütt !D->isInvalidDecl() &&
11202fd11e0bSThorsten Schütt !D->isReferenced() &&
11212fd11e0bSThorsten Schütt D->getAccess() == AS_none &&
11222fd11e0bSThorsten Schütt !D->isModulePrivate() &&
11232fd11e0bSThorsten Schütt D->getStorageClass() == 0 &&
1124a935179aSSebastian Redl D->getInitStyle() == VarDecl::CInit && // Can params have anything else?
11252fd11e0bSThorsten Schütt D->getFunctionScopeDepth() == 0 &&
11262fd11e0bSThorsten Schütt D->getObjCDeclQualifier() == 0 &&
11272fd11e0bSThorsten Schütt !D->isKNRPromoted() &&
11282fd11e0bSThorsten Schütt !D->hasInheritedDefaultArg() &&
1129a13603a2SCraig Topper D->getInit() == nullptr &&
1130d6522cfcSSebastian Redl !D->hasUninstantiatedDefaultArg()) // No default expr.
1131205c7d55SJonathan D. Turner AbbrevToUse = Writer.getDeclParmVarAbbrev();
1132d6522cfcSSebastian Redl
1133d6522cfcSSebastian Redl // Check things we know are true of *every* PARM_VAR_DECL, which is more than
1134d6522cfcSSebastian Redl // just us assuming it.
1135acb8ecd6SEnea Zaffanella assert(!D->getTSCSpec() && "PARM_VAR_DECL can't use TLS");
1136edbc6e93SRichard Smith assert(!D->isThisDeclarationADemotedDefinition()
1137edbc6e93SRichard Smith && "PARM_VAR_DECL can't be demoted definition.");
1138d6522cfcSSebastian Redl assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private");
1139d6522cfcSSebastian Redl assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var");
1140a13603a2SCraig Topper assert(D->getPreviousDecl() == nullptr && "PARM_VAR_DECL can't be redecl");
1141d6522cfcSSebastian Redl assert(!D->isStaticDataMember() &&
1142d6522cfcSSebastian Redl "PARM_VAR_DECL can't be static data member");
1143d6522cfcSSebastian Redl }
1144d6522cfcSSebastian Redl
VisitDecompositionDecl(DecompositionDecl * D)11457b76d81bSRichard Smith void ASTDeclWriter::VisitDecompositionDecl(DecompositionDecl *D) {
11467b76d81bSRichard Smith // Record the number of bindings first to simplify deserialization.
11477b76d81bSRichard Smith Record.push_back(D->bindings().size());
11487b76d81bSRichard Smith
11497b76d81bSRichard Smith VisitVarDecl(D);
11507b76d81bSRichard Smith for (auto *B : D->bindings())
11517b76d81bSRichard Smith Record.AddDeclRef(B);
11527b76d81bSRichard Smith Code = serialization::DECL_DECOMPOSITION;
11537b76d81bSRichard Smith }
11547b76d81bSRichard Smith
VisitBindingDecl(BindingDecl * D)11557b76d81bSRichard Smith void ASTDeclWriter::VisitBindingDecl(BindingDecl *D) {
11567b76d81bSRichard Smith VisitValueDecl(D);
11577b76d81bSRichard Smith Record.AddStmt(D->getBinding());
11587b76d81bSRichard Smith Code = serialization::DECL_BINDING;
11597b76d81bSRichard Smith }
11607b76d81bSRichard Smith
VisitFileScopeAsmDecl(FileScopeAsmDecl * D)1161d6522cfcSSebastian Redl void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
1162d6522cfcSSebastian Redl VisitDecl(D);
1163290d8019SRichard Smith Record.AddStmt(D->getAsmString());
116469c82bfaSRichard Smith Record.AddSourceLocation(D->getRParenLoc());
1165539c5061SSebastian Redl Code = serialization::DECL_FILE_SCOPE_ASM;
1166d6522cfcSSebastian Redl }
1167d6522cfcSSebastian Redl
VisitEmptyDecl(EmptyDecl * D)116884324357SMichael Han void ASTDeclWriter::VisitEmptyDecl(EmptyDecl *D) {
116984324357SMichael Han VisitDecl(D);
117084324357SMichael Han Code = serialization::DECL_EMPTY;
117184324357SMichael Han }
117284324357SMichael Han
VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl * D)1173b0561b33STyker void ASTDeclWriter::VisitLifetimeExtendedTemporaryDecl(
1174b0561b33STyker LifetimeExtendedTemporaryDecl *D) {
1175b0561b33STyker VisitDecl(D);
1176b0561b33STyker Record.AddDeclRef(D->getExtendingDecl());
1177b0561b33STyker Record.AddStmt(D->getTemporaryExpr());
1178b0561b33STyker Record.push_back(static_cast<bool>(D->getValue()));
1179b0561b33STyker if (D->getValue())
1180b0561b33STyker Record.AddAPValue(*D->getValue());
1181b0561b33STyker Record.push_back(D->getManglingNumber());
1182b0561b33STyker Code = serialization::DECL_LIFETIME_EXTENDED_TEMPORARY;
1183b0561b33STyker }
VisitBlockDecl(BlockDecl * D)1184d6522cfcSSebastian Redl void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) {
1185d6522cfcSSebastian Redl VisitDecl(D);
1186290d8019SRichard Smith Record.AddStmt(D->getBody());
118769c82bfaSRichard Smith Record.AddTypeSourceInfo(D->getSignatureAsWritten());
1188d6522cfcSSebastian Redl Record.push_back(D->param_size());
1189a3debed2SDavid Majnemer for (ParmVarDecl *P : D->parameters())
1190a3debed2SDavid Majnemer Record.AddDeclRef(P);
1191cf6ce28fSJohn McCall Record.push_back(D->isVariadic());
1192cf6ce28fSJohn McCall Record.push_back(D->blockMissingReturnType());
1193cf6ce28fSJohn McCall Record.push_back(D->isConversionFromLambda());
1194db49a1f7SAkira Hatanaka Record.push_back(D->doesNotEscape());
1195c5792aa9SAkira Hatanaka Record.push_back(D->canAvoidCopyToHeap());
1196c63de66cSJohn McCall Record.push_back(D->capturesCXXThis());
1197351762cdSJohn McCall Record.push_back(D->getNumCaptures());
11989371dd22SAaron Ballman for (const auto &capture : D->captures()) {
119969c82bfaSRichard Smith Record.AddDeclRef(capture.getVariable());
1200351762cdSJohn McCall
1201351762cdSJohn McCall unsigned flags = 0;
1202351762cdSJohn McCall if (capture.isByRef()) flags |= 1;
1203351762cdSJohn McCall if (capture.isNested()) flags |= 2;
1204351762cdSJohn McCall if (capture.hasCopyExpr()) flags |= 4;
1205351762cdSJohn McCall Record.push_back(flags);
1206351762cdSJohn McCall
1207290d8019SRichard Smith if (capture.hasCopyExpr()) Record.AddStmt(capture.getCopyExpr());
1208351762cdSJohn McCall }
1209c63de66cSJohn McCall
1210539c5061SSebastian Redl Code = serialization::DECL_BLOCK;
1211d6522cfcSSebastian Redl }
1212d6522cfcSSebastian Redl
VisitCapturedDecl(CapturedDecl * CD)1213ce914fc8SBen Langmuir void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) {
1214ce914fc8SBen Langmuir Record.push_back(CD->getNumParams());
1215ce914fc8SBen Langmuir VisitDecl(CD);
12169959db5fSAlexey Bataev Record.push_back(CD->getContextParamPosition());
12179959db5fSAlexey Bataev Record.push_back(CD->isNothrow() ? 1 : 0);
1218ce914fc8SBen Langmuir // Body is stored by VisitCapturedStmt.
12199959db5fSAlexey Bataev for (unsigned I = 0; I < CD->getNumParams(); ++I)
122069c82bfaSRichard Smith Record.AddDeclRef(CD->getParam(I));
1221ce914fc8SBen Langmuir Code = serialization::DECL_CAPTURED;
12226dfa25a1STareq A. Siraj }
12236dfa25a1STareq A. Siraj
VisitLinkageSpecDecl(LinkageSpecDecl * D)1224d6522cfcSSebastian Redl void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
1225d6522cfcSSebastian Redl VisitDecl(D);
1226d6522cfcSSebastian Redl Record.push_back(D->getLanguage());
122769c82bfaSRichard Smith Record.AddSourceLocation(D->getExternLoc());
122869c82bfaSRichard Smith Record.AddSourceLocation(D->getRBraceLoc());
1229539c5061SSebastian Redl Code = serialization::DECL_LINKAGE_SPEC;
1230d6522cfcSSebastian Redl }
1231d6522cfcSSebastian Redl
VisitExportDecl(ExportDecl * D)12328df390f9SRichard Smith void ASTDeclWriter::VisitExportDecl(ExportDecl *D) {
12338df390f9SRichard Smith VisitDecl(D);
12348df390f9SRichard Smith Record.AddSourceLocation(D->getRBraceLoc());
12358df390f9SRichard Smith Code = serialization::DECL_EXPORT;
12368df390f9SRichard Smith }
12378df390f9SRichard Smith
VisitLabelDecl(LabelDecl * D)1238c8e630e4SChris Lattner void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) {
1239c8e630e4SChris Lattner VisitNamedDecl(D);
1240f2ceec48SStephen Kelly Record.AddSourceLocation(D->getBeginLoc());
1241c8e630e4SChris Lattner Code = serialization::DECL_LABEL;
1242c8e630e4SChris Lattner }
1243c8e630e4SChris Lattner
1244c8e630e4SChris Lattner
VisitNamespaceDecl(NamespaceDecl * D)1245d6522cfcSSebastian Redl void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
1246e57e752bSDouglas Gregor VisitRedeclarable(D);
1247d6522cfcSSebastian Redl VisitNamedDecl(D);
124844e5c1f1SDouglas Gregor Record.push_back(D->isInline());
1249f2ceec48SStephen Kelly Record.AddSourceLocation(D->getBeginLoc());
125069c82bfaSRichard Smith Record.AddSourceLocation(D->getRBraceLoc());
1251d6522cfcSSebastian Redl
1252d6522cfcSSebastian Redl if (D->isOriginalNamespace())
125369c82bfaSRichard Smith Record.AddDeclRef(D->getAnonymousNamespace());
1254539c5061SSebastian Redl Code = serialization::DECL_NAMESPACE;
1255d6522cfcSSebastian Redl
1256e57e752bSDouglas Gregor if (Writer.hasChain() && D->isAnonymousNamespace() &&
1257ec9fd13cSDouglas Gregor D == D->getMostRecentDecl()) {
1258010288f7SSebastian Redl // This is a most recent reopening of the anonymous namespace. If its parent
1259010288f7SSebastian Redl // is in a previous PCH (or is the TU), mark that parent for update, because
1260010288f7SSebastian Redl // the original namespace always points to the latest re-opening of its
1261010288f7SSebastian Redl // anonymous namespace.
1262010288f7SSebastian Redl Decl *Parent = cast<Decl>(
1263010288f7SSebastian Redl D->getParent()->getRedeclContext()->getPrimaryContext());
1264b3722e22SDouglas Gregor if (Parent->isFromASTFile() || isa<TranslationUnitDecl>(Parent)) {
12656ef42936SRichard Smith Writer.DeclUpdates[Parent].push_back(
12664f45b71bSAaron Ballman ASTWriter::DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, D));
1267fa1f370bSSebastian Redl }
1268fa1f370bSSebastian Redl }
1269d6522cfcSSebastian Redl }
1270d6522cfcSSebastian Redl
VisitNamespaceAliasDecl(NamespaceAliasDecl * D)1271d6522cfcSSebastian Redl void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
1272f463436dSRichard Smith VisitRedeclarable(D);
1273d6522cfcSSebastian Redl VisitNamedDecl(D);
127469c82bfaSRichard Smith Record.AddSourceLocation(D->getNamespaceLoc());
127569c82bfaSRichard Smith Record.AddSourceLocation(D->getTargetNameLoc());
127669c82bfaSRichard Smith Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
127769c82bfaSRichard Smith Record.AddDeclRef(D->getNamespace());
1278539c5061SSebastian Redl Code = serialization::DECL_NAMESPACE_ALIAS;
1279d6522cfcSSebastian Redl }
1280d6522cfcSSebastian Redl
VisitUsingDecl(UsingDecl * D)1281d6522cfcSSebastian Redl void ASTDeclWriter::VisitUsingDecl(UsingDecl *D) {
1282d6522cfcSSebastian Redl VisitNamedDecl(D);
128369c82bfaSRichard Smith Record.AddSourceLocation(D->getUsingLoc());
128469c82bfaSRichard Smith Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
128569c82bfaSRichard Smith Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
128669c82bfaSRichard Smith Record.AddDeclRef(D->FirstUsingShadow.getPointer());
1287e05a3cf6SEnea Zaffanella Record.push_back(D->hasTypename());
128869c82bfaSRichard Smith Record.AddDeclRef(Context.getInstantiatedFromUsingDecl(D));
1289539c5061SSebastian Redl Code = serialization::DECL_USING;
1290d6522cfcSSebastian Redl }
1291d6522cfcSSebastian Redl
VisitUsingEnumDecl(UsingEnumDecl * D)1292b2d0c16eSNathan Sidwell void ASTDeclWriter::VisitUsingEnumDecl(UsingEnumDecl *D) {
1293b2d0c16eSNathan Sidwell VisitNamedDecl(D);
1294b2d0c16eSNathan Sidwell Record.AddSourceLocation(D->getUsingLoc());
1295b2d0c16eSNathan Sidwell Record.AddSourceLocation(D->getEnumLoc());
1296b2d0c16eSNathan Sidwell Record.AddDeclRef(D->getEnumDecl());
1297b2d0c16eSNathan Sidwell Record.AddDeclRef(D->FirstUsingShadow.getPointer());
1298b2d0c16eSNathan Sidwell Record.AddDeclRef(Context.getInstantiatedFromUsingEnumDecl(D));
1299b2d0c16eSNathan Sidwell Code = serialization::DECL_USING_ENUM;
1300b2d0c16eSNathan Sidwell }
1301b2d0c16eSNathan Sidwell
VisitUsingPackDecl(UsingPackDecl * D)1302151c4568SRichard Smith void ASTDeclWriter::VisitUsingPackDecl(UsingPackDecl *D) {
1303151c4568SRichard Smith Record.push_back(D->NumExpansions);
1304151c4568SRichard Smith VisitNamedDecl(D);
1305151c4568SRichard Smith Record.AddDeclRef(D->getInstantiatedFromUsingDecl());
1306151c4568SRichard Smith for (auto *E : D->expansions())
1307151c4568SRichard Smith Record.AddDeclRef(E);
1308151c4568SRichard Smith Code = serialization::DECL_USING_PACK;
1309151c4568SRichard Smith }
1310151c4568SRichard Smith
VisitUsingShadowDecl(UsingShadowDecl * D)1311d6522cfcSSebastian Redl void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) {
1312fd8634a0SRichard Smith VisitRedeclarable(D);
1313d6522cfcSSebastian Redl VisitNamedDecl(D);
131469c82bfaSRichard Smith Record.AddDeclRef(D->getTargetDecl());
1315a263c346SRichard Smith Record.push_back(D->getIdentifierNamespace());
131669c82bfaSRichard Smith Record.AddDeclRef(D->UsingOrNextShadow);
131769c82bfaSRichard Smith Record.AddDeclRef(Context.getInstantiatedFromUsingShadowDecl(D));
1318539c5061SSebastian Redl Code = serialization::DECL_USING_SHADOW;
1319d6522cfcSSebastian Redl }
1320d6522cfcSSebastian Redl
VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl * D)13215179eb78SRichard Smith void ASTDeclWriter::VisitConstructorUsingShadowDecl(
13225179eb78SRichard Smith ConstructorUsingShadowDecl *D) {
13235179eb78SRichard Smith VisitUsingShadowDecl(D);
13245179eb78SRichard Smith Record.AddDeclRef(D->NominatedBaseClassShadowDecl);
13255179eb78SRichard Smith Record.AddDeclRef(D->ConstructedBaseClassShadowDecl);
13265179eb78SRichard Smith Record.push_back(D->IsVirtual);
13275179eb78SRichard Smith Code = serialization::DECL_CONSTRUCTOR_USING_SHADOW;
13285179eb78SRichard Smith }
13295179eb78SRichard Smith
VisitUsingDirectiveDecl(UsingDirectiveDecl * D)1330d6522cfcSSebastian Redl void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
1331d6522cfcSSebastian Redl VisitNamedDecl(D);
133269c82bfaSRichard Smith Record.AddSourceLocation(D->getUsingLoc());
133369c82bfaSRichard Smith Record.AddSourceLocation(D->getNamespaceKeyLocation());
133469c82bfaSRichard Smith Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
133569c82bfaSRichard Smith Record.AddDeclRef(D->getNominatedNamespace());
133669c82bfaSRichard Smith Record.AddDeclRef(dyn_cast<Decl>(D->getCommonAncestor()));
1337539c5061SSebastian Redl Code = serialization::DECL_USING_DIRECTIVE;
1338d6522cfcSSebastian Redl }
1339d6522cfcSSebastian Redl
VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl * D)1340d6522cfcSSebastian Redl void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
1341d6522cfcSSebastian Redl VisitValueDecl(D);
134269c82bfaSRichard Smith Record.AddSourceLocation(D->getUsingLoc());
134369c82bfaSRichard Smith Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
134469c82bfaSRichard Smith Record.AddDeclarationNameLoc(D->DNLoc, D->getDeclName());
1345151c4568SRichard Smith Record.AddSourceLocation(D->getEllipsisLoc());
1346539c5061SSebastian Redl Code = serialization::DECL_UNRESOLVED_USING_VALUE;
1347d6522cfcSSebastian Redl }
1348d6522cfcSSebastian Redl
VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl * D)1349d6522cfcSSebastian Redl void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl(
1350d6522cfcSSebastian Redl UnresolvedUsingTypenameDecl *D) {
1351d6522cfcSSebastian Redl VisitTypeDecl(D);
135269c82bfaSRichard Smith Record.AddSourceLocation(D->getTypenameLoc());
135369c82bfaSRichard Smith Record.AddNestedNameSpecifierLoc(D->getQualifierLoc());
1354151c4568SRichard Smith Record.AddSourceLocation(D->getEllipsisLoc());
1355539c5061SSebastian Redl Code = serialization::DECL_UNRESOLVED_USING_TYPENAME;
1356d6522cfcSSebastian Redl }
1357d6522cfcSSebastian Redl
VisitUnresolvedUsingIfExistsDecl(UnresolvedUsingIfExistsDecl * D)1358369c6483SErik Pilkington void ASTDeclWriter::VisitUnresolvedUsingIfExistsDecl(
1359369c6483SErik Pilkington UnresolvedUsingIfExistsDecl *D) {
1360369c6483SErik Pilkington VisitNamedDecl(D);
1361369c6483SErik Pilkington Code = serialization::DECL_UNRESOLVED_USING_IF_EXISTS;
1362369c6483SErik Pilkington }
1363369c6483SErik Pilkington
VisitCXXRecordDecl(CXXRecordDecl * D)1364d6522cfcSSebastian Redl void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) {
1365d6522cfcSSebastian Redl VisitRecordDecl(D);
1366d6522cfcSSebastian Redl
1367d6522cfcSSebastian Redl enum {
1368d6522cfcSSebastian Redl CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1369d6522cfcSSebastian Redl };
1370d6522cfcSSebastian Redl if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) {
1371d6522cfcSSebastian Redl Record.push_back(CXXRecTemplate);
137269c82bfaSRichard Smith Record.AddDeclRef(TemplD);
1373d6522cfcSSebastian Redl } else if (MemberSpecializationInfo *MSInfo
1374d6522cfcSSebastian Redl = D->getMemberSpecializationInfo()) {
1375d6522cfcSSebastian Redl Record.push_back(CXXRecMemberSpecialization);
137669c82bfaSRichard Smith Record.AddDeclRef(MSInfo->getInstantiatedFrom());
1377d6522cfcSSebastian Redl Record.push_back(MSInfo->getTemplateSpecializationKind());
137869c82bfaSRichard Smith Record.AddSourceLocation(MSInfo->getPointOfInstantiation());
1379d6522cfcSSebastian Redl } else {
1380d6522cfcSSebastian Redl Record.push_back(CXXRecNotTemplate);
1381d6522cfcSSebastian Redl }
1382d6522cfcSSebastian Redl
1383cd45dbc5SRichard Smith Record.push_back(D->isThisDeclarationADefinition());
1384cd45dbc5SRichard Smith if (D->isThisDeclarationADefinition())
138569c82bfaSRichard Smith Record.AddCXXDefinitionData(D);
1386cd45dbc5SRichard Smith
13876bd2a89dSJohn McCall // Store (what we currently believe to be) the key function to avoid
13886bd2a89dSJohn McCall // deserializing every method so we can compute it.
1389f92f31c6SErich Keane if (D->isCompleteDefinition())
139069c82bfaSRichard Smith Record.AddDeclRef(Context.getCurrentKeyFunction(D));
13916843141dSArgyrios Kyrtzidis
1392539c5061SSebastian Redl Code = serialization::DECL_CXX_RECORD;
1393d6522cfcSSebastian Redl }
1394d6522cfcSSebastian Redl
VisitCXXMethodDecl(CXXMethodDecl * D)1395d6522cfcSSebastian Redl void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
1396d6522cfcSSebastian Redl VisitFunctionDecl(D);
13973b1a7796SArgyrios Kyrtzidis if (D->isCanonicalDecl()) {
1398d6522cfcSSebastian Redl Record.push_back(D->size_overridden_methods());
1399acfa339eSBenjamin Kramer for (const CXXMethodDecl *MD : D->overridden_methods())
1400acfa339eSBenjamin Kramer Record.AddDeclRef(MD);
14013b1a7796SArgyrios Kyrtzidis } else {
14023b1a7796SArgyrios Kyrtzidis // We only need to record overridden methods once for the canonical decl.
14033b1a7796SArgyrios Kyrtzidis Record.push_back(0);
14043b1a7796SArgyrios Kyrtzidis }
140501b2cb47SRichard Smith
14068aed4222SRichard Smith if (D->getDeclContext() == D->getLexicalDeclContext() &&
14078aed4222SRichard Smith D->getFirstDecl() == D->getMostRecentDecl() &&
140801b2cb47SRichard Smith !D->isInvalidDecl() &&
140901b2cb47SRichard Smith !D->hasAttrs() &&
141001b2cb47SRichard Smith !D->isTopLevelDeclInObjCContainer() &&
141101b2cb47SRichard Smith D->getDeclName().getNameKind() == DeclarationName::Identifier &&
141201b2cb47SRichard Smith !D->hasExtInfo() &&
141301b2cb47SRichard Smith !D->hasInheritedPrototype() &&
141401b2cb47SRichard Smith D->hasWrittenPrototype())
141501b2cb47SRichard Smith AbbrevToUse = Writer.getDeclCXXMethodAbbrev();
141601b2cb47SRichard Smith
1417539c5061SSebastian Redl Code = serialization::DECL_CXX_METHOD;
1418d6522cfcSSebastian Redl }
1419d6522cfcSSebastian Redl
VisitCXXConstructorDecl(CXXConstructorDecl * D)1420d6522cfcSSebastian Redl void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
1421ab7316f1SNathan Sidwell Record.push_back(D->getTrailingAllocKind());
142276b9027fSRichard Smith addExplicitSpecifier(D->getExplicitSpecifier(), Record);
14235179eb78SRichard Smith if (auto Inherited = D->getInheritedConstructor()) {
14245179eb78SRichard Smith Record.AddDeclRef(Inherited.getShadowDecl());
14255179eb78SRichard Smith Record.AddDeclRef(Inherited.getConstructor());
14265179eb78SRichard Smith }
14275179eb78SRichard Smith
1428d6522cfcSSebastian Redl VisitCXXMethodDecl(D);
142976b9027fSRichard Smith Code = serialization::DECL_CXX_CONSTRUCTOR;
1430d6522cfcSSebastian Redl }
1431d6522cfcSSebastian Redl
VisitCXXDestructorDecl(CXXDestructorDecl * D)1432d6522cfcSSebastian Redl void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
1433d6522cfcSSebastian Redl VisitCXXMethodDecl(D);
1434d6522cfcSSebastian Redl
143569c82bfaSRichard Smith Record.AddDeclRef(D->getOperatorDelete());
14365b34958bSRichard Smith if (D->getOperatorDelete())
14375b34958bSRichard Smith Record.AddStmt(D->getOperatorDeleteThisArg());
1438d6522cfcSSebastian Redl
1439539c5061SSebastian Redl Code = serialization::DECL_CXX_DESTRUCTOR;
1440d6522cfcSSebastian Redl }
1441d6522cfcSSebastian Redl
VisitCXXConversionDecl(CXXConversionDecl * D)1442d6522cfcSSebastian Redl void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) {
144376b9027fSRichard Smith addExplicitSpecifier(D->getExplicitSpecifier(), Record);
1444d6522cfcSSebastian Redl VisitCXXMethodDecl(D);
1445539c5061SSebastian Redl Code = serialization::DECL_CXX_CONVERSION;
1446d6522cfcSSebastian Redl }
1447d6522cfcSSebastian Redl
VisitImportDecl(ImportDecl * D)1448ba34552eSDouglas Gregor void ASTDeclWriter::VisitImportDecl(ImportDecl *D) {
1449ba34552eSDouglas Gregor VisitDecl(D);
14507b8e5558SArgyrios Kyrtzidis Record.push_back(Writer.getSubmoduleID(D->getImportedModule()));
1451ba34552eSDouglas Gregor ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs();
1452ba34552eSDouglas Gregor Record.push_back(!IdentifierLocs.empty());
1453ba34552eSDouglas Gregor if (IdentifierLocs.empty()) {
14541c301dcbSStephen Kelly Record.AddSourceLocation(D->getEndLoc());
1455ba34552eSDouglas Gregor Record.push_back(1);
1456ba34552eSDouglas Gregor } else {
1457ba34552eSDouglas Gregor for (unsigned I = 0, N = IdentifierLocs.size(); I != N; ++I)
145869c82bfaSRichard Smith Record.AddSourceLocation(IdentifierLocs[I]);
1459ba34552eSDouglas Gregor Record.push_back(IdentifierLocs.size());
1460ba34552eSDouglas Gregor }
1461ba34552eSDouglas Gregor // Note: the number of source locations must always be the last element in
1462ba34552eSDouglas Gregor // the record.
1463ba34552eSDouglas Gregor Code = serialization::DECL_IMPORT;
1464ba34552eSDouglas Gregor }
1465ba34552eSDouglas Gregor
VisitAccessSpecDecl(AccessSpecDecl * D)1466d6522cfcSSebastian Redl void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) {
1467d6522cfcSSebastian Redl VisitDecl(D);
146869c82bfaSRichard Smith Record.AddSourceLocation(D->getColonLoc());
1469539c5061SSebastian Redl Code = serialization::DECL_ACCESS_SPEC;
1470d6522cfcSSebastian Redl }
1471d6522cfcSSebastian Redl
VisitFriendDecl(FriendDecl * D)1472d6522cfcSSebastian Redl void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) {
1473eb22c870SEnea Zaffanella // Record the number of friend type template parameter lists here
1474eb22c870SEnea Zaffanella // so as to simplify memory allocation during deserialization.
1475eb22c870SEnea Zaffanella Record.push_back(D->NumTPLists);
1476d6522cfcSSebastian Redl VisitDecl(D);
1477eb22c870SEnea Zaffanella bool hasFriendDecl = D->Friend.is<NamedDecl*>();
1478eb22c870SEnea Zaffanella Record.push_back(hasFriendDecl);
1479eb22c870SEnea Zaffanella if (hasFriendDecl)
148069c82bfaSRichard Smith Record.AddDeclRef(D->getFriendDecl());
1481d6522cfcSSebastian Redl else
148269c82bfaSRichard Smith Record.AddTypeSourceInfo(D->getFriendType());
1483eb22c870SEnea Zaffanella for (unsigned i = 0; i < D->NumTPLists; ++i)
148469c82bfaSRichard Smith Record.AddTemplateParameterList(D->getFriendTypeTemplateParameterList(i));
148569c82bfaSRichard Smith Record.AddDeclRef(D->getNextFriend());
14862c2eb12dSJohn McCall Record.push_back(D->UnsupportedFriend);
148769c82bfaSRichard Smith Record.AddSourceLocation(D->FriendLoc);
1488539c5061SSebastian Redl Code = serialization::DECL_FRIEND;
1489d6522cfcSSebastian Redl }
1490d6522cfcSSebastian Redl
VisitFriendTemplateDecl(FriendTemplateDecl * D)1491d6522cfcSSebastian Redl void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
1492d6522cfcSSebastian Redl VisitDecl(D);
1493d6522cfcSSebastian Redl Record.push_back(D->getNumTemplateParameters());
1494d6522cfcSSebastian Redl for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i)
149569c82bfaSRichard Smith Record.AddTemplateParameterList(D->getTemplateParameterList(i));
1496a13603a2SCraig Topper Record.push_back(D->getFriendDecl() != nullptr);
1497d6522cfcSSebastian Redl if (D->getFriendDecl())
149869c82bfaSRichard Smith Record.AddDeclRef(D->getFriendDecl());
1499d6522cfcSSebastian Redl else
150069c82bfaSRichard Smith Record.AddTypeSourceInfo(D->getFriendType());
150169c82bfaSRichard Smith Record.AddSourceLocation(D->getFriendLoc());
1502539c5061SSebastian Redl Code = serialization::DECL_FRIEND_TEMPLATE;
1503d6522cfcSSebastian Redl }
1504d6522cfcSSebastian Redl
VisitTemplateDecl(TemplateDecl * D)1505d6522cfcSSebastian Redl void ASTDeclWriter::VisitTemplateDecl(TemplateDecl *D) {
1506d6522cfcSSebastian Redl VisitNamedDecl(D);
1507d6522cfcSSebastian Redl
150869c82bfaSRichard Smith Record.AddDeclRef(D->getTemplatedDecl());
150969c82bfaSRichard Smith Record.AddTemplateParameterList(D->getTemplateParameters());
1510d6522cfcSSebastian Redl }
1511d6522cfcSSebastian Redl
VisitConceptDecl(ConceptDecl * D)1512d7aae33aSSaar Raz void ASTDeclWriter::VisitConceptDecl(ConceptDecl *D) {
1513d7aae33aSSaar Raz VisitTemplateDecl(D);
1514d7aae33aSSaar Raz Record.AddStmt(D->getConstraintExpr());
1515d7aae33aSSaar Raz Code = serialization::DECL_CONCEPT;
1516d7aae33aSSaar Raz }
1517d7aae33aSSaar Raz
VisitRequiresExprBodyDecl(RequiresExprBodyDecl * D)1518a0f50d73SSaar Raz void ASTDeclWriter::VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D) {
1519a0f50d73SSaar Raz Code = serialization::DECL_REQUIRES_EXPR_BODY;
1520a0f50d73SSaar Raz }
1521a0f50d73SSaar Raz
VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl * D)1522d6522cfcSSebastian Redl void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
152368444de3SDouglas Gregor VisitRedeclarable(D);
152468444de3SDouglas Gregor
1525f4bc0d87SArgyrios Kyrtzidis // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that
1526f4bc0d87SArgyrios Kyrtzidis // getCommonPtr() can be used while this is still initializing.
15278db352d5SRafael Espindola if (D->isFirstDecl()) {
1528074a4096SDouglas Gregor // This declaration owns the 'common' pointer, so serialize that data now.
152969c82bfaSRichard Smith Record.AddDeclRef(D->getInstantiatedFromMemberTemplate());
1530d6522cfcSSebastian Redl if (D->getInstantiatedFromMemberTemplate())
1531d6522cfcSSebastian Redl Record.push_back(D->isMemberSpecialization());
1532d6522cfcSSebastian Redl }
1533f4bc0d87SArgyrios Kyrtzidis
1534f4bc0d87SArgyrios Kyrtzidis VisitTemplateDecl(D);
1535f4bc0d87SArgyrios Kyrtzidis Record.push_back(D->getIdentifierNamespace());
1536d6522cfcSSebastian Redl }
1537d6522cfcSSebastian Redl
VisitClassTemplateDecl(ClassTemplateDecl * D)1538d6522cfcSSebastian Redl void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
1539d6522cfcSSebastian Redl VisitRedeclarableTemplateDecl(D);
1540d6522cfcSSebastian Redl
1541509fc85bSRichard Smith if (D->isFirstDecl())
1542509fc85bSRichard Smith AddTemplateSpecializations(D);
1543539c5061SSebastian Redl Code = serialization::DECL_CLASS_TEMPLATE;
1544d6522cfcSSebastian Redl }
1545d6522cfcSSebastian Redl
VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl * D)1546d6522cfcSSebastian Redl void ASTDeclWriter::VisitClassTemplateSpecializationDecl(
1547d6522cfcSSebastian Redl ClassTemplateSpecializationDecl *D) {
1548d8a83718SRichard Smith RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1549d8a83718SRichard Smith
1550d6522cfcSSebastian Redl VisitCXXRecordDecl(D);
1551d6522cfcSSebastian Redl
1552d6522cfcSSebastian Redl llvm::PointerUnion<ClassTemplateDecl *,
1553d6522cfcSSebastian Redl ClassTemplatePartialSpecializationDecl *> InstFrom
1554d6522cfcSSebastian Redl = D->getSpecializedTemplateOrPartial();
1555d5553f1cSArgyrios Kyrtzidis if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) {
155669c82bfaSRichard Smith Record.AddDeclRef(InstFromD);
1557d6522cfcSSebastian Redl } else {
155869c82bfaSRichard Smith Record.AddDeclRef(InstFrom.get<ClassTemplatePartialSpecializationDecl *>());
155969c82bfaSRichard Smith Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
1560d6522cfcSSebastian Redl }
1561d6522cfcSSebastian Redl
156269c82bfaSRichard Smith Record.AddTemplateArgumentList(&D->getTemplateArgs());
156369c82bfaSRichard Smith Record.AddSourceLocation(D->getPointOfInstantiation());
1564d6522cfcSSebastian Redl Record.push_back(D->getSpecializationKind());
1565a31dee2eSAxel Naumann Record.push_back(D->isCanonicalDecl());
1566d6522cfcSSebastian Redl
1567d6522cfcSSebastian Redl if (D->isCanonicalDecl()) {
1568d6522cfcSSebastian Redl // When reading, we'll add it to the folding set of the following template.
156969c82bfaSRichard Smith Record.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl());
1570d6522cfcSSebastian Redl }
1571d6522cfcSSebastian Redl
1572d55889a6SRichard Smith // Explicit info.
157369c82bfaSRichard Smith Record.AddTypeSourceInfo(D->getTypeAsWritten());
1574d55889a6SRichard Smith if (D->getTypeAsWritten()) {
157569c82bfaSRichard Smith Record.AddSourceLocation(D->getExternLoc());
157669c82bfaSRichard Smith Record.AddSourceLocation(D->getTemplateKeywordLoc());
1577d55889a6SRichard Smith }
1578d55889a6SRichard Smith
1579539c5061SSebastian Redl Code = serialization::DECL_CLASS_TEMPLATE_SPECIALIZATION;
1580d6522cfcSSebastian Redl }
1581d6522cfcSSebastian Redl
VisitClassTemplatePartialSpecializationDecl(ClassTemplatePartialSpecializationDecl * D)1582d6522cfcSSebastian Redl void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl(
1583d6522cfcSSebastian Redl ClassTemplatePartialSpecializationDecl *D) {
158469c82bfaSRichard Smith Record.AddTemplateParameterList(D->getTemplateParameters());
158569c82bfaSRichard Smith Record.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten());
1586d6522cfcSSebastian Redl
1587df061c3eSSaar Raz VisitClassTemplateSpecializationDecl(D);
1588df061c3eSSaar Raz
1589d6522cfcSSebastian Redl // These are read/set from/to the first declaration.
1590a13603a2SCraig Topper if (D->getPreviousDecl() == nullptr) {
159169c82bfaSRichard Smith Record.AddDeclRef(D->getInstantiatedFromMember());
1592d6522cfcSSebastian Redl Record.push_back(D->isMemberSpecialization());
1593d6522cfcSSebastian Redl }
1594d6522cfcSSebastian Redl
1595539c5061SSebastian Redl Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION;
1596d6522cfcSSebastian Redl }
1597d6522cfcSSebastian Redl
VisitVarTemplateDecl(VarTemplateDecl * D)159839a1e507SLarisse Voufo void ASTDeclWriter::VisitVarTemplateDecl(VarTemplateDecl *D) {
159939a1e507SLarisse Voufo VisitRedeclarableTemplateDecl(D);
160039a1e507SLarisse Voufo
1601509fc85bSRichard Smith if (D->isFirstDecl())
1602509fc85bSRichard Smith AddTemplateSpecializations(D);
160339a1e507SLarisse Voufo Code = serialization::DECL_VAR_TEMPLATE;
160439a1e507SLarisse Voufo }
160539a1e507SLarisse Voufo
VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl * D)160639a1e507SLarisse Voufo void ASTDeclWriter::VisitVarTemplateSpecializationDecl(
160739a1e507SLarisse Voufo VarTemplateSpecializationDecl *D) {
1608d8a83718SRichard Smith RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1609d8a83718SRichard Smith
161039a1e507SLarisse Voufo VisitVarDecl(D);
161139a1e507SLarisse Voufo
161239a1e507SLarisse Voufo llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
161339a1e507SLarisse Voufo InstFrom = D->getSpecializedTemplateOrPartial();
161439a1e507SLarisse Voufo if (Decl *InstFromD = InstFrom.dyn_cast<VarTemplateDecl *>()) {
161569c82bfaSRichard Smith Record.AddDeclRef(InstFromD);
161639a1e507SLarisse Voufo } else {
161769c82bfaSRichard Smith Record.AddDeclRef(InstFrom.get<VarTemplatePartialSpecializationDecl *>());
161869c82bfaSRichard Smith Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
161939a1e507SLarisse Voufo }
162039a1e507SLarisse Voufo
162139a1e507SLarisse Voufo // Explicit info.
162269c82bfaSRichard Smith Record.AddTypeSourceInfo(D->getTypeAsWritten());
162339a1e507SLarisse Voufo if (D->getTypeAsWritten()) {
162469c82bfaSRichard Smith Record.AddSourceLocation(D->getExternLoc());
162569c82bfaSRichard Smith Record.AddSourceLocation(D->getTemplateKeywordLoc());
162639a1e507SLarisse Voufo }
162739a1e507SLarisse Voufo
162869c82bfaSRichard Smith Record.AddTemplateArgumentList(&D->getTemplateArgs());
162969c82bfaSRichard Smith Record.AddSourceLocation(D->getPointOfInstantiation());
163039a1e507SLarisse Voufo Record.push_back(D->getSpecializationKind());
1631435e647aSRichard Smith Record.push_back(D->IsCompleteDefinition);
163239a1e507SLarisse Voufo Record.push_back(D->isCanonicalDecl());
163339a1e507SLarisse Voufo
163439a1e507SLarisse Voufo if (D->isCanonicalDecl()) {
163539a1e507SLarisse Voufo // When reading, we'll add it to the folding set of the following template.
163669c82bfaSRichard Smith Record.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl());
163739a1e507SLarisse Voufo }
163839a1e507SLarisse Voufo
163939a1e507SLarisse Voufo Code = serialization::DECL_VAR_TEMPLATE_SPECIALIZATION;
164039a1e507SLarisse Voufo }
164139a1e507SLarisse Voufo
VisitVarTemplatePartialSpecializationDecl(VarTemplatePartialSpecializationDecl * D)164239a1e507SLarisse Voufo void ASTDeclWriter::VisitVarTemplatePartialSpecializationDecl(
164339a1e507SLarisse Voufo VarTemplatePartialSpecializationDecl *D) {
164469c82bfaSRichard Smith Record.AddTemplateParameterList(D->getTemplateParameters());
164569c82bfaSRichard Smith Record.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten());
164639a1e507SLarisse Voufo
1647df061c3eSSaar Raz VisitVarTemplateSpecializationDecl(D);
1648df061c3eSSaar Raz
164939a1e507SLarisse Voufo // These are read/set from/to the first declaration.
1650a13603a2SCraig Topper if (D->getPreviousDecl() == nullptr) {
165169c82bfaSRichard Smith Record.AddDeclRef(D->getInstantiatedFromMember());
165239a1e507SLarisse Voufo Record.push_back(D->isMemberSpecialization());
165339a1e507SLarisse Voufo }
165439a1e507SLarisse Voufo
165539a1e507SLarisse Voufo Code = serialization::DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION;
165639a1e507SLarisse Voufo }
165739a1e507SLarisse Voufo
VisitClassScopeFunctionSpecializationDecl(ClassScopeFunctionSpecializationDecl * D)165809af8c36SFrancois Pichet void ASTDeclWriter::VisitClassScopeFunctionSpecializationDecl(
165909af8c36SFrancois Pichet ClassScopeFunctionSpecializationDecl *D) {
166009af8c36SFrancois Pichet VisitDecl(D);
166169c82bfaSRichard Smith Record.AddDeclRef(D->getSpecialization());
1662f19a8b05SRichard Smith Record.push_back(D->hasExplicitTemplateArgs());
1663f19a8b05SRichard Smith if (D->hasExplicitTemplateArgs())
1664f19a8b05SRichard Smith Record.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten());
166509af8c36SFrancois Pichet Code = serialization::DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION;
166609af8c36SFrancois Pichet }
166709af8c36SFrancois Pichet
166809af8c36SFrancois Pichet
VisitFunctionTemplateDecl(FunctionTemplateDecl * D)1669d6522cfcSSebastian Redl void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
1670d6522cfcSSebastian Redl VisitRedeclarableTemplateDecl(D);
1671d6522cfcSSebastian Redl
1672509fc85bSRichard Smith if (D->isFirstDecl())
1673509fc85bSRichard Smith AddTemplateSpecializations(D);
1674539c5061SSebastian Redl Code = serialization::DECL_FUNCTION_TEMPLATE;
1675d6522cfcSSebastian Redl }
1676d6522cfcSSebastian Redl
VisitTemplateTypeParmDecl(TemplateTypeParmDecl * D)1677d6522cfcSSebastian Redl void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
1678ff1e0fceSSaar Raz Record.push_back(D->hasTypeConstraint());
1679d6522cfcSSebastian Redl VisitTypeDecl(D);
1680d6522cfcSSebastian Redl
1681d6522cfcSSebastian Redl Record.push_back(D->wasDeclaredWithTypename());
1682ff1e0fceSSaar Raz
1683ff1e0fceSSaar Raz const TypeConstraint *TC = D->getTypeConstraint();
1684ff1e0fceSSaar Raz Record.push_back(TC != nullptr);
1685ff1e0fceSSaar Raz if (TC) {
1686ff1e0fceSSaar Raz Record.AddNestedNameSpecifierLoc(TC->getNestedNameSpecifierLoc());
1687ff1e0fceSSaar Raz Record.AddDeclarationNameInfo(TC->getConceptNameInfo());
1688ff1e0fceSSaar Raz Record.AddDeclRef(TC->getNamedConcept());
1689ff1e0fceSSaar Raz Record.push_back(TC->getTemplateArgsAsWritten() != nullptr);
1690ff1e0fceSSaar Raz if (TC->getTemplateArgsAsWritten())
1691ff1e0fceSSaar Raz Record.AddASTTemplateArgumentListInfo(TC->getTemplateArgsAsWritten());
1692ff1e0fceSSaar Raz Record.AddStmt(TC->getImmediatelyDeclaredConstraint());
1693ff1e0fceSSaar Raz Record.push_back(D->isExpandedParameterPack());
1694ff1e0fceSSaar Raz if (D->isExpandedParameterPack())
1695ff1e0fceSSaar Raz Record.push_back(D->getNumExpansionParameters());
1696ff1e0fceSSaar Raz }
1697ff1e0fceSSaar Raz
16988346e52fSRichard Smith bool OwnsDefaultArg = D->hasDefaultArgument() &&
16998346e52fSRichard Smith !D->defaultArgumentWasInherited();
17008346e52fSRichard Smith Record.push_back(OwnsDefaultArg);
17018346e52fSRichard Smith if (OwnsDefaultArg)
170269c82bfaSRichard Smith Record.AddTypeSourceInfo(D->getDefaultArgumentInfo());
1703d6522cfcSSebastian Redl
1704539c5061SSebastian Redl Code = serialization::DECL_TEMPLATE_TYPE_PARM;
1705d6522cfcSSebastian Redl }
1706d6522cfcSSebastian Redl
VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl * D)1707d6522cfcSSebastian Redl void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
17080231d8daSDouglas Gregor // For an expanded parameter pack, record the number of expansion types here
17091fde8eceSRichard Smith // so that it's easier for deserialization to allocate the right amount of
17101fde8eceSRichard Smith // memory.
1711b481f028SSaar Raz Expr *TypeConstraint = D->getPlaceholderTypeConstraint();
1712b481f028SSaar Raz Record.push_back(!!TypeConstraint);
17130231d8daSDouglas Gregor if (D->isExpandedParameterPack())
17140231d8daSDouglas Gregor Record.push_back(D->getNumExpansionTypes());
17150231d8daSDouglas Gregor
1716f4cd4f94SJohn McCall VisitDeclaratorDecl(D);
1717d6522cfcSSebastian Redl // TemplateParmPosition.
1718d6522cfcSSebastian Redl Record.push_back(D->getDepth());
1719d6522cfcSSebastian Redl Record.push_back(D->getPosition());
1720b481f028SSaar Raz if (TypeConstraint)
1721b481f028SSaar Raz Record.AddStmt(TypeConstraint);
17220231d8daSDouglas Gregor
17230231d8daSDouglas Gregor if (D->isExpandedParameterPack()) {
17240231d8daSDouglas Gregor for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
172569c82bfaSRichard Smith Record.AddTypeRef(D->getExpansionType(I));
172669c82bfaSRichard Smith Record.AddTypeSourceInfo(D->getExpansionTypeSourceInfo(I));
17270231d8daSDouglas Gregor }
17280231d8daSDouglas Gregor
17290231d8daSDouglas Gregor Code = serialization::DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK;
17300231d8daSDouglas Gregor } else {
1731d6522cfcSSebastian Redl // Rest of NonTypeTemplateParmDecl.
1732da3cc0d3SDouglas Gregor Record.push_back(D->isParameterPack());
17338346e52fSRichard Smith bool OwnsDefaultArg = D->hasDefaultArgument() &&
17348346e52fSRichard Smith !D->defaultArgumentWasInherited();
17358346e52fSRichard Smith Record.push_back(OwnsDefaultArg);
17368346e52fSRichard Smith if (OwnsDefaultArg)
1737290d8019SRichard Smith Record.AddStmt(D->getDefaultArgument());
1738539c5061SSebastian Redl Code = serialization::DECL_NON_TYPE_TEMPLATE_PARM;
1739d6522cfcSSebastian Redl }
17400231d8daSDouglas Gregor }
1741d6522cfcSSebastian Redl
VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl * D)1742d6522cfcSSebastian Redl void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
17431fde8eceSRichard Smith // For an expanded parameter pack, record the number of expansion types here
17441fde8eceSRichard Smith // so that it's easier for deserialization to allocate the right amount of
17451fde8eceSRichard Smith // memory.
17461fde8eceSRichard Smith if (D->isExpandedParameterPack())
17471fde8eceSRichard Smith Record.push_back(D->getNumExpansionTemplateParameters());
17481fde8eceSRichard Smith
1749d6522cfcSSebastian Redl VisitTemplateDecl(D);
1750d6522cfcSSebastian Redl // TemplateParmPosition.
1751d6522cfcSSebastian Redl Record.push_back(D->getDepth());
1752d6522cfcSSebastian Redl Record.push_back(D->getPosition());
17531fde8eceSRichard Smith
17541fde8eceSRichard Smith if (D->isExpandedParameterPack()) {
17551fde8eceSRichard Smith for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
17561fde8eceSRichard Smith I != N; ++I)
175769c82bfaSRichard Smith Record.AddTemplateParameterList(D->getExpansionTemplateParameters(I));
17581fde8eceSRichard Smith Code = serialization::DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK;
17591fde8eceSRichard Smith } else {
1760d6522cfcSSebastian Redl // Rest of TemplateTemplateParmDecl.
1761f550077eSDouglas Gregor Record.push_back(D->isParameterPack());
17628346e52fSRichard Smith bool OwnsDefaultArg = D->hasDefaultArgument() &&
17638346e52fSRichard Smith !D->defaultArgumentWasInherited();
17648346e52fSRichard Smith Record.push_back(OwnsDefaultArg);
17658346e52fSRichard Smith if (OwnsDefaultArg)
176669c82bfaSRichard Smith Record.AddTemplateArgumentLoc(D->getDefaultArgument());
1767539c5061SSebastian Redl Code = serialization::DECL_TEMPLATE_TEMPLATE_PARM;
1768d6522cfcSSebastian Redl }
17691fde8eceSRichard Smith }
1770d6522cfcSSebastian Redl
VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl * D)17713f1b5d07SRichard Smith void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
17723f1b5d07SRichard Smith VisitRedeclarableTemplateDecl(D);
17733f1b5d07SRichard Smith Code = serialization::DECL_TYPE_ALIAS_TEMPLATE;
17743f1b5d07SRichard Smith }
17753f1b5d07SRichard Smith
VisitStaticAssertDecl(StaticAssertDecl * D)1776d6522cfcSSebastian Redl void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) {
1777d6522cfcSSebastian Redl VisitDecl(D);
1778290d8019SRichard Smith Record.AddStmt(D->getAssertExpr());
1779ded9c2eeSRichard Smith Record.push_back(D->isFailed());
1780290d8019SRichard Smith Record.AddStmt(D->getMessage());
178169c82bfaSRichard Smith Record.AddSourceLocation(D->getRParenLoc());
1782539c5061SSebastian Redl Code = serialization::DECL_STATIC_ASSERT;
1783d6522cfcSSebastian Redl }
1784d6522cfcSSebastian Redl
17859fc8faf9SAdrian Prantl /// Emit the DeclContext part of a declaration context decl.
VisitDeclContext(DeclContext * DC)1786f1c23dc4SRichard Smith void ASTDeclWriter::VisitDeclContext(DeclContext *DC) {
1787f1c23dc4SRichard Smith Record.AddOffset(Writer.WriteDeclContextLexicalBlock(Context, DC));
1788f1c23dc4SRichard Smith Record.AddOffset(Writer.WriteDeclContextVisibleBlock(Context, DC));
1789d6522cfcSSebastian Redl }
1790d6522cfcSSebastian Redl
getFirstLocalDecl(const Decl * D)17913864be7bSRichard Smith const Decl *ASTWriter::getFirstLocalDecl(const Decl *D) {
17923864be7bSRichard Smith assert(IsLocalDecl(D) && "expected a local declaration");
1793d8a83718SRichard Smith
1794d8a83718SRichard Smith const Decl *Canon = D->getCanonicalDecl();
17953864be7bSRichard Smith if (IsLocalDecl(Canon))
1796d8a83718SRichard Smith return Canon;
1797d8a83718SRichard Smith
1798d8a83718SRichard Smith const Decl *&CacheEntry = FirstLocalDeclCache[Canon];
1799d8a83718SRichard Smith if (CacheEntry)
1800d8a83718SRichard Smith return CacheEntry;
1801d8a83718SRichard Smith
1802d8a83718SRichard Smith for (const Decl *Redecl = D; Redecl; Redecl = Redecl->getPreviousDecl())
18033864be7bSRichard Smith if (IsLocalDecl(Redecl))
1804d8a83718SRichard Smith D = Redecl;
1805d8a83718SRichard Smith return CacheEntry = D;
18065fc18a9aSRichard Smith }
18075fc18a9aSRichard Smith
1808d6522cfcSSebastian Redl template <typename T>
VisitRedeclarable(Redeclarable<T> * D)1809d6522cfcSSebastian Redl void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
18108db352d5SRafael Espindola T *First = D->getFirstDecl();
18115a4737cdSRichard Smith T *MostRecent = First->getMostRecentDecl();
1812d8a83718SRichard Smith T *DAsT = static_cast<T *>(D);
18135a4737cdSRichard Smith if (MostRecent != First) {
1814d8a83718SRichard Smith assert(isRedeclarableDeclKind(DAsT->getKind()) &&
1815fe732d53SDouglas Gregor "Not considered redeclarable?");
1816fe732d53SDouglas Gregor
181769c82bfaSRichard Smith Record.AddDeclRef(First);
1818fe620d26SRichard Smith
1819d8a83718SRichard Smith // Write out a list of local redeclarations of this declaration if it's the
1820d8a83718SRichard Smith // first local declaration in the chain.
1821d8a83718SRichard Smith const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1822d8a83718SRichard Smith if (DAsT == FirstLocal) {
1823d8a83718SRichard Smith // Emit a list of all imported first declarations so that we can be sure
1824d8a83718SRichard Smith // that all redeclarations visible to this module are before D in the
1825d8a83718SRichard Smith // redecl chain.
18265fc18a9aSRichard Smith unsigned I = Record.size();
1827fe620d26SRichard Smith Record.push_back(0);
1828d8a83718SRichard Smith if (Writer.Chain)
1829d8a83718SRichard Smith AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1830d8a83718SRichard Smith // This is the number of imported first declarations + 1.
1831d8a83718SRichard Smith Record[I] = Record.size() - I;
1832d61d4acdSRichard Smith
1833d61d4acdSRichard Smith // Collect the set of local redeclarations of this declaration, from
1834d61d4acdSRichard Smith // newest to oldest.
183569c82bfaSRichard Smith ASTWriter::RecordData LocalRedecls;
183669c82bfaSRichard Smith ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls);
1837d61d4acdSRichard Smith for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1838d61d4acdSRichard Smith Prev != FirstLocal; Prev = Prev->getPreviousDecl())
1839d61d4acdSRichard Smith if (!Prev->isFromASTFile())
184069c82bfaSRichard Smith LocalRedeclWriter.AddDeclRef(Prev);
1841d61d4acdSRichard Smith
1842d61d4acdSRichard Smith // If we have any redecls, write them now as a separate record preceding
1843d61d4acdSRichard Smith // the declaration itself.
1844d61d4acdSRichard Smith if (LocalRedecls.empty())
1845d61d4acdSRichard Smith Record.push_back(0);
1846f1c23dc4SRichard Smith else
1847f1c23dc4SRichard Smith Record.AddOffset(LocalRedeclWriter.Emit(LOCAL_REDECLARATIONS));
1848d8a83718SRichard Smith } else {
1849d8a83718SRichard Smith Record.push_back(0);
185069c82bfaSRichard Smith Record.AddDeclRef(FirstLocal);
18515fc18a9aSRichard Smith }
1852358cd441SDouglas Gregor
1853358cd441SDouglas Gregor // Make sure that we serialize both the previous and the most-recent
1854358cd441SDouglas Gregor // declarations, which (transitively) ensures that all declarations in the
1855358cd441SDouglas Gregor // chain get serialized.
18565a4737cdSRichard Smith //
18575a4737cdSRichard Smith // FIXME: This is not correct; when we reach an imported declaration we
18585a4737cdSRichard Smith // won't emit its previous declaration.
18595fc18a9aSRichard Smith (void)Writer.GetDeclRef(D->getPreviousDecl());
18605a4737cdSRichard Smith (void)Writer.GetDeclRef(MostRecent);
1861358cd441SDouglas Gregor } else {
1862358cd441SDouglas Gregor // We use the sentinel value 0 to indicate an only declaration.
1863358cd441SDouglas Gregor Record.push_back(0);
18649f562c8dSDouglas Gregor }
1865d6522cfcSSebastian Redl }
1866d6522cfcSSebastian Redl
VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl * D)1867a769e072SAlexey Bataev void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
18680af7835eSAlexey Bataev Record.writeOMPChildren(D->Data);
1869a769e072SAlexey Bataev VisitDecl(D);
1870a769e072SAlexey Bataev Code = serialization::DECL_OMP_THREADPRIVATE;
1871a769e072SAlexey Bataev }
1872a769e072SAlexey Bataev
VisitOMPAllocateDecl(OMPAllocateDecl * D)187325ed0c07SAlexey Bataev void ASTDeclWriter::VisitOMPAllocateDecl(OMPAllocateDecl *D) {
18740af7835eSAlexey Bataev Record.writeOMPChildren(D->Data);
187525ed0c07SAlexey Bataev VisitDecl(D);
187625ed0c07SAlexey Bataev Code = serialization::DECL_OMP_ALLOCATE;
187725ed0c07SAlexey Bataev }
187825ed0c07SAlexey Bataev
VisitOMPRequiresDecl(OMPRequiresDecl * D)18791408f91aSKelvin Li void ASTDeclWriter::VisitOMPRequiresDecl(OMPRequiresDecl *D) {
18800af7835eSAlexey Bataev Record.writeOMPChildren(D->Data);
18811408f91aSKelvin Li VisitDecl(D);
18821408f91aSKelvin Li Code = serialization::DECL_OMP_REQUIRES;
18831408f91aSKelvin Li }
18841408f91aSKelvin Li
VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl * D)188594a4f0cbSAlexey Bataev void ASTDeclWriter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
1886c5b1d320SAlexey Bataev VisitValueDecl(D);
1887f2ceec48SStephen Kelly Record.AddSourceLocation(D->getBeginLoc());
1888e6aa4694SAlexey Bataev Record.AddStmt(D->getCombinerIn());
1889e6aa4694SAlexey Bataev Record.AddStmt(D->getCombinerOut());
1890290d8019SRichard Smith Record.AddStmt(D->getCombiner());
1891e6aa4694SAlexey Bataev Record.AddStmt(D->getInitOrig());
1892e6aa4694SAlexey Bataev Record.AddStmt(D->getInitPriv());
1893290d8019SRichard Smith Record.AddStmt(D->getInitializer());
1894070f43aeSAlexey Bataev Record.push_back(D->getInitializerKind());
189569c82bfaSRichard Smith Record.AddDeclRef(D->getPrevDeclInScope());
189694a4f0cbSAlexey Bataev Code = serialization::DECL_OMP_DECLARE_REDUCTION;
189794a4f0cbSAlexey Bataev }
189894a4f0cbSAlexey Bataev
VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl * D)1899251e1488SMichael Kruse void ASTDeclWriter::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) {
19000af7835eSAlexey Bataev Record.writeOMPChildren(D->Data);
1901251e1488SMichael Kruse VisitValueDecl(D);
1902251e1488SMichael Kruse Record.AddDeclarationName(D->getVarName());
1903251e1488SMichael Kruse Record.AddDeclRef(D->getPrevDeclInScope());
1904251e1488SMichael Kruse Code = serialization::DECL_OMP_DECLARE_MAPPER;
1905251e1488SMichael Kruse }
1906251e1488SMichael Kruse
VisitOMPCapturedExprDecl(OMPCapturedExprDecl * D)19074244be25SAlexey Bataev void ASTDeclWriter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
190890c228f0SAlexey Bataev VisitVarDecl(D);
19094244be25SAlexey Bataev Code = serialization::DECL_OMP_CAPTUREDEXPR;
191090c228f0SAlexey Bataev }
191190c228f0SAlexey Bataev
1912d6522cfcSSebastian Redl //===----------------------------------------------------------------------===//
1913d6522cfcSSebastian Redl // ASTWriter Implementation
1914d6522cfcSSebastian Redl //===----------------------------------------------------------------------===//
1915d6522cfcSSebastian Redl
WriteDeclAbbrevs()191601b2cb47SRichard Smith void ASTWriter::WriteDeclAbbrevs() {
1917d6522cfcSSebastian Redl using namespace llvm;
1918d6522cfcSSebastian Redl
1919b44f0bfbSDavid Blaikie std::shared_ptr<BitCodeAbbrev> Abv;
192003412ba0SDouglas Gregor
1921205c7d55SJonathan D. Turner // Abbreviation for DECL_FIELD
1922b44f0bfbSDavid Blaikie Abv = std::make_shared<BitCodeAbbrev>();
1923205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(serialization::DECL_FIELD));
1924205c7d55SJonathan D. Turner // Decl
1925205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
19268aed4222SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
1927b7d1ca27SArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
1928205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1929205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1930205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1931205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
19328ad3bab5SArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
1933205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
19349c04851cSChuanqi Xu Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // ModuleOwnershipKind
1935a28bcddeSDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
1936205c7d55SJonathan D. Turner // NamedDecl
1937205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1938205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
19392b560575SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
1940205c7d55SJonathan D. Turner // ValueDecl
1941205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1942205c7d55SJonathan D. Turner // DeclaratorDecl
1943205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1944205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
1945c23d734dSRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
1946205c7d55SJonathan D. Turner // FieldDecl
1947205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
19486b8e3c02SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // InitStyle
1949205c7d55SJonathan D. Turner // Type Source Info
1950205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1951205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1952b44f0bfbSDavid Blaikie DeclFieldAbbrev = Stream.EmitAbbrev(std::move(Abv));
1953205c7d55SJonathan D. Turner
1954205c7d55SJonathan D. Turner // Abbreviation for DECL_OBJC_IVAR
1955b44f0bfbSDavid Blaikie Abv = std::make_shared<BitCodeAbbrev>();
1956205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR));
1957205c7d55SJonathan D. Turner // Decl
1958205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
19598aed4222SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
1960b7d1ca27SArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
1961205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1962205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1963205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1964205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
19658ad3bab5SArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
1966205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
19679c04851cSChuanqi Xu Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // ModuleOwnershipKind
1968a28bcddeSDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
1969205c7d55SJonathan D. Turner // NamedDecl
1970205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1971205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
19722b560575SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
1973205c7d55SJonathan D. Turner // ValueDecl
1974205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1975205c7d55SJonathan D. Turner // DeclaratorDecl
1976205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1977205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
1978c23d734dSRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
1979205c7d55SJonathan D. Turner // FieldDecl
1980205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
19816b8e3c02SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // InitStyle
1982205c7d55SJonathan D. Turner // ObjC Ivar
1983205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl
1984205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize
1985205c7d55SJonathan D. Turner // Type Source Info
1986205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1987205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1988b44f0bfbSDavid Blaikie DeclObjCIvarAbbrev = Stream.EmitAbbrev(std::move(Abv));
1989205c7d55SJonathan D. Turner
1990205c7d55SJonathan D. Turner // Abbreviation for DECL_ENUM
1991b44f0bfbSDavid Blaikie Abv = std::make_shared<BitCodeAbbrev>();
1992205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(serialization::DECL_ENUM));
19933e30010dSDouglas Gregor // Redeclarable
19949f562c8dSDouglas Gregor Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
1995d6522cfcSSebastian Redl // Decl
1996d6522cfcSSebastian Redl Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
19978aed4222SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
1998b7d1ca27SArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
1999d6522cfcSSebastian Redl Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
2000d6522cfcSSebastian Redl Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
2001d6522cfcSSebastian Redl Abv->Add(BitCodeAbbrevOp(0)); // isUsed
200216180230SArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
20038ad3bab5SArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
2004d6522cfcSSebastian Redl Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
20059c04851cSChuanqi Xu Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // ModuleOwnershipKind
2006a28bcddeSDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
200703412ba0SDouglas Gregor // NamedDecl
200803412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
200903412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
20102b560575SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2011205c7d55SJonathan D. Turner // TypeDecl
2012205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2013205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
2014205c7d55SJonathan D. Turner // TagDecl
2015205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
2016205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
2017f937c023SJohn McCall Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
2018205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
2019201d3771SArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
2020a8d23ce8SDavid Blaikie Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
2021205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
2022d798c055SArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
202370d58509SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
2024205c7d55SJonathan D. Turner // EnumDecl
2025205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddTypeRef
2026205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IntegerType
2027205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getPromotionType
2028205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumPositiveBits
2029205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumNegativeBits
2030205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScoped
2031205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScopedUsingClassTag
2032205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isFixed
2033ab4d730fSRichard Trieu Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));// ODRHash
2034205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedMembEnum
2035205c7d55SJonathan D. Turner // DC
2036205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
2037205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
2038b44f0bfbSDavid Blaikie DeclEnumAbbrev = Stream.EmitAbbrev(std::move(Abv));
2039d6522cfcSSebastian Redl
204003412ba0SDouglas Gregor // Abbreviation for DECL_RECORD
2041b44f0bfbSDavid Blaikie Abv = std::make_shared<BitCodeAbbrev>();
204203412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(serialization::DECL_RECORD));
20433e30010dSDouglas Gregor // Redeclarable
20449f562c8dSDouglas Gregor Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
204503412ba0SDouglas Gregor // Decl
204603412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
20478aed4222SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
2048b7d1ca27SArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
204903412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
205003412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
205103412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(0)); // isUsed
205203412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
20538ad3bab5SArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
205403412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
20559c04851cSChuanqi Xu Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // ModuleOwnershipKind
2056a28bcddeSDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
205703412ba0SDouglas Gregor // NamedDecl
205803412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
205903412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
20602b560575SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
206103412ba0SDouglas Gregor // TypeDecl
206203412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
206303412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
206403412ba0SDouglas Gregor // TagDecl
206503412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
206603412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
2067f937c023SJohn McCall Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
206803412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
2069201d3771SArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
2070a8d23ce8SDavid Blaikie Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
207103412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
2072d798c055SArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
207370d58509SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
207403412ba0SDouglas Gregor // RecordDecl
207503412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // FlexibleArrayMember
207603412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // AnonymousStructUnion
207703412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasObjectMember
20787865220dSFariborz Jahanian Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasVolatileMember
207934fb2645SAkira Hatanaka
208034fb2645SAkira Hatanaka // isNonTrivialToPrimitiveDefaultInitialize
208134fb2645SAkira Hatanaka Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
208234fb2645SAkira Hatanaka // isNonTrivialToPrimitiveCopy
208334fb2645SAkira Hatanaka Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
208434fb2645SAkira Hatanaka // isNonTrivialToPrimitiveDestroy
208534fb2645SAkira Hatanaka Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
208609051060SAkira Hatanaka // hasNonTrivialToPrimitiveDefaultInitializeCUnion
208709051060SAkira Hatanaka Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
208809051060SAkira Hatanaka // hasNonTrivialToPrimitiveDestructCUnion
208909051060SAkira Hatanaka Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
209009051060SAkira Hatanaka // hasNonTrivialToPrimitiveCopyCUnion
209109051060SAkira Hatanaka Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
2092fcbe17c6SAkira Hatanaka // isParamDestroyedInCallee
2093fcbe17c6SAkira Hatanaka Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1));
2094e6313aceSAkira Hatanaka // getArgPassingRestrictions
2095e6313aceSAkira Hatanaka Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2));
209634fb2645SAkira Hatanaka
209703412ba0SDouglas Gregor // DC
209803412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
209903412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
2100b44f0bfbSDavid Blaikie DeclRecordAbbrev = Stream.EmitAbbrev(std::move(Abv));
210103412ba0SDouglas Gregor
210203412ba0SDouglas Gregor // Abbreviation for DECL_PARM_VAR
2103b44f0bfbSDavid Blaikie Abv = std::make_shared<BitCodeAbbrev>();
210403412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(serialization::DECL_PARM_VAR));
21053e30010dSDouglas Gregor // Redeclarable
21069f562c8dSDouglas Gregor Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
210703412ba0SDouglas Gregor // Decl
210803412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
21098aed4222SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
2110b7d1ca27SArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
211103412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
211203412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
211303412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(0)); // isUsed
211403412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
21158ad3bab5SArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
211603412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
21179c04851cSChuanqi Xu Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // ModuleOwnershipKind
2118a28bcddeSDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2119d6522cfcSSebastian Redl // NamedDecl
2120d6522cfcSSebastian Redl Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2121d6522cfcSSebastian Redl Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
21222b560575SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2123d6522cfcSSebastian Redl // ValueDecl
2124d6522cfcSSebastian Redl Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2125d6522cfcSSebastian Redl // DeclaratorDecl
2126dff1930bSAbramo Bagnara Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
2127434383d7SArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
2128c23d734dSRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
2129d6522cfcSSebastian Redl // VarDecl
2130d1a88130SVassil Vassilev Abv->Add(BitCodeAbbrevOp(0)); // SClass
2131d1a88130SVassil Vassilev Abv->Add(BitCodeAbbrevOp(0)); // TSCSpec
2132d1a88130SVassil Vassilev Abv->Add(BitCodeAbbrevOp(0)); // InitStyle
21338b529e31SDavid Goldman Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong
21348858159fSRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // Linkage
2135d6522cfcSSebastian Redl Abv->Add(BitCodeAbbrevOp(0)); // HasInit
2136d6522cfcSSebastian Redl Abv->Add(BitCodeAbbrevOp(0)); // HasMemberSpecializationInfo
2137d6522cfcSSebastian Redl // ParmVarDecl
213882490837SJohn McCall Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsObjCMethodParameter
21398fb0d9d2SJohn McCall Abv->Add(BitCodeAbbrevOp(0)); // ScopeDepth
21408fb0d9d2SJohn McCall Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex
2141d6522cfcSSebastian Redl Abv->Add(BitCodeAbbrevOp(0)); // ObjCDeclQualifier
21426a014d5cSJohn McCall Abv->Add(BitCodeAbbrevOp(0)); // KNRPromoted
2143d6522cfcSSebastian Redl Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedDefaultArg
2144d6522cfcSSebastian Redl Abv->Add(BitCodeAbbrevOp(0)); // HasUninstantiatedDefaultArg
2145205c7d55SJonathan D. Turner // Type Source Info
2146205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2147205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
2148b44f0bfbSDavid Blaikie DeclParmVarAbbrev = Stream.EmitAbbrev(std::move(Abv));
2149d6522cfcSSebastian Redl
2150780a6bf0SJonathan D. Turner // Abbreviation for DECL_TYPEDEF
2151b44f0bfbSDavid Blaikie Abv = std::make_shared<BitCodeAbbrev>();
2152205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(serialization::DECL_TYPEDEF));
215305f10357SDouglas Gregor // Redeclarable
21549f562c8dSDouglas Gregor Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
2155205c7d55SJonathan D. Turner // Decl
2156205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
21578aed4222SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
2158b7d1ca27SArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
2159205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
2160205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
216101b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isUsed
216201b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isReferenced
21638ad3bab5SArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
216401b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // C++ AccessSpecifier
21659c04851cSChuanqi Xu Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // ModuleOwnershipKind
2166a28bcddeSDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2167205c7d55SJonathan D. Turner // NamedDecl
2168205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2169205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
21702b560575SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2171205c7d55SJonathan D. Turner // TypeDecl
2172205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2173205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
2174205c7d55SJonathan D. Turner // TypedefDecl
2175205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2176205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
2177b44f0bfbSDavid Blaikie DeclTypedefAbbrev = Stream.EmitAbbrev(std::move(Abv));
2178205c7d55SJonathan D. Turner
2179780a6bf0SJonathan D. Turner // Abbreviation for DECL_VAR
2180b44f0bfbSDavid Blaikie Abv = std::make_shared<BitCodeAbbrev>();
2181205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(serialization::DECL_VAR));
21823e30010dSDouglas Gregor // Redeclarable
21839f562c8dSDouglas Gregor Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
2184205c7d55SJonathan D. Turner // Decl
2185205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
21868aed4222SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
2187b7d1ca27SArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
2188205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
2189205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
2190205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // isUsed
2191205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
21928ad3bab5SArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
2193205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
21949c04851cSChuanqi Xu Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // ModuleOwnershipKind
2195a28bcddeSDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2196205c7d55SJonathan D. Turner // NamedDecl
2197205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2198205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
21992b560575SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2200205c7d55SJonathan D. Turner // ValueDecl
2201205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2202205c7d55SJonathan D. Turner // DeclaratorDecl
2203205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
2204205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
2205c23d734dSRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
2206205c7d55SJonathan D. Turner // VarDecl
2207d1a88130SVassil Vassilev Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // SClass
2208d1a88130SVassil Vassilev Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // TSCSpec
2209d1a88130SVassil Vassilev Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // InitStyle
22101e36882bSErik Pilkington Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong
2211edbc6e93SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsThisDeclarationADemotedDefinition
2212205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isExceptionVariable
22133be68e16STaiju Tsuiki Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isNRVOVariable
2214205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCXXForRangeDecl
2215ec38cf7aSGeorge Karpenkov Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isObjCForDecl
221662f19e70SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // isInline
221762f19e70SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // isInlineSpecified
221812cda633SDouglas Gregor Abv->Add(BitCodeAbbrevOp(0)); // isConstexpr
2219bb13c9a4SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // isInitCapture
22201c34fb78SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // isPrevDeclInSameScope
222156223237SAlexey Bataev Abv->Add(BitCodeAbbrevOp(0)); // ImplicitParamKind
22228e57b07fSAkira Hatanaka Abv->Add(BitCodeAbbrevOp(0)); // EscapingByref
222350df3a02SRafael Espindola Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
22243692d20dSRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // HasConstant*
2225d1a88130SVassil Vassilev Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // VarKind (local enum)
2226205c7d55SJonathan D. Turner // Type Source Info
2227205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2228205c7d55SJonathan D. Turner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
2229b44f0bfbSDavid Blaikie DeclVarAbbrev = Stream.EmitAbbrev(std::move(Abv));
2230205c7d55SJonathan D. Turner
223101b2cb47SRichard Smith // Abbreviation for DECL_CXX_METHOD
2232b44f0bfbSDavid Blaikie Abv = std::make_shared<BitCodeAbbrev>();
223301b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(serialization::DECL_CXX_METHOD));
223401b2cb47SRichard Smith // RedeclarableDecl
223501b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // CanonicalDecl
223601b2cb47SRichard Smith // Decl
223701b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
22388aed4222SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
223901b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // Invalid
224001b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
224101b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Implicit
224201b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Used
224301b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Referenced
224401b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // InObjCContainer
224501b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Access
22469c04851cSChuanqi Xu Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // ModuleOwnershipKind
224701b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
224801b2cb47SRichard Smith // NamedDecl
224901b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(DeclarationName::Identifier)); // NameKind
225001b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Identifier
22512b560575SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
225201b2cb47SRichard Smith // ValueDecl
225301b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
225401b2cb47SRichard Smith // DeclaratorDecl
225501b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerLocStart
225601b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // HasExtInfo
2257c23d734dSRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
225801b2cb47SRichard Smith // FunctionDecl
225901b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS
226001b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // StorageClass
226101b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Inline
226201b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InlineSpecified
226301b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // VirtualAsWritten
226401b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Pure
226501b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedProto
226601b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(1)); // HasWrittenProto
226772625c2cSRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Deleted
226801b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Trivial
226902914dc1SAkira Hatanaka Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // TrivialForCall
227001b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Defaulted
227101b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ExplicitlyDefaulted
227201b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ImplicitReturnZero
22737a8c7946SNathan Ridge Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Constexpr
22740d15738fSReid Kleckner Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // UsesSEHTry
227501b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // SkippedBody
2276281d20b6SErich Keane Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // MultiVersion
227701b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // LateParsed
227801b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
227901b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LocEnd
2280e6caa26eSRichard Trieu Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // ODRHash
228101b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // TemplateKind
228201b2cb47SRichard Smith // This Array slurps the rest of the record. Fortunately we want to encode
228301b2cb47SRichard Smith // (nearly) all the remaining (variable number of) fields in the same way.
228401b2cb47SRichard Smith //
228501b2cb47SRichard Smith // This is the function template information if any, then
228601b2cb47SRichard Smith // NumParams and Params[] from FunctionDecl, and
228701b2cb47SRichard Smith // NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl.
228801b2cb47SRichard Smith //
228901b2cb47SRichard Smith // Add an AbbrevOp for 'size then elements' and use it here.
229001b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
229101b2cb47SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
2292b44f0bfbSDavid Blaikie DeclCXXMethodAbbrev = Stream.EmitAbbrev(std::move(Abv));
229301b2cb47SRichard Smith
22940cd5cd19SSam McCall unsigned ExprDependenceBits = llvm::BitWidth<ExprDependence>;
2295780a6bf0SJonathan D. Turner // Abbreviation for EXPR_DECL_REF
2296b44f0bfbSDavid Blaikie Abv = std::make_shared<BitCodeAbbrev>();
229703412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(serialization::EXPR_DECL_REF));
229803412ba0SDouglas Gregor //Stmt
229903412ba0SDouglas Gregor // Expr
230003412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
23010cd5cd19SSam McCall Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, ExprDependenceBits));
230203412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
230303412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
230403412ba0SDouglas Gregor //DeclRefExpr
230503412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HasQualifier
230603412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //GetDeclFound
230703412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ExplicitTemplateArgs
2308635ed24eSAbramo Bagnara Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HadMultipleCandidates
2309715f7a1bSRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // RefersToEnclosingVariableOrCapture
2310715f7a1bSRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // NonOdrUseReason
231103412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef
231203412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2313b44f0bfbSDavid Blaikie DeclRefExprAbbrev = Stream.EmitAbbrev(std::move(Abv));
231403412ba0SDouglas Gregor
231503412ba0SDouglas Gregor // Abbreviation for EXPR_INTEGER_LITERAL
2316b44f0bfbSDavid Blaikie Abv = std::make_shared<BitCodeAbbrev>();
231703412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL));
231803412ba0SDouglas Gregor //Stmt
231903412ba0SDouglas Gregor // Expr
232003412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
23210cd5cd19SSam McCall Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, ExprDependenceBits));
232203412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
232303412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
232403412ba0SDouglas Gregor //Integer Literal
232503412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
232603412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(32)); // Bit Width
232703412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value
2328b44f0bfbSDavid Blaikie IntegerLiteralAbbrev = Stream.EmitAbbrev(std::move(Abv));
232903412ba0SDouglas Gregor
233003412ba0SDouglas Gregor // Abbreviation for EXPR_CHARACTER_LITERAL
2331b44f0bfbSDavid Blaikie Abv = std::make_shared<BitCodeAbbrev>();
233203412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL));
233303412ba0SDouglas Gregor //Stmt
233403412ba0SDouglas Gregor // Expr
233503412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
23360cd5cd19SSam McCall Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, ExprDependenceBits));
233703412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
233803412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
233903412ba0SDouglas Gregor //Character Literal
234003412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue
234103412ba0SDouglas Gregor Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
23429a17c854SAaron Ballman Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // getKind
2343b44f0bfbSDavid Blaikie CharacterLiteralAbbrev = Stream.EmitAbbrev(std::move(Abv));
234403412ba0SDouglas Gregor
2345a27c26e7SRichard Smith // Abbreviation for EXPR_IMPLICIT_CAST
2346b44f0bfbSDavid Blaikie Abv = std::make_shared<BitCodeAbbrev>();
2347a27c26e7SRichard Smith Abv->Add(BitCodeAbbrevOp(serialization::EXPR_IMPLICIT_CAST));
2348a27c26e7SRichard Smith // Stmt
2349a27c26e7SRichard Smith // Expr
2350a27c26e7SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
23510cd5cd19SSam McCall Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, ExprDependenceBits));
2352a27c26e7SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2353a27c26e7SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2354a27c26e7SRichard Smith // CastExpr
2355a27c26e7SRichard Smith Abv->Add(BitCodeAbbrevOp(0)); // PathSize
2356f1cd6593SSerge Pavlov Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasFPFeatures
2357a27c26e7SRichard Smith Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 6)); // CastKind
2358d55661dbSRoman Lebedev Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // PartOfExplicitCast
2359a27c26e7SRichard Smith // ImplicitCastExpr
2360b44f0bfbSDavid Blaikie ExprImplicitCastAbbrev = Stream.EmitAbbrev(std::move(Abv));
2361a27c26e7SRichard Smith
2362b44f0bfbSDavid Blaikie Abv = std::make_shared<BitCodeAbbrev>();
2363539c5061SSebastian Redl Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL));
2364d6522cfcSSebastian Redl Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2365b44f0bfbSDavid Blaikie DeclContextLexicalAbbrev = Stream.EmitAbbrev(std::move(Abv));
2366ba88bfabSArgyrios Kyrtzidis
2367b44f0bfbSDavid Blaikie Abv = std::make_shared<BitCodeAbbrev>();
2368ba88bfabSArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE));
2369ba88bfabSArgyrios Kyrtzidis Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2370b44f0bfbSDavid Blaikie DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(std::move(Abv));
2371d6522cfcSSebastian Redl }
2372d6522cfcSSebastian Redl
2373d6522cfcSSebastian Redl /// isRequiredDecl - Check if this is a "required" Decl, which must be seen by
2374d6522cfcSSebastian Redl /// consumers of the AST.
2375d6522cfcSSebastian Redl ///
2376d6522cfcSSebastian Redl /// Such decls will always be deserialized from the AST file, so we would like
2377d6522cfcSSebastian Redl /// this to be as restrictive as possible. Currently the predicate is driven by
2378d6522cfcSSebastian Redl /// code generation requirements, if other clients have a different notion of
2379d6522cfcSSebastian Redl /// what is "required" then we may have to consider an alternate scheme where
2380d6522cfcSSebastian Redl /// clients can iterate over the top-level decls and get information on them,
2381d6522cfcSSebastian Redl /// without necessary deserializing them. We could explicitly require such
2382d6522cfcSSebastian Redl /// clients to use a separate API call to "realize" the decl. This should be
2383d6522cfcSSebastian Redl /// relatively painless since they would presumably only do it for top-level
2384d6522cfcSSebastian Redl /// decls.
isRequiredDecl(const Decl * D,ASTContext & Context,bool WritingModule)2385c52efa7dSRichard Smith static bool isRequiredDecl(const Decl *D, ASTContext &Context,
2386e6b7c28dSDavid Blaikie bool WritingModule) {
2387a98e8619SArgyrios Kyrtzidis // An ObjCMethodDecl is never considered as "required" because its
2388a98e8619SArgyrios Kyrtzidis // implementation container always is.
2389a98e8619SArgyrios Kyrtzidis
23900b0da296SDmitry Polukhin // File scoped assembly or obj-c or OMP declare target implementation must be
23910b0da296SDmitry Polukhin // seen.
2392d01b7497SAlexey Bataev if (isa<FileScopeAsmDecl>(D) || isa<ObjCImplDecl>(D))
2393c52efa7dSRichard Smith return true;
2394c52efa7dSRichard Smith
2395520a37f5SRichard Smith if (WritingModule && isPartOfPerModuleInitializer(D)) {
2396dc1f0421SRichard Smith // These declarations are part of the module initializer, and are emitted
2397dc1f0421SRichard Smith // if and when the module is imported, rather than being emitted eagerly.
2398dc1f0421SRichard Smith return false;
2399dc1f0421SRichard Smith }
2400d6522cfcSSebastian Redl
2401e6b7c28dSDavid Blaikie return Context.DeclMustBeEmitted(D);
2402d6522cfcSSebastian Redl }
2403d6522cfcSSebastian Redl
WriteDecl(ASTContext & Context,Decl * D)2404d6522cfcSSebastian Redl void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) {
24051e879d8bSJordan Rose PrettyDeclStackTraceEntry CrashInfo(Context, D, SourceLocation(),
24061e879d8bSJordan Rose "serializing");
24071e879d8bSJordan Rose
2408b3163e57SDouglas Gregor // Determine the ID for this declaration.
2409b3163e57SDouglas Gregor serialization::DeclID ID;
24107dd37e52SDouglas Gregor assert(!D->isFromASTFile() && "should not be emitting imported decl");
2411539c5061SSebastian Redl serialization::DeclID &IDR = DeclIDs[D];
2412d6522cfcSSebastian Redl if (IDR == 0)
2413d6522cfcSSebastian Redl IDR = NextDeclID++;
2414b3163e57SDouglas Gregor
2415b3163e57SDouglas Gregor ID = IDR;
2416d6522cfcSSebastian Redl
241734da7514SRichard Smith assert(ID >= FirstDeclID && "invalid decl ID");
2418bf6c3395SArgyrios Kyrtzidis
241969c82bfaSRichard Smith RecordData Record;
242069c82bfaSRichard Smith ASTDeclWriter W(*this, Context, Record);
242169c82bfaSRichard Smith
2422d61d4acdSRichard Smith // Build a record for this declaration
2423d61d4acdSRichard Smith W.Visit(D);
2424d61d4acdSRichard Smith
242569c82bfaSRichard Smith // Emit this declaration to the bitstream.
242669c82bfaSRichard Smith uint64_t Offset = W.Emit(D);
2427d6522cfcSSebastian Redl
2428d6522cfcSSebastian Redl // Record the offset for this declaration
24295fc727a0SArgyrios Kyrtzidis SourceLocation Loc = D->getLocation();
243069c82bfaSRichard Smith unsigned Index = ID - FirstDeclID;
2431d6522cfcSSebastian Redl if (DeclOffsets.size() == Index)
2432bb8c7e75SDaniel Grumberg DeclOffsets.emplace_back(Loc, Offset, DeclTypesBlockStartOffset);
2433d6522cfcSSebastian Redl else if (DeclOffsets.size() < Index) {
243469c82bfaSRichard Smith // FIXME: Can/should this happen?
2435d6522cfcSSebastian Redl DeclOffsets.resize(Index+1);
24365fc727a0SArgyrios Kyrtzidis DeclOffsets[Index].setLocation(Loc);
2437bb8c7e75SDaniel Grumberg DeclOffsets[Index].setBitOffset(Offset, DeclTypesBlockStartOffset);
243869c82bfaSRichard Smith } else {
243969c82bfaSRichard Smith llvm_unreachable("declarations should be emitted in ID order");
2440d6522cfcSSebastian Redl }
24415fc727a0SArgyrios Kyrtzidis
24425fc727a0SArgyrios Kyrtzidis SourceManager &SM = Context.getSourceManager();
2443df53da87SArgyrios Kyrtzidis if (Loc.isValid() && SM.isLocalSourceLocation(Loc))
2444df53da87SArgyrios Kyrtzidis associateDeclWithFile(D, ID);
2445d6522cfcSSebastian Redl
2446332aafedSBen Langmuir // Note declarations that should be deserialized eagerly so that we can add
2447332aafedSBen Langmuir // them to a record in the AST file later.
2448e6b7c28dSDavid Blaikie if (isRequiredDecl(D, Context, WritingModule))
2449332aafedSBen Langmuir EagerlyDeserializedDecls.push_back(ID);
2450d6522cfcSSebastian Redl }
2451d28ac5b9SRichard Smith
AddFunctionDefinition(const FunctionDecl * FD)2452290d8019SRichard Smith void ASTRecordWriter::AddFunctionDefinition(const FunctionDecl *FD) {
2453290d8019SRichard Smith // Switch case IDs are per function body.
2454290d8019SRichard Smith Writer->ClearSwitchCaseIDs();
2455d28ac5b9SRichard Smith
2456290d8019SRichard Smith assert(FD->doesThisDeclarationHaveABody());
2457b51cf113SRichard Smith bool ModulesCodegen = false;
245831b05692SLuboš Luňák if (!FD->isDependentContext()) {
245908267297SDavid Blaikie Optional<GVALinkage> Linkage;
246031b05692SLuboš Luňák if (Writer->WritingModule &&
24613cec39b9SChuanqi Xu Writer->WritingModule->isInterfaceOrPartition()) {
24623cec39b9SChuanqi Xu // When building a C++20 module interface unit or a partition unit, a
24633cec39b9SChuanqi Xu // strong definition in the module interface is provided by the
24643cec39b9SChuanqi Xu // compilation of that unit, not by its users. (Inline functions are still
24653cec39b9SChuanqi Xu // emitted in module users.)
246608267297SDavid Blaikie Linkage = Writer->Context->GetGVALinkageForFunction(FD);
246708267297SDavid Blaikie ModulesCodegen = *Linkage == GVA_StrongExternal;
246808267297SDavid Blaikie }
2469b198de67SDavid Blaikie if (Writer->Context->getLangOpts().ModulesCodegen ||
2470b198de67SDavid Blaikie (FD->hasAttr<DLLExportAttr>() &&
2471b198de67SDavid Blaikie Writer->Context->getLangOpts().BuildingPCHWithObjectFile)) {
2472b198de67SDavid Blaikie
247308267297SDavid Blaikie // Under -fmodules-codegen, codegen is performed for all non-internal,
2474729530f6SLuboš Luňák // non-always_inline functions, unless they are available elsewhere.
24751524e67fSDavid Blaikie if (!FD->hasAttr<AlwaysInlineAttr>()) {
247608267297SDavid Blaikie if (!Linkage)
247708267297SDavid Blaikie Linkage = Writer->Context->GetGVALinkageForFunction(FD);
2478729530f6SLuboš Luňák ModulesCodegen =
2479729530f6SLuboš Luňák *Linkage != GVA_Internal && *Linkage != GVA_AvailableExternally;
248008267297SDavid Blaikie }
2481b51cf113SRichard Smith }
24821524e67fSDavid Blaikie }
2483f63556d8SDavid Blaikie Record->push_back(ModulesCodegen);
2484f63556d8SDavid Blaikie if (ModulesCodegen)
2485e6b7c28dSDavid Blaikie Writer->ModularCodegenDecls.push_back(Writer->GetDeclRef(FD));
2486290d8019SRichard Smith if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
2487290d8019SRichard Smith Record->push_back(CD->getNumCtorInitializers());
2488290d8019SRichard Smith if (CD->getNumCtorInitializers())
2489aa165cf7SRichard Smith AddCXXCtorInitializers(
2490290d8019SRichard Smith llvm::makeArrayRef(CD->init_begin(), CD->init_end()));
2491290d8019SRichard Smith }
2492290d8019SRichard Smith AddStmt(FD->getBody());
2493d28ac5b9SRichard Smith }
2494