blob: ee693bf2fc7959e426eb5c740b672944ce8a01c0 [file] [log] [blame]
Sebastian Redld6522cf2010-08-18 23:56:31 +00001//===--- ASTWriterDecl.cpp - Declaration Serialization --------------------===//
Chris Lattner7099dbc2009-04-27 06:16:06 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements serialization for Declarations.
11//
12//===----------------------------------------------------------------------===//
13
Sebastian Redl1914c6f2010-08-18 23:56:37 +000014#include "clang/Serialization/ASTWriter.h"
Sebastian Redlfa1f3702011-04-24 16:28:13 +000015#include "ASTCommon.h"
Chris Lattnerca025db2010-05-07 21:43:38 +000016#include "clang/AST/DeclCXX.h"
Argyrios Kyrtzidis3317d982010-10-20 16:22:56 +000017#include "clang/AST/DeclContextInternals.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000018#include "clang/AST/DeclTemplate.h"
19#include "clang/AST/DeclVisitor.h"
20#include "clang/AST/Expr.h"
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +000021#include "clang/Basic/SourceManager.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000022#include "clang/Serialization/ASTReader.h"
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +000023#include "llvm/ADT/Twine.h"
Chris Lattner7099dbc2009-04-27 06:16:06 +000024#include "llvm/Bitcode/BitstreamWriter.h"
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +000025#include "llvm/Support/ErrorHandling.h"
Chris Lattner7099dbc2009-04-27 06:16:06 +000026using namespace clang;
Sebastian Redlfa1f3702011-04-24 16:28:13 +000027using namespace serialization;
Chris Lattner7099dbc2009-04-27 06:16:06 +000028
29//===----------------------------------------------------------------------===//
30// Declaration serialization
31//===----------------------------------------------------------------------===//
32
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000033namespace clang {
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000034 class ASTDeclWriter : public DeclVisitor<ASTDeclWriter, void> {
Chris Lattner7099dbc2009-04-27 06:16:06 +000035
Sebastian Redl55c0ad52010-08-18 23:56:21 +000036 ASTWriter &Writer;
Chris Lattner7099dbc2009-04-27 06:16:06 +000037 ASTContext &Context;
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000038 typedef ASTWriter::RecordData RecordData;
39 RecordData &Record;
Chris Lattner7099dbc2009-04-27 06:16:06 +000040
41 public:
Sebastian Redl539c5062010-08-18 23:57:32 +000042 serialization::DeclCode Code;
Chris Lattner258172e2009-04-27 07:35:58 +000043 unsigned AbbrevToUse;
Chris Lattner7099dbc2009-04-27 06:16:06 +000044
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000045 ASTDeclWriter(ASTWriter &Writer, ASTContext &Context, RecordData &Record)
Chris Lattner258172e2009-04-27 07:35:58 +000046 : Writer(Writer), Context(Context), Record(Record) {
47 }
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000048
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +000049 void Visit(Decl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000050
51 void VisitDecl(Decl *D);
Nico Weber66220292016-03-02 17:28:48 +000052 void VisitPragmaCommentDecl(PragmaCommentDecl *D);
Nico Webercbbaeb12016-03-02 19:28:54 +000053 void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000054 void VisitTranslationUnitDecl(TranslationUnitDecl *D);
55 void VisitNamedDecl(NamedDecl *D);
Chris Lattnerc8e630e2011-02-17 07:39:24 +000056 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregore31bbd92010-02-21 18:22:14 +000057 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000058 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
59 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000060 void VisitTypeDecl(TypeDecl *D);
Douglas Gregor1f179062011-12-19 14:40:25 +000061 void VisitTypedefNameDecl(TypedefNameDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000062 void VisitTypedefDecl(TypedefDecl *D);
Richard Smithdda56e42011-04-15 14:24:37 +000063 void VisitTypeAliasDecl(TypeAliasDecl *D);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000064 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000065 void VisitTagDecl(TagDecl *D);
66 void VisitEnumDecl(EnumDecl *D);
67 void VisitRecordDecl(RecordDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000068 void VisitCXXRecordDecl(CXXRecordDecl *D);
69 void VisitClassTemplateSpecializationDecl(
70 ClassTemplateSpecializationDecl *D);
71 void VisitClassTemplatePartialSpecializationDecl(
72 ClassTemplatePartialSpecializationDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +000073 void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D);
74 void VisitVarTemplatePartialSpecializationDecl(
75 VarTemplatePartialSpecializationDecl *D);
Fariborz Jahanian3a039e32011-08-27 20:50:59 +000076 void VisitClassScopeFunctionSpecializationDecl(
77 ClassScopeFunctionSpecializationDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000078 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000079 void VisitValueDecl(ValueDecl *D);
80 void VisitEnumConstantDecl(EnumConstantDecl *D);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000081 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +000082 void VisitDeclaratorDecl(DeclaratorDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000083 void VisitFunctionDecl(FunctionDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000084 void VisitCXXMethodDecl(CXXMethodDecl *D);
85 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
86 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
87 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000088 void VisitFieldDecl(FieldDecl *D);
John McCall5e77d762013-04-16 07:28:30 +000089 void VisitMSPropertyDecl(MSPropertyDecl *D);
Francois Pichet783dd6e2010-11-21 06:08:52 +000090 void VisitIndirectFieldDecl(IndirectFieldDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000091 void VisitVarDecl(VarDecl *D);
92 void VisitImplicitParamDecl(ImplicitParamDecl *D);
93 void VisitParmVarDecl(ParmVarDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000094 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
95 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +000096 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000097 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +000098 void VisitVarTemplateDecl(VarTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +000099 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000100 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3f1b5d02011-05-05 21:57:07 +0000101 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000102 void VisitUsingDecl(UsingDecl *D);
103 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000104 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000105 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
Douglas Gregorba345522011-12-02 23:23:56 +0000106 void VisitImportDecl(ImportDecl *D);
Abramo Bagnarad7340582010-06-05 05:09:32 +0000107 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000108 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000109 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
110 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000111 void VisitBlockDecl(BlockDecl *D);
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +0000112 void VisitCapturedDecl(CapturedDecl *D);
Michael Han84324352013-02-22 17:15:32 +0000113 void VisitEmptyDecl(EmptyDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000114
Mike Stump11289f42009-09-09 15:08:12 +0000115 void VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset,
Chris Lattner7099dbc2009-04-27 06:16:06 +0000116 uint64_t VisibleOffset);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000117 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000118
119
Alexis Hunted053252010-05-30 07:21:58 +0000120 // FIXME: Put in the same order is DeclNodes.td?
Chris Lattner7099dbc2009-04-27 06:16:06 +0000121 void VisitObjCMethodDecl(ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000122 void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000123 void VisitObjCContainerDecl(ObjCContainerDecl *D);
124 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
125 void VisitObjCIvarDecl(ObjCIvarDecl *D);
126 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
127 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000128 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
129 void VisitObjCImplDecl(ObjCImplDecl *D);
130 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
131 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
132 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
133 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
134 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
Alexey Bataeva769e072013-03-22 06:34:35 +0000135 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
Alexey Bataev4244be22016-02-11 05:35:55 +0000136 void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
Richard Smithd28ac5b2014-03-22 23:33:22 +0000137
Douglas Gregor85f3f952015-07-07 03:57:15 +0000138 /// Add an Objective-C type parameter list to the given record.
139 void AddObjCTypeParamList(ObjCTypeParamList *typeParams) {
140 // Empty type parameter list.
141 if (!typeParams) {
142 Record.push_back(0);
143 return;
144 }
145
146 Record.push_back(typeParams->size());
147 for (auto typeParam : *typeParams) {
148 Writer.AddDeclRef(typeParam, Record);
149 }
150 Writer.AddSourceLocation(typeParams->getLAngleLoc(), Record);
151 Writer.AddSourceLocation(typeParams->getRAngleLoc(), Record);
152 }
153
Richard Smithd28ac5b2014-03-22 23:33:22 +0000154 void AddFunctionDefinition(const FunctionDecl *FD) {
155 assert(FD->doesThisDeclarationHaveABody());
Richard Smithc2bb8182015-03-24 06:36:48 +0000156 if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
157 Record.push_back(CD->NumCtorInitializers);
158 if (CD->NumCtorInitializers)
159 Writer.AddCXXCtorInitializersRef(
160 llvm::makeArrayRef(CD->init_begin(), CD->init_end()), Record);
161 }
Richard Smithd28ac5b2014-03-22 23:33:22 +0000162 Writer.AddStmt(FD->getBody());
163 }
Richard Smith509fc852015-02-27 23:05:10 +0000164
Richard Smithd8a83712015-08-22 01:47:18 +0000165 /// Add to the record the first declaration from each module file that
166 /// provides a declaration of D. The intent is to provide a sufficient
167 /// set such that reloading this set will load all current redeclarations.
168 void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) {
169 llvm::MapVector<ModuleFile*, const Decl*> Firsts;
170 // FIXME: We can skip entries that we know are implied by others.
Richard Smith5f55d932015-08-27 21:38:25 +0000171 for (const Decl *R = D->getMostRecentDecl(); R; R = R->getPreviousDecl()) {
172 if (R->isFromASTFile())
Richard Smithd8a83712015-08-22 01:47:18 +0000173 Firsts[Writer.Chain->getOwningModuleFile(R)] = R;
Richard Smith5f55d932015-08-27 21:38:25 +0000174 else if (IncludeLocal)
175 Firsts[nullptr] = R;
176 }
Richard Smithd8a83712015-08-22 01:47:18 +0000177 for (const auto &F : Firsts)
178 Writer.AddDeclRef(F.second, Record);
179 }
180
Richard Smith509fc852015-02-27 23:05:10 +0000181 /// Get the specialization decl from an entry in the specialization list.
182 template <typename EntryType>
183 typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType *
184 getSpecializationDecl(EntryType &T) {
185 return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T);
186 }
187
188 /// Get the list of partial specializations from a template's common ptr.
189 template<typename T>
190 decltype(T::PartialSpecializations) &getPartialSpecializations(T *Common) {
191 return Common->PartialSpecializations;
192 }
193 ArrayRef<Decl> getPartialSpecializations(FunctionTemplateDecl::Common *) {
194 return None;
195 }
196
Richard Smith8ab0cfd2016-02-24 21:59:10 +0000197 template<typename DeclTy>
198 void AddTemplateSpecializations(DeclTy *D) {
Richard Smith509fc852015-02-27 23:05:10 +0000199 auto *Common = D->getCommonPtr();
200
201 // If we have any lazy specializations, and the external AST source is
202 // our chained AST reader, we can just write out the DeclIDs. Otherwise,
203 // we need to resolve them to actual declarations.
204 if (Writer.Chain != Writer.Context->getExternalSource() &&
205 Common->LazySpecializations) {
206 D->LoadLazySpecializations();
207 assert(!Common->LazySpecializations);
208 }
209
Richard Smith509fc852015-02-27 23:05:10 +0000210 ArrayRef<DeclID> LazySpecializations;
211 if (auto *LS = Common->LazySpecializations)
Craig Topper55e39a72015-09-29 04:53:28 +0000212 LazySpecializations = llvm::makeArrayRef(LS + 1, LS[0]);
Richard Smith509fc852015-02-27 23:05:10 +0000213
Richard Smithd8a83712015-08-22 01:47:18 +0000214 // Add a slot to the record for the number of specializations.
215 unsigned I = Record.size();
216 Record.push_back(0);
217
Richard Smith8ab0cfd2016-02-24 21:59:10 +0000218 // AddFirstDeclFromEachModule might trigger deserialization, invalidating
219 // *Specializations iterators.
220 llvm::SmallVector<const Decl*, 16> Specs;
221 for (auto &Entry : Common->Specializations)
222 Specs.push_back(getSpecializationDecl(Entry));
223 for (auto &Entry : getPartialSpecializations(Common))
224 Specs.push_back(getSpecializationDecl(Entry));
225
226 for (auto *D : Specs) {
Richard Smith509fc852015-02-27 23:05:10 +0000227 assert(D->isCanonicalDecl() && "non-canonical decl in set");
Richard Smithd8a83712015-08-22 01:47:18 +0000228 AddFirstDeclFromEachModule(D, /*IncludeLocal*/true);
Richard Smith509fc852015-02-27 23:05:10 +0000229 }
Benjamin Kramerf367dd92015-06-12 15:31:50 +0000230 Record.append(LazySpecializations.begin(), LazySpecializations.end());
Richard Smithd8a83712015-08-22 01:47:18 +0000231
232 // Update the size entry we added earlier.
233 Record[I] = Record.size() - I - 1;
234 }
235
236 /// Ensure that this template specialization is associated with the specified
237 /// template on reload.
238 void RegisterTemplateSpecialization(const Decl *Template,
239 const Decl *Specialization) {
240 Template = Template->getCanonicalDecl();
241
242 // If the canonical template is local, we'll write out this specialization
243 // when we emit it.
244 // FIXME: We can do the same thing if there is any local declaration of
245 // the template, to avoid emitting an update record.
246 if (!Template->isFromASTFile())
247 return;
248
249 // We only need to associate the first local declaration of the
250 // specialization. The other declarations will get pulled in by it.
251 if (Writer.getFirstLocalDecl(Specialization) != Specialization)
252 return;
253
254 Writer.DeclUpdates[Template].push_back(ASTWriter::DeclUpdate(
255 UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION, Specialization));
Richard Smith509fc852015-02-27 23:05:10 +0000256 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000257 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000258}
Chris Lattner7099dbc2009-04-27 06:16:06 +0000259
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000260void ASTDeclWriter::Visit(Decl *D) {
261 DeclVisitor<ASTDeclWriter>::Visit(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000262
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000263 // Source locations require array (variable-length) abbreviations. The
264 // abbreviation infrastructure requires that arrays are encoded last, so
265 // we handle it here in the case of those classes derived from DeclaratorDecl
Nick Lewycky4b81fc872015-10-18 20:32:12 +0000266 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000267 Writer.AddTypeSourceInfo(DD->getTypeSourceInfo(), Record);
268 }
269
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000270 // Handle FunctionDecl's body here and write it after all other Stmts/Exprs
271 // have been written. We want it last because we will not read it back when
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000272 // retrieving it from the AST, we'll just lazily set the offset.
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000273 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
Alexis Hunt4a8ea102011-05-06 20:44:56 +0000274 Record.push_back(FD->doesThisDeclarationHaveABody());
275 if (FD->doesThisDeclarationHaveABody())
Richard Smithc2bb8182015-03-24 06:36:48 +0000276 AddFunctionDefinition(FD);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000277 }
278}
279
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000280void ASTDeclWriter::VisitDecl(Decl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000281 Writer.AddDeclRef(cast_or_null<Decl>(D->getDeclContext()), Record);
Richard Smith8aed4222015-12-11 22:41:00 +0000282 if (D->getDeclContext() != D->getLexicalDeclContext())
283 Writer.AddDeclRef(cast_or_null<Decl>(D->getLexicalDeclContext()), Record);
284 else
285 Record.push_back(0);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000286 Record.push_back(D->isInvalidDecl());
287 Record.push_back(D->hasAttrs());
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000288 if (D->hasAttrs())
Craig Topper8c2a2a02014-08-30 16:55:39 +0000289 Writer.WriteAttributes(llvm::makeArrayRef(D->getAttrs().begin(),
290 D->getAttrs().size()), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000291 Record.push_back(D->isImplicit());
Douglas Gregorebada0772010-06-17 23:14:26 +0000292 Record.push_back(D->isUsed(false));
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +0000293 Record.push_back(D->isReferenced());
Douglas Gregor781f7132012-01-06 16:59:53 +0000294 Record.push_back(D->isTopLevelDeclInObjCContainer());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000295 Record.push_back(D->getAccess());
Douglas Gregor781f7132012-01-06 16:59:53 +0000296 Record.push_back(D->isModulePrivate());
Douglas Gregora28bcdd2011-12-01 02:07:58 +0000297 Record.push_back(Writer.inferSubmoduleIDFromLocation(D->getLocation()));
Richard Smithc264d352014-03-23 02:30:01 +0000298
299 // If this declaration injected a name into a context different from its
300 // lexical context, and that context is an imported namespace, we need to
301 // update its visible declarations to include this name.
302 //
303 // This happens when we instantiate a class with a friend declaration or a
304 // function with a local extern declaration, for instance.
Richard Smith5fc18a92015-07-12 23:43:21 +0000305 //
306 // FIXME: Can we handle this in AddedVisibleDecl instead?
Richard Smithc264d352014-03-23 02:30:01 +0000307 if (D->isOutOfLine()) {
Richard Smithe3a97022014-03-23 20:41:56 +0000308 auto *DC = D->getDeclContext();
309 while (auto *NS = dyn_cast<NamespaceDecl>(DC->getRedeclContext())) {
310 if (!NS->isFromASTFile())
311 break;
Chandler Carruth8a3d24d2015-03-26 04:27:10 +0000312 Writer.UpdatedDeclContexts.insert(NS->getPrimaryContext());
Richard Smithe3a97022014-03-23 20:41:56 +0000313 if (!NS->isInlineNamespace())
314 break;
315 DC = NS->getParent();
316 }
Richard Smithc264d352014-03-23 02:30:01 +0000317 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000318}
319
Nico Weber66220292016-03-02 17:28:48 +0000320void ASTDeclWriter::VisitPragmaCommentDecl(PragmaCommentDecl *D) {
321 StringRef Arg = D->getArg();
322 Record.push_back(Arg.size());
323 VisitDecl(D);
324 Writer.AddSourceLocation(D->getLocStart(), Record);
325 Record.push_back(D->getCommentKind());
326 Writer.AddString(Arg, Record);
327 Code = serialization::DECL_PRAGMA_COMMENT;
328}
329
Nico Webercbbaeb12016-03-02 19:28:54 +0000330void ASTDeclWriter::VisitPragmaDetectMismatchDecl(
331 PragmaDetectMismatchDecl *D) {
332 StringRef Name = D->getName();
333 StringRef Value = D->getValue();
334 Record.push_back(Name.size() + 1 + Value.size());
335 VisitDecl(D);
336 Writer.AddSourceLocation(D->getLocStart(), Record);
337 Writer.AddString(Name, Record);
338 Writer.AddString(Value, Record);
339 Code = serialization::DECL_PRAGMA_DETECT_MISMATCH;
340}
341
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000342void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
Douglas Gregordab42432011-08-12 00:15:20 +0000343 llvm_unreachable("Translation units aren't directly serialized");
Chris Lattner7099dbc2009-04-27 06:16:06 +0000344}
345
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000346void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000347 VisitDecl(D);
348 Writer.AddDeclarationName(D->getDeclName(), Record);
Richard Smith2b560572015-02-07 03:11:11 +0000349 Record.push_back(needsAnonymousDeclarationNumber(D)
350 ? Writer.getAnonymousDeclarationNumber(D)
351 : 0);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000352}
353
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000354void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000355 VisitNamedDecl(D);
Abramo Bagnarab3185b02011-03-06 15:48:19 +0000356 Writer.AddSourceLocation(D->getLocStart(), Record);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000357 Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000358}
359
Douglas Gregor1f179062011-12-19 14:40:25 +0000360void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) {
Douglas Gregor05f10352011-12-17 23:38:30 +0000361 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000362 VisitTypeDecl(D);
Enea Zaffanellaa86d88c2013-06-20 12:46:19 +0000363 Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record);
364 Record.push_back(D->isModed());
365 if (D->isModed())
366 Writer.AddTypeRef(D->getUnderlyingType(), Record);
Douglas Gregor1f179062011-12-19 14:40:25 +0000367}
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000368
Douglas Gregor1f179062011-12-19 14:40:25 +0000369void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) {
370 VisitTypedefNameDecl(D);
Richard Smith8aed4222015-12-11 22:41:00 +0000371 if (D->getDeclContext() == D->getLexicalDeclContext() &&
372 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000373 !D->isImplicit() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000374 D->getFirstDecl() == D->getMostRecentDecl() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000375 !D->isInvalidDecl() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000376 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000377 !D->isModulePrivate() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000378 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000379 D->getDeclName().getNameKind() == DeclarationName::Identifier)
380 AbbrevToUse = Writer.getDeclTypedefAbbrev();
381
Sebastian Redl539c5062010-08-18 23:57:32 +0000382 Code = serialization::DECL_TYPEDEF;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000383}
384
Richard Smithdda56e42011-04-15 14:24:37 +0000385void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) {
Douglas Gregor1f179062011-12-19 14:40:25 +0000386 VisitTypedefNameDecl(D);
Richard Smith43ccec8e2014-08-26 03:52:16 +0000387 Writer.AddDeclRef(D->getDescribedAliasTemplate(), Record);
Richard Smithdda56e42011-04-15 14:24:37 +0000388 Code = serialization::DECL_TYPEALIAS;
389}
390
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000391void ASTDeclWriter::VisitTagDecl(TagDecl *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000392 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000393 VisitTypeDecl(D);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000394 Record.push_back(D->getIdentifierNamespace());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000395 Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding
Richard Smith2c381642014-08-27 23:11:59 +0000396 if (!isa<CXXRecordDecl>(D))
397 Record.push_back(D->isCompleteDefinition());
Douglas Gregor5089c762010-02-12 17:40:34 +0000398 Record.push_back(D->isEmbeddedInDeclarator());
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +0000399 Record.push_back(D->isFreeStanding());
David Blaikiea8d23ce2013-07-14 01:07:41 +0000400 Record.push_back(D->isCompleteDefinitionRequired());
Argyrios Kyrtzidis664b6902009-07-14 03:18:02 +0000401 Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Richard Smith70d58502014-08-30 00:04:23 +0000402
403 if (D->hasExtInfo()) {
404 Record.push_back(1);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000405 Writer.AddQualifierInfo(*D->getExtInfo(), Record);
Richard Smith70d58502014-08-30 00:04:23 +0000406 } else if (auto *TD = D->getTypedefNameForAnonDecl()) {
407 Record.push_back(2);
408 Writer.AddDeclRef(TD, Record);
409 Writer.AddIdentifierRef(TD->getDeclName().getAsIdentifierInfo(), Record);
Richard Smith70d58502014-08-30 00:04:23 +0000410 } else {
411 Record.push_back(0);
412 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000413}
414
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000415void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000416 VisitTagDecl(D);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000417 Writer.AddTypeSourceInfo(D->getIntegerTypeSourceInfo(), Record);
418 if (!D->getIntegerTypeSourceInfo())
419 Writer.AddTypeRef(D->getIntegerType(), Record);
John McCall56774992009-12-09 09:09:27 +0000420 Writer.AddTypeRef(D->getPromotionType(), Record);
John McCall9aa35be2010-05-06 08:49:23 +0000421 Record.push_back(D->getNumPositiveBits());
422 Record.push_back(D->getNumNegativeBits());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000423 Record.push_back(D->isScoped());
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000424 Record.push_back(D->isScopedUsingClassTag());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000425 Record.push_back(D->isFixed());
Richard Smith4b38ded2012-03-14 23:13:10 +0000426 if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
427 Writer.AddDeclRef(MemberInfo->getInstantiatedFrom(), Record);
428 Record.push_back(MemberInfo->getTemplateSpecializationKind());
429 Writer.AddSourceLocation(MemberInfo->getPointOfInstantiation(), Record);
430 } else {
Craig Toppera13603a2014-05-22 05:54:18 +0000431 Writer.AddDeclRef(nullptr, Record);
Richard Smith4b38ded2012-03-14 23:13:10 +0000432 }
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000433
Richard Smith8aed4222015-12-11 22:41:00 +0000434 if (D->getDeclContext() == D->getLexicalDeclContext() &&
435 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000436 !D->isImplicit() &&
437 !D->isUsed(false) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000438 !D->hasExtInfo() &&
Richard Smith70d58502014-08-30 00:04:23 +0000439 !D->getTypedefNameForAnonDecl() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000440 D->getFirstDecl() == D->getMostRecentDecl() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000441 !D->isInvalidDecl() &&
442 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000443 !D->isTopLevelDeclInObjCContainer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000444 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000445 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000446 !CXXRecordDecl::classofKind(D->getKind()) &&
447 !D->getIntegerTypeSourceInfo() &&
Argyrios Kyrtzidisca370b0d2013-03-18 22:23:49 +0000448 !D->getMemberSpecializationInfo() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000449 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000450 D->getDeclName().getNameKind() == DeclarationName::Identifier)
451 AbbrevToUse = Writer.getDeclEnumAbbrev();
452
Sebastian Redl539c5062010-08-18 23:57:32 +0000453 Code = serialization::DECL_ENUM;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000454}
455
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000456void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000457 VisitTagDecl(D);
458 Record.push_back(D->hasFlexibleArrayMember());
459 Record.push_back(D->isAnonymousStructOrUnion());
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000460 Record.push_back(D->hasObjectMember());
Fariborz Jahanian78652202013-01-25 23:57:05 +0000461 Record.push_back(D->hasVolatileMember());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000462
Richard Smith8aed4222015-12-11 22:41:00 +0000463 if (D->getDeclContext() == D->getLexicalDeclContext() &&
464 !D->hasAttrs() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000465 !D->isImplicit() &&
466 !D->isUsed(false) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000467 !D->hasExtInfo() &&
Richard Smith70d58502014-08-30 00:04:23 +0000468 !D->getTypedefNameForAnonDecl() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000469 D->getFirstDecl() == D->getMostRecentDecl() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000470 !D->isInvalidDecl() &&
471 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000472 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000473 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000474 !D->isModulePrivate() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000475 !CXXRecordDecl::classofKind(D->getKind()) &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000476 !needsAnonymousDeclarationNumber(D) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000477 D->getDeclName().getNameKind() == DeclarationName::Identifier)
Douglas Gregor03412ba2011-06-03 02:27:19 +0000478 AbbrevToUse = Writer.getDeclRecordAbbrev();
479
Sebastian Redl539c5062010-08-18 23:57:32 +0000480 Code = serialization::DECL_RECORD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000481}
482
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000483void ASTDeclWriter::VisitValueDecl(ValueDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000484 VisitNamedDecl(D);
485 Writer.AddTypeRef(D->getType(), Record);
486}
487
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000488void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000489 VisitValueDecl(D);
490 Record.push_back(D->getInitExpr()? 1 : 0);
491 if (D->getInitExpr())
492 Writer.AddStmt(D->getInitExpr());
493 Writer.AddAPSInt(D->getInitVal(), Record);
Douglas Gregor03412ba2011-06-03 02:27:19 +0000494
Sebastian Redl539c5062010-08-18 23:57:32 +0000495 Code = serialization::DECL_ENUM_CONSTANT;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000496}
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000497
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000498void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000499 VisitValueDecl(D);
Abramo Bagnaradff19302011-03-08 08:55:46 +0000500 Writer.AddSourceLocation(D->getInnerLocStart(), Record);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000501 Record.push_back(D->hasExtInfo());
502 if (D->hasExtInfo())
503 Writer.AddQualifierInfo(*D->getExtInfo(), Record);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000504}
Chris Lattner7099dbc2009-04-27 06:16:06 +0000505
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000506void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000507 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000508 VisitDeclaratorDecl(D);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000509 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000510 Record.push_back(D->getIdentifierNamespace());
Douglas Gregorb2585692012-01-04 17:13:46 +0000511
512 // FunctionDecl's body is handled last at ASTWriterDecl::Visit,
513 // after everything else is written.
514
Richard Smith72625c22015-02-06 23:20:21 +0000515 Record.push_back((int)D->SClass); // FIXME: stable encoding
Douglas Gregorb2585692012-01-04 17:13:46 +0000516 Record.push_back(D->IsInline);
Richard Smith72625c22015-02-06 23:20:21 +0000517 Record.push_back(D->IsInlineSpecified);
518 Record.push_back(D->IsVirtualAsWritten);
519 Record.push_back(D->IsPure);
520 Record.push_back(D->HasInheritedPrototype);
521 Record.push_back(D->HasWrittenPrototype);
522 Record.push_back(D->IsDeleted);
523 Record.push_back(D->IsTrivial);
524 Record.push_back(D->IsDefaulted);
525 Record.push_back(D->IsExplicitlyDefaulted);
526 Record.push_back(D->HasImplicitReturnZero);
527 Record.push_back(D->IsConstexpr);
Argyrios Kyrtzidis1eb71a12012-12-06 18:59:10 +0000528 Record.push_back(D->HasSkippedBody);
Richard Smith72625c22015-02-06 23:20:21 +0000529 Record.push_back(D->IsLateTemplateParsed);
Rafael Espindola3ae00052013-05-13 00:12:11 +0000530 Record.push_back(D->getLinkageInternal());
Douglas Gregorb2585692012-01-04 17:13:46 +0000531 Writer.AddSourceLocation(D->getLocEnd(), Record);
532
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000533 Record.push_back(D->getTemplatedKind());
534 switch (D->getTemplatedKind()) {
535 case FunctionDecl::TK_NonTemplate:
536 break;
537 case FunctionDecl::TK_FunctionTemplate:
538 Writer.AddDeclRef(D->getDescribedFunctionTemplate(), Record);
539 break;
540 case FunctionDecl::TK_MemberSpecialization: {
541 MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo();
542 Writer.AddDeclRef(MemberInfo->getInstantiatedFrom(), Record);
543 Record.push_back(MemberInfo->getTemplateSpecializationKind());
544 Writer.AddSourceLocation(MemberInfo->getPointOfInstantiation(), Record);
545 break;
546 }
547 case FunctionDecl::TK_FunctionTemplateSpecialization: {
548 FunctionTemplateSpecializationInfo *
549 FTSInfo = D->getTemplateSpecializationInfo();
Richard Smithd8a83712015-08-22 01:47:18 +0000550
551 RegisterTemplateSpecialization(FTSInfo->getTemplate(), D);
552
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000553 Writer.AddDeclRef(FTSInfo->getTemplate(), Record);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000554 Record.push_back(FTSInfo->getTemplateSpecializationKind());
555
556 // Template arguments.
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000557 Writer.AddTemplateArgumentList(FTSInfo->TemplateArguments, Record);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000558
559 // Template args as written.
Craig Toppera13603a2014-05-22 05:54:18 +0000560 Record.push_back(FTSInfo->TemplateArgumentsAsWritten != nullptr);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000561 if (FTSInfo->TemplateArgumentsAsWritten) {
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000562 Record.push_back(FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs);
563 for (int i=0, e = FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs;
564 i!=e; ++i)
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000565 Writer.AddTemplateArgumentLoc((*FTSInfo->TemplateArgumentsAsWritten)[i],
566 Record);
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000567 Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->LAngleLoc,
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000568 Record);
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000569 Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->RAngleLoc,
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000570 Record);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000571 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000572
573 Writer.AddSourceLocation(FTSInfo->getPointOfInstantiation(), Record);
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000574
575 if (D->isCanonicalDecl()) {
576 // Write the template that contains the specializations set. We will
577 // add a FunctionTemplateSpecializationInfo to it when reading.
578 Writer.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl(), Record);
579 }
Argyrios Kyrtzidisdc9ca0a2010-06-25 16:24:51 +0000580 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000581 }
582 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
583 DependentFunctionTemplateSpecializationInfo *
584 DFTSInfo = D->getDependentSpecializationInfo();
585
586 // Templates.
587 Record.push_back(DFTSInfo->getNumTemplates());
588 for (int i=0, e = DFTSInfo->getNumTemplates(); i != e; ++i)
589 Writer.AddDeclRef(DFTSInfo->getTemplate(i), Record);
590
591 // Templates args.
592 Record.push_back(DFTSInfo->getNumTemplateArgs());
593 for (int i=0, e = DFTSInfo->getNumTemplateArgs(); i != e; ++i)
594 Writer.AddTemplateArgumentLoc(DFTSInfo->getTemplateArg(i), Record);
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000595 Writer.AddSourceLocation(DFTSInfo->getLAngleLoc(), Record);
596 Writer.AddSourceLocation(DFTSInfo->getRAngleLoc(), Record);
Argyrios Kyrtzidisdc9ca0a2010-06-25 16:24:51 +0000597 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000598 }
599 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000600
Chris Lattner7099dbc2009-04-27 06:16:06 +0000601 Record.push_back(D->param_size());
Aaron Ballmanf6bf62e2014-03-07 15:12:56 +0000602 for (auto P : D->params())
603 Writer.AddDeclRef(P, Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000604 Code = serialization::DECL_FUNCTION;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000605}
606
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000607void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000608 VisitNamedDecl(D);
609 // FIXME: convert to LazyStmtPtr?
Mike Stump11289f42009-09-09 15:08:12 +0000610 // Unlike C/C++, method bodies will never be in header files.
Craig Toppera13603a2014-05-22 05:54:18 +0000611 bool HasBodyStuff = D->getBody() != nullptr ||
612 D->getSelfDecl() != nullptr || D->getCmdDecl() != nullptr;
Argyrios Kyrtzidisa8607772010-08-09 10:54:37 +0000613 Record.push_back(HasBodyStuff);
614 if (HasBodyStuff) {
Argyrios Kyrtzidisddcd1322009-06-30 02:35:26 +0000615 Writer.AddStmt(D->getBody());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000616 Writer.AddDeclRef(D->getSelfDecl(), Record);
617 Writer.AddDeclRef(D->getCmdDecl(), Record);
618 }
619 Record.push_back(D->isInstanceMethod());
620 Record.push_back(D->isVariadic());
Jordan Rosed01e83a2012-10-10 16:42:25 +0000621 Record.push_back(D->isPropertyAccessor());
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000622 Record.push_back(D->isDefined());
Argyrios Kyrtzidis08f96a92012-05-09 16:12:57 +0000623 Record.push_back(D->IsOverriding);
Argyrios Kyrtzidis1eb71a12012-12-06 18:59:10 +0000624 Record.push_back(D->HasSkippedBody);
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000625
626 Record.push_back(D->IsRedeclaration);
627 Record.push_back(D->HasRedeclaration);
628 if (D->HasRedeclaration) {
629 assert(Context.getObjCMethodRedeclaration(D));
630 Writer.AddDeclRef(Context.getObjCMethodRedeclaration(D), Record);
631 }
632
Chris Lattner7099dbc2009-04-27 06:16:06 +0000633 // FIXME: stable encoding for @required/@optional
Mike Stump11289f42009-09-09 15:08:12 +0000634 Record.push_back(D->getImplementationControl());
Douglas Gregor813a0662015-06-19 18:14:38 +0000635 // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway/nullability
Mike Stump11289f42009-09-09 15:08:12 +0000636 Record.push_back(D->getObjCDeclQualifier());
Douglas Gregor33823722011-06-11 01:09:30 +0000637 Record.push_back(D->hasRelatedResultType());
Alp Toker314cc812014-01-25 16:55:45 +0000638 Writer.AddTypeRef(D->getReturnType(), Record);
639 Writer.AddTypeSourceInfo(D->getReturnTypeSourceInfo(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000640 Writer.AddSourceLocation(D->getLocEnd(), Record);
641 Record.push_back(D->param_size());
Aaron Ballman43b68be2014-03-07 17:50:17 +0000642 for (const auto *P : D->params())
643 Writer.AddDeclRef(P, Record);
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000644
645 Record.push_back(D->SelLocsKind);
646 unsigned NumStoredSelLocs = D->getNumStoredSelLocs();
647 SourceLocation *SelLocs = D->getStoredSelLocs();
648 Record.push_back(NumStoredSelLocs);
649 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
650 Writer.AddSourceLocation(SelLocs[i], Record);
651
Sebastian Redl539c5062010-08-18 23:57:32 +0000652 Code = serialization::DECL_OBJC_METHOD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000653}
654
Douglas Gregor85f3f952015-07-07 03:57:15 +0000655void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
656 VisitTypedefNameDecl(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +0000657 Record.push_back(D->Variance);
Douglas Gregore83b9562015-07-07 03:57:53 +0000658 Record.push_back(D->Index);
Douglas Gregor1ac1b632015-07-07 03:58:54 +0000659 Writer.AddSourceLocation(D->VarianceLoc, Record);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000660 Writer.AddSourceLocation(D->ColonLoc, Record);
661
662 Code = serialization::DECL_OBJC_TYPE_PARAM;
663}
664
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000665void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000666 VisitNamedDecl(D);
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +0000667 Writer.AddSourceLocation(D->getAtStartLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +0000668 Writer.AddSourceRange(D->getAtEndRange(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000669 // Abstract class (no need to define a stable serialization::DECL code).
Chris Lattner7099dbc2009-04-27 06:16:06 +0000670}
671
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000672void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
Douglas Gregor66b310c2011-12-15 18:03:09 +0000673 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000674 VisitObjCContainerDecl(D);
675 Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000676 AddObjCTypeParamList(D->TypeParamList);
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000677
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000678 Record.push_back(D->isThisDeclarationADefinition());
679 if (D->isThisDeclarationADefinition()) {
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000680 // Write the DefinitionData
681 ObjCInterfaceDecl::DefinitionData &Data = D->data();
682
Douglas Gregore9d95f12015-07-07 03:57:35 +0000683 Writer.AddTypeSourceInfo(D->getSuperClassTInfo(), Record);
Douglas Gregor16408322011-12-15 22:34:59 +0000684 Writer.AddSourceLocation(D->getEndOfDefinitionLoc(), Record);
Argyrios Kyrtzidis9ed9e5f2013-12-03 21:11:30 +0000685 Record.push_back(Data.HasDesignatedInitializers);
Douglas Gregor16408322011-12-15 22:34:59 +0000686
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000687 // Write out the protocols that are directly referenced by the @interface.
688 Record.push_back(Data.ReferencedProtocols.size());
Aaron Ballmana49c5062014-03-13 20:29:09 +0000689 for (const auto *P : D->protocols())
690 Writer.AddDeclRef(P, Record);
Aaron Ballmane9378882014-03-13 20:34:24 +0000691 for (const auto &PL : D->protocol_locs())
692 Writer.AddSourceLocation(PL, Record);
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000693
694 // Write out the protocols that are transitively referenced.
695 Record.push_back(Data.AllReferencedProtocols.size());
696 for (ObjCList<ObjCProtocolDecl>::iterator
697 P = Data.AllReferencedProtocols.begin(),
698 PEnd = Data.AllReferencedProtocols.end();
699 P != PEnd; ++P)
700 Writer.AddDeclRef(*P, Record);
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000701
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000702
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000703 if (ObjCCategoryDecl *Cat = D->getCategoryListRaw()) {
Douglas Gregor404cdde2012-01-27 01:47:08 +0000704 // Ensure that we write out the set of categories for this class.
705 Writer.ObjCClassesWithCategories.insert(D);
706
707 // Make sure that the categories get serialized.
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000708 for (; Cat; Cat = Cat->getNextClassCategoryRaw())
Douglas Gregor404cdde2012-01-27 01:47:08 +0000709 (void)Writer.GetDeclRef(Cat);
710 }
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000711 }
712
Sebastian Redl539c5062010-08-18 23:57:32 +0000713 Code = serialization::DECL_OBJC_INTERFACE;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000714}
715
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000716void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000717 VisitFieldDecl(D);
718 // FIXME: stable encoding for @public/@private/@protected/@package
Mike Stump11289f42009-09-09 15:08:12 +0000719 Record.push_back(D->getAccessControl());
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000720 Record.push_back(D->getSynthesize());
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000721
Richard Smith8aed4222015-12-11 22:41:00 +0000722 if (D->getDeclContext() == D->getLexicalDeclContext() &&
723 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000724 !D->isImplicit() &&
725 !D->isUsed(false) &&
726 !D->isInvalidDecl() &&
727 !D->isReferenced() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000728 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000729 !D->getBitWidth() &&
730 !D->hasExtInfo() &&
731 D->getDeclName())
732 AbbrevToUse = Writer.getDeclObjCIvarAbbrev();
733
Sebastian Redl539c5062010-08-18 23:57:32 +0000734 Code = serialization::DECL_OBJC_IVAR;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000735}
736
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000737void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
Douglas Gregora715bff2012-01-01 19:51:50 +0000738 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000739 VisitObjCContainerDecl(D);
Douglas Gregore6e48b12012-01-01 19:29:29 +0000740
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000741 Record.push_back(D->isThisDeclarationADefinition());
742 if (D->isThisDeclarationADefinition()) {
Douglas Gregore6e48b12012-01-01 19:29:29 +0000743 Record.push_back(D->protocol_size());
Aaron Ballman0f6e64d2014-03-13 22:58:06 +0000744 for (const auto *I : D->protocols())
745 Writer.AddDeclRef(I, Record);
Aaron Ballmana964ec12014-03-14 12:38:50 +0000746 for (const auto &PL : D->protocol_locs())
747 Writer.AddSourceLocation(PL, Record);
Douglas Gregore6e48b12012-01-01 19:29:29 +0000748 }
749
Sebastian Redl539c5062010-08-18 23:57:32 +0000750 Code = serialization::DECL_OBJC_PROTOCOL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000751}
752
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000753void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000754 VisitFieldDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000755 Code = serialization::DECL_OBJC_AT_DEFS_FIELD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000756}
757
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000758void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000759 VisitObjCContainerDecl(D);
Douglas Gregor404cdde2012-01-27 01:47:08 +0000760 Writer.AddSourceLocation(D->getCategoryNameLoc(), Record);
Fariborz Jahaniana7765fe2012-02-20 20:09:20 +0000761 Writer.AddSourceLocation(D->getIvarLBraceLoc(), Record);
762 Writer.AddSourceLocation(D->getIvarRBraceLoc(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000763 Writer.AddDeclRef(D->getClassInterface(), Record);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000764 AddObjCTypeParamList(D->TypeParamList);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000765 Record.push_back(D->protocol_size());
Aaron Ballman19a41762014-03-14 12:55:57 +0000766 for (const auto *I : D->protocols())
767 Writer.AddDeclRef(I, Record);
Aaron Ballmana73c8572014-03-14 13:03:32 +0000768 for (const auto &PL : D->protocol_locs())
769 Writer.AddSourceLocation(PL, Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000770 Code = serialization::DECL_OBJC_CATEGORY;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000771}
772
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000773void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000774 VisitNamedDecl(D);
775 Writer.AddDeclRef(D->getClassInterface(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000776 Code = serialization::DECL_OBJC_COMPATIBLE_ALIAS;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000777}
778
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000779void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000780 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000781 Writer.AddSourceLocation(D->getAtLoc(), Record);
Fariborz Jahanian86c2f5c2012-02-29 22:18:55 +0000782 Writer.AddSourceLocation(D->getLParenLoc(), Record);
Douglas Gregor813a0662015-06-19 18:14:38 +0000783 Writer.AddTypeRef(D->getType(), Record);
John McCall339bb662010-06-04 20:50:08 +0000784 Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000785 // FIXME: stable encoding
786 Record.push_back((unsigned)D->getPropertyAttributes());
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000787 Record.push_back((unsigned)D->getPropertyAttributesAsWritten());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000788 // FIXME: stable encoding
789 Record.push_back((unsigned)D->getPropertyImplementation());
790 Writer.AddDeclarationName(D->getGetterName(), Record);
791 Writer.AddDeclarationName(D->getSetterName(), Record);
792 Writer.AddDeclRef(D->getGetterMethodDecl(), Record);
793 Writer.AddDeclRef(D->getSetterMethodDecl(), Record);
794 Writer.AddDeclRef(D->getPropertyIvarDecl(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000795 Code = serialization::DECL_OBJC_PROPERTY;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000796}
797
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000798void ASTDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000799 VisitObjCContainerDecl(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000800 Writer.AddDeclRef(D->getClassInterface(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000801 // Abstract class (no need to define a stable serialization::DECL code).
Chris Lattner7099dbc2009-04-27 06:16:06 +0000802}
803
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000804void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000805 VisitObjCImplDecl(D);
806 Writer.AddIdentifierRef(D->getIdentifier(), Record);
Argyrios Kyrtzidis4996f5f2011-12-09 00:31:40 +0000807 Writer.AddSourceLocation(D->getCategoryNameLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000808 Code = serialization::DECL_OBJC_CATEGORY_IMPL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000809}
810
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000811void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000812 VisitObjCImplDecl(D);
813 Writer.AddDeclRef(D->getSuperClass(), Record);
Argyrios Kyrtzidis5d2ce842013-05-03 22:31:26 +0000814 Writer.AddSourceLocation(D->getSuperClassLoc(), Record);
Fariborz Jahaniana7765fe2012-02-20 20:09:20 +0000815 Writer.AddSourceLocation(D->getIvarLBraceLoc(), Record);
816 Writer.AddSourceLocation(D->getIvarRBraceLoc(), Record);
John McCall0d54a172012-10-17 04:53:31 +0000817 Record.push_back(D->hasNonZeroConstructors());
818 Record.push_back(D->hasDestructors());
Richard Smithc2bb8182015-03-24 06:36:48 +0000819 Record.push_back(D->NumIvarInitializers);
820 if (D->NumIvarInitializers)
821 Writer.AddCXXCtorInitializersRef(
822 llvm::makeArrayRef(D->init_begin(), D->init_end()), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000823 Code = serialization::DECL_OBJC_IMPLEMENTATION;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000824}
825
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000826void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000827 VisitDecl(D);
828 Writer.AddSourceLocation(D->getLocStart(), Record);
829 Writer.AddDeclRef(D->getPropertyDecl(), Record);
830 Writer.AddDeclRef(D->getPropertyIvarDecl(), Record);
Douglas Gregorb1b71e52010-11-17 01:03:52 +0000831 Writer.AddSourceLocation(D->getPropertyIvarDeclLoc(), Record);
Argyrios Kyrtzidisa8607772010-08-09 10:54:37 +0000832 Writer.AddStmt(D->getGetterCXXConstructor());
833 Writer.AddStmt(D->getSetterCXXAssignment());
Sebastian Redl539c5062010-08-18 23:57:32 +0000834 Code = serialization::DECL_OBJC_PROPERTY_IMPL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000835}
836
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000837void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000838 VisitDeclaratorDecl(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000839 Record.push_back(D->isMutable());
John McCallc90c1492014-10-10 18:44:34 +0000840 if (D->InitStorage.getInt() == FieldDecl::ISK_BitWidthOrNothing &&
841 D->InitStorage.getPointer() == nullptr) {
842 Record.push_back(0);
843 } else if (D->InitStorage.getInt() == FieldDecl::ISK_CapturedVLAType) {
844 Record.push_back(D->InitStorage.getInt() + 1);
Alexey Bataev39c81e22014-08-28 04:28:19 +0000845 Writer.AddTypeRef(
John McCallc90c1492014-10-10 18:44:34 +0000846 QualType(static_cast<Type *>(D->InitStorage.getPointer()), 0),
Alexey Bataev39c81e22014-08-28 04:28:19 +0000847 Record);
Richard Smith2b013182012-06-10 03:12:00 +0000848 } else {
John McCallc90c1492014-10-10 18:44:34 +0000849 Record.push_back(D->InitStorage.getInt() + 1);
850 Writer.AddStmt(static_cast<Expr *>(D->InitStorage.getPointer()));
Richard Smith2b013182012-06-10 03:12:00 +0000851 }
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000852 if (!D->getDeclName())
853 Writer.AddDeclRef(Context.getInstantiatedFromUnnamedFieldDecl(D), Record);
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000854
Richard Smith8aed4222015-12-11 22:41:00 +0000855 if (D->getDeclContext() == D->getLexicalDeclContext() &&
856 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000857 !D->isImplicit() &&
858 !D->isUsed(false) &&
859 !D->isInvalidDecl() &&
860 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000861 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000862 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000863 !D->getBitWidth() &&
Richard Smith938f40b2011-06-11 17:19:42 +0000864 !D->hasInClassInitializer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000865 !D->hasExtInfo() &&
866 !ObjCIvarDecl::classofKind(D->getKind()) &&
867 !ObjCAtDefsFieldDecl::classofKind(D->getKind()) &&
868 D->getDeclName())
869 AbbrevToUse = Writer.getDeclFieldAbbrev();
870
Sebastian Redl539c5062010-08-18 23:57:32 +0000871 Code = serialization::DECL_FIELD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000872}
873
John McCall5e77d762013-04-16 07:28:30 +0000874void ASTDeclWriter::VisitMSPropertyDecl(MSPropertyDecl *D) {
875 VisitDeclaratorDecl(D);
876 Writer.AddIdentifierRef(D->getGetterId(), Record);
877 Writer.AddIdentifierRef(D->getSetterId(), Record);
878 Code = serialization::DECL_MS_PROPERTY;
879}
880
Francois Pichet783dd6e2010-11-21 06:08:52 +0000881void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
882 VisitValueDecl(D);
883 Record.push_back(D->getChainingSize());
884
Aaron Ballman29c94602014-03-07 18:36:15 +0000885 for (const auto *P : D->chain())
Aaron Ballman13916082014-03-07 18:11:58 +0000886 Writer.AddDeclRef(P, Record);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000887 Code = serialization::DECL_INDIRECTFIELD;
888}
889
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000890void ASTDeclWriter::VisitVarDecl(VarDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000891 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000892 VisitDeclaratorDecl(D);
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000893 Record.push_back(D->getStorageClass());
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +0000894 Record.push_back(D->getTSCSpec());
Sebastian Redla9351792012-02-11 23:51:47 +0000895 Record.push_back(D->getInitStyle());
David Majnemerfa7bc782015-05-19 00:57:16 +0000896 if (!isa<ParmVarDecl>(D)) {
897 Record.push_back(D->isExceptionVariable());
898 Record.push_back(D->isNRVOVariable());
899 Record.push_back(D->isCXXForRangeDecl());
900 Record.push_back(D->isARCPseudoStrong());
901 Record.push_back(D->isConstexpr());
902 Record.push_back(D->isInitCapture());
903 Record.push_back(D->isPreviousDeclInSameBlockScope());
904 }
Rafael Espindola3ae00052013-05-13 00:12:11 +0000905 Record.push_back(D->getLinkageInternal());
Douglas Gregor12cda632012-09-20 23:43:29 +0000906
Richard Smithd0b4dd62011-12-19 06:19:21 +0000907 if (D->getInit()) {
908 Record.push_back(!D->isInitKnownICE() ? 1 : (D->isInitICE() ? 3 : 2));
Chris Lattner7099dbc2009-04-27 06:16:06 +0000909 Writer.AddStmt(D->getInit());
Richard Smithd0b4dd62011-12-19 06:19:21 +0000910 } else {
911 Record.push_back(0);
912 }
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000913
914 enum {
915 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
916 };
917 if (VarTemplateDecl *TemplD = D->getDescribedVarTemplate()) {
918 Record.push_back(VarTemplate);
919 Writer.AddDeclRef(TemplD, Record);
920 } else if (MemberSpecializationInfo *SpecInfo
921 = D->getMemberSpecializationInfo()) {
922 Record.push_back(StaticDataMemberSpecialization);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000923 Writer.AddDeclRef(SpecInfo->getInstantiatedFrom(), Record);
924 Record.push_back(SpecInfo->getTemplateSpecializationKind());
925 Writer.AddSourceLocation(SpecInfo->getPointOfInstantiation(), Record);
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000926 } else {
927 Record.push_back(VarNotTemplate);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000928 }
929
Richard Smith8aed4222015-12-11 22:41:00 +0000930 if (D->getDeclContext() == D->getLexicalDeclContext() &&
931 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000932 !D->isImplicit() &&
933 !D->isUsed(false) &&
934 !D->isInvalidDecl() &&
935 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000936 !D->isTopLevelDeclInObjCContainer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000937 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000938 !D->isModulePrivate() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000939 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000940 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
941 !D->hasExtInfo() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000942 D->getFirstDecl() == D->getMostRecentDecl() &&
Sebastian Redla9351792012-02-11 23:51:47 +0000943 D->getInitStyle() == VarDecl::CInit &&
Craig Toppera13603a2014-05-22 05:54:18 +0000944 D->getInit() == nullptr &&
John McCalld4631322011-06-17 06:42:21 +0000945 !isa<ParmVarDecl>(D) &&
Larisse Voufoa11bd8a2013-08-13 02:02:26 +0000946 !isa<VarTemplateSpecializationDecl>(D) &&
Douglas Gregor12cda632012-09-20 23:43:29 +0000947 !D->isConstexpr() &&
Richard Smithbb13c9a2013-09-28 04:02:39 +0000948 !D->isInitCapture() &&
Richard Smith1c34fb72013-08-13 18:18:50 +0000949 !D->isPreviousDeclInSameBlockScope() &&
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000950 !D->getMemberSpecializationInfo())
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000951 AbbrevToUse = Writer.getDeclVarAbbrev();
952
Sebastian Redl539c5062010-08-18 23:57:32 +0000953 Code = serialization::DECL_VAR;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000954}
955
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000956void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000957 VisitVarDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000958 Code = serialization::DECL_IMPLICIT_PARAM;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000959}
960
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000961void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000962 VisitVarDecl(D);
John McCall82490832011-05-02 00:30:12 +0000963 Record.push_back(D->isObjCMethodParameter());
John McCall8fb0d9d2011-05-01 22:35:37 +0000964 Record.push_back(D->getFunctionScopeDepth());
965 Record.push_back(D->getFunctionScopeIndex());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000966 Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding
John McCall6a014d52011-03-09 04:22:44 +0000967 Record.push_back(D->isKNRPromoted());
John McCallf3cd6652010-03-12 18:31:32 +0000968 Record.push_back(D->hasInheritedDefaultArg());
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000969 Record.push_back(D->hasUninstantiatedDefaultArg());
970 if (D->hasUninstantiatedDefaultArg())
971 Writer.AddStmt(D->getUninstantiatedDefaultArg());
Sebastian Redl539c5062010-08-18 23:57:32 +0000972 Code = serialization::DECL_PARM_VAR;
Mike Stump11289f42009-09-09 15:08:12 +0000973
John McCalld4631322011-06-17 06:42:21 +0000974 assert(!D->isARCPseudoStrong()); // can be true of ImplicitParamDecl
975
Chris Lattner258172e2009-04-27 07:35:58 +0000976 // If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here
977 // we dynamically check for the properties that we optimize for, but don't
978 // know are true of all PARM_VAR_DECLs.
Richard Smith8aed4222015-12-11 22:41:00 +0000979 if (D->getDeclContext() == D->getLexicalDeclContext() &&
980 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000981 !D->hasExtInfo() &&
Chris Lattner258172e2009-04-27 07:35:58 +0000982 !D->isImplicit() &&
Douglas Gregorebada0772010-06-17 23:14:26 +0000983 !D->isUsed(false) &&
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +0000984 !D->isInvalidDecl() &&
Eli Friedmanc09e0552012-01-13 23:41:25 +0000985 !D->isReferenced() &&
Chris Lattner258172e2009-04-27 07:35:58 +0000986 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000987 !D->isModulePrivate() &&
Chris Lattner258172e2009-04-27 07:35:58 +0000988 D->getStorageClass() == 0 &&
Sebastian Redla9351792012-02-11 23:51:47 +0000989 D->getInitStyle() == VarDecl::CInit && // Can params have anything else?
John McCall82490832011-05-02 00:30:12 +0000990 D->getFunctionScopeDepth() == 0 &&
John McCallf3cd6652010-03-12 18:31:32 +0000991 D->getObjCDeclQualifier() == 0 &&
John McCall6a014d52011-03-09 04:22:44 +0000992 !D->isKNRPromoted() &&
Chris Lattnere2437f42010-05-09 06:40:08 +0000993 !D->hasInheritedDefaultArg() &&
Craig Toppera13603a2014-05-22 05:54:18 +0000994 D->getInit() == nullptr &&
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000995 !D->hasUninstantiatedDefaultArg()) // No default expr.
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000996 AbbrevToUse = Writer.getDeclParmVarAbbrev();
Chris Lattner258172e2009-04-27 07:35:58 +0000997
998 // Check things we know are true of *every* PARM_VAR_DECL, which is more than
999 // just us assuming it.
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +00001000 assert(!D->getTSCSpec() && "PARM_VAR_DECL can't use TLS");
Chris Lattner258172e2009-04-27 07:35:58 +00001001 assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private");
Douglas Gregor3f324d562010-05-03 18:51:14 +00001002 assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var");
Craig Toppera13603a2014-05-22 05:54:18 +00001003 assert(D->getPreviousDecl() == nullptr && "PARM_VAR_DECL can't be redecl");
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001004 assert(!D->isStaticDataMember() &&
1005 "PARM_VAR_DECL can't be static data member");
Chris Lattner7099dbc2009-04-27 06:16:06 +00001006}
1007
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001008void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001009 VisitDecl(D);
1010 Writer.AddStmt(D->getAsmString());
Abramo Bagnara348823a2011-03-03 14:20:18 +00001011 Writer.AddSourceLocation(D->getRParenLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001012 Code = serialization::DECL_FILE_SCOPE_ASM;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001013}
1014
Michael Han84324352013-02-22 17:15:32 +00001015void ASTDeclWriter::VisitEmptyDecl(EmptyDecl *D) {
1016 VisitDecl(D);
1017 Code = serialization::DECL_EMPTY;
1018}
1019
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001020void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001021 VisitDecl(D);
1022 Writer.AddStmt(D->getBody());
John McCalla3ccba02010-06-04 11:21:44 +00001023 Writer.AddTypeSourceInfo(D->getSignatureAsWritten(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +00001024 Record.push_back(D->param_size());
1025 for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end();
1026 P != PEnd; ++P)
1027 Writer.AddDeclRef(*P, Record);
John McCallcf6ce282012-04-13 17:33:29 +00001028 Record.push_back(D->isVariadic());
1029 Record.push_back(D->blockMissingReturnType());
1030 Record.push_back(D->isConversionFromLambda());
John McCallc63de662011-02-02 13:00:07 +00001031 Record.push_back(D->capturesCXXThis());
John McCall351762c2011-02-07 10:33:21 +00001032 Record.push_back(D->getNumCaptures());
Aaron Ballman9371dd22014-03-14 18:34:04 +00001033 for (const auto &capture : D->captures()) {
John McCall351762c2011-02-07 10:33:21 +00001034 Writer.AddDeclRef(capture.getVariable(), Record);
1035
1036 unsigned flags = 0;
1037 if (capture.isByRef()) flags |= 1;
1038 if (capture.isNested()) flags |= 2;
1039 if (capture.hasCopyExpr()) flags |= 4;
1040 Record.push_back(flags);
1041
1042 if (capture.hasCopyExpr()) Writer.AddStmt(capture.getCopyExpr());
1043 }
John McCallc63de662011-02-02 13:00:07 +00001044
Sebastian Redl539c5062010-08-18 23:57:32 +00001045 Code = serialization::DECL_BLOCK;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001046}
1047
Ben Langmuirce914fc2013-05-03 19:20:19 +00001048void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) {
1049 Record.push_back(CD->getNumParams());
1050 VisitDecl(CD);
Alexey Bataev9959db52014-05-06 10:08:46 +00001051 Record.push_back(CD->getContextParamPosition());
1052 Record.push_back(CD->isNothrow() ? 1 : 0);
Ben Langmuirce914fc2013-05-03 19:20:19 +00001053 // Body is stored by VisitCapturedStmt.
Alexey Bataev9959db52014-05-06 10:08:46 +00001054 for (unsigned I = 0; I < CD->getNumParams(); ++I)
1055 Writer.AddDeclRef(CD->getParam(I), Record);
Ben Langmuirce914fc2013-05-03 19:20:19 +00001056 Code = serialization::DECL_CAPTURED;
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001057}
1058
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001059void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001060 VisitDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001061 Record.push_back(D->getLanguage());
Abramo Bagnaraea947882011-03-08 16:41:52 +00001062 Writer.AddSourceLocation(D->getExternLoc(), Record);
Abramo Bagnara4a8cda82011-03-03 14:52:38 +00001063 Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001064 Code = serialization::DECL_LINKAGE_SPEC;
Chris Lattnerca025db2010-05-07 21:43:38 +00001065}
1066
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001067void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) {
1068 VisitNamedDecl(D);
Abramo Bagnara1c3af962011-03-05 18:21:20 +00001069 Writer.AddSourceLocation(D->getLocStart(), Record);
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001070 Code = serialization::DECL_LABEL;
1071}
1072
1073
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001074void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
Douglas Gregore57e7522012-01-07 09:11:48 +00001075 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001076 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +00001077 Record.push_back(D->isInline());
Abramo Bagnarab5545be2011-03-08 12:38:20 +00001078 Writer.AddSourceLocation(D->getLocStart(), Record);
1079 Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001080
Chris Lattnerca025db2010-05-07 21:43:38 +00001081 if (D->isOriginalNamespace())
1082 Writer.AddDeclRef(D->getAnonymousNamespace(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001083 Code = serialization::DECL_NAMESPACE;
Sebastian Redlf03cdc52010-08-05 21:22:19 +00001084
Douglas Gregore57e7522012-01-07 09:11:48 +00001085 if (Writer.hasChain() && D->isAnonymousNamespace() &&
Douglas Gregorec9fd132012-01-14 16:38:05 +00001086 D == D->getMostRecentDecl()) {
Sebastian Redl010288f2011-04-24 16:28:21 +00001087 // This is a most recent reopening of the anonymous namespace. If its parent
1088 // is in a previous PCH (or is the TU), mark that parent for update, because
1089 // the original namespace always points to the latest re-opening of its
1090 // anonymous namespace.
1091 Decl *Parent = cast<Decl>(
1092 D->getParent()->getRedeclContext()->getPrimaryContext());
Douglas Gregorb3722e22011-09-09 23:01:35 +00001093 if (Parent->isFromASTFile() || isa<TranslationUnitDecl>(Parent)) {
Richard Smith6ef42932014-03-20 21:02:00 +00001094 Writer.DeclUpdates[Parent].push_back(
Aaron Ballman4f45b712014-03-21 15:22:56 +00001095 ASTWriter::DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, D));
Sebastian Redlfa1f3702011-04-24 16:28:13 +00001096 }
1097 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001098}
1099
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001100void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Richard Smithf4634362014-09-03 23:11:22 +00001101 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001102 VisitNamedDecl(D);
Douglas Gregorf9e43ce2010-09-01 00:08:19 +00001103 Writer.AddSourceLocation(D->getNamespaceLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001104 Writer.AddSourceLocation(D->getTargetNameLoc(), Record);
Douglas Gregorc05ba2e2011-02-25 17:08:07 +00001105 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001106 Writer.AddDeclRef(D->getNamespace(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001107 Code = serialization::DECL_NAMESPACE_ALIAS;
Chris Lattnerca025db2010-05-07 21:43:38 +00001108}
1109
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001110void ASTDeclWriter::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001111 VisitNamedDecl(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00001112 Writer.AddSourceLocation(D->getUsingLoc(), Record);
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001113 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00001114 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
Benjamin Kramere78f8ee2012-01-07 19:09:05 +00001115 Writer.AddDeclRef(D->FirstUsingShadow.getPointer(), Record);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00001116 Record.push_back(D->hasTypename());
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001117 Writer.AddDeclRef(Context.getInstantiatedFromUsingDecl(D), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001118 Code = serialization::DECL_USING;
Chris Lattnerca025db2010-05-07 21:43:38 +00001119}
1120
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001121void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) {
Richard Smithfd8634a2013-10-23 02:17:46 +00001122 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001123 VisitNamedDecl(D);
1124 Writer.AddDeclRef(D->getTargetDecl(), Record);
Argyrios Kyrtzidis2703beb2010-11-10 05:40:41 +00001125 Writer.AddDeclRef(D->UsingOrNextShadow, Record);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001126 Writer.AddDeclRef(Context.getInstantiatedFromUsingShadowDecl(D), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001127 Code = serialization::DECL_USING_SHADOW;
Chris Lattnerca025db2010-05-07 21:43:38 +00001128}
1129
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001130void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001131 VisitNamedDecl(D);
Douglas Gregor01a430132010-09-01 03:07:18 +00001132 Writer.AddSourceLocation(D->getUsingLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001133 Writer.AddSourceLocation(D->getNamespaceKeyLocation(), Record);
Douglas Gregor12441b32011-02-25 16:33:46 +00001134 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001135 Writer.AddDeclRef(D->getNominatedNamespace(), Record);
1136 Writer.AddDeclRef(dyn_cast<Decl>(D->getCommonAncestor()), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001137 Code = serialization::DECL_USING_DIRECTIVE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001138}
1139
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001140void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001141 VisitValueDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001142 Writer.AddSourceLocation(D->getUsingLoc(), Record);
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001143 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00001144 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001145 Code = serialization::DECL_UNRESOLVED_USING_VALUE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001146}
1147
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001148void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001149 UnresolvedUsingTypenameDecl *D) {
1150 VisitTypeDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001151 Writer.AddSourceLocation(D->getTypenameLoc(), Record);
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001152 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001153 Code = serialization::DECL_UNRESOLVED_USING_TYPENAME;
Chris Lattnerca025db2010-05-07 21:43:38 +00001154}
1155
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001156void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001157 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001158
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001159 enum {
1160 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1161 };
1162 if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) {
1163 Record.push_back(CXXRecTemplate);
1164 Writer.AddDeclRef(TemplD, Record);
1165 } else if (MemberSpecializationInfo *MSInfo
1166 = D->getMemberSpecializationInfo()) {
1167 Record.push_back(CXXRecMemberSpecialization);
1168 Writer.AddDeclRef(MSInfo->getInstantiatedFrom(), Record);
1169 Record.push_back(MSInfo->getTemplateSpecializationKind());
1170 Writer.AddSourceLocation(MSInfo->getPointOfInstantiation(), Record);
1171 } else {
1172 Record.push_back(CXXRecNotTemplate);
1173 }
1174
Richard Smithcd45dbc2014-04-19 03:48:30 +00001175 Record.push_back(D->isThisDeclarationADefinition());
1176 if (D->isThisDeclarationADefinition())
1177 Writer.AddCXXDefinitionData(D, Record);
1178
John McCall6bd2a892013-01-25 22:31:03 +00001179 // Store (what we currently believe to be) the key function to avoid
1180 // deserializing every method so we can compute it.
John McCallf937c022011-10-07 06:10:15 +00001181 if (D->IsCompleteDefinition)
John McCall6bd2a892013-01-25 22:31:03 +00001182 Writer.AddDeclRef(Context.getCurrentKeyFunction(D), Record);
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001183
Sebastian Redl539c5062010-08-18 23:57:32 +00001184 Code = serialization::DECL_CXX_RECORD;
Chris Lattnerca025db2010-05-07 21:43:38 +00001185}
1186
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001187void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001188 VisitFunctionDecl(D);
Argyrios Kyrtzidis3b1a7792012-10-12 05:31:40 +00001189 if (D->isCanonicalDecl()) {
1190 Record.push_back(D->size_overridden_methods());
1191 for (CXXMethodDecl::method_iterator
1192 I = D->begin_overridden_methods(), E = D->end_overridden_methods();
1193 I != E; ++I)
1194 Writer.AddDeclRef(*I, Record);
1195 } else {
1196 // We only need to record overridden methods once for the canonical decl.
1197 Record.push_back(0);
1198 }
Richard Smith01b2cb42014-07-26 06:37:51 +00001199
Richard Smith8aed4222015-12-11 22:41:00 +00001200 if (D->getDeclContext() == D->getLexicalDeclContext() &&
1201 D->getFirstDecl() == D->getMostRecentDecl() &&
Richard Smith01b2cb42014-07-26 06:37:51 +00001202 !D->isInvalidDecl() &&
1203 !D->hasAttrs() &&
1204 !D->isTopLevelDeclInObjCContainer() &&
1205 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
1206 !D->hasExtInfo() &&
1207 !D->hasInheritedPrototype() &&
1208 D->hasWrittenPrototype())
1209 AbbrevToUse = Writer.getDeclCXXMethodAbbrev();
1210
Sebastian Redl539c5062010-08-18 23:57:32 +00001211 Code = serialization::DECL_CXX_METHOD;
Chris Lattnerca025db2010-05-07 21:43:38 +00001212}
1213
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001214void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001215 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001216
Stephan Tolksdorfa6a08632014-03-27 19:22:19 +00001217 Writer.AddDeclRef(D->getInheritedConstructor(), Record);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001218 Record.push_back(D->IsExplicitSpecified);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001219
Sebastian Redl539c5062010-08-18 23:57:32 +00001220 Code = serialization::DECL_CXX_CONSTRUCTOR;
Chris Lattnerca025db2010-05-07 21:43:38 +00001221}
1222
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001223void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001224 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001225
Richard Smithf8134002015-03-10 01:41:22 +00001226 Writer.AddDeclRef(D->getOperatorDelete(), Record);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001227
Sebastian Redl539c5062010-08-18 23:57:32 +00001228 Code = serialization::DECL_CXX_DESTRUCTOR;
Chris Lattnerca025db2010-05-07 21:43:38 +00001229}
1230
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001231void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001232 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001233 Record.push_back(D->IsExplicitSpecified);
Sebastian Redl539c5062010-08-18 23:57:32 +00001234 Code = serialization::DECL_CXX_CONVERSION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001235}
1236
Douglas Gregorba345522011-12-02 23:23:56 +00001237void ASTDeclWriter::VisitImportDecl(ImportDecl *D) {
1238 VisitDecl(D);
Argyrios Kyrtzidis7b8e5552012-10-03 01:58:45 +00001239 Record.push_back(Writer.getSubmoduleID(D->getImportedModule()));
Douglas Gregorba345522011-12-02 23:23:56 +00001240 ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs();
1241 Record.push_back(!IdentifierLocs.empty());
1242 if (IdentifierLocs.empty()) {
1243 Writer.AddSourceLocation(D->getLocEnd(), Record);
1244 Record.push_back(1);
1245 } else {
1246 for (unsigned I = 0, N = IdentifierLocs.size(); I != N; ++I)
1247 Writer.AddSourceLocation(IdentifierLocs[I], Record);
1248 Record.push_back(IdentifierLocs.size());
1249 }
1250 // Note: the number of source locations must always be the last element in
1251 // the record.
1252 Code = serialization::DECL_IMPORT;
1253}
1254
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001255void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001256 VisitDecl(D);
1257 Writer.AddSourceLocation(D->getColonLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001258 Code = serialization::DECL_ACCESS_SPEC;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001259}
1260
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001261void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) {
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001262 // Record the number of friend type template parameter lists here
1263 // so as to simplify memory allocation during deserialization.
1264 Record.push_back(D->NumTPLists);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001265 VisitDecl(D);
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001266 bool hasFriendDecl = D->Friend.is<NamedDecl*>();
1267 Record.push_back(hasFriendDecl);
1268 if (hasFriendDecl)
1269 Writer.AddDeclRef(D->getFriendDecl(), Record);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001270 else
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001271 Writer.AddTypeSourceInfo(D->getFriendType(), Record);
1272 for (unsigned i = 0; i < D->NumTPLists; ++i)
1273 Writer.AddTemplateParameterList(D->getFriendTypeTemplateParameterList(i),
1274 Record);
Douglas Gregore0fb32c2010-10-27 20:23:41 +00001275 Writer.AddDeclRef(D->getNextFriend(), Record);
John McCall2c2eb122010-10-16 06:59:13 +00001276 Record.push_back(D->UnsupportedFriend);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001277 Writer.AddSourceLocation(D->FriendLoc, Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001278 Code = serialization::DECL_FRIEND;
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001279}
1280
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001281void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001282 VisitDecl(D);
1283 Record.push_back(D->getNumTemplateParameters());
1284 for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i)
1285 Writer.AddTemplateParameterList(D->getTemplateParameterList(i), Record);
Craig Toppera13603a2014-05-22 05:54:18 +00001286 Record.push_back(D->getFriendDecl() != nullptr);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001287 if (D->getFriendDecl())
1288 Writer.AddDeclRef(D->getFriendDecl(), Record);
1289 else
1290 Writer.AddTypeSourceInfo(D->getFriendType(), Record);
1291 Writer.AddSourceLocation(D->getFriendLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001292 Code = serialization::DECL_FRIEND_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001293}
1294
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001295void ASTDeclWriter::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001296 VisitNamedDecl(D);
1297
1298 Writer.AddDeclRef(D->getTemplatedDecl(), Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001299 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001300}
1301
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001302void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Douglas Gregor68444de2012-01-14 15:13:49 +00001303 VisitRedeclarable(D);
1304
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001305 // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that
1306 // getCommonPtr() can be used while this is still initializing.
Rafael Espindola8db352d2013-10-17 15:37:26 +00001307 if (D->isFirstDecl()) {
Douglas Gregor074a4092011-12-19 18:19:24 +00001308 // This declaration owns the 'common' pointer, so serialize that data now.
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001309 Writer.AddDeclRef(D->getInstantiatedFromMemberTemplate(), Record);
1310 if (D->getInstantiatedFromMemberTemplate())
1311 Record.push_back(D->isMemberSpecialization());
Douglas Gregor074a4092011-12-19 18:19:24 +00001312 }
1313
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001314 VisitTemplateDecl(D);
1315 Record.push_back(D->getIdentifierNamespace());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001316}
1317
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001318void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001319 VisitRedeclarableTemplateDecl(D);
1320
Richard Smith509fc852015-02-27 23:05:10 +00001321 if (D->isFirstDecl())
1322 AddTemplateSpecializations(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001323 Code = serialization::DECL_CLASS_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001324}
1325
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001326void ASTDeclWriter::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001327 ClassTemplateSpecializationDecl *D) {
Richard Smithd8a83712015-08-22 01:47:18 +00001328 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1329
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001330 VisitCXXRecordDecl(D);
1331
1332 llvm::PointerUnion<ClassTemplateDecl *,
1333 ClassTemplatePartialSpecializationDecl *> InstFrom
1334 = D->getSpecializedTemplateOrPartial();
Argyrios Kyrtzidisd5553f12011-08-17 21:35:28 +00001335 if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) {
Sebastian Redl401b39a2010-08-24 22:50:24 +00001336 Writer.AddDeclRef(InstFromD, Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001337 } else {
Argyrios Kyrtzidisd5553f12011-08-17 21:35:28 +00001338 Writer.AddDeclRef(InstFrom.get<ClassTemplatePartialSpecializationDecl *>(),
1339 Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001340 Writer.AddTemplateArgumentList(&D->getTemplateInstantiationArgs(), Record);
1341 }
1342
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001343 Writer.AddTemplateArgumentList(&D->getTemplateArgs(), Record);
1344 Writer.AddSourceLocation(D->getPointOfInstantiation(), Record);
1345 Record.push_back(D->getSpecializationKind());
Axel Naumanna31dee22012-10-01 07:34:47 +00001346 Record.push_back(D->isCanonicalDecl());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001347
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001348 if (D->isCanonicalDecl()) {
1349 // When reading, we'll add it to the folding set of the following template.
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001350 Writer.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl(), Record);
1351 }
1352
Richard Smithd55889a2013-09-09 16:55:27 +00001353 // Explicit info.
1354 Writer.AddTypeSourceInfo(D->getTypeAsWritten(), Record);
1355 if (D->getTypeAsWritten()) {
1356 Writer.AddSourceLocation(D->getExternLoc(), Record);
1357 Writer.AddSourceLocation(D->getTemplateKeywordLoc(), Record);
1358 }
1359
Sebastian Redl539c5062010-08-18 23:57:32 +00001360 Code = serialization::DECL_CLASS_TEMPLATE_SPECIALIZATION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001361}
1362
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001363void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001364 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001365 VisitClassTemplateSpecializationDecl(D);
1366
1367 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
Enea Zaffanella6dbe1872013-08-10 07:24:53 +00001368 Writer.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten(), Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001369
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001370 // These are read/set from/to the first declaration.
Craig Toppera13603a2014-05-22 05:54:18 +00001371 if (D->getPreviousDecl() == nullptr) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001372 Writer.AddDeclRef(D->getInstantiatedFromMember(), Record);
1373 Record.push_back(D->isMemberSpecialization());
1374 }
1375
Sebastian Redl539c5062010-08-18 23:57:32 +00001376 Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001377}
1378
Larisse Voufo39a1e502013-08-06 01:03:05 +00001379void ASTDeclWriter::VisitVarTemplateDecl(VarTemplateDecl *D) {
1380 VisitRedeclarableTemplateDecl(D);
1381
Richard Smith509fc852015-02-27 23:05:10 +00001382 if (D->isFirstDecl())
1383 AddTemplateSpecializations(D);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001384 Code = serialization::DECL_VAR_TEMPLATE;
1385}
1386
1387void ASTDeclWriter::VisitVarTemplateSpecializationDecl(
1388 VarTemplateSpecializationDecl *D) {
Richard Smithd8a83712015-08-22 01:47:18 +00001389 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1390
Larisse Voufo39a1e502013-08-06 01:03:05 +00001391 VisitVarDecl(D);
1392
1393 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
1394 InstFrom = D->getSpecializedTemplateOrPartial();
1395 if (Decl *InstFromD = InstFrom.dyn_cast<VarTemplateDecl *>()) {
1396 Writer.AddDeclRef(InstFromD, Record);
1397 } else {
1398 Writer.AddDeclRef(InstFrom.get<VarTemplatePartialSpecializationDecl *>(),
1399 Record);
1400 Writer.AddTemplateArgumentList(&D->getTemplateInstantiationArgs(), Record);
1401 }
1402
1403 // Explicit info.
1404 Writer.AddTypeSourceInfo(D->getTypeAsWritten(), Record);
1405 if (D->getTypeAsWritten()) {
1406 Writer.AddSourceLocation(D->getExternLoc(), Record);
1407 Writer.AddSourceLocation(D->getTemplateKeywordLoc(), Record);
1408 }
1409
1410 Writer.AddTemplateArgumentList(&D->getTemplateArgs(), Record);
1411 Writer.AddSourceLocation(D->getPointOfInstantiation(), Record);
1412 Record.push_back(D->getSpecializationKind());
1413 Record.push_back(D->isCanonicalDecl());
1414
1415 if (D->isCanonicalDecl()) {
1416 // When reading, we'll add it to the folding set of the following template.
1417 Writer.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl(), Record);
1418 }
1419
1420 Code = serialization::DECL_VAR_TEMPLATE_SPECIALIZATION;
1421}
1422
1423void ASTDeclWriter::VisitVarTemplatePartialSpecializationDecl(
1424 VarTemplatePartialSpecializationDecl *D) {
1425 VisitVarTemplateSpecializationDecl(D);
1426
1427 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
Enea Zaffanella6dbe1872013-08-10 07:24:53 +00001428 Writer.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten(), Record);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001429
1430 // These are read/set from/to the first declaration.
Craig Toppera13603a2014-05-22 05:54:18 +00001431 if (D->getPreviousDecl() == nullptr) {
Larisse Voufo39a1e502013-08-06 01:03:05 +00001432 Writer.AddDeclRef(D->getInstantiatedFromMember(), Record);
1433 Record.push_back(D->isMemberSpecialization());
1434 }
1435
1436 Code = serialization::DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION;
1437}
1438
Fariborz Jahanian3a039e32011-08-27 20:50:59 +00001439void ASTDeclWriter::VisitClassScopeFunctionSpecializationDecl(
1440 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichet09af8c32011-08-17 01:06:54 +00001441 VisitDecl(D);
1442 Writer.AddDeclRef(D->getSpecialization(), Record);
1443 Code = serialization::DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION;
1444}
1445
1446
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001447void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001448 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001449
Richard Smith509fc852015-02-27 23:05:10 +00001450 if (D->isFirstDecl())
1451 AddTemplateSpecializations(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001452 Code = serialization::DECL_FUNCTION_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001453}
1454
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001455void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001456 VisitTypeDecl(D);
1457
1458 Record.push_back(D->wasDeclaredWithTypename());
Richard Smith8346e522015-06-10 01:47:58 +00001459
1460 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1461 !D->defaultArgumentWasInherited();
1462 Record.push_back(OwnsDefaultArg);
1463 if (OwnsDefaultArg)
Richard Smith1469b912015-06-10 00:29:03 +00001464 Writer.AddTypeSourceInfo(D->getDefaultArgumentInfo(), Record);
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001465
Sebastian Redl539c5062010-08-18 23:57:32 +00001466 Code = serialization::DECL_TEMPLATE_TYPE_PARM;
Chris Lattnerca025db2010-05-07 21:43:38 +00001467}
1468
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001469void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001470 // For an expanded parameter pack, record the number of expansion types here
Richard Smith1fde8ec2012-09-07 02:06:42 +00001471 // so that it's easier for deserialization to allocate the right amount of
1472 // memory.
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001473 if (D->isExpandedParameterPack())
1474 Record.push_back(D->getNumExpansionTypes());
1475
John McCallf4cd4f92011-02-09 01:13:10 +00001476 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001477 // TemplateParmPosition.
1478 Record.push_back(D->getDepth());
1479 Record.push_back(D->getPosition());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001480
1481 if (D->isExpandedParameterPack()) {
1482 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
1483 Writer.AddTypeRef(D->getExpansionType(I), Record);
1484 Writer.AddTypeSourceInfo(D->getExpansionTypeSourceInfo(I), Record);
1485 }
1486
1487 Code = serialization::DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK;
1488 } else {
1489 // Rest of NonTypeTemplateParmDecl.
1490 Record.push_back(D->isParameterPack());
Richard Smith8346e522015-06-10 01:47:58 +00001491 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1492 !D->defaultArgumentWasInherited();
1493 Record.push_back(OwnsDefaultArg);
1494 if (OwnsDefaultArg)
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001495 Writer.AddStmt(D->getDefaultArgument());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001496 Code = serialization::DECL_NON_TYPE_TEMPLATE_PARM;
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001497 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001498}
1499
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001500void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Richard Smith1fde8ec2012-09-07 02:06:42 +00001501 // For an expanded parameter pack, record the number of expansion types here
1502 // so that it's easier for deserialization to allocate the right amount of
1503 // memory.
1504 if (D->isExpandedParameterPack())
1505 Record.push_back(D->getNumExpansionTemplateParameters());
1506
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001507 VisitTemplateDecl(D);
1508 // TemplateParmPosition.
1509 Record.push_back(D->getDepth());
1510 Record.push_back(D->getPosition());
Richard Smith1fde8ec2012-09-07 02:06:42 +00001511
1512 if (D->isExpandedParameterPack()) {
1513 for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
1514 I != N; ++I)
1515 Writer.AddTemplateParameterList(D->getExpansionTemplateParameters(I),
1516 Record);
1517 Code = serialization::DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK;
1518 } else {
1519 // Rest of TemplateTemplateParmDecl.
Richard Smith1fde8ec2012-09-07 02:06:42 +00001520 Record.push_back(D->isParameterPack());
Richard Smith8346e522015-06-10 01:47:58 +00001521 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1522 !D->defaultArgumentWasInherited();
1523 Record.push_back(OwnsDefaultArg);
1524 if (OwnsDefaultArg)
Richard Smith1469b912015-06-10 00:29:03 +00001525 Writer.AddTemplateArgumentLoc(D->getDefaultArgument(), Record);
Richard Smith1fde8ec2012-09-07 02:06:42 +00001526 Code = serialization::DECL_TEMPLATE_TEMPLATE_PARM;
1527 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001528}
1529
Richard Smith3f1b5d02011-05-05 21:57:07 +00001530void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1531 VisitRedeclarableTemplateDecl(D);
1532 Code = serialization::DECL_TYPE_ALIAS_TEMPLATE;
1533}
1534
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001535void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001536 VisitDecl(D);
1537 Writer.AddStmt(D->getAssertExpr());
Richard Smithded9c2e2012-07-11 22:37:56 +00001538 Record.push_back(D->isFailed());
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001539 Writer.AddStmt(D->getMessage());
Abramo Bagnaraea947882011-03-08 16:41:52 +00001540 Writer.AddSourceLocation(D->getRParenLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001541 Code = serialization::DECL_STATIC_ASSERT;
Chris Lattnerca025db2010-05-07 21:43:38 +00001542}
1543
Chris Lattner7099dbc2009-04-27 06:16:06 +00001544/// \brief Emit the DeclContext part of a declaration context decl.
1545///
1546/// \param LexicalOffset the offset at which the DECL_CONTEXT_LEXICAL
1547/// block for this declaration context is stored. May be 0 to indicate
1548/// that there are no declarations stored within this context.
1549///
1550/// \param VisibleOffset the offset at which the DECL_CONTEXT_VISIBLE
1551/// block for this declaration context is stored. May be 0 to indicate
1552/// that there are no declarations visible from this context. Note
1553/// that this value will not be emitted for non-primary declaration
1554/// contexts.
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001555void ASTDeclWriter::VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset,
Chris Lattner7099dbc2009-04-27 06:16:06 +00001556 uint64_t VisibleOffset) {
1557 Record.push_back(LexicalOffset);
1558 Record.push_back(VisibleOffset);
1559}
1560
Richard Smithd8a83712015-08-22 01:47:18 +00001561const Decl *ASTWriter::getFirstLocalDecl(const Decl *D) {
Richard Smith3864be72015-09-11 02:22:03 +00001562 /// \brief Is this a local declaration (that is, one that will be written to
1563 /// our AST file)? This is the case for declarations that are neither imported
1564 /// from another AST file nor predefined.
1565 auto IsLocalDecl = [&](const Decl *D) -> bool {
1566 if (D->isFromASTFile())
1567 return false;
1568 auto I = DeclIDs.find(D);
1569 return (I == DeclIDs.end() || I->second >= NUM_PREDEF_DECL_IDS);
1570 };
1571
1572 assert(IsLocalDecl(D) && "expected a local declaration");
Richard Smithd8a83712015-08-22 01:47:18 +00001573
1574 const Decl *Canon = D->getCanonicalDecl();
Richard Smith3864be72015-09-11 02:22:03 +00001575 if (IsLocalDecl(Canon))
Richard Smithd8a83712015-08-22 01:47:18 +00001576 return Canon;
1577
1578 const Decl *&CacheEntry = FirstLocalDeclCache[Canon];
1579 if (CacheEntry)
1580 return CacheEntry;
1581
1582 for (const Decl *Redecl = D; Redecl; Redecl = Redecl->getPreviousDecl())
Richard Smith3864be72015-09-11 02:22:03 +00001583 if (IsLocalDecl(Redecl))
Richard Smithd8a83712015-08-22 01:47:18 +00001584 D = Redecl;
1585 return CacheEntry = D;
Richard Smith5fc18a92015-07-12 23:43:21 +00001586}
1587
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001588template <typename T>
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001589void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +00001590 T *First = D->getFirstDecl();
Richard Smith5a4737c2015-02-06 02:42:59 +00001591 T *MostRecent = First->getMostRecentDecl();
Richard Smithd8a83712015-08-22 01:47:18 +00001592 T *DAsT = static_cast<T *>(D);
Richard Smith5a4737c2015-02-06 02:42:59 +00001593 if (MostRecent != First) {
Richard Smithd8a83712015-08-22 01:47:18 +00001594 assert(isRedeclarableDeclKind(DAsT->getKind()) &&
Douglas Gregorfe732d52013-01-21 16:16:40 +00001595 "Not considered redeclarable?");
Richard Smith5a4737c2015-02-06 02:42:59 +00001596
Richard Smithfe620d22015-03-05 23:24:12 +00001597 Writer.AddDeclRef(First, Record);
Richard Smithfe620d22015-03-05 23:24:12 +00001598
Richard Smithd8a83712015-08-22 01:47:18 +00001599 // Write out a list of local redeclarations of this declaration if it's the
1600 // first local declaration in the chain.
1601 const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1602 if (DAsT == FirstLocal) {
Richard Smithd8a83712015-08-22 01:47:18 +00001603 // Emit a list of all imported first declarations so that we can be sure
1604 // that all redeclarations visible to this module are before D in the
1605 // redecl chain.
1606 unsigned I = Record.size();
1607 Record.push_back(0);
1608 if (Writer.Chain)
1609 AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1610 // This is the number of imported first declarations + 1.
1611 Record[I] = Record.size() - I;
Richard Smithd61d4ac2015-08-22 20:13:39 +00001612
1613 // Collect the set of local redeclarations of this declaration, from
1614 // newest to oldest.
1615 RecordData LocalRedecls;
1616 for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1617 Prev != FirstLocal; Prev = Prev->getPreviousDecl())
1618 if (!Prev->isFromASTFile())
1619 Writer.AddDeclRef(Prev, LocalRedecls);
1620
1621 // If we have any redecls, write them now as a separate record preceding
1622 // the declaration itself.
1623 if (LocalRedecls.empty())
1624 Record.push_back(0);
1625 else {
1626 Record.push_back(Writer.Stream.GetCurrentBitNo());
1627 Writer.Stream.EmitRecord(LOCAL_REDECLARATIONS, LocalRedecls);
1628 }
Richard Smithd8a83712015-08-22 01:47:18 +00001629 } else {
1630 Record.push_back(0);
1631 Writer.AddDeclRef(FirstLocal, Record);
Richard Smithfe620d22015-03-05 23:24:12 +00001632 }
Douglas Gregor358cd442012-01-15 16:58:34 +00001633
1634 // Make sure that we serialize both the previous and the most-recent
1635 // declarations, which (transitively) ensures that all declarations in the
1636 // chain get serialized.
Richard Smith5a4737c2015-02-06 02:42:59 +00001637 //
1638 // FIXME: This is not correct; when we reach an imported declaration we
1639 // won't emit its previous declaration.
Richard Smith5fc18a92015-07-12 23:43:21 +00001640 (void)Writer.GetDeclRef(D->getPreviousDecl());
Richard Smith5a4737c2015-02-06 02:42:59 +00001641 (void)Writer.GetDeclRef(MostRecent);
Douglas Gregor358cd442012-01-15 16:58:34 +00001642 } else {
1643 // We use the sentinel value 0 to indicate an only declaration.
1644 Record.push_back(0);
Douglas Gregor9f562c82011-12-19 15:27:36 +00001645 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001646}
Chris Lattner7099dbc2009-04-27 06:16:06 +00001647
Alexey Bataeva769e072013-03-22 06:34:35 +00001648void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
1649 Record.push_back(D->varlist_size());
1650 VisitDecl(D);
Aaron Ballman2205d2a2014-03-14 15:55:35 +00001651 for (auto *I : D->varlists())
1652 Writer.AddStmt(I);
Alexey Bataeva769e072013-03-22 06:34:35 +00001653 Code = serialization::DECL_OMP_THREADPRIVATE;
1654}
1655
Alexey Bataev4244be22016-02-11 05:35:55 +00001656void ASTDeclWriter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
Alexey Bataev90c228f2016-02-08 09:29:13 +00001657 VisitVarDecl(D);
Alexey Bataev4244be22016-02-11 05:35:55 +00001658 Code = serialization::DECL_OMP_CAPTUREDEXPR;
Alexey Bataev90c228f2016-02-08 09:29:13 +00001659}
1660
Chris Lattner7099dbc2009-04-27 06:16:06 +00001661//===----------------------------------------------------------------------===//
Sebastian Redl55c0ad52010-08-18 23:56:21 +00001662// ASTWriter Implementation
Chris Lattner7099dbc2009-04-27 06:16:06 +00001663//===----------------------------------------------------------------------===//
1664
Richard Smith01b2cb42014-07-26 06:37:51 +00001665void ASTWriter::WriteDeclAbbrevs() {
Chris Lattner258172e2009-04-27 07:35:58 +00001666 using namespace llvm;
Chris Lattner258172e2009-04-27 07:35:58 +00001667
Douglas Gregor03412ba2011-06-03 02:27:19 +00001668 BitCodeAbbrev *Abv;
1669
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001670 // Abbreviation for DECL_FIELD
1671 Abv = new BitCodeAbbrev();
1672 Abv->Add(BitCodeAbbrevOp(serialization::DECL_FIELD));
1673 // Decl
1674 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001675 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001676 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001677 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1678 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1679 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1680 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001681 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001682 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001683 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001684 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001685 // NamedDecl
1686 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1687 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001688 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001689 // ValueDecl
1690 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1691 // DeclaratorDecl
1692 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1693 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
1694 // FieldDecl
1695 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
1696 Abv->Add(BitCodeAbbrevOp(0)); //getBitWidth
1697 // Type Source Info
1698 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1699 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1700 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1701 DeclFieldAbbrev = Stream.EmitAbbrev(Abv);
1702
1703 // Abbreviation for DECL_OBJC_IVAR
1704 Abv = new BitCodeAbbrev();
1705 Abv->Add(BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR));
1706 // Decl
1707 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001708 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001709 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001710 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1711 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1712 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1713 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001714 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001715 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001716 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001717 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001718 // NamedDecl
1719 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1720 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001721 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001722 // ValueDecl
1723 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1724 // DeclaratorDecl
1725 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1726 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
1727 // FieldDecl
1728 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
1729 Abv->Add(BitCodeAbbrevOp(0)); //getBitWidth
1730 // ObjC Ivar
1731 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl
1732 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize
1733 // Type Source Info
1734 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1735 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1736 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1737 DeclObjCIvarAbbrev = Stream.EmitAbbrev(Abv);
1738
1739 // Abbreviation for DECL_ENUM
1740 Abv = new BitCodeAbbrev();
1741 Abv->Add(BitCodeAbbrevOp(serialization::DECL_ENUM));
Douglas Gregor3e300102011-10-26 17:53:41 +00001742 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001743 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Chris Lattner258172e2009-04-27 07:35:58 +00001744 // Decl
1745 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001746 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001747 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Chris Lattner258172e2009-04-27 07:35:58 +00001748 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1749 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
Douglas Gregorc9c02ed2009-06-19 23:52:42 +00001750 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +00001751 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001752 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Chris Lattner258172e2009-04-27 07:35:58 +00001753 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001754 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001755 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Douglas Gregor03412ba2011-06-03 02:27:19 +00001756 // NamedDecl
1757 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1758 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001759 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001760 // TypeDecl
1761 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1762 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001763 // TagDecl
1764 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
1765 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
John McCallf937c022011-10-07 06:10:15 +00001766 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001767 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +00001768 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
David Blaikiea8d23ce2013-07-14 01:07:41 +00001769 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001770 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Richard Smith70d58502014-08-30 00:04:23 +00001771 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001772 // EnumDecl
1773 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddTypeRef
1774 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IntegerType
1775 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getPromotionType
1776 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumPositiveBits
1777 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumNegativeBits
1778 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScoped
1779 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScopedUsingClassTag
1780 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isFixed
1781 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedMembEnum
1782 // DC
1783 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
1784 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
1785 DeclEnumAbbrev = Stream.EmitAbbrev(Abv);
Mike Stump11289f42009-09-09 15:08:12 +00001786
Douglas Gregor03412ba2011-06-03 02:27:19 +00001787 // Abbreviation for DECL_RECORD
1788 Abv = new BitCodeAbbrev();
1789 Abv->Add(BitCodeAbbrevOp(serialization::DECL_RECORD));
Douglas Gregor3e300102011-10-26 17:53:41 +00001790 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001791 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Douglas Gregor03412ba2011-06-03 02:27:19 +00001792 // Decl
1793 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001794 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001795 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Douglas Gregor03412ba2011-06-03 02:27:19 +00001796 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1797 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1798 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1799 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001800 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Douglas Gregor03412ba2011-06-03 02:27:19 +00001801 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001802 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001803 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Douglas Gregor03412ba2011-06-03 02:27:19 +00001804 // NamedDecl
1805 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1806 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001807 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Douglas Gregor03412ba2011-06-03 02:27:19 +00001808 // TypeDecl
1809 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1810 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
Douglas Gregor03412ba2011-06-03 02:27:19 +00001811 // TagDecl
1812 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
1813 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
John McCallf937c022011-10-07 06:10:15 +00001814 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
Douglas Gregor03412ba2011-06-03 02:27:19 +00001815 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +00001816 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
David Blaikiea8d23ce2013-07-14 01:07:41 +00001817 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
Douglas Gregor03412ba2011-06-03 02:27:19 +00001818 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Richard Smith70d58502014-08-30 00:04:23 +00001819 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
Douglas Gregor03412ba2011-06-03 02:27:19 +00001820 // RecordDecl
1821 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // FlexibleArrayMember
1822 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // AnonymousStructUnion
1823 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasObjectMember
Fariborz Jahanian78652202013-01-25 23:57:05 +00001824 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasVolatileMember
Douglas Gregor03412ba2011-06-03 02:27:19 +00001825 // DC
1826 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
1827 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
1828 DeclRecordAbbrev = Stream.EmitAbbrev(Abv);
1829
1830 // Abbreviation for DECL_PARM_VAR
1831 Abv = new BitCodeAbbrev();
1832 Abv->Add(BitCodeAbbrevOp(serialization::DECL_PARM_VAR));
Douglas Gregor3e300102011-10-26 17:53:41 +00001833 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001834 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Douglas Gregor03412ba2011-06-03 02:27:19 +00001835 // Decl
1836 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001837 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001838 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Douglas Gregor03412ba2011-06-03 02:27:19 +00001839 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1840 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1841 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1842 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001843 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Douglas Gregor03412ba2011-06-03 02:27:19 +00001844 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001845 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001846 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Chris Lattner258172e2009-04-27 07:35:58 +00001847 // NamedDecl
1848 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1849 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001850 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Chris Lattner258172e2009-04-27 07:35:58 +00001851 // ValueDecl
1852 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +00001853 // DeclaratorDecl
Abramo Bagnaradff19302011-03-08 08:55:46 +00001854 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00001855 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Chris Lattner258172e2009-04-27 07:35:58 +00001856 // VarDecl
1857 Abv->Add(BitCodeAbbrevOp(0)); // StorageClass
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +00001858 Abv->Add(BitCodeAbbrevOp(0)); // getTSCSpec
Chris Lattner258172e2009-04-27 07:35:58 +00001859 Abv->Add(BitCodeAbbrevOp(0)); // hasCXXDirectInitializer
Richard Smith88581592013-02-12 05:48:23 +00001860 Abv->Add(BitCodeAbbrevOp(0)); // Linkage
Chris Lattner258172e2009-04-27 07:35:58 +00001861 Abv->Add(BitCodeAbbrevOp(0)); // HasInit
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001862 Abv->Add(BitCodeAbbrevOp(0)); // HasMemberSpecializationInfo
Chris Lattner258172e2009-04-27 07:35:58 +00001863 // ParmVarDecl
John McCall82490832011-05-02 00:30:12 +00001864 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsObjCMethodParameter
John McCall8fb0d9d2011-05-01 22:35:37 +00001865 Abv->Add(BitCodeAbbrevOp(0)); // ScopeDepth
1866 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex
Chris Lattner258172e2009-04-27 07:35:58 +00001867 Abv->Add(BitCodeAbbrevOp(0)); // ObjCDeclQualifier
John McCall6a014d52011-03-09 04:22:44 +00001868 Abv->Add(BitCodeAbbrevOp(0)); // KNRPromoted
John McCallf3cd6652010-03-12 18:31:32 +00001869 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedDefaultArg
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +00001870 Abv->Add(BitCodeAbbrevOp(0)); // HasUninstantiatedDefaultArg
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001871 // Type Source Info
1872 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1873 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1874 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1875 DeclParmVarAbbrev = Stream.EmitAbbrev(Abv);
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001876
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00001877 // Abbreviation for DECL_TYPEDEF
Douglas Gregor03412ba2011-06-03 02:27:19 +00001878 Abv = new BitCodeAbbrev();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001879 Abv->Add(BitCodeAbbrevOp(serialization::DECL_TYPEDEF));
Douglas Gregor05f10352011-12-17 23:38:30 +00001880 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001881 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001882 // Decl
1883 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001884 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001885 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001886 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1887 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
Richard Smith01b2cb42014-07-26 06:37:51 +00001888 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isUsed
1889 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001890 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Richard Smith01b2cb42014-07-26 06:37:51 +00001891 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001892 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001893 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001894 // NamedDecl
1895 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1896 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001897 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001898 // TypeDecl
1899 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1900 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
1901 // TypedefDecl
1902 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1903 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1904 DeclTypedefAbbrev = Stream.EmitAbbrev(Abv);
1905
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00001906 // Abbreviation for DECL_VAR
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001907 Abv = new BitCodeAbbrev();
1908 Abv->Add(BitCodeAbbrevOp(serialization::DECL_VAR));
Douglas Gregor3e300102011-10-26 17:53:41 +00001909 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001910 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001911 // Decl
1912 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001913 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001914 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001915 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1916 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1917 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1918 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001919 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001920 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001921 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001922 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001923 // NamedDecl
1924 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1925 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001926 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001927 // ValueDecl
1928 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1929 // DeclaratorDecl
1930 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1931 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
1932 // VarDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001933 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // StorageClass
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +00001934 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // getTSCSpec
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001935 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // CXXDirectInitializer
1936 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isExceptionVariable
1937 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isNRVOVariable
1938 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCXXForRangeDecl
John McCalld4631322011-06-17 06:42:21 +00001939 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong
Douglas Gregor12cda632012-09-20 23:43:29 +00001940 Abv->Add(BitCodeAbbrevOp(0)); // isConstexpr
Richard Smithbb13c9a2013-09-28 04:02:39 +00001941 Abv->Add(BitCodeAbbrevOp(0)); // isInitCapture
Richard Smith1c34fb72013-08-13 18:18:50 +00001942 Abv->Add(BitCodeAbbrevOp(0)); // isPrevDeclInSameScope
Rafael Espindola50df3a02013-05-25 17:16:20 +00001943 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001944 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasInit
1945 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasMemberSpecInfo
1946 // Type Source Info
1947 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1948 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1949 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1950 DeclVarAbbrev = Stream.EmitAbbrev(Abv);
1951
Richard Smith01b2cb42014-07-26 06:37:51 +00001952 // Abbreviation for DECL_CXX_METHOD
1953 Abv = new BitCodeAbbrev();
1954 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CXX_METHOD));
1955 // RedeclarableDecl
1956 Abv->Add(BitCodeAbbrevOp(0)); // CanonicalDecl
1957 // Decl
1958 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001959 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Richard Smith01b2cb42014-07-26 06:37:51 +00001960 Abv->Add(BitCodeAbbrevOp(0)); // Invalid
1961 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1962 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Implicit
1963 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Used
1964 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Referenced
1965 Abv->Add(BitCodeAbbrevOp(0)); // InObjCContainer
1966 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Access
1967 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ModulePrivate
1968 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
1969 // NamedDecl
1970 Abv->Add(BitCodeAbbrevOp(DeclarationName::Identifier)); // NameKind
1971 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Identifier
Richard Smith2b560572015-02-07 03:11:11 +00001972 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Richard Smith01b2cb42014-07-26 06:37:51 +00001973 // ValueDecl
1974 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1975 // DeclaratorDecl
1976 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerLocStart
1977 Abv->Add(BitCodeAbbrevOp(0)); // HasExtInfo
1978 // FunctionDecl
1979 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS
1980 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // StorageClass
1981 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Inline
1982 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InlineSpecified
1983 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // VirtualAsWritten
1984 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Pure
1985 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedProto
1986 Abv->Add(BitCodeAbbrevOp(1)); // HasWrittenProto
Richard Smith72625c22015-02-06 23:20:21 +00001987 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Deleted
Richard Smith01b2cb42014-07-26 06:37:51 +00001988 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Trivial
1989 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Defaulted
1990 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ExplicitlyDefaulted
1991 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ImplicitReturnZero
1992 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Constexpr
1993 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // SkippedBody
1994 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // LateParsed
1995 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
1996 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LocEnd
1997 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // TemplateKind
1998 // This Array slurps the rest of the record. Fortunately we want to encode
1999 // (nearly) all the remaining (variable number of) fields in the same way.
2000 //
2001 // This is the function template information if any, then
2002 // NumParams and Params[] from FunctionDecl, and
2003 // NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl.
2004 //
2005 // Add an AbbrevOp for 'size then elements' and use it here.
2006 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2007 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
2008 DeclCXXMethodAbbrev = Stream.EmitAbbrev(Abv);
2009
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00002010 // Abbreviation for EXPR_DECL_REF
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002011 Abv = new BitCodeAbbrev();
Douglas Gregor03412ba2011-06-03 02:27:19 +00002012 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_DECL_REF));
2013 //Stmt
2014 //Expr
2015 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002016 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2017 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2018 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002019 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2020 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2021 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2022 //DeclRefExpr
2023 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HasQualifier
2024 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //GetDeclFound
2025 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ExplicitTemplateArgs
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002026 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HadMultipleCandidates
Alexey Bataev19acc3d2015-01-12 10:17:46 +00002027 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2028 1)); // RefersToEnclosingVariableOrCapture
Douglas Gregor03412ba2011-06-03 02:27:19 +00002029 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef
2030 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2031 DeclRefExprAbbrev = Stream.EmitAbbrev(Abv);
2032
2033 // Abbreviation for EXPR_INTEGER_LITERAL
2034 Abv = new BitCodeAbbrev();
2035 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL));
2036 //Stmt
2037 //Expr
2038 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002039 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2040 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2041 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002042 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2043 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2044 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2045 //Integer Literal
2046 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2047 Abv->Add(BitCodeAbbrevOp(32)); // Bit Width
2048 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value
2049 IntegerLiteralAbbrev = Stream.EmitAbbrev(Abv);
2050
2051 // Abbreviation for EXPR_CHARACTER_LITERAL
2052 Abv = new BitCodeAbbrev();
2053 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL));
2054 //Stmt
2055 //Expr
2056 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002057 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2058 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2059 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002060 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2061 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2062 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
Jonathan D. Turnerd09655f2011-06-03 21:46:44 +00002063 //Character Literal
Douglas Gregor03412ba2011-06-03 02:27:19 +00002064 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue
2065 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
Aaron Ballman9a17c852016-01-07 20:59:26 +00002066 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // getKind
Douglas Gregor03412ba2011-06-03 02:27:19 +00002067 CharacterLiteralAbbrev = Stream.EmitAbbrev(Abv);
2068
Richard Smitha27c26e2014-07-27 04:19:32 +00002069 // Abbreviation for EXPR_IMPLICIT_CAST
2070 Abv = new BitCodeAbbrev();
2071 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_IMPLICIT_CAST));
2072 // Stmt
2073 // Expr
2074 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2075 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2076 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2077 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
2078 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2079 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2080 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2081 // CastExpr
2082 Abv->Add(BitCodeAbbrevOp(0)); // PathSize
2083 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 6)); // CastKind
2084 // ImplicitCastExpr
2085 ExprImplicitCastAbbrev = Stream.EmitAbbrev(Abv);
2086
Sebastian Redl66c5eef2010-07-27 00:17:23 +00002087 Abv = new BitCodeAbbrev();
Sebastian Redl539c5062010-08-18 23:57:32 +00002088 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL));
Sebastian Redl66c5eef2010-07-27 00:17:23 +00002089 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2090 DeclContextLexicalAbbrev = Stream.EmitAbbrev(Abv);
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002091
2092 Abv = new BitCodeAbbrev();
2093 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE));
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002094 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2095 DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(Abv);
Chris Lattner258172e2009-04-27 07:35:58 +00002096}
2097
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002098/// isRequiredDecl - Check if this is a "required" Decl, which must be seen by
2099/// consumers of the AST.
2100///
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002101/// Such decls will always be deserialized from the AST file, so we would like
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002102/// this to be as restrictive as possible. Currently the predicate is driven by
2103/// code generation requirements, if other clients have a different notion of
2104/// what is "required" then we may have to consider an alternate scheme where
2105/// clients can iterate over the top-level decls and get information on them,
2106/// without necessary deserializing them. We could explicitly require such
2107/// clients to use a separate API call to "realize" the decl. This should be
2108/// relatively painless since they would presumably only do it for top-level
2109/// decls.
Richard Smithc52efa72015-08-19 02:30:28 +00002110static bool isRequiredDecl(const Decl *D, ASTContext &Context,
2111 bool WritingModule) {
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00002112 // An ObjCMethodDecl is never considered as "required" because its
2113 // implementation container always is.
2114
Richard Smithc52efa72015-08-19 02:30:28 +00002115 // File scoped assembly or obj-c implementation must be seen.
2116 if (isa<FileScopeAsmDecl>(D) || isa<ObjCImplDecl>(D))
2117 return true;
2118
2119 // ImportDecl is used by codegen to determine the set of imported modules to
2120 // search for inputs for automatic linking; include it if it has a semantic
2121 // effect.
2122 if (isa<ImportDecl>(D) && !WritingModule)
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002123 return true;
2124
Argyrios Kyrtzidisc9049332010-07-29 20:08:05 +00002125 return Context.DeclMustBeEmitted(D);
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002126}
2127
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002128void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) {
Argyrios Kyrtzidisd9f526f2010-10-28 09:29:32 +00002129 // Switch case IDs are per Decl.
2130 ClearSwitchCaseIDs();
2131
Chris Lattner7099dbc2009-04-27 06:16:06 +00002132 RecordData Record;
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002133 ASTDeclWriter W(*this, Context, Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +00002134
Douglas Gregorb3163e52012-01-05 22:33:30 +00002135 // Determine the ID for this declaration.
2136 serialization::DeclID ID;
Douglas Gregor7dd37e52015-11-03 01:20:54 +00002137 assert(!D->isFromASTFile() && "should not be emitting imported decl");
2138 serialization::DeclID &IDR = DeclIDs[D];
2139 if (IDR == 0)
2140 IDR = NextDeclID++;
Douglas Gregorb3163e52012-01-05 22:33:30 +00002141
Douglas Gregor7dd37e52015-11-03 01:20:54 +00002142 ID = IDR;
Argyrios Kyrtzidisbf6c3392012-03-22 16:08:04 +00002143
2144 bool isReplacingADecl = ID < FirstDeclID;
2145
2146 // If this declaration is also a DeclContext, write blocks for the
2147 // declarations that lexically stored inside its context and those
2148 // declarations that are visible from its context. These blocks
2149 // are written before the declaration itself so that we can put
2150 // their offsets into the record for the declaration.
2151 uint64_t LexicalOffset = 0;
2152 uint64_t VisibleOffset = 0;
2153 DeclContext *DC = dyn_cast<DeclContext>(D);
2154 if (DC) {
2155 if (isReplacingADecl) {
2156 // It is replacing a decl from a chained PCH; make sure that the
2157 // DeclContext is fully loaded.
2158 if (DC->hasExternalLexicalStorage())
2159 DC->LoadLexicalDeclsFromExternalStorage();
2160 if (DC->hasExternalVisibleStorage())
2161 Chain->completeVisibleDeclsMap(DC);
2162 }
2163 LexicalOffset = WriteDeclContextLexicalBlock(Context, DC);
2164 VisibleOffset = WriteDeclContextVisibleBlock(Context, DC);
2165 }
Douglas Gregorb3163e52012-01-05 22:33:30 +00002166
Richard Smithd61d4ac2015-08-22 20:13:39 +00002167 // Build a record for this declaration
2168 Record.clear();
2169 W.Code = (serialization::DeclCode)0;
2170 W.AbbrevToUse = 0;
2171 W.Visit(D);
2172 if (DC) W.VisitDeclContext(DC, LexicalOffset, VisibleOffset);
2173
Argyrios Kyrtzidisbf6c3392012-03-22 16:08:04 +00002174 if (isReplacingADecl) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002175 // We're replacing a decl in a previous file.
Argyrios Kyrtzidis6fb60032011-10-31 07:20:15 +00002176 ReplacedDecls.push_back(ReplacedDeclInfo(ID, Stream.GetCurrentBitNo(),
2177 D->getLocation()));
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002178 } else {
2179 unsigned Index = ID - FirstDeclID;
Douglas Gregor12bfa382009-10-17 00:13:19 +00002180
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002181 // Record the offset for this declaration
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +00002182 SourceLocation Loc = D->getLocation();
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002183 if (DeclOffsets.size() == Index)
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +00002184 DeclOffsets.push_back(DeclOffset(Loc, Stream.GetCurrentBitNo()));
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002185 else if (DeclOffsets.size() < Index) {
2186 DeclOffsets.resize(Index+1);
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +00002187 DeclOffsets[Index].setLocation(Loc);
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00002188 DeclOffsets[Index].BitOffset = Stream.GetCurrentBitNo();
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002189 }
Richard Smithd61d4ac2015-08-22 20:13:39 +00002190
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +00002191 SourceManager &SM = Context.getSourceManager();
Argyrios Kyrtzidisdf53da82011-10-28 23:57:43 +00002192 if (Loc.isValid() && SM.isLocalSourceLocation(Loc))
2193 associateDeclWithFile(D, ID);
Douglas Gregor12bfa382009-10-17 00:13:19 +00002194 }
2195
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +00002196 if (!W.Code)
Chris Lattner0e62c1c2011-07-23 10:55:15 +00002197 llvm::report_fatal_error(StringRef("unexpected declaration kind '") +
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +00002198 D->getDeclKindName() + "'");
Douglas Gregor12bfa382009-10-17 00:13:19 +00002199 Stream.EmitRecord(W.Code, Record, W.AbbrevToUse);
2200
Richard Smithc2bb8182015-03-24 06:36:48 +00002201 // Flush any expressions, base specifiers, and ctor initializers that
2202 // were written as part of this declaration.
2203 FlushPendingAfterDecl();
2204
Ben Langmuir332aafe2014-01-31 01:06:56 +00002205 // Note declarations that should be deserialized eagerly so that we can add
2206 // them to a record in the AST file later.
Richard Smithc52efa72015-08-19 02:30:28 +00002207 if (isRequiredDecl(D, Context, WritingModule))
Ben Langmuir332aafe2014-01-31 01:06:56 +00002208 EagerlyDeserializedDecls.push_back(ID);
Chris Lattner7099dbc2009-04-27 06:16:06 +00002209}
Richard Smithd28ac5b2014-03-22 23:33:22 +00002210
2211void ASTWriter::AddFunctionDefinition(const FunctionDecl *FD,
2212 RecordData &Record) {
2213 ClearSwitchCaseIDs();
2214
2215 ASTDeclWriter W(*this, FD->getASTContext(), Record);
2216 W.AddFunctionDefinition(FD);
2217}