blob: f2f4a02c876b4562b1ad176511802274592d2576 [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);
52 void VisitTranslationUnitDecl(TranslationUnitDecl *D);
53 void VisitNamedDecl(NamedDecl *D);
Chris Lattnerc8e630e2011-02-17 07:39:24 +000054 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregore31bbd92010-02-21 18:22:14 +000055 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000056 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
57 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000058 void VisitTypeDecl(TypeDecl *D);
Douglas Gregor1f179062011-12-19 14:40:25 +000059 void VisitTypedefNameDecl(TypedefNameDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000060 void VisitTypedefDecl(TypedefDecl *D);
Richard Smithdda56e42011-04-15 14:24:37 +000061 void VisitTypeAliasDecl(TypeAliasDecl *D);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000062 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000063 void VisitTagDecl(TagDecl *D);
64 void VisitEnumDecl(EnumDecl *D);
65 void VisitRecordDecl(RecordDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000066 void VisitCXXRecordDecl(CXXRecordDecl *D);
67 void VisitClassTemplateSpecializationDecl(
68 ClassTemplateSpecializationDecl *D);
69 void VisitClassTemplatePartialSpecializationDecl(
70 ClassTemplatePartialSpecializationDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +000071 void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D);
72 void VisitVarTemplatePartialSpecializationDecl(
73 VarTemplatePartialSpecializationDecl *D);
Fariborz Jahanian3a039e32011-08-27 20:50:59 +000074 void VisitClassScopeFunctionSpecializationDecl(
75 ClassScopeFunctionSpecializationDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000076 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000077 void VisitValueDecl(ValueDecl *D);
78 void VisitEnumConstantDecl(EnumConstantDecl *D);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000079 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +000080 void VisitDeclaratorDecl(DeclaratorDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000081 void VisitFunctionDecl(FunctionDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000082 void VisitCXXMethodDecl(CXXMethodDecl *D);
83 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
84 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
85 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000086 void VisitFieldDecl(FieldDecl *D);
John McCall5e77d762013-04-16 07:28:30 +000087 void VisitMSPropertyDecl(MSPropertyDecl *D);
Francois Pichet783dd6e2010-11-21 06:08:52 +000088 void VisitIndirectFieldDecl(IndirectFieldDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000089 void VisitVarDecl(VarDecl *D);
90 void VisitImplicitParamDecl(ImplicitParamDecl *D);
91 void VisitParmVarDecl(ParmVarDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000092 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
93 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +000094 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000095 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +000096 void VisitVarTemplateDecl(VarTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +000097 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000098 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3f1b5d02011-05-05 21:57:07 +000099 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000100 void VisitUsingDecl(UsingDecl *D);
101 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000102 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000103 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
Douglas Gregorba345522011-12-02 23:23:56 +0000104 void VisitImportDecl(ImportDecl *D);
Abramo Bagnarad7340582010-06-05 05:09:32 +0000105 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000106 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000107 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
108 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000109 void VisitBlockDecl(BlockDecl *D);
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +0000110 void VisitCapturedDecl(CapturedDecl *D);
Michael Han84324352013-02-22 17:15:32 +0000111 void VisitEmptyDecl(EmptyDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000112
Mike Stump11289f42009-09-09 15:08:12 +0000113 void VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset,
Chris Lattner7099dbc2009-04-27 06:16:06 +0000114 uint64_t VisibleOffset);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000115 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000116
117
Alexis Hunted053252010-05-30 07:21:58 +0000118 // FIXME: Put in the same order is DeclNodes.td?
Chris Lattner7099dbc2009-04-27 06:16:06 +0000119 void VisitObjCMethodDecl(ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000120 void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000121 void VisitObjCContainerDecl(ObjCContainerDecl *D);
122 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
123 void VisitObjCIvarDecl(ObjCIvarDecl *D);
124 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
125 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000126 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
127 void VisitObjCImplDecl(ObjCImplDecl *D);
128 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
129 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
130 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
131 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
132 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
Alexey Bataeva769e072013-03-22 06:34:35 +0000133 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
Alexey Bataev4244be22016-02-11 05:35:55 +0000134 void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
Richard Smithd28ac5b2014-03-22 23:33:22 +0000135
Douglas Gregor85f3f952015-07-07 03:57:15 +0000136 /// Add an Objective-C type parameter list to the given record.
137 void AddObjCTypeParamList(ObjCTypeParamList *typeParams) {
138 // Empty type parameter list.
139 if (!typeParams) {
140 Record.push_back(0);
141 return;
142 }
143
144 Record.push_back(typeParams->size());
145 for (auto typeParam : *typeParams) {
146 Writer.AddDeclRef(typeParam, Record);
147 }
148 Writer.AddSourceLocation(typeParams->getLAngleLoc(), Record);
149 Writer.AddSourceLocation(typeParams->getRAngleLoc(), Record);
150 }
151
Richard Smithd28ac5b2014-03-22 23:33:22 +0000152 void AddFunctionDefinition(const FunctionDecl *FD) {
153 assert(FD->doesThisDeclarationHaveABody());
Richard Smithc2bb8182015-03-24 06:36:48 +0000154 if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
155 Record.push_back(CD->NumCtorInitializers);
156 if (CD->NumCtorInitializers)
157 Writer.AddCXXCtorInitializersRef(
158 llvm::makeArrayRef(CD->init_begin(), CD->init_end()), Record);
159 }
Richard Smithd28ac5b2014-03-22 23:33:22 +0000160 Writer.AddStmt(FD->getBody());
161 }
Richard Smith509fc852015-02-27 23:05:10 +0000162
Richard Smithd8a83712015-08-22 01:47:18 +0000163 /// Add to the record the first declaration from each module file that
164 /// provides a declaration of D. The intent is to provide a sufficient
165 /// set such that reloading this set will load all current redeclarations.
166 void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) {
167 llvm::MapVector<ModuleFile*, const Decl*> Firsts;
168 // FIXME: We can skip entries that we know are implied by others.
Richard Smith5f55d932015-08-27 21:38:25 +0000169 for (const Decl *R = D->getMostRecentDecl(); R; R = R->getPreviousDecl()) {
170 if (R->isFromASTFile())
Richard Smithd8a83712015-08-22 01:47:18 +0000171 Firsts[Writer.Chain->getOwningModuleFile(R)] = R;
Richard Smith5f55d932015-08-27 21:38:25 +0000172 else if (IncludeLocal)
173 Firsts[nullptr] = R;
174 }
Richard Smithd8a83712015-08-22 01:47:18 +0000175 for (const auto &F : Firsts)
176 Writer.AddDeclRef(F.second, Record);
177 }
178
Richard Smith509fc852015-02-27 23:05:10 +0000179 /// Get the specialization decl from an entry in the specialization list.
180 template <typename EntryType>
181 typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType *
182 getSpecializationDecl(EntryType &T) {
183 return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T);
184 }
185
186 /// Get the list of partial specializations from a template's common ptr.
187 template<typename T>
188 decltype(T::PartialSpecializations) &getPartialSpecializations(T *Common) {
189 return Common->PartialSpecializations;
190 }
191 ArrayRef<Decl> getPartialSpecializations(FunctionTemplateDecl::Common *) {
192 return None;
193 }
194
195 template<typename Decl>
196 void AddTemplateSpecializations(Decl *D) {
197 auto *Common = D->getCommonPtr();
198
199 // If we have any lazy specializations, and the external AST source is
200 // our chained AST reader, we can just write out the DeclIDs. Otherwise,
201 // we need to resolve them to actual declarations.
202 if (Writer.Chain != Writer.Context->getExternalSource() &&
203 Common->LazySpecializations) {
204 D->LoadLazySpecializations();
205 assert(!Common->LazySpecializations);
206 }
207
208 auto &Specializations = Common->Specializations;
209 auto &&PartialSpecializations = getPartialSpecializations(Common);
210 ArrayRef<DeclID> LazySpecializations;
211 if (auto *LS = Common->LazySpecializations)
Craig Topper55e39a72015-09-29 04:53:28 +0000212 LazySpecializations = llvm::makeArrayRef(LS + 1, LS[0]);
Richard Smith509fc852015-02-27 23:05:10 +0000213
Richard Smithd8a83712015-08-22 01:47:18 +0000214 // Add a slot to the record for the number of specializations.
215 unsigned I = Record.size();
216 Record.push_back(0);
217
Richard Smith509fc852015-02-27 23:05:10 +0000218 for (auto &Entry : Specializations) {
219 auto *D = getSpecializationDecl(Entry);
220 assert(D->isCanonicalDecl() && "non-canonical decl in set");
Richard Smithd8a83712015-08-22 01:47:18 +0000221 AddFirstDeclFromEachModule(D, /*IncludeLocal*/true);
Richard Smith509fc852015-02-27 23:05:10 +0000222 }
223 for (auto &Entry : PartialSpecializations) {
224 auto *D = getSpecializationDecl(Entry);
225 assert(D->isCanonicalDecl() && "non-canonical decl in set");
Richard Smithd8a83712015-08-22 01:47:18 +0000226 AddFirstDeclFromEachModule(D, /*IncludeLocal*/true);
Richard Smith509fc852015-02-27 23:05:10 +0000227 }
Benjamin Kramerf367dd92015-06-12 15:31:50 +0000228 Record.append(LazySpecializations.begin(), LazySpecializations.end());
Richard Smithd8a83712015-08-22 01:47:18 +0000229
230 // Update the size entry we added earlier.
231 Record[I] = Record.size() - I - 1;
232 }
233
234 /// Ensure that this template specialization is associated with the specified
235 /// template on reload.
236 void RegisterTemplateSpecialization(const Decl *Template,
237 const Decl *Specialization) {
238 Template = Template->getCanonicalDecl();
239
240 // If the canonical template is local, we'll write out this specialization
241 // when we emit it.
242 // FIXME: We can do the same thing if there is any local declaration of
243 // the template, to avoid emitting an update record.
244 if (!Template->isFromASTFile())
245 return;
246
247 // We only need to associate the first local declaration of the
248 // specialization. The other declarations will get pulled in by it.
249 if (Writer.getFirstLocalDecl(Specialization) != Specialization)
250 return;
251
252 Writer.DeclUpdates[Template].push_back(ASTWriter::DeclUpdate(
253 UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION, Specialization));
Richard Smith509fc852015-02-27 23:05:10 +0000254 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000255 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000256}
Chris Lattner7099dbc2009-04-27 06:16:06 +0000257
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000258void ASTDeclWriter::Visit(Decl *D) {
259 DeclVisitor<ASTDeclWriter>::Visit(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000260
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000261 // Source locations require array (variable-length) abbreviations. The
262 // abbreviation infrastructure requires that arrays are encoded last, so
263 // we handle it here in the case of those classes derived from DeclaratorDecl
Nick Lewycky4b81fc872015-10-18 20:32:12 +0000264 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000265 Writer.AddTypeSourceInfo(DD->getTypeSourceInfo(), Record);
266 }
267
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000268 // Handle FunctionDecl's body here and write it after all other Stmts/Exprs
269 // have been written. We want it last because we will not read it back when
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000270 // retrieving it from the AST, we'll just lazily set the offset.
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000271 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
Alexis Hunt4a8ea102011-05-06 20:44:56 +0000272 Record.push_back(FD->doesThisDeclarationHaveABody());
273 if (FD->doesThisDeclarationHaveABody())
Richard Smithc2bb8182015-03-24 06:36:48 +0000274 AddFunctionDefinition(FD);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000275 }
276}
277
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000278void ASTDeclWriter::VisitDecl(Decl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000279 Writer.AddDeclRef(cast_or_null<Decl>(D->getDeclContext()), Record);
Richard Smith8aed4222015-12-11 22:41:00 +0000280 if (D->getDeclContext() != D->getLexicalDeclContext())
281 Writer.AddDeclRef(cast_or_null<Decl>(D->getLexicalDeclContext()), Record);
282 else
283 Record.push_back(0);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000284 Record.push_back(D->isInvalidDecl());
285 Record.push_back(D->hasAttrs());
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000286 if (D->hasAttrs())
Craig Topper8c2a2a02014-08-30 16:55:39 +0000287 Writer.WriteAttributes(llvm::makeArrayRef(D->getAttrs().begin(),
288 D->getAttrs().size()), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000289 Record.push_back(D->isImplicit());
Douglas Gregorebada0772010-06-17 23:14:26 +0000290 Record.push_back(D->isUsed(false));
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +0000291 Record.push_back(D->isReferenced());
Douglas Gregor781f7132012-01-06 16:59:53 +0000292 Record.push_back(D->isTopLevelDeclInObjCContainer());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000293 Record.push_back(D->getAccess());
Douglas Gregor781f7132012-01-06 16:59:53 +0000294 Record.push_back(D->isModulePrivate());
Douglas Gregora28bcdd2011-12-01 02:07:58 +0000295 Record.push_back(Writer.inferSubmoduleIDFromLocation(D->getLocation()));
Richard Smithc264d352014-03-23 02:30:01 +0000296
297 // If this declaration injected a name into a context different from its
298 // lexical context, and that context is an imported namespace, we need to
299 // update its visible declarations to include this name.
300 //
301 // This happens when we instantiate a class with a friend declaration or a
302 // function with a local extern declaration, for instance.
Richard Smith5fc18a92015-07-12 23:43:21 +0000303 //
304 // FIXME: Can we handle this in AddedVisibleDecl instead?
Richard Smithc264d352014-03-23 02:30:01 +0000305 if (D->isOutOfLine()) {
Richard Smithe3a97022014-03-23 20:41:56 +0000306 auto *DC = D->getDeclContext();
307 while (auto *NS = dyn_cast<NamespaceDecl>(DC->getRedeclContext())) {
308 if (!NS->isFromASTFile())
309 break;
Chandler Carruth8a3d24d2015-03-26 04:27:10 +0000310 Writer.UpdatedDeclContexts.insert(NS->getPrimaryContext());
Richard Smithe3a97022014-03-23 20:41:56 +0000311 if (!NS->isInlineNamespace())
312 break;
313 DC = NS->getParent();
314 }
Richard Smithc264d352014-03-23 02:30:01 +0000315 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000316}
317
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000318void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
Douglas Gregordab42432011-08-12 00:15:20 +0000319 llvm_unreachable("Translation units aren't directly serialized");
Chris Lattner7099dbc2009-04-27 06:16:06 +0000320}
321
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000322void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000323 VisitDecl(D);
324 Writer.AddDeclarationName(D->getDeclName(), Record);
Richard Smith2b560572015-02-07 03:11:11 +0000325 Record.push_back(needsAnonymousDeclarationNumber(D)
326 ? Writer.getAnonymousDeclarationNumber(D)
327 : 0);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000328}
329
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000330void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000331 VisitNamedDecl(D);
Abramo Bagnarab3185b02011-03-06 15:48:19 +0000332 Writer.AddSourceLocation(D->getLocStart(), Record);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000333 Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000334}
335
Douglas Gregor1f179062011-12-19 14:40:25 +0000336void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) {
Douglas Gregor05f10352011-12-17 23:38:30 +0000337 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000338 VisitTypeDecl(D);
Enea Zaffanellaa86d88c2013-06-20 12:46:19 +0000339 Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record);
340 Record.push_back(D->isModed());
341 if (D->isModed())
342 Writer.AddTypeRef(D->getUnderlyingType(), Record);
Douglas Gregor1f179062011-12-19 14:40:25 +0000343}
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000344
Douglas Gregor1f179062011-12-19 14:40:25 +0000345void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) {
346 VisitTypedefNameDecl(D);
Richard Smith8aed4222015-12-11 22:41:00 +0000347 if (D->getDeclContext() == D->getLexicalDeclContext() &&
348 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000349 !D->isImplicit() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000350 D->getFirstDecl() == D->getMostRecentDecl() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000351 !D->isInvalidDecl() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000352 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000353 !D->isModulePrivate() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000354 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000355 D->getDeclName().getNameKind() == DeclarationName::Identifier)
356 AbbrevToUse = Writer.getDeclTypedefAbbrev();
357
Sebastian Redl539c5062010-08-18 23:57:32 +0000358 Code = serialization::DECL_TYPEDEF;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000359}
360
Richard Smithdda56e42011-04-15 14:24:37 +0000361void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) {
Douglas Gregor1f179062011-12-19 14:40:25 +0000362 VisitTypedefNameDecl(D);
Richard Smith43ccec8e2014-08-26 03:52:16 +0000363 Writer.AddDeclRef(D->getDescribedAliasTemplate(), Record);
Richard Smithdda56e42011-04-15 14:24:37 +0000364 Code = serialization::DECL_TYPEALIAS;
365}
366
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000367void ASTDeclWriter::VisitTagDecl(TagDecl *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000368 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000369 VisitTypeDecl(D);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000370 Record.push_back(D->getIdentifierNamespace());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000371 Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding
Richard Smith2c381642014-08-27 23:11:59 +0000372 if (!isa<CXXRecordDecl>(D))
373 Record.push_back(D->isCompleteDefinition());
Douglas Gregor5089c762010-02-12 17:40:34 +0000374 Record.push_back(D->isEmbeddedInDeclarator());
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +0000375 Record.push_back(D->isFreeStanding());
David Blaikiea8d23ce2013-07-14 01:07:41 +0000376 Record.push_back(D->isCompleteDefinitionRequired());
Argyrios Kyrtzidis664b6902009-07-14 03:18:02 +0000377 Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Richard Smith70d58502014-08-30 00:04:23 +0000378
379 if (D->hasExtInfo()) {
380 Record.push_back(1);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000381 Writer.AddQualifierInfo(*D->getExtInfo(), Record);
Richard Smith70d58502014-08-30 00:04:23 +0000382 } else if (auto *TD = D->getTypedefNameForAnonDecl()) {
383 Record.push_back(2);
384 Writer.AddDeclRef(TD, Record);
385 Writer.AddIdentifierRef(TD->getDeclName().getAsIdentifierInfo(), Record);
Richard Smith70d58502014-08-30 00:04:23 +0000386 } else {
387 Record.push_back(0);
388 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000389}
390
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000391void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000392 VisitTagDecl(D);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000393 Writer.AddTypeSourceInfo(D->getIntegerTypeSourceInfo(), Record);
394 if (!D->getIntegerTypeSourceInfo())
395 Writer.AddTypeRef(D->getIntegerType(), Record);
John McCall56774992009-12-09 09:09:27 +0000396 Writer.AddTypeRef(D->getPromotionType(), Record);
John McCall9aa35be2010-05-06 08:49:23 +0000397 Record.push_back(D->getNumPositiveBits());
398 Record.push_back(D->getNumNegativeBits());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000399 Record.push_back(D->isScoped());
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000400 Record.push_back(D->isScopedUsingClassTag());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000401 Record.push_back(D->isFixed());
Richard Smith4b38ded2012-03-14 23:13:10 +0000402 if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
403 Writer.AddDeclRef(MemberInfo->getInstantiatedFrom(), Record);
404 Record.push_back(MemberInfo->getTemplateSpecializationKind());
405 Writer.AddSourceLocation(MemberInfo->getPointOfInstantiation(), Record);
406 } else {
Craig Toppera13603a2014-05-22 05:54:18 +0000407 Writer.AddDeclRef(nullptr, Record);
Richard Smith4b38ded2012-03-14 23:13:10 +0000408 }
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000409
Richard Smith8aed4222015-12-11 22:41:00 +0000410 if (D->getDeclContext() == D->getLexicalDeclContext() &&
411 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000412 !D->isImplicit() &&
413 !D->isUsed(false) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000414 !D->hasExtInfo() &&
Richard Smith70d58502014-08-30 00:04:23 +0000415 !D->getTypedefNameForAnonDecl() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000416 D->getFirstDecl() == D->getMostRecentDecl() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000417 !D->isInvalidDecl() &&
418 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000419 !D->isTopLevelDeclInObjCContainer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000420 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000421 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000422 !CXXRecordDecl::classofKind(D->getKind()) &&
423 !D->getIntegerTypeSourceInfo() &&
Argyrios Kyrtzidisca370b0d2013-03-18 22:23:49 +0000424 !D->getMemberSpecializationInfo() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000425 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000426 D->getDeclName().getNameKind() == DeclarationName::Identifier)
427 AbbrevToUse = Writer.getDeclEnumAbbrev();
428
Sebastian Redl539c5062010-08-18 23:57:32 +0000429 Code = serialization::DECL_ENUM;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000430}
431
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000432void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000433 VisitTagDecl(D);
434 Record.push_back(D->hasFlexibleArrayMember());
435 Record.push_back(D->isAnonymousStructOrUnion());
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000436 Record.push_back(D->hasObjectMember());
Fariborz Jahanian78652202013-01-25 23:57:05 +0000437 Record.push_back(D->hasVolatileMember());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000438
Richard Smith8aed4222015-12-11 22:41:00 +0000439 if (D->getDeclContext() == D->getLexicalDeclContext() &&
440 !D->hasAttrs() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000441 !D->isImplicit() &&
442 !D->isUsed(false) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000443 !D->hasExtInfo() &&
Richard Smith70d58502014-08-30 00:04:23 +0000444 !D->getTypedefNameForAnonDecl() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000445 D->getFirstDecl() == D->getMostRecentDecl() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000446 !D->isInvalidDecl() &&
447 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000448 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000449 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000450 !D->isModulePrivate() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000451 !CXXRecordDecl::classofKind(D->getKind()) &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000452 !needsAnonymousDeclarationNumber(D) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000453 D->getDeclName().getNameKind() == DeclarationName::Identifier)
Douglas Gregor03412ba2011-06-03 02:27:19 +0000454 AbbrevToUse = Writer.getDeclRecordAbbrev();
455
Sebastian Redl539c5062010-08-18 23:57:32 +0000456 Code = serialization::DECL_RECORD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000457}
458
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000459void ASTDeclWriter::VisitValueDecl(ValueDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000460 VisitNamedDecl(D);
461 Writer.AddTypeRef(D->getType(), Record);
462}
463
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000464void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000465 VisitValueDecl(D);
466 Record.push_back(D->getInitExpr()? 1 : 0);
467 if (D->getInitExpr())
468 Writer.AddStmt(D->getInitExpr());
469 Writer.AddAPSInt(D->getInitVal(), Record);
Douglas Gregor03412ba2011-06-03 02:27:19 +0000470
Sebastian Redl539c5062010-08-18 23:57:32 +0000471 Code = serialization::DECL_ENUM_CONSTANT;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000472}
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000473
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000474void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000475 VisitValueDecl(D);
Abramo Bagnaradff19302011-03-08 08:55:46 +0000476 Writer.AddSourceLocation(D->getInnerLocStart(), Record);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000477 Record.push_back(D->hasExtInfo());
478 if (D->hasExtInfo())
479 Writer.AddQualifierInfo(*D->getExtInfo(), Record);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000480}
Chris Lattner7099dbc2009-04-27 06:16:06 +0000481
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000482void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000483 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000484 VisitDeclaratorDecl(D);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000485 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000486 Record.push_back(D->getIdentifierNamespace());
Douglas Gregorb2585692012-01-04 17:13:46 +0000487
488 // FunctionDecl's body is handled last at ASTWriterDecl::Visit,
489 // after everything else is written.
490
Richard Smith72625c22015-02-06 23:20:21 +0000491 Record.push_back((int)D->SClass); // FIXME: stable encoding
Douglas Gregorb2585692012-01-04 17:13:46 +0000492 Record.push_back(D->IsInline);
Richard Smith72625c22015-02-06 23:20:21 +0000493 Record.push_back(D->IsInlineSpecified);
494 Record.push_back(D->IsVirtualAsWritten);
495 Record.push_back(D->IsPure);
496 Record.push_back(D->HasInheritedPrototype);
497 Record.push_back(D->HasWrittenPrototype);
498 Record.push_back(D->IsDeleted);
499 Record.push_back(D->IsTrivial);
500 Record.push_back(D->IsDefaulted);
501 Record.push_back(D->IsExplicitlyDefaulted);
502 Record.push_back(D->HasImplicitReturnZero);
503 Record.push_back(D->IsConstexpr);
Argyrios Kyrtzidis1eb71a12012-12-06 18:59:10 +0000504 Record.push_back(D->HasSkippedBody);
Richard Smith72625c22015-02-06 23:20:21 +0000505 Record.push_back(D->IsLateTemplateParsed);
Rafael Espindola3ae00052013-05-13 00:12:11 +0000506 Record.push_back(D->getLinkageInternal());
Douglas Gregorb2585692012-01-04 17:13:46 +0000507 Writer.AddSourceLocation(D->getLocEnd(), Record);
508
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000509 Record.push_back(D->getTemplatedKind());
510 switch (D->getTemplatedKind()) {
511 case FunctionDecl::TK_NonTemplate:
512 break;
513 case FunctionDecl::TK_FunctionTemplate:
514 Writer.AddDeclRef(D->getDescribedFunctionTemplate(), Record);
515 break;
516 case FunctionDecl::TK_MemberSpecialization: {
517 MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo();
518 Writer.AddDeclRef(MemberInfo->getInstantiatedFrom(), Record);
519 Record.push_back(MemberInfo->getTemplateSpecializationKind());
520 Writer.AddSourceLocation(MemberInfo->getPointOfInstantiation(), Record);
521 break;
522 }
523 case FunctionDecl::TK_FunctionTemplateSpecialization: {
524 FunctionTemplateSpecializationInfo *
525 FTSInfo = D->getTemplateSpecializationInfo();
Richard Smithd8a83712015-08-22 01:47:18 +0000526
527 RegisterTemplateSpecialization(FTSInfo->getTemplate(), D);
528
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000529 Writer.AddDeclRef(FTSInfo->getTemplate(), Record);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000530 Record.push_back(FTSInfo->getTemplateSpecializationKind());
531
532 // Template arguments.
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000533 Writer.AddTemplateArgumentList(FTSInfo->TemplateArguments, Record);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000534
535 // Template args as written.
Craig Toppera13603a2014-05-22 05:54:18 +0000536 Record.push_back(FTSInfo->TemplateArgumentsAsWritten != nullptr);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000537 if (FTSInfo->TemplateArgumentsAsWritten) {
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000538 Record.push_back(FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs);
539 for (int i=0, e = FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs;
540 i!=e; ++i)
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000541 Writer.AddTemplateArgumentLoc((*FTSInfo->TemplateArgumentsAsWritten)[i],
542 Record);
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000543 Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->LAngleLoc,
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000544 Record);
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000545 Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->RAngleLoc,
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000546 Record);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000547 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000548
549 Writer.AddSourceLocation(FTSInfo->getPointOfInstantiation(), Record);
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000550
551 if (D->isCanonicalDecl()) {
552 // Write the template that contains the specializations set. We will
553 // add a FunctionTemplateSpecializationInfo to it when reading.
554 Writer.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl(), Record);
555 }
Argyrios Kyrtzidisdc9ca0a2010-06-25 16:24:51 +0000556 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000557 }
558 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
559 DependentFunctionTemplateSpecializationInfo *
560 DFTSInfo = D->getDependentSpecializationInfo();
561
562 // Templates.
563 Record.push_back(DFTSInfo->getNumTemplates());
564 for (int i=0, e = DFTSInfo->getNumTemplates(); i != e; ++i)
565 Writer.AddDeclRef(DFTSInfo->getTemplate(i), Record);
566
567 // Templates args.
568 Record.push_back(DFTSInfo->getNumTemplateArgs());
569 for (int i=0, e = DFTSInfo->getNumTemplateArgs(); i != e; ++i)
570 Writer.AddTemplateArgumentLoc(DFTSInfo->getTemplateArg(i), Record);
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000571 Writer.AddSourceLocation(DFTSInfo->getLAngleLoc(), Record);
572 Writer.AddSourceLocation(DFTSInfo->getRAngleLoc(), Record);
Argyrios Kyrtzidisdc9ca0a2010-06-25 16:24:51 +0000573 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000574 }
575 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000576
Chris Lattner7099dbc2009-04-27 06:16:06 +0000577 Record.push_back(D->param_size());
Aaron Ballmanf6bf62e2014-03-07 15:12:56 +0000578 for (auto P : D->params())
579 Writer.AddDeclRef(P, Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000580 Code = serialization::DECL_FUNCTION;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000581}
582
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000583void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000584 VisitNamedDecl(D);
585 // FIXME: convert to LazyStmtPtr?
Mike Stump11289f42009-09-09 15:08:12 +0000586 // Unlike C/C++, method bodies will never be in header files.
Craig Toppera13603a2014-05-22 05:54:18 +0000587 bool HasBodyStuff = D->getBody() != nullptr ||
588 D->getSelfDecl() != nullptr || D->getCmdDecl() != nullptr;
Argyrios Kyrtzidisa8607772010-08-09 10:54:37 +0000589 Record.push_back(HasBodyStuff);
590 if (HasBodyStuff) {
Argyrios Kyrtzidisddcd1322009-06-30 02:35:26 +0000591 Writer.AddStmt(D->getBody());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000592 Writer.AddDeclRef(D->getSelfDecl(), Record);
593 Writer.AddDeclRef(D->getCmdDecl(), Record);
594 }
595 Record.push_back(D->isInstanceMethod());
596 Record.push_back(D->isVariadic());
Jordan Rosed01e83a2012-10-10 16:42:25 +0000597 Record.push_back(D->isPropertyAccessor());
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000598 Record.push_back(D->isDefined());
Argyrios Kyrtzidis08f96a92012-05-09 16:12:57 +0000599 Record.push_back(D->IsOverriding);
Argyrios Kyrtzidis1eb71a12012-12-06 18:59:10 +0000600 Record.push_back(D->HasSkippedBody);
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000601
602 Record.push_back(D->IsRedeclaration);
603 Record.push_back(D->HasRedeclaration);
604 if (D->HasRedeclaration) {
605 assert(Context.getObjCMethodRedeclaration(D));
606 Writer.AddDeclRef(Context.getObjCMethodRedeclaration(D), Record);
607 }
608
Chris Lattner7099dbc2009-04-27 06:16:06 +0000609 // FIXME: stable encoding for @required/@optional
Mike Stump11289f42009-09-09 15:08:12 +0000610 Record.push_back(D->getImplementationControl());
Douglas Gregor813a0662015-06-19 18:14:38 +0000611 // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway/nullability
Mike Stump11289f42009-09-09 15:08:12 +0000612 Record.push_back(D->getObjCDeclQualifier());
Douglas Gregor33823722011-06-11 01:09:30 +0000613 Record.push_back(D->hasRelatedResultType());
Alp Toker314cc812014-01-25 16:55:45 +0000614 Writer.AddTypeRef(D->getReturnType(), Record);
615 Writer.AddTypeSourceInfo(D->getReturnTypeSourceInfo(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000616 Writer.AddSourceLocation(D->getLocEnd(), Record);
617 Record.push_back(D->param_size());
Aaron Ballman43b68be2014-03-07 17:50:17 +0000618 for (const auto *P : D->params())
619 Writer.AddDeclRef(P, Record);
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000620
621 Record.push_back(D->SelLocsKind);
622 unsigned NumStoredSelLocs = D->getNumStoredSelLocs();
623 SourceLocation *SelLocs = D->getStoredSelLocs();
624 Record.push_back(NumStoredSelLocs);
625 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
626 Writer.AddSourceLocation(SelLocs[i], Record);
627
Sebastian Redl539c5062010-08-18 23:57:32 +0000628 Code = serialization::DECL_OBJC_METHOD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000629}
630
Douglas Gregor85f3f952015-07-07 03:57:15 +0000631void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
632 VisitTypedefNameDecl(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +0000633 Record.push_back(D->Variance);
Douglas Gregore83b9562015-07-07 03:57:53 +0000634 Record.push_back(D->Index);
Douglas Gregor1ac1b632015-07-07 03:58:54 +0000635 Writer.AddSourceLocation(D->VarianceLoc, Record);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000636 Writer.AddSourceLocation(D->ColonLoc, Record);
637
638 Code = serialization::DECL_OBJC_TYPE_PARAM;
639}
640
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000641void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000642 VisitNamedDecl(D);
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +0000643 Writer.AddSourceLocation(D->getAtStartLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +0000644 Writer.AddSourceRange(D->getAtEndRange(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000645 // Abstract class (no need to define a stable serialization::DECL code).
Chris Lattner7099dbc2009-04-27 06:16:06 +0000646}
647
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000648void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
Douglas Gregor66b310c2011-12-15 18:03:09 +0000649 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000650 VisitObjCContainerDecl(D);
651 Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000652 AddObjCTypeParamList(D->TypeParamList);
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000653
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000654 Record.push_back(D->isThisDeclarationADefinition());
655 if (D->isThisDeclarationADefinition()) {
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000656 // Write the DefinitionData
657 ObjCInterfaceDecl::DefinitionData &Data = D->data();
658
Douglas Gregore9d95f12015-07-07 03:57:35 +0000659 Writer.AddTypeSourceInfo(D->getSuperClassTInfo(), Record);
Douglas Gregor16408322011-12-15 22:34:59 +0000660 Writer.AddSourceLocation(D->getEndOfDefinitionLoc(), Record);
Argyrios Kyrtzidis9ed9e5f2013-12-03 21:11:30 +0000661 Record.push_back(Data.HasDesignatedInitializers);
Douglas Gregor16408322011-12-15 22:34:59 +0000662
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000663 // Write out the protocols that are directly referenced by the @interface.
664 Record.push_back(Data.ReferencedProtocols.size());
Aaron Ballmana49c5062014-03-13 20:29:09 +0000665 for (const auto *P : D->protocols())
666 Writer.AddDeclRef(P, Record);
Aaron Ballmane9378882014-03-13 20:34:24 +0000667 for (const auto &PL : D->protocol_locs())
668 Writer.AddSourceLocation(PL, Record);
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000669
670 // Write out the protocols that are transitively referenced.
671 Record.push_back(Data.AllReferencedProtocols.size());
672 for (ObjCList<ObjCProtocolDecl>::iterator
673 P = Data.AllReferencedProtocols.begin(),
674 PEnd = Data.AllReferencedProtocols.end();
675 P != PEnd; ++P)
676 Writer.AddDeclRef(*P, Record);
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000677
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000678
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000679 if (ObjCCategoryDecl *Cat = D->getCategoryListRaw()) {
Douglas Gregor404cdde2012-01-27 01:47:08 +0000680 // Ensure that we write out the set of categories for this class.
681 Writer.ObjCClassesWithCategories.insert(D);
682
683 // Make sure that the categories get serialized.
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000684 for (; Cat; Cat = Cat->getNextClassCategoryRaw())
Douglas Gregor404cdde2012-01-27 01:47:08 +0000685 (void)Writer.GetDeclRef(Cat);
686 }
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000687 }
688
Sebastian Redl539c5062010-08-18 23:57:32 +0000689 Code = serialization::DECL_OBJC_INTERFACE;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000690}
691
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000692void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000693 VisitFieldDecl(D);
694 // FIXME: stable encoding for @public/@private/@protected/@package
Mike Stump11289f42009-09-09 15:08:12 +0000695 Record.push_back(D->getAccessControl());
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000696 Record.push_back(D->getSynthesize());
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000697
Richard Smith8aed4222015-12-11 22:41:00 +0000698 if (D->getDeclContext() == D->getLexicalDeclContext() &&
699 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000700 !D->isImplicit() &&
701 !D->isUsed(false) &&
702 !D->isInvalidDecl() &&
703 !D->isReferenced() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000704 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000705 !D->getBitWidth() &&
706 !D->hasExtInfo() &&
707 D->getDeclName())
708 AbbrevToUse = Writer.getDeclObjCIvarAbbrev();
709
Sebastian Redl539c5062010-08-18 23:57:32 +0000710 Code = serialization::DECL_OBJC_IVAR;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000711}
712
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000713void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
Douglas Gregora715bff2012-01-01 19:51:50 +0000714 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000715 VisitObjCContainerDecl(D);
Douglas Gregore6e48b12012-01-01 19:29:29 +0000716
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000717 Record.push_back(D->isThisDeclarationADefinition());
718 if (D->isThisDeclarationADefinition()) {
Douglas Gregore6e48b12012-01-01 19:29:29 +0000719 Record.push_back(D->protocol_size());
Aaron Ballman0f6e64d2014-03-13 22:58:06 +0000720 for (const auto *I : D->protocols())
721 Writer.AddDeclRef(I, Record);
Aaron Ballmana964ec12014-03-14 12:38:50 +0000722 for (const auto &PL : D->protocol_locs())
723 Writer.AddSourceLocation(PL, Record);
Douglas Gregore6e48b12012-01-01 19:29:29 +0000724 }
725
Sebastian Redl539c5062010-08-18 23:57:32 +0000726 Code = serialization::DECL_OBJC_PROTOCOL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000727}
728
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000729void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000730 VisitFieldDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000731 Code = serialization::DECL_OBJC_AT_DEFS_FIELD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000732}
733
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000734void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000735 VisitObjCContainerDecl(D);
Douglas Gregor404cdde2012-01-27 01:47:08 +0000736 Writer.AddSourceLocation(D->getCategoryNameLoc(), Record);
Fariborz Jahaniana7765fe2012-02-20 20:09:20 +0000737 Writer.AddSourceLocation(D->getIvarLBraceLoc(), Record);
738 Writer.AddSourceLocation(D->getIvarRBraceLoc(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000739 Writer.AddDeclRef(D->getClassInterface(), Record);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000740 AddObjCTypeParamList(D->TypeParamList);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000741 Record.push_back(D->protocol_size());
Aaron Ballman19a41762014-03-14 12:55:57 +0000742 for (const auto *I : D->protocols())
743 Writer.AddDeclRef(I, Record);
Aaron Ballmana73c8572014-03-14 13:03:32 +0000744 for (const auto &PL : D->protocol_locs())
745 Writer.AddSourceLocation(PL, Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000746 Code = serialization::DECL_OBJC_CATEGORY;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000747}
748
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000749void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000750 VisitNamedDecl(D);
751 Writer.AddDeclRef(D->getClassInterface(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000752 Code = serialization::DECL_OBJC_COMPATIBLE_ALIAS;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000753}
754
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000755void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000756 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000757 Writer.AddSourceLocation(D->getAtLoc(), Record);
Fariborz Jahanian86c2f5c2012-02-29 22:18:55 +0000758 Writer.AddSourceLocation(D->getLParenLoc(), Record);
Douglas Gregor813a0662015-06-19 18:14:38 +0000759 Writer.AddTypeRef(D->getType(), Record);
John McCall339bb662010-06-04 20:50:08 +0000760 Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000761 // FIXME: stable encoding
762 Record.push_back((unsigned)D->getPropertyAttributes());
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000763 Record.push_back((unsigned)D->getPropertyAttributesAsWritten());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000764 // FIXME: stable encoding
765 Record.push_back((unsigned)D->getPropertyImplementation());
766 Writer.AddDeclarationName(D->getGetterName(), Record);
767 Writer.AddDeclarationName(D->getSetterName(), Record);
768 Writer.AddDeclRef(D->getGetterMethodDecl(), Record);
769 Writer.AddDeclRef(D->getSetterMethodDecl(), Record);
770 Writer.AddDeclRef(D->getPropertyIvarDecl(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000771 Code = serialization::DECL_OBJC_PROPERTY;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000772}
773
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000774void ASTDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000775 VisitObjCContainerDecl(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000776 Writer.AddDeclRef(D->getClassInterface(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000777 // Abstract class (no need to define a stable serialization::DECL code).
Chris Lattner7099dbc2009-04-27 06:16:06 +0000778}
779
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000780void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000781 VisitObjCImplDecl(D);
782 Writer.AddIdentifierRef(D->getIdentifier(), Record);
Argyrios Kyrtzidis4996f5f2011-12-09 00:31:40 +0000783 Writer.AddSourceLocation(D->getCategoryNameLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000784 Code = serialization::DECL_OBJC_CATEGORY_IMPL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000785}
786
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000787void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000788 VisitObjCImplDecl(D);
789 Writer.AddDeclRef(D->getSuperClass(), Record);
Argyrios Kyrtzidis5d2ce842013-05-03 22:31:26 +0000790 Writer.AddSourceLocation(D->getSuperClassLoc(), Record);
Fariborz Jahaniana7765fe2012-02-20 20:09:20 +0000791 Writer.AddSourceLocation(D->getIvarLBraceLoc(), Record);
792 Writer.AddSourceLocation(D->getIvarRBraceLoc(), Record);
John McCall0d54a172012-10-17 04:53:31 +0000793 Record.push_back(D->hasNonZeroConstructors());
794 Record.push_back(D->hasDestructors());
Richard Smithc2bb8182015-03-24 06:36:48 +0000795 Record.push_back(D->NumIvarInitializers);
796 if (D->NumIvarInitializers)
797 Writer.AddCXXCtorInitializersRef(
798 llvm::makeArrayRef(D->init_begin(), D->init_end()), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000799 Code = serialization::DECL_OBJC_IMPLEMENTATION;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000800}
801
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000802void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000803 VisitDecl(D);
804 Writer.AddSourceLocation(D->getLocStart(), Record);
805 Writer.AddDeclRef(D->getPropertyDecl(), Record);
806 Writer.AddDeclRef(D->getPropertyIvarDecl(), Record);
Douglas Gregorb1b71e52010-11-17 01:03:52 +0000807 Writer.AddSourceLocation(D->getPropertyIvarDeclLoc(), Record);
Argyrios Kyrtzidisa8607772010-08-09 10:54:37 +0000808 Writer.AddStmt(D->getGetterCXXConstructor());
809 Writer.AddStmt(D->getSetterCXXAssignment());
Sebastian Redl539c5062010-08-18 23:57:32 +0000810 Code = serialization::DECL_OBJC_PROPERTY_IMPL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000811}
812
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000813void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000814 VisitDeclaratorDecl(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000815 Record.push_back(D->isMutable());
John McCallc90c1492014-10-10 18:44:34 +0000816 if (D->InitStorage.getInt() == FieldDecl::ISK_BitWidthOrNothing &&
817 D->InitStorage.getPointer() == nullptr) {
818 Record.push_back(0);
819 } else if (D->InitStorage.getInt() == FieldDecl::ISK_CapturedVLAType) {
820 Record.push_back(D->InitStorage.getInt() + 1);
Alexey Bataev39c81e22014-08-28 04:28:19 +0000821 Writer.AddTypeRef(
John McCallc90c1492014-10-10 18:44:34 +0000822 QualType(static_cast<Type *>(D->InitStorage.getPointer()), 0),
Alexey Bataev39c81e22014-08-28 04:28:19 +0000823 Record);
Richard Smith2b013182012-06-10 03:12:00 +0000824 } else {
John McCallc90c1492014-10-10 18:44:34 +0000825 Record.push_back(D->InitStorage.getInt() + 1);
826 Writer.AddStmt(static_cast<Expr *>(D->InitStorage.getPointer()));
Richard Smith2b013182012-06-10 03:12:00 +0000827 }
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000828 if (!D->getDeclName())
829 Writer.AddDeclRef(Context.getInstantiatedFromUnnamedFieldDecl(D), Record);
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000830
Richard Smith8aed4222015-12-11 22:41:00 +0000831 if (D->getDeclContext() == D->getLexicalDeclContext() &&
832 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000833 !D->isImplicit() &&
834 !D->isUsed(false) &&
835 !D->isInvalidDecl() &&
836 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000837 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000838 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000839 !D->getBitWidth() &&
Richard Smith938f40b2011-06-11 17:19:42 +0000840 !D->hasInClassInitializer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000841 !D->hasExtInfo() &&
842 !ObjCIvarDecl::classofKind(D->getKind()) &&
843 !ObjCAtDefsFieldDecl::classofKind(D->getKind()) &&
844 D->getDeclName())
845 AbbrevToUse = Writer.getDeclFieldAbbrev();
846
Sebastian Redl539c5062010-08-18 23:57:32 +0000847 Code = serialization::DECL_FIELD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000848}
849
John McCall5e77d762013-04-16 07:28:30 +0000850void ASTDeclWriter::VisitMSPropertyDecl(MSPropertyDecl *D) {
851 VisitDeclaratorDecl(D);
852 Writer.AddIdentifierRef(D->getGetterId(), Record);
853 Writer.AddIdentifierRef(D->getSetterId(), Record);
854 Code = serialization::DECL_MS_PROPERTY;
855}
856
Francois Pichet783dd6e2010-11-21 06:08:52 +0000857void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
858 VisitValueDecl(D);
859 Record.push_back(D->getChainingSize());
860
Aaron Ballman29c94602014-03-07 18:36:15 +0000861 for (const auto *P : D->chain())
Aaron Ballman13916082014-03-07 18:11:58 +0000862 Writer.AddDeclRef(P, Record);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000863 Code = serialization::DECL_INDIRECTFIELD;
864}
865
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000866void ASTDeclWriter::VisitVarDecl(VarDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000867 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000868 VisitDeclaratorDecl(D);
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000869 Record.push_back(D->getStorageClass());
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +0000870 Record.push_back(D->getTSCSpec());
Sebastian Redla9351792012-02-11 23:51:47 +0000871 Record.push_back(D->getInitStyle());
David Majnemerfa7bc782015-05-19 00:57:16 +0000872 if (!isa<ParmVarDecl>(D)) {
873 Record.push_back(D->isExceptionVariable());
874 Record.push_back(D->isNRVOVariable());
875 Record.push_back(D->isCXXForRangeDecl());
876 Record.push_back(D->isARCPseudoStrong());
877 Record.push_back(D->isConstexpr());
878 Record.push_back(D->isInitCapture());
879 Record.push_back(D->isPreviousDeclInSameBlockScope());
880 }
Rafael Espindola3ae00052013-05-13 00:12:11 +0000881 Record.push_back(D->getLinkageInternal());
Douglas Gregor12cda632012-09-20 23:43:29 +0000882
Richard Smithd0b4dd62011-12-19 06:19:21 +0000883 if (D->getInit()) {
884 Record.push_back(!D->isInitKnownICE() ? 1 : (D->isInitICE() ? 3 : 2));
Chris Lattner7099dbc2009-04-27 06:16:06 +0000885 Writer.AddStmt(D->getInit());
Richard Smithd0b4dd62011-12-19 06:19:21 +0000886 } else {
887 Record.push_back(0);
888 }
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000889
890 enum {
891 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
892 };
893 if (VarTemplateDecl *TemplD = D->getDescribedVarTemplate()) {
894 Record.push_back(VarTemplate);
895 Writer.AddDeclRef(TemplD, Record);
896 } else if (MemberSpecializationInfo *SpecInfo
897 = D->getMemberSpecializationInfo()) {
898 Record.push_back(StaticDataMemberSpecialization);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000899 Writer.AddDeclRef(SpecInfo->getInstantiatedFrom(), Record);
900 Record.push_back(SpecInfo->getTemplateSpecializationKind());
901 Writer.AddSourceLocation(SpecInfo->getPointOfInstantiation(), Record);
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000902 } else {
903 Record.push_back(VarNotTemplate);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000904 }
905
Richard Smith8aed4222015-12-11 22:41:00 +0000906 if (D->getDeclContext() == D->getLexicalDeclContext() &&
907 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000908 !D->isImplicit() &&
909 !D->isUsed(false) &&
910 !D->isInvalidDecl() &&
911 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000912 !D->isTopLevelDeclInObjCContainer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000913 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000914 !D->isModulePrivate() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000915 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000916 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
917 !D->hasExtInfo() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000918 D->getFirstDecl() == D->getMostRecentDecl() &&
Sebastian Redla9351792012-02-11 23:51:47 +0000919 D->getInitStyle() == VarDecl::CInit &&
Craig Toppera13603a2014-05-22 05:54:18 +0000920 D->getInit() == nullptr &&
John McCalld4631322011-06-17 06:42:21 +0000921 !isa<ParmVarDecl>(D) &&
Larisse Voufoa11bd8a2013-08-13 02:02:26 +0000922 !isa<VarTemplateSpecializationDecl>(D) &&
Douglas Gregor12cda632012-09-20 23:43:29 +0000923 !D->isConstexpr() &&
Richard Smithbb13c9a2013-09-28 04:02:39 +0000924 !D->isInitCapture() &&
Richard Smith1c34fb72013-08-13 18:18:50 +0000925 !D->isPreviousDeclInSameBlockScope() &&
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000926 !D->getMemberSpecializationInfo())
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000927 AbbrevToUse = Writer.getDeclVarAbbrev();
928
Sebastian Redl539c5062010-08-18 23:57:32 +0000929 Code = serialization::DECL_VAR;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000930}
931
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000932void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000933 VisitVarDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000934 Code = serialization::DECL_IMPLICIT_PARAM;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000935}
936
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000937void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000938 VisitVarDecl(D);
John McCall82490832011-05-02 00:30:12 +0000939 Record.push_back(D->isObjCMethodParameter());
John McCall8fb0d9d2011-05-01 22:35:37 +0000940 Record.push_back(D->getFunctionScopeDepth());
941 Record.push_back(D->getFunctionScopeIndex());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000942 Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding
John McCall6a014d52011-03-09 04:22:44 +0000943 Record.push_back(D->isKNRPromoted());
John McCallf3cd6652010-03-12 18:31:32 +0000944 Record.push_back(D->hasInheritedDefaultArg());
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000945 Record.push_back(D->hasUninstantiatedDefaultArg());
946 if (D->hasUninstantiatedDefaultArg())
947 Writer.AddStmt(D->getUninstantiatedDefaultArg());
Sebastian Redl539c5062010-08-18 23:57:32 +0000948 Code = serialization::DECL_PARM_VAR;
Mike Stump11289f42009-09-09 15:08:12 +0000949
John McCalld4631322011-06-17 06:42:21 +0000950 assert(!D->isARCPseudoStrong()); // can be true of ImplicitParamDecl
951
Chris Lattner258172e2009-04-27 07:35:58 +0000952 // If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here
953 // we dynamically check for the properties that we optimize for, but don't
954 // know are true of all PARM_VAR_DECLs.
Richard Smith8aed4222015-12-11 22:41:00 +0000955 if (D->getDeclContext() == D->getLexicalDeclContext() &&
956 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000957 !D->hasExtInfo() &&
Chris Lattner258172e2009-04-27 07:35:58 +0000958 !D->isImplicit() &&
Douglas Gregorebada0772010-06-17 23:14:26 +0000959 !D->isUsed(false) &&
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +0000960 !D->isInvalidDecl() &&
Eli Friedmanc09e0552012-01-13 23:41:25 +0000961 !D->isReferenced() &&
Chris Lattner258172e2009-04-27 07:35:58 +0000962 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000963 !D->isModulePrivate() &&
Chris Lattner258172e2009-04-27 07:35:58 +0000964 D->getStorageClass() == 0 &&
Sebastian Redla9351792012-02-11 23:51:47 +0000965 D->getInitStyle() == VarDecl::CInit && // Can params have anything else?
John McCall82490832011-05-02 00:30:12 +0000966 D->getFunctionScopeDepth() == 0 &&
John McCallf3cd6652010-03-12 18:31:32 +0000967 D->getObjCDeclQualifier() == 0 &&
John McCall6a014d52011-03-09 04:22:44 +0000968 !D->isKNRPromoted() &&
Chris Lattnere2437f42010-05-09 06:40:08 +0000969 !D->hasInheritedDefaultArg() &&
Craig Toppera13603a2014-05-22 05:54:18 +0000970 D->getInit() == nullptr &&
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000971 !D->hasUninstantiatedDefaultArg()) // No default expr.
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000972 AbbrevToUse = Writer.getDeclParmVarAbbrev();
Chris Lattner258172e2009-04-27 07:35:58 +0000973
974 // Check things we know are true of *every* PARM_VAR_DECL, which is more than
975 // just us assuming it.
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +0000976 assert(!D->getTSCSpec() && "PARM_VAR_DECL can't use TLS");
Chris Lattner258172e2009-04-27 07:35:58 +0000977 assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private");
Douglas Gregor3f324d562010-05-03 18:51:14 +0000978 assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var");
Craig Toppera13603a2014-05-22 05:54:18 +0000979 assert(D->getPreviousDecl() == nullptr && "PARM_VAR_DECL can't be redecl");
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000980 assert(!D->isStaticDataMember() &&
981 "PARM_VAR_DECL can't be static data member");
Chris Lattner7099dbc2009-04-27 06:16:06 +0000982}
983
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000984void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000985 VisitDecl(D);
986 Writer.AddStmt(D->getAsmString());
Abramo Bagnara348823a2011-03-03 14:20:18 +0000987 Writer.AddSourceLocation(D->getRParenLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000988 Code = serialization::DECL_FILE_SCOPE_ASM;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000989}
990
Michael Han84324352013-02-22 17:15:32 +0000991void ASTDeclWriter::VisitEmptyDecl(EmptyDecl *D) {
992 VisitDecl(D);
993 Code = serialization::DECL_EMPTY;
994}
995
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000996void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000997 VisitDecl(D);
998 Writer.AddStmt(D->getBody());
John McCalla3ccba02010-06-04 11:21:44 +0000999 Writer.AddTypeSourceInfo(D->getSignatureAsWritten(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +00001000 Record.push_back(D->param_size());
1001 for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end();
1002 P != PEnd; ++P)
1003 Writer.AddDeclRef(*P, Record);
John McCallcf6ce282012-04-13 17:33:29 +00001004 Record.push_back(D->isVariadic());
1005 Record.push_back(D->blockMissingReturnType());
1006 Record.push_back(D->isConversionFromLambda());
John McCallc63de662011-02-02 13:00:07 +00001007 Record.push_back(D->capturesCXXThis());
John McCall351762c2011-02-07 10:33:21 +00001008 Record.push_back(D->getNumCaptures());
Aaron Ballman9371dd22014-03-14 18:34:04 +00001009 for (const auto &capture : D->captures()) {
John McCall351762c2011-02-07 10:33:21 +00001010 Writer.AddDeclRef(capture.getVariable(), Record);
1011
1012 unsigned flags = 0;
1013 if (capture.isByRef()) flags |= 1;
1014 if (capture.isNested()) flags |= 2;
1015 if (capture.hasCopyExpr()) flags |= 4;
1016 Record.push_back(flags);
1017
1018 if (capture.hasCopyExpr()) Writer.AddStmt(capture.getCopyExpr());
1019 }
John McCallc63de662011-02-02 13:00:07 +00001020
Sebastian Redl539c5062010-08-18 23:57:32 +00001021 Code = serialization::DECL_BLOCK;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001022}
1023
Ben Langmuirce914fc2013-05-03 19:20:19 +00001024void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) {
1025 Record.push_back(CD->getNumParams());
1026 VisitDecl(CD);
Alexey Bataev9959db52014-05-06 10:08:46 +00001027 Record.push_back(CD->getContextParamPosition());
1028 Record.push_back(CD->isNothrow() ? 1 : 0);
Ben Langmuirce914fc2013-05-03 19:20:19 +00001029 // Body is stored by VisitCapturedStmt.
Alexey Bataev9959db52014-05-06 10:08:46 +00001030 for (unsigned I = 0; I < CD->getNumParams(); ++I)
1031 Writer.AddDeclRef(CD->getParam(I), Record);
Ben Langmuirce914fc2013-05-03 19:20:19 +00001032 Code = serialization::DECL_CAPTURED;
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001033}
1034
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001035void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001036 VisitDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001037 Record.push_back(D->getLanguage());
Abramo Bagnaraea947882011-03-08 16:41:52 +00001038 Writer.AddSourceLocation(D->getExternLoc(), Record);
Abramo Bagnara4a8cda82011-03-03 14:52:38 +00001039 Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001040 Code = serialization::DECL_LINKAGE_SPEC;
Chris Lattnerca025db2010-05-07 21:43:38 +00001041}
1042
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001043void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) {
1044 VisitNamedDecl(D);
Abramo Bagnara1c3af962011-03-05 18:21:20 +00001045 Writer.AddSourceLocation(D->getLocStart(), Record);
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001046 Code = serialization::DECL_LABEL;
1047}
1048
1049
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001050void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
Douglas Gregore57e7522012-01-07 09:11:48 +00001051 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001052 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +00001053 Record.push_back(D->isInline());
Abramo Bagnarab5545be2011-03-08 12:38:20 +00001054 Writer.AddSourceLocation(D->getLocStart(), Record);
1055 Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001056
Chris Lattnerca025db2010-05-07 21:43:38 +00001057 if (D->isOriginalNamespace())
1058 Writer.AddDeclRef(D->getAnonymousNamespace(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001059 Code = serialization::DECL_NAMESPACE;
Sebastian Redlf03cdc52010-08-05 21:22:19 +00001060
Douglas Gregore57e7522012-01-07 09:11:48 +00001061 if (Writer.hasChain() && D->isAnonymousNamespace() &&
Douglas Gregorec9fd132012-01-14 16:38:05 +00001062 D == D->getMostRecentDecl()) {
Sebastian Redl010288f2011-04-24 16:28:21 +00001063 // This is a most recent reopening of the anonymous namespace. If its parent
1064 // is in a previous PCH (or is the TU), mark that parent for update, because
1065 // the original namespace always points to the latest re-opening of its
1066 // anonymous namespace.
1067 Decl *Parent = cast<Decl>(
1068 D->getParent()->getRedeclContext()->getPrimaryContext());
Douglas Gregorb3722e22011-09-09 23:01:35 +00001069 if (Parent->isFromASTFile() || isa<TranslationUnitDecl>(Parent)) {
Richard Smith6ef42932014-03-20 21:02:00 +00001070 Writer.DeclUpdates[Parent].push_back(
Aaron Ballman4f45b712014-03-21 15:22:56 +00001071 ASTWriter::DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, D));
Sebastian Redlfa1f3702011-04-24 16:28:13 +00001072 }
1073 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001074}
1075
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001076void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Richard Smithf4634362014-09-03 23:11:22 +00001077 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001078 VisitNamedDecl(D);
Douglas Gregorf9e43ce2010-09-01 00:08:19 +00001079 Writer.AddSourceLocation(D->getNamespaceLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001080 Writer.AddSourceLocation(D->getTargetNameLoc(), Record);
Douglas Gregorc05ba2e2011-02-25 17:08:07 +00001081 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001082 Writer.AddDeclRef(D->getNamespace(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001083 Code = serialization::DECL_NAMESPACE_ALIAS;
Chris Lattnerca025db2010-05-07 21:43:38 +00001084}
1085
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001086void ASTDeclWriter::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001087 VisitNamedDecl(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00001088 Writer.AddSourceLocation(D->getUsingLoc(), Record);
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001089 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00001090 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
Benjamin Kramere78f8ee2012-01-07 19:09:05 +00001091 Writer.AddDeclRef(D->FirstUsingShadow.getPointer(), Record);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00001092 Record.push_back(D->hasTypename());
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001093 Writer.AddDeclRef(Context.getInstantiatedFromUsingDecl(D), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001094 Code = serialization::DECL_USING;
Chris Lattnerca025db2010-05-07 21:43:38 +00001095}
1096
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001097void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) {
Richard Smithfd8634a2013-10-23 02:17:46 +00001098 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001099 VisitNamedDecl(D);
1100 Writer.AddDeclRef(D->getTargetDecl(), Record);
Argyrios Kyrtzidis2703beb2010-11-10 05:40:41 +00001101 Writer.AddDeclRef(D->UsingOrNextShadow, Record);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001102 Writer.AddDeclRef(Context.getInstantiatedFromUsingShadowDecl(D), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001103 Code = serialization::DECL_USING_SHADOW;
Chris Lattnerca025db2010-05-07 21:43:38 +00001104}
1105
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001106void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001107 VisitNamedDecl(D);
Douglas Gregor01a430132010-09-01 03:07:18 +00001108 Writer.AddSourceLocation(D->getUsingLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001109 Writer.AddSourceLocation(D->getNamespaceKeyLocation(), Record);
Douglas Gregor12441b32011-02-25 16:33:46 +00001110 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001111 Writer.AddDeclRef(D->getNominatedNamespace(), Record);
1112 Writer.AddDeclRef(dyn_cast<Decl>(D->getCommonAncestor()), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001113 Code = serialization::DECL_USING_DIRECTIVE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001114}
1115
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001116void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001117 VisitValueDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001118 Writer.AddSourceLocation(D->getUsingLoc(), Record);
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001119 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00001120 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001121 Code = serialization::DECL_UNRESOLVED_USING_VALUE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001122}
1123
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001124void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001125 UnresolvedUsingTypenameDecl *D) {
1126 VisitTypeDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001127 Writer.AddSourceLocation(D->getTypenameLoc(), Record);
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001128 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001129 Code = serialization::DECL_UNRESOLVED_USING_TYPENAME;
Chris Lattnerca025db2010-05-07 21:43:38 +00001130}
1131
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001132void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001133 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001134
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001135 enum {
1136 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1137 };
1138 if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) {
1139 Record.push_back(CXXRecTemplate);
1140 Writer.AddDeclRef(TemplD, Record);
1141 } else if (MemberSpecializationInfo *MSInfo
1142 = D->getMemberSpecializationInfo()) {
1143 Record.push_back(CXXRecMemberSpecialization);
1144 Writer.AddDeclRef(MSInfo->getInstantiatedFrom(), Record);
1145 Record.push_back(MSInfo->getTemplateSpecializationKind());
1146 Writer.AddSourceLocation(MSInfo->getPointOfInstantiation(), Record);
1147 } else {
1148 Record.push_back(CXXRecNotTemplate);
1149 }
1150
Richard Smithcd45dbc2014-04-19 03:48:30 +00001151 Record.push_back(D->isThisDeclarationADefinition());
1152 if (D->isThisDeclarationADefinition())
1153 Writer.AddCXXDefinitionData(D, Record);
1154
John McCall6bd2a892013-01-25 22:31:03 +00001155 // Store (what we currently believe to be) the key function to avoid
1156 // deserializing every method so we can compute it.
John McCallf937c022011-10-07 06:10:15 +00001157 if (D->IsCompleteDefinition)
John McCall6bd2a892013-01-25 22:31:03 +00001158 Writer.AddDeclRef(Context.getCurrentKeyFunction(D), Record);
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001159
Sebastian Redl539c5062010-08-18 23:57:32 +00001160 Code = serialization::DECL_CXX_RECORD;
Chris Lattnerca025db2010-05-07 21:43:38 +00001161}
1162
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001163void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001164 VisitFunctionDecl(D);
Argyrios Kyrtzidis3b1a7792012-10-12 05:31:40 +00001165 if (D->isCanonicalDecl()) {
1166 Record.push_back(D->size_overridden_methods());
1167 for (CXXMethodDecl::method_iterator
1168 I = D->begin_overridden_methods(), E = D->end_overridden_methods();
1169 I != E; ++I)
1170 Writer.AddDeclRef(*I, Record);
1171 } else {
1172 // We only need to record overridden methods once for the canonical decl.
1173 Record.push_back(0);
1174 }
Richard Smith01b2cb42014-07-26 06:37:51 +00001175
Richard Smith8aed4222015-12-11 22:41:00 +00001176 if (D->getDeclContext() == D->getLexicalDeclContext() &&
1177 D->getFirstDecl() == D->getMostRecentDecl() &&
Richard Smith01b2cb42014-07-26 06:37:51 +00001178 !D->isInvalidDecl() &&
1179 !D->hasAttrs() &&
1180 !D->isTopLevelDeclInObjCContainer() &&
1181 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
1182 !D->hasExtInfo() &&
1183 !D->hasInheritedPrototype() &&
1184 D->hasWrittenPrototype())
1185 AbbrevToUse = Writer.getDeclCXXMethodAbbrev();
1186
Sebastian Redl539c5062010-08-18 23:57:32 +00001187 Code = serialization::DECL_CXX_METHOD;
Chris Lattnerca025db2010-05-07 21:43:38 +00001188}
1189
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001190void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001191 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001192
Stephan Tolksdorfa6a08632014-03-27 19:22:19 +00001193 Writer.AddDeclRef(D->getInheritedConstructor(), Record);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001194 Record.push_back(D->IsExplicitSpecified);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001195
Sebastian Redl539c5062010-08-18 23:57:32 +00001196 Code = serialization::DECL_CXX_CONSTRUCTOR;
Chris Lattnerca025db2010-05-07 21:43:38 +00001197}
1198
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001199void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001200 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001201
Richard Smithf8134002015-03-10 01:41:22 +00001202 Writer.AddDeclRef(D->getOperatorDelete(), Record);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001203
Sebastian Redl539c5062010-08-18 23:57:32 +00001204 Code = serialization::DECL_CXX_DESTRUCTOR;
Chris Lattnerca025db2010-05-07 21:43:38 +00001205}
1206
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001207void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001208 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001209 Record.push_back(D->IsExplicitSpecified);
Sebastian Redl539c5062010-08-18 23:57:32 +00001210 Code = serialization::DECL_CXX_CONVERSION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001211}
1212
Douglas Gregorba345522011-12-02 23:23:56 +00001213void ASTDeclWriter::VisitImportDecl(ImportDecl *D) {
1214 VisitDecl(D);
Argyrios Kyrtzidis7b8e5552012-10-03 01:58:45 +00001215 Record.push_back(Writer.getSubmoduleID(D->getImportedModule()));
Douglas Gregorba345522011-12-02 23:23:56 +00001216 ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs();
1217 Record.push_back(!IdentifierLocs.empty());
1218 if (IdentifierLocs.empty()) {
1219 Writer.AddSourceLocation(D->getLocEnd(), Record);
1220 Record.push_back(1);
1221 } else {
1222 for (unsigned I = 0, N = IdentifierLocs.size(); I != N; ++I)
1223 Writer.AddSourceLocation(IdentifierLocs[I], Record);
1224 Record.push_back(IdentifierLocs.size());
1225 }
1226 // Note: the number of source locations must always be the last element in
1227 // the record.
1228 Code = serialization::DECL_IMPORT;
1229}
1230
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001231void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001232 VisitDecl(D);
1233 Writer.AddSourceLocation(D->getColonLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001234 Code = serialization::DECL_ACCESS_SPEC;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001235}
1236
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001237void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) {
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001238 // Record the number of friend type template parameter lists here
1239 // so as to simplify memory allocation during deserialization.
1240 Record.push_back(D->NumTPLists);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001241 VisitDecl(D);
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001242 bool hasFriendDecl = D->Friend.is<NamedDecl*>();
1243 Record.push_back(hasFriendDecl);
1244 if (hasFriendDecl)
1245 Writer.AddDeclRef(D->getFriendDecl(), Record);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001246 else
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001247 Writer.AddTypeSourceInfo(D->getFriendType(), Record);
1248 for (unsigned i = 0; i < D->NumTPLists; ++i)
1249 Writer.AddTemplateParameterList(D->getFriendTypeTemplateParameterList(i),
1250 Record);
Douglas Gregore0fb32c2010-10-27 20:23:41 +00001251 Writer.AddDeclRef(D->getNextFriend(), Record);
John McCall2c2eb122010-10-16 06:59:13 +00001252 Record.push_back(D->UnsupportedFriend);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001253 Writer.AddSourceLocation(D->FriendLoc, Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001254 Code = serialization::DECL_FRIEND;
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001255}
1256
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001257void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001258 VisitDecl(D);
1259 Record.push_back(D->getNumTemplateParameters());
1260 for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i)
1261 Writer.AddTemplateParameterList(D->getTemplateParameterList(i), Record);
Craig Toppera13603a2014-05-22 05:54:18 +00001262 Record.push_back(D->getFriendDecl() != nullptr);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001263 if (D->getFriendDecl())
1264 Writer.AddDeclRef(D->getFriendDecl(), Record);
1265 else
1266 Writer.AddTypeSourceInfo(D->getFriendType(), Record);
1267 Writer.AddSourceLocation(D->getFriendLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001268 Code = serialization::DECL_FRIEND_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001269}
1270
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001271void ASTDeclWriter::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001272 VisitNamedDecl(D);
1273
1274 Writer.AddDeclRef(D->getTemplatedDecl(), Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001275 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001276}
1277
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001278void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Douglas Gregor68444de2012-01-14 15:13:49 +00001279 VisitRedeclarable(D);
1280
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001281 // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that
1282 // getCommonPtr() can be used while this is still initializing.
Rafael Espindola8db352d2013-10-17 15:37:26 +00001283 if (D->isFirstDecl()) {
Douglas Gregor074a4092011-12-19 18:19:24 +00001284 // This declaration owns the 'common' pointer, so serialize that data now.
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001285 Writer.AddDeclRef(D->getInstantiatedFromMemberTemplate(), Record);
1286 if (D->getInstantiatedFromMemberTemplate())
1287 Record.push_back(D->isMemberSpecialization());
Douglas Gregor074a4092011-12-19 18:19:24 +00001288 }
1289
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001290 VisitTemplateDecl(D);
1291 Record.push_back(D->getIdentifierNamespace());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001292}
1293
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001294void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001295 VisitRedeclarableTemplateDecl(D);
1296
Richard Smith509fc852015-02-27 23:05:10 +00001297 if (D->isFirstDecl())
1298 AddTemplateSpecializations(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001299 Code = serialization::DECL_CLASS_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001300}
1301
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001302void ASTDeclWriter::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001303 ClassTemplateSpecializationDecl *D) {
Richard Smithd8a83712015-08-22 01:47:18 +00001304 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1305
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001306 VisitCXXRecordDecl(D);
1307
1308 llvm::PointerUnion<ClassTemplateDecl *,
1309 ClassTemplatePartialSpecializationDecl *> InstFrom
1310 = D->getSpecializedTemplateOrPartial();
Argyrios Kyrtzidisd5553f12011-08-17 21:35:28 +00001311 if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) {
Sebastian Redl401b39a2010-08-24 22:50:24 +00001312 Writer.AddDeclRef(InstFromD, Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001313 } else {
Argyrios Kyrtzidisd5553f12011-08-17 21:35:28 +00001314 Writer.AddDeclRef(InstFrom.get<ClassTemplatePartialSpecializationDecl *>(),
1315 Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001316 Writer.AddTemplateArgumentList(&D->getTemplateInstantiationArgs(), Record);
1317 }
1318
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001319 Writer.AddTemplateArgumentList(&D->getTemplateArgs(), Record);
1320 Writer.AddSourceLocation(D->getPointOfInstantiation(), Record);
1321 Record.push_back(D->getSpecializationKind());
Axel Naumanna31dee22012-10-01 07:34:47 +00001322 Record.push_back(D->isCanonicalDecl());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001323
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001324 if (D->isCanonicalDecl()) {
1325 // When reading, we'll add it to the folding set of the following template.
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001326 Writer.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl(), Record);
1327 }
1328
Richard Smithd55889a2013-09-09 16:55:27 +00001329 // Explicit info.
1330 Writer.AddTypeSourceInfo(D->getTypeAsWritten(), Record);
1331 if (D->getTypeAsWritten()) {
1332 Writer.AddSourceLocation(D->getExternLoc(), Record);
1333 Writer.AddSourceLocation(D->getTemplateKeywordLoc(), Record);
1334 }
1335
Sebastian Redl539c5062010-08-18 23:57:32 +00001336 Code = serialization::DECL_CLASS_TEMPLATE_SPECIALIZATION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001337}
1338
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001339void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001340 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001341 VisitClassTemplateSpecializationDecl(D);
1342
1343 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
Enea Zaffanella6dbe1872013-08-10 07:24:53 +00001344 Writer.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten(), Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001345
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001346 // These are read/set from/to the first declaration.
Craig Toppera13603a2014-05-22 05:54:18 +00001347 if (D->getPreviousDecl() == nullptr) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001348 Writer.AddDeclRef(D->getInstantiatedFromMember(), Record);
1349 Record.push_back(D->isMemberSpecialization());
1350 }
1351
Sebastian Redl539c5062010-08-18 23:57:32 +00001352 Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001353}
1354
Larisse Voufo39a1e502013-08-06 01:03:05 +00001355void ASTDeclWriter::VisitVarTemplateDecl(VarTemplateDecl *D) {
1356 VisitRedeclarableTemplateDecl(D);
1357
Richard Smith509fc852015-02-27 23:05:10 +00001358 if (D->isFirstDecl())
1359 AddTemplateSpecializations(D);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001360 Code = serialization::DECL_VAR_TEMPLATE;
1361}
1362
1363void ASTDeclWriter::VisitVarTemplateSpecializationDecl(
1364 VarTemplateSpecializationDecl *D) {
Richard Smithd8a83712015-08-22 01:47:18 +00001365 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1366
Larisse Voufo39a1e502013-08-06 01:03:05 +00001367 VisitVarDecl(D);
1368
1369 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
1370 InstFrom = D->getSpecializedTemplateOrPartial();
1371 if (Decl *InstFromD = InstFrom.dyn_cast<VarTemplateDecl *>()) {
1372 Writer.AddDeclRef(InstFromD, Record);
1373 } else {
1374 Writer.AddDeclRef(InstFrom.get<VarTemplatePartialSpecializationDecl *>(),
1375 Record);
1376 Writer.AddTemplateArgumentList(&D->getTemplateInstantiationArgs(), Record);
1377 }
1378
1379 // Explicit info.
1380 Writer.AddTypeSourceInfo(D->getTypeAsWritten(), Record);
1381 if (D->getTypeAsWritten()) {
1382 Writer.AddSourceLocation(D->getExternLoc(), Record);
1383 Writer.AddSourceLocation(D->getTemplateKeywordLoc(), Record);
1384 }
1385
1386 Writer.AddTemplateArgumentList(&D->getTemplateArgs(), Record);
1387 Writer.AddSourceLocation(D->getPointOfInstantiation(), Record);
1388 Record.push_back(D->getSpecializationKind());
1389 Record.push_back(D->isCanonicalDecl());
1390
1391 if (D->isCanonicalDecl()) {
1392 // When reading, we'll add it to the folding set of the following template.
1393 Writer.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl(), Record);
1394 }
1395
1396 Code = serialization::DECL_VAR_TEMPLATE_SPECIALIZATION;
1397}
1398
1399void ASTDeclWriter::VisitVarTemplatePartialSpecializationDecl(
1400 VarTemplatePartialSpecializationDecl *D) {
1401 VisitVarTemplateSpecializationDecl(D);
1402
1403 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
Enea Zaffanella6dbe1872013-08-10 07:24:53 +00001404 Writer.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten(), Record);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001405
1406 // These are read/set from/to the first declaration.
Craig Toppera13603a2014-05-22 05:54:18 +00001407 if (D->getPreviousDecl() == nullptr) {
Larisse Voufo39a1e502013-08-06 01:03:05 +00001408 Writer.AddDeclRef(D->getInstantiatedFromMember(), Record);
1409 Record.push_back(D->isMemberSpecialization());
1410 }
1411
1412 Code = serialization::DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION;
1413}
1414
Fariborz Jahanian3a039e32011-08-27 20:50:59 +00001415void ASTDeclWriter::VisitClassScopeFunctionSpecializationDecl(
1416 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichet09af8c32011-08-17 01:06:54 +00001417 VisitDecl(D);
1418 Writer.AddDeclRef(D->getSpecialization(), Record);
1419 Code = serialization::DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION;
1420}
1421
1422
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001423void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001424 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001425
Richard Smith509fc852015-02-27 23:05:10 +00001426 if (D->isFirstDecl())
1427 AddTemplateSpecializations(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001428 Code = serialization::DECL_FUNCTION_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001429}
1430
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001431void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001432 VisitTypeDecl(D);
1433
1434 Record.push_back(D->wasDeclaredWithTypename());
Richard Smith8346e522015-06-10 01:47:58 +00001435
1436 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1437 !D->defaultArgumentWasInherited();
1438 Record.push_back(OwnsDefaultArg);
1439 if (OwnsDefaultArg)
Richard Smith1469b912015-06-10 00:29:03 +00001440 Writer.AddTypeSourceInfo(D->getDefaultArgumentInfo(), Record);
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001441
Sebastian Redl539c5062010-08-18 23:57:32 +00001442 Code = serialization::DECL_TEMPLATE_TYPE_PARM;
Chris Lattnerca025db2010-05-07 21:43:38 +00001443}
1444
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001445void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001446 // For an expanded parameter pack, record the number of expansion types here
Richard Smith1fde8ec2012-09-07 02:06:42 +00001447 // so that it's easier for deserialization to allocate the right amount of
1448 // memory.
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001449 if (D->isExpandedParameterPack())
1450 Record.push_back(D->getNumExpansionTypes());
1451
John McCallf4cd4f92011-02-09 01:13:10 +00001452 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001453 // TemplateParmPosition.
1454 Record.push_back(D->getDepth());
1455 Record.push_back(D->getPosition());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001456
1457 if (D->isExpandedParameterPack()) {
1458 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
1459 Writer.AddTypeRef(D->getExpansionType(I), Record);
1460 Writer.AddTypeSourceInfo(D->getExpansionTypeSourceInfo(I), Record);
1461 }
1462
1463 Code = serialization::DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK;
1464 } else {
1465 // Rest of NonTypeTemplateParmDecl.
1466 Record.push_back(D->isParameterPack());
Richard Smith8346e522015-06-10 01:47:58 +00001467 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1468 !D->defaultArgumentWasInherited();
1469 Record.push_back(OwnsDefaultArg);
1470 if (OwnsDefaultArg)
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001471 Writer.AddStmt(D->getDefaultArgument());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001472 Code = serialization::DECL_NON_TYPE_TEMPLATE_PARM;
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001473 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001474}
1475
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001476void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Richard Smith1fde8ec2012-09-07 02:06:42 +00001477 // For an expanded parameter pack, record the number of expansion types here
1478 // so that it's easier for deserialization to allocate the right amount of
1479 // memory.
1480 if (D->isExpandedParameterPack())
1481 Record.push_back(D->getNumExpansionTemplateParameters());
1482
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001483 VisitTemplateDecl(D);
1484 // TemplateParmPosition.
1485 Record.push_back(D->getDepth());
1486 Record.push_back(D->getPosition());
Richard Smith1fde8ec2012-09-07 02:06:42 +00001487
1488 if (D->isExpandedParameterPack()) {
1489 for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
1490 I != N; ++I)
1491 Writer.AddTemplateParameterList(D->getExpansionTemplateParameters(I),
1492 Record);
1493 Code = serialization::DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK;
1494 } else {
1495 // Rest of TemplateTemplateParmDecl.
Richard Smith1fde8ec2012-09-07 02:06:42 +00001496 Record.push_back(D->isParameterPack());
Richard Smith8346e522015-06-10 01:47:58 +00001497 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1498 !D->defaultArgumentWasInherited();
1499 Record.push_back(OwnsDefaultArg);
1500 if (OwnsDefaultArg)
Richard Smith1469b912015-06-10 00:29:03 +00001501 Writer.AddTemplateArgumentLoc(D->getDefaultArgument(), Record);
Richard Smith1fde8ec2012-09-07 02:06:42 +00001502 Code = serialization::DECL_TEMPLATE_TEMPLATE_PARM;
1503 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001504}
1505
Richard Smith3f1b5d02011-05-05 21:57:07 +00001506void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1507 VisitRedeclarableTemplateDecl(D);
1508 Code = serialization::DECL_TYPE_ALIAS_TEMPLATE;
1509}
1510
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001511void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001512 VisitDecl(D);
1513 Writer.AddStmt(D->getAssertExpr());
Richard Smithded9c2e2012-07-11 22:37:56 +00001514 Record.push_back(D->isFailed());
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001515 Writer.AddStmt(D->getMessage());
Abramo Bagnaraea947882011-03-08 16:41:52 +00001516 Writer.AddSourceLocation(D->getRParenLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001517 Code = serialization::DECL_STATIC_ASSERT;
Chris Lattnerca025db2010-05-07 21:43:38 +00001518}
1519
Chris Lattner7099dbc2009-04-27 06:16:06 +00001520/// \brief Emit the DeclContext part of a declaration context decl.
1521///
1522/// \param LexicalOffset the offset at which the DECL_CONTEXT_LEXICAL
1523/// block for this declaration context is stored. May be 0 to indicate
1524/// that there are no declarations stored within this context.
1525///
1526/// \param VisibleOffset the offset at which the DECL_CONTEXT_VISIBLE
1527/// block for this declaration context is stored. May be 0 to indicate
1528/// that there are no declarations visible from this context. Note
1529/// that this value will not be emitted for non-primary declaration
1530/// contexts.
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001531void ASTDeclWriter::VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset,
Chris Lattner7099dbc2009-04-27 06:16:06 +00001532 uint64_t VisibleOffset) {
1533 Record.push_back(LexicalOffset);
1534 Record.push_back(VisibleOffset);
1535}
1536
Richard Smithd8a83712015-08-22 01:47:18 +00001537const Decl *ASTWriter::getFirstLocalDecl(const Decl *D) {
Richard Smith3864be72015-09-11 02:22:03 +00001538 /// \brief Is this a local declaration (that is, one that will be written to
1539 /// our AST file)? This is the case for declarations that are neither imported
1540 /// from another AST file nor predefined.
1541 auto IsLocalDecl = [&](const Decl *D) -> bool {
1542 if (D->isFromASTFile())
1543 return false;
1544 auto I = DeclIDs.find(D);
1545 return (I == DeclIDs.end() || I->second >= NUM_PREDEF_DECL_IDS);
1546 };
1547
1548 assert(IsLocalDecl(D) && "expected a local declaration");
Richard Smithd8a83712015-08-22 01:47:18 +00001549
1550 const Decl *Canon = D->getCanonicalDecl();
Richard Smith3864be72015-09-11 02:22:03 +00001551 if (IsLocalDecl(Canon))
Richard Smithd8a83712015-08-22 01:47:18 +00001552 return Canon;
1553
1554 const Decl *&CacheEntry = FirstLocalDeclCache[Canon];
1555 if (CacheEntry)
1556 return CacheEntry;
1557
1558 for (const Decl *Redecl = D; Redecl; Redecl = Redecl->getPreviousDecl())
Richard Smith3864be72015-09-11 02:22:03 +00001559 if (IsLocalDecl(Redecl))
Richard Smithd8a83712015-08-22 01:47:18 +00001560 D = Redecl;
1561 return CacheEntry = D;
Richard Smith5fc18a92015-07-12 23:43:21 +00001562}
1563
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001564template <typename T>
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001565void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +00001566 T *First = D->getFirstDecl();
Richard Smith5a4737c2015-02-06 02:42:59 +00001567 T *MostRecent = First->getMostRecentDecl();
Richard Smithd8a83712015-08-22 01:47:18 +00001568 T *DAsT = static_cast<T *>(D);
Richard Smith5a4737c2015-02-06 02:42:59 +00001569 if (MostRecent != First) {
Richard Smithd8a83712015-08-22 01:47:18 +00001570 assert(isRedeclarableDeclKind(DAsT->getKind()) &&
Douglas Gregorfe732d52013-01-21 16:16:40 +00001571 "Not considered redeclarable?");
Richard Smith5a4737c2015-02-06 02:42:59 +00001572
Richard Smithfe620d22015-03-05 23:24:12 +00001573 Writer.AddDeclRef(First, Record);
Richard Smithfe620d22015-03-05 23:24:12 +00001574
Richard Smithd8a83712015-08-22 01:47:18 +00001575 // Write out a list of local redeclarations of this declaration if it's the
1576 // first local declaration in the chain.
1577 const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1578 if (DAsT == FirstLocal) {
Richard Smithd8a83712015-08-22 01:47:18 +00001579 // Emit a list of all imported first declarations so that we can be sure
1580 // that all redeclarations visible to this module are before D in the
1581 // redecl chain.
1582 unsigned I = Record.size();
1583 Record.push_back(0);
1584 if (Writer.Chain)
1585 AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1586 // This is the number of imported first declarations + 1.
1587 Record[I] = Record.size() - I;
Richard Smithd61d4ac2015-08-22 20:13:39 +00001588
1589 // Collect the set of local redeclarations of this declaration, from
1590 // newest to oldest.
1591 RecordData LocalRedecls;
1592 for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1593 Prev != FirstLocal; Prev = Prev->getPreviousDecl())
1594 if (!Prev->isFromASTFile())
1595 Writer.AddDeclRef(Prev, LocalRedecls);
1596
1597 // If we have any redecls, write them now as a separate record preceding
1598 // the declaration itself.
1599 if (LocalRedecls.empty())
1600 Record.push_back(0);
1601 else {
1602 Record.push_back(Writer.Stream.GetCurrentBitNo());
1603 Writer.Stream.EmitRecord(LOCAL_REDECLARATIONS, LocalRedecls);
1604 }
Richard Smithd8a83712015-08-22 01:47:18 +00001605 } else {
1606 Record.push_back(0);
1607 Writer.AddDeclRef(FirstLocal, Record);
Richard Smithfe620d22015-03-05 23:24:12 +00001608 }
Douglas Gregor358cd442012-01-15 16:58:34 +00001609
1610 // Make sure that we serialize both the previous and the most-recent
1611 // declarations, which (transitively) ensures that all declarations in the
1612 // chain get serialized.
Richard Smith5a4737c2015-02-06 02:42:59 +00001613 //
1614 // FIXME: This is not correct; when we reach an imported declaration we
1615 // won't emit its previous declaration.
Richard Smith5fc18a92015-07-12 23:43:21 +00001616 (void)Writer.GetDeclRef(D->getPreviousDecl());
Richard Smith5a4737c2015-02-06 02:42:59 +00001617 (void)Writer.GetDeclRef(MostRecent);
Douglas Gregor358cd442012-01-15 16:58:34 +00001618 } else {
1619 // We use the sentinel value 0 to indicate an only declaration.
1620 Record.push_back(0);
Douglas Gregor9f562c82011-12-19 15:27:36 +00001621 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001622}
Chris Lattner7099dbc2009-04-27 06:16:06 +00001623
Alexey Bataeva769e072013-03-22 06:34:35 +00001624void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
1625 Record.push_back(D->varlist_size());
1626 VisitDecl(D);
Aaron Ballman2205d2a2014-03-14 15:55:35 +00001627 for (auto *I : D->varlists())
1628 Writer.AddStmt(I);
Alexey Bataeva769e072013-03-22 06:34:35 +00001629 Code = serialization::DECL_OMP_THREADPRIVATE;
1630}
1631
Alexey Bataev4244be22016-02-11 05:35:55 +00001632void ASTDeclWriter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
Alexey Bataev90c228f2016-02-08 09:29:13 +00001633 VisitVarDecl(D);
Alexey Bataev4244be22016-02-11 05:35:55 +00001634 Code = serialization::DECL_OMP_CAPTUREDEXPR;
Alexey Bataev90c228f2016-02-08 09:29:13 +00001635}
1636
Chris Lattner7099dbc2009-04-27 06:16:06 +00001637//===----------------------------------------------------------------------===//
Sebastian Redl55c0ad52010-08-18 23:56:21 +00001638// ASTWriter Implementation
Chris Lattner7099dbc2009-04-27 06:16:06 +00001639//===----------------------------------------------------------------------===//
1640
Richard Smith01b2cb42014-07-26 06:37:51 +00001641void ASTWriter::WriteDeclAbbrevs() {
Chris Lattner258172e2009-04-27 07:35:58 +00001642 using namespace llvm;
Chris Lattner258172e2009-04-27 07:35:58 +00001643
Douglas Gregor03412ba2011-06-03 02:27:19 +00001644 BitCodeAbbrev *Abv;
1645
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001646 // Abbreviation for DECL_FIELD
1647 Abv = new BitCodeAbbrev();
1648 Abv->Add(BitCodeAbbrevOp(serialization::DECL_FIELD));
1649 // Decl
1650 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001651 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001652 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001653 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1654 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1655 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1656 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001657 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001658 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001659 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001660 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001661 // NamedDecl
1662 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1663 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001664 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001665 // ValueDecl
1666 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1667 // DeclaratorDecl
1668 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1669 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
1670 // FieldDecl
1671 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
1672 Abv->Add(BitCodeAbbrevOp(0)); //getBitWidth
1673 // Type Source Info
1674 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1675 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1676 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1677 DeclFieldAbbrev = Stream.EmitAbbrev(Abv);
1678
1679 // Abbreviation for DECL_OBJC_IVAR
1680 Abv = new BitCodeAbbrev();
1681 Abv->Add(BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR));
1682 // Decl
1683 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001684 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001685 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001686 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1687 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1688 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1689 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001690 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001691 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001692 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001693 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001694 // NamedDecl
1695 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1696 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001697 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001698 // ValueDecl
1699 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1700 // DeclaratorDecl
1701 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1702 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
1703 // FieldDecl
1704 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
1705 Abv->Add(BitCodeAbbrevOp(0)); //getBitWidth
1706 // ObjC Ivar
1707 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl
1708 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize
1709 // Type Source Info
1710 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1711 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1712 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1713 DeclObjCIvarAbbrev = Stream.EmitAbbrev(Abv);
1714
1715 // Abbreviation for DECL_ENUM
1716 Abv = new BitCodeAbbrev();
1717 Abv->Add(BitCodeAbbrevOp(serialization::DECL_ENUM));
Douglas Gregor3e300102011-10-26 17:53:41 +00001718 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001719 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Chris Lattner258172e2009-04-27 07:35:58 +00001720 // Decl
1721 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001722 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001723 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Chris Lattner258172e2009-04-27 07:35:58 +00001724 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1725 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
Douglas Gregorc9c02ed2009-06-19 23:52:42 +00001726 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +00001727 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001728 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Chris Lattner258172e2009-04-27 07:35:58 +00001729 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001730 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001731 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Douglas Gregor03412ba2011-06-03 02:27:19 +00001732 // NamedDecl
1733 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1734 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001735 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001736 // TypeDecl
1737 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1738 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001739 // TagDecl
1740 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
1741 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
John McCallf937c022011-10-07 06:10:15 +00001742 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001743 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +00001744 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
David Blaikiea8d23ce2013-07-14 01:07:41 +00001745 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001746 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Richard Smith70d58502014-08-30 00:04:23 +00001747 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001748 // EnumDecl
1749 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddTypeRef
1750 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IntegerType
1751 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getPromotionType
1752 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumPositiveBits
1753 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumNegativeBits
1754 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScoped
1755 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScopedUsingClassTag
1756 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isFixed
1757 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedMembEnum
1758 // DC
1759 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
1760 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
1761 DeclEnumAbbrev = Stream.EmitAbbrev(Abv);
Mike Stump11289f42009-09-09 15:08:12 +00001762
Douglas Gregor03412ba2011-06-03 02:27:19 +00001763 // Abbreviation for DECL_RECORD
1764 Abv = new BitCodeAbbrev();
1765 Abv->Add(BitCodeAbbrevOp(serialization::DECL_RECORD));
Douglas Gregor3e300102011-10-26 17:53:41 +00001766 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001767 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Douglas Gregor03412ba2011-06-03 02:27:19 +00001768 // Decl
1769 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001770 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001771 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Douglas Gregor03412ba2011-06-03 02:27:19 +00001772 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1773 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1774 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1775 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001776 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Douglas Gregor03412ba2011-06-03 02:27:19 +00001777 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001778 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001779 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Douglas Gregor03412ba2011-06-03 02:27:19 +00001780 // NamedDecl
1781 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1782 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001783 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Douglas Gregor03412ba2011-06-03 02:27:19 +00001784 // TypeDecl
1785 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1786 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
Douglas Gregor03412ba2011-06-03 02:27:19 +00001787 // TagDecl
1788 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
1789 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
John McCallf937c022011-10-07 06:10:15 +00001790 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
Douglas Gregor03412ba2011-06-03 02:27:19 +00001791 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +00001792 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
David Blaikiea8d23ce2013-07-14 01:07:41 +00001793 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
Douglas Gregor03412ba2011-06-03 02:27:19 +00001794 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Richard Smith70d58502014-08-30 00:04:23 +00001795 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
Douglas Gregor03412ba2011-06-03 02:27:19 +00001796 // RecordDecl
1797 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // FlexibleArrayMember
1798 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // AnonymousStructUnion
1799 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasObjectMember
Fariborz Jahanian78652202013-01-25 23:57:05 +00001800 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasVolatileMember
Douglas Gregor03412ba2011-06-03 02:27:19 +00001801 // DC
1802 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
1803 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
1804 DeclRecordAbbrev = Stream.EmitAbbrev(Abv);
1805
1806 // Abbreviation for DECL_PARM_VAR
1807 Abv = new BitCodeAbbrev();
1808 Abv->Add(BitCodeAbbrevOp(serialization::DECL_PARM_VAR));
Douglas Gregor3e300102011-10-26 17:53:41 +00001809 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001810 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Douglas Gregor03412ba2011-06-03 02:27:19 +00001811 // Decl
1812 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001813 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001814 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Douglas Gregor03412ba2011-06-03 02:27:19 +00001815 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1816 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1817 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1818 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001819 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Douglas Gregor03412ba2011-06-03 02:27:19 +00001820 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001821 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001822 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Chris Lattner258172e2009-04-27 07:35:58 +00001823 // NamedDecl
1824 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1825 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001826 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Chris Lattner258172e2009-04-27 07:35:58 +00001827 // ValueDecl
1828 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +00001829 // DeclaratorDecl
Abramo Bagnaradff19302011-03-08 08:55:46 +00001830 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00001831 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Chris Lattner258172e2009-04-27 07:35:58 +00001832 // VarDecl
1833 Abv->Add(BitCodeAbbrevOp(0)); // StorageClass
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +00001834 Abv->Add(BitCodeAbbrevOp(0)); // getTSCSpec
Chris Lattner258172e2009-04-27 07:35:58 +00001835 Abv->Add(BitCodeAbbrevOp(0)); // hasCXXDirectInitializer
Richard Smith88581592013-02-12 05:48:23 +00001836 Abv->Add(BitCodeAbbrevOp(0)); // Linkage
Chris Lattner258172e2009-04-27 07:35:58 +00001837 Abv->Add(BitCodeAbbrevOp(0)); // HasInit
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001838 Abv->Add(BitCodeAbbrevOp(0)); // HasMemberSpecializationInfo
Chris Lattner258172e2009-04-27 07:35:58 +00001839 // ParmVarDecl
John McCall82490832011-05-02 00:30:12 +00001840 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsObjCMethodParameter
John McCall8fb0d9d2011-05-01 22:35:37 +00001841 Abv->Add(BitCodeAbbrevOp(0)); // ScopeDepth
1842 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex
Chris Lattner258172e2009-04-27 07:35:58 +00001843 Abv->Add(BitCodeAbbrevOp(0)); // ObjCDeclQualifier
John McCall6a014d52011-03-09 04:22:44 +00001844 Abv->Add(BitCodeAbbrevOp(0)); // KNRPromoted
John McCallf3cd6652010-03-12 18:31:32 +00001845 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedDefaultArg
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +00001846 Abv->Add(BitCodeAbbrevOp(0)); // HasUninstantiatedDefaultArg
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001847 // Type Source Info
1848 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1849 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1850 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1851 DeclParmVarAbbrev = Stream.EmitAbbrev(Abv);
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001852
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00001853 // Abbreviation for DECL_TYPEDEF
Douglas Gregor03412ba2011-06-03 02:27:19 +00001854 Abv = new BitCodeAbbrev();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001855 Abv->Add(BitCodeAbbrevOp(serialization::DECL_TYPEDEF));
Douglas Gregor05f10352011-12-17 23:38:30 +00001856 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001857 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001858 // Decl
1859 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001860 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001861 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001862 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1863 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
Richard Smith01b2cb42014-07-26 06:37:51 +00001864 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isUsed
1865 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001866 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Richard Smith01b2cb42014-07-26 06:37:51 +00001867 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001868 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001869 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001870 // NamedDecl
1871 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1872 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001873 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001874 // TypeDecl
1875 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1876 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
1877 // TypedefDecl
1878 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1879 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1880 DeclTypedefAbbrev = Stream.EmitAbbrev(Abv);
1881
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00001882 // Abbreviation for DECL_VAR
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001883 Abv = new BitCodeAbbrev();
1884 Abv->Add(BitCodeAbbrevOp(serialization::DECL_VAR));
Douglas Gregor3e300102011-10-26 17:53:41 +00001885 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001886 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001887 // Decl
1888 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001889 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001890 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001891 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1892 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1893 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1894 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001895 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001896 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001897 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001898 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001899 // NamedDecl
1900 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1901 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001902 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001903 // ValueDecl
1904 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1905 // DeclaratorDecl
1906 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1907 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
1908 // VarDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001909 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // StorageClass
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +00001910 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // getTSCSpec
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001911 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // CXXDirectInitializer
1912 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isExceptionVariable
1913 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isNRVOVariable
1914 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCXXForRangeDecl
John McCalld4631322011-06-17 06:42:21 +00001915 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong
Douglas Gregor12cda632012-09-20 23:43:29 +00001916 Abv->Add(BitCodeAbbrevOp(0)); // isConstexpr
Richard Smithbb13c9a2013-09-28 04:02:39 +00001917 Abv->Add(BitCodeAbbrevOp(0)); // isInitCapture
Richard Smith1c34fb72013-08-13 18:18:50 +00001918 Abv->Add(BitCodeAbbrevOp(0)); // isPrevDeclInSameScope
Rafael Espindola50df3a02013-05-25 17:16:20 +00001919 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001920 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasInit
1921 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasMemberSpecInfo
1922 // Type Source Info
1923 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1924 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1925 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1926 DeclVarAbbrev = Stream.EmitAbbrev(Abv);
1927
Richard Smith01b2cb42014-07-26 06:37:51 +00001928 // Abbreviation for DECL_CXX_METHOD
1929 Abv = new BitCodeAbbrev();
1930 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CXX_METHOD));
1931 // RedeclarableDecl
1932 Abv->Add(BitCodeAbbrevOp(0)); // CanonicalDecl
1933 // Decl
1934 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001935 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Richard Smith01b2cb42014-07-26 06:37:51 +00001936 Abv->Add(BitCodeAbbrevOp(0)); // Invalid
1937 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1938 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Implicit
1939 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Used
1940 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Referenced
1941 Abv->Add(BitCodeAbbrevOp(0)); // InObjCContainer
1942 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Access
1943 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ModulePrivate
1944 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
1945 // NamedDecl
1946 Abv->Add(BitCodeAbbrevOp(DeclarationName::Identifier)); // NameKind
1947 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Identifier
Richard Smith2b560572015-02-07 03:11:11 +00001948 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Richard Smith01b2cb42014-07-26 06:37:51 +00001949 // ValueDecl
1950 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1951 // DeclaratorDecl
1952 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerLocStart
1953 Abv->Add(BitCodeAbbrevOp(0)); // HasExtInfo
1954 // FunctionDecl
1955 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS
1956 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // StorageClass
1957 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Inline
1958 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InlineSpecified
1959 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // VirtualAsWritten
1960 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Pure
1961 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedProto
1962 Abv->Add(BitCodeAbbrevOp(1)); // HasWrittenProto
Richard Smith72625c22015-02-06 23:20:21 +00001963 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Deleted
Richard Smith01b2cb42014-07-26 06:37:51 +00001964 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Trivial
1965 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Defaulted
1966 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ExplicitlyDefaulted
1967 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ImplicitReturnZero
1968 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Constexpr
1969 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // SkippedBody
1970 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // LateParsed
1971 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
1972 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LocEnd
1973 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // TemplateKind
1974 // This Array slurps the rest of the record. Fortunately we want to encode
1975 // (nearly) all the remaining (variable number of) fields in the same way.
1976 //
1977 // This is the function template information if any, then
1978 // NumParams and Params[] from FunctionDecl, and
1979 // NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl.
1980 //
1981 // Add an AbbrevOp for 'size then elements' and use it here.
1982 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1983 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1984 DeclCXXMethodAbbrev = Stream.EmitAbbrev(Abv);
1985
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00001986 // Abbreviation for EXPR_DECL_REF
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001987 Abv = new BitCodeAbbrev();
Douglas Gregor03412ba2011-06-03 02:27:19 +00001988 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_DECL_REF));
1989 //Stmt
1990 //Expr
1991 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00001992 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
1993 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
1994 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00001995 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
1996 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
1997 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
1998 //DeclRefExpr
1999 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HasQualifier
2000 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //GetDeclFound
2001 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ExplicitTemplateArgs
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002002 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HadMultipleCandidates
Alexey Bataev19acc3d2015-01-12 10:17:46 +00002003 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2004 1)); // RefersToEnclosingVariableOrCapture
Douglas Gregor03412ba2011-06-03 02:27:19 +00002005 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef
2006 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2007 DeclRefExprAbbrev = Stream.EmitAbbrev(Abv);
2008
2009 // Abbreviation for EXPR_INTEGER_LITERAL
2010 Abv = new BitCodeAbbrev();
2011 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL));
2012 //Stmt
2013 //Expr
2014 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002015 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2016 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2017 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002018 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2019 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2020 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2021 //Integer Literal
2022 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2023 Abv->Add(BitCodeAbbrevOp(32)); // Bit Width
2024 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value
2025 IntegerLiteralAbbrev = Stream.EmitAbbrev(Abv);
2026
2027 // Abbreviation for EXPR_CHARACTER_LITERAL
2028 Abv = new BitCodeAbbrev();
2029 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL));
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
Jonathan D. Turnerd09655f2011-06-03 21:46:44 +00002039 //Character Literal
Douglas Gregor03412ba2011-06-03 02:27:19 +00002040 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue
2041 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
Aaron Ballman9a17c852016-01-07 20:59:26 +00002042 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // getKind
Douglas Gregor03412ba2011-06-03 02:27:19 +00002043 CharacterLiteralAbbrev = Stream.EmitAbbrev(Abv);
2044
Richard Smitha27c26e2014-07-27 04:19:32 +00002045 // Abbreviation for EXPR_IMPLICIT_CAST
2046 Abv = new BitCodeAbbrev();
2047 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_IMPLICIT_CAST));
2048 // Stmt
2049 // Expr
2050 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2051 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2052 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2053 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
2054 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2055 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2056 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2057 // CastExpr
2058 Abv->Add(BitCodeAbbrevOp(0)); // PathSize
2059 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 6)); // CastKind
2060 // ImplicitCastExpr
2061 ExprImplicitCastAbbrev = Stream.EmitAbbrev(Abv);
2062
Sebastian Redl66c5eef2010-07-27 00:17:23 +00002063 Abv = new BitCodeAbbrev();
Sebastian Redl539c5062010-08-18 23:57:32 +00002064 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL));
Sebastian Redl66c5eef2010-07-27 00:17:23 +00002065 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2066 DeclContextLexicalAbbrev = Stream.EmitAbbrev(Abv);
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002067
2068 Abv = new BitCodeAbbrev();
2069 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE));
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002070 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2071 DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(Abv);
Chris Lattner258172e2009-04-27 07:35:58 +00002072}
2073
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002074/// isRequiredDecl - Check if this is a "required" Decl, which must be seen by
2075/// consumers of the AST.
2076///
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002077/// Such decls will always be deserialized from the AST file, so we would like
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002078/// this to be as restrictive as possible. Currently the predicate is driven by
2079/// code generation requirements, if other clients have a different notion of
2080/// what is "required" then we may have to consider an alternate scheme where
2081/// clients can iterate over the top-level decls and get information on them,
2082/// without necessary deserializing them. We could explicitly require such
2083/// clients to use a separate API call to "realize" the decl. This should be
2084/// relatively painless since they would presumably only do it for top-level
2085/// decls.
Richard Smithc52efa72015-08-19 02:30:28 +00002086static bool isRequiredDecl(const Decl *D, ASTContext &Context,
2087 bool WritingModule) {
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00002088 // An ObjCMethodDecl is never considered as "required" because its
2089 // implementation container always is.
2090
Richard Smithc52efa72015-08-19 02:30:28 +00002091 // File scoped assembly or obj-c implementation must be seen.
2092 if (isa<FileScopeAsmDecl>(D) || isa<ObjCImplDecl>(D))
2093 return true;
2094
2095 // ImportDecl is used by codegen to determine the set of imported modules to
2096 // search for inputs for automatic linking; include it if it has a semantic
2097 // effect.
2098 if (isa<ImportDecl>(D) && !WritingModule)
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002099 return true;
2100
Argyrios Kyrtzidisc9049332010-07-29 20:08:05 +00002101 return Context.DeclMustBeEmitted(D);
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002102}
2103
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002104void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) {
Argyrios Kyrtzidisd9f526f2010-10-28 09:29:32 +00002105 // Switch case IDs are per Decl.
2106 ClearSwitchCaseIDs();
2107
Chris Lattner7099dbc2009-04-27 06:16:06 +00002108 RecordData Record;
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002109 ASTDeclWriter W(*this, Context, Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +00002110
Douglas Gregorb3163e52012-01-05 22:33:30 +00002111 // Determine the ID for this declaration.
2112 serialization::DeclID ID;
Douglas Gregor7dd37e52015-11-03 01:20:54 +00002113 assert(!D->isFromASTFile() && "should not be emitting imported decl");
2114 serialization::DeclID &IDR = DeclIDs[D];
2115 if (IDR == 0)
2116 IDR = NextDeclID++;
Douglas Gregorb3163e52012-01-05 22:33:30 +00002117
Douglas Gregor7dd37e52015-11-03 01:20:54 +00002118 ID = IDR;
Argyrios Kyrtzidisbf6c3392012-03-22 16:08:04 +00002119
2120 bool isReplacingADecl = ID < FirstDeclID;
2121
2122 // If this declaration is also a DeclContext, write blocks for the
2123 // declarations that lexically stored inside its context and those
2124 // declarations that are visible from its context. These blocks
2125 // are written before the declaration itself so that we can put
2126 // their offsets into the record for the declaration.
2127 uint64_t LexicalOffset = 0;
2128 uint64_t VisibleOffset = 0;
2129 DeclContext *DC = dyn_cast<DeclContext>(D);
2130 if (DC) {
2131 if (isReplacingADecl) {
2132 // It is replacing a decl from a chained PCH; make sure that the
2133 // DeclContext is fully loaded.
2134 if (DC->hasExternalLexicalStorage())
2135 DC->LoadLexicalDeclsFromExternalStorage();
2136 if (DC->hasExternalVisibleStorage())
2137 Chain->completeVisibleDeclsMap(DC);
2138 }
2139 LexicalOffset = WriteDeclContextLexicalBlock(Context, DC);
2140 VisibleOffset = WriteDeclContextVisibleBlock(Context, DC);
2141 }
Douglas Gregorb3163e52012-01-05 22:33:30 +00002142
Richard Smithd61d4ac2015-08-22 20:13:39 +00002143 // Build a record for this declaration
2144 Record.clear();
2145 W.Code = (serialization::DeclCode)0;
2146 W.AbbrevToUse = 0;
2147 W.Visit(D);
2148 if (DC) W.VisitDeclContext(DC, LexicalOffset, VisibleOffset);
2149
Argyrios Kyrtzidisbf6c3392012-03-22 16:08:04 +00002150 if (isReplacingADecl) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002151 // We're replacing a decl in a previous file.
Argyrios Kyrtzidis6fb60032011-10-31 07:20:15 +00002152 ReplacedDecls.push_back(ReplacedDeclInfo(ID, Stream.GetCurrentBitNo(),
2153 D->getLocation()));
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002154 } else {
2155 unsigned Index = ID - FirstDeclID;
Douglas Gregor12bfa382009-10-17 00:13:19 +00002156
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002157 // Record the offset for this declaration
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +00002158 SourceLocation Loc = D->getLocation();
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002159 if (DeclOffsets.size() == Index)
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +00002160 DeclOffsets.push_back(DeclOffset(Loc, Stream.GetCurrentBitNo()));
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002161 else if (DeclOffsets.size() < Index) {
2162 DeclOffsets.resize(Index+1);
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +00002163 DeclOffsets[Index].setLocation(Loc);
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00002164 DeclOffsets[Index].BitOffset = Stream.GetCurrentBitNo();
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002165 }
Richard Smithd61d4ac2015-08-22 20:13:39 +00002166
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +00002167 SourceManager &SM = Context.getSourceManager();
Argyrios Kyrtzidisdf53da82011-10-28 23:57:43 +00002168 if (Loc.isValid() && SM.isLocalSourceLocation(Loc))
2169 associateDeclWithFile(D, ID);
Douglas Gregor12bfa382009-10-17 00:13:19 +00002170 }
2171
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +00002172 if (!W.Code)
Chris Lattner0e62c1c2011-07-23 10:55:15 +00002173 llvm::report_fatal_error(StringRef("unexpected declaration kind '") +
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +00002174 D->getDeclKindName() + "'");
Douglas Gregor12bfa382009-10-17 00:13:19 +00002175 Stream.EmitRecord(W.Code, Record, W.AbbrevToUse);
2176
Richard Smithc2bb8182015-03-24 06:36:48 +00002177 // Flush any expressions, base specifiers, and ctor initializers that
2178 // were written as part of this declaration.
2179 FlushPendingAfterDecl();
2180
Ben Langmuir332aafe2014-01-31 01:06:56 +00002181 // Note declarations that should be deserialized eagerly so that we can add
2182 // them to a record in the AST file later.
Richard Smithc52efa72015-08-19 02:30:28 +00002183 if (isRequiredDecl(D, Context, WritingModule))
Ben Langmuir332aafe2014-01-31 01:06:56 +00002184 EagerlyDeserializedDecls.push_back(ID);
Chris Lattner7099dbc2009-04-27 06:16:06 +00002185}
Richard Smithd28ac5b2014-03-22 23:33:22 +00002186
2187void ASTWriter::AddFunctionDefinition(const FunctionDecl *FD,
2188 RecordData &Record) {
2189 ClearSwitchCaseIDs();
2190
2191 ASTDeclWriter W(*this, FD->getASTContext(), Record);
2192 W.AddFunctionDefinition(FD);
2193}