blob: 88b74a4b4c5e87cc1f003b7badf87ea6aff57426 [file] [log] [blame]
Sebastian Redld6522cf2010-08-18 23:56:31 +00001//===--- ASTWriterDecl.cpp - Declaration Serialization --------------------===//
Chris Lattner7099dbc2009-04-27 06:16:06 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements serialization for Declarations.
11//
12//===----------------------------------------------------------------------===//
13
Sebastian Redl1914c6f2010-08-18 23:56:37 +000014#include "clang/Serialization/ASTWriter.h"
Sebastian Redlfa1f3702011-04-24 16:28:13 +000015#include "ASTCommon.h"
Chris Lattnerca025db2010-05-07 21:43:38 +000016#include "clang/AST/DeclCXX.h"
Argyrios Kyrtzidis3317d982010-10-20 16:22:56 +000017#include "clang/AST/DeclContextInternals.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000018#include "clang/AST/DeclTemplate.h"
19#include "clang/AST/DeclVisitor.h"
20#include "clang/AST/Expr.h"
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +000021#include "clang/Basic/SourceManager.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000022#include "clang/Serialization/ASTReader.h"
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +000023#include "llvm/ADT/Twine.h"
Chris Lattner7099dbc2009-04-27 06:16:06 +000024#include "llvm/Bitcode/BitstreamWriter.h"
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +000025#include "llvm/Support/ErrorHandling.h"
Chris Lattner7099dbc2009-04-27 06:16:06 +000026using namespace clang;
Sebastian Redlfa1f3702011-04-24 16:28:13 +000027using namespace serialization;
Chris Lattner7099dbc2009-04-27 06:16:06 +000028
29//===----------------------------------------------------------------------===//
30// Declaration serialization
31//===----------------------------------------------------------------------===//
32
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000033namespace clang {
Sebastian Redl42a0f6a2010-08-18 23:56:27 +000034 class ASTDeclWriter : public DeclVisitor<ASTDeclWriter, void> {
Chris Lattner7099dbc2009-04-27 06:16:06 +000035
Sebastian Redl55c0ad52010-08-18 23:56:21 +000036 ASTWriter &Writer;
Chris Lattner7099dbc2009-04-27 06:16:06 +000037 ASTContext &Context;
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000038 typedef ASTWriter::RecordData RecordData;
39 RecordData &Record;
Chris Lattner7099dbc2009-04-27 06:16:06 +000040
41 public:
Sebastian Redl539c5062010-08-18 23:57:32 +000042 serialization::DeclCode Code;
Chris Lattner258172e2009-04-27 07:35:58 +000043 unsigned AbbrevToUse;
Chris Lattner7099dbc2009-04-27 06:16:06 +000044
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000045 ASTDeclWriter(ASTWriter &Writer, ASTContext &Context, RecordData &Record)
Chris Lattner258172e2009-04-27 07:35:58 +000046 : Writer(Writer), Context(Context), Record(Record) {
47 }
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000048
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +000049 void Visit(Decl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000050
51 void VisitDecl(Decl *D);
Nico Weber66220292016-03-02 17:28:48 +000052 void VisitPragmaCommentDecl(PragmaCommentDecl *D);
Nico Webercbbaeb12016-03-02 19:28:54 +000053 void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000054 void VisitTranslationUnitDecl(TranslationUnitDecl *D);
55 void VisitNamedDecl(NamedDecl *D);
Chris Lattnerc8e630e2011-02-17 07:39:24 +000056 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregore31bbd92010-02-21 18:22:14 +000057 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000058 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
59 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000060 void VisitTypeDecl(TypeDecl *D);
Douglas Gregor1f179062011-12-19 14:40:25 +000061 void VisitTypedefNameDecl(TypedefNameDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000062 void VisitTypedefDecl(TypedefDecl *D);
Richard Smithdda56e42011-04-15 14:24:37 +000063 void VisitTypeAliasDecl(TypeAliasDecl *D);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000064 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000065 void VisitTagDecl(TagDecl *D);
66 void VisitEnumDecl(EnumDecl *D);
67 void VisitRecordDecl(RecordDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000068 void VisitCXXRecordDecl(CXXRecordDecl *D);
69 void VisitClassTemplateSpecializationDecl(
70 ClassTemplateSpecializationDecl *D);
71 void VisitClassTemplatePartialSpecializationDecl(
72 ClassTemplatePartialSpecializationDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +000073 void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D);
74 void VisitVarTemplatePartialSpecializationDecl(
75 VarTemplatePartialSpecializationDecl *D);
Fariborz Jahanian3a039e32011-08-27 20:50:59 +000076 void VisitClassScopeFunctionSpecializationDecl(
77 ClassScopeFunctionSpecializationDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000078 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000079 void VisitValueDecl(ValueDecl *D);
80 void VisitEnumConstantDecl(EnumConstantDecl *D);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +000081 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +000082 void VisitDeclaratorDecl(DeclaratorDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000083 void VisitFunctionDecl(FunctionDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000084 void VisitCXXMethodDecl(CXXMethodDecl *D);
85 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
86 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
87 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000088 void VisitFieldDecl(FieldDecl *D);
John McCall5e77d762013-04-16 07:28:30 +000089 void VisitMSPropertyDecl(MSPropertyDecl *D);
Francois Pichet783dd6e2010-11-21 06:08:52 +000090 void VisitIndirectFieldDecl(IndirectFieldDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +000091 void VisitVarDecl(VarDecl *D);
92 void VisitImplicitParamDecl(ImplicitParamDecl *D);
93 void VisitParmVarDecl(ParmVarDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000094 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
95 void VisitTemplateDecl(TemplateDecl *D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +000096 void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +000097 void VisitClassTemplateDecl(ClassTemplateDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +000098 void VisitVarTemplateDecl(VarTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +000099 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000100 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3f1b5d02011-05-05 21:57:07 +0000101 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000102 void VisitUsingDecl(UsingDecl *D);
103 void VisitUsingShadowDecl(UsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000104 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000105 void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
Douglas Gregorba345522011-12-02 23:23:56 +0000106 void VisitImportDecl(ImportDecl *D);
Abramo Bagnarad7340582010-06-05 05:09:32 +0000107 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000108 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000109 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
110 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000111 void VisitBlockDecl(BlockDecl *D);
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +0000112 void VisitCapturedDecl(CapturedDecl *D);
Michael Han84324352013-02-22 17:15:32 +0000113 void VisitEmptyDecl(EmptyDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000114
Mike Stump11289f42009-09-09 15:08:12 +0000115 void VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset,
Chris Lattner7099dbc2009-04-27 06:16:06 +0000116 uint64_t VisibleOffset);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000117 template <typename T> void VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000118
119
Alexis Hunted053252010-05-30 07:21:58 +0000120 // FIXME: Put in the same order is DeclNodes.td?
Chris Lattner7099dbc2009-04-27 06:16:06 +0000121 void VisitObjCMethodDecl(ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000122 void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000123 void VisitObjCContainerDecl(ObjCContainerDecl *D);
124 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
125 void VisitObjCIvarDecl(ObjCIvarDecl *D);
126 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
127 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000128 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
129 void VisitObjCImplDecl(ObjCImplDecl *D);
130 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
131 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
132 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
133 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
134 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
Alexey Bataeva769e072013-03-22 06:34:35 +0000135 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000136 void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
Alexey Bataev4244be22016-02-11 05:35:55 +0000137 void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
Richard Smithd28ac5b2014-03-22 23:33:22 +0000138
Douglas Gregor85f3f952015-07-07 03:57:15 +0000139 /// Add an Objective-C type parameter list to the given record.
140 void AddObjCTypeParamList(ObjCTypeParamList *typeParams) {
141 // Empty type parameter list.
142 if (!typeParams) {
143 Record.push_back(0);
144 return;
145 }
146
147 Record.push_back(typeParams->size());
148 for (auto typeParam : *typeParams) {
149 Writer.AddDeclRef(typeParam, Record);
150 }
151 Writer.AddSourceLocation(typeParams->getLAngleLoc(), Record);
152 Writer.AddSourceLocation(typeParams->getRAngleLoc(), Record);
153 }
154
Richard Smithd28ac5b2014-03-22 23:33:22 +0000155 void AddFunctionDefinition(const FunctionDecl *FD) {
156 assert(FD->doesThisDeclarationHaveABody());
Richard Smithc2bb8182015-03-24 06:36:48 +0000157 if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
158 Record.push_back(CD->NumCtorInitializers);
159 if (CD->NumCtorInitializers)
160 Writer.AddCXXCtorInitializersRef(
161 llvm::makeArrayRef(CD->init_begin(), CD->init_end()), Record);
162 }
Richard Smithd28ac5b2014-03-22 23:33:22 +0000163 Writer.AddStmt(FD->getBody());
164 }
Richard Smith509fc852015-02-27 23:05:10 +0000165
Richard Smithd8a83712015-08-22 01:47:18 +0000166 /// Add to the record the first declaration from each module file that
167 /// provides a declaration of D. The intent is to provide a sufficient
168 /// set such that reloading this set will load all current redeclarations.
169 void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) {
170 llvm::MapVector<ModuleFile*, const Decl*> Firsts;
171 // FIXME: We can skip entries that we know are implied by others.
Richard Smith5f55d932015-08-27 21:38:25 +0000172 for (const Decl *R = D->getMostRecentDecl(); R; R = R->getPreviousDecl()) {
173 if (R->isFromASTFile())
Richard Smithd8a83712015-08-22 01:47:18 +0000174 Firsts[Writer.Chain->getOwningModuleFile(R)] = R;
Richard Smith5f55d932015-08-27 21:38:25 +0000175 else if (IncludeLocal)
176 Firsts[nullptr] = R;
177 }
Richard Smithd8a83712015-08-22 01:47:18 +0000178 for (const auto &F : Firsts)
179 Writer.AddDeclRef(F.second, Record);
180 }
181
Richard Smith509fc852015-02-27 23:05:10 +0000182 /// Get the specialization decl from an entry in the specialization list.
183 template <typename EntryType>
184 typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType *
185 getSpecializationDecl(EntryType &T) {
186 return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T);
187 }
188
189 /// Get the list of partial specializations from a template's common ptr.
190 template<typename T>
191 decltype(T::PartialSpecializations) &getPartialSpecializations(T *Common) {
192 return Common->PartialSpecializations;
193 }
194 ArrayRef<Decl> getPartialSpecializations(FunctionTemplateDecl::Common *) {
195 return None;
196 }
197
Richard Smith8ab0cfd2016-02-24 21:59:10 +0000198 template<typename DeclTy>
199 void AddTemplateSpecializations(DeclTy *D) {
Richard Smith509fc852015-02-27 23:05:10 +0000200 auto *Common = D->getCommonPtr();
201
202 // If we have any lazy specializations, and the external AST source is
203 // our chained AST reader, we can just write out the DeclIDs. Otherwise,
204 // we need to resolve them to actual declarations.
205 if (Writer.Chain != Writer.Context->getExternalSource() &&
206 Common->LazySpecializations) {
207 D->LoadLazySpecializations();
208 assert(!Common->LazySpecializations);
209 }
210
Richard Smith509fc852015-02-27 23:05:10 +0000211 ArrayRef<DeclID> LazySpecializations;
212 if (auto *LS = Common->LazySpecializations)
Craig Topper55e39a72015-09-29 04:53:28 +0000213 LazySpecializations = llvm::makeArrayRef(LS + 1, LS[0]);
Richard Smith509fc852015-02-27 23:05:10 +0000214
Richard Smithd8a83712015-08-22 01:47:18 +0000215 // Add a slot to the record for the number of specializations.
216 unsigned I = Record.size();
217 Record.push_back(0);
218
Richard Smith8ab0cfd2016-02-24 21:59:10 +0000219 // AddFirstDeclFromEachModule might trigger deserialization, invalidating
220 // *Specializations iterators.
221 llvm::SmallVector<const Decl*, 16> Specs;
222 for (auto &Entry : Common->Specializations)
223 Specs.push_back(getSpecializationDecl(Entry));
224 for (auto &Entry : getPartialSpecializations(Common))
225 Specs.push_back(getSpecializationDecl(Entry));
226
227 for (auto *D : Specs) {
Richard Smith509fc852015-02-27 23:05:10 +0000228 assert(D->isCanonicalDecl() && "non-canonical decl in set");
Richard Smithd8a83712015-08-22 01:47:18 +0000229 AddFirstDeclFromEachModule(D, /*IncludeLocal*/true);
Richard Smith509fc852015-02-27 23:05:10 +0000230 }
Benjamin Kramerf367dd92015-06-12 15:31:50 +0000231 Record.append(LazySpecializations.begin(), LazySpecializations.end());
Richard Smithd8a83712015-08-22 01:47:18 +0000232
233 // Update the size entry we added earlier.
234 Record[I] = Record.size() - I - 1;
235 }
236
237 /// Ensure that this template specialization is associated with the specified
238 /// template on reload.
239 void RegisterTemplateSpecialization(const Decl *Template,
240 const Decl *Specialization) {
241 Template = Template->getCanonicalDecl();
242
243 // If the canonical template is local, we'll write out this specialization
244 // when we emit it.
245 // FIXME: We can do the same thing if there is any local declaration of
246 // the template, to avoid emitting an update record.
247 if (!Template->isFromASTFile())
248 return;
249
250 // We only need to associate the first local declaration of the
251 // specialization. The other declarations will get pulled in by it.
252 if (Writer.getFirstLocalDecl(Specialization) != Specialization)
253 return;
254
255 Writer.DeclUpdates[Template].push_back(ASTWriter::DeclUpdate(
256 UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION, Specialization));
Richard Smith509fc852015-02-27 23:05:10 +0000257 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000258 };
Alexander Kornienkoab9db512015-06-22 23:07:51 +0000259}
Chris Lattner7099dbc2009-04-27 06:16:06 +0000260
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000261void ASTDeclWriter::Visit(Decl *D) {
262 DeclVisitor<ASTDeclWriter>::Visit(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000263
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000264 // Source locations require array (variable-length) abbreviations. The
265 // abbreviation infrastructure requires that arrays are encoded last, so
266 // we handle it here in the case of those classes derived from DeclaratorDecl
Nick Lewycky4b81fc872015-10-18 20:32:12 +0000267 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000268 Writer.AddTypeSourceInfo(DD->getTypeSourceInfo(), Record);
269 }
270
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000271 // Handle FunctionDecl's body here and write it after all other Stmts/Exprs
272 // have been written. We want it last because we will not read it back when
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000273 // retrieving it from the AST, we'll just lazily set the offset.
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000274 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
Alexis Hunt4a8ea102011-05-06 20:44:56 +0000275 Record.push_back(FD->doesThisDeclarationHaveABody());
276 if (FD->doesThisDeclarationHaveABody())
Richard Smithc2bb8182015-03-24 06:36:48 +0000277 AddFunctionDefinition(FD);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000278 }
279}
280
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000281void ASTDeclWriter::VisitDecl(Decl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000282 Writer.AddDeclRef(cast_or_null<Decl>(D->getDeclContext()), Record);
Richard Smith8aed4222015-12-11 22:41:00 +0000283 if (D->getDeclContext() != D->getLexicalDeclContext())
284 Writer.AddDeclRef(cast_or_null<Decl>(D->getLexicalDeclContext()), Record);
285 else
286 Record.push_back(0);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000287 Record.push_back(D->isInvalidDecl());
288 Record.push_back(D->hasAttrs());
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000289 if (D->hasAttrs())
Craig Topper8c2a2a02014-08-30 16:55:39 +0000290 Writer.WriteAttributes(llvm::makeArrayRef(D->getAttrs().begin(),
291 D->getAttrs().size()), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000292 Record.push_back(D->isImplicit());
Douglas Gregorebada0772010-06-17 23:14:26 +0000293 Record.push_back(D->isUsed(false));
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +0000294 Record.push_back(D->isReferenced());
Douglas Gregor781f7132012-01-06 16:59:53 +0000295 Record.push_back(D->isTopLevelDeclInObjCContainer());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000296 Record.push_back(D->getAccess());
Douglas Gregor781f7132012-01-06 16:59:53 +0000297 Record.push_back(D->isModulePrivate());
Douglas Gregora28bcdd2011-12-01 02:07:58 +0000298 Record.push_back(Writer.inferSubmoduleIDFromLocation(D->getLocation()));
Richard Smithc264d352014-03-23 02:30:01 +0000299
300 // If this declaration injected a name into a context different from its
301 // lexical context, and that context is an imported namespace, we need to
302 // update its visible declarations to include this name.
303 //
304 // This happens when we instantiate a class with a friend declaration or a
305 // function with a local extern declaration, for instance.
Richard Smith5fc18a92015-07-12 23:43:21 +0000306 //
307 // FIXME: Can we handle this in AddedVisibleDecl instead?
Richard Smithc264d352014-03-23 02:30:01 +0000308 if (D->isOutOfLine()) {
Richard Smithe3a97022014-03-23 20:41:56 +0000309 auto *DC = D->getDeclContext();
310 while (auto *NS = dyn_cast<NamespaceDecl>(DC->getRedeclContext())) {
311 if (!NS->isFromASTFile())
312 break;
Chandler Carruth8a3d24d2015-03-26 04:27:10 +0000313 Writer.UpdatedDeclContexts.insert(NS->getPrimaryContext());
Richard Smithe3a97022014-03-23 20:41:56 +0000314 if (!NS->isInlineNamespace())
315 break;
316 DC = NS->getParent();
317 }
Richard Smithc264d352014-03-23 02:30:01 +0000318 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000319}
320
Nico Weber66220292016-03-02 17:28:48 +0000321void ASTDeclWriter::VisitPragmaCommentDecl(PragmaCommentDecl *D) {
322 StringRef Arg = D->getArg();
323 Record.push_back(Arg.size());
324 VisitDecl(D);
325 Writer.AddSourceLocation(D->getLocStart(), Record);
326 Record.push_back(D->getCommentKind());
327 Writer.AddString(Arg, Record);
328 Code = serialization::DECL_PRAGMA_COMMENT;
329}
330
Nico Webercbbaeb12016-03-02 19:28:54 +0000331void ASTDeclWriter::VisitPragmaDetectMismatchDecl(
332 PragmaDetectMismatchDecl *D) {
333 StringRef Name = D->getName();
334 StringRef Value = D->getValue();
335 Record.push_back(Name.size() + 1 + Value.size());
336 VisitDecl(D);
337 Writer.AddSourceLocation(D->getLocStart(), Record);
338 Writer.AddString(Name, Record);
339 Writer.AddString(Value, Record);
340 Code = serialization::DECL_PRAGMA_DETECT_MISMATCH;
341}
342
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000343void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) {
Douglas Gregordab42432011-08-12 00:15:20 +0000344 llvm_unreachable("Translation units aren't directly serialized");
Chris Lattner7099dbc2009-04-27 06:16:06 +0000345}
346
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000347void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000348 VisitDecl(D);
349 Writer.AddDeclarationName(D->getDeclName(), Record);
Richard Smith2b560572015-02-07 03:11:11 +0000350 Record.push_back(needsAnonymousDeclarationNumber(D)
351 ? Writer.getAnonymousDeclarationNumber(D)
352 : 0);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000353}
354
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000355void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000356 VisitNamedDecl(D);
Abramo Bagnarab3185b02011-03-06 15:48:19 +0000357 Writer.AddSourceLocation(D->getLocStart(), Record);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000358 Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000359}
360
Douglas Gregor1f179062011-12-19 14:40:25 +0000361void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) {
Douglas Gregor05f10352011-12-17 23:38:30 +0000362 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000363 VisitTypeDecl(D);
Enea Zaffanellaa86d88c2013-06-20 12:46:19 +0000364 Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record);
365 Record.push_back(D->isModed());
366 if (D->isModed())
367 Writer.AddTypeRef(D->getUnderlyingType(), Record);
Douglas Gregor1f179062011-12-19 14:40:25 +0000368}
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000369
Douglas Gregor1f179062011-12-19 14:40:25 +0000370void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) {
371 VisitTypedefNameDecl(D);
Richard Smith8aed4222015-12-11 22:41:00 +0000372 if (D->getDeclContext() == D->getLexicalDeclContext() &&
373 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000374 !D->isImplicit() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000375 D->getFirstDecl() == D->getMostRecentDecl() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000376 !D->isInvalidDecl() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000377 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000378 !D->isModulePrivate() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000379 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000380 D->getDeclName().getNameKind() == DeclarationName::Identifier)
381 AbbrevToUse = Writer.getDeclTypedefAbbrev();
382
Sebastian Redl539c5062010-08-18 23:57:32 +0000383 Code = serialization::DECL_TYPEDEF;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000384}
385
Richard Smithdda56e42011-04-15 14:24:37 +0000386void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) {
Douglas Gregor1f179062011-12-19 14:40:25 +0000387 VisitTypedefNameDecl(D);
Richard Smith43ccec8e2014-08-26 03:52:16 +0000388 Writer.AddDeclRef(D->getDescribedAliasTemplate(), Record);
Richard Smithdda56e42011-04-15 14:24:37 +0000389 Code = serialization::DECL_TYPEALIAS;
390}
391
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000392void ASTDeclWriter::VisitTagDecl(TagDecl *D) {
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +0000393 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000394 VisitTypeDecl(D);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000395 Record.push_back(D->getIdentifierNamespace());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000396 Record.push_back((unsigned)D->getTagKind()); // FIXME: stable encoding
Richard Smith2c381642014-08-27 23:11:59 +0000397 if (!isa<CXXRecordDecl>(D))
398 Record.push_back(D->isCompleteDefinition());
Douglas Gregor5089c762010-02-12 17:40:34 +0000399 Record.push_back(D->isEmbeddedInDeclarator());
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +0000400 Record.push_back(D->isFreeStanding());
David Blaikiea8d23ce2013-07-14 01:07:41 +0000401 Record.push_back(D->isCompleteDefinitionRequired());
Argyrios Kyrtzidis664b6902009-07-14 03:18:02 +0000402 Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Richard Smith70d58502014-08-30 00:04:23 +0000403
404 if (D->hasExtInfo()) {
405 Record.push_back(1);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000406 Writer.AddQualifierInfo(*D->getExtInfo(), Record);
Richard Smith70d58502014-08-30 00:04:23 +0000407 } else if (auto *TD = D->getTypedefNameForAnonDecl()) {
408 Record.push_back(2);
409 Writer.AddDeclRef(TD, Record);
410 Writer.AddIdentifierRef(TD->getDeclName().getAsIdentifierInfo(), Record);
Richard Smith70d58502014-08-30 00:04:23 +0000411 } else {
412 Record.push_back(0);
413 }
Chris Lattner7099dbc2009-04-27 06:16:06 +0000414}
415
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000416void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000417 VisitTagDecl(D);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000418 Writer.AddTypeSourceInfo(D->getIntegerTypeSourceInfo(), Record);
419 if (!D->getIntegerTypeSourceInfo())
420 Writer.AddTypeRef(D->getIntegerType(), Record);
John McCall56774992009-12-09 09:09:27 +0000421 Writer.AddTypeRef(D->getPromotionType(), Record);
John McCall9aa35be2010-05-06 08:49:23 +0000422 Record.push_back(D->getNumPositiveBits());
423 Record.push_back(D->getNumNegativeBits());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000424 Record.push_back(D->isScoped());
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000425 Record.push_back(D->isScopedUsingClassTag());
Douglas Gregor0bf31402010-10-08 23:50:27 +0000426 Record.push_back(D->isFixed());
Richard Smith4b38ded2012-03-14 23:13:10 +0000427 if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
428 Writer.AddDeclRef(MemberInfo->getInstantiatedFrom(), Record);
429 Record.push_back(MemberInfo->getTemplateSpecializationKind());
430 Writer.AddSourceLocation(MemberInfo->getPointOfInstantiation(), Record);
431 } else {
Craig Toppera13603a2014-05-22 05:54:18 +0000432 Writer.AddDeclRef(nullptr, Record);
Richard Smith4b38ded2012-03-14 23:13:10 +0000433 }
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000434
Richard Smith8aed4222015-12-11 22:41:00 +0000435 if (D->getDeclContext() == D->getLexicalDeclContext() &&
436 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000437 !D->isImplicit() &&
438 !D->isUsed(false) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000439 !D->hasExtInfo() &&
Richard Smith70d58502014-08-30 00:04:23 +0000440 !D->getTypedefNameForAnonDecl() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000441 D->getFirstDecl() == D->getMostRecentDecl() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000442 !D->isInvalidDecl() &&
443 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000444 !D->isTopLevelDeclInObjCContainer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000445 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000446 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000447 !CXXRecordDecl::classofKind(D->getKind()) &&
448 !D->getIntegerTypeSourceInfo() &&
Argyrios Kyrtzidisca370b0d2013-03-18 22:23:49 +0000449 !D->getMemberSpecializationInfo() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000450 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000451 D->getDeclName().getNameKind() == DeclarationName::Identifier)
452 AbbrevToUse = Writer.getDeclEnumAbbrev();
453
Sebastian Redl539c5062010-08-18 23:57:32 +0000454 Code = serialization::DECL_ENUM;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000455}
456
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000457void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000458 VisitTagDecl(D);
459 Record.push_back(D->hasFlexibleArrayMember());
460 Record.push_back(D->isAnonymousStructOrUnion());
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000461 Record.push_back(D->hasObjectMember());
Fariborz Jahanian78652202013-01-25 23:57:05 +0000462 Record.push_back(D->hasVolatileMember());
Douglas Gregor03412ba2011-06-03 02:27:19 +0000463
Richard Smith8aed4222015-12-11 22:41:00 +0000464 if (D->getDeclContext() == D->getLexicalDeclContext() &&
465 !D->hasAttrs() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000466 !D->isImplicit() &&
467 !D->isUsed(false) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000468 !D->hasExtInfo() &&
Richard Smith70d58502014-08-30 00:04:23 +0000469 !D->getTypedefNameForAnonDecl() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000470 D->getFirstDecl() == D->getMostRecentDecl() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000471 !D->isInvalidDecl() &&
472 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000473 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000474 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000475 !D->isModulePrivate() &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000476 !CXXRecordDecl::classofKind(D->getKind()) &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000477 !needsAnonymousDeclarationNumber(D) &&
Douglas Gregor03412ba2011-06-03 02:27:19 +0000478 D->getDeclName().getNameKind() == DeclarationName::Identifier)
Douglas Gregor03412ba2011-06-03 02:27:19 +0000479 AbbrevToUse = Writer.getDeclRecordAbbrev();
480
Sebastian Redl539c5062010-08-18 23:57:32 +0000481 Code = serialization::DECL_RECORD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000482}
483
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000484void ASTDeclWriter::VisitValueDecl(ValueDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000485 VisitNamedDecl(D);
486 Writer.AddTypeRef(D->getType(), Record);
487}
488
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000489void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000490 VisitValueDecl(D);
491 Record.push_back(D->getInitExpr()? 1 : 0);
492 if (D->getInitExpr())
493 Writer.AddStmt(D->getInitExpr());
494 Writer.AddAPSInt(D->getInitVal(), Record);
Douglas Gregor03412ba2011-06-03 02:27:19 +0000495
Sebastian Redl539c5062010-08-18 23:57:32 +0000496 Code = serialization::DECL_ENUM_CONSTANT;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000497}
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000498
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000499void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000500 VisitValueDecl(D);
Abramo Bagnaradff19302011-03-08 08:55:46 +0000501 Writer.AddSourceLocation(D->getInnerLocStart(), Record);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000502 Record.push_back(D->hasExtInfo());
503 if (D->hasExtInfo())
504 Writer.AddQualifierInfo(*D->getExtInfo(), Record);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000505}
Chris Lattner7099dbc2009-04-27 06:16:06 +0000506
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000507void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000508 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000509 VisitDeclaratorDecl(D);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000510 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000511 Record.push_back(D->getIdentifierNamespace());
Douglas Gregorb2585692012-01-04 17:13:46 +0000512
513 // FunctionDecl's body is handled last at ASTWriterDecl::Visit,
514 // after everything else is written.
515
Richard Smith72625c22015-02-06 23:20:21 +0000516 Record.push_back((int)D->SClass); // FIXME: stable encoding
Douglas Gregorb2585692012-01-04 17:13:46 +0000517 Record.push_back(D->IsInline);
Richard Smith72625c22015-02-06 23:20:21 +0000518 Record.push_back(D->IsInlineSpecified);
519 Record.push_back(D->IsVirtualAsWritten);
520 Record.push_back(D->IsPure);
521 Record.push_back(D->HasInheritedPrototype);
522 Record.push_back(D->HasWrittenPrototype);
523 Record.push_back(D->IsDeleted);
524 Record.push_back(D->IsTrivial);
525 Record.push_back(D->IsDefaulted);
526 Record.push_back(D->IsExplicitlyDefaulted);
527 Record.push_back(D->HasImplicitReturnZero);
528 Record.push_back(D->IsConstexpr);
Argyrios Kyrtzidis1eb71a12012-12-06 18:59:10 +0000529 Record.push_back(D->HasSkippedBody);
Richard Smith72625c22015-02-06 23:20:21 +0000530 Record.push_back(D->IsLateTemplateParsed);
Rafael Espindola3ae00052013-05-13 00:12:11 +0000531 Record.push_back(D->getLinkageInternal());
Douglas Gregorb2585692012-01-04 17:13:46 +0000532 Writer.AddSourceLocation(D->getLocEnd(), Record);
533
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000534 Record.push_back(D->getTemplatedKind());
535 switch (D->getTemplatedKind()) {
536 case FunctionDecl::TK_NonTemplate:
537 break;
538 case FunctionDecl::TK_FunctionTemplate:
539 Writer.AddDeclRef(D->getDescribedFunctionTemplate(), Record);
540 break;
541 case FunctionDecl::TK_MemberSpecialization: {
542 MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo();
543 Writer.AddDeclRef(MemberInfo->getInstantiatedFrom(), Record);
544 Record.push_back(MemberInfo->getTemplateSpecializationKind());
545 Writer.AddSourceLocation(MemberInfo->getPointOfInstantiation(), Record);
546 break;
547 }
548 case FunctionDecl::TK_FunctionTemplateSpecialization: {
549 FunctionTemplateSpecializationInfo *
550 FTSInfo = D->getTemplateSpecializationInfo();
Richard Smithd8a83712015-08-22 01:47:18 +0000551
552 RegisterTemplateSpecialization(FTSInfo->getTemplate(), D);
553
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000554 Writer.AddDeclRef(FTSInfo->getTemplate(), Record);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000555 Record.push_back(FTSInfo->getTemplateSpecializationKind());
556
557 // Template arguments.
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +0000558 Writer.AddTemplateArgumentList(FTSInfo->TemplateArguments, Record);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000559
560 // Template args as written.
Craig Toppera13603a2014-05-22 05:54:18 +0000561 Record.push_back(FTSInfo->TemplateArgumentsAsWritten != nullptr);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000562 if (FTSInfo->TemplateArgumentsAsWritten) {
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000563 Record.push_back(FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs);
564 for (int i=0, e = FTSInfo->TemplateArgumentsAsWritten->NumTemplateArgs;
565 i!=e; ++i)
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000566 Writer.AddTemplateArgumentLoc((*FTSInfo->TemplateArgumentsAsWritten)[i],
567 Record);
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000568 Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->LAngleLoc,
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000569 Record);
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000570 Writer.AddSourceLocation(FTSInfo->TemplateArgumentsAsWritten->RAngleLoc,
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000571 Record);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000572 }
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000573
574 Writer.AddSourceLocation(FTSInfo->getPointOfInstantiation(), Record);
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000575
576 if (D->isCanonicalDecl()) {
577 // Write the template that contains the specializations set. We will
578 // add a FunctionTemplateSpecializationInfo to it when reading.
579 Writer.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl(), Record);
580 }
Argyrios Kyrtzidisdc9ca0a2010-06-25 16:24:51 +0000581 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000582 }
583 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
584 DependentFunctionTemplateSpecializationInfo *
585 DFTSInfo = D->getDependentSpecializationInfo();
586
587 // Templates.
588 Record.push_back(DFTSInfo->getNumTemplates());
589 for (int i=0, e = DFTSInfo->getNumTemplates(); i != e; ++i)
590 Writer.AddDeclRef(DFTSInfo->getTemplate(i), Record);
591
592 // Templates args.
593 Record.push_back(DFTSInfo->getNumTemplateArgs());
594 for (int i=0, e = DFTSInfo->getNumTemplateArgs(); i != e; ++i)
595 Writer.AddTemplateArgumentLoc(DFTSInfo->getTemplateArg(i), Record);
Argyrios Kyrtzidis927d8e02010-07-05 10:37:55 +0000596 Writer.AddSourceLocation(DFTSInfo->getLAngleLoc(), Record);
597 Writer.AddSourceLocation(DFTSInfo->getRAngleLoc(), Record);
Argyrios Kyrtzidisdc9ca0a2010-06-25 16:24:51 +0000598 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000599 }
600 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000601
Chris Lattner7099dbc2009-04-27 06:16:06 +0000602 Record.push_back(D->param_size());
Aaron Ballmanf6bf62e2014-03-07 15:12:56 +0000603 for (auto P : D->params())
604 Writer.AddDeclRef(P, Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000605 Code = serialization::DECL_FUNCTION;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000606}
607
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000608void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000609 VisitNamedDecl(D);
610 // FIXME: convert to LazyStmtPtr?
Mike Stump11289f42009-09-09 15:08:12 +0000611 // Unlike C/C++, method bodies will never be in header files.
Craig Toppera13603a2014-05-22 05:54:18 +0000612 bool HasBodyStuff = D->getBody() != nullptr ||
613 D->getSelfDecl() != nullptr || D->getCmdDecl() != nullptr;
Argyrios Kyrtzidisa8607772010-08-09 10:54:37 +0000614 Record.push_back(HasBodyStuff);
615 if (HasBodyStuff) {
Argyrios Kyrtzidisddcd1322009-06-30 02:35:26 +0000616 Writer.AddStmt(D->getBody());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000617 Writer.AddDeclRef(D->getSelfDecl(), Record);
618 Writer.AddDeclRef(D->getCmdDecl(), Record);
619 }
620 Record.push_back(D->isInstanceMethod());
621 Record.push_back(D->isVariadic());
Jordan Rosed01e83a2012-10-10 16:42:25 +0000622 Record.push_back(D->isPropertyAccessor());
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000623 Record.push_back(D->isDefined());
Argyrios Kyrtzidis08f96a92012-05-09 16:12:57 +0000624 Record.push_back(D->IsOverriding);
Argyrios Kyrtzidis1eb71a12012-12-06 18:59:10 +0000625 Record.push_back(D->HasSkippedBody);
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000626
627 Record.push_back(D->IsRedeclaration);
628 Record.push_back(D->HasRedeclaration);
629 if (D->HasRedeclaration) {
630 assert(Context.getObjCMethodRedeclaration(D));
631 Writer.AddDeclRef(Context.getObjCMethodRedeclaration(D), Record);
632 }
633
Chris Lattner7099dbc2009-04-27 06:16:06 +0000634 // FIXME: stable encoding for @required/@optional
Mike Stump11289f42009-09-09 15:08:12 +0000635 Record.push_back(D->getImplementationControl());
Douglas Gregor813a0662015-06-19 18:14:38 +0000636 // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway/nullability
Mike Stump11289f42009-09-09 15:08:12 +0000637 Record.push_back(D->getObjCDeclQualifier());
Douglas Gregor33823722011-06-11 01:09:30 +0000638 Record.push_back(D->hasRelatedResultType());
Alp Toker314cc812014-01-25 16:55:45 +0000639 Writer.AddTypeRef(D->getReturnType(), Record);
640 Writer.AddTypeSourceInfo(D->getReturnTypeSourceInfo(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000641 Writer.AddSourceLocation(D->getLocEnd(), Record);
642 Record.push_back(D->param_size());
Aaron Ballman43b68be2014-03-07 17:50:17 +0000643 for (const auto *P : D->params())
644 Writer.AddDeclRef(P, Record);
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000645
646 Record.push_back(D->SelLocsKind);
647 unsigned NumStoredSelLocs = D->getNumStoredSelLocs();
648 SourceLocation *SelLocs = D->getStoredSelLocs();
649 Record.push_back(NumStoredSelLocs);
650 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
651 Writer.AddSourceLocation(SelLocs[i], Record);
652
Sebastian Redl539c5062010-08-18 23:57:32 +0000653 Code = serialization::DECL_OBJC_METHOD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000654}
655
Douglas Gregor85f3f952015-07-07 03:57:15 +0000656void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
657 VisitTypedefNameDecl(D);
Douglas Gregor1ac1b632015-07-07 03:58:54 +0000658 Record.push_back(D->Variance);
Douglas Gregore83b9562015-07-07 03:57:53 +0000659 Record.push_back(D->Index);
Douglas Gregor1ac1b632015-07-07 03:58:54 +0000660 Writer.AddSourceLocation(D->VarianceLoc, Record);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000661 Writer.AddSourceLocation(D->ColonLoc, Record);
662
663 Code = serialization::DECL_OBJC_TYPE_PARAM;
664}
665
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000666void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000667 VisitNamedDecl(D);
Argyrios Kyrtzidis52f53fb2011-10-04 04:48:02 +0000668 Writer.AddSourceLocation(D->getAtStartLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +0000669 Writer.AddSourceRange(D->getAtEndRange(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000670 // Abstract class (no need to define a stable serialization::DECL code).
Chris Lattner7099dbc2009-04-27 06:16:06 +0000671}
672
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000673void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) {
Douglas Gregor66b310c2011-12-15 18:03:09 +0000674 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000675 VisitObjCContainerDecl(D);
676 Writer.AddTypeRef(QualType(D->getTypeForDecl(), 0), Record);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000677 AddObjCTypeParamList(D->TypeParamList);
Ted Kremenek0ef508d2010-09-01 01:21:15 +0000678
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000679 Record.push_back(D->isThisDeclarationADefinition());
680 if (D->isThisDeclarationADefinition()) {
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000681 // Write the DefinitionData
682 ObjCInterfaceDecl::DefinitionData &Data = D->data();
683
Douglas Gregore9d95f12015-07-07 03:57:35 +0000684 Writer.AddTypeSourceInfo(D->getSuperClassTInfo(), Record);
Douglas Gregor16408322011-12-15 22:34:59 +0000685 Writer.AddSourceLocation(D->getEndOfDefinitionLoc(), Record);
Argyrios Kyrtzidis9ed9e5f2013-12-03 21:11:30 +0000686 Record.push_back(Data.HasDesignatedInitializers);
Douglas Gregor16408322011-12-15 22:34:59 +0000687
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000688 // Write out the protocols that are directly referenced by the @interface.
689 Record.push_back(Data.ReferencedProtocols.size());
Aaron Ballmana49c5062014-03-13 20:29:09 +0000690 for (const auto *P : D->protocols())
691 Writer.AddDeclRef(P, Record);
Aaron Ballmane9378882014-03-13 20:34:24 +0000692 for (const auto &PL : D->protocol_locs())
693 Writer.AddSourceLocation(PL, Record);
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000694
695 // Write out the protocols that are transitively referenced.
696 Record.push_back(Data.AllReferencedProtocols.size());
697 for (ObjCList<ObjCProtocolDecl>::iterator
698 P = Data.AllReferencedProtocols.begin(),
699 PEnd = Data.AllReferencedProtocols.end();
700 P != PEnd; ++P)
701 Writer.AddDeclRef(*P, Record);
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000702
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000703
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000704 if (ObjCCategoryDecl *Cat = D->getCategoryListRaw()) {
Douglas Gregor404cdde2012-01-27 01:47:08 +0000705 // Ensure that we write out the set of categories for this class.
706 Writer.ObjCClassesWithCategories.insert(D);
707
708 // Make sure that the categories get serialized.
Douglas Gregor048fbfa2013-01-16 23:00:23 +0000709 for (; Cat; Cat = Cat->getNextClassCategoryRaw())
Douglas Gregor404cdde2012-01-27 01:47:08 +0000710 (void)Writer.GetDeclRef(Cat);
711 }
Douglas Gregorc0ac7d62011-12-15 05:27:12 +0000712 }
713
Sebastian Redl539c5062010-08-18 23:57:32 +0000714 Code = serialization::DECL_OBJC_INTERFACE;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000715}
716
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000717void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000718 VisitFieldDecl(D);
719 // FIXME: stable encoding for @public/@private/@protected/@package
Mike Stump11289f42009-09-09 15:08:12 +0000720 Record.push_back(D->getAccessControl());
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +0000721 Record.push_back(D->getSynthesize());
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000722
Richard Smith8aed4222015-12-11 22:41:00 +0000723 if (D->getDeclContext() == D->getLexicalDeclContext() &&
724 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000725 !D->isImplicit() &&
726 !D->isUsed(false) &&
727 !D->isInvalidDecl() &&
728 !D->isReferenced() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000729 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000730 !D->getBitWidth() &&
731 !D->hasExtInfo() &&
732 D->getDeclName())
733 AbbrevToUse = Writer.getDeclObjCIvarAbbrev();
734
Sebastian Redl539c5062010-08-18 23:57:32 +0000735 Code = serialization::DECL_OBJC_IVAR;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000736}
737
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000738void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) {
Douglas Gregora715bff2012-01-01 19:51:50 +0000739 VisitRedeclarable(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000740 VisitObjCContainerDecl(D);
Douglas Gregore6e48b12012-01-01 19:29:29 +0000741
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000742 Record.push_back(D->isThisDeclarationADefinition());
743 if (D->isThisDeclarationADefinition()) {
Douglas Gregore6e48b12012-01-01 19:29:29 +0000744 Record.push_back(D->protocol_size());
Aaron Ballman0f6e64d2014-03-13 22:58:06 +0000745 for (const auto *I : D->protocols())
746 Writer.AddDeclRef(I, Record);
Aaron Ballmana964ec12014-03-14 12:38:50 +0000747 for (const auto &PL : D->protocol_locs())
748 Writer.AddSourceLocation(PL, Record);
Douglas Gregore6e48b12012-01-01 19:29:29 +0000749 }
750
Sebastian Redl539c5062010-08-18 23:57:32 +0000751 Code = serialization::DECL_OBJC_PROTOCOL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000752}
753
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000754void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000755 VisitFieldDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000756 Code = serialization::DECL_OBJC_AT_DEFS_FIELD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000757}
758
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000759void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000760 VisitObjCContainerDecl(D);
Douglas Gregor404cdde2012-01-27 01:47:08 +0000761 Writer.AddSourceLocation(D->getCategoryNameLoc(), Record);
Fariborz Jahaniana7765fe2012-02-20 20:09:20 +0000762 Writer.AddSourceLocation(D->getIvarLBraceLoc(), Record);
763 Writer.AddSourceLocation(D->getIvarRBraceLoc(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000764 Writer.AddDeclRef(D->getClassInterface(), Record);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000765 AddObjCTypeParamList(D->TypeParamList);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000766 Record.push_back(D->protocol_size());
Aaron Ballman19a41762014-03-14 12:55:57 +0000767 for (const auto *I : D->protocols())
768 Writer.AddDeclRef(I, Record);
Aaron Ballmana73c8572014-03-14 13:03:32 +0000769 for (const auto &PL : D->protocol_locs())
770 Writer.AddSourceLocation(PL, Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000771 Code = serialization::DECL_OBJC_CATEGORY;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000772}
773
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000774void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000775 VisitNamedDecl(D);
776 Writer.AddDeclRef(D->getClassInterface(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000777 Code = serialization::DECL_OBJC_COMPATIBLE_ALIAS;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000778}
779
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000780void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000781 VisitNamedDecl(D);
Fariborz Jahanianda8ec2b2010-01-21 17:36:00 +0000782 Writer.AddSourceLocation(D->getAtLoc(), Record);
Fariborz Jahanian86c2f5c2012-02-29 22:18:55 +0000783 Writer.AddSourceLocation(D->getLParenLoc(), Record);
Douglas Gregor813a0662015-06-19 18:14:38 +0000784 Writer.AddTypeRef(D->getType(), Record);
John McCall339bb662010-06-04 20:50:08 +0000785 Writer.AddTypeSourceInfo(D->getTypeSourceInfo(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000786 // FIXME: stable encoding
787 Record.push_back((unsigned)D->getPropertyAttributes());
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +0000788 Record.push_back((unsigned)D->getPropertyAttributesAsWritten());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000789 // FIXME: stable encoding
790 Record.push_back((unsigned)D->getPropertyImplementation());
791 Writer.AddDeclarationName(D->getGetterName(), Record);
792 Writer.AddDeclarationName(D->getSetterName(), Record);
793 Writer.AddDeclRef(D->getGetterMethodDecl(), Record);
794 Writer.AddDeclRef(D->getSetterMethodDecl(), Record);
795 Writer.AddDeclRef(D->getPropertyIvarDecl(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000796 Code = serialization::DECL_OBJC_PROPERTY;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000797}
798
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000799void ASTDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +0000800 VisitObjCContainerDecl(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000801 Writer.AddDeclRef(D->getClassInterface(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000802 // Abstract class (no need to define a stable serialization::DECL code).
Chris Lattner7099dbc2009-04-27 06:16:06 +0000803}
804
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000805void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000806 VisitObjCImplDecl(D);
807 Writer.AddIdentifierRef(D->getIdentifier(), Record);
Argyrios Kyrtzidis4996f5f2011-12-09 00:31:40 +0000808 Writer.AddSourceLocation(D->getCategoryNameLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000809 Code = serialization::DECL_OBJC_CATEGORY_IMPL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000810}
811
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000812void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000813 VisitObjCImplDecl(D);
814 Writer.AddDeclRef(D->getSuperClass(), Record);
Argyrios Kyrtzidis5d2ce842013-05-03 22:31:26 +0000815 Writer.AddSourceLocation(D->getSuperClassLoc(), Record);
Fariborz Jahaniana7765fe2012-02-20 20:09:20 +0000816 Writer.AddSourceLocation(D->getIvarLBraceLoc(), Record);
817 Writer.AddSourceLocation(D->getIvarRBraceLoc(), Record);
John McCall0d54a172012-10-17 04:53:31 +0000818 Record.push_back(D->hasNonZeroConstructors());
819 Record.push_back(D->hasDestructors());
Richard Smithc2bb8182015-03-24 06:36:48 +0000820 Record.push_back(D->NumIvarInitializers);
821 if (D->NumIvarInitializers)
822 Writer.AddCXXCtorInitializersRef(
823 llvm::makeArrayRef(D->init_begin(), D->init_end()), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +0000824 Code = serialization::DECL_OBJC_IMPLEMENTATION;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000825}
826
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000827void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000828 VisitDecl(D);
829 Writer.AddSourceLocation(D->getLocStart(), Record);
830 Writer.AddDeclRef(D->getPropertyDecl(), Record);
831 Writer.AddDeclRef(D->getPropertyIvarDecl(), Record);
Douglas Gregorb1b71e52010-11-17 01:03:52 +0000832 Writer.AddSourceLocation(D->getPropertyIvarDeclLoc(), Record);
Argyrios Kyrtzidisa8607772010-08-09 10:54:37 +0000833 Writer.AddStmt(D->getGetterCXXConstructor());
834 Writer.AddStmt(D->getSetterCXXAssignment());
Sebastian Redl539c5062010-08-18 23:57:32 +0000835 Code = serialization::DECL_OBJC_PROPERTY_IMPL;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000836}
837
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000838void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000839 VisitDeclaratorDecl(D);
Chris Lattner7099dbc2009-04-27 06:16:06 +0000840 Record.push_back(D->isMutable());
John McCallc90c1492014-10-10 18:44:34 +0000841 if (D->InitStorage.getInt() == FieldDecl::ISK_BitWidthOrNothing &&
842 D->InitStorage.getPointer() == nullptr) {
843 Record.push_back(0);
844 } else if (D->InitStorage.getInt() == FieldDecl::ISK_CapturedVLAType) {
845 Record.push_back(D->InitStorage.getInt() + 1);
Alexey Bataev39c81e22014-08-28 04:28:19 +0000846 Writer.AddTypeRef(
John McCallc90c1492014-10-10 18:44:34 +0000847 QualType(static_cast<Type *>(D->InitStorage.getPointer()), 0),
Alexey Bataev39c81e22014-08-28 04:28:19 +0000848 Record);
Richard Smith2b013182012-06-10 03:12:00 +0000849 } else {
John McCallc90c1492014-10-10 18:44:34 +0000850 Record.push_back(D->InitStorage.getInt() + 1);
851 Writer.AddStmt(static_cast<Expr *>(D->InitStorage.getPointer()));
Richard Smith2b013182012-06-10 03:12:00 +0000852 }
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +0000853 if (!D->getDeclName())
854 Writer.AddDeclRef(Context.getInstantiatedFromUnnamedFieldDecl(D), Record);
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000855
Richard Smith8aed4222015-12-11 22:41:00 +0000856 if (D->getDeclContext() == D->getLexicalDeclContext() &&
857 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000858 !D->isImplicit() &&
859 !D->isUsed(false) &&
860 !D->isInvalidDecl() &&
861 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000862 !D->isTopLevelDeclInObjCContainer() &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000863 !D->isModulePrivate() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000864 !D->getBitWidth() &&
Richard Smith938f40b2011-06-11 17:19:42 +0000865 !D->hasInClassInitializer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000866 !D->hasExtInfo() &&
867 !ObjCIvarDecl::classofKind(D->getKind()) &&
868 !ObjCAtDefsFieldDecl::classofKind(D->getKind()) &&
869 D->getDeclName())
870 AbbrevToUse = Writer.getDeclFieldAbbrev();
871
Sebastian Redl539c5062010-08-18 23:57:32 +0000872 Code = serialization::DECL_FIELD;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000873}
874
John McCall5e77d762013-04-16 07:28:30 +0000875void ASTDeclWriter::VisitMSPropertyDecl(MSPropertyDecl *D) {
876 VisitDeclaratorDecl(D);
877 Writer.AddIdentifierRef(D->getGetterId(), Record);
878 Writer.AddIdentifierRef(D->getSetterId(), Record);
879 Code = serialization::DECL_MS_PROPERTY;
880}
881
Francois Pichet783dd6e2010-11-21 06:08:52 +0000882void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) {
883 VisitValueDecl(D);
884 Record.push_back(D->getChainingSize());
885
Aaron Ballman29c94602014-03-07 18:36:15 +0000886 for (const auto *P : D->chain())
Aaron Ballman13916082014-03-07 18:11:58 +0000887 Writer.AddDeclRef(P, Record);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000888 Code = serialization::DECL_INDIRECTFIELD;
889}
890
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000891void ASTDeclWriter::VisitVarDecl(VarDecl *D) {
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000892 VisitRedeclarable(D);
Douglas Gregor3e300102011-10-26 17:53:41 +0000893 VisitDeclaratorDecl(D);
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000894 Record.push_back(D->getStorageClass());
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +0000895 Record.push_back(D->getTSCSpec());
Sebastian Redla9351792012-02-11 23:51:47 +0000896 Record.push_back(D->getInitStyle());
David Majnemerfa7bc782015-05-19 00:57:16 +0000897 if (!isa<ParmVarDecl>(D)) {
898 Record.push_back(D->isExceptionVariable());
899 Record.push_back(D->isNRVOVariable());
900 Record.push_back(D->isCXXForRangeDecl());
901 Record.push_back(D->isARCPseudoStrong());
902 Record.push_back(D->isConstexpr());
903 Record.push_back(D->isInitCapture());
904 Record.push_back(D->isPreviousDeclInSameBlockScope());
905 }
Rafael Espindola3ae00052013-05-13 00:12:11 +0000906 Record.push_back(D->getLinkageInternal());
Douglas Gregor12cda632012-09-20 23:43:29 +0000907
Richard Smithd0b4dd62011-12-19 06:19:21 +0000908 if (D->getInit()) {
909 Record.push_back(!D->isInitKnownICE() ? 1 : (D->isInitICE() ? 3 : 2));
Chris Lattner7099dbc2009-04-27 06:16:06 +0000910 Writer.AddStmt(D->getInit());
Richard Smithd0b4dd62011-12-19 06:19:21 +0000911 } else {
912 Record.push_back(0);
913 }
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000914
915 enum {
916 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
917 };
918 if (VarTemplateDecl *TemplD = D->getDescribedVarTemplate()) {
919 Record.push_back(VarTemplate);
920 Writer.AddDeclRef(TemplD, Record);
921 } else if (MemberSpecializationInfo *SpecInfo
922 = D->getMemberSpecializationInfo()) {
923 Record.push_back(StaticDataMemberSpecialization);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000924 Writer.AddDeclRef(SpecInfo->getInstantiatedFrom(), Record);
925 Record.push_back(SpecInfo->getTemplateSpecializationKind());
926 Writer.AddSourceLocation(SpecInfo->getPointOfInstantiation(), Record);
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000927 } else {
928 Record.push_back(VarNotTemplate);
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +0000929 }
930
Richard Smith8aed4222015-12-11 22:41:00 +0000931 if (D->getDeclContext() == D->getLexicalDeclContext() &&
932 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000933 !D->isImplicit() &&
934 !D->isUsed(false) &&
935 !D->isInvalidDecl() &&
936 !D->isReferenced() &&
Argyrios Kyrtzidisa7245002011-11-23 21:11:23 +0000937 !D->isTopLevelDeclInObjCContainer() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000938 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000939 !D->isModulePrivate() &&
Richard Smithd08aeb62014-08-28 01:33:39 +0000940 !needsAnonymousDeclarationNumber(D) &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000941 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
942 !D->hasExtInfo() &&
Rafael Espindola8db352d2013-10-17 15:37:26 +0000943 D->getFirstDecl() == D->getMostRecentDecl() &&
Sebastian Redla9351792012-02-11 23:51:47 +0000944 D->getInitStyle() == VarDecl::CInit &&
Craig Toppera13603a2014-05-22 05:54:18 +0000945 D->getInit() == nullptr &&
John McCalld4631322011-06-17 06:42:21 +0000946 !isa<ParmVarDecl>(D) &&
Larisse Voufoa11bd8a2013-08-13 02:02:26 +0000947 !isa<VarTemplateSpecializationDecl>(D) &&
Douglas Gregor12cda632012-09-20 23:43:29 +0000948 !D->isConstexpr() &&
Richard Smithbb13c9a2013-09-28 04:02:39 +0000949 !D->isInitCapture() &&
Richard Smith1c34fb72013-08-13 18:18:50 +0000950 !D->isPreviousDeclInSameBlockScope() &&
Larisse Voufod8dd97c2013-08-14 03:09:19 +0000951 !D->getMemberSpecializationInfo())
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000952 AbbrevToUse = Writer.getDeclVarAbbrev();
953
Sebastian Redl539c5062010-08-18 23:57:32 +0000954 Code = serialization::DECL_VAR;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000955}
956
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000957void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000958 VisitVarDecl(D);
Sebastian Redl539c5062010-08-18 23:57:32 +0000959 Code = serialization::DECL_IMPLICIT_PARAM;
Chris Lattner7099dbc2009-04-27 06:16:06 +0000960}
961
Sebastian Redl42a0f6a2010-08-18 23:56:27 +0000962void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +0000963 VisitVarDecl(D);
John McCall82490832011-05-02 00:30:12 +0000964 Record.push_back(D->isObjCMethodParameter());
John McCall8fb0d9d2011-05-01 22:35:37 +0000965 Record.push_back(D->getFunctionScopeDepth());
966 Record.push_back(D->getFunctionScopeIndex());
Chris Lattner7099dbc2009-04-27 06:16:06 +0000967 Record.push_back(D->getObjCDeclQualifier()); // FIXME: stable encoding
John McCall6a014d52011-03-09 04:22:44 +0000968 Record.push_back(D->isKNRPromoted());
John McCallf3cd6652010-03-12 18:31:32 +0000969 Record.push_back(D->hasInheritedDefaultArg());
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000970 Record.push_back(D->hasUninstantiatedDefaultArg());
971 if (D->hasUninstantiatedDefaultArg())
972 Writer.AddStmt(D->getUninstantiatedDefaultArg());
Sebastian Redl539c5062010-08-18 23:57:32 +0000973 Code = serialization::DECL_PARM_VAR;
Mike Stump11289f42009-09-09 15:08:12 +0000974
John McCalld4631322011-06-17 06:42:21 +0000975 assert(!D->isARCPseudoStrong()); // can be true of ImplicitParamDecl
976
Chris Lattner258172e2009-04-27 07:35:58 +0000977 // If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here
978 // we dynamically check for the properties that we optimize for, but don't
979 // know are true of all PARM_VAR_DECLs.
Richard Smith8aed4222015-12-11 22:41:00 +0000980 if (D->getDeclContext() == D->getLexicalDeclContext() &&
981 !D->hasAttrs() &&
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000982 !D->hasExtInfo() &&
Chris Lattner258172e2009-04-27 07:35:58 +0000983 !D->isImplicit() &&
Douglas Gregorebada0772010-06-17 23:14:26 +0000984 !D->isUsed(false) &&
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +0000985 !D->isInvalidDecl() &&
Eli Friedmanc09e0552012-01-13 23:41:25 +0000986 !D->isReferenced() &&
Chris Lattner258172e2009-04-27 07:35:58 +0000987 D->getAccess() == AS_none &&
Douglas Gregor26701a42011-09-09 02:06:17 +0000988 !D->isModulePrivate() &&
Chris Lattner258172e2009-04-27 07:35:58 +0000989 D->getStorageClass() == 0 &&
Sebastian Redla9351792012-02-11 23:51:47 +0000990 D->getInitStyle() == VarDecl::CInit && // Can params have anything else?
John McCall82490832011-05-02 00:30:12 +0000991 D->getFunctionScopeDepth() == 0 &&
John McCallf3cd6652010-03-12 18:31:32 +0000992 D->getObjCDeclQualifier() == 0 &&
John McCall6a014d52011-03-09 04:22:44 +0000993 !D->isKNRPromoted() &&
Chris Lattnere2437f42010-05-09 06:40:08 +0000994 !D->hasInheritedDefaultArg() &&
Craig Toppera13603a2014-05-22 05:54:18 +0000995 D->getInit() == nullptr &&
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +0000996 !D->hasUninstantiatedDefaultArg()) // No default expr.
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000997 AbbrevToUse = Writer.getDeclParmVarAbbrev();
Chris Lattner258172e2009-04-27 07:35:58 +0000998
999 // Check things we know are true of *every* PARM_VAR_DECL, which is more than
1000 // just us assuming it.
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +00001001 assert(!D->getTSCSpec() && "PARM_VAR_DECL can't use TLS");
Chris Lattner258172e2009-04-27 07:35:58 +00001002 assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private");
Douglas Gregor3f324d562010-05-03 18:51:14 +00001003 assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var");
Craig Toppera13603a2014-05-22 05:54:18 +00001004 assert(D->getPreviousDecl() == nullptr && "PARM_VAR_DECL can't be redecl");
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001005 assert(!D->isStaticDataMember() &&
1006 "PARM_VAR_DECL can't be static data member");
Chris Lattner7099dbc2009-04-27 06:16:06 +00001007}
1008
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001009void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001010 VisitDecl(D);
1011 Writer.AddStmt(D->getAsmString());
Abramo Bagnara348823a2011-03-03 14:20:18 +00001012 Writer.AddSourceLocation(D->getRParenLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001013 Code = serialization::DECL_FILE_SCOPE_ASM;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001014}
1015
Michael Han84324352013-02-22 17:15:32 +00001016void ASTDeclWriter::VisitEmptyDecl(EmptyDecl *D) {
1017 VisitDecl(D);
1018 Code = serialization::DECL_EMPTY;
1019}
1020
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001021void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) {
Chris Lattner7099dbc2009-04-27 06:16:06 +00001022 VisitDecl(D);
1023 Writer.AddStmt(D->getBody());
John McCalla3ccba02010-06-04 11:21:44 +00001024 Writer.AddTypeSourceInfo(D->getSignatureAsWritten(), Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +00001025 Record.push_back(D->param_size());
1026 for (FunctionDecl::param_iterator P = D->param_begin(), PEnd = D->param_end();
1027 P != PEnd; ++P)
1028 Writer.AddDeclRef(*P, Record);
John McCallcf6ce282012-04-13 17:33:29 +00001029 Record.push_back(D->isVariadic());
1030 Record.push_back(D->blockMissingReturnType());
1031 Record.push_back(D->isConversionFromLambda());
John McCallc63de662011-02-02 13:00:07 +00001032 Record.push_back(D->capturesCXXThis());
John McCall351762c2011-02-07 10:33:21 +00001033 Record.push_back(D->getNumCaptures());
Aaron Ballman9371dd22014-03-14 18:34:04 +00001034 for (const auto &capture : D->captures()) {
John McCall351762c2011-02-07 10:33:21 +00001035 Writer.AddDeclRef(capture.getVariable(), Record);
1036
1037 unsigned flags = 0;
1038 if (capture.isByRef()) flags |= 1;
1039 if (capture.isNested()) flags |= 2;
1040 if (capture.hasCopyExpr()) flags |= 4;
1041 Record.push_back(flags);
1042
1043 if (capture.hasCopyExpr()) Writer.AddStmt(capture.getCopyExpr());
1044 }
John McCallc63de662011-02-02 13:00:07 +00001045
Sebastian Redl539c5062010-08-18 23:57:32 +00001046 Code = serialization::DECL_BLOCK;
Chris Lattner7099dbc2009-04-27 06:16:06 +00001047}
1048
Ben Langmuirce914fc2013-05-03 19:20:19 +00001049void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) {
1050 Record.push_back(CD->getNumParams());
1051 VisitDecl(CD);
Alexey Bataev9959db52014-05-06 10:08:46 +00001052 Record.push_back(CD->getContextParamPosition());
1053 Record.push_back(CD->isNothrow() ? 1 : 0);
Ben Langmuirce914fc2013-05-03 19:20:19 +00001054 // Body is stored by VisitCapturedStmt.
Alexey Bataev9959db52014-05-06 10:08:46 +00001055 for (unsigned I = 0; I < CD->getNumParams(); ++I)
1056 Writer.AddDeclRef(CD->getParam(I), Record);
Ben Langmuirce914fc2013-05-03 19:20:19 +00001057 Code = serialization::DECL_CAPTURED;
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001058}
1059
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001060void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001061 VisitDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001062 Record.push_back(D->getLanguage());
Abramo Bagnaraea947882011-03-08 16:41:52 +00001063 Writer.AddSourceLocation(D->getExternLoc(), Record);
Abramo Bagnara4a8cda82011-03-03 14:52:38 +00001064 Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001065 Code = serialization::DECL_LINKAGE_SPEC;
Chris Lattnerca025db2010-05-07 21:43:38 +00001066}
1067
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001068void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) {
1069 VisitNamedDecl(D);
Abramo Bagnara1c3af962011-03-05 18:21:20 +00001070 Writer.AddSourceLocation(D->getLocStart(), Record);
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001071 Code = serialization::DECL_LABEL;
1072}
1073
1074
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001075void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) {
Douglas Gregore57e7522012-01-07 09:11:48 +00001076 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001077 VisitNamedDecl(D);
Douglas Gregor44e5c1f2010-10-05 20:41:58 +00001078 Record.push_back(D->isInline());
Abramo Bagnarab5545be2011-03-08 12:38:20 +00001079 Writer.AddSourceLocation(D->getLocStart(), Record);
1080 Writer.AddSourceLocation(D->getRBraceLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001081
Chris Lattnerca025db2010-05-07 21:43:38 +00001082 if (D->isOriginalNamespace())
1083 Writer.AddDeclRef(D->getAnonymousNamespace(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001084 Code = serialization::DECL_NAMESPACE;
Sebastian Redlf03cdc52010-08-05 21:22:19 +00001085
Douglas Gregore57e7522012-01-07 09:11:48 +00001086 if (Writer.hasChain() && D->isAnonymousNamespace() &&
Douglas Gregorec9fd132012-01-14 16:38:05 +00001087 D == D->getMostRecentDecl()) {
Sebastian Redl010288f2011-04-24 16:28:21 +00001088 // This is a most recent reopening of the anonymous namespace. If its parent
1089 // is in a previous PCH (or is the TU), mark that parent for update, because
1090 // the original namespace always points to the latest re-opening of its
1091 // anonymous namespace.
1092 Decl *Parent = cast<Decl>(
1093 D->getParent()->getRedeclContext()->getPrimaryContext());
Douglas Gregorb3722e22011-09-09 23:01:35 +00001094 if (Parent->isFromASTFile() || isa<TranslationUnitDecl>(Parent)) {
Richard Smith6ef42932014-03-20 21:02:00 +00001095 Writer.DeclUpdates[Parent].push_back(
Aaron Ballman4f45b712014-03-21 15:22:56 +00001096 ASTWriter::DeclUpdate(UPD_CXX_ADDED_ANONYMOUS_NAMESPACE, D));
Sebastian Redlfa1f3702011-04-24 16:28:13 +00001097 }
1098 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001099}
1100
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001101void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Richard Smithf4634362014-09-03 23:11:22 +00001102 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001103 VisitNamedDecl(D);
Douglas Gregorf9e43ce2010-09-01 00:08:19 +00001104 Writer.AddSourceLocation(D->getNamespaceLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001105 Writer.AddSourceLocation(D->getTargetNameLoc(), Record);
Douglas Gregorc05ba2e2011-02-25 17:08:07 +00001106 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001107 Writer.AddDeclRef(D->getNamespace(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001108 Code = serialization::DECL_NAMESPACE_ALIAS;
Chris Lattnerca025db2010-05-07 21:43:38 +00001109}
1110
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001111void ASTDeclWriter::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001112 VisitNamedDecl(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00001113 Writer.AddSourceLocation(D->getUsingLoc(), Record);
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001114 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00001115 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
Benjamin Kramere78f8ee2012-01-07 19:09:05 +00001116 Writer.AddDeclRef(D->FirstUsingShadow.getPointer(), Record);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00001117 Record.push_back(D->hasTypename());
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001118 Writer.AddDeclRef(Context.getInstantiatedFromUsingDecl(D), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001119 Code = serialization::DECL_USING;
Chris Lattnerca025db2010-05-07 21:43:38 +00001120}
1121
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001122void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) {
Richard Smithfd8634a2013-10-23 02:17:46 +00001123 VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001124 VisitNamedDecl(D);
1125 Writer.AddDeclRef(D->getTargetDecl(), Record);
Argyrios Kyrtzidis2703beb2010-11-10 05:40:41 +00001126 Writer.AddDeclRef(D->UsingOrNextShadow, Record);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001127 Writer.AddDeclRef(Context.getInstantiatedFromUsingShadowDecl(D), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001128 Code = serialization::DECL_USING_SHADOW;
Chris Lattnerca025db2010-05-07 21:43:38 +00001129}
1130
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001131void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001132 VisitNamedDecl(D);
Douglas Gregor01a430132010-09-01 03:07:18 +00001133 Writer.AddSourceLocation(D->getUsingLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001134 Writer.AddSourceLocation(D->getNamespaceKeyLocation(), Record);
Douglas Gregor12441b32011-02-25 16:33:46 +00001135 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001136 Writer.AddDeclRef(D->getNominatedNamespace(), Record);
1137 Writer.AddDeclRef(dyn_cast<Decl>(D->getCommonAncestor()), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001138 Code = serialization::DECL_USING_DIRECTIVE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001139}
1140
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001141void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001142 VisitValueDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001143 Writer.AddSourceLocation(D->getUsingLoc(), Record);
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001144 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00001145 Writer.AddDeclarationNameLoc(D->DNLoc, D->getDeclName(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001146 Code = serialization::DECL_UNRESOLVED_USING_VALUE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001147}
1148
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001149void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001150 UnresolvedUsingTypenameDecl *D) {
1151 VisitTypeDecl(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001152 Writer.AddSourceLocation(D->getTypenameLoc(), Record);
Douglas Gregora9d87bc2011-02-25 00:36:19 +00001153 Writer.AddNestedNameSpecifierLoc(D->getQualifierLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001154 Code = serialization::DECL_UNRESOLVED_USING_TYPENAME;
Chris Lattnerca025db2010-05-07 21:43:38 +00001155}
1156
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001157void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001158 VisitRecordDecl(D);
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001159
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001160 enum {
1161 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1162 };
1163 if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) {
1164 Record.push_back(CXXRecTemplate);
1165 Writer.AddDeclRef(TemplD, Record);
1166 } else if (MemberSpecializationInfo *MSInfo
1167 = D->getMemberSpecializationInfo()) {
1168 Record.push_back(CXXRecMemberSpecialization);
1169 Writer.AddDeclRef(MSInfo->getInstantiatedFrom(), Record);
1170 Record.push_back(MSInfo->getTemplateSpecializationKind());
1171 Writer.AddSourceLocation(MSInfo->getPointOfInstantiation(), Record);
1172 } else {
1173 Record.push_back(CXXRecNotTemplate);
1174 }
1175
Richard Smithcd45dbc2014-04-19 03:48:30 +00001176 Record.push_back(D->isThisDeclarationADefinition());
1177 if (D->isThisDeclarationADefinition())
1178 Writer.AddCXXDefinitionData(D, Record);
1179
John McCall6bd2a892013-01-25 22:31:03 +00001180 // Store (what we currently believe to be) the key function to avoid
1181 // deserializing every method so we can compute it.
John McCallf937c022011-10-07 06:10:15 +00001182 if (D->IsCompleteDefinition)
John McCall6bd2a892013-01-25 22:31:03 +00001183 Writer.AddDeclRef(Context.getCurrentKeyFunction(D), Record);
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001184
Sebastian Redl539c5062010-08-18 23:57:32 +00001185 Code = serialization::DECL_CXX_RECORD;
Chris Lattnerca025db2010-05-07 21:43:38 +00001186}
1187
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001188void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001189 VisitFunctionDecl(D);
Argyrios Kyrtzidis3b1a7792012-10-12 05:31:40 +00001190 if (D->isCanonicalDecl()) {
1191 Record.push_back(D->size_overridden_methods());
1192 for (CXXMethodDecl::method_iterator
1193 I = D->begin_overridden_methods(), E = D->end_overridden_methods();
1194 I != E; ++I)
1195 Writer.AddDeclRef(*I, Record);
1196 } else {
1197 // We only need to record overridden methods once for the canonical decl.
1198 Record.push_back(0);
1199 }
Richard Smith01b2cb42014-07-26 06:37:51 +00001200
Richard Smith8aed4222015-12-11 22:41:00 +00001201 if (D->getDeclContext() == D->getLexicalDeclContext() &&
1202 D->getFirstDecl() == D->getMostRecentDecl() &&
Richard Smith01b2cb42014-07-26 06:37:51 +00001203 !D->isInvalidDecl() &&
1204 !D->hasAttrs() &&
1205 !D->isTopLevelDeclInObjCContainer() &&
1206 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
1207 !D->hasExtInfo() &&
1208 !D->hasInheritedPrototype() &&
1209 D->hasWrittenPrototype())
1210 AbbrevToUse = Writer.getDeclCXXMethodAbbrev();
1211
Sebastian Redl539c5062010-08-18 23:57:32 +00001212 Code = serialization::DECL_CXX_METHOD;
Chris Lattnerca025db2010-05-07 21:43:38 +00001213}
1214
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001215void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001216 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001217
Stephan Tolksdorfa6a08632014-03-27 19:22:19 +00001218 Writer.AddDeclRef(D->getInheritedConstructor(), Record);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001219 Record.push_back(D->IsExplicitSpecified);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001220
Sebastian Redl539c5062010-08-18 23:57:32 +00001221 Code = serialization::DECL_CXX_CONSTRUCTOR;
Chris Lattnerca025db2010-05-07 21:43:38 +00001222}
1223
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001224void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001225 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001226
Richard Smithf8134002015-03-10 01:41:22 +00001227 Writer.AddDeclRef(D->getOperatorDelete(), Record);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001228
Sebastian Redl539c5062010-08-18 23:57:32 +00001229 Code = serialization::DECL_CXX_DESTRUCTOR;
Chris Lattnerca025db2010-05-07 21:43:38 +00001230}
1231
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001232void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001233 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001234 Record.push_back(D->IsExplicitSpecified);
Sebastian Redl539c5062010-08-18 23:57:32 +00001235 Code = serialization::DECL_CXX_CONVERSION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001236}
1237
Douglas Gregorba345522011-12-02 23:23:56 +00001238void ASTDeclWriter::VisitImportDecl(ImportDecl *D) {
1239 VisitDecl(D);
Argyrios Kyrtzidis7b8e5552012-10-03 01:58:45 +00001240 Record.push_back(Writer.getSubmoduleID(D->getImportedModule()));
Douglas Gregorba345522011-12-02 23:23:56 +00001241 ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs();
1242 Record.push_back(!IdentifierLocs.empty());
1243 if (IdentifierLocs.empty()) {
1244 Writer.AddSourceLocation(D->getLocEnd(), Record);
1245 Record.push_back(1);
1246 } else {
1247 for (unsigned I = 0, N = IdentifierLocs.size(); I != N; ++I)
1248 Writer.AddSourceLocation(IdentifierLocs[I], Record);
1249 Record.push_back(IdentifierLocs.size());
1250 }
1251 // Note: the number of source locations must always be the last element in
1252 // the record.
1253 Code = serialization::DECL_IMPORT;
1254}
1255
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001256void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001257 VisitDecl(D);
1258 Writer.AddSourceLocation(D->getColonLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001259 Code = serialization::DECL_ACCESS_SPEC;
Abramo Bagnarad7340582010-06-05 05:09:32 +00001260}
1261
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001262void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) {
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001263 // Record the number of friend type template parameter lists here
1264 // so as to simplify memory allocation during deserialization.
1265 Record.push_back(D->NumTPLists);
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001266 VisitDecl(D);
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001267 bool hasFriendDecl = D->Friend.is<NamedDecl*>();
1268 Record.push_back(hasFriendDecl);
1269 if (hasFriendDecl)
1270 Writer.AddDeclRef(D->getFriendDecl(), Record);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001271 else
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001272 Writer.AddTypeSourceInfo(D->getFriendType(), Record);
1273 for (unsigned i = 0; i < D->NumTPLists; ++i)
1274 Writer.AddTemplateParameterList(D->getFriendTypeTemplateParameterList(i),
1275 Record);
Douglas Gregore0fb32c2010-10-27 20:23:41 +00001276 Writer.AddDeclRef(D->getNextFriend(), Record);
John McCall2c2eb122010-10-16 06:59:13 +00001277 Record.push_back(D->UnsupportedFriend);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001278 Writer.AddSourceLocation(D->FriendLoc, Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001279 Code = serialization::DECL_FRIEND;
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001280}
1281
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001282void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001283 VisitDecl(D);
1284 Record.push_back(D->getNumTemplateParameters());
1285 for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i)
1286 Writer.AddTemplateParameterList(D->getTemplateParameterList(i), Record);
Craig Toppera13603a2014-05-22 05:54:18 +00001287 Record.push_back(D->getFriendDecl() != nullptr);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001288 if (D->getFriendDecl())
1289 Writer.AddDeclRef(D->getFriendDecl(), Record);
1290 else
1291 Writer.AddTypeSourceInfo(D->getFriendType(), Record);
1292 Writer.AddSourceLocation(D->getFriendLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001293 Code = serialization::DECL_FRIEND_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001294}
1295
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001296void ASTDeclWriter::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001297 VisitNamedDecl(D);
1298
1299 Writer.AddDeclRef(D->getTemplatedDecl(), Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001300 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
Chris Lattnerca025db2010-05-07 21:43:38 +00001301}
1302
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001303void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Douglas Gregor68444de2012-01-14 15:13:49 +00001304 VisitRedeclarable(D);
1305
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001306 // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that
1307 // getCommonPtr() can be used while this is still initializing.
Rafael Espindola8db352d2013-10-17 15:37:26 +00001308 if (D->isFirstDecl()) {
Douglas Gregor074a4092011-12-19 18:19:24 +00001309 // This declaration owns the 'common' pointer, so serialize that data now.
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001310 Writer.AddDeclRef(D->getInstantiatedFromMemberTemplate(), Record);
1311 if (D->getInstantiatedFromMemberTemplate())
1312 Record.push_back(D->isMemberSpecialization());
Douglas Gregor074a4092011-12-19 18:19:24 +00001313 }
1314
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001315 VisitTemplateDecl(D);
1316 Record.push_back(D->getIdentifierNamespace());
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001317}
1318
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001319void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001320 VisitRedeclarableTemplateDecl(D);
1321
Richard Smith509fc852015-02-27 23:05:10 +00001322 if (D->isFirstDecl())
1323 AddTemplateSpecializations(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001324 Code = serialization::DECL_CLASS_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001325}
1326
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001327void ASTDeclWriter::VisitClassTemplateSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001328 ClassTemplateSpecializationDecl *D) {
Richard Smithd8a83712015-08-22 01:47:18 +00001329 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1330
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001331 VisitCXXRecordDecl(D);
1332
1333 llvm::PointerUnion<ClassTemplateDecl *,
1334 ClassTemplatePartialSpecializationDecl *> InstFrom
1335 = D->getSpecializedTemplateOrPartial();
Argyrios Kyrtzidisd5553f12011-08-17 21:35:28 +00001336 if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) {
Sebastian Redl401b39a2010-08-24 22:50:24 +00001337 Writer.AddDeclRef(InstFromD, Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001338 } else {
Argyrios Kyrtzidisd5553f12011-08-17 21:35:28 +00001339 Writer.AddDeclRef(InstFrom.get<ClassTemplatePartialSpecializationDecl *>(),
1340 Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001341 Writer.AddTemplateArgumentList(&D->getTemplateInstantiationArgs(), Record);
1342 }
1343
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001344 Writer.AddTemplateArgumentList(&D->getTemplateArgs(), Record);
1345 Writer.AddSourceLocation(D->getPointOfInstantiation(), Record);
1346 Record.push_back(D->getSpecializationKind());
Axel Naumanna31dee22012-10-01 07:34:47 +00001347 Record.push_back(D->isCanonicalDecl());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001348
Argyrios Kyrtzidisc1624e92010-07-20 13:59:40 +00001349 if (D->isCanonicalDecl()) {
1350 // When reading, we'll add it to the folding set of the following template.
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00001351 Writer.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl(), Record);
1352 }
1353
Richard Smithd55889a2013-09-09 16:55:27 +00001354 // Explicit info.
1355 Writer.AddTypeSourceInfo(D->getTypeAsWritten(), Record);
1356 if (D->getTypeAsWritten()) {
1357 Writer.AddSourceLocation(D->getExternLoc(), Record);
1358 Writer.AddSourceLocation(D->getTemplateKeywordLoc(), Record);
1359 }
1360
Sebastian Redl539c5062010-08-18 23:57:32 +00001361 Code = serialization::DECL_CLASS_TEMPLATE_SPECIALIZATION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001362}
1363
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001364void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001365 ClassTemplatePartialSpecializationDecl *D) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001366 VisitClassTemplateSpecializationDecl(D);
1367
1368 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
Enea Zaffanella6dbe1872013-08-10 07:24:53 +00001369 Writer.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten(), Record);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001370
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001371 // These are read/set from/to the first declaration.
Craig Toppera13603a2014-05-22 05:54:18 +00001372 if (D->getPreviousDecl() == nullptr) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001373 Writer.AddDeclRef(D->getInstantiatedFromMember(), Record);
1374 Record.push_back(D->isMemberSpecialization());
1375 }
1376
Sebastian Redl539c5062010-08-18 23:57:32 +00001377 Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION;
Chris Lattnerca025db2010-05-07 21:43:38 +00001378}
1379
Larisse Voufo39a1e502013-08-06 01:03:05 +00001380void ASTDeclWriter::VisitVarTemplateDecl(VarTemplateDecl *D) {
1381 VisitRedeclarableTemplateDecl(D);
1382
Richard Smith509fc852015-02-27 23:05:10 +00001383 if (D->isFirstDecl())
1384 AddTemplateSpecializations(D);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001385 Code = serialization::DECL_VAR_TEMPLATE;
1386}
1387
1388void ASTDeclWriter::VisitVarTemplateSpecializationDecl(
1389 VarTemplateSpecializationDecl *D) {
Richard Smithd8a83712015-08-22 01:47:18 +00001390 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1391
Larisse Voufo39a1e502013-08-06 01:03:05 +00001392 VisitVarDecl(D);
1393
1394 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
1395 InstFrom = D->getSpecializedTemplateOrPartial();
1396 if (Decl *InstFromD = InstFrom.dyn_cast<VarTemplateDecl *>()) {
1397 Writer.AddDeclRef(InstFromD, Record);
1398 } else {
1399 Writer.AddDeclRef(InstFrom.get<VarTemplatePartialSpecializationDecl *>(),
1400 Record);
1401 Writer.AddTemplateArgumentList(&D->getTemplateInstantiationArgs(), Record);
1402 }
1403
1404 // Explicit info.
1405 Writer.AddTypeSourceInfo(D->getTypeAsWritten(), Record);
1406 if (D->getTypeAsWritten()) {
1407 Writer.AddSourceLocation(D->getExternLoc(), Record);
1408 Writer.AddSourceLocation(D->getTemplateKeywordLoc(), Record);
1409 }
1410
1411 Writer.AddTemplateArgumentList(&D->getTemplateArgs(), Record);
1412 Writer.AddSourceLocation(D->getPointOfInstantiation(), Record);
1413 Record.push_back(D->getSpecializationKind());
1414 Record.push_back(D->isCanonicalDecl());
1415
1416 if (D->isCanonicalDecl()) {
1417 // When reading, we'll add it to the folding set of the following template.
1418 Writer.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl(), Record);
1419 }
1420
1421 Code = serialization::DECL_VAR_TEMPLATE_SPECIALIZATION;
1422}
1423
1424void ASTDeclWriter::VisitVarTemplatePartialSpecializationDecl(
1425 VarTemplatePartialSpecializationDecl *D) {
1426 VisitVarTemplateSpecializationDecl(D);
1427
1428 Writer.AddTemplateParameterList(D->getTemplateParameters(), Record);
Enea Zaffanella6dbe1872013-08-10 07:24:53 +00001429 Writer.AddASTTemplateArgumentListInfo(D->getTemplateArgsAsWritten(), Record);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001430
1431 // These are read/set from/to the first declaration.
Craig Toppera13603a2014-05-22 05:54:18 +00001432 if (D->getPreviousDecl() == nullptr) {
Larisse Voufo39a1e502013-08-06 01:03:05 +00001433 Writer.AddDeclRef(D->getInstantiatedFromMember(), Record);
1434 Record.push_back(D->isMemberSpecialization());
1435 }
1436
1437 Code = serialization::DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION;
1438}
1439
Fariborz Jahanian3a039e32011-08-27 20:50:59 +00001440void ASTDeclWriter::VisitClassScopeFunctionSpecializationDecl(
1441 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichet09af8c32011-08-17 01:06:54 +00001442 VisitDecl(D);
1443 Writer.AddDeclRef(D->getSpecialization(), Record);
1444 Code = serialization::DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION;
1445}
1446
1447
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001448void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001449 VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001450
Richard Smith509fc852015-02-27 23:05:10 +00001451 if (D->isFirstDecl())
1452 AddTemplateSpecializations(D);
Sebastian Redl539c5062010-08-18 23:57:32 +00001453 Code = serialization::DECL_FUNCTION_TEMPLATE;
Chris Lattnerca025db2010-05-07 21:43:38 +00001454}
1455
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001456void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001457 VisitTypeDecl(D);
1458
1459 Record.push_back(D->wasDeclaredWithTypename());
Richard Smith8346e522015-06-10 01:47:58 +00001460
1461 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1462 !D->defaultArgumentWasInherited();
1463 Record.push_back(OwnsDefaultArg);
1464 if (OwnsDefaultArg)
Richard Smith1469b912015-06-10 00:29:03 +00001465 Writer.AddTypeSourceInfo(D->getDefaultArgumentInfo(), Record);
Argyrios Kyrtzidis106caf922010-06-19 19:28:53 +00001466
Sebastian Redl539c5062010-08-18 23:57:32 +00001467 Code = serialization::DECL_TEMPLATE_TYPE_PARM;
Chris Lattnerca025db2010-05-07 21:43:38 +00001468}
1469
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001470void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001471 // For an expanded parameter pack, record the number of expansion types here
Richard Smith1fde8ec2012-09-07 02:06:42 +00001472 // so that it's easier for deserialization to allocate the right amount of
1473 // memory.
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001474 if (D->isExpandedParameterPack())
1475 Record.push_back(D->getNumExpansionTypes());
1476
John McCallf4cd4f92011-02-09 01:13:10 +00001477 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001478 // TemplateParmPosition.
1479 Record.push_back(D->getDepth());
1480 Record.push_back(D->getPosition());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001481
1482 if (D->isExpandedParameterPack()) {
1483 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
1484 Writer.AddTypeRef(D->getExpansionType(I), Record);
1485 Writer.AddTypeSourceInfo(D->getExpansionTypeSourceInfo(I), Record);
1486 }
1487
1488 Code = serialization::DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK;
1489 } else {
1490 // Rest of NonTypeTemplateParmDecl.
1491 Record.push_back(D->isParameterPack());
Richard Smith8346e522015-06-10 01:47:58 +00001492 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1493 !D->defaultArgumentWasInherited();
1494 Record.push_back(OwnsDefaultArg);
1495 if (OwnsDefaultArg)
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001496 Writer.AddStmt(D->getDefaultArgument());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00001497 Code = serialization::DECL_NON_TYPE_TEMPLATE_PARM;
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00001498 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001499}
1500
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001501void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Richard Smith1fde8ec2012-09-07 02:06:42 +00001502 // For an expanded parameter pack, record the number of expansion types here
1503 // so that it's easier for deserialization to allocate the right amount of
1504 // memory.
1505 if (D->isExpandedParameterPack())
1506 Record.push_back(D->getNumExpansionTemplateParameters());
1507
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00001508 VisitTemplateDecl(D);
1509 // TemplateParmPosition.
1510 Record.push_back(D->getDepth());
1511 Record.push_back(D->getPosition());
Richard Smith1fde8ec2012-09-07 02:06:42 +00001512
1513 if (D->isExpandedParameterPack()) {
1514 for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
1515 I != N; ++I)
1516 Writer.AddTemplateParameterList(D->getExpansionTemplateParameters(I),
1517 Record);
1518 Code = serialization::DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK;
1519 } else {
1520 // Rest of TemplateTemplateParmDecl.
Richard Smith1fde8ec2012-09-07 02:06:42 +00001521 Record.push_back(D->isParameterPack());
Richard Smith8346e522015-06-10 01:47:58 +00001522 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1523 !D->defaultArgumentWasInherited();
1524 Record.push_back(OwnsDefaultArg);
1525 if (OwnsDefaultArg)
Richard Smith1469b912015-06-10 00:29:03 +00001526 Writer.AddTemplateArgumentLoc(D->getDefaultArgument(), Record);
Richard Smith1fde8ec2012-09-07 02:06:42 +00001527 Code = serialization::DECL_TEMPLATE_TEMPLATE_PARM;
1528 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001529}
1530
Richard Smith3f1b5d02011-05-05 21:57:07 +00001531void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
1532 VisitRedeclarableTemplateDecl(D);
1533 Code = serialization::DECL_TYPE_ALIAS_TEMPLATE;
1534}
1535
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001536void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001537 VisitDecl(D);
1538 Writer.AddStmt(D->getAssertExpr());
Richard Smithded9c2e2012-07-11 22:37:56 +00001539 Record.push_back(D->isFailed());
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00001540 Writer.AddStmt(D->getMessage());
Abramo Bagnaraea947882011-03-08 16:41:52 +00001541 Writer.AddSourceLocation(D->getRParenLoc(), Record);
Sebastian Redl539c5062010-08-18 23:57:32 +00001542 Code = serialization::DECL_STATIC_ASSERT;
Chris Lattnerca025db2010-05-07 21:43:38 +00001543}
1544
Chris Lattner7099dbc2009-04-27 06:16:06 +00001545/// \brief Emit the DeclContext part of a declaration context decl.
1546///
1547/// \param LexicalOffset the offset at which the DECL_CONTEXT_LEXICAL
1548/// block for this declaration context is stored. May be 0 to indicate
1549/// that there are no declarations stored within this context.
1550///
1551/// \param VisibleOffset the offset at which the DECL_CONTEXT_VISIBLE
1552/// block for this declaration context is stored. May be 0 to indicate
1553/// that there are no declarations visible from this context. Note
1554/// that this value will not be emitted for non-primary declaration
1555/// contexts.
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001556void ASTDeclWriter::VisitDeclContext(DeclContext *DC, uint64_t LexicalOffset,
Chris Lattner7099dbc2009-04-27 06:16:06 +00001557 uint64_t VisibleOffset) {
1558 Record.push_back(LexicalOffset);
1559 Record.push_back(VisibleOffset);
1560}
1561
Richard Smithd8a83712015-08-22 01:47:18 +00001562const Decl *ASTWriter::getFirstLocalDecl(const Decl *D) {
Richard Smith3864be72015-09-11 02:22:03 +00001563 /// \brief Is this a local declaration (that is, one that will be written to
1564 /// our AST file)? This is the case for declarations that are neither imported
1565 /// from another AST file nor predefined.
1566 auto IsLocalDecl = [&](const Decl *D) -> bool {
1567 if (D->isFromASTFile())
1568 return false;
1569 auto I = DeclIDs.find(D);
1570 return (I == DeclIDs.end() || I->second >= NUM_PREDEF_DECL_IDS);
1571 };
1572
1573 assert(IsLocalDecl(D) && "expected a local declaration");
Richard Smithd8a83712015-08-22 01:47:18 +00001574
1575 const Decl *Canon = D->getCanonicalDecl();
Richard Smith3864be72015-09-11 02:22:03 +00001576 if (IsLocalDecl(Canon))
Richard Smithd8a83712015-08-22 01:47:18 +00001577 return Canon;
1578
1579 const Decl *&CacheEntry = FirstLocalDeclCache[Canon];
1580 if (CacheEntry)
1581 return CacheEntry;
1582
1583 for (const Decl *Redecl = D; Redecl; Redecl = Redecl->getPreviousDecl())
Richard Smith3864be72015-09-11 02:22:03 +00001584 if (IsLocalDecl(Redecl))
Richard Smithd8a83712015-08-22 01:47:18 +00001585 D = Redecl;
1586 return CacheEntry = D;
Richard Smith5fc18a92015-07-12 23:43:21 +00001587}
1588
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001589template <typename T>
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00001590void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) {
Rafael Espindola8db352d2013-10-17 15:37:26 +00001591 T *First = D->getFirstDecl();
Richard Smith5a4737c2015-02-06 02:42:59 +00001592 T *MostRecent = First->getMostRecentDecl();
Richard Smithd8a83712015-08-22 01:47:18 +00001593 T *DAsT = static_cast<T *>(D);
Richard Smith5a4737c2015-02-06 02:42:59 +00001594 if (MostRecent != First) {
Richard Smithd8a83712015-08-22 01:47:18 +00001595 assert(isRedeclarableDeclKind(DAsT->getKind()) &&
Douglas Gregorfe732d52013-01-21 16:16:40 +00001596 "Not considered redeclarable?");
Richard Smith5a4737c2015-02-06 02:42:59 +00001597
Richard Smithfe620d22015-03-05 23:24:12 +00001598 Writer.AddDeclRef(First, Record);
Richard Smithfe620d22015-03-05 23:24:12 +00001599
Richard Smithd8a83712015-08-22 01:47:18 +00001600 // Write out a list of local redeclarations of this declaration if it's the
1601 // first local declaration in the chain.
1602 const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
1603 if (DAsT == FirstLocal) {
Richard Smithd8a83712015-08-22 01:47:18 +00001604 // Emit a list of all imported first declarations so that we can be sure
1605 // that all redeclarations visible to this module are before D in the
1606 // redecl chain.
1607 unsigned I = Record.size();
1608 Record.push_back(0);
1609 if (Writer.Chain)
1610 AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
1611 // This is the number of imported first declarations + 1.
1612 Record[I] = Record.size() - I;
Richard Smithd61d4ac2015-08-22 20:13:39 +00001613
1614 // Collect the set of local redeclarations of this declaration, from
1615 // newest to oldest.
1616 RecordData LocalRedecls;
1617 for (const Decl *Prev = FirstLocal->getMostRecentDecl();
1618 Prev != FirstLocal; Prev = Prev->getPreviousDecl())
1619 if (!Prev->isFromASTFile())
1620 Writer.AddDeclRef(Prev, LocalRedecls);
1621
1622 // If we have any redecls, write them now as a separate record preceding
1623 // the declaration itself.
1624 if (LocalRedecls.empty())
1625 Record.push_back(0);
1626 else {
1627 Record.push_back(Writer.Stream.GetCurrentBitNo());
1628 Writer.Stream.EmitRecord(LOCAL_REDECLARATIONS, LocalRedecls);
1629 }
Richard Smithd8a83712015-08-22 01:47:18 +00001630 } else {
1631 Record.push_back(0);
1632 Writer.AddDeclRef(FirstLocal, Record);
Richard Smithfe620d22015-03-05 23:24:12 +00001633 }
Douglas Gregor358cd442012-01-15 16:58:34 +00001634
1635 // Make sure that we serialize both the previous and the most-recent
1636 // declarations, which (transitively) ensures that all declarations in the
1637 // chain get serialized.
Richard Smith5a4737c2015-02-06 02:42:59 +00001638 //
1639 // FIXME: This is not correct; when we reach an imported declaration we
1640 // won't emit its previous declaration.
Richard Smith5fc18a92015-07-12 23:43:21 +00001641 (void)Writer.GetDeclRef(D->getPreviousDecl());
Richard Smith5a4737c2015-02-06 02:42:59 +00001642 (void)Writer.GetDeclRef(MostRecent);
Douglas Gregor358cd442012-01-15 16:58:34 +00001643 } else {
1644 // We use the sentinel value 0 to indicate an only declaration.
1645 Record.push_back(0);
Douglas Gregor9f562c82011-12-19 15:27:36 +00001646 }
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00001647}
Chris Lattner7099dbc2009-04-27 06:16:06 +00001648
Alexey Bataeva769e072013-03-22 06:34:35 +00001649void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
1650 Record.push_back(D->varlist_size());
1651 VisitDecl(D);
Aaron Ballman2205d2a2014-03-14 15:55:35 +00001652 for (auto *I : D->varlists())
1653 Writer.AddStmt(I);
Alexey Bataeva769e072013-03-22 06:34:35 +00001654 Code = serialization::DECL_OMP_THREADPRIVATE;
1655}
1656
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00001657void ASTDeclWriter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
1658 VisitNamedDecl(D);
1659 Writer.AddSourceLocation(D->getLocStart(), Record);
1660 Writer.AddStmt(D->getCombiner());
1661 Writer.AddStmt(D->getInitializer());
1662 Writer.AddDeclRef(D->getPrevDeclInScope(), Record);
1663 Writer.AddTypeRef(D->getType(), Record);
1664 Code = serialization::DECL_OMP_DECLARE_REDUCTION;
1665}
1666
Alexey Bataev4244be22016-02-11 05:35:55 +00001667void ASTDeclWriter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
Alexey Bataev90c228f2016-02-08 09:29:13 +00001668 VisitVarDecl(D);
Alexey Bataev4244be22016-02-11 05:35:55 +00001669 Code = serialization::DECL_OMP_CAPTUREDEXPR;
Alexey Bataev90c228f2016-02-08 09:29:13 +00001670}
1671
Chris Lattner7099dbc2009-04-27 06:16:06 +00001672//===----------------------------------------------------------------------===//
Sebastian Redl55c0ad52010-08-18 23:56:21 +00001673// ASTWriter Implementation
Chris Lattner7099dbc2009-04-27 06:16:06 +00001674//===----------------------------------------------------------------------===//
1675
Richard Smith01b2cb42014-07-26 06:37:51 +00001676void ASTWriter::WriteDeclAbbrevs() {
Chris Lattner258172e2009-04-27 07:35:58 +00001677 using namespace llvm;
Chris Lattner258172e2009-04-27 07:35:58 +00001678
Douglas Gregor03412ba2011-06-03 02:27:19 +00001679 BitCodeAbbrev *Abv;
1680
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001681 // Abbreviation for DECL_FIELD
1682 Abv = new BitCodeAbbrev();
1683 Abv->Add(BitCodeAbbrevOp(serialization::DECL_FIELD));
1684 // Decl
1685 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001686 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001687 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001688 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1689 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1690 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1691 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001692 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001693 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001694 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001695 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001696 // NamedDecl
1697 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1698 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001699 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001700 // ValueDecl
1701 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1702 // DeclaratorDecl
1703 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1704 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
1705 // FieldDecl
1706 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
1707 Abv->Add(BitCodeAbbrevOp(0)); //getBitWidth
1708 // Type Source Info
1709 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1710 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1711 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1712 DeclFieldAbbrev = Stream.EmitAbbrev(Abv);
1713
1714 // Abbreviation for DECL_OBJC_IVAR
1715 Abv = new BitCodeAbbrev();
1716 Abv->Add(BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR));
1717 // Decl
1718 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001719 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001720 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001721 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1722 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1723 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1724 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001725 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001726 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001727 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001728 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001729 // NamedDecl
1730 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1731 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001732 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001733 // ValueDecl
1734 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1735 // DeclaratorDecl
1736 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1737 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
1738 // FieldDecl
1739 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
1740 Abv->Add(BitCodeAbbrevOp(0)); //getBitWidth
1741 // ObjC Ivar
1742 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl
1743 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize
1744 // Type Source Info
1745 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1746 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1747 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1748 DeclObjCIvarAbbrev = Stream.EmitAbbrev(Abv);
1749
1750 // Abbreviation for DECL_ENUM
1751 Abv = new BitCodeAbbrev();
1752 Abv->Add(BitCodeAbbrevOp(serialization::DECL_ENUM));
Douglas Gregor3e300102011-10-26 17:53:41 +00001753 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001754 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Chris Lattner258172e2009-04-27 07:35:58 +00001755 // Decl
1756 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001757 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001758 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Chris Lattner258172e2009-04-27 07:35:58 +00001759 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1760 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
Douglas Gregorc9c02ed2009-06-19 23:52:42 +00001761 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +00001762 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001763 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Chris Lattner258172e2009-04-27 07:35:58 +00001764 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001765 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001766 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Douglas Gregor03412ba2011-06-03 02:27:19 +00001767 // NamedDecl
1768 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1769 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001770 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001771 // TypeDecl
1772 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1773 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001774 // TagDecl
1775 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
1776 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
John McCallf937c022011-10-07 06:10:15 +00001777 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001778 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +00001779 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
David Blaikiea8d23ce2013-07-14 01:07:41 +00001780 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001781 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Richard Smith70d58502014-08-30 00:04:23 +00001782 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001783 // EnumDecl
1784 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddTypeRef
1785 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IntegerType
1786 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getPromotionType
1787 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumPositiveBits
1788 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getNumNegativeBits
1789 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScoped
1790 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isScopedUsingClassTag
1791 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isFixed
1792 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedMembEnum
1793 // DC
1794 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
1795 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
1796 DeclEnumAbbrev = Stream.EmitAbbrev(Abv);
Mike Stump11289f42009-09-09 15:08:12 +00001797
Douglas Gregor03412ba2011-06-03 02:27:19 +00001798 // Abbreviation for DECL_RECORD
1799 Abv = new BitCodeAbbrev();
1800 Abv->Add(BitCodeAbbrevOp(serialization::DECL_RECORD));
Douglas Gregor3e300102011-10-26 17:53:41 +00001801 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001802 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Douglas Gregor03412ba2011-06-03 02:27:19 +00001803 // Decl
1804 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001805 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001806 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Douglas Gregor03412ba2011-06-03 02:27:19 +00001807 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1808 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1809 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1810 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001811 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Douglas Gregor03412ba2011-06-03 02:27:19 +00001812 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001813 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001814 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Douglas Gregor03412ba2011-06-03 02:27:19 +00001815 // NamedDecl
1816 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1817 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001818 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Douglas Gregor03412ba2011-06-03 02:27:19 +00001819 // TypeDecl
1820 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1821 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
Douglas Gregor03412ba2011-06-03 02:27:19 +00001822 // TagDecl
1823 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
1824 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getTagKind
John McCallf937c022011-10-07 06:10:15 +00001825 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCompleteDefinition
Douglas Gregor03412ba2011-06-03 02:27:19 +00001826 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // EmbeddedInDeclarator
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +00001827 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsFreeStanding
David Blaikiea8d23ce2013-07-14 01:07:41 +00001828 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsCompleteDefinitionRequired
Douglas Gregor03412ba2011-06-03 02:27:19 +00001829 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
Richard Smith70d58502014-08-30 00:04:23 +00001830 Abv->Add(BitCodeAbbrevOp(0)); // ExtInfoKind
Douglas Gregor03412ba2011-06-03 02:27:19 +00001831 // RecordDecl
1832 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // FlexibleArrayMember
1833 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // AnonymousStructUnion
1834 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasObjectMember
Fariborz Jahanian78652202013-01-25 23:57:05 +00001835 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // hasVolatileMember
Douglas Gregor03412ba2011-06-03 02:27:19 +00001836 // DC
1837 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
1838 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
1839 DeclRecordAbbrev = Stream.EmitAbbrev(Abv);
1840
1841 // Abbreviation for DECL_PARM_VAR
1842 Abv = new BitCodeAbbrev();
1843 Abv->Add(BitCodeAbbrevOp(serialization::DECL_PARM_VAR));
Douglas Gregor3e300102011-10-26 17:53:41 +00001844 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001845 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Douglas Gregor03412ba2011-06-03 02:27:19 +00001846 // Decl
1847 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001848 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001849 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Douglas Gregor03412ba2011-06-03 02:27:19 +00001850 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1851 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1852 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1853 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001854 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Douglas Gregor03412ba2011-06-03 02:27:19 +00001855 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001856 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001857 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Chris Lattner258172e2009-04-27 07:35:58 +00001858 // NamedDecl
1859 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1860 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001861 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Chris Lattner258172e2009-04-27 07:35:58 +00001862 // ValueDecl
1863 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +00001864 // DeclaratorDecl
Abramo Bagnaradff19302011-03-08 08:55:46 +00001865 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +00001866 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
Chris Lattner258172e2009-04-27 07:35:58 +00001867 // VarDecl
1868 Abv->Add(BitCodeAbbrevOp(0)); // StorageClass
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +00001869 Abv->Add(BitCodeAbbrevOp(0)); // getTSCSpec
Chris Lattner258172e2009-04-27 07:35:58 +00001870 Abv->Add(BitCodeAbbrevOp(0)); // hasCXXDirectInitializer
Richard Smith88581592013-02-12 05:48:23 +00001871 Abv->Add(BitCodeAbbrevOp(0)); // Linkage
Chris Lattner258172e2009-04-27 07:35:58 +00001872 Abv->Add(BitCodeAbbrevOp(0)); // HasInit
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001873 Abv->Add(BitCodeAbbrevOp(0)); // HasMemberSpecializationInfo
Chris Lattner258172e2009-04-27 07:35:58 +00001874 // ParmVarDecl
John McCall82490832011-05-02 00:30:12 +00001875 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // IsObjCMethodParameter
John McCall8fb0d9d2011-05-01 22:35:37 +00001876 Abv->Add(BitCodeAbbrevOp(0)); // ScopeDepth
1877 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex
Chris Lattner258172e2009-04-27 07:35:58 +00001878 Abv->Add(BitCodeAbbrevOp(0)); // ObjCDeclQualifier
John McCall6a014d52011-03-09 04:22:44 +00001879 Abv->Add(BitCodeAbbrevOp(0)); // KNRPromoted
John McCallf3cd6652010-03-12 18:31:32 +00001880 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedDefaultArg
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +00001881 Abv->Add(BitCodeAbbrevOp(0)); // HasUninstantiatedDefaultArg
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001882 // Type Source Info
1883 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1884 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1885 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1886 DeclParmVarAbbrev = Stream.EmitAbbrev(Abv);
Sebastian Redl66c5eef2010-07-27 00:17:23 +00001887
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00001888 // Abbreviation for DECL_TYPEDEF
Douglas Gregor03412ba2011-06-03 02:27:19 +00001889 Abv = new BitCodeAbbrev();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001890 Abv->Add(BitCodeAbbrevOp(serialization::DECL_TYPEDEF));
Douglas Gregor05f10352011-12-17 23:38:30 +00001891 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001892 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001893 // Decl
1894 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001895 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001896 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001897 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1898 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
Richard Smith01b2cb42014-07-26 06:37:51 +00001899 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isUsed
1900 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001901 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Richard Smith01b2cb42014-07-26 06:37:51 +00001902 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001903 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001904 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001905 // NamedDecl
1906 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1907 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001908 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001909 // TypeDecl
1910 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
1911 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
1912 // TypedefDecl
1913 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1914 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1915 DeclTypedefAbbrev = Stream.EmitAbbrev(Abv);
1916
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00001917 // Abbreviation for DECL_VAR
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001918 Abv = new BitCodeAbbrev();
1919 Abv->Add(BitCodeAbbrevOp(serialization::DECL_VAR));
Douglas Gregor3e300102011-10-26 17:53:41 +00001920 // Redeclarable
Douglas Gregor9f562c82011-12-19 15:27:36 +00001921 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001922 // Decl
1923 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001924 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Argyrios Kyrtzidisb7d1ca22012-03-09 21:09:04 +00001925 Abv->Add(BitCodeAbbrevOp(0)); // isInvalidDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001926 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1927 Abv->Add(BitCodeAbbrevOp(0)); // isImplicit
1928 Abv->Add(BitCodeAbbrevOp(0)); // isUsed
1929 Abv->Add(BitCodeAbbrevOp(0)); // isReferenced
Argyrios Kyrtzidis8ad3bab2011-11-23 20:27:36 +00001930 Abv->Add(BitCodeAbbrevOp(0)); // TopLevelDeclInObjCContainer
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001931 Abv->Add(BitCodeAbbrevOp(AS_none)); // C++ AccessSpecifier
Douglas Gregor26701a42011-09-09 02:06:17 +00001932 Abv->Add(BitCodeAbbrevOp(0)); // ModulePrivate
Douglas Gregora28bcdd2011-12-01 02:07:58 +00001933 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001934 // NamedDecl
1935 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
1936 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
Richard Smith2b560572015-02-07 03:11:11 +00001937 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001938 // ValueDecl
1939 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1940 // DeclaratorDecl
1941 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
1942 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
1943 // VarDecl
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001944 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // StorageClass
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +00001945 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // getTSCSpec
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001946 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // CXXDirectInitializer
1947 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isExceptionVariable
1948 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isNRVOVariable
1949 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isCXXForRangeDecl
John McCalld4631322011-06-17 06:42:21 +00001950 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isARCPseudoStrong
Douglas Gregor12cda632012-09-20 23:43:29 +00001951 Abv->Add(BitCodeAbbrevOp(0)); // isConstexpr
Richard Smithbb13c9a2013-09-28 04:02:39 +00001952 Abv->Add(BitCodeAbbrevOp(0)); // isInitCapture
Richard Smith1c34fb72013-08-13 18:18:50 +00001953 Abv->Add(BitCodeAbbrevOp(0)); // isPrevDeclInSameScope
Rafael Espindola50df3a02013-05-25 17:16:20 +00001954 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00001955 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasInit
1956 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasMemberSpecInfo
1957 // Type Source Info
1958 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
1959 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
1960 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
1961 DeclVarAbbrev = Stream.EmitAbbrev(Abv);
1962
Richard Smith01b2cb42014-07-26 06:37:51 +00001963 // Abbreviation for DECL_CXX_METHOD
1964 Abv = new BitCodeAbbrev();
1965 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CXX_METHOD));
1966 // RedeclarableDecl
1967 Abv->Add(BitCodeAbbrevOp(0)); // CanonicalDecl
1968 // Decl
1969 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
Richard Smith8aed4222015-12-11 22:41:00 +00001970 Abv->Add(BitCodeAbbrevOp(0)); // LexicalDeclContext
Richard Smith01b2cb42014-07-26 06:37:51 +00001971 Abv->Add(BitCodeAbbrevOp(0)); // Invalid
1972 Abv->Add(BitCodeAbbrevOp(0)); // HasAttrs
1973 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Implicit
1974 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Used
1975 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Referenced
1976 Abv->Add(BitCodeAbbrevOp(0)); // InObjCContainer
1977 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // Access
1978 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ModulePrivate
1979 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
1980 // NamedDecl
1981 Abv->Add(BitCodeAbbrevOp(DeclarationName::Identifier)); // NameKind
1982 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Identifier
Richard Smith2b560572015-02-07 03:11:11 +00001983 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
Richard Smith01b2cb42014-07-26 06:37:51 +00001984 // ValueDecl
1985 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
1986 // DeclaratorDecl
1987 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerLocStart
1988 Abv->Add(BitCodeAbbrevOp(0)); // HasExtInfo
1989 // FunctionDecl
1990 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS
1991 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // StorageClass
1992 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Inline
1993 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // InlineSpecified
1994 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // VirtualAsWritten
1995 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Pure
1996 Abv->Add(BitCodeAbbrevOp(0)); // HasInheritedProto
1997 Abv->Add(BitCodeAbbrevOp(1)); // HasWrittenProto
Richard Smith72625c22015-02-06 23:20:21 +00001998 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Deleted
Richard Smith01b2cb42014-07-26 06:37:51 +00001999 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Trivial
2000 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Defaulted
2001 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ExplicitlyDefaulted
2002 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // ImplicitReturnZero
2003 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Constexpr
2004 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // SkippedBody
2005 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // LateParsed
2006 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // Linkage
2007 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LocEnd
2008 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // TemplateKind
2009 // This Array slurps the rest of the record. Fortunately we want to encode
2010 // (nearly) all the remaining (variable number of) fields in the same way.
2011 //
2012 // This is the function template information if any, then
2013 // NumParams and Params[] from FunctionDecl, and
2014 // NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl.
2015 //
2016 // Add an AbbrevOp for 'size then elements' and use it here.
2017 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2018 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
2019 DeclCXXMethodAbbrev = Stream.EmitAbbrev(Abv);
2020
Jonathan D. Turner780a6bf2011-06-06 16:22:39 +00002021 // Abbreviation for EXPR_DECL_REF
Jonathan D. Turner205c7d52011-06-03 23:11:16 +00002022 Abv = new BitCodeAbbrev();
Douglas Gregor03412ba2011-06-03 02:27:19 +00002023 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_DECL_REF));
2024 //Stmt
2025 //Expr
2026 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002027 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2028 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2029 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002030 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2031 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2032 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2033 //DeclRefExpr
2034 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HasQualifier
2035 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //GetDeclFound
2036 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ExplicitTemplateArgs
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002037 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HadMultipleCandidates
Alexey Bataev19acc3d2015-01-12 10:17:46 +00002038 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2039 1)); // RefersToEnclosingVariableOrCapture
Douglas Gregor03412ba2011-06-03 02:27:19 +00002040 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef
2041 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2042 DeclRefExprAbbrev = Stream.EmitAbbrev(Abv);
2043
2044 // Abbreviation for EXPR_INTEGER_LITERAL
2045 Abv = new BitCodeAbbrev();
2046 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL));
2047 //Stmt
2048 //Expr
2049 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002050 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2051 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2052 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002053 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2054 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2055 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2056 //Integer Literal
2057 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2058 Abv->Add(BitCodeAbbrevOp(32)); // Bit Width
2059 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value
2060 IntegerLiteralAbbrev = Stream.EmitAbbrev(Abv);
2061
2062 // Abbreviation for EXPR_CHARACTER_LITERAL
2063 Abv = new BitCodeAbbrev();
2064 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL));
2065 //Stmt
2066 //Expr
2067 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
Douglas Gregor678d76c2011-07-01 01:22:09 +00002068 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2069 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2070 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
Douglas Gregor03412ba2011-06-03 02:27:19 +00002071 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2072 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2073 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
Jonathan D. Turnerd09655f2011-06-03 21:46:44 +00002074 //Character Literal
Douglas Gregor03412ba2011-06-03 02:27:19 +00002075 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue
2076 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
Aaron Ballman9a17c852016-01-07 20:59:26 +00002077 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // getKind
Douglas Gregor03412ba2011-06-03 02:27:19 +00002078 CharacterLiteralAbbrev = Stream.EmitAbbrev(Abv);
2079
Richard Smitha27c26e2014-07-27 04:19:32 +00002080 // Abbreviation for EXPR_IMPLICIT_CAST
2081 Abv = new BitCodeAbbrev();
2082 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_IMPLICIT_CAST));
2083 // Stmt
2084 // Expr
2085 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2086 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent
2087 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent
2088 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent
2089 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack
2090 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind
2091 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind
2092 // CastExpr
2093 Abv->Add(BitCodeAbbrevOp(0)); // PathSize
2094 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 6)); // CastKind
2095 // ImplicitCastExpr
2096 ExprImplicitCastAbbrev = Stream.EmitAbbrev(Abv);
2097
Sebastian Redl66c5eef2010-07-27 00:17:23 +00002098 Abv = new BitCodeAbbrev();
Sebastian Redl539c5062010-08-18 23:57:32 +00002099 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL));
Sebastian Redl66c5eef2010-07-27 00:17:23 +00002100 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2101 DeclContextLexicalAbbrev = Stream.EmitAbbrev(Abv);
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002102
2103 Abv = new BitCodeAbbrev();
2104 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE));
Argyrios Kyrtzidisba88bfa2010-08-20 16:04:35 +00002105 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2106 DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(Abv);
Chris Lattner258172e2009-04-27 07:35:58 +00002107}
2108
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002109/// isRequiredDecl - Check if this is a "required" Decl, which must be seen by
2110/// consumers of the AST.
2111///
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002112/// Such decls will always be deserialized from the AST file, so we would like
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002113/// this to be as restrictive as possible. Currently the predicate is driven by
2114/// code generation requirements, if other clients have a different notion of
2115/// what is "required" then we may have to consider an alternate scheme where
2116/// clients can iterate over the top-level decls and get information on them,
2117/// without necessary deserializing them. We could explicitly require such
2118/// clients to use a separate API call to "realize" the decl. This should be
2119/// relatively painless since they would presumably only do it for top-level
2120/// decls.
Richard Smithc52efa72015-08-19 02:30:28 +00002121static bool isRequiredDecl(const Decl *D, ASTContext &Context,
2122 bool WritingModule) {
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00002123 // An ObjCMethodDecl is never considered as "required" because its
2124 // implementation container always is.
2125
Richard Smithc52efa72015-08-19 02:30:28 +00002126 // File scoped assembly or obj-c implementation must be seen.
2127 if (isa<FileScopeAsmDecl>(D) || isa<ObjCImplDecl>(D))
2128 return true;
2129
2130 // ImportDecl is used by codegen to determine the set of imported modules to
2131 // search for inputs for automatic linking; include it if it has a semantic
2132 // effect.
2133 if (isa<ImportDecl>(D) && !WritingModule)
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002134 return true;
2135
Argyrios Kyrtzidisc9049332010-07-29 20:08:05 +00002136 return Context.DeclMustBeEmitted(D);
Daniel Dunbar5bb5ec52009-09-17 03:06:51 +00002137}
2138
Sebastian Redl55c0ad52010-08-18 23:56:21 +00002139void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) {
Argyrios Kyrtzidisd9f526f2010-10-28 09:29:32 +00002140 // Switch case IDs are per Decl.
2141 ClearSwitchCaseIDs();
2142
Chris Lattner7099dbc2009-04-27 06:16:06 +00002143 RecordData Record;
Sebastian Redl42a0f6a2010-08-18 23:56:27 +00002144 ASTDeclWriter W(*this, Context, Record);
Chris Lattner7099dbc2009-04-27 06:16:06 +00002145
Douglas Gregorb3163e52012-01-05 22:33:30 +00002146 // Determine the ID for this declaration.
2147 serialization::DeclID ID;
Douglas Gregor7dd37e52015-11-03 01:20:54 +00002148 assert(!D->isFromASTFile() && "should not be emitting imported decl");
2149 serialization::DeclID &IDR = DeclIDs[D];
2150 if (IDR == 0)
2151 IDR = NextDeclID++;
Douglas Gregorb3163e52012-01-05 22:33:30 +00002152
Douglas Gregor7dd37e52015-11-03 01:20:54 +00002153 ID = IDR;
Argyrios Kyrtzidisbf6c3392012-03-22 16:08:04 +00002154
2155 bool isReplacingADecl = ID < FirstDeclID;
2156
2157 // If this declaration is also a DeclContext, write blocks for the
2158 // declarations that lexically stored inside its context and those
2159 // declarations that are visible from its context. These blocks
2160 // are written before the declaration itself so that we can put
2161 // their offsets into the record for the declaration.
2162 uint64_t LexicalOffset = 0;
2163 uint64_t VisibleOffset = 0;
2164 DeclContext *DC = dyn_cast<DeclContext>(D);
2165 if (DC) {
2166 if (isReplacingADecl) {
2167 // It is replacing a decl from a chained PCH; make sure that the
2168 // DeclContext is fully loaded.
2169 if (DC->hasExternalLexicalStorage())
2170 DC->LoadLexicalDeclsFromExternalStorage();
2171 if (DC->hasExternalVisibleStorage())
2172 Chain->completeVisibleDeclsMap(DC);
2173 }
2174 LexicalOffset = WriteDeclContextLexicalBlock(Context, DC);
2175 VisibleOffset = WriteDeclContextVisibleBlock(Context, DC);
2176 }
Douglas Gregorb3163e52012-01-05 22:33:30 +00002177
Richard Smithd61d4ac2015-08-22 20:13:39 +00002178 // Build a record for this declaration
2179 Record.clear();
2180 W.Code = (serialization::DeclCode)0;
2181 W.AbbrevToUse = 0;
2182 W.Visit(D);
2183 if (DC) W.VisitDeclContext(DC, LexicalOffset, VisibleOffset);
2184
Argyrios Kyrtzidisbf6c3392012-03-22 16:08:04 +00002185 if (isReplacingADecl) {
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002186 // We're replacing a decl in a previous file.
Argyrios Kyrtzidis6fb60032011-10-31 07:20:15 +00002187 ReplacedDecls.push_back(ReplacedDeclInfo(ID, Stream.GetCurrentBitNo(),
2188 D->getLocation()));
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002189 } else {
2190 unsigned Index = ID - FirstDeclID;
Douglas Gregor12bfa382009-10-17 00:13:19 +00002191
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002192 // Record the offset for this declaration
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +00002193 SourceLocation Loc = D->getLocation();
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002194 if (DeclOffsets.size() == Index)
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +00002195 DeclOffsets.push_back(DeclOffset(Loc, Stream.GetCurrentBitNo()));
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002196 else if (DeclOffsets.size() < Index) {
2197 DeclOffsets.resize(Index+1);
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +00002198 DeclOffsets[Index].setLocation(Loc);
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00002199 DeclOffsets[Index].BitOffset = Stream.GetCurrentBitNo();
Sebastian Redle7c1fe62010-08-13 00:28:03 +00002200 }
Richard Smithd61d4ac2015-08-22 20:13:39 +00002201
Argyrios Kyrtzidis5fc727a2011-10-28 22:54:21 +00002202 SourceManager &SM = Context.getSourceManager();
Argyrios Kyrtzidisdf53da82011-10-28 23:57:43 +00002203 if (Loc.isValid() && SM.isLocalSourceLocation(Loc))
2204 associateDeclWithFile(D, ID);
Douglas Gregor12bfa382009-10-17 00:13:19 +00002205 }
2206
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +00002207 if (!W.Code)
Chris Lattner0e62c1c2011-07-23 10:55:15 +00002208 llvm::report_fatal_error(StringRef("unexpected declaration kind '") +
Daniel Dunbarf5bda7b2009-12-03 09:13:36 +00002209 D->getDeclKindName() + "'");
Douglas Gregor12bfa382009-10-17 00:13:19 +00002210 Stream.EmitRecord(W.Code, Record, W.AbbrevToUse);
2211
Richard Smithc2bb8182015-03-24 06:36:48 +00002212 // Flush any expressions, base specifiers, and ctor initializers that
2213 // were written as part of this declaration.
2214 FlushPendingAfterDecl();
2215
Ben Langmuir332aafe2014-01-31 01:06:56 +00002216 // Note declarations that should be deserialized eagerly so that we can add
2217 // them to a record in the AST file later.
Richard Smithc52efa72015-08-19 02:30:28 +00002218 if (isRequiredDecl(D, Context, WritingModule))
Ben Langmuir332aafe2014-01-31 01:06:56 +00002219 EagerlyDeserializedDecls.push_back(ID);
Chris Lattner7099dbc2009-04-27 06:16:06 +00002220}
Richard Smithd28ac5b2014-03-22 23:33:22 +00002221
2222void ASTWriter::AddFunctionDefinition(const FunctionDecl *FD,
2223 RecordData &Record) {
2224 ClearSwitchCaseIDs();
2225
2226 ASTDeclWriter W(*this, FD->getASTContext(), Record);
2227 W.AddFunctionDefinition(FD);
2228}