blob: 77e89522ebf85b186bd974b1ab31c47d47574d7a [file] [log] [blame]
Sebastian Redld6522cf2010-08-18 23:56:31 +00001//===--- ASTWriterDecl.cpp - Declaration Serialization --------------------===//
Chris Lattner7099dbc2009-04-27 06:16:06 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements serialization for Declarations.
11//
12//===----------------------------------------------------------------------===//
13
Sebastian Redl1914c6f2010-08-18 23:56:37 +000014#include "clang/Serialization/ASTWriter.h"
Sebastian Redlfa1f3702011-04-24 16:28:13 +000015#include "ASTCommon.h"
Chris Lattnerca025db2010-05-07 21:43:38 +000016#include "clang/AST/DeclCXX.h"
Argyrios Kyrtzidis3317d982010-10-20 16:22:56 +000017#include "clang/AST/DeclContextInternals.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000018#include "clang/AST/DeclTemplate.h"
19#include "clang/AST/DeclVisitor.h"
20#include "clang/AST/Expr.h"
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +000021#include "clang/Basic/SourceManager.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000022#include "clang/Serialization/ASTReader.h"
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +000023#include "llvm/ADT/Twine.h"
Chris Lattner7099dbc2009-04-27 06:16:06 +000024#include "llvm/Bitcode/BitstreamWriter.h"
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +000025#include "llvm/Support/ErrorHandling.h"
Chris Lattner7099dbc2009-04-27 06:16:06 +000026using namespace clang;
Sebastian Redlfa1f3702011-04-24 16:28:13 +000027using namespace serialization;
Chris Lattner7099dbc2009-04-27 06:16:06 +000028
29//===----------------------------------------------------------------------===//
30// Declaration serialization
31//===----------------------------------------------------------------------===//
32
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000033namespace clang {
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000034 class ASTDeclWriter : public DeclVisitor<ASTDeclWriter, void> {
Chris Lattner7099dbc2009-04-27 06:16:06 +000035
Sebastian Redl55c0ad52010-08-18 23:56:21 +000036 ASTWriter &Writer;
Chris Lattner7099dbc2009-04-27 06:16:06 +000037 ASTContext &Context;
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000038 typedef ASTWriter::RecordData RecordData;
39 RecordData &Record;
Chris Lattner7099dbc2009-04-27 06:16:06 +000040
41 public:
Sebastian Redl539c5062010-08-18 23:57:32 +000042 serialization::DeclCode Code;
Chris Lattner258172e2009-04-27 07:35:58 +000043 unsigned AbbrevToUse;
Chris Lattner7099dbc2009-04-27 06:16:06 +000044
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000045 ASTDeclWriter(ASTWriter &Writer, ASTContext &Context, RecordData &Record)
Chris Lattner258172e2009-04-27 07:35:58 +000046 : Writer(Writer), Context(Context), Record(Record) {
47 }
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000048
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +000049 void Visit(Decl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000050
51 void VisitDecl(Decl *D);
Nico Weber66220292016-03-02 17:28:48 +000052 void VisitPragmaCommentDecl(PragmaCommentDecl *D);
Nico Webercbbaeb12016-03-02 19:28:54 +000053 void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000054 void VisitTranslationUnitDecl(TranslationUnitDecl *D);
55 void VisitNamedDecl(NamedDecl *D);
Chris Lattnerc8e630e2011-02-17 07:39:24 +000056 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregore31bbd92010-02-21 18:22:14 +000057 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000058 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
59 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000060 void VisitTypeDecl(TypeDecl *D);
Douglas Gregor1f179062011-12-19 14:40:25 +000061 void VisitTypedefNameDecl(TypedefNameDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000062 void VisitTypedefDecl(TypedefDecl *D);
Richard Smithdda56e42011-04-15 14:24:37 +000063 void VisitTypeAliasDecl(TypeAliasDecl *D);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000064 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000065 void VisitTagDecl(TagDecl *D);
66 void VisitEnumDecl(EnumDecl *D);
67 void VisitRecordDecl(RecordDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000068 void VisitCXXRecordDecl(CXXRecordDecl *D);
69 void VisitClassTemplateSpecializationDecl(
70 ClassTemplateSpecializationDecl *D);
71 void VisitClassTemplatePartialSpecializationDecl(
72 ClassTemplatePartialSpecializationDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +000073 void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D);
74 void VisitVarTemplatePartialSpecializationDecl(
75 VarTemplatePartialSpecializationDecl *D);
Fariborz Jahanian3a039e32011-08-27 20:50:59 +000076 void VisitClassScopeFunctionSpecializationDecl(
77 ClassScopeFunctionSpecializationDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000078 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000079 void VisitValueDecl(ValueDecl *D);
80 void VisitEnumConstantDecl(EnumConstantDecl *D);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000081 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +000082 void VisitDeclaratorDecl(DeclaratorDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000083 void VisitFunctionDecl(FunctionDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000084 void VisitCXXMethodDecl(CXXMethodDecl *D);
85 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
86 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
87 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000088 void VisitFieldDecl(FieldDecl *D);
John McCall5e77d762013-04-16 07:28:30 +000089 void VisitMSPropertyDecl(MSPropertyDecl *D);
Francois Pichet783dd6e2010-11-21 06:08:52 +000090 void VisitIndirectFieldDecl(IndirectFieldDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000091 void VisitVarDecl(VarDecl *D);
92 void VisitImplicitParamDecl(ImplicitParamDecl *D);
93 void VisitParmVarDecl(ParmVarDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000094 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
95 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +000096 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000097 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +000098 void VisitVarTemplateDecl(VarTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +000099 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000100 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3f1b5d02011-05-05 21:57:07 +0000101 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000102 void VisitUsingDecl(UsingDecl *D);
103 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000104 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000105 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
Douglas Gregorba345522011-12-02 23:23:56 +0000106 void VisitImportDecl(ImportDecl *D);
Abramo Bagnarad7340582010-06-05 05:09:32 +0000107 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000108 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000109 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
110 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000111 void VisitBlockDecl(BlockDecl *D);
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +0000112 void VisitCapturedDecl(CapturedDecl *D);
Michael Han84324352013-02-22 17:15:32 +0000113 void VisitEmptyDecl(EmptyDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000114
Mike Stump11289f42009-09-09 15:08:12 +0000115 void VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset,
Chris Lattner7099dbc2009-04-27 06:16:06 +0000116 uint64_t VisibleOffset);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000117 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000118
119
Alexis Hunted053252010-05-30 07:21:58 +0000120 // FIXME: Put in the same order is DeclNodes.td?
Chris Lattner7099dbc2009-04-27 06:16:06 +0000121 void VisitObjCMethodDecl(ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000122 void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000123 void VisitObjCContainerDecl(ObjCContainerDecl *D);
124 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
125 void VisitObjCIvarDecl(ObjCIvarDecl *D);
126 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
127 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000128 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
129 void VisitObjCImplDecl(ObjCImplDecl *D);
130 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
131 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
132 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
133 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
134 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
Alexey Bataeva769e072013-03-22 06:34:35 +0000135 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000136 void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
Alexey Bataev4244be22016-02-11 05:35:55 +0000137 void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
Richard Smithd28ac5b2014-03-22 23:33:22 +0000138
Richard Smithe37e9f42016-03-25 01:17:43 +0000139 void AddLocalOffset(uint64_t LocalOffset) {
140 uint64_t Offset = Writer.Stream.GetCurrentBitNo();
141 assert(LocalOffset < Offset && "invalid offset");
142 Record.push_back(LocalOffset ? Offset - LocalOffset : 0);
143 }
144
Douglas Gregor85f3f952015-07-07 03:57:15 +0000145 /// Add an Objective-C type parameter list to the given record.
146 void AddObjCTypeParamList(ObjCTypeParamList *typeParams) {
147 // Empty type parameter list.
148 if (!typeParams) {
149 Record.push_back(0);
150 return;
151 }
152
153 Record.push_back(typeParams->size());
154 for (auto typeParam : *typeParams) {
155 Writer.AddDeclRef(typeParam, Record);
156 }
157 Writer.AddSourceLocation(typeParams->getLAngleLoc(), Record);
158 Writer.AddSourceLocation(typeParams->getRAngleLoc(), Record);
159 }
160
Richard Smithd28ac5b2014-03-22 23:33:22 +0000161 void AddFunctionDefinition(const FunctionDecl *FD) {
162 assert(FD->doesThisDeclarationHaveABody());
Richard Smithc2bb8182015-03-24 06:36:48 +0000163 if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
164 Record.push_back(CD->NumCtorInitializers);
165 if (CD->NumCtorInitializers)
166 Writer.AddCXXCtorInitializersRef(
167 llvm::makeArrayRef(CD->init_begin(), CD->init_end()), Record);
168 }
Richard Smithd28ac5b2014-03-22 23:33:22 +0000169 Writer.AddStmt(FD->getBody());
170 }
Richard Smith509fc852015-02-27 23:05:10 +0000171
Richard Smithd8a83712015-08-22 01:47:18 +0000172 /// Add to the record the first declaration from each module file that
173 /// provides a declaration of D. The intent is to provide a sufficient
174 /// set such that reloading this set will load all current redeclarations.
175 void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) {
176 llvm::MapVector<ModuleFile*, const Decl*> Firsts;
177 // FIXME: We can skip entries that we know are implied by others.
Richard Smith5f55d932015-08-27 21:38:25 +0000178 for (const Decl *R = D->getMostRecentDecl(); R; R = R->getPreviousDecl()) {
179 if (R->isFromASTFile())
Richard Smithd8a83712015-08-22 01:47:18 +0000180 Firsts[Writer.Chain->getOwningModuleFile(R)] = R;
Richard Smith5f55d932015-08-27 21:38:25 +0000181 else if (IncludeLocal)
182 Firsts[nullptr] = R;
183 }
Richard Smithd8a83712015-08-22 01:47:18 +0000184 for (const auto &F : Firsts)
185 Writer.AddDeclRef(F.second, Record);
186 }
187
Richard Smith509fc852015-02-27 23:05:10 +0000188 /// Get the specialization decl from an entry in the specialization list.
189 template <typename EntryType>
190 typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType *
191 getSpecializationDecl(EntryType &T) {
192 return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T);
193 }
194
195 /// Get the list of partial specializations from a template's common ptr.
196 template<typename T>
197 decltype(T::PartialSpecializations) &getPartialSpecializations(T *Common) {
198 return Common->PartialSpecializations;
199 }
200 ArrayRef<Decl> getPartialSpecializations(FunctionTemplateDecl::Common *) {
201 return None;
202 }
203
Richard Smith8ab0cfd2016-02-24 21:59:10 +0000204 template<typename DeclTy>
205 void AddTemplateSpecializations(DeclTy *D) {
Richard Smith509fc852015-02-27 23:05:10 +0000206 auto *Common = D->getCommonPtr();
207
208 // If we have any lazy specializations, and the external AST source is
209 // our chained AST reader, we can just write out the DeclIDs. Otherwise,
210 // we need to resolve them to actual declarations.
211 if (Writer.Chain != Writer.Context->getExternalSource() &&
212 Common->LazySpecializations) {
213 D->LoadLazySpecializations();
214 assert(!Common->LazySpecializations);
215 }
216
Richard Smith509fc852015-02-27 23:05:10 +0000217 ArrayRef<DeclID> LazySpecializations;
218 if (auto *LS = Common->LazySpecializations)
Craig Topper55e39a72015-09-29 04:53:28 +0000219 LazySpecializations = llvm::makeArrayRef(LS + 1, LS[0]);
Richard Smith509fc852015-02-27 23:05:10 +0000220
Richard Smithd8a83712015-08-22 01:47:18 +0000221 // Add a slot to the record for the number of specializations.
222 unsigned I = Record.size();
223 Record.push_back(0);
224
Richard Smith8ab0cfd2016-02-24 21:59:10 +0000225 // AddFirstDeclFromEachModule might trigger deserialization, invalidating
226 // *Specializations iterators.
227 llvm::SmallVector<const Decl*, 16> Specs;
228 for (auto &Entry : Common->Specializations)
229 Specs.push_back(getSpecializationDecl(Entry));
230 for (auto &Entry : getPartialSpecializations(Common))
231 Specs.push_back(getSpecializationDecl(Entry));
232
233 for (auto *D : Specs) {
Richard Smith509fc852015-02-27 23:05:10 +0000234 assert(D->isCanonicalDecl() && "non-canonical decl in set");
Richard Smithd8a83712015-08-22 01:47:18 +0000235 AddFirstDeclFromEachModule(D, /*IncludeLocal*/true);
Richard Smith509fc852015-02-27 23:05:10 +0000236 }
Benjamin Kramerf367dd92015-06-12 15:31:50 +0000237 Record.append(LazySpecializations.begin(), LazySpecializations.end());
Richard Smithd8a83712015-08-22 01:47:18 +0000238
239 // Update the size entry we added earlier.
240 Record[I] = Record.size() - I - 1;
241 }
242
243 /// Ensure that this template specialization is associated with the specified
244 /// template on reload.
245 void RegisterTemplateSpecialization(const Decl *Template,
246 const Decl *Specialization) {
247 Template = Template->getCanonicalDecl();
248
249 // If the canonical template is local, we'll write out this specialization
250 // when we emit it.
251 // FIXME: We can do the same thing if there is any local declaration of
252 // the template, to avoid emitting an update record.
253 if (!Template->isFromASTFile())
254 return;
255
256 // We only need to associate the first local declaration of the
257 // specialization. The other declarations will get pulled in by it.
258 if (Writer.getFirstLocalDecl(Specialization) != Specialization)
259 return;
260
261 Writer.DeclUpdates[Template].push_back(ASTWriter::DeclUpdate(
262 UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION, Specialization));
Richard Smith509fc852015-02-27 23:05:10 +0000263 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000264 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000265}
Chris Lattner7099dbc2009-04-27 06:16:06 +0000266
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000267void ASTDeclWriter::Visit(Decl *D) {
268 DeclVisitor<ASTDeclWriter>::Visit(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000269
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000270 // Source locations require array (variable-length) abbreviations. The
271 // abbreviation infrastructure requires that arrays are encoded last, so
272 // we handle it here in the case of those classes derived from DeclaratorDecl
Nick Lewycky4b81fc872015-10-18 20:32:12 +0000273 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000274 Writer.AddTypeSourceInfo(DD->getTypeSourceInfo(), Record);
275 }
276
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000277 // Handle FunctionDecl's body here and write it after all other Stmts/Exprs
278 // have been written. We want it last because we will not read it back when
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000279 // retrieving it from the AST, we'll just lazily set the offset.
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000280 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
Alexis Hunt4a8ea102011-05-06 20:44:56 +0000281 Record.push_back(FD->doesThisDeclarationHaveABody());
282 if (FD->doesThisDeclarationHaveABody())
Richard Smithc2bb8182015-03-24 06:36:48 +0000283 AddFunctionDefinition(FD);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000284 }
285}
286
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000287void ASTDeclWriter::VisitDecl(Decl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000288 Writer.AddDeclRef(cast_or_null<Decl>(D->getDeclContext()), Record);
Richard Smith8aed4222015-12-11 22:41:00 +0000289 if (D->getDeclContext() != D->getLexicalDeclContext())
290 Writer.AddDeclRef(cast_or_null<Decl>(D->getLexicalDeclContext()), Record);
291 else
292 Record.push_back(0);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000293 Record.push_back(D->isInvalidDecl());
294 Record.push_back(D->hasAttrs());
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000295 if (D->hasAttrs())
Craig Topper8c2a2a02014-08-30 16:55:39 +0000296 Writer.WriteAttributes(llvm::makeArrayRef(D->getAttrs().begin(),
297 D->getAttrs().size()), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000298 Record.push_back(D->isImplicit());
Douglas Gregorebada0772010-06-17 23:14:26 +0000299 Record.push_back(D->isUsed(false));
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +0000300 Record.push_back(D->isReferenced());
Douglas Gregor781f7132012-01-06 16:59:53 +0000301 Record.push_back(D->isTopLevelDeclInObjCContainer());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000302 Record.push_back(D->getAccess());
Douglas Gregor781f7132012-01-06 16:59:53 +0000303 Record.push_back(D->isModulePrivate());
Douglas Gregora28bcdd2011-12-01 02:07:58 +0000304 Record.push_back(Writer.inferSubmoduleIDFromLocation(D->getLocation()));
Richard Smithc264d352014-03-23 02:30:01 +0000305
306 // If this declaration injected a name into a context different from its
307 // lexical context, and that context is an imported namespace, we need to
308 // update its visible declarations to include this name.
309 //
310 // This happens when we instantiate a class with a friend declaration or a
311 // function with a local extern declaration, for instance.
Richard Smith5fc18a92015-07-12 23:43:21 +0000312 //
313 // FIXME: Can we handle this in AddedVisibleDecl instead?
Richard Smithc264d352014-03-23 02:30:01 +0000314 if (D->isOutOfLine()) {
Richard Smithe3a97022014-03-23 20:41:56 +0000315 auto *DC = D->getDeclContext();
316 while (auto *NS = dyn_cast<NamespaceDecl>(DC->getRedeclContext())) {
317 if (!NS->isFromASTFile())
318 break;
Chandler Carruth8a3d24d2015-03-26 04:27:10 +0000319 Writer.UpdatedDeclContexts.insert(NS->getPrimaryContext());
Richard Smithe3a97022014-03-23 20:41:56 +0000320 if (!NS->isInlineNamespace())
321 break;
322 DC = NS->getParent();
323 }
Richard Smithc264d352014-03-23 02:30:01 +0000324 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000325}
326
Nico Weber66220292016-03-02 17:28:48 +0000327void ASTDeclWriter::VisitPragmaCommentDecl(PragmaCommentDecl *D) {
328 StringRef Arg = D->getArg();
329 Record.push_back(Arg.size());
330 VisitDecl(D);
331 Writer.AddSourceLocation(D->getLocStart(), Record);
332 Record.push_back(D->getCommentKind());
333 Writer.AddString(Arg, Record);
334 Code = serialization::DECL_PRAGMA_COMMENT;
335}
336
Nico Webercbbaeb12016-03-02 19:28:54 +0000337void ASTDeclWriter::VisitPragmaDetectMismatchDecl(
338 PragmaDetectMismatchDecl *D) {
339 StringRef Name = D->getName();
340 StringRef Value = D->getValue();
341 Record.push_back(Name.size() + 1 + Value.size());
342 VisitDecl(D);
343 Writer.AddSourceLocation(D->getLocStart(), Record);
344 Writer.AddString(Name, Record);
345 Writer.AddString(Value, Record);
346 Code = serialization::DECL_PRAGMA_DETECT_MISMATCH;
347}
348
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000349void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
Douglas Gregordab42432011-08-12 00:15:20 +0000350 llvm_unreachable("Translation units aren't directly serialized");
Chris Lattner7099dbc2009-04-27 06:16:06 +0000351}
352
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000353void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000354 VisitDecl(D);
355 Writer.AddDeclarationName(D->getDeclName(), Record);
Richard Smith2b560572015-02-07 03:11:11 +0000356 Record.push_back(needsAnonymousDeclarationNumber(D)
357 ? Writer.getAnonymousDeclarationNumber(D)
358 : 0);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000359}
360
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000361void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000362 VisitNamedDecl(D);
Abramo Bagnarab3185b02011-03-06 15:48:19 +0000363 Writer.AddSourceLocation(D->getLocStart(), Record);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000364 Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000365}
366
Douglas Gregor1f179062011-12-19 14:40:25 +0000367void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) {
Douglas Gregor05f10352011-12-17 23:38:30 +0000368 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000369 VisitTypeDecl(D);
Enea Zaffanellaa86d88c2013-06-20 12:46:19 +0000370 Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record);
371 Record.push_back(D->isModed());
372 if (D->isModed())
373 Writer.AddTypeRef(D->getUnderlyingType(), Record);
Douglas Gregor1f179062011-12-19 14:40:25 +0000374}
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000375
Douglas Gregor1f179062011-12-19 14:40:25 +0000376void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) {
377 VisitTypedefNameDecl(D);
Richard Smith8aed4222015-12-11 22:41:00 +0000378 if (D->getDeclContext() == D->getLexicalDeclContext() &&
379 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000380 !D->isImplicit() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000381 D->getFirstDecl() == D->getMostRecentDecl() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000382 !D->isInvalidDecl() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000383 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000384 !D->isModulePrivate() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000385 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000386 D->getDeclName().getNameKind() == DeclarationName::Identifier)
387 AbbrevToUse = Writer.getDeclTypedefAbbrev();
388
Sebastian Redl539c5062010-08-18 23:57:32 +0000389 Code = serialization::DECL_TYPEDEF;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000390}
391
Richard Smithdda56e42011-04-15 14:24:37 +0000392void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) {
Douglas Gregor1f179062011-12-19 14:40:25 +0000393 VisitTypedefNameDecl(D);
Richard Smith43ccec8e2014-08-26 03:52:16 +0000394 Writer.AddDeclRef(D->getDescribedAliasTemplate(), Record);
Richard Smithdda56e42011-04-15 14:24:37 +0000395 Code = serialization::DECL_TYPEALIAS;
396}
397
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000398void ASTDeclWriter::VisitTagDecl(TagDecl *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000399 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000400 VisitTypeDecl(D);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000401 Record.push_back(D->getIdentifierNamespace());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000402 Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding
Richard Smith2c381642014-08-27 23:11:59 +0000403 if (!isa<CXXRecordDecl>(D))
404 Record.push_back(D->isCompleteDefinition());
Douglas Gregor5089c762010-02-12 17:40:34 +0000405 Record.push_back(D->isEmbeddedInDeclarator());
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +0000406 Record.push_back(D->isFreeStanding());
David Blaikiea8d23ce2013-07-14 01:07:41 +0000407 Record.push_back(D->isCompleteDefinitionRequired());
Argyrios Kyrtzidis664b6902009-07-14 03:18:02 +0000408 Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Richard Smith70d58502014-08-30 00:04:23 +0000409
410 if (D->hasExtInfo()) {
411 Record.push_back(1);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000412 Writer.AddQualifierInfo(*D->getExtInfo(), Record);
Richard Smith70d58502014-08-30 00:04:23 +0000413 } else if (auto *TD = D->getTypedefNameForAnonDecl()) {
414 Record.push_back(2);
415 Writer.AddDeclRef(TD, Record);
416 Writer.AddIdentifierRef(TD->getDeclName().getAsIdentifierInfo(), Record);
Richard Smith70d58502014-08-30 00:04:23 +0000417 } else {
418 Record.push_back(0);
419 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000420}
421
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000422void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000423 VisitTagDecl(D);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000424 Writer.AddTypeSourceInfo(D->getIntegerTypeSourceInfo(), Record);
425 if (!D->getIntegerTypeSourceInfo())
426 Writer.AddTypeRef(D->getIntegerType(), Record);
John McCall56774992009-12-09 09:09:27 +0000427 Writer.AddTypeRef(D->getPromotionType(), Record);
John McCall9aa35be2010-05-06 08:49:23 +0000428 Record.push_back(D->getNumPositiveBits());
429 Record.push_back(D->getNumNegativeBits());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000430 Record.push_back(D->isScoped());
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000431 Record.push_back(D->isScopedUsingClassTag());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000432 Record.push_back(D->isFixed());
Richard Smith4b38ded2012-03-14 23:13:10 +0000433 if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
434 Writer.AddDeclRef(MemberInfo->getInstantiatedFrom(), Record);
435 Record.push_back(MemberInfo->getTemplateSpecializationKind());
436 Writer.AddSourceLocation(MemberInfo->getPointOfInstantiation(), Record);
437 } else {
Craig Toppera13603a2014-05-22 05:54:18 +0000438 Writer.AddDeclRef(nullptr, Record);
Richard Smith4b38ded2012-03-14 23:13:10 +0000439 }
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000440
Richard Smith8aed4222015-12-11 22:41:00 +0000441 if (D->getDeclContext() == D->getLexicalDeclContext() &&
442 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000443 !D->isImplicit() &&
444 !D->isUsed(false) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000445 !D->hasExtInfo() &&
Richard Smith70d58502014-08-30 00:04:23 +0000446 !D->getTypedefNameForAnonDecl() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000447 D->getFirstDecl() == D->getMostRecentDecl() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000448 !D->isInvalidDecl() &&
449 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000450 !D->isTopLevelDeclInObjCContainer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000451 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000452 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000453 !CXXRecordDecl::classofKind(D->getKind()) &&
454 !D->getIntegerTypeSourceInfo() &&
Argyrios Kyrtzidisca370b0d2013-03-18 22:23:49 +0000455 !D->getMemberSpecializationInfo() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000456 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000457 D->getDeclName().getNameKind() == DeclarationName::Identifier)
458 AbbrevToUse = Writer.getDeclEnumAbbrev();
459
Sebastian Redl539c5062010-08-18 23:57:32 +0000460 Code = serialization::DECL_ENUM;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000461}
462
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000463void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000464 VisitTagDecl(D);
465 Record.push_back(D->hasFlexibleArrayMember());
466 Record.push_back(D->isAnonymousStructOrUnion());
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000467 Record.push_back(D->hasObjectMember());
Fariborz Jahanian78652202013-01-25 23:57:05 +0000468 Record.push_back(D->hasVolatileMember());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000469
Richard Smith8aed4222015-12-11 22:41:00 +0000470 if (D->getDeclContext() == D->getLexicalDeclContext() &&
471 !D->hasAttrs() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000472 !D->isImplicit() &&
473 !D->isUsed(false) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000474 !D->hasExtInfo() &&
Richard Smith70d58502014-08-30 00:04:23 +0000475 !D->getTypedefNameForAnonDecl() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000476 D->getFirstDecl() == D->getMostRecentDecl() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000477 !D->isInvalidDecl() &&
478 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000479 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000480 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000481 !D->isModulePrivate() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000482 !CXXRecordDecl::classofKind(D->getKind()) &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000483 !needsAnonymousDeclarationNumber(D) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000484 D->getDeclName().getNameKind() == DeclarationName::Identifier)
Douglas Gregor03412ba2011-06-03 02:27:19 +0000485 AbbrevToUse = Writer.getDeclRecordAbbrev();
486
Sebastian Redl539c5062010-08-18 23:57:32 +0000487 Code = serialization::DECL_RECORD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000488}
489
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000490void ASTDeclWriter::VisitValueDecl(ValueDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000491 VisitNamedDecl(D);
492 Writer.AddTypeRef(D->getType(), Record);
493}
494
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000495void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000496 VisitValueDecl(D);
497 Record.push_back(D->getInitExpr()? 1 : 0);
498 if (D->getInitExpr())
499 Writer.AddStmt(D->getInitExpr());
500 Writer.AddAPSInt(D->getInitVal(), Record);
Douglas Gregor03412ba2011-06-03 02:27:19 +0000501
Sebastian Redl539c5062010-08-18 23:57:32 +0000502 Code = serialization::DECL_ENUM_CONSTANT;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000503}
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000504
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000505void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000506 VisitValueDecl(D);
Abramo Bagnaradff19302011-03-08 08:55:46 +0000507 Writer.AddSourceLocation(D->getInnerLocStart(), Record);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000508 Record.push_back(D->hasExtInfo());
509 if (D->hasExtInfo())
510 Writer.AddQualifierInfo(*D->getExtInfo(), Record);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000511}
Chris Lattner7099dbc2009-04-27 06:16:06 +0000512
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000513void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000514 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000515 VisitDeclaratorDecl(D);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000516 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000517 Record.push_back(D->getIdentifierNamespace());
Douglas Gregorb2585692012-01-04 17:13:46 +0000518
519 // FunctionDecl's body is handled last at ASTWriterDecl::Visit,
520 // after everything else is written.
521
Richard Smith72625c22015-02-06 23:20:21 +0000522 Record.push_back((int)D->SClass); // FIXME: stable encoding
Douglas Gregorb2585692012-01-04 17:13:46 +0000523 Record.push_back(D->IsInline);
Richard Smith72625c22015-02-06 23:20:21 +0000524 Record.push_back(D->IsInlineSpecified);
525 Record.push_back(D->IsVirtualAsWritten);
526 Record.push_back(D->IsPure);
527 Record.push_back(D->HasInheritedPrototype);
528 Record.push_back(D->HasWrittenPrototype);
529 Record.push_back(D->IsDeleted);
530 Record.push_back(D->IsTrivial);
531 Record.push_back(D->IsDefaulted);
532 Record.push_back(D->IsExplicitlyDefaulted);
533 Record.push_back(D->HasImplicitReturnZero);
534 Record.push_back(D->IsConstexpr);
Argyrios Kyrtzidis1eb71a12012-12-06 18:59:10 +0000535 Record.push_back(D->HasSkippedBody);
Richard Smith72625c22015-02-06 23:20:21 +0000536 Record.push_back(D->IsLateTemplateParsed);
Rafael Espindola3ae00052013-05-13 00:12:11 +0000537 Record.push_back(D->getLinkageInternal());
Douglas Gregorb2585692012-01-04 17:13:46 +0000538 Writer.AddSourceLocation(D->getLocEnd(), Record);
539
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000540 Record.push_back(D->getTemplatedKind());
541 switch (D->getTemplatedKind()) {
542 case FunctionDecl::TK_NonTemplate:
543 break;
544 case FunctionDecl::TK_FunctionTemplate:
545 Writer.AddDeclRef(D->getDescribedFunctionTemplate(), Record);
546 break;
547 case FunctionDecl::TK_MemberSpecialization: {
548 MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo();
549 Writer.AddDeclRef(MemberInfo->getInstantiatedFrom(), Record);
550 Record.push_back(MemberInfo->getTemplateSpecializationKind());
551 Writer.AddSourceLocation(MemberInfo->getPointOfInstantiation(), Record);
552 break;
553 }
554 case FunctionDecl::TK_FunctionTemplateSpecialization: {
555 FunctionTemplateSpecializationInfo *
556 FTSInfo = D->getTemplateSpecializationInfo();
Richard Smithd8a83712015-08-22 01:47:18 +0000557
558 RegisterTemplateSpecialization(FTSInfo->getTemplate(), D);
559
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000560 Writer.AddDeclRef(FTSInfo->getTemplate(), Record);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000561 Record.push_back(FTSInfo->getTemplateSpecializationKind());
562
563 // Template arguments.
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000564 Writer.AddTemplateArgumentList(FTSInfo->TemplateArguments, Record);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000565
566 // Template args as written.
Craig Toppera13603a2014-05-22 05:54:18 +0000567 Record.push_back(FTSInfo->TemplateArgumentsAsWritten != nullptr);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000568 if (FTSInfo->TemplateArgumentsAsWritten) {
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000569 Record.push_back(FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs);
570 for (int i=0, e = FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs;
571 i!=e; ++i)
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000572 Writer.AddTemplateArgumentLoc((*FTSInfo->TemplateArgumentsAsWritten)[i],
573 Record);
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000574 Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->LAngleLoc,
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000575 Record);
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000576 Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->RAngleLoc,
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000577 Record);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000578 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000579
580 Writer.AddSourceLocation(FTSInfo->getPointOfInstantiation(), Record);
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000581
582 if (D->isCanonicalDecl()) {
583 // Write the template that contains the specializations set. We will
584 // add a FunctionTemplateSpecializationInfo to it when reading.
585 Writer.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl(), Record);
586 }
Argyrios Kyrtzidisdc9ca0a2010-06-25 16:24:51 +0000587 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000588 }
589 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
590 DependentFunctionTemplateSpecializationInfo *
591 DFTSInfo = D->getDependentSpecializationInfo();
592
593 // Templates.
594 Record.push_back(DFTSInfo->getNumTemplates());
595 for (int i=0, e = DFTSInfo->getNumTemplates(); i != e; ++i)
596 Writer.AddDeclRef(DFTSInfo->getTemplate(i), Record);
597
598 // Templates args.
599 Record.push_back(DFTSInfo->getNumTemplateArgs());
600 for (int i=0, e = DFTSInfo->getNumTemplateArgs(); i != e; ++i)
601 Writer.AddTemplateArgumentLoc(DFTSInfo->getTemplateArg(i), Record);
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000602 Writer.AddSourceLocation(DFTSInfo->getLAngleLoc(), Record);
603 Writer.AddSourceLocation(DFTSInfo->getRAngleLoc(), Record);
Argyrios Kyrtzidisdc9ca0a2010-06-25 16:24:51 +0000604 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000605 }
606 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000607
Chris Lattner7099dbc2009-04-27 06:16:06 +0000608 Record.push_back(D->param_size());
Aaron Ballmanf6bf62e2014-03-07 15:12:56 +0000609 for (auto P : D->params())
610 Writer.AddDeclRef(P, Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000611 Code = serialization::DECL_FUNCTION;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000612}
613
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000614void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000615 VisitNamedDecl(D);
616 // FIXME: convert to LazyStmtPtr?
Mike Stump11289f42009-09-09 15:08:12 +0000617 // Unlike C/C++, method bodies will never be in header files.
Craig Toppera13603a2014-05-22 05:54:18 +0000618 bool HasBodyStuff = D->getBody() != nullptr ||
619 D->getSelfDecl() != nullptr || D->getCmdDecl() != nullptr;
Argyrios Kyrtzidisa8607772010-08-09 10:54:37 +0000620 Record.push_back(HasBodyStuff);
621 if (HasBodyStuff) {
Argyrios Kyrtzidisddcd1322009-06-30 02:35:26 +0000622 Writer.AddStmt(D->getBody());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000623 Writer.AddDeclRef(D->getSelfDecl(), Record);
624 Writer.AddDeclRef(D->getCmdDecl(), Record);
625 }
626 Record.push_back(D->isInstanceMethod());
627 Record.push_back(D->isVariadic());
Jordan Rosed01e83a2012-10-10 16:42:25 +0000628 Record.push_back(D->isPropertyAccessor());
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000629 Record.push_back(D->isDefined());
Argyrios Kyrtzidis08f96a92012-05-09 16:12:57 +0000630 Record.push_back(D->IsOverriding);
Argyrios Kyrtzidis1eb71a12012-12-06 18:59:10 +0000631 Record.push_back(D->HasSkippedBody);
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000632
633 Record.push_back(D->IsRedeclaration);
634 Record.push_back(D->HasRedeclaration);
635 if (D->HasRedeclaration) {
636 assert(Context.getObjCMethodRedeclaration(D));
637 Writer.AddDeclRef(Context.getObjCMethodRedeclaration(D), Record);
638 }
639
Chris Lattner7099dbc2009-04-27 06:16:06 +0000640 // FIXME: stable encoding for @required/@optional
Mike Stump11289f42009-09-09 15:08:12 +0000641 Record.push_back(D->getImplementationControl());
Douglas Gregor813a0662015-06-19 18:14:38 +0000642 // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway/nullability
Mike Stump11289f42009-09-09 15:08:12 +0000643 Record.push_back(D->getObjCDeclQualifier());
Douglas Gregor33823722011-06-11 01:09:30 +0000644 Record.push_back(D->hasRelatedResultType());
Alp Toker314cc812014-01-25 16:55:45 +0000645 Writer.AddTypeRef(D->getReturnType(), Record);
646 Writer.AddTypeSourceInfo(D->getReturnTypeSourceInfo(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000647 Writer.AddSourceLocation(D->getLocEnd(), Record);
648 Record.push_back(D->param_size());
Aaron Ballman43b68be2014-03-07 17:50:17 +0000649 for (const auto *P : D->params())
650 Writer.AddDeclRef(P, Record);
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000651
652 Record.push_back(D->SelLocsKind);
653 unsigned NumStoredSelLocs = D->getNumStoredSelLocs();
654 SourceLocation *SelLocs = D->getStoredSelLocs();
655 Record.push_back(NumStoredSelLocs);
656 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
657 Writer.AddSourceLocation(SelLocs[i], Record);
658
Sebastian Redl539c5062010-08-18 23:57:32 +0000659 Code = serialization::DECL_OBJC_METHOD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000660}
661
Douglas Gregor85f3f952015-07-07 03:57:15 +0000662void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
663 VisitTypedefNameDecl(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +0000664 Record.push_back(D->Variance);
Douglas Gregore83b9562015-07-07 03:57:53 +0000665 Record.push_back(D->Index);
Douglas Gregor1ac1b632015-07-07 03:58:54 +0000666 Writer.AddSourceLocation(D->VarianceLoc, Record);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000667 Writer.AddSourceLocation(D->ColonLoc, Record);
668
669 Code = serialization::DECL_OBJC_TYPE_PARAM;
670}
671
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000672void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000673 VisitNamedDecl(D);
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +0000674 Writer.AddSourceLocation(D->getAtStartLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +0000675 Writer.AddSourceRange(D->getAtEndRange(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000676 // Abstract class (no need to define a stable serialization::DECL code).
Chris Lattner7099dbc2009-04-27 06:16:06 +0000677}
678
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000679void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
Douglas Gregor66b310c2011-12-15 18:03:09 +0000680 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000681 VisitObjCContainerDecl(D);
682 Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000683 AddObjCTypeParamList(D->TypeParamList);
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000684
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000685 Record.push_back(D->isThisDeclarationADefinition());
686 if (D->isThisDeclarationADefinition()) {
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000687 // Write the DefinitionData
688 ObjCInterfaceDecl::DefinitionData &Data = D->data();
689
Douglas Gregore9d95f12015-07-07 03:57:35 +0000690 Writer.AddTypeSourceInfo(D->getSuperClassTInfo(), Record);
Douglas Gregor16408322011-12-15 22:34:59 +0000691 Writer.AddSourceLocation(D->getEndOfDefinitionLoc(), Record);
Argyrios Kyrtzidis9ed9e5f2013-12-03 21:11:30 +0000692 Record.push_back(Data.HasDesignatedInitializers);
Douglas Gregor16408322011-12-15 22:34:59 +0000693
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000694 // Write out the protocols that are directly referenced by the @interface.
695 Record.push_back(Data.ReferencedProtocols.size());
Aaron Ballmana49c5062014-03-13 20:29:09 +0000696 for (const auto *P : D->protocols())
697 Writer.AddDeclRef(P, Record);
Aaron Ballmane9378882014-03-13 20:34:24 +0000698 for (const auto &PL : D->protocol_locs())
699 Writer.AddSourceLocation(PL, Record);
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000700
701 // Write out the protocols that are transitively referenced.
702 Record.push_back(Data.AllReferencedProtocols.size());
703 for (ObjCList<ObjCProtocolDecl>::iterator
704 P = Data.AllReferencedProtocols.begin(),
705 PEnd = Data.AllReferencedProtocols.end();
706 P != PEnd; ++P)
707 Writer.AddDeclRef(*P, Record);
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000708
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000709
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000710 if (ObjCCategoryDecl *Cat = D->getCategoryListRaw()) {
Douglas Gregor404cdde2012-01-27 01:47:08 +0000711 // Ensure that we write out the set of categories for this class.
712 Writer.ObjCClassesWithCategories.insert(D);
713
714 // Make sure that the categories get serialized.
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000715 for (; Cat; Cat = Cat->getNextClassCategoryRaw())
Douglas Gregor404cdde2012-01-27 01:47:08 +0000716 (void)Writer.GetDeclRef(Cat);
717 }
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000718 }
719
Sebastian Redl539c5062010-08-18 23:57:32 +0000720 Code = serialization::DECL_OBJC_INTERFACE;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000721}
722
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000723void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000724 VisitFieldDecl(D);
725 // FIXME: stable encoding for @public/@private/@protected/@package
Mike Stump11289f42009-09-09 15:08:12 +0000726 Record.push_back(D->getAccessControl());
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000727 Record.push_back(D->getSynthesize());
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000728
Richard Smith8aed4222015-12-11 22:41:00 +0000729 if (D->getDeclContext() == D->getLexicalDeclContext() &&
730 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000731 !D->isImplicit() &&
732 !D->isUsed(false) &&
733 !D->isInvalidDecl() &&
734 !D->isReferenced() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000735 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000736 !D->getBitWidth() &&
737 !D->hasExtInfo() &&
738 D->getDeclName())
739 AbbrevToUse = Writer.getDeclObjCIvarAbbrev();
740
Sebastian Redl539c5062010-08-18 23:57:32 +0000741 Code = serialization::DECL_OBJC_IVAR;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000742}
743
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000744void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
Douglas Gregora715bff2012-01-01 19:51:50 +0000745 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000746 VisitObjCContainerDecl(D);
Douglas Gregore6e48b12012-01-01 19:29:29 +0000747
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000748 Record.push_back(D->isThisDeclarationADefinition());
749 if (D->isThisDeclarationADefinition()) {
Douglas Gregore6e48b12012-01-01 19:29:29 +0000750 Record.push_back(D->protocol_size());
Aaron Ballman0f6e64d2014-03-13 22:58:06 +0000751 for (const auto *I : D->protocols())
752 Writer.AddDeclRef(I, Record);
Aaron Ballmana964ec12014-03-14 12:38:50 +0000753 for (const auto &PL : D->protocol_locs())
754 Writer.AddSourceLocation(PL, Record);
Douglas Gregore6e48b12012-01-01 19:29:29 +0000755 }
756
Sebastian Redl539c5062010-08-18 23:57:32 +0000757 Code = serialization::DECL_OBJC_PROTOCOL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000758}
759
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000760void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000761 VisitFieldDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000762 Code = serialization::DECL_OBJC_AT_DEFS_FIELD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000763}
764
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000765void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000766 VisitObjCContainerDecl(D);
Douglas Gregor404cdde2012-01-27 01:47:08 +0000767 Writer.AddSourceLocation(D->getCategoryNameLoc(), Record);
Fariborz Jahaniana7765fe2012-02-20 20:09:20 +0000768 Writer.AddSourceLocation(D->getIvarLBraceLoc(), Record);
769 Writer.AddSourceLocation(D->getIvarRBraceLoc(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000770 Writer.AddDeclRef(D->getClassInterface(), Record);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000771 AddObjCTypeParamList(D->TypeParamList);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000772 Record.push_back(D->protocol_size());
Aaron Ballman19a41762014-03-14 12:55:57 +0000773 for (const auto *I : D->protocols())
774 Writer.AddDeclRef(I, Record);
Aaron Ballmana73c8572014-03-14 13:03:32 +0000775 for (const auto &PL : D->protocol_locs())
776 Writer.AddSourceLocation(PL, Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000777 Code = serialization::DECL_OBJC_CATEGORY;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000778}
779
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000780void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000781 VisitNamedDecl(D);
782 Writer.AddDeclRef(D->getClassInterface(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000783 Code = serialization::DECL_OBJC_COMPATIBLE_ALIAS;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000784}
785
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000786void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000787 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000788 Writer.AddSourceLocation(D->getAtLoc(), Record);
Fariborz Jahanian86c2f5c2012-02-29 22:18:55 +0000789 Writer.AddSourceLocation(D->getLParenLoc(), Record);
Douglas Gregor813a0662015-06-19 18:14:38 +0000790 Writer.AddTypeRef(D->getType(), Record);
John McCall339bb662010-06-04 20:50:08 +0000791 Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000792 // FIXME: stable encoding
793 Record.push_back((unsigned)D->getPropertyAttributes());
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000794 Record.push_back((unsigned)D->getPropertyAttributesAsWritten());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000795 // FIXME: stable encoding
796 Record.push_back((unsigned)D->getPropertyImplementation());
797 Writer.AddDeclarationName(D->getGetterName(), Record);
798 Writer.AddDeclarationName(D->getSetterName(), Record);
799 Writer.AddDeclRef(D->getGetterMethodDecl(), Record);
800 Writer.AddDeclRef(D->getSetterMethodDecl(), Record);
801 Writer.AddDeclRef(D->getPropertyIvarDecl(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000802 Code = serialization::DECL_OBJC_PROPERTY;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000803}
804
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000805void ASTDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000806 VisitObjCContainerDecl(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000807 Writer.AddDeclRef(D->getClassInterface(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000808 // Abstract class (no need to define a stable serialization::DECL code).
Chris Lattner7099dbc2009-04-27 06:16:06 +0000809}
810
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000811void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000812 VisitObjCImplDecl(D);
813 Writer.AddIdentifierRef(D->getIdentifier(), Record);
Argyrios Kyrtzidis4996f5f2011-12-09 00:31:40 +0000814 Writer.AddSourceLocation(D->getCategoryNameLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000815 Code = serialization::DECL_OBJC_CATEGORY_IMPL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000816}
817
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000818void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000819 VisitObjCImplDecl(D);
820 Writer.AddDeclRef(D->getSuperClass(), Record);
Argyrios Kyrtzidis5d2ce842013-05-03 22:31:26 +0000821 Writer.AddSourceLocation(D->getSuperClassLoc(), Record);
Fariborz Jahaniana7765fe2012-02-20 20:09:20 +0000822 Writer.AddSourceLocation(D->getIvarLBraceLoc(), Record);
823 Writer.AddSourceLocation(D->getIvarRBraceLoc(), Record);
John McCall0d54a172012-10-17 04:53:31 +0000824 Record.push_back(D->hasNonZeroConstructors());
825 Record.push_back(D->hasDestructors());
Richard Smithc2bb8182015-03-24 06:36:48 +0000826 Record.push_back(D->NumIvarInitializers);
827 if (D->NumIvarInitializers)
828 Writer.AddCXXCtorInitializersRef(
829 llvm::makeArrayRef(D->init_begin(), D->init_end()), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000830 Code = serialization::DECL_OBJC_IMPLEMENTATION;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000831}
832
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000833void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000834 VisitDecl(D);
835 Writer.AddSourceLocation(D->getLocStart(), Record);
836 Writer.AddDeclRef(D->getPropertyDecl(), Record);
837 Writer.AddDeclRef(D->getPropertyIvarDecl(), Record);
Douglas Gregorb1b71e52010-11-17 01:03:52 +0000838 Writer.AddSourceLocation(D->getPropertyIvarDeclLoc(), Record);
Argyrios Kyrtzidisa8607772010-08-09 10:54:37 +0000839 Writer.AddStmt(D->getGetterCXXConstructor());
840 Writer.AddStmt(D->getSetterCXXAssignment());
Sebastian Redl539c5062010-08-18 23:57:32 +0000841 Code = serialization::DECL_OBJC_PROPERTY_IMPL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000842}
843
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000844void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000845 VisitDeclaratorDecl(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000846 Record.push_back(D->isMutable());
John McCallc90c1492014-10-10 18:44:34 +0000847 if (D->InitStorage.getInt() == FieldDecl::ISK_BitWidthOrNothing &&
848 D->InitStorage.getPointer() == nullptr) {
849 Record.push_back(0);
850 } else if (D->InitStorage.getInt() == FieldDecl::ISK_CapturedVLAType) {
851 Record.push_back(D->InitStorage.getInt() + 1);
Alexey Bataev39c81e22014-08-28 04:28:19 +0000852 Writer.AddTypeRef(
John McCallc90c1492014-10-10 18:44:34 +0000853 QualType(static_cast<Type *>(D->InitStorage.getPointer()), 0),
Alexey Bataev39c81e22014-08-28 04:28:19 +0000854 Record);
Richard Smith2b013182012-06-10 03:12:00 +0000855 } else {
John McCallc90c1492014-10-10 18:44:34 +0000856 Record.push_back(D->InitStorage.getInt() + 1);
857 Writer.AddStmt(static_cast<Expr *>(D->InitStorage.getPointer()));
Richard Smith2b013182012-06-10 03:12:00 +0000858 }
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000859 if (!D->getDeclName())
860 Writer.AddDeclRef(Context.getInstantiatedFromUnnamedFieldDecl(D), Record);
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000861
Richard Smith8aed4222015-12-11 22:41:00 +0000862 if (D->getDeclContext() == D->getLexicalDeclContext() &&
863 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000864 !D->isImplicit() &&
865 !D->isUsed(false) &&
866 !D->isInvalidDecl() &&
867 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000868 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000869 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000870 !D->getBitWidth() &&
Richard Smith938f40b2011-06-11 17:19:42 +0000871 !D->hasInClassInitializer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000872 !D->hasExtInfo() &&
873 !ObjCIvarDecl::classofKind(D->getKind()) &&
874 !ObjCAtDefsFieldDecl::classofKind(D->getKind()) &&
875 D->getDeclName())
876 AbbrevToUse = Writer.getDeclFieldAbbrev();
877
Sebastian Redl539c5062010-08-18 23:57:32 +0000878 Code = serialization::DECL_FIELD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000879}
880
John McCall5e77d762013-04-16 07:28:30 +0000881void ASTDeclWriter::VisitMSPropertyDecl(MSPropertyDecl *D) {
882 VisitDeclaratorDecl(D);
883 Writer.AddIdentifierRef(D->getGetterId(), Record);
884 Writer.AddIdentifierRef(D->getSetterId(), Record);
885 Code = serialization::DECL_MS_PROPERTY;
886}
887
Francois Pichet783dd6e2010-11-21 06:08:52 +0000888void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
889 VisitValueDecl(D);
890 Record.push_back(D->getChainingSize());
891
Aaron Ballman29c94602014-03-07 18:36:15 +0000892 for (const auto *P : D->chain())
Aaron Ballman13916082014-03-07 18:11:58 +0000893 Writer.AddDeclRef(P, Record);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000894 Code = serialization::DECL_INDIRECTFIELD;
895}
896
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000897void ASTDeclWriter::VisitVarDecl(VarDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000898 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000899 VisitDeclaratorDecl(D);
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000900 Record.push_back(D->getStorageClass());
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +0000901 Record.push_back(D->getTSCSpec());
Sebastian Redla9351792012-02-11 23:51:47 +0000902 Record.push_back(D->getInitStyle());
David Majnemerfa7bc782015-05-19 00:57:16 +0000903 if (!isa<ParmVarDecl>(D)) {
904 Record.push_back(D->isExceptionVariable());
905 Record.push_back(D->isNRVOVariable());
906 Record.push_back(D->isCXXForRangeDecl());
907 Record.push_back(D->isARCPseudoStrong());
908 Record.push_back(D->isConstexpr());
909 Record.push_back(D->isInitCapture());
910 Record.push_back(D->isPreviousDeclInSameBlockScope());
911 }
Rafael Espindola3ae00052013-05-13 00:12:11 +0000912 Record.push_back(D->getLinkageInternal());
Douglas Gregor12cda632012-09-20 23:43:29 +0000913
Richard Smithd0b4dd62011-12-19 06:19:21 +0000914 if (D->getInit()) {
915 Record.push_back(!D->isInitKnownICE() ? 1 : (D->isInitICE() ? 3 : 2));
Chris Lattner7099dbc2009-04-27 06:16:06 +0000916 Writer.AddStmt(D->getInit());
Richard Smithd0b4dd62011-12-19 06:19:21 +0000917 } else {
918 Record.push_back(0);
919 }
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000920
921 enum {
922 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
923 };
924 if (VarTemplateDecl *TemplD = D->getDescribedVarTemplate()) {
925 Record.push_back(VarTemplate);
926 Writer.AddDeclRef(TemplD, Record);
927 } else if (MemberSpecializationInfo *SpecInfo
928 = D->getMemberSpecializationInfo()) {
929 Record.push_back(StaticDataMemberSpecialization);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000930 Writer.AddDeclRef(SpecInfo->getInstantiatedFrom(), Record);
931 Record.push_back(SpecInfo->getTemplateSpecializationKind());
932 Writer.AddSourceLocation(SpecInfo->getPointOfInstantiation(), Record);
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000933 } else {
934 Record.push_back(VarNotTemplate);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000935 }
936
Richard Smith8aed4222015-12-11 22:41:00 +0000937 if (D->getDeclContext() == D->getLexicalDeclContext() &&
938 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000939 !D->isImplicit() &&
940 !D->isUsed(false) &&
941 !D->isInvalidDecl() &&
942 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000943 !D->isTopLevelDeclInObjCContainer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000944 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000945 !D->isModulePrivate() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000946 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000947 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
948 !D->hasExtInfo() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000949 D->getFirstDecl() == D->getMostRecentDecl() &&
Sebastian Redla9351792012-02-11 23:51:47 +0000950 D->getInitStyle() == VarDecl::CInit &&
Craig Toppera13603a2014-05-22 05:54:18 +0000951 D->getInit() == nullptr &&
John McCalld4631322011-06-17 06:42:21 +0000952 !isa<ParmVarDecl>(D) &&
Larisse Voufoa11bd8a2013-08-13 02:02:26 +0000953 !isa<VarTemplateSpecializationDecl>(D) &&
Douglas Gregor12cda632012-09-20 23:43:29 +0000954 !D->isConstexpr() &&
Richard Smithbb13c9a2013-09-28 04:02:39 +0000955 !D->isInitCapture() &&
Richard Smith1c34fb72013-08-13 18:18:50 +0000956 !D->isPreviousDeclInSameBlockScope() &&
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000957 !D->getMemberSpecializationInfo())
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000958 AbbrevToUse = Writer.getDeclVarAbbrev();
959
Sebastian Redl539c5062010-08-18 23:57:32 +0000960 Code = serialization::DECL_VAR;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000961}
962
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000963void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000964 VisitVarDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000965 Code = serialization::DECL_IMPLICIT_PARAM;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000966}
967
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000968void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000969 VisitVarDecl(D);
John McCall82490832011-05-02 00:30:12 +0000970 Record.push_back(D->isObjCMethodParameter());
John McCall8fb0d9d2011-05-01 22:35:37 +0000971 Record.push_back(D->getFunctionScopeDepth());
972 Record.push_back(D->getFunctionScopeIndex());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000973 Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding
John McCall6a014d52011-03-09 04:22:44 +0000974 Record.push_back(D->isKNRPromoted());
John McCallf3cd6652010-03-12 18:31:32 +0000975 Record.push_back(D->hasInheritedDefaultArg());
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000976 Record.push_back(D->hasUninstantiatedDefaultArg());
977 if (D->hasUninstantiatedDefaultArg())
978 Writer.AddStmt(D->getUninstantiatedDefaultArg());
Sebastian Redl539c5062010-08-18 23:57:32 +0000979 Code = serialization::DECL_PARM_VAR;
Mike Stump11289f42009-09-09 15:08:12 +0000980
John McCalld4631322011-06-17 06:42:21 +0000981 assert(!D->isARCPseudoStrong()); // can be true of ImplicitParamDecl
982
Chris Lattner258172e2009-04-27 07:35:58 +0000983 // If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here
984 // we dynamically check for the properties that we optimize for, but don't
985 // know are true of all PARM_VAR_DECLs.
Richard Smith8aed4222015-12-11 22:41:00 +0000986 if (D->getDeclContext() == D->getLexicalDeclContext() &&
987 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000988 !D->hasExtInfo() &&
Chris Lattner258172e2009-04-27 07:35:58 +0000989 !D->isImplicit() &&
Douglas Gregorebada0772010-06-17 23:14:26 +0000990 !D->isUsed(false) &&
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +0000991 !D->isInvalidDecl() &&
Eli Friedmanc09e0552012-01-13 23:41:25 +0000992 !D->isReferenced() &&
Chris Lattner258172e2009-04-27 07:35:58 +0000993 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000994 !D->isModulePrivate() &&
Chris Lattner258172e2009-04-27 07:35:58 +0000995 D->getStorageClass() == 0 &&
Sebastian Redla9351792012-02-11 23:51:47 +0000996 D->getInitStyle() == VarDecl::CInit && // Can params have anything else?
John McCall82490832011-05-02 00:30:12 +0000997 D->getFunctionScopeDepth() == 0 &&
John McCallf3cd6652010-03-12 18:31:32 +0000998 D->getObjCDeclQualifier() == 0 &&
John McCall6a014d52011-03-09 04:22:44 +0000999 !D->isKNRPromoted() &&
Chris Lattnere2437f42010-05-09 06:40:08 +00001000 !D->hasInheritedDefaultArg() &&
Craig Toppera13603a2014-05-22 05:54:18 +00001001 D->getInit() == nullptr &&
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +00001002 !D->hasUninstantiatedDefaultArg()) // No default expr.
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001003 AbbrevToUse = Writer.getDeclParmVarAbbrev();
Chris Lattner258172e2009-04-27 07:35:58 +00001004
1005 // Check things we know are true of *every* PARM_VAR_DECL, which is more than
1006 // just us assuming it.
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +00001007 assert(!D->getTSCSpec() && "PARM_VAR_DECL can't use TLS");
Chris Lattner258172e2009-04-27 07:35:58 +00001008 assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private");
Douglas Gregor3f324d562010-05-03 18:51:14 +00001009 assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var");
Craig Toppera13603a2014-05-22 05:54:18 +00001010 assert(D->getPreviousDecl() == nullptr && "PARM_VAR_DECL can't be redecl");
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001011 assert(!D->isStaticDataMember() &&
1012 "PARM_VAR_DECL can't be static data member");
Chris Lattner7099dbc2009-04-27 06:16:06 +00001013}
1014
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001015void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001016 VisitDecl(D);
1017 Writer.AddStmt(D->getAsmString());
Abramo Bagnara348823a2011-03-03 14:20:18 +00001018 Writer.AddSourceLocation(D->getRParenLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001019 Code = serialization::DECL_FILE_SCOPE_ASM;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001020}
1021
Michael Han84324352013-02-22 17:15:32 +00001022void ASTDeclWriter::VisitEmptyDecl(EmptyDecl *D) {
1023 VisitDecl(D);
1024 Code = serialization::DECL_EMPTY;
1025}
1026
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001027void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001028 VisitDecl(D);
1029 Writer.AddStmt(D->getBody());
John McCalla3ccba02010-06-04 11:21:44 +00001030 Writer.AddTypeSourceInfo(D->getSignatureAsWritten(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +00001031 Record.push_back(D->param_size());
1032 for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end();
1033 P != PEnd; ++P)
1034 Writer.AddDeclRef(*P, Record);
John McCallcf6ce282012-04-13 17:33:29 +00001035 Record.push_back(D->isVariadic());
1036 Record.push_back(D->blockMissingReturnType());
1037 Record.push_back(D->isConversionFromLambda());
John McCallc63de662011-02-02 13:00:07 +00001038 Record.push_back(D->capturesCXXThis());
John McCall351762c2011-02-07 10:33:21 +00001039 Record.push_back(D->getNumCaptures());
Aaron Ballman9371dd22014-03-14 18:34:04 +00001040 for (const auto &capture : D->captures()) {
John McCall351762c2011-02-07 10:33:21 +00001041 Writer.AddDeclRef(capture.getVariable(), Record);
1042
1043 unsigned flags = 0;
1044 if (capture.isByRef()) flags |= 1;
1045 if (capture.isNested()) flags |= 2;
1046 if (capture.hasCopyExpr()) flags |= 4;
1047 Record.push_back(flags);
1048
1049 if (capture.hasCopyExpr()) Writer.AddStmt(capture.getCopyExpr());
1050 }
John McCallc63de662011-02-02 13:00:07 +00001051
Sebastian Redl539c5062010-08-18 23:57:32 +00001052 Code = serialization::DECL_BLOCK;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001053}
1054
Ben Langmuirce914fc2013-05-03 19:20:19 +00001055void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) {
1056 Record.push_back(CD->getNumParams());
1057 VisitDecl(CD);
Alexey Bataev9959db52014-05-06 10:08:46 +00001058 Record.push_back(CD->getContextParamPosition());
1059 Record.push_back(CD->isNothrow() ? 1 : 0);
Ben Langmuirce914fc2013-05-03 19:20:19 +00001060 // Body is stored by VisitCapturedStmt.
Alexey Bataev9959db52014-05-06 10:08:46 +00001061 for (unsigned I = 0; I < CD->getNumParams(); ++I)
1062 Writer.AddDeclRef(CD->getParam(I), Record);
Ben Langmuirce914fc2013-05-03 19:20:19 +00001063 Code = serialization::DECL_CAPTURED;
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001064}
1065
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001066void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001067 VisitDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001068 Record.push_back(D->getLanguage());
Abramo Bagnaraea947882011-03-08 16:41:52 +00001069 Writer.AddSourceLocation(D->getExternLoc(), Record);
Abramo Bagnara4a8cda82011-03-03 14:52:38 +00001070 Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001071 Code = serialization::DECL_LINKAGE_SPEC;
Chris Lattnerca025db2010-05-07 21:43:38 +00001072}
1073
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001074void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) {
1075 VisitNamedDecl(D);
Abramo Bagnara1c3af962011-03-05 18:21:20 +00001076 Writer.AddSourceLocation(D->getLocStart(), Record);
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001077 Code = serialization::DECL_LABEL;
1078}
1079
1080
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001081void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
Douglas Gregore57e7522012-01-07 09:11:48 +00001082 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001083 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +00001084 Record.push_back(D->isInline());
Abramo Bagnarab5545be2011-03-08 12:38:20 +00001085 Writer.AddSourceLocation(D->getLocStart(), Record);
1086 Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001087
Chris Lattnerca025db2010-05-07 21:43:38 +00001088 if (D->isOriginalNamespace())
1089 Writer.AddDeclRef(D->getAnonymousNamespace(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001090 Code = serialization::DECL_NAMESPACE;
Sebastian Redlf03cdc52010-08-05 21:22:19 +00001091
Douglas Gregore57e7522012-01-07 09:11:48 +00001092 if (Writer.hasChain() && D->isAnonymousNamespace() &&
Douglas Gregorec9fd132012-01-14 16:38:05 +00001093 D == D->getMostRecentDecl()) {
Sebastian Redl010288f2011-04-24 16:28:21 +00001094 // This is a most recent reopening of the anonymous namespace. If its parent
1095 // is in a previous PCH (or is the TU), mark that parent for update, because
1096 // the original namespace always points to the latest re-opening of its
1097 // anonymous namespace.
1098 Decl *Parent = cast<Decl>(
1099 D->getParent()->getRedeclContext()->getPrimaryContext());
Douglas Gregorb3722e22011-09-09 23:01:35 +00001100 if (Parent->isFromASTFile() || isa<TranslationUnitDecl>(Parent)) {
Richard Smith6ef42932014-03-20 21:02:00 +00001101 Writer.DeclUpdates[Parent].push_back(
Aaron Ballman4f45b712014-03-21 15:22:56 +00001102 ASTWriter::DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, D));
Sebastian Redlfa1f3702011-04-24 16:28:13 +00001103 }
1104 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001105}
1106
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001107void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Richard Smithf4634362014-09-03 23:11:22 +00001108 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001109 VisitNamedDecl(D);
Douglas Gregorf9e43ce2010-09-01 00:08:19 +00001110 Writer.AddSourceLocation(D->getNamespaceLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001111 Writer.AddSourceLocation(D->getTargetNameLoc(), Record);
Douglas Gregorc05ba2e2011-02-25 17:08:07 +00001112 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001113 Writer.AddDeclRef(D->getNamespace(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001114 Code = serialization::DECL_NAMESPACE_ALIAS;
Chris Lattnerca025db2010-05-07 21:43:38 +00001115}
1116
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001117void ASTDeclWriter::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001118 VisitNamedDecl(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00001119 Writer.AddSourceLocation(D->getUsingLoc(), Record);
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001120 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00001121 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
Benjamin Kramere78f8ee2012-01-07 19:09:05 +00001122 Writer.AddDeclRef(D->FirstUsingShadow.getPointer(), Record);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00001123 Record.push_back(D->hasTypename());
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001124 Writer.AddDeclRef(Context.getInstantiatedFromUsingDecl(D), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001125 Code = serialization::DECL_USING;
Chris Lattnerca025db2010-05-07 21:43:38 +00001126}
1127
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001128void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) {
Richard Smithfd8634a2013-10-23 02:17:46 +00001129 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001130 VisitNamedDecl(D);
1131 Writer.AddDeclRef(D->getTargetDecl(), Record);
Argyrios Kyrtzidis2703beb2010-11-10 05:40:41 +00001132 Writer.AddDeclRef(D->UsingOrNextShadow, Record);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001133 Writer.AddDeclRef(Context.getInstantiatedFromUsingShadowDecl(D), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001134 Code = serialization::DECL_USING_SHADOW;
Chris Lattnerca025db2010-05-07 21:43:38 +00001135}
1136
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001137void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001138 VisitNamedDecl(D);
Douglas Gregor01a430132010-09-01 03:07:18 +00001139 Writer.AddSourceLocation(D->getUsingLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001140 Writer.AddSourceLocation(D->getNamespaceKeyLocation(), Record);
Douglas Gregor12441b32011-02-25 16:33:46 +00001141 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001142 Writer.AddDeclRef(D->getNominatedNamespace(), Record);
1143 Writer.AddDeclRef(dyn_cast<Decl>(D->getCommonAncestor()), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001144 Code = serialization::DECL_USING_DIRECTIVE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001145}
1146
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001147void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001148 VisitValueDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001149 Writer.AddSourceLocation(D->getUsingLoc(), Record);
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001150 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00001151 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001152 Code = serialization::DECL_UNRESOLVED_USING_VALUE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001153}
1154
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001155void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001156 UnresolvedUsingTypenameDecl *D) {
1157 VisitTypeDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001158 Writer.AddSourceLocation(D->getTypenameLoc(), Record);
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001159 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001160 Code = serialization::DECL_UNRESOLVED_USING_TYPENAME;
Chris Lattnerca025db2010-05-07 21:43:38 +00001161}
1162
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001163void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001164 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001165
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001166 enum {
1167 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1168 };
1169 if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) {
1170 Record.push_back(CXXRecTemplate);
1171 Writer.AddDeclRef(TemplD, Record);
1172 } else if (MemberSpecializationInfo *MSInfo
1173 = D->getMemberSpecializationInfo()) {
1174 Record.push_back(CXXRecMemberSpecialization);
1175 Writer.AddDeclRef(MSInfo->getInstantiatedFrom(), Record);
1176 Record.push_back(MSInfo->getTemplateSpecializationKind());
1177 Writer.AddSourceLocation(MSInfo->getPointOfInstantiation(), Record);
1178 } else {
1179 Record.push_back(CXXRecNotTemplate);
1180 }
1181
Richard Smithcd45dbc2014-04-19 03:48:30 +00001182 Record.push_back(D->isThisDeclarationADefinition());
1183 if (D->isThisDeclarationADefinition())
1184 Writer.AddCXXDefinitionData(D, Record);
1185
John McCall6bd2a892013-01-25 22:31:03 +00001186 // Store (what we currently believe to be) the key function to avoid
1187 // deserializing every method so we can compute it.
John McCallf937c022011-10-07 06:10:15 +00001188 if (D->IsCompleteDefinition)
John McCall6bd2a892013-01-25 22:31:03 +00001189 Writer.AddDeclRef(Context.getCurrentKeyFunction(D), Record);
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001190
Sebastian Redl539c5062010-08-18 23:57:32 +00001191 Code = serialization::DECL_CXX_RECORD;
Chris Lattnerca025db2010-05-07 21:43:38 +00001192}
1193
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001194void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001195 VisitFunctionDecl(D);
Argyrios Kyrtzidis3b1a7792012-10-12 05:31:40 +00001196 if (D->isCanonicalDecl()) {
1197 Record.push_back(D->size_overridden_methods());
1198 for (CXXMethodDecl::method_iterator
1199 I = D->begin_overridden_methods(), E = D->end_overridden_methods();
1200 I != E; ++I)
1201 Writer.AddDeclRef(*I, Record);
1202 } else {
1203 // We only need to record overridden methods once for the canonical decl.
1204 Record.push_back(0);
1205 }
Richard Smith01b2cb42014-07-26 06:37:51 +00001206
Richard Smith8aed4222015-12-11 22:41:00 +00001207 if (D->getDeclContext() == D->getLexicalDeclContext() &&
1208 D->getFirstDecl() == D->getMostRecentDecl() &&
Richard Smith01b2cb42014-07-26 06:37:51 +00001209 !D->isInvalidDecl() &&
1210 !D->hasAttrs() &&
1211 !D->isTopLevelDeclInObjCContainer() &&
1212 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
1213 !D->hasExtInfo() &&
1214 !D->hasInheritedPrototype() &&
1215 D->hasWrittenPrototype())
1216 AbbrevToUse = Writer.getDeclCXXMethodAbbrev();
1217
Sebastian Redl539c5062010-08-18 23:57:32 +00001218 Code = serialization::DECL_CXX_METHOD;
Chris Lattnerca025db2010-05-07 21:43:38 +00001219}
1220
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001221void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001222 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001223
Stephan Tolksdorfa6a08632014-03-27 19:22:19 +00001224 Writer.AddDeclRef(D->getInheritedConstructor(), Record);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001225 Record.push_back(D->IsExplicitSpecified);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001226
Sebastian Redl539c5062010-08-18 23:57:32 +00001227 Code = serialization::DECL_CXX_CONSTRUCTOR;
Chris Lattnerca025db2010-05-07 21:43:38 +00001228}
1229
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001230void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001231 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001232
Richard Smithf8134002015-03-10 01:41:22 +00001233 Writer.AddDeclRef(D->getOperatorDelete(), Record);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001234
Sebastian Redl539c5062010-08-18 23:57:32 +00001235 Code = serialization::DECL_CXX_DESTRUCTOR;
Chris Lattnerca025db2010-05-07 21:43:38 +00001236}
1237
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001238void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001239 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001240 Record.push_back(D->IsExplicitSpecified);
Sebastian Redl539c5062010-08-18 23:57:32 +00001241 Code = serialization::DECL_CXX_CONVERSION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001242}
1243
Douglas Gregorba345522011-12-02 23:23:56 +00001244void ASTDeclWriter::VisitImportDecl(ImportDecl *D) {
1245 VisitDecl(D);
Argyrios Kyrtzidis7b8e5552012-10-03 01:58:45 +00001246 Record.push_back(Writer.getSubmoduleID(D->getImportedModule()));
Douglas Gregorba345522011-12-02 23:23:56 +00001247 ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs();
1248 Record.push_back(!IdentifierLocs.empty());
1249 if (IdentifierLocs.empty()) {
1250 Writer.AddSourceLocation(D->getLocEnd(), Record);
1251 Record.push_back(1);
1252 } else {
1253 for (unsigned I = 0, N = IdentifierLocs.size(); I != N; ++I)
1254 Writer.AddSourceLocation(IdentifierLocs[I], Record);
1255 Record.push_back(IdentifierLocs.size());
1256 }
1257 // Note: the number of source locations must always be the last element in
1258 // the record.
1259 Code = serialization::DECL_IMPORT;
1260}
1261
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001262void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001263 VisitDecl(D);
1264 Writer.AddSourceLocation(D->getColonLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001265 Code = serialization::DECL_ACCESS_SPEC;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001266}
1267
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001268void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) {
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001269 // Record the number of friend type template parameter lists here
1270 // so as to simplify memory allocation during deserialization.
1271 Record.push_back(D->NumTPLists);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001272 VisitDecl(D);
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001273 bool hasFriendDecl = D->Friend.is<NamedDecl*>();
1274 Record.push_back(hasFriendDecl);
1275 if (hasFriendDecl)
1276 Writer.AddDeclRef(D->getFriendDecl(), Record);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001277 else
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001278 Writer.AddTypeSourceInfo(D->getFriendType(), Record);
1279 for (unsigned i = 0; i < D->NumTPLists; ++i)
1280 Writer.AddTemplateParameterList(D->getFriendTypeTemplateParameterList(i),
1281 Record);
Douglas Gregore0fb32c2010-10-27 20:23:41 +00001282 Writer.AddDeclRef(D->getNextFriend(), Record);
John McCall2c2eb122010-10-16 06:59:13 +00001283 Record.push_back(D->UnsupportedFriend);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001284 Writer.AddSourceLocation(D->FriendLoc, Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001285 Code = serialization::DECL_FRIEND;
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001286}
1287
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001288void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001289 VisitDecl(D);
1290 Record.push_back(D->getNumTemplateParameters());
1291 for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i)
1292 Writer.AddTemplateParameterList(D->getTemplateParameterList(i), Record);
Craig Toppera13603a2014-05-22 05:54:18 +00001293 Record.push_back(D->getFriendDecl() != nullptr);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001294 if (D->getFriendDecl())
1295 Writer.AddDeclRef(D->getFriendDecl(), Record);
1296 else
1297 Writer.AddTypeSourceInfo(D->getFriendType(), Record);
1298 Writer.AddSourceLocation(D->getFriendLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001299 Code = serialization::DECL_FRIEND_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001300}
1301
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001302void ASTDeclWriter::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001303 VisitNamedDecl(D);
1304
1305 Writer.AddDeclRef(D->getTemplatedDecl(), Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001306 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001307}
1308
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001309void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Douglas Gregor68444de2012-01-14 15:13:49 +00001310 VisitRedeclarable(D);
1311
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001312 // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that
1313 // getCommonPtr() can be used while this is still initializing.
Rafael Espindola8db352d2013-10-17 15:37:26 +00001314 if (D->isFirstDecl()) {
Douglas Gregor074a4092011-12-19 18:19:24 +00001315 // This declaration owns the 'common' pointer, so serialize that data now.
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001316 Writer.AddDeclRef(D->getInstantiatedFromMemberTemplate(), Record);
1317 if (D->getInstantiatedFromMemberTemplate())
1318 Record.push_back(D->isMemberSpecialization());
Douglas Gregor074a4092011-12-19 18:19:24 +00001319 }
1320
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001321 VisitTemplateDecl(D);
1322 Record.push_back(D->getIdentifierNamespace());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001323}
1324
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001325void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001326 VisitRedeclarableTemplateDecl(D);
1327
Richard Smith509fc852015-02-27 23:05:10 +00001328 if (D->isFirstDecl())
1329 AddTemplateSpecializations(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001330 Code = serialization::DECL_CLASS_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001331}
1332
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001333void ASTDeclWriter::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001334 ClassTemplateSpecializationDecl *D) {
Richard Smithd8a83712015-08-22 01:47:18 +00001335 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1336
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001337 VisitCXXRecordDecl(D);
1338
1339 llvm::PointerUnion<ClassTemplateDecl *,
1340 ClassTemplatePartialSpecializationDecl *> InstFrom
1341 = D->getSpecializedTemplateOrPartial();
Argyrios Kyrtzidisd5553f12011-08-17 21:35:28 +00001342 if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) {
Sebastian Redl401b39a2010-08-24 22:50:24 +00001343 Writer.AddDeclRef(InstFromD, Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001344 } else {
Argyrios Kyrtzidisd5553f12011-08-17 21:35:28 +00001345 Writer.AddDeclRef(InstFrom.get<ClassTemplatePartialSpecializationDecl *>(),
1346 Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001347 Writer.AddTemplateArgumentList(&D->getTemplateInstantiationArgs(), Record);
1348 }
1349
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001350 Writer.AddTemplateArgumentList(&D->getTemplateArgs(), Record);
1351 Writer.AddSourceLocation(D->getPointOfInstantiation(), Record);
1352 Record.push_back(D->getSpecializationKind());
Axel Naumanna31dee22012-10-01 07:34:47 +00001353 Record.push_back(D->isCanonicalDecl());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001354
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001355 if (D->isCanonicalDecl()) {
1356 // When reading, we'll add it to the folding set of the following template.
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001357 Writer.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl(), Record);
1358 }
1359
Richard Smithd55889a2013-09-09 16:55:27 +00001360 // Explicit info.
1361 Writer.AddTypeSourceInfo(D->getTypeAsWritten(), Record);
1362 if (D->getTypeAsWritten()) {
1363 Writer.AddSourceLocation(D->getExternLoc(), Record);
1364 Writer.AddSourceLocation(D->getTemplateKeywordLoc(), Record);
1365 }
1366
Sebastian Redl539c5062010-08-18 23:57:32 +00001367 Code = serialization::DECL_CLASS_TEMPLATE_SPECIALIZATION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001368}
1369
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001370void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001371 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001372 VisitClassTemplateSpecializationDecl(D);
1373
1374 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
Enea Zaffanella6dbe1872013-08-10 07:24:53 +00001375 Writer.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten(), Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001376
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001377 // These are read/set from/to the first declaration.
Craig Toppera13603a2014-05-22 05:54:18 +00001378 if (D->getPreviousDecl() == nullptr) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001379 Writer.AddDeclRef(D->getInstantiatedFromMember(), Record);
1380 Record.push_back(D->isMemberSpecialization());
1381 }
1382
Sebastian Redl539c5062010-08-18 23:57:32 +00001383 Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001384}
1385
Larisse Voufo39a1e502013-08-06 01:03:05 +00001386void ASTDeclWriter::VisitVarTemplateDecl(VarTemplateDecl *D) {
1387 VisitRedeclarableTemplateDecl(D);
1388
Richard Smith509fc852015-02-27 23:05:10 +00001389 if (D->isFirstDecl())
1390 AddTemplateSpecializations(D);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001391 Code = serialization::DECL_VAR_TEMPLATE;
1392}
1393
1394void ASTDeclWriter::VisitVarTemplateSpecializationDecl(
1395 VarTemplateSpecializationDecl *D) {
Richard Smithd8a83712015-08-22 01:47:18 +00001396 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1397
Larisse Voufo39a1e502013-08-06 01:03:05 +00001398 VisitVarDecl(D);
1399
1400 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
1401 InstFrom = D->getSpecializedTemplateOrPartial();
1402 if (Decl *InstFromD = InstFrom.dyn_cast<VarTemplateDecl *>()) {
1403 Writer.AddDeclRef(InstFromD, Record);
1404 } else {
1405 Writer.AddDeclRef(InstFrom.get<VarTemplatePartialSpecializationDecl *>(),
1406 Record);
1407 Writer.AddTemplateArgumentList(&D->getTemplateInstantiationArgs(), Record);
1408 }
1409
1410 // Explicit info.
1411 Writer.AddTypeSourceInfo(D->getTypeAsWritten(), Record);
1412 if (D->getTypeAsWritten()) {
1413 Writer.AddSourceLocation(D->getExternLoc(), Record);
1414 Writer.AddSourceLocation(D->getTemplateKeywordLoc(), Record);
1415 }
1416
1417 Writer.AddTemplateArgumentList(&D->getTemplateArgs(), Record);
1418 Writer.AddSourceLocation(D->getPointOfInstantiation(), Record);
1419 Record.push_back(D->getSpecializationKind());
1420 Record.push_back(D->isCanonicalDecl());
1421
1422 if (D->isCanonicalDecl()) {
1423 // When reading, we'll add it to the folding set of the following template.
1424 Writer.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl(), Record);
1425 }
1426
1427 Code = serialization::DECL_VAR_TEMPLATE_SPECIALIZATION;
1428}
1429
1430void ASTDeclWriter::VisitVarTemplatePartialSpecializationDecl(
1431 VarTemplatePartialSpecializationDecl *D) {
1432 VisitVarTemplateSpecializationDecl(D);
1433
1434 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
Enea Zaffanella6dbe1872013-08-10 07:24:53 +00001435 Writer.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten(), Record);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001436
1437 // These are read/set from/to the first declaration.
Craig Toppera13603a2014-05-22 05:54:18 +00001438 if (D->getPreviousDecl() == nullptr) {
Larisse Voufo39a1e502013-08-06 01:03:05 +00001439 Writer.AddDeclRef(D->getInstantiatedFromMember(), Record);
1440 Record.push_back(D->isMemberSpecialization());
1441 }
1442
1443 Code = serialization::DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION;
1444}
1445
Fariborz Jahanian3a039e32011-08-27 20:50:59 +00001446void ASTDeclWriter::VisitClassScopeFunctionSpecializationDecl(
1447 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichet09af8c32011-08-17 01:06:54 +00001448 VisitDecl(D);
1449 Writer.AddDeclRef(D->getSpecialization(), Record);
1450 Code = serialization::DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION;
1451}
1452
1453
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001454void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001455 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001456
Richard Smith509fc852015-02-27 23:05:10 +00001457 if (D->isFirstDecl())
1458 AddTemplateSpecializations(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001459 Code = serialization::DECL_FUNCTION_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001460}
1461
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001462void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001463 VisitTypeDecl(D);
1464
1465 Record.push_back(D->wasDeclaredWithTypename());
Richard Smith8346e522015-06-10 01:47:58 +00001466
1467 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1468 !D->defaultArgumentWasInherited();
1469 Record.push_back(OwnsDefaultArg);
1470 if (OwnsDefaultArg)
Richard Smith1469b912015-06-10 00:29:03 +00001471 Writer.AddTypeSourceInfo(D->getDefaultArgumentInfo(), Record);
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001472
Sebastian Redl539c5062010-08-18 23:57:32 +00001473 Code = serialization::DECL_TEMPLATE_TYPE_PARM;
Chris Lattnerca025db2010-05-07 21:43:38 +00001474}
1475
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001476void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001477 // For an expanded parameter pack, record the number of expansion types here
Richard Smith1fde8ec2012-09-07 02:06:42 +00001478 // so that it's easier for deserialization to allocate the right amount of
1479 // memory.
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001480 if (D->isExpandedParameterPack())
1481 Record.push_back(D->getNumExpansionTypes());
1482
John McCallf4cd4f92011-02-09 01:13:10 +00001483 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001484 // TemplateParmPosition.
1485 Record.push_back(D->getDepth());
1486 Record.push_back(D->getPosition());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001487
1488 if (D->isExpandedParameterPack()) {
1489 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
1490 Writer.AddTypeRef(D->getExpansionType(I), Record);
1491 Writer.AddTypeSourceInfo(D->getExpansionTypeSourceInfo(I), Record);
1492 }
1493
1494 Code = serialization::DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK;
1495 } else {
1496 // Rest of NonTypeTemplateParmDecl.
1497 Record.push_back(D->isParameterPack());
Richard Smith8346e522015-06-10 01:47:58 +00001498 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1499 !D->defaultArgumentWasInherited();
1500 Record.push_back(OwnsDefaultArg);
1501 if (OwnsDefaultArg)
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001502 Writer.AddStmt(D->getDefaultArgument());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001503 Code = serialization::DECL_NON_TYPE_TEMPLATE_PARM;
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001504 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001505}
1506
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001507void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Richard Smith1fde8ec2012-09-07 02:06:42 +00001508 // For an expanded parameter pack, record the number of expansion types here
1509 // so that it's easier for deserialization to allocate the right amount of
1510 // memory.
1511 if (D->isExpandedParameterPack())
1512 Record.push_back(D->getNumExpansionTemplateParameters());
1513
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001514 VisitTemplateDecl(D);
1515 // TemplateParmPosition.
1516 Record.push_back(D->getDepth());
1517 Record.push_back(D->getPosition());
Richard Smith1fde8ec2012-09-07 02:06:42 +00001518
1519 if (D->isExpandedParameterPack()) {
1520 for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
1521 I != N; ++I)
1522 Writer.AddTemplateParameterList(D->getExpansionTemplateParameters(I),
1523 Record);
1524 Code = serialization::DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK;
1525 } else {
1526 // Rest of TemplateTemplateParmDecl.
Richard Smith1fde8ec2012-09-07 02:06:42 +00001527 Record.push_back(D->isParameterPack());
Richard Smith8346e522015-06-10 01:47:58 +00001528 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1529 !D->defaultArgumentWasInherited();
1530 Record.push_back(OwnsDefaultArg);
1531 if (OwnsDefaultArg)
Richard Smith1469b912015-06-10 00:29:03 +00001532 Writer.AddTemplateArgumentLoc(D->getDefaultArgument(), Record);
Richard Smith1fde8ec2012-09-07 02:06:42 +00001533 Code = serialization::DECL_TEMPLATE_TEMPLATE_PARM;
1534 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001535}
1536
Richard Smith3f1b5d02011-05-05 21:57:07 +00001537void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1538 VisitRedeclarableTemplateDecl(D);
1539 Code = serialization::DECL_TYPE_ALIAS_TEMPLATE;
1540}
1541
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001542void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001543 VisitDecl(D);
1544 Writer.AddStmt(D->getAssertExpr());
Richard Smithded9c2e2012-07-11 22:37:56 +00001545 Record.push_back(D->isFailed());
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001546 Writer.AddStmt(D->getMessage());
Abramo Bagnaraea947882011-03-08 16:41:52 +00001547 Writer.AddSourceLocation(D->getRParenLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001548 Code = serialization::DECL_STATIC_ASSERT;
Chris Lattnerca025db2010-05-07 21:43:38 +00001549}
1550
Chris Lattner7099dbc2009-04-27 06:16:06 +00001551/// \brief Emit the DeclContext part of a declaration context decl.
1552///
1553/// \param LexicalOffset the offset at which the DECL_CONTEXT_LEXICAL
1554/// block for this declaration context is stored. May be 0 to indicate
1555/// that there are no declarations stored within this context.
1556///
1557/// \param VisibleOffset the offset at which the DECL_CONTEXT_VISIBLE
1558/// block for this declaration context is stored. May be 0 to indicate
1559/// that there are no declarations visible from this context. Note
1560/// that this value will not be emitted for non-primary declaration
1561/// contexts.
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001562void ASTDeclWriter::VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset,
Chris Lattner7099dbc2009-04-27 06:16:06 +00001563 uint64_t VisibleOffset) {
Richard Smithe37e9f42016-03-25 01:17:43 +00001564 AddLocalOffset(LexicalOffset);
1565 AddLocalOffset(VisibleOffset);
Chris Lattner7099dbc2009-04-27 06:16:06 +00001566}
1567
Richard Smithd8a83712015-08-22 01:47:18 +00001568const Decl *ASTWriter::getFirstLocalDecl(const Decl *D) {
Richard Smith3864be72015-09-11 02:22:03 +00001569 /// \brief Is this a local declaration (that is, one that will be written to
1570 /// our AST file)? This is the case for declarations that are neither imported
1571 /// from another AST file nor predefined.
1572 auto IsLocalDecl = [&](const Decl *D) -> bool {
1573 if (D->isFromASTFile())
1574 return false;
1575 auto I = DeclIDs.find(D);
1576 return (I == DeclIDs.end() || I->second >= NUM_PREDEF_DECL_IDS);
1577 };
1578
1579 assert(IsLocalDecl(D) && "expected a local declaration");
Richard Smithd8a83712015-08-22 01:47:18 +00001580
1581 const Decl *Canon = D->getCanonicalDecl();
Richard Smith3864be72015-09-11 02:22:03 +00001582 if (IsLocalDecl(Canon))
Richard Smithd8a83712015-08-22 01:47:18 +00001583 return Canon;
1584
1585 const Decl *&CacheEntry = FirstLocalDeclCache[Canon];
1586 if (CacheEntry)
1587 return CacheEntry;
1588
1589 for (const Decl *Redecl = D; Redecl; Redecl = Redecl->getPreviousDecl())
Richard Smith3864be72015-09-11 02:22:03 +00001590 if (IsLocalDecl(Redecl))
Richard Smithd8a83712015-08-22 01:47:18 +00001591 D = Redecl;
1592 return CacheEntry = D;
Richard Smith5fc18a92015-07-12 23:43:21 +00001593}
1594
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001595template <typename T>
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001596void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +00001597 T *First = D->getFirstDecl();
Richard Smith5a4737c2015-02-06 02:42:59 +00001598 T *MostRecent = First->getMostRecentDecl();
Richard Smithd8a83712015-08-22 01:47:18 +00001599 T *DAsT = static_cast<T *>(D);
Richard Smith5a4737c2015-02-06 02:42:59 +00001600 if (MostRecent != First) {
Richard Smithd8a83712015-08-22 01:47:18 +00001601 assert(isRedeclarableDeclKind(DAsT->getKind()) &&
Douglas Gregorfe732d52013-01-21 16:16:40 +00001602 "Not considered redeclarable?");
Richard Smith5a4737c2015-02-06 02:42:59 +00001603
Richard Smithfe620d22015-03-05 23:24:12 +00001604 Writer.AddDeclRef(First, Record);
Richard Smithfe620d22015-03-05 23:24:12 +00001605
Richard Smithd8a83712015-08-22 01:47:18 +00001606 // Write out a list of local redeclarations of this declaration if it's the
1607 // first local declaration in the chain.
1608 const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1609 if (DAsT == FirstLocal) {
Richard Smithd8a83712015-08-22 01:47:18 +00001610 // Emit a list of all imported first declarations so that we can be sure
1611 // that all redeclarations visible to this module are before D in the
1612 // redecl chain.
1613 unsigned I = Record.size();
1614 Record.push_back(0);
1615 if (Writer.Chain)
1616 AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1617 // This is the number of imported first declarations + 1.
1618 Record[I] = Record.size() - I;
Richard Smithd61d4ac2015-08-22 20:13:39 +00001619
1620 // Collect the set of local redeclarations of this declaration, from
1621 // newest to oldest.
1622 RecordData LocalRedecls;
1623 for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1624 Prev != FirstLocal; Prev = Prev->getPreviousDecl())
1625 if (!Prev->isFromASTFile())
1626 Writer.AddDeclRef(Prev, LocalRedecls);
1627
1628 // If we have any redecls, write them now as a separate record preceding
1629 // the declaration itself.
1630 if (LocalRedecls.empty())
1631 Record.push_back(0);
1632 else {
Richard Smithd07268c2016-03-24 23:41:14 +00001633 auto Start = Writer.Stream.GetCurrentBitNo();
Richard Smithd61d4ac2015-08-22 20:13:39 +00001634 Writer.Stream.EmitRecord(LOCAL_REDECLARATIONS, LocalRedecls);
Richard Smithe37e9f42016-03-25 01:17:43 +00001635 AddLocalOffset(Start);
Richard Smithd61d4ac2015-08-22 20:13:39 +00001636 }
Richard Smithd8a83712015-08-22 01:47:18 +00001637 } else {
1638 Record.push_back(0);
1639 Writer.AddDeclRef(FirstLocal, Record);
Richard Smithfe620d22015-03-05 23:24:12 +00001640 }
Douglas Gregor358cd442012-01-15 16:58:34 +00001641
1642 // Make sure that we serialize both the previous and the most-recent
1643 // declarations, which (transitively) ensures that all declarations in the
1644 // chain get serialized.
Richard Smith5a4737c2015-02-06 02:42:59 +00001645 //
1646 // FIXME: This is not correct; when we reach an imported declaration we
1647 // won't emit its previous declaration.
Richard Smith5fc18a92015-07-12 23:43:21 +00001648 (void)Writer.GetDeclRef(D->getPreviousDecl());
Richard Smith5a4737c2015-02-06 02:42:59 +00001649 (void)Writer.GetDeclRef(MostRecent);
Douglas Gregor358cd442012-01-15 16:58:34 +00001650 } else {
1651 // We use the sentinel value 0 to indicate an only declaration.
1652 Record.push_back(0);
Douglas Gregor9f562c82011-12-19 15:27:36 +00001653 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001654}
Chris Lattner7099dbc2009-04-27 06:16:06 +00001655
Alexey Bataeva769e072013-03-22 06:34:35 +00001656void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
1657 Record.push_back(D->varlist_size());
1658 VisitDecl(D);
Aaron Ballman2205d2a2014-03-14 15:55:35 +00001659 for (auto *I : D->varlists())
1660 Writer.AddStmt(I);
Alexey Bataeva769e072013-03-22 06:34:35 +00001661 Code = serialization::DECL_OMP_THREADPRIVATE;
1662}
1663
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00001664void ASTDeclWriter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
Alexey Bataevc5b1d322016-03-04 09:22:22 +00001665 VisitValueDecl(D);
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00001666 Writer.AddSourceLocation(D->getLocStart(), Record);
1667 Writer.AddStmt(D->getCombiner());
1668 Writer.AddStmt(D->getInitializer());
1669 Writer.AddDeclRef(D->getPrevDeclInScope(), Record);
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00001670 Code = serialization::DECL_OMP_DECLARE_REDUCTION;
1671}
1672
Alexey Bataev4244be22016-02-11 05:35:55 +00001673void ASTDeclWriter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
Alexey Bataev90c228f2016-02-08 09:29:13 +00001674 VisitVarDecl(D);
Alexey Bataev4244be22016-02-11 05:35:55 +00001675 Code = serialization::DECL_OMP_CAPTUREDEXPR;
Alexey Bataev90c228f2016-02-08 09:29:13 +00001676}
1677
Chris Lattner7099dbc2009-04-27 06:16:06 +00001678//===----------------------------------------------------------------------===//
Sebastian Redl55c0ad52010-08-18 23:56:21 +00001679// ASTWriter Implementation
Chris Lattner7099dbc2009-04-27 06:16:06 +00001680//===----------------------------------------------------------------------===//
1681
Richard Smith01b2cb42014-07-26 06:37:51 +00001682void ASTWriter::WriteDeclAbbrevs() {
Chris Lattner258172e2009-04-27 07:35:58 +00001683 using namespace llvm;
Chris Lattner258172e2009-04-27 07:35:58 +00001684
Douglas Gregor03412ba2011-06-03 02:27:19 +00001685 BitCodeAbbrev *Abv;
1686
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001687 // Abbreviation for DECL_FIELD
1688 Abv = new BitCodeAbbrev();
1689 Abv->Add(BitCodeAbbrevOp(serialization::DECL_FIELD));
1690 // Decl
1691 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001692 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001693 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001694 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1695 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1696 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1697 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001698 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001699 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001700 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001701 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001702 // NamedDecl
1703 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1704 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001705 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001706 // ValueDecl
1707 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1708 // DeclaratorDecl
1709 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1710 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
1711 // FieldDecl
1712 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
1713 Abv->Add(BitCodeAbbrevOp(0)); //getBitWidth
1714 // Type Source Info
1715 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1716 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1717 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1718 DeclFieldAbbrev = Stream.EmitAbbrev(Abv);
1719
1720 // Abbreviation for DECL_OBJC_IVAR
1721 Abv = new BitCodeAbbrev();
1722 Abv->Add(BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR));
1723 // Decl
1724 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001725 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001726 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001727 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1728 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1729 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1730 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001731 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001732 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001733 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001734 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001735 // NamedDecl
1736 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1737 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001738 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001739 // ValueDecl
1740 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1741 // DeclaratorDecl
1742 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1743 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
1744 // FieldDecl
1745 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
1746 Abv->Add(BitCodeAbbrevOp(0)); //getBitWidth
1747 // ObjC Ivar
1748 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl
1749 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize
1750 // Type Source Info
1751 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1752 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1753 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1754 DeclObjCIvarAbbrev = Stream.EmitAbbrev(Abv);
1755
1756 // Abbreviation for DECL_ENUM
1757 Abv = new BitCodeAbbrev();
1758 Abv->Add(BitCodeAbbrevOp(serialization::DECL_ENUM));
Douglas Gregor3e300102011-10-26 17:53:41 +00001759 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001760 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Chris Lattner258172e2009-04-27 07:35:58 +00001761 // Decl
1762 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001763 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001764 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Chris Lattner258172e2009-04-27 07:35:58 +00001765 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1766 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
Douglas Gregorc9c02ed2009-06-19 23:52:42 +00001767 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +00001768 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001769 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Chris Lattner258172e2009-04-27 07:35:58 +00001770 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001771 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001772 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Douglas Gregor03412ba2011-06-03 02:27:19 +00001773 // NamedDecl
1774 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1775 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001776 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001777 // TypeDecl
1778 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1779 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001780 // TagDecl
1781 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
1782 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
John McCallf937c022011-10-07 06:10:15 +00001783 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001784 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +00001785 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
David Blaikiea8d23ce2013-07-14 01:07:41 +00001786 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001787 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Richard Smith70d58502014-08-30 00:04:23 +00001788 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001789 // EnumDecl
1790 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddTypeRef
1791 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IntegerType
1792 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getPromotionType
1793 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumPositiveBits
1794 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumNegativeBits
1795 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScoped
1796 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScopedUsingClassTag
1797 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isFixed
1798 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedMembEnum
1799 // DC
1800 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
1801 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
1802 DeclEnumAbbrev = Stream.EmitAbbrev(Abv);
Mike Stump11289f42009-09-09 15:08:12 +00001803
Douglas Gregor03412ba2011-06-03 02:27:19 +00001804 // Abbreviation for DECL_RECORD
1805 Abv = new BitCodeAbbrev();
1806 Abv->Add(BitCodeAbbrevOp(serialization::DECL_RECORD));
Douglas Gregor3e300102011-10-26 17:53:41 +00001807 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001808 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Douglas Gregor03412ba2011-06-03 02:27:19 +00001809 // Decl
1810 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001811 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001812 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Douglas Gregor03412ba2011-06-03 02:27:19 +00001813 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1814 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1815 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1816 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001817 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Douglas Gregor03412ba2011-06-03 02:27:19 +00001818 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001819 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001820 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Douglas Gregor03412ba2011-06-03 02:27:19 +00001821 // NamedDecl
1822 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1823 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001824 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Douglas Gregor03412ba2011-06-03 02:27:19 +00001825 // TypeDecl
1826 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1827 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
Douglas Gregor03412ba2011-06-03 02:27:19 +00001828 // TagDecl
1829 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
1830 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
John McCallf937c022011-10-07 06:10:15 +00001831 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
Douglas Gregor03412ba2011-06-03 02:27:19 +00001832 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +00001833 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
David Blaikiea8d23ce2013-07-14 01:07:41 +00001834 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
Douglas Gregor03412ba2011-06-03 02:27:19 +00001835 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Richard Smith70d58502014-08-30 00:04:23 +00001836 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
Douglas Gregor03412ba2011-06-03 02:27:19 +00001837 // RecordDecl
1838 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // FlexibleArrayMember
1839 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // AnonymousStructUnion
1840 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasObjectMember
Fariborz Jahanian78652202013-01-25 23:57:05 +00001841 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasVolatileMember
Douglas Gregor03412ba2011-06-03 02:27:19 +00001842 // DC
1843 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
1844 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
1845 DeclRecordAbbrev = Stream.EmitAbbrev(Abv);
1846
1847 // Abbreviation for DECL_PARM_VAR
1848 Abv = new BitCodeAbbrev();
1849 Abv->Add(BitCodeAbbrevOp(serialization::DECL_PARM_VAR));
Douglas Gregor3e300102011-10-26 17:53:41 +00001850 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001851 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Douglas Gregor03412ba2011-06-03 02:27:19 +00001852 // Decl
1853 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001854 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001855 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Douglas Gregor03412ba2011-06-03 02:27:19 +00001856 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1857 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1858 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1859 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001860 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Douglas Gregor03412ba2011-06-03 02:27:19 +00001861 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001862 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001863 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Chris Lattner258172e2009-04-27 07:35:58 +00001864 // NamedDecl
1865 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1866 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001867 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Chris Lattner258172e2009-04-27 07:35:58 +00001868 // ValueDecl
1869 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +00001870 // DeclaratorDecl
Abramo Bagnaradff19302011-03-08 08:55:46 +00001871 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00001872 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Chris Lattner258172e2009-04-27 07:35:58 +00001873 // VarDecl
1874 Abv->Add(BitCodeAbbrevOp(0)); // StorageClass
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +00001875 Abv->Add(BitCodeAbbrevOp(0)); // getTSCSpec
Chris Lattner258172e2009-04-27 07:35:58 +00001876 Abv->Add(BitCodeAbbrevOp(0)); // hasCXXDirectInitializer
Richard Smith88581592013-02-12 05:48:23 +00001877 Abv->Add(BitCodeAbbrevOp(0)); // Linkage
Chris Lattner258172e2009-04-27 07:35:58 +00001878 Abv->Add(BitCodeAbbrevOp(0)); // HasInit
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001879 Abv->Add(BitCodeAbbrevOp(0)); // HasMemberSpecializationInfo
Chris Lattner258172e2009-04-27 07:35:58 +00001880 // ParmVarDecl
John McCall82490832011-05-02 00:30:12 +00001881 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsObjCMethodParameter
John McCall8fb0d9d2011-05-01 22:35:37 +00001882 Abv->Add(BitCodeAbbrevOp(0)); // ScopeDepth
1883 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex
Chris Lattner258172e2009-04-27 07:35:58 +00001884 Abv->Add(BitCodeAbbrevOp(0)); // ObjCDeclQualifier
John McCall6a014d52011-03-09 04:22:44 +00001885 Abv->Add(BitCodeAbbrevOp(0)); // KNRPromoted
John McCallf3cd6652010-03-12 18:31:32 +00001886 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedDefaultArg
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +00001887 Abv->Add(BitCodeAbbrevOp(0)); // HasUninstantiatedDefaultArg
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001888 // Type Source Info
1889 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1890 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1891 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1892 DeclParmVarAbbrev = Stream.EmitAbbrev(Abv);
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001893
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00001894 // Abbreviation for DECL_TYPEDEF
Douglas Gregor03412ba2011-06-03 02:27:19 +00001895 Abv = new BitCodeAbbrev();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001896 Abv->Add(BitCodeAbbrevOp(serialization::DECL_TYPEDEF));
Douglas Gregor05f10352011-12-17 23:38:30 +00001897 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001898 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001899 // Decl
1900 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001901 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001902 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001903 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1904 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
Richard Smith01b2cb42014-07-26 06:37:51 +00001905 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isUsed
1906 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001907 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Richard Smith01b2cb42014-07-26 06:37:51 +00001908 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001909 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001910 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001911 // NamedDecl
1912 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1913 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001914 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001915 // TypeDecl
1916 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1917 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
1918 // TypedefDecl
1919 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1920 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1921 DeclTypedefAbbrev = Stream.EmitAbbrev(Abv);
1922
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00001923 // Abbreviation for DECL_VAR
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001924 Abv = new BitCodeAbbrev();
1925 Abv->Add(BitCodeAbbrevOp(serialization::DECL_VAR));
Douglas Gregor3e300102011-10-26 17:53:41 +00001926 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001927 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001928 // Decl
1929 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001930 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001931 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001932 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1933 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1934 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1935 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001936 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001937 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001938 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001939 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001940 // NamedDecl
1941 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1942 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001943 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001944 // ValueDecl
1945 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1946 // DeclaratorDecl
1947 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1948 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
1949 // VarDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001950 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // StorageClass
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +00001951 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // getTSCSpec
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001952 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // CXXDirectInitializer
1953 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isExceptionVariable
1954 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isNRVOVariable
1955 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCXXForRangeDecl
John McCalld4631322011-06-17 06:42:21 +00001956 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong
Douglas Gregor12cda632012-09-20 23:43:29 +00001957 Abv->Add(BitCodeAbbrevOp(0)); // isConstexpr
Richard Smithbb13c9a2013-09-28 04:02:39 +00001958 Abv->Add(BitCodeAbbrevOp(0)); // isInitCapture
Richard Smith1c34fb72013-08-13 18:18:50 +00001959 Abv->Add(BitCodeAbbrevOp(0)); // isPrevDeclInSameScope
Rafael Espindola50df3a02013-05-25 17:16:20 +00001960 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001961 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasInit
1962 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasMemberSpecInfo
1963 // Type Source Info
1964 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1965 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1966 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1967 DeclVarAbbrev = Stream.EmitAbbrev(Abv);
1968
Richard Smith01b2cb42014-07-26 06:37:51 +00001969 // Abbreviation for DECL_CXX_METHOD
1970 Abv = new BitCodeAbbrev();
1971 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CXX_METHOD));
1972 // RedeclarableDecl
1973 Abv->Add(BitCodeAbbrevOp(0)); // CanonicalDecl
1974 // Decl
1975 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001976 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Richard Smith01b2cb42014-07-26 06:37:51 +00001977 Abv->Add(BitCodeAbbrevOp(0)); // Invalid
1978 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1979 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Implicit
1980 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Used
1981 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Referenced
1982 Abv->Add(BitCodeAbbrevOp(0)); // InObjCContainer
1983 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Access
1984 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ModulePrivate
1985 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
1986 // NamedDecl
1987 Abv->Add(BitCodeAbbrevOp(DeclarationName::Identifier)); // NameKind
1988 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Identifier
Richard Smith2b560572015-02-07 03:11:11 +00001989 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Richard Smith01b2cb42014-07-26 06:37:51 +00001990 // ValueDecl
1991 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1992 // DeclaratorDecl
1993 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerLocStart
1994 Abv->Add(BitCodeAbbrevOp(0)); // HasExtInfo
1995 // FunctionDecl
1996 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS
1997 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // StorageClass
1998 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Inline
1999 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InlineSpecified
2000 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // VirtualAsWritten
2001 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Pure
2002 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedProto
2003 Abv->Add(BitCodeAbbrevOp(1)); // HasWrittenProto
Richard Smith72625c22015-02-06 23:20:21 +00002004 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Deleted
Richard Smith01b2cb42014-07-26 06:37:51 +00002005 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Trivial
2006 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Defaulted
2007 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ExplicitlyDefaulted
2008 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ImplicitReturnZero
2009 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Constexpr
2010 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // SkippedBody
2011 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // LateParsed
2012 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
2013 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LocEnd
2014 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // TemplateKind
2015 // This Array slurps the rest of the record. Fortunately we want to encode
2016 // (nearly) all the remaining (variable number of) fields in the same way.
2017 //
2018 // This is the function template information if any, then
2019 // NumParams and Params[] from FunctionDecl, and
2020 // NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl.
2021 //
2022 // Add an AbbrevOp for 'size then elements' and use it here.
2023 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2024 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
2025 DeclCXXMethodAbbrev = Stream.EmitAbbrev(Abv);
2026
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00002027 // Abbreviation for EXPR_DECL_REF
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002028 Abv = new BitCodeAbbrev();
Douglas Gregor03412ba2011-06-03 02:27:19 +00002029 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_DECL_REF));
2030 //Stmt
2031 //Expr
2032 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002033 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2034 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2035 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002036 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2037 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2038 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2039 //DeclRefExpr
2040 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HasQualifier
2041 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //GetDeclFound
2042 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ExplicitTemplateArgs
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002043 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HadMultipleCandidates
Alexey Bataev19acc3d2015-01-12 10:17:46 +00002044 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2045 1)); // RefersToEnclosingVariableOrCapture
Douglas Gregor03412ba2011-06-03 02:27:19 +00002046 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef
2047 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2048 DeclRefExprAbbrev = Stream.EmitAbbrev(Abv);
2049
2050 // Abbreviation for EXPR_INTEGER_LITERAL
2051 Abv = new BitCodeAbbrev();
2052 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL));
2053 //Stmt
2054 //Expr
2055 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002056 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2057 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2058 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002059 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2060 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2061 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2062 //Integer Literal
2063 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2064 Abv->Add(BitCodeAbbrevOp(32)); // Bit Width
2065 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value
2066 IntegerLiteralAbbrev = Stream.EmitAbbrev(Abv);
2067
2068 // Abbreviation for EXPR_CHARACTER_LITERAL
2069 Abv = new BitCodeAbbrev();
2070 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL));
2071 //Stmt
2072 //Expr
2073 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002074 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2075 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2076 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002077 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2078 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2079 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
Jonathan D. Turnerd09655f2011-06-03 21:46:44 +00002080 //Character Literal
Douglas Gregor03412ba2011-06-03 02:27:19 +00002081 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue
2082 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
Aaron Ballman9a17c852016-01-07 20:59:26 +00002083 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // getKind
Douglas Gregor03412ba2011-06-03 02:27:19 +00002084 CharacterLiteralAbbrev = Stream.EmitAbbrev(Abv);
2085
Richard Smitha27c26e2014-07-27 04:19:32 +00002086 // Abbreviation for EXPR_IMPLICIT_CAST
2087 Abv = new BitCodeAbbrev();
2088 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_IMPLICIT_CAST));
2089 // Stmt
2090 // Expr
2091 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2092 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2093 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2094 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
2095 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2096 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2097 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2098 // CastExpr
2099 Abv->Add(BitCodeAbbrevOp(0)); // PathSize
2100 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 6)); // CastKind
2101 // ImplicitCastExpr
2102 ExprImplicitCastAbbrev = Stream.EmitAbbrev(Abv);
2103
Sebastian Redl66c5eef2010-07-27 00:17:23 +00002104 Abv = new BitCodeAbbrev();
Sebastian Redl539c5062010-08-18 23:57:32 +00002105 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL));
Sebastian Redl66c5eef2010-07-27 00:17:23 +00002106 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2107 DeclContextLexicalAbbrev = Stream.EmitAbbrev(Abv);
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002108
2109 Abv = new BitCodeAbbrev();
2110 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE));
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002111 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2112 DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(Abv);
Chris Lattner258172e2009-04-27 07:35:58 +00002113}
2114
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002115/// isRequiredDecl - Check if this is a "required" Decl, which must be seen by
2116/// consumers of the AST.
2117///
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002118/// Such decls will always be deserialized from the AST file, so we would like
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002119/// this to be as restrictive as possible. Currently the predicate is driven by
2120/// code generation requirements, if other clients have a different notion of
2121/// what is "required" then we may have to consider an alternate scheme where
2122/// clients can iterate over the top-level decls and get information on them,
2123/// without necessary deserializing them. We could explicitly require such
2124/// clients to use a separate API call to "realize" the decl. This should be
2125/// relatively painless since they would presumably only do it for top-level
2126/// decls.
Richard Smithc52efa72015-08-19 02:30:28 +00002127static bool isRequiredDecl(const Decl *D, ASTContext &Context,
2128 bool WritingModule) {
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00002129 // An ObjCMethodDecl is never considered as "required" because its
2130 // implementation container always is.
2131
Richard Smithc52efa72015-08-19 02:30:28 +00002132 // File scoped assembly or obj-c implementation must be seen.
2133 if (isa<FileScopeAsmDecl>(D) || isa<ObjCImplDecl>(D))
2134 return true;
2135
2136 // ImportDecl is used by codegen to determine the set of imported modules to
2137 // search for inputs for automatic linking; include it if it has a semantic
2138 // effect.
2139 if (isa<ImportDecl>(D) && !WritingModule)
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002140 return true;
2141
Argyrios Kyrtzidisc9049332010-07-29 20:08:05 +00002142 return Context.DeclMustBeEmitted(D);
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002143}
2144
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002145void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) {
Argyrios Kyrtzidisd9f526f2010-10-28 09:29:32 +00002146 // Switch case IDs are per Decl.
2147 ClearSwitchCaseIDs();
2148
Chris Lattner7099dbc2009-04-27 06:16:06 +00002149 RecordData Record;
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002150 ASTDeclWriter W(*this, Context, Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +00002151
Douglas Gregorb3163e52012-01-05 22:33:30 +00002152 // Determine the ID for this declaration.
2153 serialization::DeclID ID;
Douglas Gregor7dd37e52015-11-03 01:20:54 +00002154 assert(!D->isFromASTFile() && "should not be emitting imported decl");
2155 serialization::DeclID &IDR = DeclIDs[D];
2156 if (IDR == 0)
2157 IDR = NextDeclID++;
Douglas Gregorb3163e52012-01-05 22:33:30 +00002158
Douglas Gregor7dd37e52015-11-03 01:20:54 +00002159 ID = IDR;
Argyrios Kyrtzidisbf6c3392012-03-22 16:08:04 +00002160
Richard Smith34da7512016-03-27 05:52:25 +00002161 assert(ID >= FirstDeclID && "invalid decl ID");
Argyrios Kyrtzidisbf6c3392012-03-22 16:08:04 +00002162
2163 // If this declaration is also a DeclContext, write blocks for the
2164 // declarations that lexically stored inside its context and those
2165 // declarations that are visible from its context. These blocks
2166 // are written before the declaration itself so that we can put
2167 // their offsets into the record for the declaration.
2168 uint64_t LexicalOffset = 0;
2169 uint64_t VisibleOffset = 0;
2170 DeclContext *DC = dyn_cast<DeclContext>(D);
2171 if (DC) {
Argyrios Kyrtzidisbf6c3392012-03-22 16:08:04 +00002172 LexicalOffset = WriteDeclContextLexicalBlock(Context, DC);
2173 VisibleOffset = WriteDeclContextVisibleBlock(Context, DC);
2174 }
Douglas Gregorb3163e52012-01-05 22:33:30 +00002175
Richard Smithd61d4ac2015-08-22 20:13:39 +00002176 // Build a record for this declaration
2177 Record.clear();
2178 W.Code = (serialization::DeclCode)0;
2179 W.AbbrevToUse = 0;
2180 W.Visit(D);
2181 if (DC) W.VisitDeclContext(DC, LexicalOffset, VisibleOffset);
2182
Richard Smith34da7512016-03-27 05:52:25 +00002183 unsigned Index = ID - FirstDeclID;
Douglas Gregor12bfa382009-10-17 00:13:19 +00002184
Richard Smith34da7512016-03-27 05:52:25 +00002185 // Record the offset for this declaration
2186 SourceLocation Loc = D->getLocation();
2187 if (DeclOffsets.size() == Index)
2188 DeclOffsets.push_back(DeclOffset(Loc, Stream.GetCurrentBitNo()));
2189 else if (DeclOffsets.size() < Index) {
2190 DeclOffsets.resize(Index+1);
2191 DeclOffsets[Index].setLocation(Loc);
2192 DeclOffsets[Index].BitOffset = Stream.GetCurrentBitNo();
Douglas Gregor12bfa382009-10-17 00:13:19 +00002193 }
2194
Richard Smith34da7512016-03-27 05:52:25 +00002195 SourceManager &SM = Context.getSourceManager();
2196 if (Loc.isValid() && SM.isLocalSourceLocation(Loc))
2197 associateDeclWithFile(D, ID);
2198
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +00002199 if (!W.Code)
Chris Lattner0e62c1c2011-07-23 10:55:15 +00002200 llvm::report_fatal_error(StringRef("unexpected declaration kind '") +
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +00002201 D->getDeclKindName() + "'");
Douglas Gregor12bfa382009-10-17 00:13:19 +00002202 Stream.EmitRecord(W.Code, Record, W.AbbrevToUse);
2203
Richard Smithc2bb8182015-03-24 06:36:48 +00002204 // Flush any expressions, base specifiers, and ctor initializers that
2205 // were written as part of this declaration.
2206 FlushPendingAfterDecl();
2207
Ben Langmuir332aafe2014-01-31 01:06:56 +00002208 // Note declarations that should be deserialized eagerly so that we can add
2209 // them to a record in the AST file later.
Richard Smithc52efa72015-08-19 02:30:28 +00002210 if (isRequiredDecl(D, Context, WritingModule))
Ben Langmuir332aafe2014-01-31 01:06:56 +00002211 EagerlyDeserializedDecls.push_back(ID);
Chris Lattner7099dbc2009-04-27 06:16:06 +00002212}
Richard Smithd28ac5b2014-03-22 23:33:22 +00002213
2214void ASTWriter::AddFunctionDefinition(const FunctionDecl *FD,
2215 RecordData &Record) {
2216 ClearSwitchCaseIDs();
2217
2218 ASTDeclWriter W(*this, FD->getASTContext(), Record);
2219 W.AddFunctionDefinition(FD);
2220}