blob: 3f8ddf1292e23ec9af38288e38f0c0e260c6ceb2 [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);
Richard Smithd28ac5b2014-03-22 23:33:22 +0000134
Douglas Gregor85f3f952015-07-07 03:57:15 +0000135 /// Add an Objective-C type parameter list to the given record.
136 void AddObjCTypeParamList(ObjCTypeParamList *typeParams) {
137 // Empty type parameter list.
138 if (!typeParams) {
139 Record.push_back(0);
140 return;
141 }
142
143 Record.push_back(typeParams->size());
144 for (auto typeParam : *typeParams) {
145 Writer.AddDeclRef(typeParam, Record);
146 }
147 Writer.AddSourceLocation(typeParams->getLAngleLoc(), Record);
148 Writer.AddSourceLocation(typeParams->getRAngleLoc(), Record);
149 }
150
Richard Smithd28ac5b2014-03-22 23:33:22 +0000151 void AddFunctionDefinition(const FunctionDecl *FD) {
152 assert(FD->doesThisDeclarationHaveABody());
Richard Smithc2bb8182015-03-24 06:36:48 +0000153 if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
154 Record.push_back(CD->NumCtorInitializers);
155 if (CD->NumCtorInitializers)
156 Writer.AddCXXCtorInitializersRef(
157 llvm::makeArrayRef(CD->init_begin(), CD->init_end()), Record);
158 }
Richard Smithd28ac5b2014-03-22 23:33:22 +0000159 Writer.AddStmt(FD->getBody());
160 }
Richard Smith509fc852015-02-27 23:05:10 +0000161
Richard Smithd8a83712015-08-22 01:47:18 +0000162 /// Add to the record the first declaration from each module file that
163 /// provides a declaration of D. The intent is to provide a sufficient
164 /// set such that reloading this set will load all current redeclarations.
165 void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) {
166 llvm::MapVector<ModuleFile*, const Decl*> Firsts;
167 // FIXME: We can skip entries that we know are implied by others.
168 for (const Decl *R = D->getMostRecentDecl(); R; R = R->getPreviousDecl())
169 if (IncludeLocal || R->isFromASTFile())
170 Firsts[Writer.Chain->getOwningModuleFile(R)] = R;
171 for (const auto &F : Firsts)
172 Writer.AddDeclRef(F.second, Record);
173 }
174
Richard Smith509fc852015-02-27 23:05:10 +0000175 /// Get the specialization decl from an entry in the specialization list.
176 template <typename EntryType>
177 typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType *
178 getSpecializationDecl(EntryType &T) {
179 return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T);
180 }
181
182 /// Get the list of partial specializations from a template's common ptr.
183 template<typename T>
184 decltype(T::PartialSpecializations) &getPartialSpecializations(T *Common) {
185 return Common->PartialSpecializations;
186 }
187 ArrayRef<Decl> getPartialSpecializations(FunctionTemplateDecl::Common *) {
188 return None;
189 }
190
191 template<typename Decl>
192 void AddTemplateSpecializations(Decl *D) {
193 auto *Common = D->getCommonPtr();
194
195 // If we have any lazy specializations, and the external AST source is
196 // our chained AST reader, we can just write out the DeclIDs. Otherwise,
197 // we need to resolve them to actual declarations.
198 if (Writer.Chain != Writer.Context->getExternalSource() &&
199 Common->LazySpecializations) {
200 D->LoadLazySpecializations();
201 assert(!Common->LazySpecializations);
202 }
203
204 auto &Specializations = Common->Specializations;
205 auto &&PartialSpecializations = getPartialSpecializations(Common);
206 ArrayRef<DeclID> LazySpecializations;
207 if (auto *LS = Common->LazySpecializations)
208 LazySpecializations = ArrayRef<DeclID>(LS + 1, LS + 1 + LS[0]);
209
Richard Smithd8a83712015-08-22 01:47:18 +0000210 // Add a slot to the record for the number of specializations.
211 unsigned I = Record.size();
212 Record.push_back(0);
213
Richard Smith509fc852015-02-27 23:05:10 +0000214 for (auto &Entry : Specializations) {
215 auto *D = getSpecializationDecl(Entry);
216 assert(D->isCanonicalDecl() && "non-canonical decl in set");
Richard Smithd8a83712015-08-22 01:47:18 +0000217 AddFirstDeclFromEachModule(D, /*IncludeLocal*/true);
Richard Smith509fc852015-02-27 23:05:10 +0000218 }
219 for (auto &Entry : PartialSpecializations) {
220 auto *D = getSpecializationDecl(Entry);
221 assert(D->isCanonicalDecl() && "non-canonical decl in set");
Richard Smithd8a83712015-08-22 01:47:18 +0000222 AddFirstDeclFromEachModule(D, /*IncludeLocal*/true);
Richard Smith509fc852015-02-27 23:05:10 +0000223 }
Benjamin Kramerf367dd92015-06-12 15:31:50 +0000224 Record.append(LazySpecializations.begin(), LazySpecializations.end());
Richard Smithd8a83712015-08-22 01:47:18 +0000225
226 // Update the size entry we added earlier.
227 Record[I] = Record.size() - I - 1;
228 }
229
230 /// Ensure that this template specialization is associated with the specified
231 /// template on reload.
232 void RegisterTemplateSpecialization(const Decl *Template,
233 const Decl *Specialization) {
234 Template = Template->getCanonicalDecl();
235
236 // If the canonical template is local, we'll write out this specialization
237 // when we emit it.
238 // FIXME: We can do the same thing if there is any local declaration of
239 // the template, to avoid emitting an update record.
240 if (!Template->isFromASTFile())
241 return;
242
243 // We only need to associate the first local declaration of the
244 // specialization. The other declarations will get pulled in by it.
245 if (Writer.getFirstLocalDecl(Specialization) != Specialization)
246 return;
247
248 Writer.DeclUpdates[Template].push_back(ASTWriter::DeclUpdate(
249 UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION, Specialization));
Richard Smith509fc852015-02-27 23:05:10 +0000250 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000251 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000252}
Chris Lattner7099dbc2009-04-27 06:16:06 +0000253
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000254void ASTDeclWriter::Visit(Decl *D) {
255 DeclVisitor<ASTDeclWriter>::Visit(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000256
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000257 // Source locations require array (variable-length) abbreviations. The
258 // abbreviation infrastructure requires that arrays are encoded last, so
259 // we handle it here in the case of those classes derived from DeclaratorDecl
260 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)){
261 Writer.AddTypeSourceInfo(DD->getTypeSourceInfo(), Record);
262 }
263
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000264 // Handle FunctionDecl's body here and write it after all other Stmts/Exprs
265 // have been written. We want it last because we will not read it back when
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000266 // retrieving it from the AST, we'll just lazily set the offset.
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000267 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
Alexis Hunt4a8ea102011-05-06 20:44:56 +0000268 Record.push_back(FD->doesThisDeclarationHaveABody());
269 if (FD->doesThisDeclarationHaveABody())
Richard Smithc2bb8182015-03-24 06:36:48 +0000270 AddFunctionDefinition(FD);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000271 }
272}
273
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000274void ASTDeclWriter::VisitDecl(Decl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000275 Writer.AddDeclRef(cast_or_null<Decl>(D->getDeclContext()), Record);
276 Writer.AddDeclRef(cast_or_null<Decl>(D->getLexicalDeclContext()), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000277 Record.push_back(D->isInvalidDecl());
278 Record.push_back(D->hasAttrs());
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000279 if (D->hasAttrs())
Craig Topper8c2a2a02014-08-30 16:55:39 +0000280 Writer.WriteAttributes(llvm::makeArrayRef(D->getAttrs().begin(),
281 D->getAttrs().size()), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000282 Record.push_back(D->isImplicit());
Douglas Gregorebada0772010-06-17 23:14:26 +0000283 Record.push_back(D->isUsed(false));
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +0000284 Record.push_back(D->isReferenced());
Douglas Gregor781f7132012-01-06 16:59:53 +0000285 Record.push_back(D->isTopLevelDeclInObjCContainer());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000286 Record.push_back(D->getAccess());
Douglas Gregor781f7132012-01-06 16:59:53 +0000287 Record.push_back(D->isModulePrivate());
Douglas Gregora28bcdd2011-12-01 02:07:58 +0000288 Record.push_back(Writer.inferSubmoduleIDFromLocation(D->getLocation()));
Richard Smithc264d352014-03-23 02:30:01 +0000289
290 // If this declaration injected a name into a context different from its
291 // lexical context, and that context is an imported namespace, we need to
292 // update its visible declarations to include this name.
293 //
294 // This happens when we instantiate a class with a friend declaration or a
295 // function with a local extern declaration, for instance.
Richard Smith5fc18a92015-07-12 23:43:21 +0000296 //
297 // FIXME: Can we handle this in AddedVisibleDecl instead?
Richard Smithc264d352014-03-23 02:30:01 +0000298 if (D->isOutOfLine()) {
Richard Smithe3a97022014-03-23 20:41:56 +0000299 auto *DC = D->getDeclContext();
300 while (auto *NS = dyn_cast<NamespaceDecl>(DC->getRedeclContext())) {
301 if (!NS->isFromASTFile())
302 break;
Chandler Carruth8a3d24d2015-03-26 04:27:10 +0000303 Writer.UpdatedDeclContexts.insert(NS->getPrimaryContext());
Richard Smithe3a97022014-03-23 20:41:56 +0000304 if (!NS->isInlineNamespace())
305 break;
306 DC = NS->getParent();
307 }
Richard Smithc264d352014-03-23 02:30:01 +0000308 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000309}
310
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000311void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
Douglas Gregordab42432011-08-12 00:15:20 +0000312 llvm_unreachable("Translation units aren't directly serialized");
Chris Lattner7099dbc2009-04-27 06:16:06 +0000313}
314
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000315void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000316 VisitDecl(D);
317 Writer.AddDeclarationName(D->getDeclName(), Record);
Richard Smith2b560572015-02-07 03:11:11 +0000318 Record.push_back(needsAnonymousDeclarationNumber(D)
319 ? Writer.getAnonymousDeclarationNumber(D)
320 : 0);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000321}
322
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000323void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000324 VisitNamedDecl(D);
Abramo Bagnarab3185b02011-03-06 15:48:19 +0000325 Writer.AddSourceLocation(D->getLocStart(), Record);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000326 Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000327}
328
Douglas Gregor1f179062011-12-19 14:40:25 +0000329void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) {
Douglas Gregor05f10352011-12-17 23:38:30 +0000330 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000331 VisitTypeDecl(D);
Enea Zaffanellaa86d88c2013-06-20 12:46:19 +0000332 Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record);
333 Record.push_back(D->isModed());
334 if (D->isModed())
335 Writer.AddTypeRef(D->getUnderlyingType(), Record);
Douglas Gregor1f179062011-12-19 14:40:25 +0000336}
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000337
Douglas Gregor1f179062011-12-19 14:40:25 +0000338void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) {
339 VisitTypedefNameDecl(D);
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000340 if (!D->hasAttrs() &&
341 !D->isImplicit() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000342 D->getFirstDecl() == D->getMostRecentDecl() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000343 !D->isInvalidDecl() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000344 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000345 !D->isModulePrivate() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000346 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000347 D->getDeclName().getNameKind() == DeclarationName::Identifier)
348 AbbrevToUse = Writer.getDeclTypedefAbbrev();
349
Sebastian Redl539c5062010-08-18 23:57:32 +0000350 Code = serialization::DECL_TYPEDEF;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000351}
352
Richard Smithdda56e42011-04-15 14:24:37 +0000353void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) {
Douglas Gregor1f179062011-12-19 14:40:25 +0000354 VisitTypedefNameDecl(D);
Richard Smith43ccec8e2014-08-26 03:52:16 +0000355 Writer.AddDeclRef(D->getDescribedAliasTemplate(), Record);
Richard Smithdda56e42011-04-15 14:24:37 +0000356 Code = serialization::DECL_TYPEALIAS;
357}
358
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000359void ASTDeclWriter::VisitTagDecl(TagDecl *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000360 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000361 VisitTypeDecl(D);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000362 Record.push_back(D->getIdentifierNamespace());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000363 Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding
Richard Smith2c381642014-08-27 23:11:59 +0000364 if (!isa<CXXRecordDecl>(D))
365 Record.push_back(D->isCompleteDefinition());
Douglas Gregor5089c762010-02-12 17:40:34 +0000366 Record.push_back(D->isEmbeddedInDeclarator());
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +0000367 Record.push_back(D->isFreeStanding());
David Blaikiea8d23ce2013-07-14 01:07:41 +0000368 Record.push_back(D->isCompleteDefinitionRequired());
Argyrios Kyrtzidis664b6902009-07-14 03:18:02 +0000369 Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Richard Smith70d58502014-08-30 00:04:23 +0000370
371 if (D->hasExtInfo()) {
372 Record.push_back(1);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000373 Writer.AddQualifierInfo(*D->getExtInfo(), Record);
Richard Smith70d58502014-08-30 00:04:23 +0000374 } else if (auto *TD = D->getTypedefNameForAnonDecl()) {
375 Record.push_back(2);
376 Writer.AddDeclRef(TD, Record);
377 Writer.AddIdentifierRef(TD->getDeclName().getAsIdentifierInfo(), Record);
378 } else if (auto *DD = D->getDeclaratorForAnonDecl()) {
379 Record.push_back(3);
380 Writer.AddDeclRef(DD, Record);
381 } else {
382 Record.push_back(0);
383 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000384}
385
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000386void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000387 VisitTagDecl(D);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000388 Writer.AddTypeSourceInfo(D->getIntegerTypeSourceInfo(), Record);
389 if (!D->getIntegerTypeSourceInfo())
390 Writer.AddTypeRef(D->getIntegerType(), Record);
John McCall56774992009-12-09 09:09:27 +0000391 Writer.AddTypeRef(D->getPromotionType(), Record);
John McCall9aa35be2010-05-06 08:49:23 +0000392 Record.push_back(D->getNumPositiveBits());
393 Record.push_back(D->getNumNegativeBits());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000394 Record.push_back(D->isScoped());
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000395 Record.push_back(D->isScopedUsingClassTag());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000396 Record.push_back(D->isFixed());
Richard Smith4b38ded2012-03-14 23:13:10 +0000397 if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
398 Writer.AddDeclRef(MemberInfo->getInstantiatedFrom(), Record);
399 Record.push_back(MemberInfo->getTemplateSpecializationKind());
400 Writer.AddSourceLocation(MemberInfo->getPointOfInstantiation(), Record);
401 } else {
Craig Toppera13603a2014-05-22 05:54:18 +0000402 Writer.AddDeclRef(nullptr, Record);
Richard Smith4b38ded2012-03-14 23:13:10 +0000403 }
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000404
405 if (!D->hasAttrs() &&
406 !D->isImplicit() &&
407 !D->isUsed(false) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000408 !D->hasExtInfo() &&
Richard Smith70d58502014-08-30 00:04:23 +0000409 !D->getTypedefNameForAnonDecl() &&
410 !D->getDeclaratorForAnonDecl() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000411 D->getFirstDecl() == D->getMostRecentDecl() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000412 !D->isInvalidDecl() &&
413 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000414 !D->isTopLevelDeclInObjCContainer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000415 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000416 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000417 !CXXRecordDecl::classofKind(D->getKind()) &&
418 !D->getIntegerTypeSourceInfo() &&
Argyrios Kyrtzidisca370b0d2013-03-18 22:23:49 +0000419 !D->getMemberSpecializationInfo() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000420 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000421 D->getDeclName().getNameKind() == DeclarationName::Identifier)
422 AbbrevToUse = Writer.getDeclEnumAbbrev();
423
Sebastian Redl539c5062010-08-18 23:57:32 +0000424 Code = serialization::DECL_ENUM;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000425}
426
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000427void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000428 VisitTagDecl(D);
429 Record.push_back(D->hasFlexibleArrayMember());
430 Record.push_back(D->isAnonymousStructOrUnion());
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000431 Record.push_back(D->hasObjectMember());
Fariborz Jahanian78652202013-01-25 23:57:05 +0000432 Record.push_back(D->hasVolatileMember());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000433
434 if (!D->hasAttrs() &&
435 !D->isImplicit() &&
436 !D->isUsed(false) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000437 !D->hasExtInfo() &&
Richard Smith70d58502014-08-30 00:04:23 +0000438 !D->getTypedefNameForAnonDecl() &&
439 !D->getDeclaratorForAnonDecl() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000440 D->getFirstDecl() == D->getMostRecentDecl() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000441 !D->isInvalidDecl() &&
442 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000443 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000444 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000445 !D->isModulePrivate() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000446 !CXXRecordDecl::classofKind(D->getKind()) &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000447 !needsAnonymousDeclarationNumber(D) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000448 D->getDeclName().getNameKind() == DeclarationName::Identifier)
Douglas Gregor03412ba2011-06-03 02:27:19 +0000449 AbbrevToUse = Writer.getDeclRecordAbbrev();
450
Sebastian Redl539c5062010-08-18 23:57:32 +0000451 Code = serialization::DECL_RECORD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000452}
453
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000454void ASTDeclWriter::VisitValueDecl(ValueDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000455 VisitNamedDecl(D);
456 Writer.AddTypeRef(D->getType(), Record);
457}
458
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000459void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000460 VisitValueDecl(D);
461 Record.push_back(D->getInitExpr()? 1 : 0);
462 if (D->getInitExpr())
463 Writer.AddStmt(D->getInitExpr());
464 Writer.AddAPSInt(D->getInitVal(), Record);
Douglas Gregor03412ba2011-06-03 02:27:19 +0000465
Sebastian Redl539c5062010-08-18 23:57:32 +0000466 Code = serialization::DECL_ENUM_CONSTANT;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000467}
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000468
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000469void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000470 VisitValueDecl(D);
Abramo Bagnaradff19302011-03-08 08:55:46 +0000471 Writer.AddSourceLocation(D->getInnerLocStart(), Record);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000472 Record.push_back(D->hasExtInfo());
473 if (D->hasExtInfo())
474 Writer.AddQualifierInfo(*D->getExtInfo(), Record);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000475}
Chris Lattner7099dbc2009-04-27 06:16:06 +0000476
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000477void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000478 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000479 VisitDeclaratorDecl(D);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000480 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000481 Record.push_back(D->getIdentifierNamespace());
Douglas Gregorb2585692012-01-04 17:13:46 +0000482
483 // FunctionDecl's body is handled last at ASTWriterDecl::Visit,
484 // after everything else is written.
485
Richard Smith72625c22015-02-06 23:20:21 +0000486 Record.push_back((int)D->SClass); // FIXME: stable encoding
Douglas Gregorb2585692012-01-04 17:13:46 +0000487 Record.push_back(D->IsInline);
Richard Smith72625c22015-02-06 23:20:21 +0000488 Record.push_back(D->IsInlineSpecified);
489 Record.push_back(D->IsVirtualAsWritten);
490 Record.push_back(D->IsPure);
491 Record.push_back(D->HasInheritedPrototype);
492 Record.push_back(D->HasWrittenPrototype);
493 Record.push_back(D->IsDeleted);
494 Record.push_back(D->IsTrivial);
495 Record.push_back(D->IsDefaulted);
496 Record.push_back(D->IsExplicitlyDefaulted);
497 Record.push_back(D->HasImplicitReturnZero);
498 Record.push_back(D->IsConstexpr);
Argyrios Kyrtzidis1eb71a12012-12-06 18:59:10 +0000499 Record.push_back(D->HasSkippedBody);
Richard Smith72625c22015-02-06 23:20:21 +0000500 Record.push_back(D->IsLateTemplateParsed);
Rafael Espindola3ae00052013-05-13 00:12:11 +0000501 Record.push_back(D->getLinkageInternal());
Douglas Gregorb2585692012-01-04 17:13:46 +0000502 Writer.AddSourceLocation(D->getLocEnd(), Record);
503
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000504 Record.push_back(D->getTemplatedKind());
505 switch (D->getTemplatedKind()) {
506 case FunctionDecl::TK_NonTemplate:
507 break;
508 case FunctionDecl::TK_FunctionTemplate:
509 Writer.AddDeclRef(D->getDescribedFunctionTemplate(), Record);
510 break;
511 case FunctionDecl::TK_MemberSpecialization: {
512 MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo();
513 Writer.AddDeclRef(MemberInfo->getInstantiatedFrom(), Record);
514 Record.push_back(MemberInfo->getTemplateSpecializationKind());
515 Writer.AddSourceLocation(MemberInfo->getPointOfInstantiation(), Record);
516 break;
517 }
518 case FunctionDecl::TK_FunctionTemplateSpecialization: {
519 FunctionTemplateSpecializationInfo *
520 FTSInfo = D->getTemplateSpecializationInfo();
Richard Smithd8a83712015-08-22 01:47:18 +0000521
522 RegisterTemplateSpecialization(FTSInfo->getTemplate(), D);
523
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000524 Writer.AddDeclRef(FTSInfo->getTemplate(), Record);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000525 Record.push_back(FTSInfo->getTemplateSpecializationKind());
526
527 // Template arguments.
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000528 Writer.AddTemplateArgumentList(FTSInfo->TemplateArguments, Record);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000529
530 // Template args as written.
Craig Toppera13603a2014-05-22 05:54:18 +0000531 Record.push_back(FTSInfo->TemplateArgumentsAsWritten != nullptr);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000532 if (FTSInfo->TemplateArgumentsAsWritten) {
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000533 Record.push_back(FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs);
534 for (int i=0, e = FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs;
535 i!=e; ++i)
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000536 Writer.AddTemplateArgumentLoc((*FTSInfo->TemplateArgumentsAsWritten)[i],
537 Record);
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000538 Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->LAngleLoc,
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000539 Record);
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000540 Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->RAngleLoc,
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000541 Record);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000542 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000543
544 Writer.AddSourceLocation(FTSInfo->getPointOfInstantiation(), Record);
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000545
546 if (D->isCanonicalDecl()) {
547 // Write the template that contains the specializations set. We will
548 // add a FunctionTemplateSpecializationInfo to it when reading.
549 Writer.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl(), Record);
550 }
Argyrios Kyrtzidisdc9ca0a2010-06-25 16:24:51 +0000551 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000552 }
553 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
554 DependentFunctionTemplateSpecializationInfo *
555 DFTSInfo = D->getDependentSpecializationInfo();
556
557 // Templates.
558 Record.push_back(DFTSInfo->getNumTemplates());
559 for (int i=0, e = DFTSInfo->getNumTemplates(); i != e; ++i)
560 Writer.AddDeclRef(DFTSInfo->getTemplate(i), Record);
561
562 // Templates args.
563 Record.push_back(DFTSInfo->getNumTemplateArgs());
564 for (int i=0, e = DFTSInfo->getNumTemplateArgs(); i != e; ++i)
565 Writer.AddTemplateArgumentLoc(DFTSInfo->getTemplateArg(i), Record);
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000566 Writer.AddSourceLocation(DFTSInfo->getLAngleLoc(), Record);
567 Writer.AddSourceLocation(DFTSInfo->getRAngleLoc(), Record);
Argyrios Kyrtzidisdc9ca0a2010-06-25 16:24:51 +0000568 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000569 }
570 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000571
Chris Lattner7099dbc2009-04-27 06:16:06 +0000572 Record.push_back(D->param_size());
Aaron Ballmanf6bf62e2014-03-07 15:12:56 +0000573 for (auto P : D->params())
574 Writer.AddDeclRef(P, Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000575 Code = serialization::DECL_FUNCTION;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000576}
577
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000578void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000579 VisitNamedDecl(D);
580 // FIXME: convert to LazyStmtPtr?
Mike Stump11289f42009-09-09 15:08:12 +0000581 // Unlike C/C++, method bodies will never be in header files.
Craig Toppera13603a2014-05-22 05:54:18 +0000582 bool HasBodyStuff = D->getBody() != nullptr ||
583 D->getSelfDecl() != nullptr || D->getCmdDecl() != nullptr;
Argyrios Kyrtzidisa8607772010-08-09 10:54:37 +0000584 Record.push_back(HasBodyStuff);
585 if (HasBodyStuff) {
Argyrios Kyrtzidisddcd1322009-06-30 02:35:26 +0000586 Writer.AddStmt(D->getBody());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000587 Writer.AddDeclRef(D->getSelfDecl(), Record);
588 Writer.AddDeclRef(D->getCmdDecl(), Record);
589 }
590 Record.push_back(D->isInstanceMethod());
591 Record.push_back(D->isVariadic());
Jordan Rosed01e83a2012-10-10 16:42:25 +0000592 Record.push_back(D->isPropertyAccessor());
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000593 Record.push_back(D->isDefined());
Argyrios Kyrtzidis08f96a92012-05-09 16:12:57 +0000594 Record.push_back(D->IsOverriding);
Argyrios Kyrtzidis1eb71a12012-12-06 18:59:10 +0000595 Record.push_back(D->HasSkippedBody);
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000596
597 Record.push_back(D->IsRedeclaration);
598 Record.push_back(D->HasRedeclaration);
599 if (D->HasRedeclaration) {
600 assert(Context.getObjCMethodRedeclaration(D));
601 Writer.AddDeclRef(Context.getObjCMethodRedeclaration(D), Record);
602 }
603
Chris Lattner7099dbc2009-04-27 06:16:06 +0000604 // FIXME: stable encoding for @required/@optional
Mike Stump11289f42009-09-09 15:08:12 +0000605 Record.push_back(D->getImplementationControl());
Douglas Gregor813a0662015-06-19 18:14:38 +0000606 // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway/nullability
Mike Stump11289f42009-09-09 15:08:12 +0000607 Record.push_back(D->getObjCDeclQualifier());
Douglas Gregor33823722011-06-11 01:09:30 +0000608 Record.push_back(D->hasRelatedResultType());
Alp Toker314cc812014-01-25 16:55:45 +0000609 Writer.AddTypeRef(D->getReturnType(), Record);
610 Writer.AddTypeSourceInfo(D->getReturnTypeSourceInfo(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000611 Writer.AddSourceLocation(D->getLocEnd(), Record);
612 Record.push_back(D->param_size());
Aaron Ballman43b68be2014-03-07 17:50:17 +0000613 for (const auto *P : D->params())
614 Writer.AddDeclRef(P, Record);
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000615
616 Record.push_back(D->SelLocsKind);
617 unsigned NumStoredSelLocs = D->getNumStoredSelLocs();
618 SourceLocation *SelLocs = D->getStoredSelLocs();
619 Record.push_back(NumStoredSelLocs);
620 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
621 Writer.AddSourceLocation(SelLocs[i], Record);
622
Sebastian Redl539c5062010-08-18 23:57:32 +0000623 Code = serialization::DECL_OBJC_METHOD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000624}
625
Douglas Gregor85f3f952015-07-07 03:57:15 +0000626void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
627 VisitTypedefNameDecl(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +0000628 Record.push_back(D->Variance);
Douglas Gregore83b9562015-07-07 03:57:53 +0000629 Record.push_back(D->Index);
Douglas Gregor1ac1b632015-07-07 03:58:54 +0000630 Writer.AddSourceLocation(D->VarianceLoc, Record);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000631 Writer.AddSourceLocation(D->ColonLoc, Record);
632
633 Code = serialization::DECL_OBJC_TYPE_PARAM;
634}
635
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000636void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000637 VisitNamedDecl(D);
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +0000638 Writer.AddSourceLocation(D->getAtStartLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +0000639 Writer.AddSourceRange(D->getAtEndRange(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000640 // Abstract class (no need to define a stable serialization::DECL code).
Chris Lattner7099dbc2009-04-27 06:16:06 +0000641}
642
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000643void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
Douglas Gregor66b310c2011-12-15 18:03:09 +0000644 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000645 VisitObjCContainerDecl(D);
646 Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000647 AddObjCTypeParamList(D->TypeParamList);
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000648
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000649 Record.push_back(D->isThisDeclarationADefinition());
650 if (D->isThisDeclarationADefinition()) {
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000651 // Write the DefinitionData
652 ObjCInterfaceDecl::DefinitionData &Data = D->data();
653
Douglas Gregore9d95f12015-07-07 03:57:35 +0000654 Writer.AddTypeSourceInfo(D->getSuperClassTInfo(), Record);
Douglas Gregor16408322011-12-15 22:34:59 +0000655 Writer.AddSourceLocation(D->getEndOfDefinitionLoc(), Record);
Argyrios Kyrtzidis9ed9e5f2013-12-03 21:11:30 +0000656 Record.push_back(Data.HasDesignatedInitializers);
Douglas Gregor16408322011-12-15 22:34:59 +0000657
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000658 // Write out the protocols that are directly referenced by the @interface.
659 Record.push_back(Data.ReferencedProtocols.size());
Aaron Ballmana49c5062014-03-13 20:29:09 +0000660 for (const auto *P : D->protocols())
661 Writer.AddDeclRef(P, Record);
Aaron Ballmane9378882014-03-13 20:34:24 +0000662 for (const auto &PL : D->protocol_locs())
663 Writer.AddSourceLocation(PL, Record);
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000664
665 // Write out the protocols that are transitively referenced.
666 Record.push_back(Data.AllReferencedProtocols.size());
667 for (ObjCList<ObjCProtocolDecl>::iterator
668 P = Data.AllReferencedProtocols.begin(),
669 PEnd = Data.AllReferencedProtocols.end();
670 P != PEnd; ++P)
671 Writer.AddDeclRef(*P, Record);
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000672
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000673
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000674 if (ObjCCategoryDecl *Cat = D->getCategoryListRaw()) {
Douglas Gregor404cdde2012-01-27 01:47:08 +0000675 // Ensure that we write out the set of categories for this class.
676 Writer.ObjCClassesWithCategories.insert(D);
677
678 // Make sure that the categories get serialized.
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000679 for (; Cat; Cat = Cat->getNextClassCategoryRaw())
Douglas Gregor404cdde2012-01-27 01:47:08 +0000680 (void)Writer.GetDeclRef(Cat);
681 }
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000682 }
683
Sebastian Redl539c5062010-08-18 23:57:32 +0000684 Code = serialization::DECL_OBJC_INTERFACE;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000685}
686
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000687void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000688 VisitFieldDecl(D);
689 // FIXME: stable encoding for @public/@private/@protected/@package
Mike Stump11289f42009-09-09 15:08:12 +0000690 Record.push_back(D->getAccessControl());
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000691 Record.push_back(D->getSynthesize());
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000692
693 if (!D->hasAttrs() &&
694 !D->isImplicit() &&
695 !D->isUsed(false) &&
696 !D->isInvalidDecl() &&
697 !D->isReferenced() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000698 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000699 !D->getBitWidth() &&
700 !D->hasExtInfo() &&
701 D->getDeclName())
702 AbbrevToUse = Writer.getDeclObjCIvarAbbrev();
703
Sebastian Redl539c5062010-08-18 23:57:32 +0000704 Code = serialization::DECL_OBJC_IVAR;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000705}
706
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000707void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
Douglas Gregora715bff2012-01-01 19:51:50 +0000708 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000709 VisitObjCContainerDecl(D);
Douglas Gregore6e48b12012-01-01 19:29:29 +0000710
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000711 Record.push_back(D->isThisDeclarationADefinition());
712 if (D->isThisDeclarationADefinition()) {
Douglas Gregore6e48b12012-01-01 19:29:29 +0000713 Record.push_back(D->protocol_size());
Aaron Ballman0f6e64d2014-03-13 22:58:06 +0000714 for (const auto *I : D->protocols())
715 Writer.AddDeclRef(I, Record);
Aaron Ballmana964ec12014-03-14 12:38:50 +0000716 for (const auto &PL : D->protocol_locs())
717 Writer.AddSourceLocation(PL, Record);
Douglas Gregore6e48b12012-01-01 19:29:29 +0000718 }
719
Sebastian Redl539c5062010-08-18 23:57:32 +0000720 Code = serialization::DECL_OBJC_PROTOCOL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000721}
722
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000723void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000724 VisitFieldDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000725 Code = serialization::DECL_OBJC_AT_DEFS_FIELD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000726}
727
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000728void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000729 VisitObjCContainerDecl(D);
Douglas Gregor404cdde2012-01-27 01:47:08 +0000730 Writer.AddSourceLocation(D->getCategoryNameLoc(), Record);
Fariborz Jahaniana7765fe2012-02-20 20:09:20 +0000731 Writer.AddSourceLocation(D->getIvarLBraceLoc(), Record);
732 Writer.AddSourceLocation(D->getIvarRBraceLoc(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000733 Writer.AddDeclRef(D->getClassInterface(), Record);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000734 AddObjCTypeParamList(D->TypeParamList);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000735 Record.push_back(D->protocol_size());
Aaron Ballman19a41762014-03-14 12:55:57 +0000736 for (const auto *I : D->protocols())
737 Writer.AddDeclRef(I, Record);
Aaron Ballmana73c8572014-03-14 13:03:32 +0000738 for (const auto &PL : D->protocol_locs())
739 Writer.AddSourceLocation(PL, Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000740 Code = serialization::DECL_OBJC_CATEGORY;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000741}
742
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000743void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000744 VisitNamedDecl(D);
745 Writer.AddDeclRef(D->getClassInterface(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000746 Code = serialization::DECL_OBJC_COMPATIBLE_ALIAS;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000747}
748
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000749void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000750 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000751 Writer.AddSourceLocation(D->getAtLoc(), Record);
Fariborz Jahanian86c2f5c2012-02-29 22:18:55 +0000752 Writer.AddSourceLocation(D->getLParenLoc(), Record);
Douglas Gregor813a0662015-06-19 18:14:38 +0000753 Writer.AddTypeRef(D->getType(), Record);
John McCall339bb662010-06-04 20:50:08 +0000754 Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000755 // FIXME: stable encoding
756 Record.push_back((unsigned)D->getPropertyAttributes());
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000757 Record.push_back((unsigned)D->getPropertyAttributesAsWritten());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000758 // FIXME: stable encoding
759 Record.push_back((unsigned)D->getPropertyImplementation());
760 Writer.AddDeclarationName(D->getGetterName(), Record);
761 Writer.AddDeclarationName(D->getSetterName(), Record);
762 Writer.AddDeclRef(D->getGetterMethodDecl(), Record);
763 Writer.AddDeclRef(D->getSetterMethodDecl(), Record);
764 Writer.AddDeclRef(D->getPropertyIvarDecl(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000765 Code = serialization::DECL_OBJC_PROPERTY;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000766}
767
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000768void ASTDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000769 VisitObjCContainerDecl(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000770 Writer.AddDeclRef(D->getClassInterface(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000771 // Abstract class (no need to define a stable serialization::DECL code).
Chris Lattner7099dbc2009-04-27 06:16:06 +0000772}
773
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000774void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000775 VisitObjCImplDecl(D);
776 Writer.AddIdentifierRef(D->getIdentifier(), Record);
Argyrios Kyrtzidis4996f5f2011-12-09 00:31:40 +0000777 Writer.AddSourceLocation(D->getCategoryNameLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000778 Code = serialization::DECL_OBJC_CATEGORY_IMPL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000779}
780
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000781void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000782 VisitObjCImplDecl(D);
783 Writer.AddDeclRef(D->getSuperClass(), Record);
Argyrios Kyrtzidis5d2ce842013-05-03 22:31:26 +0000784 Writer.AddSourceLocation(D->getSuperClassLoc(), Record);
Fariborz Jahaniana7765fe2012-02-20 20:09:20 +0000785 Writer.AddSourceLocation(D->getIvarLBraceLoc(), Record);
786 Writer.AddSourceLocation(D->getIvarRBraceLoc(), Record);
John McCall0d54a172012-10-17 04:53:31 +0000787 Record.push_back(D->hasNonZeroConstructors());
788 Record.push_back(D->hasDestructors());
Richard Smithc2bb8182015-03-24 06:36:48 +0000789 Record.push_back(D->NumIvarInitializers);
790 if (D->NumIvarInitializers)
791 Writer.AddCXXCtorInitializersRef(
792 llvm::makeArrayRef(D->init_begin(), D->init_end()), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000793 Code = serialization::DECL_OBJC_IMPLEMENTATION;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000794}
795
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000796void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000797 VisitDecl(D);
798 Writer.AddSourceLocation(D->getLocStart(), Record);
799 Writer.AddDeclRef(D->getPropertyDecl(), Record);
800 Writer.AddDeclRef(D->getPropertyIvarDecl(), Record);
Douglas Gregorb1b71e52010-11-17 01:03:52 +0000801 Writer.AddSourceLocation(D->getPropertyIvarDeclLoc(), Record);
Argyrios Kyrtzidisa8607772010-08-09 10:54:37 +0000802 Writer.AddStmt(D->getGetterCXXConstructor());
803 Writer.AddStmt(D->getSetterCXXAssignment());
Sebastian Redl539c5062010-08-18 23:57:32 +0000804 Code = serialization::DECL_OBJC_PROPERTY_IMPL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000805}
806
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000807void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000808 VisitDeclaratorDecl(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000809 Record.push_back(D->isMutable());
John McCallc90c1492014-10-10 18:44:34 +0000810 if (D->InitStorage.getInt() == FieldDecl::ISK_BitWidthOrNothing &&
811 D->InitStorage.getPointer() == nullptr) {
812 Record.push_back(0);
813 } else if (D->InitStorage.getInt() == FieldDecl::ISK_CapturedVLAType) {
814 Record.push_back(D->InitStorage.getInt() + 1);
Alexey Bataev39c81e22014-08-28 04:28:19 +0000815 Writer.AddTypeRef(
John McCallc90c1492014-10-10 18:44:34 +0000816 QualType(static_cast<Type *>(D->InitStorage.getPointer()), 0),
Alexey Bataev39c81e22014-08-28 04:28:19 +0000817 Record);
Richard Smith2b013182012-06-10 03:12:00 +0000818 } else {
John McCallc90c1492014-10-10 18:44:34 +0000819 Record.push_back(D->InitStorage.getInt() + 1);
820 Writer.AddStmt(static_cast<Expr *>(D->InitStorage.getPointer()));
Richard Smith2b013182012-06-10 03:12:00 +0000821 }
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000822 if (!D->getDeclName())
823 Writer.AddDeclRef(Context.getInstantiatedFromUnnamedFieldDecl(D), Record);
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000824
825 if (!D->hasAttrs() &&
826 !D->isImplicit() &&
827 !D->isUsed(false) &&
828 !D->isInvalidDecl() &&
829 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000830 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000831 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000832 !D->getBitWidth() &&
Richard Smith938f40b2011-06-11 17:19:42 +0000833 !D->hasInClassInitializer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000834 !D->hasExtInfo() &&
835 !ObjCIvarDecl::classofKind(D->getKind()) &&
836 !ObjCAtDefsFieldDecl::classofKind(D->getKind()) &&
837 D->getDeclName())
838 AbbrevToUse = Writer.getDeclFieldAbbrev();
839
Sebastian Redl539c5062010-08-18 23:57:32 +0000840 Code = serialization::DECL_FIELD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000841}
842
John McCall5e77d762013-04-16 07:28:30 +0000843void ASTDeclWriter::VisitMSPropertyDecl(MSPropertyDecl *D) {
844 VisitDeclaratorDecl(D);
845 Writer.AddIdentifierRef(D->getGetterId(), Record);
846 Writer.AddIdentifierRef(D->getSetterId(), Record);
847 Code = serialization::DECL_MS_PROPERTY;
848}
849
Francois Pichet783dd6e2010-11-21 06:08:52 +0000850void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
851 VisitValueDecl(D);
852 Record.push_back(D->getChainingSize());
853
Aaron Ballman29c94602014-03-07 18:36:15 +0000854 for (const auto *P : D->chain())
Aaron Ballman13916082014-03-07 18:11:58 +0000855 Writer.AddDeclRef(P, Record);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000856 Code = serialization::DECL_INDIRECTFIELD;
857}
858
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000859void ASTDeclWriter::VisitVarDecl(VarDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000860 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000861 VisitDeclaratorDecl(D);
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000862 Record.push_back(D->getStorageClass());
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +0000863 Record.push_back(D->getTSCSpec());
Sebastian Redla9351792012-02-11 23:51:47 +0000864 Record.push_back(D->getInitStyle());
David Majnemerfa7bc782015-05-19 00:57:16 +0000865 if (!isa<ParmVarDecl>(D)) {
866 Record.push_back(D->isExceptionVariable());
867 Record.push_back(D->isNRVOVariable());
868 Record.push_back(D->isCXXForRangeDecl());
869 Record.push_back(D->isARCPseudoStrong());
870 Record.push_back(D->isConstexpr());
871 Record.push_back(D->isInitCapture());
872 Record.push_back(D->isPreviousDeclInSameBlockScope());
873 }
Rafael Espindola3ae00052013-05-13 00:12:11 +0000874 Record.push_back(D->getLinkageInternal());
Douglas Gregor12cda632012-09-20 23:43:29 +0000875
Richard Smithd0b4dd62011-12-19 06:19:21 +0000876 if (D->getInit()) {
877 Record.push_back(!D->isInitKnownICE() ? 1 : (D->isInitICE() ? 3 : 2));
Chris Lattner7099dbc2009-04-27 06:16:06 +0000878 Writer.AddStmt(D->getInit());
Richard Smithd0b4dd62011-12-19 06:19:21 +0000879 } else {
880 Record.push_back(0);
881 }
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000882
883 enum {
884 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
885 };
886 if (VarTemplateDecl *TemplD = D->getDescribedVarTemplate()) {
887 Record.push_back(VarTemplate);
888 Writer.AddDeclRef(TemplD, Record);
889 } else if (MemberSpecializationInfo *SpecInfo
890 = D->getMemberSpecializationInfo()) {
891 Record.push_back(StaticDataMemberSpecialization);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000892 Writer.AddDeclRef(SpecInfo->getInstantiatedFrom(), Record);
893 Record.push_back(SpecInfo->getTemplateSpecializationKind());
894 Writer.AddSourceLocation(SpecInfo->getPointOfInstantiation(), Record);
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000895 } else {
896 Record.push_back(VarNotTemplate);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000897 }
898
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000899 if (!D->hasAttrs() &&
900 !D->isImplicit() &&
901 !D->isUsed(false) &&
902 !D->isInvalidDecl() &&
903 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000904 !D->isTopLevelDeclInObjCContainer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000905 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000906 !D->isModulePrivate() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000907 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000908 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
909 !D->hasExtInfo() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000910 D->getFirstDecl() == D->getMostRecentDecl() &&
Sebastian Redla9351792012-02-11 23:51:47 +0000911 D->getInitStyle() == VarDecl::CInit &&
Craig Toppera13603a2014-05-22 05:54:18 +0000912 D->getInit() == nullptr &&
John McCalld4631322011-06-17 06:42:21 +0000913 !isa<ParmVarDecl>(D) &&
Larisse Voufoa11bd8a2013-08-13 02:02:26 +0000914 !isa<VarTemplateSpecializationDecl>(D) &&
Douglas Gregor12cda632012-09-20 23:43:29 +0000915 !D->isConstexpr() &&
Richard Smithbb13c9a2013-09-28 04:02:39 +0000916 !D->isInitCapture() &&
Richard Smith1c34fb72013-08-13 18:18:50 +0000917 !D->isPreviousDeclInSameBlockScope() &&
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000918 !D->getMemberSpecializationInfo())
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000919 AbbrevToUse = Writer.getDeclVarAbbrev();
920
Sebastian Redl539c5062010-08-18 23:57:32 +0000921 Code = serialization::DECL_VAR;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000922}
923
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000924void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000925 VisitVarDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000926 Code = serialization::DECL_IMPLICIT_PARAM;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000927}
928
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000929void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000930 VisitVarDecl(D);
John McCall82490832011-05-02 00:30:12 +0000931 Record.push_back(D->isObjCMethodParameter());
John McCall8fb0d9d2011-05-01 22:35:37 +0000932 Record.push_back(D->getFunctionScopeDepth());
933 Record.push_back(D->getFunctionScopeIndex());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000934 Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding
John McCall6a014d52011-03-09 04:22:44 +0000935 Record.push_back(D->isKNRPromoted());
John McCallf3cd6652010-03-12 18:31:32 +0000936 Record.push_back(D->hasInheritedDefaultArg());
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000937 Record.push_back(D->hasUninstantiatedDefaultArg());
938 if (D->hasUninstantiatedDefaultArg())
939 Writer.AddStmt(D->getUninstantiatedDefaultArg());
Sebastian Redl539c5062010-08-18 23:57:32 +0000940 Code = serialization::DECL_PARM_VAR;
Mike Stump11289f42009-09-09 15:08:12 +0000941
John McCalld4631322011-06-17 06:42:21 +0000942 assert(!D->isARCPseudoStrong()); // can be true of ImplicitParamDecl
943
Chris Lattner258172e2009-04-27 07:35:58 +0000944 // If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here
945 // we dynamically check for the properties that we optimize for, but don't
946 // know are true of all PARM_VAR_DECLs.
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000947 if (!D->hasAttrs() &&
948 !D->hasExtInfo() &&
Chris Lattner258172e2009-04-27 07:35:58 +0000949 !D->isImplicit() &&
Douglas Gregorebada0772010-06-17 23:14:26 +0000950 !D->isUsed(false) &&
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +0000951 !D->isInvalidDecl() &&
Eli Friedmanc09e0552012-01-13 23:41:25 +0000952 !D->isReferenced() &&
Chris Lattner258172e2009-04-27 07:35:58 +0000953 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000954 !D->isModulePrivate() &&
Chris Lattner258172e2009-04-27 07:35:58 +0000955 D->getStorageClass() == 0 &&
Sebastian Redla9351792012-02-11 23:51:47 +0000956 D->getInitStyle() == VarDecl::CInit && // Can params have anything else?
John McCall82490832011-05-02 00:30:12 +0000957 D->getFunctionScopeDepth() == 0 &&
John McCallf3cd6652010-03-12 18:31:32 +0000958 D->getObjCDeclQualifier() == 0 &&
John McCall6a014d52011-03-09 04:22:44 +0000959 !D->isKNRPromoted() &&
Chris Lattnere2437f42010-05-09 06:40:08 +0000960 !D->hasInheritedDefaultArg() &&
Craig Toppera13603a2014-05-22 05:54:18 +0000961 D->getInit() == nullptr &&
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000962 !D->hasUninstantiatedDefaultArg()) // No default expr.
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000963 AbbrevToUse = Writer.getDeclParmVarAbbrev();
Chris Lattner258172e2009-04-27 07:35:58 +0000964
965 // Check things we know are true of *every* PARM_VAR_DECL, which is more than
966 // just us assuming it.
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +0000967 assert(!D->getTSCSpec() && "PARM_VAR_DECL can't use TLS");
Chris Lattner258172e2009-04-27 07:35:58 +0000968 assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private");
Douglas Gregor3f324d562010-05-03 18:51:14 +0000969 assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var");
Craig Toppera13603a2014-05-22 05:54:18 +0000970 assert(D->getPreviousDecl() == nullptr && "PARM_VAR_DECL can't be redecl");
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000971 assert(!D->isStaticDataMember() &&
972 "PARM_VAR_DECL can't be static data member");
Chris Lattner7099dbc2009-04-27 06:16:06 +0000973}
974
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000975void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000976 VisitDecl(D);
977 Writer.AddStmt(D->getAsmString());
Abramo Bagnara348823a2011-03-03 14:20:18 +0000978 Writer.AddSourceLocation(D->getRParenLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000979 Code = serialization::DECL_FILE_SCOPE_ASM;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000980}
981
Michael Han84324352013-02-22 17:15:32 +0000982void ASTDeclWriter::VisitEmptyDecl(EmptyDecl *D) {
983 VisitDecl(D);
984 Code = serialization::DECL_EMPTY;
985}
986
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000987void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000988 VisitDecl(D);
989 Writer.AddStmt(D->getBody());
John McCalla3ccba02010-06-04 11:21:44 +0000990 Writer.AddTypeSourceInfo(D->getSignatureAsWritten(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000991 Record.push_back(D->param_size());
992 for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end();
993 P != PEnd; ++P)
994 Writer.AddDeclRef(*P, Record);
John McCallcf6ce282012-04-13 17:33:29 +0000995 Record.push_back(D->isVariadic());
996 Record.push_back(D->blockMissingReturnType());
997 Record.push_back(D->isConversionFromLambda());
John McCallc63de662011-02-02 13:00:07 +0000998 Record.push_back(D->capturesCXXThis());
John McCall351762c2011-02-07 10:33:21 +0000999 Record.push_back(D->getNumCaptures());
Aaron Ballman9371dd22014-03-14 18:34:04 +00001000 for (const auto &capture : D->captures()) {
John McCall351762c2011-02-07 10:33:21 +00001001 Writer.AddDeclRef(capture.getVariable(), Record);
1002
1003 unsigned flags = 0;
1004 if (capture.isByRef()) flags |= 1;
1005 if (capture.isNested()) flags |= 2;
1006 if (capture.hasCopyExpr()) flags |= 4;
1007 Record.push_back(flags);
1008
1009 if (capture.hasCopyExpr()) Writer.AddStmt(capture.getCopyExpr());
1010 }
John McCallc63de662011-02-02 13:00:07 +00001011
Sebastian Redl539c5062010-08-18 23:57:32 +00001012 Code = serialization::DECL_BLOCK;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001013}
1014
Ben Langmuirce914fc2013-05-03 19:20:19 +00001015void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) {
1016 Record.push_back(CD->getNumParams());
1017 VisitDecl(CD);
Alexey Bataev9959db52014-05-06 10:08:46 +00001018 Record.push_back(CD->getContextParamPosition());
1019 Record.push_back(CD->isNothrow() ? 1 : 0);
Ben Langmuirce914fc2013-05-03 19:20:19 +00001020 // Body is stored by VisitCapturedStmt.
Alexey Bataev9959db52014-05-06 10:08:46 +00001021 for (unsigned I = 0; I < CD->getNumParams(); ++I)
1022 Writer.AddDeclRef(CD->getParam(I), Record);
Ben Langmuirce914fc2013-05-03 19:20:19 +00001023 Code = serialization::DECL_CAPTURED;
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001024}
1025
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001026void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001027 VisitDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001028 Record.push_back(D->getLanguage());
Abramo Bagnaraea947882011-03-08 16:41:52 +00001029 Writer.AddSourceLocation(D->getExternLoc(), Record);
Abramo Bagnara4a8cda82011-03-03 14:52:38 +00001030 Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001031 Code = serialization::DECL_LINKAGE_SPEC;
Chris Lattnerca025db2010-05-07 21:43:38 +00001032}
1033
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001034void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) {
1035 VisitNamedDecl(D);
Abramo Bagnara1c3af962011-03-05 18:21:20 +00001036 Writer.AddSourceLocation(D->getLocStart(), Record);
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001037 Code = serialization::DECL_LABEL;
1038}
1039
1040
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001041void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
Douglas Gregore57e7522012-01-07 09:11:48 +00001042 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001043 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +00001044 Record.push_back(D->isInline());
Abramo Bagnarab5545be2011-03-08 12:38:20 +00001045 Writer.AddSourceLocation(D->getLocStart(), Record);
1046 Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001047
Chris Lattnerca025db2010-05-07 21:43:38 +00001048 if (D->isOriginalNamespace())
1049 Writer.AddDeclRef(D->getAnonymousNamespace(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001050 Code = serialization::DECL_NAMESPACE;
Sebastian Redlf03cdc52010-08-05 21:22:19 +00001051
Douglas Gregore57e7522012-01-07 09:11:48 +00001052 if (Writer.hasChain() && D->isAnonymousNamespace() &&
Douglas Gregorec9fd132012-01-14 16:38:05 +00001053 D == D->getMostRecentDecl()) {
Sebastian Redl010288f2011-04-24 16:28:21 +00001054 // This is a most recent reopening of the anonymous namespace. If its parent
1055 // is in a previous PCH (or is the TU), mark that parent for update, because
1056 // the original namespace always points to the latest re-opening of its
1057 // anonymous namespace.
1058 Decl *Parent = cast<Decl>(
1059 D->getParent()->getRedeclContext()->getPrimaryContext());
Douglas Gregorb3722e22011-09-09 23:01:35 +00001060 if (Parent->isFromASTFile() || isa<TranslationUnitDecl>(Parent)) {
Richard Smith6ef42932014-03-20 21:02:00 +00001061 Writer.DeclUpdates[Parent].push_back(
Aaron Ballman4f45b712014-03-21 15:22:56 +00001062 ASTWriter::DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, D));
Sebastian Redlfa1f3702011-04-24 16:28:13 +00001063 }
1064 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001065}
1066
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001067void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Richard Smithf4634362014-09-03 23:11:22 +00001068 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001069 VisitNamedDecl(D);
Douglas Gregorf9e43ce2010-09-01 00:08:19 +00001070 Writer.AddSourceLocation(D->getNamespaceLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001071 Writer.AddSourceLocation(D->getTargetNameLoc(), Record);
Douglas Gregorc05ba2e2011-02-25 17:08:07 +00001072 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001073 Writer.AddDeclRef(D->getNamespace(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001074 Code = serialization::DECL_NAMESPACE_ALIAS;
Chris Lattnerca025db2010-05-07 21:43:38 +00001075}
1076
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001077void ASTDeclWriter::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001078 VisitNamedDecl(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00001079 Writer.AddSourceLocation(D->getUsingLoc(), Record);
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001080 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00001081 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
Benjamin Kramere78f8ee2012-01-07 19:09:05 +00001082 Writer.AddDeclRef(D->FirstUsingShadow.getPointer(), Record);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00001083 Record.push_back(D->hasTypename());
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001084 Writer.AddDeclRef(Context.getInstantiatedFromUsingDecl(D), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001085 Code = serialization::DECL_USING;
Chris Lattnerca025db2010-05-07 21:43:38 +00001086}
1087
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001088void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) {
Richard Smithfd8634a2013-10-23 02:17:46 +00001089 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001090 VisitNamedDecl(D);
1091 Writer.AddDeclRef(D->getTargetDecl(), Record);
Argyrios Kyrtzidis2703beb2010-11-10 05:40:41 +00001092 Writer.AddDeclRef(D->UsingOrNextShadow, Record);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001093 Writer.AddDeclRef(Context.getInstantiatedFromUsingShadowDecl(D), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001094 Code = serialization::DECL_USING_SHADOW;
Chris Lattnerca025db2010-05-07 21:43:38 +00001095}
1096
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001097void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001098 VisitNamedDecl(D);
Douglas Gregor01a430132010-09-01 03:07:18 +00001099 Writer.AddSourceLocation(D->getUsingLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001100 Writer.AddSourceLocation(D->getNamespaceKeyLocation(), Record);
Douglas Gregor12441b32011-02-25 16:33:46 +00001101 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001102 Writer.AddDeclRef(D->getNominatedNamespace(), Record);
1103 Writer.AddDeclRef(dyn_cast<Decl>(D->getCommonAncestor()), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001104 Code = serialization::DECL_USING_DIRECTIVE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001105}
1106
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001107void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001108 VisitValueDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001109 Writer.AddSourceLocation(D->getUsingLoc(), Record);
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001110 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00001111 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001112 Code = serialization::DECL_UNRESOLVED_USING_VALUE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001113}
1114
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001115void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001116 UnresolvedUsingTypenameDecl *D) {
1117 VisitTypeDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001118 Writer.AddSourceLocation(D->getTypenameLoc(), Record);
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001119 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001120 Code = serialization::DECL_UNRESOLVED_USING_TYPENAME;
Chris Lattnerca025db2010-05-07 21:43:38 +00001121}
1122
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001123void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001124 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001125
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001126 enum {
1127 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1128 };
1129 if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) {
1130 Record.push_back(CXXRecTemplate);
1131 Writer.AddDeclRef(TemplD, Record);
1132 } else if (MemberSpecializationInfo *MSInfo
1133 = D->getMemberSpecializationInfo()) {
1134 Record.push_back(CXXRecMemberSpecialization);
1135 Writer.AddDeclRef(MSInfo->getInstantiatedFrom(), Record);
1136 Record.push_back(MSInfo->getTemplateSpecializationKind());
1137 Writer.AddSourceLocation(MSInfo->getPointOfInstantiation(), Record);
1138 } else {
1139 Record.push_back(CXXRecNotTemplate);
1140 }
1141
Richard Smithcd45dbc2014-04-19 03:48:30 +00001142 Record.push_back(D->isThisDeclarationADefinition());
1143 if (D->isThisDeclarationADefinition())
1144 Writer.AddCXXDefinitionData(D, Record);
1145
John McCall6bd2a892013-01-25 22:31:03 +00001146 // Store (what we currently believe to be) the key function to avoid
1147 // deserializing every method so we can compute it.
John McCallf937c022011-10-07 06:10:15 +00001148 if (D->IsCompleteDefinition)
John McCall6bd2a892013-01-25 22:31:03 +00001149 Writer.AddDeclRef(Context.getCurrentKeyFunction(D), Record);
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001150
Sebastian Redl539c5062010-08-18 23:57:32 +00001151 Code = serialization::DECL_CXX_RECORD;
Chris Lattnerca025db2010-05-07 21:43:38 +00001152}
1153
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001154void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001155 VisitFunctionDecl(D);
Argyrios Kyrtzidis3b1a7792012-10-12 05:31:40 +00001156 if (D->isCanonicalDecl()) {
1157 Record.push_back(D->size_overridden_methods());
1158 for (CXXMethodDecl::method_iterator
1159 I = D->begin_overridden_methods(), E = D->end_overridden_methods();
1160 I != E; ++I)
1161 Writer.AddDeclRef(*I, Record);
1162 } else {
1163 // We only need to record overridden methods once for the canonical decl.
1164 Record.push_back(0);
1165 }
Richard Smith01b2cb42014-07-26 06:37:51 +00001166
1167 if (D->getFirstDecl() == D->getMostRecentDecl() &&
1168 !D->isInvalidDecl() &&
1169 !D->hasAttrs() &&
1170 !D->isTopLevelDeclInObjCContainer() &&
1171 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
1172 !D->hasExtInfo() &&
1173 !D->hasInheritedPrototype() &&
1174 D->hasWrittenPrototype())
1175 AbbrevToUse = Writer.getDeclCXXMethodAbbrev();
1176
Sebastian Redl539c5062010-08-18 23:57:32 +00001177 Code = serialization::DECL_CXX_METHOD;
Chris Lattnerca025db2010-05-07 21:43:38 +00001178}
1179
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001180void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001181 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001182
Stephan Tolksdorfa6a08632014-03-27 19:22:19 +00001183 Writer.AddDeclRef(D->getInheritedConstructor(), Record);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001184 Record.push_back(D->IsExplicitSpecified);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001185
Sebastian Redl539c5062010-08-18 23:57:32 +00001186 Code = serialization::DECL_CXX_CONSTRUCTOR;
Chris Lattnerca025db2010-05-07 21:43:38 +00001187}
1188
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001189void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001190 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001191
Richard Smithf8134002015-03-10 01:41:22 +00001192 Writer.AddDeclRef(D->getOperatorDelete(), Record);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001193
Sebastian Redl539c5062010-08-18 23:57:32 +00001194 Code = serialization::DECL_CXX_DESTRUCTOR;
Chris Lattnerca025db2010-05-07 21:43:38 +00001195}
1196
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001197void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001198 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001199 Record.push_back(D->IsExplicitSpecified);
Sebastian Redl539c5062010-08-18 23:57:32 +00001200 Code = serialization::DECL_CXX_CONVERSION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001201}
1202
Douglas Gregorba345522011-12-02 23:23:56 +00001203void ASTDeclWriter::VisitImportDecl(ImportDecl *D) {
1204 VisitDecl(D);
Argyrios Kyrtzidis7b8e5552012-10-03 01:58:45 +00001205 Record.push_back(Writer.getSubmoduleID(D->getImportedModule()));
Douglas Gregorba345522011-12-02 23:23:56 +00001206 ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs();
1207 Record.push_back(!IdentifierLocs.empty());
1208 if (IdentifierLocs.empty()) {
1209 Writer.AddSourceLocation(D->getLocEnd(), Record);
1210 Record.push_back(1);
1211 } else {
1212 for (unsigned I = 0, N = IdentifierLocs.size(); I != N; ++I)
1213 Writer.AddSourceLocation(IdentifierLocs[I], Record);
1214 Record.push_back(IdentifierLocs.size());
1215 }
1216 // Note: the number of source locations must always be the last element in
1217 // the record.
1218 Code = serialization::DECL_IMPORT;
1219}
1220
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001221void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001222 VisitDecl(D);
1223 Writer.AddSourceLocation(D->getColonLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001224 Code = serialization::DECL_ACCESS_SPEC;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001225}
1226
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001227void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) {
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001228 // Record the number of friend type template parameter lists here
1229 // so as to simplify memory allocation during deserialization.
1230 Record.push_back(D->NumTPLists);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001231 VisitDecl(D);
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001232 bool hasFriendDecl = D->Friend.is<NamedDecl*>();
1233 Record.push_back(hasFriendDecl);
1234 if (hasFriendDecl)
1235 Writer.AddDeclRef(D->getFriendDecl(), Record);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001236 else
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001237 Writer.AddTypeSourceInfo(D->getFriendType(), Record);
1238 for (unsigned i = 0; i < D->NumTPLists; ++i)
1239 Writer.AddTemplateParameterList(D->getFriendTypeTemplateParameterList(i),
1240 Record);
Douglas Gregore0fb32c2010-10-27 20:23:41 +00001241 Writer.AddDeclRef(D->getNextFriend(), Record);
John McCall2c2eb122010-10-16 06:59:13 +00001242 Record.push_back(D->UnsupportedFriend);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001243 Writer.AddSourceLocation(D->FriendLoc, Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001244 Code = serialization::DECL_FRIEND;
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001245}
1246
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001247void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001248 VisitDecl(D);
1249 Record.push_back(D->getNumTemplateParameters());
1250 for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i)
1251 Writer.AddTemplateParameterList(D->getTemplateParameterList(i), Record);
Craig Toppera13603a2014-05-22 05:54:18 +00001252 Record.push_back(D->getFriendDecl() != nullptr);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001253 if (D->getFriendDecl())
1254 Writer.AddDeclRef(D->getFriendDecl(), Record);
1255 else
1256 Writer.AddTypeSourceInfo(D->getFriendType(), Record);
1257 Writer.AddSourceLocation(D->getFriendLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001258 Code = serialization::DECL_FRIEND_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001259}
1260
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001261void ASTDeclWriter::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001262 VisitNamedDecl(D);
1263
1264 Writer.AddDeclRef(D->getTemplatedDecl(), Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001265 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001266}
1267
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001268void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Douglas Gregor68444de2012-01-14 15:13:49 +00001269 VisitRedeclarable(D);
1270
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001271 // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that
1272 // getCommonPtr() can be used while this is still initializing.
Rafael Espindola8db352d2013-10-17 15:37:26 +00001273 if (D->isFirstDecl()) {
Douglas Gregor074a4092011-12-19 18:19:24 +00001274 // This declaration owns the 'common' pointer, so serialize that data now.
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001275 Writer.AddDeclRef(D->getInstantiatedFromMemberTemplate(), Record);
1276 if (D->getInstantiatedFromMemberTemplate())
1277 Record.push_back(D->isMemberSpecialization());
Douglas Gregor074a4092011-12-19 18:19:24 +00001278 }
1279
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001280 VisitTemplateDecl(D);
1281 Record.push_back(D->getIdentifierNamespace());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001282}
1283
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001284void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001285 VisitRedeclarableTemplateDecl(D);
1286
Richard Smith509fc852015-02-27 23:05:10 +00001287 if (D->isFirstDecl())
1288 AddTemplateSpecializations(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001289 Code = serialization::DECL_CLASS_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001290}
1291
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001292void ASTDeclWriter::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001293 ClassTemplateSpecializationDecl *D) {
Richard Smithd8a83712015-08-22 01:47:18 +00001294 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1295
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001296 VisitCXXRecordDecl(D);
1297
1298 llvm::PointerUnion<ClassTemplateDecl *,
1299 ClassTemplatePartialSpecializationDecl *> InstFrom
1300 = D->getSpecializedTemplateOrPartial();
Argyrios Kyrtzidisd5553f12011-08-17 21:35:28 +00001301 if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) {
Sebastian Redl401b39a2010-08-24 22:50:24 +00001302 Writer.AddDeclRef(InstFromD, Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001303 } else {
Argyrios Kyrtzidisd5553f12011-08-17 21:35:28 +00001304 Writer.AddDeclRef(InstFrom.get<ClassTemplatePartialSpecializationDecl *>(),
1305 Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001306 Writer.AddTemplateArgumentList(&D->getTemplateInstantiationArgs(), Record);
1307 }
1308
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001309 Writer.AddTemplateArgumentList(&D->getTemplateArgs(), Record);
1310 Writer.AddSourceLocation(D->getPointOfInstantiation(), Record);
1311 Record.push_back(D->getSpecializationKind());
Axel Naumanna31dee22012-10-01 07:34:47 +00001312 Record.push_back(D->isCanonicalDecl());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001313
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001314 if (D->isCanonicalDecl()) {
1315 // When reading, we'll add it to the folding set of the following template.
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001316 Writer.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl(), Record);
1317 }
1318
Richard Smithd55889a2013-09-09 16:55:27 +00001319 // Explicit info.
1320 Writer.AddTypeSourceInfo(D->getTypeAsWritten(), Record);
1321 if (D->getTypeAsWritten()) {
1322 Writer.AddSourceLocation(D->getExternLoc(), Record);
1323 Writer.AddSourceLocation(D->getTemplateKeywordLoc(), Record);
1324 }
1325
Sebastian Redl539c5062010-08-18 23:57:32 +00001326 Code = serialization::DECL_CLASS_TEMPLATE_SPECIALIZATION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001327}
1328
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001329void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001330 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001331 VisitClassTemplateSpecializationDecl(D);
1332
1333 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
Enea Zaffanella6dbe1872013-08-10 07:24:53 +00001334 Writer.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten(), Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001335
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001336 // These are read/set from/to the first declaration.
Craig Toppera13603a2014-05-22 05:54:18 +00001337 if (D->getPreviousDecl() == nullptr) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001338 Writer.AddDeclRef(D->getInstantiatedFromMember(), Record);
1339 Record.push_back(D->isMemberSpecialization());
1340 }
1341
Sebastian Redl539c5062010-08-18 23:57:32 +00001342 Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001343}
1344
Larisse Voufo39a1e502013-08-06 01:03:05 +00001345void ASTDeclWriter::VisitVarTemplateDecl(VarTemplateDecl *D) {
1346 VisitRedeclarableTemplateDecl(D);
1347
Richard Smith509fc852015-02-27 23:05:10 +00001348 if (D->isFirstDecl())
1349 AddTemplateSpecializations(D);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001350 Code = serialization::DECL_VAR_TEMPLATE;
1351}
1352
1353void ASTDeclWriter::VisitVarTemplateSpecializationDecl(
1354 VarTemplateSpecializationDecl *D) {
Richard Smithd8a83712015-08-22 01:47:18 +00001355 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1356
Larisse Voufo39a1e502013-08-06 01:03:05 +00001357 VisitVarDecl(D);
1358
1359 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
1360 InstFrom = D->getSpecializedTemplateOrPartial();
1361 if (Decl *InstFromD = InstFrom.dyn_cast<VarTemplateDecl *>()) {
1362 Writer.AddDeclRef(InstFromD, Record);
1363 } else {
1364 Writer.AddDeclRef(InstFrom.get<VarTemplatePartialSpecializationDecl *>(),
1365 Record);
1366 Writer.AddTemplateArgumentList(&D->getTemplateInstantiationArgs(), Record);
1367 }
1368
1369 // Explicit info.
1370 Writer.AddTypeSourceInfo(D->getTypeAsWritten(), Record);
1371 if (D->getTypeAsWritten()) {
1372 Writer.AddSourceLocation(D->getExternLoc(), Record);
1373 Writer.AddSourceLocation(D->getTemplateKeywordLoc(), Record);
1374 }
1375
1376 Writer.AddTemplateArgumentList(&D->getTemplateArgs(), Record);
1377 Writer.AddSourceLocation(D->getPointOfInstantiation(), Record);
1378 Record.push_back(D->getSpecializationKind());
1379 Record.push_back(D->isCanonicalDecl());
1380
1381 if (D->isCanonicalDecl()) {
1382 // When reading, we'll add it to the folding set of the following template.
1383 Writer.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl(), Record);
1384 }
1385
1386 Code = serialization::DECL_VAR_TEMPLATE_SPECIALIZATION;
1387}
1388
1389void ASTDeclWriter::VisitVarTemplatePartialSpecializationDecl(
1390 VarTemplatePartialSpecializationDecl *D) {
1391 VisitVarTemplateSpecializationDecl(D);
1392
1393 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
Enea Zaffanella6dbe1872013-08-10 07:24:53 +00001394 Writer.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten(), Record);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001395
1396 // These are read/set from/to the first declaration.
Craig Toppera13603a2014-05-22 05:54:18 +00001397 if (D->getPreviousDecl() == nullptr) {
Larisse Voufo39a1e502013-08-06 01:03:05 +00001398 Writer.AddDeclRef(D->getInstantiatedFromMember(), Record);
1399 Record.push_back(D->isMemberSpecialization());
1400 }
1401
1402 Code = serialization::DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION;
1403}
1404
Fariborz Jahanian3a039e32011-08-27 20:50:59 +00001405void ASTDeclWriter::VisitClassScopeFunctionSpecializationDecl(
1406 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichet09af8c32011-08-17 01:06:54 +00001407 VisitDecl(D);
1408 Writer.AddDeclRef(D->getSpecialization(), Record);
1409 Code = serialization::DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION;
1410}
1411
1412
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001413void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001414 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001415
Richard Smith509fc852015-02-27 23:05:10 +00001416 if (D->isFirstDecl())
1417 AddTemplateSpecializations(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001418 Code = serialization::DECL_FUNCTION_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001419}
1420
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001421void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001422 VisitTypeDecl(D);
1423
1424 Record.push_back(D->wasDeclaredWithTypename());
Richard Smith8346e522015-06-10 01:47:58 +00001425
1426 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1427 !D->defaultArgumentWasInherited();
1428 Record.push_back(OwnsDefaultArg);
1429 if (OwnsDefaultArg)
Richard Smith1469b912015-06-10 00:29:03 +00001430 Writer.AddTypeSourceInfo(D->getDefaultArgumentInfo(), Record);
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001431
Sebastian Redl539c5062010-08-18 23:57:32 +00001432 Code = serialization::DECL_TEMPLATE_TYPE_PARM;
Chris Lattnerca025db2010-05-07 21:43:38 +00001433}
1434
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001435void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001436 // For an expanded parameter pack, record the number of expansion types here
Richard Smith1fde8ec2012-09-07 02:06:42 +00001437 // so that it's easier for deserialization to allocate the right amount of
1438 // memory.
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001439 if (D->isExpandedParameterPack())
1440 Record.push_back(D->getNumExpansionTypes());
1441
John McCallf4cd4f92011-02-09 01:13:10 +00001442 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001443 // TemplateParmPosition.
1444 Record.push_back(D->getDepth());
1445 Record.push_back(D->getPosition());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001446
1447 if (D->isExpandedParameterPack()) {
1448 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
1449 Writer.AddTypeRef(D->getExpansionType(I), Record);
1450 Writer.AddTypeSourceInfo(D->getExpansionTypeSourceInfo(I), Record);
1451 }
1452
1453 Code = serialization::DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK;
1454 } else {
1455 // Rest of NonTypeTemplateParmDecl.
1456 Record.push_back(D->isParameterPack());
Richard Smith8346e522015-06-10 01:47:58 +00001457 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1458 !D->defaultArgumentWasInherited();
1459 Record.push_back(OwnsDefaultArg);
1460 if (OwnsDefaultArg)
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001461 Writer.AddStmt(D->getDefaultArgument());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001462 Code = serialization::DECL_NON_TYPE_TEMPLATE_PARM;
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001463 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001464}
1465
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001466void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Richard Smith1fde8ec2012-09-07 02:06:42 +00001467 // For an expanded parameter pack, record the number of expansion types here
1468 // so that it's easier for deserialization to allocate the right amount of
1469 // memory.
1470 if (D->isExpandedParameterPack())
1471 Record.push_back(D->getNumExpansionTemplateParameters());
1472
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001473 VisitTemplateDecl(D);
1474 // TemplateParmPosition.
1475 Record.push_back(D->getDepth());
1476 Record.push_back(D->getPosition());
Richard Smith1fde8ec2012-09-07 02:06:42 +00001477
1478 if (D->isExpandedParameterPack()) {
1479 for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
1480 I != N; ++I)
1481 Writer.AddTemplateParameterList(D->getExpansionTemplateParameters(I),
1482 Record);
1483 Code = serialization::DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK;
1484 } else {
1485 // Rest of TemplateTemplateParmDecl.
Richard Smith1fde8ec2012-09-07 02:06:42 +00001486 Record.push_back(D->isParameterPack());
Richard Smith8346e522015-06-10 01:47:58 +00001487 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1488 !D->defaultArgumentWasInherited();
1489 Record.push_back(OwnsDefaultArg);
1490 if (OwnsDefaultArg)
Richard Smith1469b912015-06-10 00:29:03 +00001491 Writer.AddTemplateArgumentLoc(D->getDefaultArgument(), Record);
Richard Smith1fde8ec2012-09-07 02:06:42 +00001492 Code = serialization::DECL_TEMPLATE_TEMPLATE_PARM;
1493 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001494}
1495
Richard Smith3f1b5d02011-05-05 21:57:07 +00001496void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1497 VisitRedeclarableTemplateDecl(D);
1498 Code = serialization::DECL_TYPE_ALIAS_TEMPLATE;
1499}
1500
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001501void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001502 VisitDecl(D);
1503 Writer.AddStmt(D->getAssertExpr());
Richard Smithded9c2e2012-07-11 22:37:56 +00001504 Record.push_back(D->isFailed());
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001505 Writer.AddStmt(D->getMessage());
Abramo Bagnaraea947882011-03-08 16:41:52 +00001506 Writer.AddSourceLocation(D->getRParenLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001507 Code = serialization::DECL_STATIC_ASSERT;
Chris Lattnerca025db2010-05-07 21:43:38 +00001508}
1509
Chris Lattner7099dbc2009-04-27 06:16:06 +00001510/// \brief Emit the DeclContext part of a declaration context decl.
1511///
1512/// \param LexicalOffset the offset at which the DECL_CONTEXT_LEXICAL
1513/// block for this declaration context is stored. May be 0 to indicate
1514/// that there are no declarations stored within this context.
1515///
1516/// \param VisibleOffset the offset at which the DECL_CONTEXT_VISIBLE
1517/// block for this declaration context is stored. May be 0 to indicate
1518/// that there are no declarations visible from this context. Note
1519/// that this value will not be emitted for non-primary declaration
1520/// contexts.
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001521void ASTDeclWriter::VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset,
Chris Lattner7099dbc2009-04-27 06:16:06 +00001522 uint64_t VisibleOffset) {
1523 Record.push_back(LexicalOffset);
1524 Record.push_back(VisibleOffset);
1525}
1526
Richard Smithd8a83712015-08-22 01:47:18 +00001527/// \brief Is this a local declaration (that is, one that will be written to
1528/// our AST file)? This is the case for declarations that are neither imported
1529/// from another AST file nor predefined.
1530static bool isLocalDecl(ASTWriter &W, const Decl *D) {
1531 if (D->isFromASTFile())
1532 return false;
1533 return W.getDeclID(D) >= NUM_PREDEF_DECL_IDS;
1534}
1535
1536const Decl *ASTWriter::getFirstLocalDecl(const Decl *D) {
1537 assert(isLocalDecl(*this, D) && "expected a local declaration");
1538
1539 const Decl *Canon = D->getCanonicalDecl();
1540 if (isLocalDecl(*this, Canon))
1541 return Canon;
1542
1543 const Decl *&CacheEntry = FirstLocalDeclCache[Canon];
1544 if (CacheEntry)
1545 return CacheEntry;
1546
1547 for (const Decl *Redecl = D; Redecl; Redecl = Redecl->getPreviousDecl())
1548 if (isLocalDecl(*this, Redecl))
1549 D = Redecl;
1550 return CacheEntry = D;
Richard Smith5fc18a92015-07-12 23:43:21 +00001551}
1552
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001553template <typename T>
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001554void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +00001555 T *First = D->getFirstDecl();
Richard Smith5a4737c2015-02-06 02:42:59 +00001556 T *MostRecent = First->getMostRecentDecl();
Richard Smithd8a83712015-08-22 01:47:18 +00001557 T *DAsT = static_cast<T *>(D);
Richard Smith5a4737c2015-02-06 02:42:59 +00001558 if (MostRecent != First) {
Richard Smithd8a83712015-08-22 01:47:18 +00001559 assert(isRedeclarableDeclKind(DAsT->getKind()) &&
Douglas Gregorfe732d52013-01-21 16:16:40 +00001560 "Not considered redeclarable?");
Richard Smith5a4737c2015-02-06 02:42:59 +00001561
Richard Smithfe620d22015-03-05 23:24:12 +00001562 Writer.AddDeclRef(First, Record);
Richard Smithfe620d22015-03-05 23:24:12 +00001563
Richard Smithd8a83712015-08-22 01:47:18 +00001564 // Write out a list of local redeclarations of this declaration if it's the
1565 // first local declaration in the chain.
1566 const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1567 if (DAsT == FirstLocal) {
Richard Smithd8a83712015-08-22 01:47:18 +00001568 // Emit a list of all imported first declarations so that we can be sure
1569 // that all redeclarations visible to this module are before D in the
1570 // redecl chain.
1571 unsigned I = Record.size();
1572 Record.push_back(0);
1573 if (Writer.Chain)
1574 AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1575 // This is the number of imported first declarations + 1.
1576 Record[I] = Record.size() - I;
Richard Smithd61d4ac2015-08-22 20:13:39 +00001577
1578 // Collect the set of local redeclarations of this declaration, from
1579 // newest to oldest.
1580 RecordData LocalRedecls;
1581 for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1582 Prev != FirstLocal; Prev = Prev->getPreviousDecl())
1583 if (!Prev->isFromASTFile())
1584 Writer.AddDeclRef(Prev, LocalRedecls);
1585
1586 // If we have any redecls, write them now as a separate record preceding
1587 // the declaration itself.
1588 if (LocalRedecls.empty())
1589 Record.push_back(0);
1590 else {
1591 Record.push_back(Writer.Stream.GetCurrentBitNo());
1592 Writer.Stream.EmitRecord(LOCAL_REDECLARATIONS, LocalRedecls);
1593 }
Richard Smithd8a83712015-08-22 01:47:18 +00001594 } else {
1595 Record.push_back(0);
1596 Writer.AddDeclRef(FirstLocal, Record);
Richard Smithfe620d22015-03-05 23:24:12 +00001597 }
Douglas Gregor358cd442012-01-15 16:58:34 +00001598
1599 // Make sure that we serialize both the previous and the most-recent
1600 // declarations, which (transitively) ensures that all declarations in the
1601 // chain get serialized.
Richard Smith5a4737c2015-02-06 02:42:59 +00001602 //
1603 // FIXME: This is not correct; when we reach an imported declaration we
1604 // won't emit its previous declaration.
Richard Smith5fc18a92015-07-12 23:43:21 +00001605 (void)Writer.GetDeclRef(D->getPreviousDecl());
Richard Smith5a4737c2015-02-06 02:42:59 +00001606 (void)Writer.GetDeclRef(MostRecent);
Douglas Gregor358cd442012-01-15 16:58:34 +00001607 } else {
1608 // We use the sentinel value 0 to indicate an only declaration.
1609 Record.push_back(0);
Douglas Gregor9f562c82011-12-19 15:27:36 +00001610 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001611}
Chris Lattner7099dbc2009-04-27 06:16:06 +00001612
Alexey Bataeva769e072013-03-22 06:34:35 +00001613void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
1614 Record.push_back(D->varlist_size());
1615 VisitDecl(D);
Aaron Ballman2205d2a2014-03-14 15:55:35 +00001616 for (auto *I : D->varlists())
1617 Writer.AddStmt(I);
Alexey Bataeva769e072013-03-22 06:34:35 +00001618 Code = serialization::DECL_OMP_THREADPRIVATE;
1619}
1620
Chris Lattner7099dbc2009-04-27 06:16:06 +00001621//===----------------------------------------------------------------------===//
Sebastian Redl55c0ad52010-08-18 23:56:21 +00001622// ASTWriter Implementation
Chris Lattner7099dbc2009-04-27 06:16:06 +00001623//===----------------------------------------------------------------------===//
1624
Richard Smith01b2cb42014-07-26 06:37:51 +00001625void ASTWriter::WriteDeclAbbrevs() {
Chris Lattner258172e2009-04-27 07:35:58 +00001626 using namespace llvm;
Chris Lattner258172e2009-04-27 07:35:58 +00001627
Douglas Gregor03412ba2011-06-03 02:27:19 +00001628 BitCodeAbbrev *Abv;
1629
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001630 // Abbreviation for DECL_FIELD
1631 Abv = new BitCodeAbbrev();
1632 Abv->Add(BitCodeAbbrevOp(serialization::DECL_FIELD));
1633 // Decl
1634 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
1635 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001636 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001637 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1638 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1639 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1640 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001641 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001642 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001643 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001644 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001645 // NamedDecl
1646 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1647 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001648 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001649 // ValueDecl
1650 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1651 // DeclaratorDecl
1652 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1653 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
1654 // FieldDecl
1655 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
1656 Abv->Add(BitCodeAbbrevOp(0)); //getBitWidth
1657 // Type Source Info
1658 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1659 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1660 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1661 DeclFieldAbbrev = Stream.EmitAbbrev(Abv);
1662
1663 // Abbreviation for DECL_OBJC_IVAR
1664 Abv = new BitCodeAbbrev();
1665 Abv->Add(BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR));
1666 // Decl
1667 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
1668 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001669 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001670 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1671 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1672 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1673 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001674 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001675 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001676 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001677 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001678 // NamedDecl
1679 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1680 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001681 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001682 // ValueDecl
1683 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1684 // DeclaratorDecl
1685 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1686 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
1687 // FieldDecl
1688 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
1689 Abv->Add(BitCodeAbbrevOp(0)); //getBitWidth
1690 // ObjC Ivar
1691 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl
1692 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize
1693 // Type Source Info
1694 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1695 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1696 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1697 DeclObjCIvarAbbrev = Stream.EmitAbbrev(Abv);
1698
1699 // Abbreviation for DECL_ENUM
1700 Abv = new BitCodeAbbrev();
1701 Abv->Add(BitCodeAbbrevOp(serialization::DECL_ENUM));
Douglas Gregor3e300102011-10-26 17:53:41 +00001702 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001703 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Chris Lattner258172e2009-04-27 07:35:58 +00001704 // Decl
1705 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
1706 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001707 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Chris Lattner258172e2009-04-27 07:35:58 +00001708 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1709 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
Douglas Gregorc9c02ed2009-06-19 23:52:42 +00001710 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +00001711 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001712 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Chris Lattner258172e2009-04-27 07:35:58 +00001713 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001714 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001715 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Douglas Gregor03412ba2011-06-03 02:27:19 +00001716 // NamedDecl
1717 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1718 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001719 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001720 // TypeDecl
1721 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1722 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001723 // TagDecl
1724 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
1725 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
John McCallf937c022011-10-07 06:10:15 +00001726 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001727 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +00001728 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
David Blaikiea8d23ce2013-07-14 01:07:41 +00001729 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001730 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Richard Smith70d58502014-08-30 00:04:23 +00001731 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001732 // EnumDecl
1733 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddTypeRef
1734 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IntegerType
1735 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getPromotionType
1736 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumPositiveBits
1737 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumNegativeBits
1738 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScoped
1739 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScopedUsingClassTag
1740 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isFixed
1741 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedMembEnum
1742 // DC
1743 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
1744 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
1745 DeclEnumAbbrev = Stream.EmitAbbrev(Abv);
Mike Stump11289f42009-09-09 15:08:12 +00001746
Douglas Gregor03412ba2011-06-03 02:27:19 +00001747 // Abbreviation for DECL_RECORD
1748 Abv = new BitCodeAbbrev();
1749 Abv->Add(BitCodeAbbrevOp(serialization::DECL_RECORD));
Douglas Gregor3e300102011-10-26 17:53:41 +00001750 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001751 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Douglas Gregor03412ba2011-06-03 02:27:19 +00001752 // Decl
1753 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
1754 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001755 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Douglas Gregor03412ba2011-06-03 02:27:19 +00001756 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1757 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1758 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1759 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001760 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Douglas Gregor03412ba2011-06-03 02:27:19 +00001761 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001762 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001763 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Douglas Gregor03412ba2011-06-03 02:27:19 +00001764 // NamedDecl
1765 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1766 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001767 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Douglas Gregor03412ba2011-06-03 02:27:19 +00001768 // TypeDecl
1769 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1770 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
Douglas Gregor03412ba2011-06-03 02:27:19 +00001771 // TagDecl
1772 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
1773 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
John McCallf937c022011-10-07 06:10:15 +00001774 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
Douglas Gregor03412ba2011-06-03 02:27:19 +00001775 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +00001776 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
David Blaikiea8d23ce2013-07-14 01:07:41 +00001777 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
Douglas Gregor03412ba2011-06-03 02:27:19 +00001778 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Richard Smith70d58502014-08-30 00:04:23 +00001779 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
Douglas Gregor03412ba2011-06-03 02:27:19 +00001780 // RecordDecl
1781 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // FlexibleArrayMember
1782 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // AnonymousStructUnion
1783 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasObjectMember
Fariborz Jahanian78652202013-01-25 23:57:05 +00001784 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasVolatileMember
Douglas Gregor03412ba2011-06-03 02:27:19 +00001785 // DC
1786 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
1787 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
1788 DeclRecordAbbrev = Stream.EmitAbbrev(Abv);
1789
1790 // Abbreviation for DECL_PARM_VAR
1791 Abv = new BitCodeAbbrev();
1792 Abv->Add(BitCodeAbbrevOp(serialization::DECL_PARM_VAR));
Douglas Gregor3e300102011-10-26 17:53:41 +00001793 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001794 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Douglas Gregor03412ba2011-06-03 02:27:19 +00001795 // Decl
1796 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
1797 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001798 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Douglas Gregor03412ba2011-06-03 02:27:19 +00001799 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1800 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1801 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1802 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001803 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Douglas Gregor03412ba2011-06-03 02:27:19 +00001804 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001805 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001806 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Chris Lattner258172e2009-04-27 07:35:58 +00001807 // NamedDecl
1808 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1809 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001810 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Chris Lattner258172e2009-04-27 07:35:58 +00001811 // ValueDecl
1812 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +00001813 // DeclaratorDecl
Abramo Bagnaradff19302011-03-08 08:55:46 +00001814 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00001815 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Chris Lattner258172e2009-04-27 07:35:58 +00001816 // VarDecl
1817 Abv->Add(BitCodeAbbrevOp(0)); // StorageClass
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +00001818 Abv->Add(BitCodeAbbrevOp(0)); // getTSCSpec
Chris Lattner258172e2009-04-27 07:35:58 +00001819 Abv->Add(BitCodeAbbrevOp(0)); // hasCXXDirectInitializer
Richard Smith88581592013-02-12 05:48:23 +00001820 Abv->Add(BitCodeAbbrevOp(0)); // Linkage
Chris Lattner258172e2009-04-27 07:35:58 +00001821 Abv->Add(BitCodeAbbrevOp(0)); // HasInit
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001822 Abv->Add(BitCodeAbbrevOp(0)); // HasMemberSpecializationInfo
Chris Lattner258172e2009-04-27 07:35:58 +00001823 // ParmVarDecl
John McCall82490832011-05-02 00:30:12 +00001824 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsObjCMethodParameter
John McCall8fb0d9d2011-05-01 22:35:37 +00001825 Abv->Add(BitCodeAbbrevOp(0)); // ScopeDepth
1826 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex
Chris Lattner258172e2009-04-27 07:35:58 +00001827 Abv->Add(BitCodeAbbrevOp(0)); // ObjCDeclQualifier
John McCall6a014d52011-03-09 04:22:44 +00001828 Abv->Add(BitCodeAbbrevOp(0)); // KNRPromoted
John McCallf3cd6652010-03-12 18:31:32 +00001829 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedDefaultArg
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +00001830 Abv->Add(BitCodeAbbrevOp(0)); // HasUninstantiatedDefaultArg
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001831 // Type Source Info
1832 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1833 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1834 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1835 DeclParmVarAbbrev = Stream.EmitAbbrev(Abv);
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001836
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00001837 // Abbreviation for DECL_TYPEDEF
Douglas Gregor03412ba2011-06-03 02:27:19 +00001838 Abv = new BitCodeAbbrev();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001839 Abv->Add(BitCodeAbbrevOp(serialization::DECL_TYPEDEF));
Douglas Gregor05f10352011-12-17 23:38:30 +00001840 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001841 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001842 // Decl
1843 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
1844 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001845 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001846 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1847 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
Richard Smith01b2cb42014-07-26 06:37:51 +00001848 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isUsed
1849 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001850 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Richard Smith01b2cb42014-07-26 06:37:51 +00001851 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001852 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001853 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001854 // NamedDecl
1855 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1856 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001857 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001858 // TypeDecl
1859 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1860 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
1861 // TypedefDecl
1862 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1863 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1864 DeclTypedefAbbrev = Stream.EmitAbbrev(Abv);
1865
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00001866 // Abbreviation for DECL_VAR
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001867 Abv = new BitCodeAbbrev();
1868 Abv->Add(BitCodeAbbrevOp(serialization::DECL_VAR));
Douglas Gregor3e300102011-10-26 17:53:41 +00001869 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001870 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001871 // Decl
1872 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
1873 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001874 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001875 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1876 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1877 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1878 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001879 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001880 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001881 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001882 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001883 // NamedDecl
1884 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1885 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001886 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001887 // ValueDecl
1888 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1889 // DeclaratorDecl
1890 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1891 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
1892 // VarDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001893 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // StorageClass
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +00001894 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // getTSCSpec
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001895 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // CXXDirectInitializer
1896 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isExceptionVariable
1897 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isNRVOVariable
1898 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCXXForRangeDecl
John McCalld4631322011-06-17 06:42:21 +00001899 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong
Douglas Gregor12cda632012-09-20 23:43:29 +00001900 Abv->Add(BitCodeAbbrevOp(0)); // isConstexpr
Richard Smithbb13c9a2013-09-28 04:02:39 +00001901 Abv->Add(BitCodeAbbrevOp(0)); // isInitCapture
Richard Smith1c34fb72013-08-13 18:18:50 +00001902 Abv->Add(BitCodeAbbrevOp(0)); // isPrevDeclInSameScope
Rafael Espindola50df3a02013-05-25 17:16:20 +00001903 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001904 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasInit
1905 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasMemberSpecInfo
1906 // Type Source Info
1907 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1908 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1909 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1910 DeclVarAbbrev = Stream.EmitAbbrev(Abv);
1911
Richard Smith01b2cb42014-07-26 06:37:51 +00001912 // Abbreviation for DECL_CXX_METHOD
1913 Abv = new BitCodeAbbrev();
1914 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CXX_METHOD));
1915 // RedeclarableDecl
1916 Abv->Add(BitCodeAbbrevOp(0)); // CanonicalDecl
1917 // Decl
1918 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
1919 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalDeclContext
1920 Abv->Add(BitCodeAbbrevOp(0)); // Invalid
1921 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1922 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Implicit
1923 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Used
1924 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Referenced
1925 Abv->Add(BitCodeAbbrevOp(0)); // InObjCContainer
1926 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Access
1927 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ModulePrivate
1928 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
1929 // NamedDecl
1930 Abv->Add(BitCodeAbbrevOp(DeclarationName::Identifier)); // NameKind
1931 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Identifier
Richard Smith2b560572015-02-07 03:11:11 +00001932 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Richard Smith01b2cb42014-07-26 06:37:51 +00001933 // ValueDecl
1934 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1935 // DeclaratorDecl
1936 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerLocStart
1937 Abv->Add(BitCodeAbbrevOp(0)); // HasExtInfo
1938 // FunctionDecl
1939 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS
1940 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // StorageClass
1941 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Inline
1942 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InlineSpecified
1943 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // VirtualAsWritten
1944 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Pure
1945 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedProto
1946 Abv->Add(BitCodeAbbrevOp(1)); // HasWrittenProto
Richard Smith72625c22015-02-06 23:20:21 +00001947 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Deleted
Richard Smith01b2cb42014-07-26 06:37:51 +00001948 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Trivial
1949 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Defaulted
1950 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ExplicitlyDefaulted
1951 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ImplicitReturnZero
1952 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Constexpr
1953 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // SkippedBody
1954 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // LateParsed
1955 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
1956 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LocEnd
1957 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // TemplateKind
1958 // This Array slurps the rest of the record. Fortunately we want to encode
1959 // (nearly) all the remaining (variable number of) fields in the same way.
1960 //
1961 // This is the function template information if any, then
1962 // NumParams and Params[] from FunctionDecl, and
1963 // NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl.
1964 //
1965 // Add an AbbrevOp for 'size then elements' and use it here.
1966 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1967 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1968 DeclCXXMethodAbbrev = Stream.EmitAbbrev(Abv);
1969
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00001970 // Abbreviation for EXPR_DECL_REF
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001971 Abv = new BitCodeAbbrev();
Douglas Gregor03412ba2011-06-03 02:27:19 +00001972 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_DECL_REF));
1973 //Stmt
1974 //Expr
1975 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00001976 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
1977 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
1978 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00001979 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
1980 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
1981 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
1982 //DeclRefExpr
1983 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HasQualifier
1984 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //GetDeclFound
1985 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ExplicitTemplateArgs
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00001986 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HadMultipleCandidates
Alexey Bataev19acc3d2015-01-12 10:17:46 +00001987 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
1988 1)); // RefersToEnclosingVariableOrCapture
Douglas Gregor03412ba2011-06-03 02:27:19 +00001989 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef
1990 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
1991 DeclRefExprAbbrev = Stream.EmitAbbrev(Abv);
1992
1993 // Abbreviation for EXPR_INTEGER_LITERAL
1994 Abv = new BitCodeAbbrev();
1995 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL));
1996 //Stmt
1997 //Expr
1998 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00001999 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2000 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2001 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002002 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2003 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2004 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2005 //Integer Literal
2006 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2007 Abv->Add(BitCodeAbbrevOp(32)); // Bit Width
2008 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value
2009 IntegerLiteralAbbrev = Stream.EmitAbbrev(Abv);
2010
2011 // Abbreviation for EXPR_CHARACTER_LITERAL
2012 Abv = new BitCodeAbbrev();
2013 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL));
2014 //Stmt
2015 //Expr
2016 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002017 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2018 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2019 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002020 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2021 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2022 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
Jonathan D. Turnerd09655f2011-06-03 21:46:44 +00002023 //Character Literal
Douglas Gregor03412ba2011-06-03 02:27:19 +00002024 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue
2025 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
Eli Friedman21530f72012-09-14 00:51:36 +00002026 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // getKind
Douglas Gregor03412ba2011-06-03 02:27:19 +00002027 CharacterLiteralAbbrev = Stream.EmitAbbrev(Abv);
2028
Richard Smitha27c26e2014-07-27 04:19:32 +00002029 // Abbreviation for EXPR_IMPLICIT_CAST
2030 Abv = new BitCodeAbbrev();
2031 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_IMPLICIT_CAST));
2032 // Stmt
2033 // Expr
2034 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2035 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2036 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2037 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
2038 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2039 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2040 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2041 // CastExpr
2042 Abv->Add(BitCodeAbbrevOp(0)); // PathSize
2043 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 6)); // CastKind
2044 // ImplicitCastExpr
2045 ExprImplicitCastAbbrev = Stream.EmitAbbrev(Abv);
2046
Sebastian Redl66c5eef2010-07-27 00:17:23 +00002047 Abv = new BitCodeAbbrev();
Sebastian Redl539c5062010-08-18 23:57:32 +00002048 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL));
Sebastian Redl66c5eef2010-07-27 00:17:23 +00002049 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2050 DeclContextLexicalAbbrev = Stream.EmitAbbrev(Abv);
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002051
2052 Abv = new BitCodeAbbrev();
2053 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE));
2054 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));
2055 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2056 DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(Abv);
Chris Lattner258172e2009-04-27 07:35:58 +00002057}
2058
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002059/// isRequiredDecl - Check if this is a "required" Decl, which must be seen by
2060/// consumers of the AST.
2061///
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002062/// Such decls will always be deserialized from the AST file, so we would like
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002063/// this to be as restrictive as possible. Currently the predicate is driven by
2064/// code generation requirements, if other clients have a different notion of
2065/// what is "required" then we may have to consider an alternate scheme where
2066/// clients can iterate over the top-level decls and get information on them,
2067/// without necessary deserializing them. We could explicitly require such
2068/// clients to use a separate API call to "realize" the decl. This should be
2069/// relatively painless since they would presumably only do it for top-level
2070/// decls.
Richard Smithc52efa72015-08-19 02:30:28 +00002071static bool isRequiredDecl(const Decl *D, ASTContext &Context,
2072 bool WritingModule) {
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00002073 // An ObjCMethodDecl is never considered as "required" because its
2074 // implementation container always is.
2075
Richard Smithc52efa72015-08-19 02:30:28 +00002076 // File scoped assembly or obj-c implementation must be seen.
2077 if (isa<FileScopeAsmDecl>(D) || isa<ObjCImplDecl>(D))
2078 return true;
2079
2080 // ImportDecl is used by codegen to determine the set of imported modules to
2081 // search for inputs for automatic linking; include it if it has a semantic
2082 // effect.
2083 if (isa<ImportDecl>(D) && !WritingModule)
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002084 return true;
2085
Argyrios Kyrtzidisc9049332010-07-29 20:08:05 +00002086 return Context.DeclMustBeEmitted(D);
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002087}
2088
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002089void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) {
Argyrios Kyrtzidisd9f526f2010-10-28 09:29:32 +00002090 // Switch case IDs are per Decl.
2091 ClearSwitchCaseIDs();
2092
Chris Lattner7099dbc2009-04-27 06:16:06 +00002093 RecordData Record;
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002094 ASTDeclWriter W(*this, Context, Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +00002095
Douglas Gregorb3163e52012-01-05 22:33:30 +00002096 // Determine the ID for this declaration.
2097 serialization::DeclID ID;
Richard Smith5a4737c2015-02-06 02:42:59 +00002098 if (D->isFromASTFile()) {
2099 assert(isRewritten(D) && "should not be emitting imported decl");
Douglas Gregorb3163e52012-01-05 22:33:30 +00002100 ID = getDeclID(D);
Richard Smith5a4737c2015-02-06 02:42:59 +00002101 } else {
Douglas Gregorb3163e52012-01-05 22:33:30 +00002102 serialization::DeclID &IDR = DeclIDs[D];
2103 if (IDR == 0)
2104 IDR = NextDeclID++;
2105
2106 ID= IDR;
2107 }
Argyrios Kyrtzidisbf6c3392012-03-22 16:08:04 +00002108
2109 bool isReplacingADecl = ID < FirstDeclID;
2110
2111 // If this declaration is also a DeclContext, write blocks for the
2112 // declarations that lexically stored inside its context and those
2113 // declarations that are visible from its context. These blocks
2114 // are written before the declaration itself so that we can put
2115 // their offsets into the record for the declaration.
2116 uint64_t LexicalOffset = 0;
2117 uint64_t VisibleOffset = 0;
2118 DeclContext *DC = dyn_cast<DeclContext>(D);
2119 if (DC) {
2120 if (isReplacingADecl) {
2121 // It is replacing a decl from a chained PCH; make sure that the
2122 // DeclContext is fully loaded.
2123 if (DC->hasExternalLexicalStorage())
2124 DC->LoadLexicalDeclsFromExternalStorage();
2125 if (DC->hasExternalVisibleStorage())
2126 Chain->completeVisibleDeclsMap(DC);
2127 }
2128 LexicalOffset = WriteDeclContextLexicalBlock(Context, DC);
2129 VisibleOffset = WriteDeclContextVisibleBlock(Context, DC);
2130 }
Douglas Gregorb3163e52012-01-05 22:33:30 +00002131
Richard Smithd61d4ac2015-08-22 20:13:39 +00002132 // Build a record for this declaration
2133 Record.clear();
2134 W.Code = (serialization::DeclCode)0;
2135 W.AbbrevToUse = 0;
2136 W.Visit(D);
2137 if (DC) W.VisitDeclContext(DC, LexicalOffset, VisibleOffset);
2138
Argyrios Kyrtzidisbf6c3392012-03-22 16:08:04 +00002139 if (isReplacingADecl) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002140 // We're replacing a decl in a previous file.
Argyrios Kyrtzidis6fb60032011-10-31 07:20:15 +00002141 ReplacedDecls.push_back(ReplacedDeclInfo(ID, Stream.GetCurrentBitNo(),
2142 D->getLocation()));
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002143 } else {
2144 unsigned Index = ID - FirstDeclID;
Douglas Gregor12bfa382009-10-17 00:13:19 +00002145
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002146 // Record the offset for this declaration
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +00002147 SourceLocation Loc = D->getLocation();
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002148 if (DeclOffsets.size() == Index)
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +00002149 DeclOffsets.push_back(DeclOffset(Loc, Stream.GetCurrentBitNo()));
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002150 else if (DeclOffsets.size() < Index) {
2151 DeclOffsets.resize(Index+1);
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +00002152 DeclOffsets[Index].setLocation(Loc);
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00002153 DeclOffsets[Index].BitOffset = Stream.GetCurrentBitNo();
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002154 }
Richard Smithd61d4ac2015-08-22 20:13:39 +00002155
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +00002156 SourceManager &SM = Context.getSourceManager();
Argyrios Kyrtzidisdf53da82011-10-28 23:57:43 +00002157 if (Loc.isValid() && SM.isLocalSourceLocation(Loc))
2158 associateDeclWithFile(D, ID);
Douglas Gregor12bfa382009-10-17 00:13:19 +00002159 }
2160
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +00002161 if (!W.Code)
Chris Lattner0e62c1c2011-07-23 10:55:15 +00002162 llvm::report_fatal_error(StringRef("unexpected declaration kind '") +
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +00002163 D->getDeclKindName() + "'");
Douglas Gregor12bfa382009-10-17 00:13:19 +00002164 Stream.EmitRecord(W.Code, Record, W.AbbrevToUse);
2165
Richard Smithc2bb8182015-03-24 06:36:48 +00002166 // Flush any expressions, base specifiers, and ctor initializers that
2167 // were written as part of this declaration.
2168 FlushPendingAfterDecl();
2169
Ben Langmuir332aafe2014-01-31 01:06:56 +00002170 // Note declarations that should be deserialized eagerly so that we can add
2171 // them to a record in the AST file later.
Richard Smithc52efa72015-08-19 02:30:28 +00002172 if (isRequiredDecl(D, Context, WritingModule))
Ben Langmuir332aafe2014-01-31 01:06:56 +00002173 EagerlyDeserializedDecls.push_back(ID);
Chris Lattner7099dbc2009-04-27 06:16:06 +00002174}
Richard Smithd28ac5b2014-03-22 23:33:22 +00002175
2176void ASTWriter::AddFunctionDefinition(const FunctionDecl *FD,
2177 RecordData &Record) {
2178 ClearSwitchCaseIDs();
2179
2180 ASTDeclWriter W(*this, FD->getASTContext(), Record);
2181 W.AddFunctionDefinition(FD);
2182}