1 | //===--- ASTWriterDecl.cpp - Declaration Serialization --------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // This file implements serialization for Declarations. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #include "ASTCommon.h" |
14 | #include "clang/AST/Attr.h" |
15 | #include "clang/AST/DeclCXX.h" |
16 | #include "clang/AST/DeclTemplate.h" |
17 | #include "clang/AST/DeclVisitor.h" |
18 | #include "clang/AST/Expr.h" |
19 | #include "clang/AST/OpenMPClause.h" |
20 | #include "clang/AST/PrettyDeclStackTrace.h" |
21 | #include "clang/Basic/SourceManager.h" |
22 | #include "clang/Serialization/ASTReader.h" |
23 | #include "clang/Serialization/ASTRecordWriter.h" |
24 | #include "llvm/Bitstream/BitstreamWriter.h" |
25 | #include "llvm/Support/ErrorHandling.h" |
26 | #include <optional> |
27 | using namespace clang; |
28 | using namespace serialization; |
29 | |
30 | //===----------------------------------------------------------------------===// |
31 | // Utility functions |
32 | //===----------------------------------------------------------------------===// |
33 | |
34 | namespace { |
35 | |
36 | // Helper function that returns true if the decl passed in the argument is |
37 | // a defintion in dependent contxt. |
38 | template <typename DT> bool isDefinitionInDependentContext(DT *D) { |
39 | return D->isDependentContext() && D->isThisDeclarationADefinition(); |
40 | } |
41 | |
42 | } // namespace |
43 | |
44 | //===----------------------------------------------------------------------===// |
45 | // Declaration serialization |
46 | //===----------------------------------------------------------------------===// |
47 | |
48 | namespace clang { |
49 | class ASTDeclWriter : public DeclVisitor<ASTDeclWriter, void> { |
50 | ASTWriter &Writer; |
51 | ASTRecordWriter Record; |
52 | |
53 | serialization::DeclCode Code; |
54 | unsigned AbbrevToUse; |
55 | |
56 | bool GeneratingReducedBMI = false; |
57 | |
58 | public: |
59 | ASTDeclWriter(ASTWriter &Writer, ASTContext &Context, |
60 | ASTWriter::RecordDataImpl &Record, bool GeneratingReducedBMI) |
61 | : Writer(Writer), Record(Context, Writer, Record), |
62 | Code((serialization::DeclCode)0), AbbrevToUse(0), |
63 | GeneratingReducedBMI(GeneratingReducedBMI) {} |
64 | |
65 | uint64_t Emit(Decl *D) { |
66 | if (!Code) |
67 | llvm::report_fatal_error(reason: StringRef("unexpected declaration kind '" ) + |
68 | D->getDeclKindName() + "'" ); |
69 | return Record.Emit(Code, Abbrev: AbbrevToUse); |
70 | } |
71 | |
72 | void Visit(Decl *D); |
73 | |
74 | void VisitDecl(Decl *D); |
75 | void VisitPragmaCommentDecl(PragmaCommentDecl *D); |
76 | void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D); |
77 | void VisitTranslationUnitDecl(TranslationUnitDecl *D); |
78 | void VisitNamedDecl(NamedDecl *D); |
79 | void VisitLabelDecl(LabelDecl *LD); |
80 | void VisitNamespaceDecl(NamespaceDecl *D); |
81 | void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
82 | void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
83 | void VisitTypeDecl(TypeDecl *D); |
84 | void VisitTypedefNameDecl(TypedefNameDecl *D); |
85 | void VisitTypedefDecl(TypedefDecl *D); |
86 | void VisitTypeAliasDecl(TypeAliasDecl *D); |
87 | void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
88 | void VisitUnresolvedUsingIfExistsDecl(UnresolvedUsingIfExistsDecl *D); |
89 | void VisitTagDecl(TagDecl *D); |
90 | void VisitEnumDecl(EnumDecl *D); |
91 | void VisitRecordDecl(RecordDecl *D); |
92 | void VisitCXXRecordDecl(CXXRecordDecl *D); |
93 | void VisitClassTemplateSpecializationDecl( |
94 | ClassTemplateSpecializationDecl *D); |
95 | void VisitClassTemplatePartialSpecializationDecl( |
96 | ClassTemplatePartialSpecializationDecl *D); |
97 | void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D); |
98 | void VisitVarTemplatePartialSpecializationDecl( |
99 | VarTemplatePartialSpecializationDecl *D); |
100 | void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
101 | void VisitValueDecl(ValueDecl *D); |
102 | void VisitEnumConstantDecl(EnumConstantDecl *D); |
103 | void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
104 | void VisitDeclaratorDecl(DeclaratorDecl *D); |
105 | void VisitFunctionDecl(FunctionDecl *D); |
106 | void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D); |
107 | void VisitCXXMethodDecl(CXXMethodDecl *D); |
108 | void VisitCXXConstructorDecl(CXXConstructorDecl *D); |
109 | void VisitCXXDestructorDecl(CXXDestructorDecl *D); |
110 | void VisitCXXConversionDecl(CXXConversionDecl *D); |
111 | void VisitFieldDecl(FieldDecl *D); |
112 | void VisitMSPropertyDecl(MSPropertyDecl *D); |
113 | void VisitMSGuidDecl(MSGuidDecl *D); |
114 | void VisitUnnamedGlobalConstantDecl(UnnamedGlobalConstantDecl *D); |
115 | void VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D); |
116 | void VisitIndirectFieldDecl(IndirectFieldDecl *D); |
117 | void VisitVarDecl(VarDecl *D); |
118 | void VisitImplicitParamDecl(ImplicitParamDecl *D); |
119 | void VisitParmVarDecl(ParmVarDecl *D); |
120 | void VisitDecompositionDecl(DecompositionDecl *D); |
121 | void VisitBindingDecl(BindingDecl *D); |
122 | void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
123 | void VisitTemplateDecl(TemplateDecl *D); |
124 | void VisitConceptDecl(ConceptDecl *D); |
125 | void VisitImplicitConceptSpecializationDecl( |
126 | ImplicitConceptSpecializationDecl *D); |
127 | void VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D); |
128 | void VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D); |
129 | void VisitClassTemplateDecl(ClassTemplateDecl *D); |
130 | void VisitVarTemplateDecl(VarTemplateDecl *D); |
131 | void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
132 | void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
133 | void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
134 | void VisitUsingDecl(UsingDecl *D); |
135 | void VisitUsingEnumDecl(UsingEnumDecl *D); |
136 | void VisitUsingPackDecl(UsingPackDecl *D); |
137 | void VisitUsingShadowDecl(UsingShadowDecl *D); |
138 | void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D); |
139 | void VisitLinkageSpecDecl(LinkageSpecDecl *D); |
140 | void VisitExportDecl(ExportDecl *D); |
141 | void VisitFileScopeAsmDecl(FileScopeAsmDecl *D); |
142 | void VisitTopLevelStmtDecl(TopLevelStmtDecl *D); |
143 | void VisitImportDecl(ImportDecl *D); |
144 | void VisitAccessSpecDecl(AccessSpecDecl *D); |
145 | void VisitFriendDecl(FriendDecl *D); |
146 | void VisitFriendTemplateDecl(FriendTemplateDecl *D); |
147 | void VisitStaticAssertDecl(StaticAssertDecl *D); |
148 | void VisitBlockDecl(BlockDecl *D); |
149 | void VisitOutlinedFunctionDecl(OutlinedFunctionDecl *D); |
150 | void VisitCapturedDecl(CapturedDecl *D); |
151 | void VisitEmptyDecl(EmptyDecl *D); |
152 | void VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D); |
153 | void VisitDeclContext(DeclContext *DC); |
154 | template <typename T> void VisitRedeclarable(Redeclarable<T> *D); |
155 | void VisitHLSLBufferDecl(HLSLBufferDecl *D); |
156 | |
157 | // FIXME: Put in the same order is DeclNodes.td? |
158 | void VisitObjCMethodDecl(ObjCMethodDecl *D); |
159 | void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
160 | void VisitObjCContainerDecl(ObjCContainerDecl *D); |
161 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
162 | void VisitObjCIvarDecl(ObjCIvarDecl *D); |
163 | void VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
164 | void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D); |
165 | void VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
166 | void VisitObjCImplDecl(ObjCImplDecl *D); |
167 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
168 | void VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
169 | void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); |
170 | void VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
171 | void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
172 | void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D); |
173 | void VisitOMPAllocateDecl(OMPAllocateDecl *D); |
174 | void VisitOMPRequiresDecl(OMPRequiresDecl *D); |
175 | void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D); |
176 | void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D); |
177 | void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D); |
178 | |
179 | void VisitOpenACCDeclareDecl(OpenACCDeclareDecl *D); |
180 | void VisitOpenACCRoutineDecl(OpenACCRoutineDecl *D); |
181 | |
182 | /// Add an Objective-C type parameter list to the given record. |
183 | void AddObjCTypeParamList(ObjCTypeParamList *typeParams) { |
184 | // Empty type parameter list. |
185 | if (!typeParams) { |
186 | Record.push_back(N: 0); |
187 | return; |
188 | } |
189 | |
190 | Record.push_back(N: typeParams->size()); |
191 | for (auto *typeParam : *typeParams) { |
192 | Record.AddDeclRef(typeParam); |
193 | } |
194 | Record.AddSourceLocation(Loc: typeParams->getLAngleLoc()); |
195 | Record.AddSourceLocation(Loc: typeParams->getRAngleLoc()); |
196 | } |
197 | |
198 | /// Collect the first declaration from each module file that provides a |
199 | /// declaration of D. |
200 | void CollectFirstDeclFromEachModule( |
201 | const Decl *D, bool IncludeLocal, |
202 | llvm::MapVector<ModuleFile *, const Decl *> &Firsts) { |
203 | |
204 | // FIXME: We can skip entries that we know are implied by others. |
205 | for (const Decl *R = D->getMostRecentDecl(); R; R = R->getPreviousDecl()) { |
206 | if (R->isFromASTFile()) |
207 | Firsts[Writer.Chain->getOwningModuleFile(D: R)] = R; |
208 | else if (IncludeLocal) |
209 | Firsts[nullptr] = R; |
210 | } |
211 | } |
212 | |
213 | /// Add to the record the first declaration from each module file that |
214 | /// provides a declaration of D. The intent is to provide a sufficient |
215 | /// set such that reloading this set will load all current redeclarations. |
216 | void AddFirstDeclFromEachModule(const Decl *D, bool IncludeLocal) { |
217 | llvm::MapVector<ModuleFile *, const Decl *> Firsts; |
218 | CollectFirstDeclFromEachModule(D, IncludeLocal, Firsts); |
219 | |
220 | for (const auto &F : Firsts) |
221 | Record.AddDeclRef(D: F.second); |
222 | } |
223 | |
224 | /// Add to the record the first template specialization from each module |
225 | /// file that provides a declaration of D. We store the DeclId and an |
226 | /// ODRHash of the template arguments of D which should provide enough |
227 | /// information to load D only if the template instantiator needs it. |
228 | void AddFirstSpecializationDeclFromEachModule( |
229 | const Decl *D, llvm::SmallVectorImpl<const Decl *> &SpecsInMap, |
230 | llvm::SmallVectorImpl<const Decl *> &PartialSpecsInMap) { |
231 | assert((isa<ClassTemplateSpecializationDecl>(D) || |
232 | isa<VarTemplateSpecializationDecl>(D) || isa<FunctionDecl>(D)) && |
233 | "Must not be called with other decls" ); |
234 | llvm::MapVector<ModuleFile *, const Decl *> Firsts; |
235 | CollectFirstDeclFromEachModule(D, /*IncludeLocal*/ true, Firsts); |
236 | |
237 | for (const auto &F : Firsts) { |
238 | if (isa<ClassTemplatePartialSpecializationDecl, |
239 | VarTemplatePartialSpecializationDecl>(Val: F.second)) |
240 | PartialSpecsInMap.push_back(Elt: F.second); |
241 | else |
242 | SpecsInMap.push_back(Elt: F.second); |
243 | } |
244 | } |
245 | |
246 | /// Get the specialization decl from an entry in the specialization list. |
247 | template <typename EntryType> |
248 | typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType * |
249 | getSpecializationDecl(EntryType &T) { |
250 | return RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::getDecl(&T); |
251 | } |
252 | |
253 | /// Get the list of partial specializations from a template's common ptr. |
254 | template<typename T> |
255 | decltype(T::PartialSpecializations) &getPartialSpecializations(T *Common) { |
256 | return Common->PartialSpecializations; |
257 | } |
258 | MutableArrayRef<FunctionTemplateSpecializationInfo> |
259 | getPartialSpecializations(FunctionTemplateDecl::Common *) { |
260 | return std::nullopt; |
261 | } |
262 | |
263 | template<typename DeclTy> |
264 | void AddTemplateSpecializations(DeclTy *D) { |
265 | auto *Common = D->getCommonPtr(); |
266 | |
267 | // If we have any lazy specializations, and the external AST source is |
268 | // our chained AST reader, we can just write out the DeclIDs. Otherwise, |
269 | // we need to resolve them to actual declarations. |
270 | if (Writer.Chain != Record.getASTContext().getExternalSource() && |
271 | Writer.Chain && Writer.Chain->haveUnloadedSpecializations(D)) { |
272 | D->LoadLazySpecializations(); |
273 | assert(!Writer.Chain->haveUnloadedSpecializations(D)); |
274 | } |
275 | |
276 | // AddFirstSpecializationDeclFromEachModule might trigger deserialization, |
277 | // invalidating *Specializations iterators. |
278 | llvm::SmallVector<const Decl *, 16> AllSpecs; |
279 | for (auto &Entry : Common->Specializations) |
280 | AllSpecs.push_back(Elt: getSpecializationDecl(Entry)); |
281 | for (auto &Entry : getPartialSpecializations(Common)) |
282 | AllSpecs.push_back(Elt: getSpecializationDecl(Entry)); |
283 | |
284 | llvm::SmallVector<const Decl *, 16> Specs; |
285 | llvm::SmallVector<const Decl *, 16> PartialSpecs; |
286 | for (auto *D : AllSpecs) { |
287 | assert(D->isCanonicalDecl() && "non-canonical decl in set" ); |
288 | AddFirstSpecializationDeclFromEachModule(D, SpecsInMap&: Specs, PartialSpecsInMap&: PartialSpecs); |
289 | } |
290 | |
291 | Record.AddOffset(BitOffset: Writer.WriteSpecializationInfoLookupTable( |
292 | D, Specializations&: Specs, /*IsPartial=*/false)); |
293 | |
294 | // Function Template Decl doesn't have partial decls. |
295 | if (isa<FunctionTemplateDecl>(D)) { |
296 | assert(PartialSpecs.empty()); |
297 | return; |
298 | } |
299 | |
300 | Record.AddOffset(BitOffset: Writer.WriteSpecializationInfoLookupTable( |
301 | D, Specializations&: PartialSpecs, /*IsPartial=*/true)); |
302 | } |
303 | |
304 | /// Ensure that this template specialization is associated with the specified |
305 | /// template on reload. |
306 | void RegisterTemplateSpecialization(const Decl *Template, |
307 | const Decl *Specialization) { |
308 | Template = Template->getCanonicalDecl(); |
309 | |
310 | // If the canonical template is local, we'll write out this specialization |
311 | // when we emit it. |
312 | // FIXME: We can do the same thing if there is any local declaration of |
313 | // the template, to avoid emitting an update record. |
314 | if (!Template->isFromASTFile()) |
315 | return; |
316 | |
317 | // We only need to associate the first local declaration of the |
318 | // specialization. The other declarations will get pulled in by it. |
319 | if (Writer.getFirstLocalDecl(D: Specialization) != Specialization) |
320 | return; |
321 | |
322 | if (isa<ClassTemplatePartialSpecializationDecl, |
323 | VarTemplatePartialSpecializationDecl>(Val: Specialization)) |
324 | Writer.PartialSpecializationsUpdates[cast<NamedDecl>(Val: Template)] |
325 | .push_back(cast<NamedDecl>(Val: Specialization)); |
326 | else |
327 | Writer.SpecializationsUpdates[cast<NamedDecl>(Val: Template)].push_back( |
328 | cast<NamedDecl>(Val: Specialization)); |
329 | } |
330 | }; |
331 | } |
332 | |
333 | // When building a C++20 module interface unit or a partition unit, a |
334 | // strong definition in the module interface is provided by the |
335 | // compilation of that unit, not by its users. (Inline variables are still |
336 | // emitted in module users.) |
337 | static bool shouldVarGenerateHereOnly(const VarDecl *VD) { |
338 | if (VD->getStorageDuration() != SD_Static) |
339 | return false; |
340 | |
341 | if (VD->getDescribedVarTemplate()) |
342 | return false; |
343 | |
344 | Module *M = VD->getOwningModule(); |
345 | if (!M) |
346 | return false; |
347 | |
348 | M = M->getTopLevelModule(); |
349 | ASTContext &Ctx = VD->getASTContext(); |
350 | if (!M->isInterfaceOrPartition() && |
351 | (!VD->hasAttr<DLLExportAttr>() || |
352 | !Ctx.getLangOpts().BuildingPCHWithObjectFile)) |
353 | return false; |
354 | |
355 | return Ctx.GetGVALinkageForVariable(VD) >= GVA_StrongExternal; |
356 | } |
357 | |
358 | static bool shouldFunctionGenerateHereOnly(const FunctionDecl *FD) { |
359 | if (FD->isDependentContext()) |
360 | return false; |
361 | |
362 | ASTContext &Ctx = FD->getASTContext(); |
363 | auto Linkage = Ctx.GetGVALinkageForFunction(FD); |
364 | if (Ctx.getLangOpts().ModulesCodegen || |
365 | (FD->hasAttr<DLLExportAttr>() && |
366 | Ctx.getLangOpts().BuildingPCHWithObjectFile)) |
367 | // Under -fmodules-codegen, codegen is performed for all non-internal, |
368 | // non-always_inline functions, unless they are available elsewhere. |
369 | if (!FD->hasAttr<AlwaysInlineAttr>() && Linkage != GVA_Internal && |
370 | Linkage != GVA_AvailableExternally) |
371 | return true; |
372 | |
373 | Module *M = FD->getOwningModule(); |
374 | if (!M) |
375 | return false; |
376 | |
377 | M = M->getTopLevelModule(); |
378 | if (M->isInterfaceOrPartition()) |
379 | if (Linkage >= GVA_StrongExternal) |
380 | return true; |
381 | |
382 | return false; |
383 | } |
384 | |
385 | bool clang::CanElideDeclDef(const Decl *D) { |
386 | if (auto *FD = dyn_cast<FunctionDecl>(Val: D)) { |
387 | if (FD->isInlined() || FD->isConstexpr() || FD->isConsteval()) |
388 | return false; |
389 | |
390 | // If the function should be generated somewhere else, we shouldn't elide |
391 | // it. |
392 | if (!shouldFunctionGenerateHereOnly(FD)) |
393 | return false; |
394 | } |
395 | |
396 | if (auto *VD = dyn_cast<VarDecl>(Val: D)) { |
397 | if (VD->getDeclContext()->isDependentContext()) |
398 | return false; |
399 | |
400 | // Constant initialized variable may not affect the ABI, but they |
401 | // may be used in constant evaluation in the frontend, so we have |
402 | // to remain them. |
403 | if (VD->hasConstantInitialization() || VD->isConstexpr()) |
404 | return false; |
405 | |
406 | // If the variable should be generated somewhere else, we shouldn't elide |
407 | // it. |
408 | if (!shouldVarGenerateHereOnly(VD)) |
409 | return false; |
410 | } |
411 | |
412 | return true; |
413 | } |
414 | |
415 | void ASTDeclWriter::Visit(Decl *D) { |
416 | DeclVisitor<ASTDeclWriter>::Visit(D); |
417 | |
418 | // Source locations require array (variable-length) abbreviations. The |
419 | // abbreviation infrastructure requires that arrays are encoded last, so |
420 | // we handle it here in the case of those classes derived from DeclaratorDecl |
421 | if (auto *DD = dyn_cast<DeclaratorDecl>(Val: D)) { |
422 | if (auto *TInfo = DD->getTypeSourceInfo()) |
423 | Record.AddTypeLoc(TL: TInfo->getTypeLoc()); |
424 | } |
425 | |
426 | // Handle FunctionDecl's body here and write it after all other Stmts/Exprs |
427 | // have been written. We want it last because we will not read it back when |
428 | // retrieving it from the AST, we'll just lazily set the offset. |
429 | if (auto *FD = dyn_cast<FunctionDecl>(Val: D)) { |
430 | if (!GeneratingReducedBMI || !CanElideDeclDef(FD)) { |
431 | Record.push_back(N: FD->doesThisDeclarationHaveABody()); |
432 | if (FD->doesThisDeclarationHaveABody()) |
433 | Record.AddFunctionDefinition(FD); |
434 | } else |
435 | Record.push_back(N: 0); |
436 | } |
437 | |
438 | // Similar to FunctionDecls, handle VarDecl's initializer here and write it |
439 | // after all other Stmts/Exprs. We will not read the initializer until after |
440 | // we have finished recursive deserialization, because it can recursively |
441 | // refer back to the variable. |
442 | if (auto *VD = dyn_cast<VarDecl>(Val: D)) { |
443 | if (!GeneratingReducedBMI || !CanElideDeclDef(VD)) |
444 | Record.AddVarDeclInit(VD); |
445 | else |
446 | Record.push_back(N: 0); |
447 | } |
448 | |
449 | // And similarly for FieldDecls. We already serialized whether there is a |
450 | // default member initializer. |
451 | if (auto *FD = dyn_cast<FieldDecl>(Val: D)) { |
452 | if (FD->hasInClassInitializer()) { |
453 | if (Expr *Init = FD->getInClassInitializer()) { |
454 | Record.push_back(N: 1); |
455 | Record.AddStmt(Init); |
456 | } else { |
457 | Record.push_back(N: 0); |
458 | // Initializer has not been instantiated yet. |
459 | } |
460 | } |
461 | } |
462 | |
463 | // If this declaration is also a DeclContext, write blocks for the |
464 | // declarations that lexically stored inside its context and those |
465 | // declarations that are visible from its context. |
466 | if (auto *DC = dyn_cast<DeclContext>(Val: D)) |
467 | VisitDeclContext(DC); |
468 | } |
469 | |
470 | void ASTDeclWriter::VisitDecl(Decl *D) { |
471 | BitsPacker DeclBits; |
472 | |
473 | // The order matters here. It will be better to put the bit with higher |
474 | // probability to be 0 in the end of the bits. |
475 | // |
476 | // Since we're using VBR6 format to store it. |
477 | // It will be pretty effient if all the higher bits are 0. |
478 | // For example, if we need to pack 8 bits into a value and the stored value |
479 | // is 0xf0, the actual stored value will be 0b000111'110000, which takes 12 |
480 | // bits actually. However, if we changed the order to be 0x0f, then we can |
481 | // store it as 0b001111, which takes 6 bits only now. |
482 | DeclBits.addBits(Value: (uint64_t)D->getModuleOwnershipKind(), /*BitWidth=*/BitsWidth: 3); |
483 | DeclBits.addBit(Value: D->isReferenced()); |
484 | DeclBits.addBit(Value: D->isUsed(CheckUsedAttr: false)); |
485 | DeclBits.addBits(Value: D->getAccess(), /*BitWidth=*/BitsWidth: 2); |
486 | DeclBits.addBit(Value: D->isImplicit()); |
487 | DeclBits.addBit(Value: D->getDeclContext() != D->getLexicalDeclContext()); |
488 | DeclBits.addBit(Value: D->hasAttrs()); |
489 | DeclBits.addBit(Value: D->isTopLevelDeclInObjCContainer()); |
490 | DeclBits.addBit(Value: D->isInvalidDecl()); |
491 | Record.push_back(N: DeclBits); |
492 | |
493 | Record.AddDeclRef(D: cast_or_null<Decl>(Val: D->getDeclContext())); |
494 | if (D->getDeclContext() != D->getLexicalDeclContext()) |
495 | Record.AddDeclRef(D: cast_or_null<Decl>(Val: D->getLexicalDeclContext())); |
496 | |
497 | if (D->hasAttrs()) |
498 | Record.AddAttributes(Attrs: D->getAttrs()); |
499 | |
500 | Record.push_back(N: Writer.getSubmoduleID(Mod: D->getOwningModule())); |
501 | |
502 | // If this declaration injected a name into a context different from its |
503 | // lexical context, and that context is an imported namespace, we need to |
504 | // update its visible declarations to include this name. |
505 | // |
506 | // This happens when we instantiate a class with a friend declaration or a |
507 | // function with a local extern declaration, for instance. |
508 | // |
509 | // FIXME: Can we handle this in AddedVisibleDecl instead? |
510 | if (D->isOutOfLine()) { |
511 | auto *DC = D->getDeclContext(); |
512 | while (auto *NS = dyn_cast<NamespaceDecl>(Val: DC->getRedeclContext())) { |
513 | if (!NS->isFromASTFile()) |
514 | break; |
515 | Writer.UpdatedDeclContexts.insert(NS->getPrimaryContext()); |
516 | if (!NS->isInlineNamespace()) |
517 | break; |
518 | DC = NS->getParent(); |
519 | } |
520 | } |
521 | } |
522 | |
523 | void ASTDeclWriter::(PragmaCommentDecl *D) { |
524 | StringRef Arg = D->getArg(); |
525 | Record.push_back(N: Arg.size()); |
526 | VisitDecl(D); |
527 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
528 | Record.push_back(N: D->getCommentKind()); |
529 | Record.AddString(Str: Arg); |
530 | Code = serialization::DECL_PRAGMA_COMMENT; |
531 | } |
532 | |
533 | void ASTDeclWriter::VisitPragmaDetectMismatchDecl( |
534 | PragmaDetectMismatchDecl *D) { |
535 | StringRef Name = D->getName(); |
536 | StringRef Value = D->getValue(); |
537 | Record.push_back(N: Name.size() + 1 + Value.size()); |
538 | VisitDecl(D); |
539 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
540 | Record.AddString(Str: Name); |
541 | Record.AddString(Str: Value); |
542 | Code = serialization::DECL_PRAGMA_DETECT_MISMATCH; |
543 | } |
544 | |
545 | void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { |
546 | llvm_unreachable("Translation units aren't directly serialized" ); |
547 | } |
548 | |
549 | void ASTDeclWriter::VisitNamedDecl(NamedDecl *D) { |
550 | VisitDecl(D); |
551 | Record.AddDeclarationName(Name: D->getDeclName()); |
552 | Record.push_back(N: needsAnonymousDeclarationNumber(D) |
553 | ? Writer.getAnonymousDeclarationNumber(D) |
554 | : 0); |
555 | } |
556 | |
557 | void ASTDeclWriter::VisitTypeDecl(TypeDecl *D) { |
558 | VisitNamedDecl(D); |
559 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
560 | Record.AddTypeRef(T: QualType(D->getTypeForDecl(), 0)); |
561 | } |
562 | |
563 | void ASTDeclWriter::VisitTypedefNameDecl(TypedefNameDecl *D) { |
564 | VisitRedeclarable(D); |
565 | VisitTypeDecl(D); |
566 | Record.AddTypeSourceInfo(TInfo: D->getTypeSourceInfo()); |
567 | Record.push_back(N: D->isModed()); |
568 | if (D->isModed()) |
569 | Record.AddTypeRef(T: D->getUnderlyingType()); |
570 | Record.AddDeclRef(D->getAnonDeclWithTypedefName(AnyRedecl: false)); |
571 | } |
572 | |
573 | void ASTDeclWriter::VisitTypedefDecl(TypedefDecl *D) { |
574 | VisitTypedefNameDecl(D); |
575 | if (D->getDeclContext() == D->getLexicalDeclContext() && |
576 | !D->hasAttrs() && |
577 | !D->isImplicit() && |
578 | D->getFirstDecl() == D->getMostRecentDecl() && |
579 | !D->isInvalidDecl() && |
580 | !D->isTopLevelDeclInObjCContainer() && |
581 | !D->isModulePrivate() && |
582 | !needsAnonymousDeclarationNumber(D) && |
583 | D->getDeclName().getNameKind() == DeclarationName::Identifier) |
584 | AbbrevToUse = Writer.getDeclTypedefAbbrev(); |
585 | |
586 | Code = serialization::DECL_TYPEDEF; |
587 | } |
588 | |
589 | void ASTDeclWriter::VisitTypeAliasDecl(TypeAliasDecl *D) { |
590 | VisitTypedefNameDecl(D); |
591 | Record.AddDeclRef(D->getDescribedAliasTemplate()); |
592 | Code = serialization::DECL_TYPEALIAS; |
593 | } |
594 | |
595 | void ASTDeclWriter::VisitTagDecl(TagDecl *D) { |
596 | static_assert(DeclContext::NumTagDeclBits == 23, |
597 | "You need to update the serializer after you change the " |
598 | "TagDeclBits" ); |
599 | |
600 | VisitRedeclarable(D); |
601 | VisitTypeDecl(D); |
602 | Record.push_back(N: D->getIdentifierNamespace()); |
603 | |
604 | BitsPacker TagDeclBits; |
605 | TagDeclBits.addBits(Value: llvm::to_underlying(E: D->getTagKind()), /*BitWidth=*/BitsWidth: 3); |
606 | TagDeclBits.addBit(Value: !isa<CXXRecordDecl>(Val: D) ? D->isCompleteDefinition() : 0); |
607 | TagDeclBits.addBit(Value: D->isEmbeddedInDeclarator()); |
608 | TagDeclBits.addBit(Value: D->isFreeStanding()); |
609 | TagDeclBits.addBit(Value: D->isCompleteDefinitionRequired()); |
610 | TagDeclBits.addBits( |
611 | Value: D->hasExtInfo() ? 1 : (D->getTypedefNameForAnonDecl() ? 2 : 0), |
612 | /*BitWidth=*/BitsWidth: 2); |
613 | Record.push_back(N: TagDeclBits); |
614 | |
615 | Record.AddSourceRange(Range: D->getBraceRange()); |
616 | |
617 | if (D->hasExtInfo()) { |
618 | Record.AddQualifierInfo(Info: *D->getExtInfo()); |
619 | } else if (auto *TD = D->getTypedefNameForAnonDecl()) { |
620 | Record.AddDeclRef(TD); |
621 | Record.AddIdentifierRef(II: TD->getDeclName().getAsIdentifierInfo()); |
622 | } |
623 | } |
624 | |
625 | void ASTDeclWriter::VisitEnumDecl(EnumDecl *D) { |
626 | static_assert(DeclContext::NumEnumDeclBits == 43, |
627 | "You need to update the serializer after you change the " |
628 | "EnumDeclBits" ); |
629 | |
630 | VisitTagDecl(D); |
631 | Record.AddTypeSourceInfo(TInfo: D->getIntegerTypeSourceInfo()); |
632 | if (!D->getIntegerTypeSourceInfo()) |
633 | Record.AddTypeRef(T: D->getIntegerType()); |
634 | Record.AddTypeRef(T: D->getPromotionType()); |
635 | |
636 | BitsPacker EnumDeclBits; |
637 | EnumDeclBits.addBits(Value: D->getNumPositiveBits(), /*BitWidth=*/BitsWidth: 8); |
638 | EnumDeclBits.addBits(Value: D->getNumNegativeBits(), /*BitWidth=*/BitsWidth: 8); |
639 | EnumDeclBits.addBit(Value: D->isScoped()); |
640 | EnumDeclBits.addBit(Value: D->isScopedUsingClassTag()); |
641 | EnumDeclBits.addBit(Value: D->isFixed()); |
642 | Record.push_back(N: EnumDeclBits); |
643 | |
644 | Record.push_back(N: D->getODRHash()); |
645 | |
646 | if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) { |
647 | Record.AddDeclRef(MemberInfo->getInstantiatedFrom()); |
648 | Record.push_back(N: MemberInfo->getTemplateSpecializationKind()); |
649 | Record.AddSourceLocation(Loc: MemberInfo->getPointOfInstantiation()); |
650 | } else { |
651 | Record.AddDeclRef(D: nullptr); |
652 | } |
653 | |
654 | if (D->getDeclContext() == D->getLexicalDeclContext() && !D->hasAttrs() && |
655 | !D->isInvalidDecl() && !D->isImplicit() && !D->hasExtInfo() && |
656 | !D->getTypedefNameForAnonDecl() && |
657 | D->getFirstDecl() == D->getMostRecentDecl() && |
658 | !D->isTopLevelDeclInObjCContainer() && |
659 | !CXXRecordDecl::classofKind(K: D->getKind()) && |
660 | !D->getIntegerTypeSourceInfo() && !D->getMemberSpecializationInfo() && |
661 | !needsAnonymousDeclarationNumber(D) && |
662 | D->getDeclName().getNameKind() == DeclarationName::Identifier) |
663 | AbbrevToUse = Writer.getDeclEnumAbbrev(); |
664 | |
665 | Code = serialization::DECL_ENUM; |
666 | } |
667 | |
668 | void ASTDeclWriter::VisitRecordDecl(RecordDecl *D) { |
669 | static_assert(DeclContext::NumRecordDeclBits == 64, |
670 | "You need to update the serializer after you change the " |
671 | "RecordDeclBits" ); |
672 | |
673 | VisitTagDecl(D); |
674 | |
675 | BitsPacker RecordDeclBits; |
676 | RecordDeclBits.addBit(Value: D->hasFlexibleArrayMember()); |
677 | RecordDeclBits.addBit(Value: D->isAnonymousStructOrUnion()); |
678 | RecordDeclBits.addBit(Value: D->hasObjectMember()); |
679 | RecordDeclBits.addBit(Value: D->hasVolatileMember()); |
680 | RecordDeclBits.addBit(Value: D->isNonTrivialToPrimitiveDefaultInitialize()); |
681 | RecordDeclBits.addBit(Value: D->isNonTrivialToPrimitiveCopy()); |
682 | RecordDeclBits.addBit(Value: D->isNonTrivialToPrimitiveDestroy()); |
683 | RecordDeclBits.addBit(Value: D->hasNonTrivialToPrimitiveDefaultInitializeCUnion()); |
684 | RecordDeclBits.addBit(Value: D->hasNonTrivialToPrimitiveDestructCUnion()); |
685 | RecordDeclBits.addBit(Value: D->hasNonTrivialToPrimitiveCopyCUnion()); |
686 | RecordDeclBits.addBit(Value: D->hasUninitializedExplicitInitFields()); |
687 | RecordDeclBits.addBit(Value: D->isParamDestroyedInCallee()); |
688 | RecordDeclBits.addBits(Value: llvm::to_underlying(E: D->getArgPassingRestrictions()), BitsWidth: 2); |
689 | Record.push_back(N: RecordDeclBits); |
690 | |
691 | // Only compute this for C/Objective-C, in C++ this is computed as part |
692 | // of CXXRecordDecl. |
693 | if (!isa<CXXRecordDecl>(Val: D)) |
694 | Record.push_back(N: D->getODRHash()); |
695 | |
696 | if (D->getDeclContext() == D->getLexicalDeclContext() && !D->hasAttrs() && |
697 | !D->isImplicit() && !D->isInvalidDecl() && !D->hasExtInfo() && |
698 | !D->getTypedefNameForAnonDecl() && |
699 | D->getFirstDecl() == D->getMostRecentDecl() && |
700 | !D->isTopLevelDeclInObjCContainer() && |
701 | !CXXRecordDecl::classofKind(K: D->getKind()) && |
702 | !needsAnonymousDeclarationNumber(D) && |
703 | D->getDeclName().getNameKind() == DeclarationName::Identifier) |
704 | AbbrevToUse = Writer.getDeclRecordAbbrev(); |
705 | |
706 | Code = serialization::DECL_RECORD; |
707 | } |
708 | |
709 | void ASTDeclWriter::VisitValueDecl(ValueDecl *D) { |
710 | VisitNamedDecl(D); |
711 | Record.AddTypeRef(T: D->getType()); |
712 | } |
713 | |
714 | void ASTDeclWriter::VisitEnumConstantDecl(EnumConstantDecl *D) { |
715 | VisitValueDecl(D); |
716 | Record.push_back(N: D->getInitExpr()? 1 : 0); |
717 | if (D->getInitExpr()) |
718 | Record.AddStmt(D->getInitExpr()); |
719 | Record.AddAPSInt(Value: D->getInitVal()); |
720 | |
721 | Code = serialization::DECL_ENUM_CONSTANT; |
722 | } |
723 | |
724 | void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) { |
725 | VisitValueDecl(D); |
726 | Record.AddSourceLocation(Loc: D->getInnerLocStart()); |
727 | Record.push_back(N: D->hasExtInfo()); |
728 | if (D->hasExtInfo()) { |
729 | DeclaratorDecl::ExtInfo *Info = D->getExtInfo(); |
730 | Record.AddQualifierInfo(Info: *Info); |
731 | Record.AddStmt( |
732 | const_cast<Expr *>(Info->TrailingRequiresClause.ConstraintExpr)); |
733 | Record.writeUnsignedOrNone(Value: Info->TrailingRequiresClause.ArgPackSubstIndex); |
734 | } |
735 | // The location information is deferred until the end of the record. |
736 | Record.AddTypeRef(T: D->getTypeSourceInfo() ? D->getTypeSourceInfo()->getType() |
737 | : QualType()); |
738 | } |
739 | |
740 | void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) { |
741 | static_assert(DeclContext::NumFunctionDeclBits == 45, |
742 | "You need to update the serializer after you change the " |
743 | "FunctionDeclBits" ); |
744 | |
745 | VisitRedeclarable(D); |
746 | |
747 | Record.push_back(N: D->getTemplatedKind()); |
748 | switch (D->getTemplatedKind()) { |
749 | case FunctionDecl::TK_NonTemplate: |
750 | break; |
751 | case FunctionDecl::TK_DependentNonTemplate: |
752 | Record.AddDeclRef(D->getInstantiatedFromDecl()); |
753 | break; |
754 | case FunctionDecl::TK_FunctionTemplate: |
755 | Record.AddDeclRef(D->getDescribedFunctionTemplate()); |
756 | break; |
757 | case FunctionDecl::TK_MemberSpecialization: { |
758 | MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo(); |
759 | Record.AddDeclRef(MemberInfo->getInstantiatedFrom()); |
760 | Record.push_back(N: MemberInfo->getTemplateSpecializationKind()); |
761 | Record.AddSourceLocation(Loc: MemberInfo->getPointOfInstantiation()); |
762 | break; |
763 | } |
764 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
765 | FunctionTemplateSpecializationInfo * |
766 | FTSInfo = D->getTemplateSpecializationInfo(); |
767 | |
768 | RegisterTemplateSpecialization(FTSInfo->getTemplate(), D); |
769 | |
770 | Record.AddDeclRef(FTSInfo->getTemplate()); |
771 | Record.push_back(N: FTSInfo->getTemplateSpecializationKind()); |
772 | |
773 | // Template arguments. |
774 | Record.AddTemplateArgumentList(TemplateArgs: FTSInfo->TemplateArguments); |
775 | |
776 | // Template args as written. |
777 | Record.push_back(N: FTSInfo->TemplateArgumentsAsWritten != nullptr); |
778 | if (FTSInfo->TemplateArgumentsAsWritten) |
779 | Record.AddASTTemplateArgumentListInfo( |
780 | ASTTemplArgList: FTSInfo->TemplateArgumentsAsWritten); |
781 | |
782 | Record.AddSourceLocation(Loc: FTSInfo->getPointOfInstantiation()); |
783 | |
784 | if (MemberSpecializationInfo *MemberInfo = |
785 | FTSInfo->getMemberSpecializationInfo()) { |
786 | Record.push_back(N: 1); |
787 | Record.AddDeclRef(MemberInfo->getInstantiatedFrom()); |
788 | Record.push_back(N: MemberInfo->getTemplateSpecializationKind()); |
789 | Record.AddSourceLocation(Loc: MemberInfo->getPointOfInstantiation()); |
790 | } else { |
791 | Record.push_back(N: 0); |
792 | } |
793 | |
794 | if (D->isCanonicalDecl()) { |
795 | // Write the template that contains the specializations set. We will |
796 | // add a FunctionTemplateSpecializationInfo to it when reading. |
797 | Record.AddDeclRef(FTSInfo->getTemplate()->getCanonicalDecl()); |
798 | } |
799 | break; |
800 | } |
801 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
802 | DependentFunctionTemplateSpecializationInfo * |
803 | DFTSInfo = D->getDependentSpecializationInfo(); |
804 | |
805 | // Candidates. |
806 | Record.push_back(N: DFTSInfo->getCandidates().size()); |
807 | for (FunctionTemplateDecl *FTD : DFTSInfo->getCandidates()) |
808 | Record.AddDeclRef(FTD); |
809 | |
810 | // Templates args. |
811 | Record.push_back(N: DFTSInfo->TemplateArgumentsAsWritten != nullptr); |
812 | if (DFTSInfo->TemplateArgumentsAsWritten) |
813 | Record.AddASTTemplateArgumentListInfo( |
814 | ASTTemplArgList: DFTSInfo->TemplateArgumentsAsWritten); |
815 | break; |
816 | } |
817 | } |
818 | |
819 | VisitDeclaratorDecl(D); |
820 | Record.AddDeclarationNameLoc(DNLoc: D->DNLoc, Name: D->getDeclName()); |
821 | Record.push_back(N: D->getIdentifierNamespace()); |
822 | |
823 | // The order matters here. It will be better to put the bit with higher |
824 | // probability to be 0 in the end of the bits. See the comments in VisitDecl |
825 | // for details. |
826 | BitsPacker FunctionDeclBits; |
827 | // FIXME: stable encoding |
828 | FunctionDeclBits.addBits(Value: llvm::to_underlying(D->getLinkageInternal()), BitsWidth: 3); |
829 | FunctionDeclBits.addBits(Value: (uint32_t)D->getStorageClass(), /*BitWidth=*/BitsWidth: 3); |
830 | FunctionDeclBits.addBit(Value: D->isInlineSpecified()); |
831 | FunctionDeclBits.addBit(Value: D->isInlined()); |
832 | FunctionDeclBits.addBit(Value: D->hasSkippedBody()); |
833 | FunctionDeclBits.addBit(Value: D->isVirtualAsWritten()); |
834 | FunctionDeclBits.addBit(Value: D->isPureVirtual()); |
835 | FunctionDeclBits.addBit(Value: D->hasInheritedPrototype()); |
836 | FunctionDeclBits.addBit(Value: D->hasWrittenPrototype()); |
837 | FunctionDeclBits.addBit(Value: D->isDeletedBit()); |
838 | FunctionDeclBits.addBit(Value: D->isTrivial()); |
839 | FunctionDeclBits.addBit(Value: D->isTrivialForCall()); |
840 | FunctionDeclBits.addBit(Value: D->isDefaulted()); |
841 | FunctionDeclBits.addBit(Value: D->isExplicitlyDefaulted()); |
842 | FunctionDeclBits.addBit(Value: D->isIneligibleOrNotSelected()); |
843 | FunctionDeclBits.addBits(Value: (uint64_t)(D->getConstexprKind()), /*BitWidth=*/BitsWidth: 2); |
844 | FunctionDeclBits.addBit(Value: D->hasImplicitReturnZero()); |
845 | FunctionDeclBits.addBit(Value: D->isMultiVersion()); |
846 | FunctionDeclBits.addBit(Value: D->isLateTemplateParsed()); |
847 | FunctionDeclBits.addBit(Value: D->isInstantiatedFromMemberTemplate()); |
848 | FunctionDeclBits.addBit(Value: D->FriendConstraintRefersToEnclosingTemplate()); |
849 | FunctionDeclBits.addBit(Value: D->usesSEHTry()); |
850 | FunctionDeclBits.addBit(Value: D->isDestroyingOperatorDelete()); |
851 | FunctionDeclBits.addBit(Value: D->isTypeAwareOperatorNewOrDelete()); |
852 | Record.push_back(N: FunctionDeclBits); |
853 | |
854 | Record.AddSourceLocation(Loc: D->getEndLoc()); |
855 | if (D->isExplicitlyDefaulted()) |
856 | Record.AddSourceLocation(Loc: D->getDefaultLoc()); |
857 | |
858 | Record.push_back(N: D->getODRHash()); |
859 | |
860 | if (D->isDefaulted() || D->isDeletedAsWritten()) { |
861 | if (auto *FDI = D->getDefalutedOrDeletedInfo()) { |
862 | // Store both that there is an DefaultedOrDeletedInfo and whether it |
863 | // contains a DeletedMessage. |
864 | StringLiteral *DeletedMessage = FDI->getDeletedMessage(); |
865 | Record.push_back(N: 1 | (DeletedMessage ? 2 : 0)); |
866 | if (DeletedMessage) |
867 | Record.AddStmt(DeletedMessage); |
868 | |
869 | Record.push_back(N: FDI->getUnqualifiedLookups().size()); |
870 | for (DeclAccessPair P : FDI->getUnqualifiedLookups()) { |
871 | Record.AddDeclRef(P.getDecl()); |
872 | Record.push_back(N: P.getAccess()); |
873 | } |
874 | } else { |
875 | Record.push_back(N: 0); |
876 | } |
877 | } |
878 | |
879 | if (D->getFriendObjectKind()) { |
880 | // For a friend function defined inline within a class template, we have to |
881 | // force the definition to be the one inside the definition of the template |
882 | // class. Remember this relation to deserialize them together. |
883 | if (auto *RD = dyn_cast<CXXRecordDecl>(D->getLexicalParent()); |
884 | RD && isDefinitionInDependentContext(RD)) { |
885 | Writer.RelatedDeclsMap[Writer.GetDeclRef(D: RD)].push_back( |
886 | Writer.GetDeclRef(D)); |
887 | } |
888 | } |
889 | |
890 | Record.push_back(N: D->param_size()); |
891 | for (auto *P : D->parameters()) |
892 | Record.AddDeclRef(P); |
893 | Code = serialization::DECL_FUNCTION; |
894 | } |
895 | |
896 | static void addExplicitSpecifier(ExplicitSpecifier ES, |
897 | ASTRecordWriter &Record) { |
898 | uint64_t Kind = static_cast<uint64_t>(ES.getKind()); |
899 | Kind = Kind << 1 | static_cast<bool>(ES.getExpr()); |
900 | Record.push_back(N: Kind); |
901 | if (ES.getExpr()) { |
902 | Record.AddStmt(ES.getExpr()); |
903 | } |
904 | } |
905 | |
906 | void ASTDeclWriter::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) { |
907 | addExplicitSpecifier(ES: D->getExplicitSpecifier(), Record); |
908 | Record.AddDeclRef(D->Ctor); |
909 | VisitFunctionDecl(D); |
910 | Record.push_back(N: static_cast<unsigned char>(D->getDeductionCandidateKind())); |
911 | Record.AddDeclRef(D->getSourceDeductionGuide()); |
912 | Record.push_back( |
913 | N: static_cast<unsigned char>(D->getSourceDeductionGuideKind())); |
914 | Code = serialization::DECL_CXX_DEDUCTION_GUIDE; |
915 | } |
916 | |
917 | void ASTDeclWriter::VisitObjCMethodDecl(ObjCMethodDecl *D) { |
918 | static_assert(DeclContext::NumObjCMethodDeclBits == 37, |
919 | "You need to update the serializer after you change the " |
920 | "ObjCMethodDeclBits" ); |
921 | |
922 | VisitNamedDecl(D); |
923 | // FIXME: convert to LazyStmtPtr? |
924 | // Unlike C/C++, method bodies will never be in header files. |
925 | bool HasBodyStuff = D->getBody() != nullptr; |
926 | Record.push_back(N: HasBodyStuff); |
927 | if (HasBodyStuff) { |
928 | Record.AddStmt(S: D->getBody()); |
929 | } |
930 | Record.AddDeclRef(D->getSelfDecl()); |
931 | Record.AddDeclRef(D->getCmdDecl()); |
932 | Record.push_back(N: D->isInstanceMethod()); |
933 | Record.push_back(N: D->isVariadic()); |
934 | Record.push_back(N: D->isPropertyAccessor()); |
935 | Record.push_back(N: D->isSynthesizedAccessorStub()); |
936 | Record.push_back(N: D->isDefined()); |
937 | Record.push_back(N: D->isOverriding()); |
938 | Record.push_back(N: D->hasSkippedBody()); |
939 | |
940 | Record.push_back(N: D->isRedeclaration()); |
941 | Record.push_back(N: D->hasRedeclaration()); |
942 | if (D->hasRedeclaration()) { |
943 | assert(Record.getASTContext().getObjCMethodRedeclaration(D)); |
944 | Record.AddDeclRef(D: Record.getASTContext().getObjCMethodRedeclaration(D)); |
945 | } |
946 | |
947 | // FIXME: stable encoding for @required/@optional |
948 | Record.push_back(N: llvm::to_underlying(E: D->getImplementationControl())); |
949 | // FIXME: stable encoding for in/out/inout/bycopy/byref/oneway/nullability |
950 | Record.push_back(N: D->getObjCDeclQualifier()); |
951 | Record.push_back(N: D->hasRelatedResultType()); |
952 | Record.AddTypeRef(T: D->getReturnType()); |
953 | Record.AddTypeSourceInfo(TInfo: D->getReturnTypeSourceInfo()); |
954 | Record.AddSourceLocation(Loc: D->getEndLoc()); |
955 | Record.push_back(N: D->param_size()); |
956 | for (const auto *P : D->parameters()) |
957 | Record.AddDeclRef(P); |
958 | |
959 | Record.push_back(N: D->getSelLocsKind()); |
960 | unsigned NumStoredSelLocs = D->getNumStoredSelLocs(); |
961 | SourceLocation *SelLocs = D->getStoredSelLocs(); |
962 | Record.push_back(N: NumStoredSelLocs); |
963 | for (unsigned i = 0; i != NumStoredSelLocs; ++i) |
964 | Record.AddSourceLocation(Loc: SelLocs[i]); |
965 | |
966 | Code = serialization::DECL_OBJC_METHOD; |
967 | } |
968 | |
969 | void ASTDeclWriter::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
970 | VisitTypedefNameDecl(D); |
971 | Record.push_back(N: D->Variance); |
972 | Record.push_back(N: D->Index); |
973 | Record.AddSourceLocation(Loc: D->VarianceLoc); |
974 | Record.AddSourceLocation(Loc: D->ColonLoc); |
975 | |
976 | Code = serialization::DECL_OBJC_TYPE_PARAM; |
977 | } |
978 | |
979 | void ASTDeclWriter::VisitObjCContainerDecl(ObjCContainerDecl *D) { |
980 | static_assert(DeclContext::NumObjCContainerDeclBits == 64, |
981 | "You need to update the serializer after you change the " |
982 | "ObjCContainerDeclBits" ); |
983 | |
984 | VisitNamedDecl(D); |
985 | Record.AddSourceLocation(Loc: D->getAtStartLoc()); |
986 | Record.AddSourceRange(Range: D->getAtEndRange()); |
987 | // Abstract class (no need to define a stable serialization::DECL code). |
988 | } |
989 | |
990 | void ASTDeclWriter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *D) { |
991 | VisitRedeclarable(D); |
992 | VisitObjCContainerDecl(D); |
993 | Record.AddTypeRef(T: QualType(D->getTypeForDecl(), 0)); |
994 | AddObjCTypeParamList(typeParams: D->TypeParamList); |
995 | |
996 | Record.push_back(N: D->isThisDeclarationADefinition()); |
997 | if (D->isThisDeclarationADefinition()) { |
998 | // Write the DefinitionData |
999 | ObjCInterfaceDecl::DefinitionData &Data = D->data(); |
1000 | |
1001 | Record.AddTypeSourceInfo(TInfo: D->getSuperClassTInfo()); |
1002 | Record.AddSourceLocation(Loc: D->getEndOfDefinitionLoc()); |
1003 | Record.push_back(N: Data.HasDesignatedInitializers); |
1004 | Record.push_back(N: D->getODRHash()); |
1005 | |
1006 | // Write out the protocols that are directly referenced by the @interface. |
1007 | Record.push_back(N: Data.ReferencedProtocols.size()); |
1008 | for (const auto *P : D->protocols()) |
1009 | Record.AddDeclRef(P); |
1010 | for (const auto &PL : D->protocol_locs()) |
1011 | Record.AddSourceLocation(Loc: PL); |
1012 | |
1013 | // Write out the protocols that are transitively referenced. |
1014 | Record.push_back(N: Data.AllReferencedProtocols.size()); |
1015 | for (ObjCList<ObjCProtocolDecl>::iterator |
1016 | P = Data.AllReferencedProtocols.begin(), |
1017 | PEnd = Data.AllReferencedProtocols.end(); |
1018 | P != PEnd; ++P) |
1019 | Record.AddDeclRef(*P); |
1020 | |
1021 | |
1022 | if (ObjCCategoryDecl *Cat = D->getCategoryListRaw()) { |
1023 | // Ensure that we write out the set of categories for this class. |
1024 | Writer.ObjCClassesWithCategories.insert(X: D); |
1025 | |
1026 | // Make sure that the categories get serialized. |
1027 | for (; Cat; Cat = Cat->getNextClassCategoryRaw()) |
1028 | (void)Writer.GetDeclRef(Cat); |
1029 | } |
1030 | } |
1031 | |
1032 | Code = serialization::DECL_OBJC_INTERFACE; |
1033 | } |
1034 | |
1035 | void ASTDeclWriter::VisitObjCIvarDecl(ObjCIvarDecl *D) { |
1036 | VisitFieldDecl(D); |
1037 | // FIXME: stable encoding for @public/@private/@protected/@package |
1038 | Record.push_back(N: D->getAccessControl()); |
1039 | Record.push_back(N: D->getSynthesize()); |
1040 | |
1041 | if (D->getDeclContext() == D->getLexicalDeclContext() && |
1042 | !D->hasAttrs() && |
1043 | !D->isImplicit() && |
1044 | !D->isUsed(false) && |
1045 | !D->isInvalidDecl() && |
1046 | !D->isReferenced() && |
1047 | !D->isModulePrivate() && |
1048 | !D->getBitWidth() && |
1049 | !D->hasExtInfo() && |
1050 | D->getDeclName()) |
1051 | AbbrevToUse = Writer.getDeclObjCIvarAbbrev(); |
1052 | |
1053 | Code = serialization::DECL_OBJC_IVAR; |
1054 | } |
1055 | |
1056 | void ASTDeclWriter::VisitObjCProtocolDecl(ObjCProtocolDecl *D) { |
1057 | VisitRedeclarable(D); |
1058 | VisitObjCContainerDecl(D); |
1059 | |
1060 | Record.push_back(N: D->isThisDeclarationADefinition()); |
1061 | if (D->isThisDeclarationADefinition()) { |
1062 | Record.push_back(N: D->protocol_size()); |
1063 | for (const auto *I : D->protocols()) |
1064 | Record.AddDeclRef(I); |
1065 | for (const auto &PL : D->protocol_locs()) |
1066 | Record.AddSourceLocation(Loc: PL); |
1067 | Record.push_back(N: D->getODRHash()); |
1068 | } |
1069 | |
1070 | Code = serialization::DECL_OBJC_PROTOCOL; |
1071 | } |
1072 | |
1073 | void ASTDeclWriter::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D) { |
1074 | VisitFieldDecl(D); |
1075 | Code = serialization::DECL_OBJC_AT_DEFS_FIELD; |
1076 | } |
1077 | |
1078 | void ASTDeclWriter::VisitObjCCategoryDecl(ObjCCategoryDecl *D) { |
1079 | VisitObjCContainerDecl(D); |
1080 | Record.AddSourceLocation(Loc: D->getCategoryNameLoc()); |
1081 | Record.AddSourceLocation(Loc: D->getIvarLBraceLoc()); |
1082 | Record.AddSourceLocation(Loc: D->getIvarRBraceLoc()); |
1083 | Record.AddDeclRef(D->getClassInterface()); |
1084 | AddObjCTypeParamList(typeParams: D->TypeParamList); |
1085 | Record.push_back(N: D->protocol_size()); |
1086 | for (const auto *I : D->protocols()) |
1087 | Record.AddDeclRef(I); |
1088 | for (const auto &PL : D->protocol_locs()) |
1089 | Record.AddSourceLocation(Loc: PL); |
1090 | Code = serialization::DECL_OBJC_CATEGORY; |
1091 | } |
1092 | |
1093 | void ASTDeclWriter::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D) { |
1094 | VisitNamedDecl(D); |
1095 | Record.AddDeclRef(D->getClassInterface()); |
1096 | Code = serialization::DECL_OBJC_COMPATIBLE_ALIAS; |
1097 | } |
1098 | |
1099 | void ASTDeclWriter::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
1100 | VisitNamedDecl(D); |
1101 | Record.AddSourceLocation(Loc: D->getAtLoc()); |
1102 | Record.AddSourceLocation(Loc: D->getLParenLoc()); |
1103 | Record.AddTypeRef(T: D->getType()); |
1104 | Record.AddTypeSourceInfo(TInfo: D->getTypeSourceInfo()); |
1105 | // FIXME: stable encoding |
1106 | Record.push_back(N: (unsigned)D->getPropertyAttributes()); |
1107 | Record.push_back(N: (unsigned)D->getPropertyAttributesAsWritten()); |
1108 | // FIXME: stable encoding |
1109 | Record.push_back(N: (unsigned)D->getPropertyImplementation()); |
1110 | Record.AddDeclarationName(Name: D->getGetterName()); |
1111 | Record.AddSourceLocation(Loc: D->getGetterNameLoc()); |
1112 | Record.AddDeclarationName(Name: D->getSetterName()); |
1113 | Record.AddSourceLocation(Loc: D->getSetterNameLoc()); |
1114 | Record.AddDeclRef(D->getGetterMethodDecl()); |
1115 | Record.AddDeclRef(D->getSetterMethodDecl()); |
1116 | Record.AddDeclRef(D->getPropertyIvarDecl()); |
1117 | Code = serialization::DECL_OBJC_PROPERTY; |
1118 | } |
1119 | |
1120 | void ASTDeclWriter::VisitObjCImplDecl(ObjCImplDecl *D) { |
1121 | VisitObjCContainerDecl(D); |
1122 | Record.AddDeclRef(D->getClassInterface()); |
1123 | // Abstract class (no need to define a stable serialization::DECL code). |
1124 | } |
1125 | |
1126 | void ASTDeclWriter::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
1127 | VisitObjCImplDecl(D); |
1128 | Record.AddSourceLocation(Loc: D->getCategoryNameLoc()); |
1129 | Code = serialization::DECL_OBJC_CATEGORY_IMPL; |
1130 | } |
1131 | |
1132 | void ASTDeclWriter::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
1133 | VisitObjCImplDecl(D); |
1134 | Record.AddDeclRef(D->getSuperClass()); |
1135 | Record.AddSourceLocation(Loc: D->getSuperClassLoc()); |
1136 | Record.AddSourceLocation(Loc: D->getIvarLBraceLoc()); |
1137 | Record.AddSourceLocation(Loc: D->getIvarRBraceLoc()); |
1138 | Record.push_back(N: D->hasNonZeroConstructors()); |
1139 | Record.push_back(N: D->hasDestructors()); |
1140 | Record.push_back(N: D->NumIvarInitializers); |
1141 | if (D->NumIvarInitializers) |
1142 | Record.AddCXXCtorInitializers( |
1143 | CtorInits: llvm::ArrayRef(D->init_begin(), D->init_end())); |
1144 | Code = serialization::DECL_OBJC_IMPLEMENTATION; |
1145 | } |
1146 | |
1147 | void ASTDeclWriter::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
1148 | VisitDecl(D); |
1149 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
1150 | Record.AddDeclRef(D->getPropertyDecl()); |
1151 | Record.AddDeclRef(D->getPropertyIvarDecl()); |
1152 | Record.AddSourceLocation(Loc: D->getPropertyIvarDeclLoc()); |
1153 | Record.AddDeclRef(D->getGetterMethodDecl()); |
1154 | Record.AddDeclRef(D->getSetterMethodDecl()); |
1155 | Record.AddStmt(D->getGetterCXXConstructor()); |
1156 | Record.AddStmt(D->getSetterCXXAssignment()); |
1157 | Code = serialization::DECL_OBJC_PROPERTY_IMPL; |
1158 | } |
1159 | |
1160 | void ASTDeclWriter::VisitFieldDecl(FieldDecl *D) { |
1161 | VisitDeclaratorDecl(D); |
1162 | Record.push_back(N: D->isMutable()); |
1163 | |
1164 | Record.push_back(N: (D->StorageKind << 1) | D->BitField); |
1165 | if (D->StorageKind == FieldDecl::ISK_CapturedVLAType) |
1166 | Record.AddTypeRef(T: QualType(D->getCapturedVLAType(), 0)); |
1167 | else if (D->BitField) |
1168 | Record.AddStmt(D->getBitWidth()); |
1169 | |
1170 | if (!D->getDeclName() || D->isPlaceholderVar(Writer.getLangOpts())) |
1171 | Record.AddDeclRef( |
1172 | D: Record.getASTContext().getInstantiatedFromUnnamedFieldDecl(D)); |
1173 | |
1174 | if (D->getDeclContext() == D->getLexicalDeclContext() && |
1175 | !D->hasAttrs() && |
1176 | !D->isImplicit() && |
1177 | !D->isUsed(false) && |
1178 | !D->isInvalidDecl() && |
1179 | !D->isReferenced() && |
1180 | !D->isTopLevelDeclInObjCContainer() && |
1181 | !D->isModulePrivate() && |
1182 | !D->getBitWidth() && |
1183 | !D->hasInClassInitializer() && |
1184 | !D->hasCapturedVLAType() && |
1185 | !D->hasExtInfo() && |
1186 | !ObjCIvarDecl::classofKind(K: D->getKind()) && |
1187 | !ObjCAtDefsFieldDecl::classofKind(K: D->getKind()) && |
1188 | D->getDeclName()) |
1189 | AbbrevToUse = Writer.getDeclFieldAbbrev(); |
1190 | |
1191 | Code = serialization::DECL_FIELD; |
1192 | } |
1193 | |
1194 | void ASTDeclWriter::VisitMSPropertyDecl(MSPropertyDecl *D) { |
1195 | VisitDeclaratorDecl(D); |
1196 | Record.AddIdentifierRef(II: D->getGetterId()); |
1197 | Record.AddIdentifierRef(II: D->getSetterId()); |
1198 | Code = serialization::DECL_MS_PROPERTY; |
1199 | } |
1200 | |
1201 | void ASTDeclWriter::VisitMSGuidDecl(MSGuidDecl *D) { |
1202 | VisitValueDecl(D); |
1203 | MSGuidDecl::Parts Parts = D->getParts(); |
1204 | Record.push_back(N: Parts.Part1); |
1205 | Record.push_back(N: Parts.Part2); |
1206 | Record.push_back(N: Parts.Part3); |
1207 | Record.append(begin: std::begin(arr&: Parts.Part4And5), end: std::end(arr&: Parts.Part4And5)); |
1208 | Code = serialization::DECL_MS_GUID; |
1209 | } |
1210 | |
1211 | void ASTDeclWriter::VisitUnnamedGlobalConstantDecl( |
1212 | UnnamedGlobalConstantDecl *D) { |
1213 | VisitValueDecl(D); |
1214 | Record.AddAPValue(Value: D->getValue()); |
1215 | Code = serialization::DECL_UNNAMED_GLOBAL_CONSTANT; |
1216 | } |
1217 | |
1218 | void ASTDeclWriter::VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D) { |
1219 | VisitValueDecl(D); |
1220 | Record.AddAPValue(Value: D->getValue()); |
1221 | Code = serialization::DECL_TEMPLATE_PARAM_OBJECT; |
1222 | } |
1223 | |
1224 | void ASTDeclWriter::VisitIndirectFieldDecl(IndirectFieldDecl *D) { |
1225 | VisitValueDecl(D); |
1226 | Record.push_back(N: D->getChainingSize()); |
1227 | |
1228 | for (const auto *P : D->chain()) |
1229 | Record.AddDeclRef(P); |
1230 | Code = serialization::DECL_INDIRECTFIELD; |
1231 | } |
1232 | |
1233 | void ASTDeclWriter::VisitVarDecl(VarDecl *D) { |
1234 | VisitRedeclarable(D); |
1235 | VisitDeclaratorDecl(D); |
1236 | |
1237 | // The order matters here. It will be better to put the bit with higher |
1238 | // probability to be 0 in the end of the bits. See the comments in VisitDecl |
1239 | // for details. |
1240 | BitsPacker VarDeclBits; |
1241 | VarDeclBits.addBits(Value: llvm::to_underlying(D->getLinkageInternal()), |
1242 | /*BitWidth=*/BitsWidth: 3); |
1243 | |
1244 | bool ModulesCodegen = shouldVarGenerateHereOnly(VD: D); |
1245 | VarDeclBits.addBit(Value: ModulesCodegen); |
1246 | |
1247 | VarDeclBits.addBits(Value: D->getStorageClass(), /*BitWidth=*/BitsWidth: 3); |
1248 | VarDeclBits.addBits(Value: D->getTSCSpec(), /*BitWidth=*/BitsWidth: 2); |
1249 | VarDeclBits.addBits(Value: D->getInitStyle(), /*BitWidth=*/BitsWidth: 2); |
1250 | VarDeclBits.addBit(Value: D->isARCPseudoStrong()); |
1251 | |
1252 | bool HasDeducedType = false; |
1253 | if (!isa<ParmVarDecl>(Val: D)) { |
1254 | VarDeclBits.addBit(Value: D->isThisDeclarationADemotedDefinition()); |
1255 | VarDeclBits.addBit(Value: D->isExceptionVariable()); |
1256 | VarDeclBits.addBit(Value: D->isNRVOVariable()); |
1257 | VarDeclBits.addBit(Value: D->isCXXForRangeDecl()); |
1258 | |
1259 | VarDeclBits.addBit(Value: D->isInline()); |
1260 | VarDeclBits.addBit(Value: D->isInlineSpecified()); |
1261 | VarDeclBits.addBit(Value: D->isConstexpr()); |
1262 | VarDeclBits.addBit(Value: D->isInitCapture()); |
1263 | VarDeclBits.addBit(Value: D->isPreviousDeclInSameBlockScope()); |
1264 | |
1265 | VarDeclBits.addBit(Value: D->isEscapingByref()); |
1266 | HasDeducedType = D->getType()->getContainedDeducedType(); |
1267 | VarDeclBits.addBit(Value: HasDeducedType); |
1268 | |
1269 | if (const auto *IPD = dyn_cast<ImplicitParamDecl>(Val: D)) |
1270 | VarDeclBits.addBits(Value: llvm::to_underlying(E: IPD->getParameterKind()), |
1271 | /*Width=*/BitsWidth: 3); |
1272 | else |
1273 | VarDeclBits.addBits(Value: 0, /*Width=*/BitsWidth: 3); |
1274 | |
1275 | VarDeclBits.addBit(Value: D->isObjCForDecl()); |
1276 | } |
1277 | |
1278 | Record.push_back(N: VarDeclBits); |
1279 | |
1280 | if (ModulesCodegen) |
1281 | Writer.AddDeclRef(D, Writer.ModularCodegenDecls); |
1282 | |
1283 | if (D->hasAttr<BlocksAttr>()) { |
1284 | BlockVarCopyInit Init = Record.getASTContext().getBlockVarCopyInit(D); |
1285 | Record.AddStmt(Init.getCopyExpr()); |
1286 | if (Init.getCopyExpr()) |
1287 | Record.push_back(N: Init.canThrow()); |
1288 | } |
1289 | |
1290 | enum { |
1291 | VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization |
1292 | }; |
1293 | if (VarTemplateDecl *TemplD = D->getDescribedVarTemplate()) { |
1294 | Record.push_back(N: VarTemplate); |
1295 | Record.AddDeclRef(TemplD); |
1296 | } else if (MemberSpecializationInfo *SpecInfo |
1297 | = D->getMemberSpecializationInfo()) { |
1298 | Record.push_back(N: StaticDataMemberSpecialization); |
1299 | Record.AddDeclRef(SpecInfo->getInstantiatedFrom()); |
1300 | Record.push_back(N: SpecInfo->getTemplateSpecializationKind()); |
1301 | Record.AddSourceLocation(Loc: SpecInfo->getPointOfInstantiation()); |
1302 | } else { |
1303 | Record.push_back(N: VarNotTemplate); |
1304 | } |
1305 | |
1306 | if (D->getDeclContext() == D->getLexicalDeclContext() && !D->hasAttrs() && |
1307 | !D->isTopLevelDeclInObjCContainer() && |
1308 | !needsAnonymousDeclarationNumber(D) && |
1309 | D->getDeclName().getNameKind() == DeclarationName::Identifier && |
1310 | !D->hasExtInfo() && D->getFirstDecl() == D->getMostRecentDecl() && |
1311 | D->getKind() == Decl::Var && !D->isInline() && !D->isConstexpr() && |
1312 | !D->isInitCapture() && !D->isPreviousDeclInSameBlockScope() && |
1313 | !D->isEscapingByref() && !HasDeducedType && |
1314 | D->getStorageDuration() != SD_Static && !D->getDescribedVarTemplate() && |
1315 | !D->getMemberSpecializationInfo() && !D->isObjCForDecl() && |
1316 | !isa<ImplicitParamDecl>(D) && !D->isEscapingByref()) |
1317 | AbbrevToUse = Writer.getDeclVarAbbrev(); |
1318 | |
1319 | Code = serialization::DECL_VAR; |
1320 | } |
1321 | |
1322 | void ASTDeclWriter::VisitImplicitParamDecl(ImplicitParamDecl *D) { |
1323 | VisitVarDecl(D); |
1324 | Code = serialization::DECL_IMPLICIT_PARAM; |
1325 | } |
1326 | |
1327 | void ASTDeclWriter::VisitParmVarDecl(ParmVarDecl *D) { |
1328 | VisitVarDecl(D); |
1329 | |
1330 | // See the implementation of `ParmVarDecl::getParameterIndex()`, which may |
1331 | // exceed the size of the normal bitfield. So it may be better to not pack |
1332 | // these bits. |
1333 | Record.push_back(N: D->getFunctionScopeIndex()); |
1334 | |
1335 | BitsPacker ParmVarDeclBits; |
1336 | ParmVarDeclBits.addBit(Value: D->isObjCMethodParameter()); |
1337 | ParmVarDeclBits.addBits(Value: D->getFunctionScopeDepth(), /*BitsWidth=*/7); |
1338 | // FIXME: stable encoding |
1339 | ParmVarDeclBits.addBits(Value: D->getObjCDeclQualifier(), /*BitsWidth=*/7); |
1340 | ParmVarDeclBits.addBit(Value: D->isKNRPromoted()); |
1341 | ParmVarDeclBits.addBit(Value: D->hasInheritedDefaultArg()); |
1342 | ParmVarDeclBits.addBit(Value: D->hasUninstantiatedDefaultArg()); |
1343 | ParmVarDeclBits.addBit(Value: D->getExplicitObjectParamThisLoc().isValid()); |
1344 | Record.push_back(N: ParmVarDeclBits); |
1345 | |
1346 | if (D->hasUninstantiatedDefaultArg()) |
1347 | Record.AddStmt(D->getUninstantiatedDefaultArg()); |
1348 | if (D->getExplicitObjectParamThisLoc().isValid()) |
1349 | Record.AddSourceLocation(Loc: D->getExplicitObjectParamThisLoc()); |
1350 | Code = serialization::DECL_PARM_VAR; |
1351 | |
1352 | // If the assumptions about the DECL_PARM_VAR abbrev are true, use it. Here |
1353 | // we dynamically check for the properties that we optimize for, but don't |
1354 | // know are true of all PARM_VAR_DECLs. |
1355 | if (D->getDeclContext() == D->getLexicalDeclContext() && !D->hasAttrs() && |
1356 | !D->hasExtInfo() && D->getStorageClass() == 0 && !D->isInvalidDecl() && |
1357 | !D->isTopLevelDeclInObjCContainer() && |
1358 | D->getInitStyle() == VarDecl::CInit && // Can params have anything else? |
1359 | D->getInit() == nullptr) // No default expr. |
1360 | AbbrevToUse = Writer.getDeclParmVarAbbrev(); |
1361 | |
1362 | // Check things we know are true of *every* PARM_VAR_DECL, which is more than |
1363 | // just us assuming it. |
1364 | assert(!D->getTSCSpec() && "PARM_VAR_DECL can't use TLS" ); |
1365 | assert(!D->isThisDeclarationADemotedDefinition() |
1366 | && "PARM_VAR_DECL can't be demoted definition." ); |
1367 | assert(D->getAccess() == AS_none && "PARM_VAR_DECL can't be public/private" ); |
1368 | assert(!D->isExceptionVariable() && "PARM_VAR_DECL can't be exception var" ); |
1369 | assert(D->getPreviousDecl() == nullptr && "PARM_VAR_DECL can't be redecl" ); |
1370 | assert(!D->isStaticDataMember() && |
1371 | "PARM_VAR_DECL can't be static data member" ); |
1372 | } |
1373 | |
1374 | void ASTDeclWriter::VisitDecompositionDecl(DecompositionDecl *D) { |
1375 | // Record the number of bindings first to simplify deserialization. |
1376 | Record.push_back(N: D->bindings().size()); |
1377 | |
1378 | VisitVarDecl(D); |
1379 | for (auto *B : D->bindings()) |
1380 | Record.AddDeclRef(B); |
1381 | Code = serialization::DECL_DECOMPOSITION; |
1382 | } |
1383 | |
1384 | void ASTDeclWriter::VisitBindingDecl(BindingDecl *D) { |
1385 | VisitValueDecl(D); |
1386 | Record.AddStmt(D->getBinding()); |
1387 | Code = serialization::DECL_BINDING; |
1388 | } |
1389 | |
1390 | void ASTDeclWriter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) { |
1391 | VisitDecl(D); |
1392 | Record.AddStmt(D->getAsmStringExpr()); |
1393 | Record.AddSourceLocation(Loc: D->getRParenLoc()); |
1394 | Code = serialization::DECL_FILE_SCOPE_ASM; |
1395 | } |
1396 | |
1397 | void ASTDeclWriter::VisitTopLevelStmtDecl(TopLevelStmtDecl *D) { |
1398 | VisitDecl(D); |
1399 | Record.AddStmt(S: D->getStmt()); |
1400 | Code = serialization::DECL_TOP_LEVEL_STMT_DECL; |
1401 | } |
1402 | |
1403 | void ASTDeclWriter::VisitEmptyDecl(EmptyDecl *D) { |
1404 | VisitDecl(D); |
1405 | Code = serialization::DECL_EMPTY; |
1406 | } |
1407 | |
1408 | void ASTDeclWriter::VisitLifetimeExtendedTemporaryDecl( |
1409 | LifetimeExtendedTemporaryDecl *D) { |
1410 | VisitDecl(D); |
1411 | Record.AddDeclRef(D->getExtendingDecl()); |
1412 | Record.AddStmt(D->getTemporaryExpr()); |
1413 | Record.push_back(N: static_cast<bool>(D->getValue())); |
1414 | if (D->getValue()) |
1415 | Record.AddAPValue(Value: *D->getValue()); |
1416 | Record.push_back(N: D->getManglingNumber()); |
1417 | Code = serialization::DECL_LIFETIME_EXTENDED_TEMPORARY; |
1418 | } |
1419 | void ASTDeclWriter::VisitBlockDecl(BlockDecl *D) { |
1420 | VisitDecl(D); |
1421 | Record.AddStmt(S: D->getBody()); |
1422 | Record.AddTypeSourceInfo(TInfo: D->getSignatureAsWritten()); |
1423 | Record.push_back(N: D->param_size()); |
1424 | for (ParmVarDecl *P : D->parameters()) |
1425 | Record.AddDeclRef(P); |
1426 | Record.push_back(N: D->isVariadic()); |
1427 | Record.push_back(N: D->blockMissingReturnType()); |
1428 | Record.push_back(N: D->isConversionFromLambda()); |
1429 | Record.push_back(N: D->doesNotEscape()); |
1430 | Record.push_back(N: D->canAvoidCopyToHeap()); |
1431 | Record.push_back(N: D->capturesCXXThis()); |
1432 | Record.push_back(N: D->getNumCaptures()); |
1433 | for (const auto &capture : D->captures()) { |
1434 | Record.AddDeclRef(capture.getVariable()); |
1435 | |
1436 | unsigned flags = 0; |
1437 | if (capture.isByRef()) flags |= 1; |
1438 | if (capture.isNested()) flags |= 2; |
1439 | if (capture.hasCopyExpr()) flags |= 4; |
1440 | Record.push_back(N: flags); |
1441 | |
1442 | if (capture.hasCopyExpr()) Record.AddStmt(capture.getCopyExpr()); |
1443 | } |
1444 | |
1445 | Code = serialization::DECL_BLOCK; |
1446 | } |
1447 | |
1448 | void ASTDeclWriter::VisitOutlinedFunctionDecl(OutlinedFunctionDecl *D) { |
1449 | Record.push_back(N: D->getNumParams()); |
1450 | VisitDecl(D); |
1451 | for (unsigned I = 0; I < D->getNumParams(); ++I) |
1452 | Record.AddDeclRef(D->getParam(i: I)); |
1453 | Record.push_back(N: D->isNothrow() ? 1 : 0); |
1454 | Record.AddStmt(S: D->getBody()); |
1455 | Code = serialization::DECL_OUTLINEDFUNCTION; |
1456 | } |
1457 | |
1458 | void ASTDeclWriter::VisitCapturedDecl(CapturedDecl *CD) { |
1459 | Record.push_back(N: CD->getNumParams()); |
1460 | VisitDecl(CD); |
1461 | Record.push_back(N: CD->getContextParamPosition()); |
1462 | Record.push_back(N: CD->isNothrow() ? 1 : 0); |
1463 | // Body is stored by VisitCapturedStmt. |
1464 | for (unsigned I = 0; I < CD->getNumParams(); ++I) |
1465 | Record.AddDeclRef(CD->getParam(i: I)); |
1466 | Code = serialization::DECL_CAPTURED; |
1467 | } |
1468 | |
1469 | void ASTDeclWriter::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
1470 | static_assert(DeclContext::NumLinkageSpecDeclBits == 17, |
1471 | "You need to update the serializer after you change the" |
1472 | "LinkageSpecDeclBits" ); |
1473 | |
1474 | VisitDecl(D); |
1475 | Record.push_back(N: llvm::to_underlying(E: D->getLanguage())); |
1476 | Record.AddSourceLocation(Loc: D->getExternLoc()); |
1477 | Record.AddSourceLocation(Loc: D->getRBraceLoc()); |
1478 | Code = serialization::DECL_LINKAGE_SPEC; |
1479 | } |
1480 | |
1481 | void ASTDeclWriter::VisitExportDecl(ExportDecl *D) { |
1482 | VisitDecl(D); |
1483 | Record.AddSourceLocation(Loc: D->getRBraceLoc()); |
1484 | Code = serialization::DECL_EXPORT; |
1485 | } |
1486 | |
1487 | void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) { |
1488 | VisitNamedDecl(D); |
1489 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
1490 | Code = serialization::DECL_LABEL; |
1491 | } |
1492 | |
1493 | |
1494 | void ASTDeclWriter::VisitNamespaceDecl(NamespaceDecl *D) { |
1495 | VisitRedeclarable(D); |
1496 | VisitNamedDecl(D); |
1497 | |
1498 | BitsPacker NamespaceDeclBits; |
1499 | NamespaceDeclBits.addBit(Value: D->isInline()); |
1500 | NamespaceDeclBits.addBit(Value: D->isNested()); |
1501 | Record.push_back(N: NamespaceDeclBits); |
1502 | |
1503 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
1504 | Record.AddSourceLocation(Loc: D->getRBraceLoc()); |
1505 | |
1506 | if (D->isFirstDecl()) |
1507 | Record.AddDeclRef(D->getAnonymousNamespace()); |
1508 | Code = serialization::DECL_NAMESPACE; |
1509 | |
1510 | if (Writer.hasChain() && D->isAnonymousNamespace() && |
1511 | D == D->getMostRecentDecl()) { |
1512 | // This is a most recent reopening of the anonymous namespace. If its parent |
1513 | // is in a previous PCH (or is the TU), mark that parent for update, because |
1514 | // the original namespace always points to the latest re-opening of its |
1515 | // anonymous namespace. |
1516 | Decl *Parent = cast<Decl>( |
1517 | D->getParent()->getRedeclContext()->getPrimaryContext()); |
1518 | if (Parent->isFromASTFile() || isa<TranslationUnitDecl>(Val: Parent)) { |
1519 | Writer.DeclUpdates[Parent].push_back( |
1520 | Elt: ASTWriter::DeclUpdate(DeclUpdateKind::CXXAddedAnonymousNamespace, D)); |
1521 | } |
1522 | } |
1523 | } |
1524 | |
1525 | void ASTDeclWriter::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
1526 | VisitRedeclarable(D); |
1527 | VisitNamedDecl(D); |
1528 | Record.AddSourceLocation(Loc: D->getNamespaceLoc()); |
1529 | Record.AddSourceLocation(Loc: D->getTargetNameLoc()); |
1530 | Record.AddNestedNameSpecifierLoc(NNS: D->getQualifierLoc()); |
1531 | Record.AddDeclRef(D->getNamespace()); |
1532 | Code = serialization::DECL_NAMESPACE_ALIAS; |
1533 | } |
1534 | |
1535 | void ASTDeclWriter::VisitUsingDecl(UsingDecl *D) { |
1536 | VisitNamedDecl(D); |
1537 | Record.AddSourceLocation(Loc: D->getUsingLoc()); |
1538 | Record.AddNestedNameSpecifierLoc(NNS: D->getQualifierLoc()); |
1539 | Record.AddDeclarationNameLoc(DNLoc: D->DNLoc, Name: D->getDeclName()); |
1540 | Record.AddDeclRef(D->FirstUsingShadow.getPointer()); |
1541 | Record.push_back(N: D->hasTypename()); |
1542 | Record.AddDeclRef(D: Record.getASTContext().getInstantiatedFromUsingDecl(D)); |
1543 | Code = serialization::DECL_USING; |
1544 | } |
1545 | |
1546 | void ASTDeclWriter::VisitUsingEnumDecl(UsingEnumDecl *D) { |
1547 | VisitNamedDecl(D); |
1548 | Record.AddSourceLocation(Loc: D->getUsingLoc()); |
1549 | Record.AddSourceLocation(Loc: D->getEnumLoc()); |
1550 | Record.AddTypeSourceInfo(TInfo: D->getEnumType()); |
1551 | Record.AddDeclRef(D->FirstUsingShadow.getPointer()); |
1552 | Record.AddDeclRef(D: Record.getASTContext().getInstantiatedFromUsingEnumDecl(D)); |
1553 | Code = serialization::DECL_USING_ENUM; |
1554 | } |
1555 | |
1556 | void ASTDeclWriter::VisitUsingPackDecl(UsingPackDecl *D) { |
1557 | Record.push_back(N: D->NumExpansions); |
1558 | VisitNamedDecl(D); |
1559 | Record.AddDeclRef(D->getInstantiatedFromUsingDecl()); |
1560 | for (auto *E : D->expansions()) |
1561 | Record.AddDeclRef(E); |
1562 | Code = serialization::DECL_USING_PACK; |
1563 | } |
1564 | |
1565 | void ASTDeclWriter::VisitUsingShadowDecl(UsingShadowDecl *D) { |
1566 | VisitRedeclarable(D); |
1567 | VisitNamedDecl(D); |
1568 | Record.AddDeclRef(D->getTargetDecl()); |
1569 | Record.push_back(N: D->getIdentifierNamespace()); |
1570 | Record.AddDeclRef(D->UsingOrNextShadow); |
1571 | Record.AddDeclRef( |
1572 | D: Record.getASTContext().getInstantiatedFromUsingShadowDecl(D)); |
1573 | |
1574 | if (D->getDeclContext() == D->getLexicalDeclContext() && |
1575 | D->getFirstDecl() == D->getMostRecentDecl() && !D->hasAttrs() && |
1576 | !needsAnonymousDeclarationNumber(D) && |
1577 | D->getDeclName().getNameKind() == DeclarationName::Identifier) |
1578 | AbbrevToUse = Writer.getDeclUsingShadowAbbrev(); |
1579 | |
1580 | Code = serialization::DECL_USING_SHADOW; |
1581 | } |
1582 | |
1583 | void ASTDeclWriter::VisitConstructorUsingShadowDecl( |
1584 | ConstructorUsingShadowDecl *D) { |
1585 | VisitUsingShadowDecl(D); |
1586 | Record.AddDeclRef(D->NominatedBaseClassShadowDecl); |
1587 | Record.AddDeclRef(D->ConstructedBaseClassShadowDecl); |
1588 | Record.push_back(N: D->IsVirtual); |
1589 | Code = serialization::DECL_CONSTRUCTOR_USING_SHADOW; |
1590 | } |
1591 | |
1592 | void ASTDeclWriter::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
1593 | VisitNamedDecl(D); |
1594 | Record.AddSourceLocation(Loc: D->getUsingLoc()); |
1595 | Record.AddSourceLocation(Loc: D->getNamespaceKeyLocation()); |
1596 | Record.AddNestedNameSpecifierLoc(NNS: D->getQualifierLoc()); |
1597 | Record.AddDeclRef(D->getNominatedNamespace()); |
1598 | Record.AddDeclRef(D: dyn_cast<Decl>(Val: D->getCommonAncestor())); |
1599 | Code = serialization::DECL_USING_DIRECTIVE; |
1600 | } |
1601 | |
1602 | void ASTDeclWriter::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { |
1603 | VisitValueDecl(D); |
1604 | Record.AddSourceLocation(Loc: D->getUsingLoc()); |
1605 | Record.AddNestedNameSpecifierLoc(NNS: D->getQualifierLoc()); |
1606 | Record.AddDeclarationNameLoc(DNLoc: D->DNLoc, Name: D->getDeclName()); |
1607 | Record.AddSourceLocation(Loc: D->getEllipsisLoc()); |
1608 | Code = serialization::DECL_UNRESOLVED_USING_VALUE; |
1609 | } |
1610 | |
1611 | void ASTDeclWriter::VisitUnresolvedUsingTypenameDecl( |
1612 | UnresolvedUsingTypenameDecl *D) { |
1613 | VisitTypeDecl(D); |
1614 | Record.AddSourceLocation(Loc: D->getTypenameLoc()); |
1615 | Record.AddNestedNameSpecifierLoc(NNS: D->getQualifierLoc()); |
1616 | Record.AddSourceLocation(Loc: D->getEllipsisLoc()); |
1617 | Code = serialization::DECL_UNRESOLVED_USING_TYPENAME; |
1618 | } |
1619 | |
1620 | void ASTDeclWriter::VisitUnresolvedUsingIfExistsDecl( |
1621 | UnresolvedUsingIfExistsDecl *D) { |
1622 | VisitNamedDecl(D); |
1623 | Code = serialization::DECL_UNRESOLVED_USING_IF_EXISTS; |
1624 | } |
1625 | |
1626 | void ASTDeclWriter::VisitCXXRecordDecl(CXXRecordDecl *D) { |
1627 | VisitRecordDecl(D); |
1628 | |
1629 | enum { |
1630 | CXXRecNotTemplate = 0, |
1631 | CXXRecTemplate, |
1632 | CXXRecMemberSpecialization, |
1633 | CXXLambda |
1634 | }; |
1635 | if (ClassTemplateDecl *TemplD = D->getDescribedClassTemplate()) { |
1636 | Record.push_back(N: CXXRecTemplate); |
1637 | Record.AddDeclRef(TemplD); |
1638 | } else if (MemberSpecializationInfo *MSInfo |
1639 | = D->getMemberSpecializationInfo()) { |
1640 | Record.push_back(N: CXXRecMemberSpecialization); |
1641 | Record.AddDeclRef(MSInfo->getInstantiatedFrom()); |
1642 | Record.push_back(N: MSInfo->getTemplateSpecializationKind()); |
1643 | Record.AddSourceLocation(Loc: MSInfo->getPointOfInstantiation()); |
1644 | } else if (D->isLambda()) { |
1645 | // For a lambda, we need some information early for merging. |
1646 | Record.push_back(N: CXXLambda); |
1647 | if (auto *Context = D->getLambdaContextDecl()) { |
1648 | Record.AddDeclRef(D: Context); |
1649 | Record.push_back(N: D->getLambdaIndexInContext()); |
1650 | } else { |
1651 | Record.push_back(N: 0); |
1652 | } |
1653 | // For lambdas inside template functions, remember the mapping to |
1654 | // deserialize them together. |
1655 | if (auto *FD = llvm::dyn_cast_or_null<FunctionDecl>(D->getDeclContext()); |
1656 | FD && isDefinitionInDependentContext(FD)) { |
1657 | Writer.RelatedDeclsMap[Writer.GetDeclRef(D: FD)].push_back( |
1658 | Writer.GetDeclRef(D->getLambdaCallOperator())); |
1659 | } |
1660 | } else { |
1661 | Record.push_back(N: CXXRecNotTemplate); |
1662 | } |
1663 | |
1664 | Record.push_back(N: D->isThisDeclarationADefinition()); |
1665 | if (D->isThisDeclarationADefinition()) |
1666 | Record.AddCXXDefinitionData(D); |
1667 | |
1668 | if (D->isCompleteDefinition() && D->isInNamedModule()) |
1669 | Writer.AddDeclRef(D, Writer.ModularCodegenDecls); |
1670 | |
1671 | // Store (what we currently believe to be) the key function to avoid |
1672 | // deserializing every method so we can compute it. |
1673 | // |
1674 | // FIXME: Avoid adding the key function if the class is defined in |
1675 | // module purview since in that case the key function is meaningless. |
1676 | if (D->isCompleteDefinition()) |
1677 | Record.AddDeclRef(D: Record.getASTContext().getCurrentKeyFunction(D)); |
1678 | |
1679 | Code = serialization::DECL_CXX_RECORD; |
1680 | } |
1681 | |
1682 | void ASTDeclWriter::VisitCXXMethodDecl(CXXMethodDecl *D) { |
1683 | VisitFunctionDecl(D); |
1684 | if (D->isCanonicalDecl()) { |
1685 | Record.push_back(N: D->size_overridden_methods()); |
1686 | for (const CXXMethodDecl *MD : D->overridden_methods()) |
1687 | Record.AddDeclRef(MD); |
1688 | } else { |
1689 | // We only need to record overridden methods once for the canonical decl. |
1690 | Record.push_back(N: 0); |
1691 | } |
1692 | |
1693 | if (D->getDeclContext() == D->getLexicalDeclContext() && |
1694 | D->getFirstDecl() == D->getMostRecentDecl() && !D->isInvalidDecl() && |
1695 | !D->hasAttrs() && !D->isTopLevelDeclInObjCContainer() && |
1696 | D->getDeclName().getNameKind() == DeclarationName::Identifier && |
1697 | !D->hasExtInfo() && !D->isExplicitlyDefaulted()) { |
1698 | if (D->getTemplatedKind() == FunctionDecl::TK_NonTemplate || |
1699 | D->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate || |
1700 | D->getTemplatedKind() == FunctionDecl::TK_MemberSpecialization || |
1701 | D->getTemplatedKind() == FunctionDecl::TK_DependentNonTemplate) |
1702 | AbbrevToUse = Writer.getDeclCXXMethodAbbrev(Kind: D->getTemplatedKind()); |
1703 | else if (D->getTemplatedKind() == |
1704 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
1705 | FunctionTemplateSpecializationInfo *FTSInfo = |
1706 | D->getTemplateSpecializationInfo(); |
1707 | |
1708 | if (FTSInfo->TemplateArguments->size() == 1) { |
1709 | const TemplateArgument &TA = FTSInfo->TemplateArguments->get(Idx: 0); |
1710 | if (TA.getKind() == TemplateArgument::Type && |
1711 | !FTSInfo->TemplateArgumentsAsWritten && |
1712 | !FTSInfo->getMemberSpecializationInfo()) |
1713 | AbbrevToUse = Writer.getDeclCXXMethodAbbrev(Kind: D->getTemplatedKind()); |
1714 | } |
1715 | } else if (D->getTemplatedKind() == |
1716 | FunctionDecl::TK_DependentFunctionTemplateSpecialization) { |
1717 | DependentFunctionTemplateSpecializationInfo *DFTSInfo = |
1718 | D->getDependentSpecializationInfo(); |
1719 | if (!DFTSInfo->TemplateArgumentsAsWritten) |
1720 | AbbrevToUse = Writer.getDeclCXXMethodAbbrev(Kind: D->getTemplatedKind()); |
1721 | } |
1722 | } |
1723 | |
1724 | Code = serialization::DECL_CXX_METHOD; |
1725 | } |
1726 | |
1727 | void ASTDeclWriter::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
1728 | static_assert(DeclContext::NumCXXConstructorDeclBits == 64, |
1729 | "You need to update the serializer after you change the " |
1730 | "CXXConstructorDeclBits" ); |
1731 | |
1732 | Record.push_back(N: D->getTrailingAllocKind()); |
1733 | addExplicitSpecifier(ES: D->getExplicitSpecifierInternal(), Record); |
1734 | if (auto Inherited = D->getInheritedConstructor()) { |
1735 | Record.AddDeclRef(Inherited.getShadowDecl()); |
1736 | Record.AddDeclRef(Inherited.getConstructor()); |
1737 | } |
1738 | |
1739 | VisitCXXMethodDecl(D); |
1740 | Code = serialization::DECL_CXX_CONSTRUCTOR; |
1741 | } |
1742 | |
1743 | void ASTDeclWriter::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
1744 | VisitCXXMethodDecl(D); |
1745 | |
1746 | Record.AddDeclRef(D->getOperatorDelete()); |
1747 | if (D->getOperatorDelete()) |
1748 | Record.AddStmt(D->getOperatorDeleteThisArg()); |
1749 | |
1750 | Code = serialization::DECL_CXX_DESTRUCTOR; |
1751 | } |
1752 | |
1753 | void ASTDeclWriter::VisitCXXConversionDecl(CXXConversionDecl *D) { |
1754 | addExplicitSpecifier(ES: D->getExplicitSpecifier(), Record); |
1755 | VisitCXXMethodDecl(D); |
1756 | Code = serialization::DECL_CXX_CONVERSION; |
1757 | } |
1758 | |
1759 | void ASTDeclWriter::VisitImportDecl(ImportDecl *D) { |
1760 | VisitDecl(D); |
1761 | Record.push_back(N: Writer.getSubmoduleID(Mod: D->getImportedModule())); |
1762 | ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs(); |
1763 | Record.push_back(N: !IdentifierLocs.empty()); |
1764 | if (IdentifierLocs.empty()) { |
1765 | Record.AddSourceLocation(Loc: D->getEndLoc()); |
1766 | Record.push_back(N: 1); |
1767 | } else { |
1768 | for (unsigned I = 0, N = IdentifierLocs.size(); I != N; ++I) |
1769 | Record.AddSourceLocation(Loc: IdentifierLocs[I]); |
1770 | Record.push_back(N: IdentifierLocs.size()); |
1771 | } |
1772 | // Note: the number of source locations must always be the last element in |
1773 | // the record. |
1774 | Code = serialization::DECL_IMPORT; |
1775 | } |
1776 | |
1777 | void ASTDeclWriter::VisitAccessSpecDecl(AccessSpecDecl *D) { |
1778 | VisitDecl(D); |
1779 | Record.AddSourceLocation(Loc: D->getColonLoc()); |
1780 | Code = serialization::DECL_ACCESS_SPEC; |
1781 | } |
1782 | |
1783 | void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) { |
1784 | // Record the number of friend type template parameter lists here |
1785 | // so as to simplify memory allocation during deserialization. |
1786 | Record.push_back(N: D->NumTPLists); |
1787 | VisitDecl(D); |
1788 | bool hasFriendDecl = isa<NamedDecl *>(Val: D->Friend); |
1789 | Record.push_back(N: hasFriendDecl); |
1790 | if (hasFriendDecl) |
1791 | Record.AddDeclRef(D->getFriendDecl()); |
1792 | else |
1793 | Record.AddTypeSourceInfo(TInfo: D->getFriendType()); |
1794 | for (unsigned i = 0; i < D->NumTPLists; ++i) |
1795 | Record.AddTemplateParameterList(TemplateParams: D->getFriendTypeTemplateParameterList(N: i)); |
1796 | Record.AddDeclRef(D->getNextFriend()); |
1797 | Record.push_back(N: D->UnsupportedFriend); |
1798 | Record.AddSourceLocation(Loc: D->FriendLoc); |
1799 | Record.AddSourceLocation(Loc: D->EllipsisLoc); |
1800 | Code = serialization::DECL_FRIEND; |
1801 | } |
1802 | |
1803 | void ASTDeclWriter::VisitFriendTemplateDecl(FriendTemplateDecl *D) { |
1804 | VisitDecl(D); |
1805 | Record.push_back(N: D->getNumTemplateParameters()); |
1806 | for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i) |
1807 | Record.AddTemplateParameterList(TemplateParams: D->getTemplateParameterList(i)); |
1808 | Record.push_back(N: D->getFriendDecl() != nullptr); |
1809 | if (D->getFriendDecl()) |
1810 | Record.AddDeclRef(D->getFriendDecl()); |
1811 | else |
1812 | Record.AddTypeSourceInfo(TInfo: D->getFriendType()); |
1813 | Record.AddSourceLocation(Loc: D->getFriendLoc()); |
1814 | Code = serialization::DECL_FRIEND_TEMPLATE; |
1815 | } |
1816 | |
1817 | void ASTDeclWriter::VisitTemplateDecl(TemplateDecl *D) { |
1818 | VisitNamedDecl(D); |
1819 | |
1820 | Record.AddTemplateParameterList(TemplateParams: D->getTemplateParameters()); |
1821 | Record.AddDeclRef(D->getTemplatedDecl()); |
1822 | } |
1823 | |
1824 | void ASTDeclWriter::VisitConceptDecl(ConceptDecl *D) { |
1825 | VisitTemplateDecl(D); |
1826 | Record.AddStmt(D->getConstraintExpr()); |
1827 | Code = serialization::DECL_CONCEPT; |
1828 | } |
1829 | |
1830 | void ASTDeclWriter::VisitImplicitConceptSpecializationDecl( |
1831 | ImplicitConceptSpecializationDecl *D) { |
1832 | Record.push_back(N: D->getTemplateArguments().size()); |
1833 | VisitDecl(D); |
1834 | for (const TemplateArgument &Arg : D->getTemplateArguments()) |
1835 | Record.AddTemplateArgument(Arg); |
1836 | Code = serialization::DECL_IMPLICIT_CONCEPT_SPECIALIZATION; |
1837 | } |
1838 | |
1839 | void ASTDeclWriter::VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D) { |
1840 | Code = serialization::DECL_REQUIRES_EXPR_BODY; |
1841 | } |
1842 | |
1843 | void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { |
1844 | VisitRedeclarable(D); |
1845 | |
1846 | // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that |
1847 | // getCommonPtr() can be used while this is still initializing. |
1848 | if (D->isFirstDecl()) { |
1849 | // This declaration owns the 'common' pointer, so serialize that data now. |
1850 | Record.AddDeclRef(D->getInstantiatedFromMemberTemplate()); |
1851 | if (D->getInstantiatedFromMemberTemplate()) |
1852 | Record.push_back(N: D->isMemberSpecialization()); |
1853 | } |
1854 | |
1855 | VisitTemplateDecl(D); |
1856 | Record.push_back(N: D->getIdentifierNamespace()); |
1857 | } |
1858 | |
1859 | void ASTDeclWriter::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
1860 | VisitRedeclarableTemplateDecl(D); |
1861 | |
1862 | if (D->isFirstDecl()) |
1863 | AddTemplateSpecializations(D); |
1864 | |
1865 | // Force emitting the corresponding deduction guide in reduced BMI mode. |
1866 | // Otherwise, the deduction guide may be optimized out incorrectly. |
1867 | if (Writer.isGeneratingReducedBMI()) { |
1868 | auto Name = |
1869 | Record.getASTContext().DeclarationNames.getCXXDeductionGuideName(D); |
1870 | for (auto *DG : D->getDeclContext()->noload_lookup(Name)) |
1871 | Writer.GetDeclRef(DG->getCanonicalDecl()); |
1872 | } |
1873 | |
1874 | Code = serialization::DECL_CLASS_TEMPLATE; |
1875 | } |
1876 | |
1877 | void ASTDeclWriter::VisitClassTemplateSpecializationDecl( |
1878 | ClassTemplateSpecializationDecl *D) { |
1879 | RegisterTemplateSpecialization(D->getSpecializedTemplate(), D); |
1880 | |
1881 | VisitCXXRecordDecl(D); |
1882 | |
1883 | llvm::PointerUnion<ClassTemplateDecl *, |
1884 | ClassTemplatePartialSpecializationDecl *> InstFrom |
1885 | = D->getSpecializedTemplateOrPartial(); |
1886 | if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) { |
1887 | Record.AddDeclRef(D: InstFromD); |
1888 | } else { |
1889 | Record.AddDeclRef(cast<ClassTemplatePartialSpecializationDecl *>(Val&: InstFrom)); |
1890 | Record.AddTemplateArgumentList(TemplateArgs: &D->getTemplateInstantiationArgs()); |
1891 | } |
1892 | |
1893 | Record.AddTemplateArgumentList(TemplateArgs: &D->getTemplateArgs()); |
1894 | Record.AddSourceLocation(Loc: D->getPointOfInstantiation()); |
1895 | Record.push_back(N: D->getSpecializationKind()); |
1896 | Record.push_back(N: D->hasStrictPackMatch()); |
1897 | Record.push_back(N: D->isCanonicalDecl()); |
1898 | |
1899 | if (D->isCanonicalDecl()) { |
1900 | // When reading, we'll add it to the folding set of the following template. |
1901 | Record.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl()); |
1902 | } |
1903 | |
1904 | bool ExplicitInstantiation = |
1905 | D->getTemplateSpecializationKind() == |
1906 | TSK_ExplicitInstantiationDeclaration || |
1907 | D->getTemplateSpecializationKind() == TSK_ExplicitInstantiationDefinition; |
1908 | Record.push_back(N: ExplicitInstantiation); |
1909 | if (ExplicitInstantiation) { |
1910 | Record.AddSourceLocation(Loc: D->getExternKeywordLoc()); |
1911 | Record.AddSourceLocation(Loc: D->getTemplateKeywordLoc()); |
1912 | } |
1913 | |
1914 | const ASTTemplateArgumentListInfo *ArgsWritten = |
1915 | D->getTemplateArgsAsWritten(); |
1916 | Record.push_back(N: !!ArgsWritten); |
1917 | if (ArgsWritten) |
1918 | Record.AddASTTemplateArgumentListInfo(ASTTemplArgList: ArgsWritten); |
1919 | |
1920 | // Mention the implicitly generated C++ deduction guide to make sure the |
1921 | // deduction guide will be rewritten as expected. |
1922 | // |
1923 | // FIXME: Would it be more efficient to add a callback register function |
1924 | // in sema to register the deduction guide? |
1925 | if (Writer.isWritingStdCXXNamedModules()) { |
1926 | auto Name = |
1927 | Record.getASTContext().DeclarationNames.getCXXDeductionGuideName( |
1928 | D->getSpecializedTemplate()); |
1929 | for (auto *DG : D->getDeclContext()->noload_lookup(Name)) |
1930 | Writer.GetDeclRef(DG->getCanonicalDecl()); |
1931 | } |
1932 | |
1933 | Code = serialization::DECL_CLASS_TEMPLATE_SPECIALIZATION; |
1934 | } |
1935 | |
1936 | void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl( |
1937 | ClassTemplatePartialSpecializationDecl *D) { |
1938 | Record.AddTemplateParameterList(TemplateParams: D->getTemplateParameters()); |
1939 | |
1940 | VisitClassTemplateSpecializationDecl(D); |
1941 | |
1942 | // These are read/set from/to the first declaration. |
1943 | if (D->getPreviousDecl() == nullptr) { |
1944 | Record.AddDeclRef(D->getInstantiatedFromMember()); |
1945 | Record.push_back(N: D->isMemberSpecialization()); |
1946 | } |
1947 | |
1948 | Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION; |
1949 | } |
1950 | |
1951 | void ASTDeclWriter::VisitVarTemplateDecl(VarTemplateDecl *D) { |
1952 | VisitRedeclarableTemplateDecl(D); |
1953 | |
1954 | if (D->isFirstDecl()) |
1955 | AddTemplateSpecializations(D); |
1956 | Code = serialization::DECL_VAR_TEMPLATE; |
1957 | } |
1958 | |
1959 | void ASTDeclWriter::VisitVarTemplateSpecializationDecl( |
1960 | VarTemplateSpecializationDecl *D) { |
1961 | RegisterTemplateSpecialization(D->getSpecializedTemplate(), D); |
1962 | |
1963 | llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *> |
1964 | InstFrom = D->getSpecializedTemplateOrPartial(); |
1965 | if (Decl *InstFromD = InstFrom.dyn_cast<VarTemplateDecl *>()) { |
1966 | Record.AddDeclRef(D: InstFromD); |
1967 | } else { |
1968 | Record.AddDeclRef(cast<VarTemplatePartialSpecializationDecl *>(Val&: InstFrom)); |
1969 | Record.AddTemplateArgumentList(TemplateArgs: &D->getTemplateInstantiationArgs()); |
1970 | } |
1971 | |
1972 | bool ExplicitInstantiation = |
1973 | D->getTemplateSpecializationKind() == |
1974 | TSK_ExplicitInstantiationDeclaration || |
1975 | D->getTemplateSpecializationKind() == TSK_ExplicitInstantiationDefinition; |
1976 | Record.push_back(N: ExplicitInstantiation); |
1977 | if (ExplicitInstantiation) { |
1978 | Record.AddSourceLocation(Loc: D->getExternKeywordLoc()); |
1979 | Record.AddSourceLocation(Loc: D->getTemplateKeywordLoc()); |
1980 | } |
1981 | |
1982 | const ASTTemplateArgumentListInfo *ArgsWritten = |
1983 | D->getTemplateArgsAsWritten(); |
1984 | Record.push_back(N: !!ArgsWritten); |
1985 | if (ArgsWritten) |
1986 | Record.AddASTTemplateArgumentListInfo(ASTTemplArgList: ArgsWritten); |
1987 | |
1988 | Record.AddTemplateArgumentList(TemplateArgs: &D->getTemplateArgs()); |
1989 | Record.AddSourceLocation(Loc: D->getPointOfInstantiation()); |
1990 | Record.push_back(N: D->getSpecializationKind()); |
1991 | Record.push_back(N: D->IsCompleteDefinition); |
1992 | |
1993 | VisitVarDecl(D); |
1994 | |
1995 | Record.push_back(N: D->isCanonicalDecl()); |
1996 | |
1997 | if (D->isCanonicalDecl()) { |
1998 | // When reading, we'll add it to the folding set of the following template. |
1999 | Record.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl()); |
2000 | } |
2001 | |
2002 | Code = serialization::DECL_VAR_TEMPLATE_SPECIALIZATION; |
2003 | } |
2004 | |
2005 | void ASTDeclWriter::VisitVarTemplatePartialSpecializationDecl( |
2006 | VarTemplatePartialSpecializationDecl *D) { |
2007 | Record.AddTemplateParameterList(TemplateParams: D->getTemplateParameters()); |
2008 | |
2009 | VisitVarTemplateSpecializationDecl(D); |
2010 | |
2011 | // These are read/set from/to the first declaration. |
2012 | if (D->getPreviousDecl() == nullptr) { |
2013 | Record.AddDeclRef(D->getInstantiatedFromMember()); |
2014 | Record.push_back(N: D->isMemberSpecialization()); |
2015 | } |
2016 | |
2017 | Code = serialization::DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION; |
2018 | } |
2019 | |
2020 | void ASTDeclWriter::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
2021 | VisitRedeclarableTemplateDecl(D); |
2022 | |
2023 | if (D->isFirstDecl()) |
2024 | AddTemplateSpecializations(D); |
2025 | Code = serialization::DECL_FUNCTION_TEMPLATE; |
2026 | } |
2027 | |
2028 | void ASTDeclWriter::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
2029 | Record.push_back(N: D->hasTypeConstraint()); |
2030 | VisitTypeDecl(D); |
2031 | |
2032 | Record.push_back(N: D->wasDeclaredWithTypename()); |
2033 | |
2034 | const TypeConstraint *TC = D->getTypeConstraint(); |
2035 | if (D->hasTypeConstraint()) |
2036 | Record.push_back(/*TypeConstraintInitialized=*/N: TC != nullptr); |
2037 | if (TC) { |
2038 | auto *CR = TC->getConceptReference(); |
2039 | Record.push_back(N: CR != nullptr); |
2040 | if (CR) |
2041 | Record.AddConceptReference(CR); |
2042 | Record.AddStmt(TC->getImmediatelyDeclaredConstraint()); |
2043 | Record.writeUnsignedOrNone(Value: TC->getArgPackSubstIndex()); |
2044 | Record.writeUnsignedOrNone(Value: D->getNumExpansionParameters()); |
2045 | } |
2046 | |
2047 | bool OwnsDefaultArg = D->hasDefaultArgument() && |
2048 | !D->defaultArgumentWasInherited(); |
2049 | Record.push_back(N: OwnsDefaultArg); |
2050 | if (OwnsDefaultArg) |
2051 | Record.AddTemplateArgumentLoc(Arg: D->getDefaultArgument()); |
2052 | |
2053 | if (!D->hasTypeConstraint() && !OwnsDefaultArg && |
2054 | D->getDeclContext() == D->getLexicalDeclContext() && |
2055 | !D->isInvalidDecl() && !D->hasAttrs() && |
2056 | !D->isTopLevelDeclInObjCContainer() && !D->isImplicit() && |
2057 | D->getDeclName().getNameKind() == DeclarationName::Identifier) |
2058 | AbbrevToUse = Writer.getDeclTemplateTypeParmAbbrev(); |
2059 | |
2060 | Code = serialization::DECL_TEMPLATE_TYPE_PARM; |
2061 | } |
2062 | |
2063 | void ASTDeclWriter::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
2064 | // For an expanded parameter pack, record the number of expansion types here |
2065 | // so that it's easier for deserialization to allocate the right amount of |
2066 | // memory. |
2067 | Record.push_back(N: D->hasPlaceholderTypeConstraint()); |
2068 | if (D->isExpandedParameterPack()) |
2069 | Record.push_back(N: D->getNumExpansionTypes()); |
2070 | |
2071 | VisitDeclaratorDecl(D); |
2072 | // TemplateParmPosition. |
2073 | Record.push_back(N: D->getDepth()); |
2074 | Record.push_back(N: D->getPosition()); |
2075 | |
2076 | if (D->hasPlaceholderTypeConstraint()) |
2077 | Record.AddStmt(D->getPlaceholderTypeConstraint()); |
2078 | |
2079 | if (D->isExpandedParameterPack()) { |
2080 | for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) { |
2081 | Record.AddTypeRef(T: D->getExpansionType(I)); |
2082 | Record.AddTypeSourceInfo(TInfo: D->getExpansionTypeSourceInfo(I)); |
2083 | } |
2084 | |
2085 | Code = serialization::DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK; |
2086 | } else { |
2087 | // Rest of NonTypeTemplateParmDecl. |
2088 | Record.push_back(N: D->isParameterPack()); |
2089 | bool OwnsDefaultArg = D->hasDefaultArgument() && |
2090 | !D->defaultArgumentWasInherited(); |
2091 | Record.push_back(N: OwnsDefaultArg); |
2092 | if (OwnsDefaultArg) |
2093 | Record.AddTemplateArgumentLoc(Arg: D->getDefaultArgument()); |
2094 | Code = serialization::DECL_NON_TYPE_TEMPLATE_PARM; |
2095 | } |
2096 | } |
2097 | |
2098 | void ASTDeclWriter::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
2099 | // For an expanded parameter pack, record the number of expansion types here |
2100 | // so that it's easier for deserialization to allocate the right amount of |
2101 | // memory. |
2102 | if (D->isExpandedParameterPack()) |
2103 | Record.push_back(N: D->getNumExpansionTemplateParameters()); |
2104 | |
2105 | VisitTemplateDecl(D); |
2106 | Record.push_back(N: D->wasDeclaredWithTypename()); |
2107 | // TemplateParmPosition. |
2108 | Record.push_back(N: D->getDepth()); |
2109 | Record.push_back(N: D->getPosition()); |
2110 | |
2111 | if (D->isExpandedParameterPack()) { |
2112 | for (unsigned I = 0, N = D->getNumExpansionTemplateParameters(); |
2113 | I != N; ++I) |
2114 | Record.AddTemplateParameterList(TemplateParams: D->getExpansionTemplateParameters(I)); |
2115 | Code = serialization::DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK; |
2116 | } else { |
2117 | // Rest of TemplateTemplateParmDecl. |
2118 | Record.push_back(N: D->isParameterPack()); |
2119 | bool OwnsDefaultArg = D->hasDefaultArgument() && |
2120 | !D->defaultArgumentWasInherited(); |
2121 | Record.push_back(N: OwnsDefaultArg); |
2122 | if (OwnsDefaultArg) |
2123 | Record.AddTemplateArgumentLoc(Arg: D->getDefaultArgument()); |
2124 | Code = serialization::DECL_TEMPLATE_TEMPLATE_PARM; |
2125 | } |
2126 | } |
2127 | |
2128 | void ASTDeclWriter::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
2129 | VisitRedeclarableTemplateDecl(D); |
2130 | Code = serialization::DECL_TYPE_ALIAS_TEMPLATE; |
2131 | } |
2132 | |
2133 | void ASTDeclWriter::VisitStaticAssertDecl(StaticAssertDecl *D) { |
2134 | VisitDecl(D); |
2135 | Record.AddStmt(D->getAssertExpr()); |
2136 | Record.push_back(N: D->isFailed()); |
2137 | Record.AddStmt(D->getMessage()); |
2138 | Record.AddSourceLocation(Loc: D->getRParenLoc()); |
2139 | Code = serialization::DECL_STATIC_ASSERT; |
2140 | } |
2141 | |
2142 | /// Emit the DeclContext part of a declaration context decl. |
2143 | void ASTDeclWriter::VisitDeclContext(DeclContext *DC) { |
2144 | static_assert(DeclContext::NumDeclContextBits == 13, |
2145 | "You need to update the serializer after you change the " |
2146 | "DeclContextBits" ); |
2147 | |
2148 | uint64_t LexicalOffset = 0; |
2149 | uint64_t VisibleOffset = 0; |
2150 | uint64_t ModuleLocalOffset = 0; |
2151 | uint64_t TULocalOffset = 0; |
2152 | |
2153 | if (Writer.isGeneratingReducedBMI() && isa<NamespaceDecl>(Val: DC) && |
2154 | cast<NamespaceDecl>(Val: DC)->isFromExplicitGlobalModule()) { |
2155 | // In reduced BMI, delay writing lexical and visible block for namespace |
2156 | // in the global module fragment. See the comments of DelayedNamespace for |
2157 | // details. |
2158 | Writer.DelayedNamespace.push_back(Elt: cast<NamespaceDecl>(Val: DC)); |
2159 | } else { |
2160 | LexicalOffset = |
2161 | Writer.WriteDeclContextLexicalBlock(Context&: Record.getASTContext(), DC); |
2162 | Writer.WriteDeclContextVisibleBlock(Context&: Record.getASTContext(), DC, |
2163 | VisibleBlockOffset&: VisibleOffset, ModuleLocalBlockOffset&: ModuleLocalOffset, |
2164 | TULocalBlockOffset&: TULocalOffset); |
2165 | } |
2166 | |
2167 | Record.AddOffset(BitOffset: LexicalOffset); |
2168 | Record.AddOffset(BitOffset: VisibleOffset); |
2169 | Record.AddOffset(BitOffset: ModuleLocalOffset); |
2170 | Record.AddOffset(BitOffset: TULocalOffset); |
2171 | } |
2172 | |
2173 | const Decl *ASTWriter::getFirstLocalDecl(const Decl *D) { |
2174 | assert(IsLocalDecl(D) && "expected a local declaration" ); |
2175 | |
2176 | const Decl *Canon = D->getCanonicalDecl(); |
2177 | if (IsLocalDecl(D: Canon)) |
2178 | return Canon; |
2179 | |
2180 | const Decl *&CacheEntry = FirstLocalDeclCache[Canon]; |
2181 | if (CacheEntry) |
2182 | return CacheEntry; |
2183 | |
2184 | for (const Decl *Redecl = D; Redecl; Redecl = Redecl->getPreviousDecl()) |
2185 | if (IsLocalDecl(D: Redecl)) |
2186 | D = Redecl; |
2187 | return CacheEntry = D; |
2188 | } |
2189 | |
2190 | template <typename T> |
2191 | void ASTDeclWriter::VisitRedeclarable(Redeclarable<T> *D) { |
2192 | T *First = D->getFirstDecl(); |
2193 | T *MostRecent = First->getMostRecentDecl(); |
2194 | T *DAsT = static_cast<T *>(D); |
2195 | if (MostRecent != First) { |
2196 | assert(isRedeclarableDeclKind(DAsT->getKind()) && |
2197 | "Not considered redeclarable?" ); |
2198 | |
2199 | Record.AddDeclRef(D: First); |
2200 | |
2201 | // Write out a list of local redeclarations of this declaration if it's the |
2202 | // first local declaration in the chain. |
2203 | const Decl *FirstLocal = Writer.getFirstLocalDecl(D: DAsT); |
2204 | if (DAsT == FirstLocal) { |
2205 | // Emit a list of all imported first declarations so that we can be sure |
2206 | // that all redeclarations visible to this module are before D in the |
2207 | // redecl chain. |
2208 | unsigned I = Record.size(); |
2209 | Record.push_back(N: 0); |
2210 | if (Writer.Chain) |
2211 | AddFirstDeclFromEachModule(D: DAsT, /*IncludeLocal*/false); |
2212 | // This is the number of imported first declarations + 1. |
2213 | Record[I] = Record.size() - I; |
2214 | |
2215 | // Collect the set of local redeclarations of this declaration, from |
2216 | // newest to oldest. |
2217 | ASTWriter::RecordData LocalRedecls; |
2218 | ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls); |
2219 | for (const Decl *Prev = FirstLocal->getMostRecentDecl(); |
2220 | Prev != FirstLocal; Prev = Prev->getPreviousDecl()) |
2221 | if (!Prev->isFromASTFile()) |
2222 | LocalRedeclWriter.AddDeclRef(D: Prev); |
2223 | |
2224 | // If we have any redecls, write them now as a separate record preceding |
2225 | // the declaration itself. |
2226 | if (LocalRedecls.empty()) |
2227 | Record.push_back(N: 0); |
2228 | else |
2229 | Record.AddOffset(BitOffset: LocalRedeclWriter.Emit(Code: LOCAL_REDECLARATIONS)); |
2230 | } else { |
2231 | Record.push_back(N: 0); |
2232 | Record.AddDeclRef(D: FirstLocal); |
2233 | } |
2234 | |
2235 | // Make sure that we serialize both the previous and the most-recent |
2236 | // declarations, which (transitively) ensures that all declarations in the |
2237 | // chain get serialized. |
2238 | // |
2239 | // FIXME: This is not correct; when we reach an imported declaration we |
2240 | // won't emit its previous declaration. |
2241 | (void)Writer.GetDeclRef(D: D->getPreviousDecl()); |
2242 | (void)Writer.GetDeclRef(D: MostRecent); |
2243 | } else { |
2244 | // We use the sentinel value 0 to indicate an only declaration. |
2245 | Record.push_back(N: 0); |
2246 | } |
2247 | } |
2248 | |
2249 | void ASTDeclWriter::VisitHLSLBufferDecl(HLSLBufferDecl *D) { |
2250 | VisitNamedDecl(D); |
2251 | VisitDeclContext(D); |
2252 | Record.push_back(N: D->isCBuffer()); |
2253 | Record.AddSourceLocation(Loc: D->getLocStart()); |
2254 | Record.AddSourceLocation(Loc: D->getLBraceLoc()); |
2255 | Record.AddSourceLocation(Loc: D->getRBraceLoc()); |
2256 | |
2257 | Code = serialization::DECL_HLSL_BUFFER; |
2258 | } |
2259 | |
2260 | void ASTDeclWriter::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) { |
2261 | Record.writeOMPChildren(Data: D->Data); |
2262 | VisitDecl(D); |
2263 | Code = serialization::DECL_OMP_THREADPRIVATE; |
2264 | } |
2265 | |
2266 | void ASTDeclWriter::VisitOMPAllocateDecl(OMPAllocateDecl *D) { |
2267 | Record.writeOMPChildren(Data: D->Data); |
2268 | VisitDecl(D); |
2269 | Code = serialization::DECL_OMP_ALLOCATE; |
2270 | } |
2271 | |
2272 | void ASTDeclWriter::VisitOMPRequiresDecl(OMPRequiresDecl *D) { |
2273 | Record.writeOMPChildren(Data: D->Data); |
2274 | VisitDecl(D); |
2275 | Code = serialization::DECL_OMP_REQUIRES; |
2276 | } |
2277 | |
2278 | void ASTDeclWriter::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) { |
2279 | static_assert(DeclContext::NumOMPDeclareReductionDeclBits == 15, |
2280 | "You need to update the serializer after you change the " |
2281 | "NumOMPDeclareReductionDeclBits" ); |
2282 | |
2283 | VisitValueDecl(D); |
2284 | Record.AddSourceLocation(Loc: D->getBeginLoc()); |
2285 | Record.AddStmt(D->getCombinerIn()); |
2286 | Record.AddStmt(D->getCombinerOut()); |
2287 | Record.AddStmt(D->getCombiner()); |
2288 | Record.AddStmt(D->getInitOrig()); |
2289 | Record.AddStmt(D->getInitPriv()); |
2290 | Record.AddStmt(D->getInitializer()); |
2291 | Record.push_back(N: llvm::to_underlying(E: D->getInitializerKind())); |
2292 | Record.AddDeclRef(D->getPrevDeclInScope()); |
2293 | Code = serialization::DECL_OMP_DECLARE_REDUCTION; |
2294 | } |
2295 | |
2296 | void ASTDeclWriter::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) { |
2297 | Record.writeOMPChildren(Data: D->Data); |
2298 | VisitValueDecl(D); |
2299 | Record.AddDeclarationName(Name: D->getVarName()); |
2300 | Record.AddDeclRef(D->getPrevDeclInScope()); |
2301 | Code = serialization::DECL_OMP_DECLARE_MAPPER; |
2302 | } |
2303 | |
2304 | void ASTDeclWriter::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) { |
2305 | VisitVarDecl(D); |
2306 | Code = serialization::DECL_OMP_CAPTUREDEXPR; |
2307 | } |
2308 | |
2309 | void ASTDeclWriter::VisitOpenACCDeclareDecl(OpenACCDeclareDecl *D) { |
2310 | Record.writeUInt32(Value: D->clauses().size()); |
2311 | VisitDecl(D); |
2312 | Record.writeEnum(value: D->DirKind); |
2313 | Record.AddSourceLocation(Loc: D->DirectiveLoc); |
2314 | Record.AddSourceLocation(Loc: D->EndLoc); |
2315 | Record.writeOpenACCClauseList(Clauses: D->clauses()); |
2316 | Code = serialization::DECL_OPENACC_DECLARE; |
2317 | } |
2318 | void ASTDeclWriter::VisitOpenACCRoutineDecl(OpenACCRoutineDecl *D) { |
2319 | Record.writeUInt32(Value: D->clauses().size()); |
2320 | VisitDecl(D); |
2321 | Record.writeEnum(value: D->DirKind); |
2322 | Record.AddSourceLocation(Loc: D->DirectiveLoc); |
2323 | Record.AddSourceLocation(Loc: D->EndLoc); |
2324 | Record.AddSourceRange(Range: D->ParensLoc); |
2325 | Record.AddStmt(D->FuncRef); |
2326 | Record.writeOpenACCClauseList(Clauses: D->clauses()); |
2327 | Code = serialization::DECL_OPENACC_ROUTINE; |
2328 | } |
2329 | |
2330 | //===----------------------------------------------------------------------===// |
2331 | // ASTWriter Implementation |
2332 | //===----------------------------------------------------------------------===// |
2333 | |
2334 | namespace { |
2335 | template <FunctionDecl::TemplatedKind Kind> |
2336 | std::shared_ptr<llvm::BitCodeAbbrev> |
2337 | getFunctionDeclAbbrev(serialization::DeclCode Code) { |
2338 | using namespace llvm; |
2339 | |
2340 | auto Abv = std::make_shared<BitCodeAbbrev>(); |
2341 | Abv->Add(OpInfo: BitCodeAbbrevOp(Code)); |
2342 | // RedeclarableDecl |
2343 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // CanonicalDecl |
2344 | Abv->Add(OpInfo: BitCodeAbbrevOp(Kind)); |
2345 | if constexpr (Kind == FunctionDecl::TK_NonTemplate) { |
2346 | |
2347 | } else if constexpr (Kind == FunctionDecl::TK_FunctionTemplate) { |
2348 | // DescribedFunctionTemplate |
2349 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); |
2350 | } else if constexpr (Kind == FunctionDecl::TK_DependentNonTemplate) { |
2351 | // Instantiated From Decl |
2352 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); |
2353 | } else if constexpr (Kind == FunctionDecl::TK_MemberSpecialization) { |
2354 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedFrom |
2355 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
2356 | 3)); // TemplateSpecializationKind |
2357 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Specialized Location |
2358 | } else if constexpr (Kind == |
2359 | FunctionDecl::TK_FunctionTemplateSpecialization) { |
2360 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Template |
2361 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
2362 | 3)); // TemplateSpecializationKind |
2363 | Abv->Add(OpInfo: BitCodeAbbrevOp(1)); // Template Argument Size |
2364 | Abv->Add(OpInfo: BitCodeAbbrevOp(TemplateArgument::Type)); // Template Argument Kind |
2365 | Abv->Add( |
2366 | OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Template Argument Type |
2367 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Is Defaulted |
2368 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // TemplateArgumentsAsWritten |
2369 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation |
2370 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); |
2371 | Abv->Add( |
2372 | OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Canonical Decl of template |
2373 | } else if constexpr (Kind == FunctionDecl:: |
2374 | TK_DependentFunctionTemplateSpecialization) { |
2375 | // Candidates of specialization |
2376 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
2377 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // TemplateArgumentsAsWritten |
2378 | } else { |
2379 | llvm_unreachable("Unknown templated kind?" ); |
2380 | } |
2381 | // Decl |
2382 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
2383 | 8)); // Packed DeclBits: ModuleOwnershipKind, |
2384 | // isUsed, isReferenced, AccessSpecifier, |
2385 | // isImplicit |
2386 | // |
2387 | // The following bits should be 0: |
2388 | // HasStandaloneLexicalDC, HasAttrs, |
2389 | // TopLevelDeclInObjCContainer, |
2390 | // isInvalidDecl |
2391 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
2392 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
2393 | // NamedDecl |
2394 | Abv->Add(OpInfo: BitCodeAbbrevOp(DeclarationName::Identifier)); // NameKind |
2395 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Identifier |
2396 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
2397 | // ValueDecl |
2398 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
2399 | // DeclaratorDecl |
2400 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerLocStart |
2401 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // HasExtInfo |
2402 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType |
2403 | // FunctionDecl |
2404 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS |
2405 | Abv->Add(OpInfo: BitCodeAbbrevOp( |
2406 | BitCodeAbbrevOp::Fixed, |
2407 | 28)); // Packed Function Bits: StorageClass, Inline, InlineSpecified, |
2408 | // VirtualAsWritten, Pure, HasInheritedProto, HasWrittenProto, |
2409 | // Deleted, Trivial, TrivialForCall, Defaulted, ExplicitlyDefaulted, |
2410 | // IsIneligibleOrNotSelected, ImplicitReturnZero, Constexpr, |
2411 | // UsesSEHTry, SkippedBody, MultiVersion, LateParsed, |
2412 | // FriendConstraintRefersToEnclosingTemplate, Linkage, |
2413 | // ShouldSkipCheckingODR |
2414 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LocEnd |
2415 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // ODRHash |
2416 | // This Array slurps the rest of the record. Fortunately we want to encode |
2417 | // (nearly) all the remaining (variable number of) fields in the same way. |
2418 | // |
2419 | // This is: |
2420 | // NumParams and Params[] from FunctionDecl, and |
2421 | // NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl. |
2422 | // |
2423 | // Add an AbbrevOp for 'size then elements' and use it here. |
2424 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
2425 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); |
2426 | return Abv; |
2427 | } |
2428 | |
2429 | template <FunctionDecl::TemplatedKind Kind> |
2430 | std::shared_ptr<llvm::BitCodeAbbrev> getCXXMethodAbbrev() { |
2431 | return getFunctionDeclAbbrev<Kind>(serialization::DECL_CXX_METHOD); |
2432 | } |
2433 | } // namespace |
2434 | |
2435 | void ASTWriter::WriteDeclAbbrevs() { |
2436 | using namespace llvm; |
2437 | |
2438 | std::shared_ptr<BitCodeAbbrev> Abv; |
2439 | |
2440 | // Abbreviation for DECL_FIELD |
2441 | Abv = std::make_shared<BitCodeAbbrev>(); |
2442 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_FIELD)); |
2443 | // Decl |
2444 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
2445 | 7)); // Packed DeclBits: ModuleOwnershipKind, |
2446 | // isUsed, isReferenced, AccessSpecifier, |
2447 | // |
2448 | // The following bits should be 0: |
2449 | // isImplicit, HasStandaloneLexicalDC, HasAttrs, |
2450 | // TopLevelDeclInObjCContainer, |
2451 | // isInvalidDecl |
2452 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
2453 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
2454 | // NamedDecl |
2455 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
2456 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
2457 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
2458 | // ValueDecl |
2459 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
2460 | // DeclaratorDecl |
2461 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc |
2462 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // hasExtInfo |
2463 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType |
2464 | // FieldDecl |
2465 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable |
2466 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // StorageKind |
2467 | // Type Source Info |
2468 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
2469 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc |
2470 | DeclFieldAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2471 | |
2472 | // Abbreviation for DECL_OBJC_IVAR |
2473 | Abv = std::make_shared<BitCodeAbbrev>(); |
2474 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR)); |
2475 | // Decl |
2476 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
2477 | 12)); // Packed DeclBits: HasStandaloneLexicalDC, |
2478 | // isInvalidDecl, HasAttrs, isImplicit, isUsed, |
2479 | // isReferenced, TopLevelDeclInObjCContainer, |
2480 | // AccessSpecifier, ModuleOwnershipKind |
2481 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
2482 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
2483 | // NamedDecl |
2484 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
2485 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
2486 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
2487 | // ValueDecl |
2488 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
2489 | // DeclaratorDecl |
2490 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc |
2491 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // hasExtInfo |
2492 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType |
2493 | // FieldDecl |
2494 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable |
2495 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // InitStyle |
2496 | // ObjC Ivar |
2497 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl |
2498 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize |
2499 | // Type Source Info |
2500 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
2501 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc |
2502 | DeclObjCIvarAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2503 | |
2504 | // Abbreviation for DECL_ENUM |
2505 | Abv = std::make_shared<BitCodeAbbrev>(); |
2506 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_ENUM)); |
2507 | // Redeclarable |
2508 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // No redeclaration |
2509 | // Decl |
2510 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
2511 | 7)); // Packed DeclBits: ModuleOwnershipKind, |
2512 | // isUsed, isReferenced, AccessSpecifier, |
2513 | // |
2514 | // The following bits should be 0: |
2515 | // isImplicit, HasStandaloneLexicalDC, HasAttrs, |
2516 | // TopLevelDeclInObjCContainer, |
2517 | // isInvalidDecl |
2518 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
2519 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
2520 | // NamedDecl |
2521 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
2522 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
2523 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
2524 | // TypeDecl |
2525 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
2526 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref |
2527 | // TagDecl |
2528 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace |
2529 | Abv->Add(OpInfo: BitCodeAbbrevOp( |
2530 | BitCodeAbbrevOp::Fixed, |
2531 | 9)); // Packed Tag Decl Bits: getTagKind, isCompleteDefinition, |
2532 | // EmbeddedInDeclarator, IsFreeStanding, |
2533 | // isCompleteDefinitionRequired, ExtInfoKind |
2534 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation |
2535 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation |
2536 | // EnumDecl |
2537 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddTypeRef |
2538 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IntegerType |
2539 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getPromotionType |
2540 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 20)); // Enum Decl Bits |
2541 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));// ODRHash |
2542 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedMembEnum |
2543 | // DC |
2544 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset |
2545 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset |
2546 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ModuleLocalOffset |
2547 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TULocalOffset |
2548 | DeclEnumAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2549 | |
2550 | // Abbreviation for DECL_RECORD |
2551 | Abv = std::make_shared<BitCodeAbbrev>(); |
2552 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_RECORD)); |
2553 | // Redeclarable |
2554 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // No redeclaration |
2555 | // Decl |
2556 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
2557 | 7)); // Packed DeclBits: ModuleOwnershipKind, |
2558 | // isUsed, isReferenced, AccessSpecifier, |
2559 | // |
2560 | // The following bits should be 0: |
2561 | // isImplicit, HasStandaloneLexicalDC, HasAttrs, |
2562 | // TopLevelDeclInObjCContainer, |
2563 | // isInvalidDecl |
2564 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
2565 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
2566 | // NamedDecl |
2567 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
2568 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
2569 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
2570 | // TypeDecl |
2571 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
2572 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref |
2573 | // TagDecl |
2574 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace |
2575 | Abv->Add(OpInfo: BitCodeAbbrevOp( |
2576 | BitCodeAbbrevOp::Fixed, |
2577 | 9)); // Packed Tag Decl Bits: getTagKind, isCompleteDefinition, |
2578 | // EmbeddedInDeclarator, IsFreeStanding, |
2579 | // isCompleteDefinitionRequired, ExtInfoKind |
2580 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation |
2581 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation |
2582 | // RecordDecl |
2583 | Abv->Add(OpInfo: BitCodeAbbrevOp( |
2584 | BitCodeAbbrevOp::Fixed, |
2585 | 14)); // Packed Record Decl Bits: FlexibleArrayMember, |
2586 | // AnonymousStructUnion, hasObjectMember, hasVolatileMember, |
2587 | // isNonTrivialToPrimitiveDefaultInitialize, |
2588 | // isNonTrivialToPrimitiveCopy, isNonTrivialToPrimitiveDestroy, |
2589 | // hasNonTrivialToPrimitiveDefaultInitializeCUnion, |
2590 | // hasNonTrivialToPrimitiveDestructCUnion, |
2591 | // hasNonTrivialToPrimitiveCopyCUnion, |
2592 | // hasUninitializedExplicitInitFields, isParamDestroyedInCallee, |
2593 | // getArgPassingRestrictions |
2594 | // ODRHash |
2595 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 26)); |
2596 | |
2597 | // DC |
2598 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset |
2599 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset |
2600 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ModuleLocalOffset |
2601 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TULocalOffset |
2602 | DeclRecordAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2603 | |
2604 | // Abbreviation for DECL_PARM_VAR |
2605 | Abv = std::make_shared<BitCodeAbbrev>(); |
2606 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_PARM_VAR)); |
2607 | // Redeclarable |
2608 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // No redeclaration |
2609 | // Decl |
2610 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
2611 | 8)); // Packed DeclBits: ModuleOwnershipKind, isUsed, |
2612 | // isReferenced, AccessSpecifier, |
2613 | // HasStandaloneLexicalDC, HasAttrs, isImplicit, |
2614 | // TopLevelDeclInObjCContainer, |
2615 | // isInvalidDecl, |
2616 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
2617 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
2618 | // NamedDecl |
2619 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
2620 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
2621 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
2622 | // ValueDecl |
2623 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
2624 | // DeclaratorDecl |
2625 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc |
2626 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // hasExtInfo |
2627 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType |
2628 | // VarDecl |
2629 | Abv->Add( |
2630 | OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
2631 | 12)); // Packed Var Decl bits: SClass, TSCSpec, InitStyle, |
2632 | // isARCPseudoStrong, Linkage, ModulesCodegen |
2633 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // VarKind (local enum) |
2634 | // ParmVarDecl |
2635 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex |
2636 | Abv->Add(OpInfo: BitCodeAbbrevOp( |
2637 | BitCodeAbbrevOp::Fixed, |
2638 | 19)); // Packed Parm Var Decl bits: IsObjCMethodParameter, ScopeDepth, |
2639 | // ObjCDeclQualifier, KNRPromoted, |
2640 | // HasInheritedDefaultArg, HasUninstantiatedDefaultArg |
2641 | // Type Source Info |
2642 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
2643 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc |
2644 | DeclParmVarAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2645 | |
2646 | // Abbreviation for DECL_TYPEDEF |
2647 | Abv = std::make_shared<BitCodeAbbrev>(); |
2648 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_TYPEDEF)); |
2649 | // Redeclarable |
2650 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // No redeclaration |
2651 | // Decl |
2652 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
2653 | 7)); // Packed DeclBits: ModuleOwnershipKind, |
2654 | // isReferenced, isUsed, AccessSpecifier. Other |
2655 | // higher bits should be 0: isImplicit, |
2656 | // HasStandaloneLexicalDC, HasAttrs, |
2657 | // TopLevelDeclInObjCContainer, isInvalidDecl |
2658 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
2659 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
2660 | // NamedDecl |
2661 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
2662 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
2663 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
2664 | // TypeDecl |
2665 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
2666 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref |
2667 | // TypedefDecl |
2668 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
2669 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc |
2670 | DeclTypedefAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2671 | |
2672 | // Abbreviation for DECL_VAR |
2673 | Abv = std::make_shared<BitCodeAbbrev>(); |
2674 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_VAR)); |
2675 | // Redeclarable |
2676 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // No redeclaration |
2677 | // Decl |
2678 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
2679 | 12)); // Packed DeclBits: HasStandaloneLexicalDC, |
2680 | // isInvalidDecl, HasAttrs, isImplicit, isUsed, |
2681 | // isReferenced, TopLevelDeclInObjCContainer, |
2682 | // AccessSpecifier, ModuleOwnershipKind |
2683 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
2684 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
2685 | // NamedDecl |
2686 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
2687 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
2688 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // AnonDeclNumber |
2689 | // ValueDecl |
2690 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
2691 | // DeclaratorDecl |
2692 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc |
2693 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // hasExtInfo |
2694 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType |
2695 | // VarDecl |
2696 | Abv->Add(OpInfo: BitCodeAbbrevOp( |
2697 | BitCodeAbbrevOp::Fixed, |
2698 | 21)); // Packed Var Decl bits: Linkage, ModulesCodegen, |
2699 | // SClass, TSCSpec, InitStyle, |
2700 | // isARCPseudoStrong, IsThisDeclarationADemotedDefinition, |
2701 | // isExceptionVariable, isNRVOVariable, isCXXForRangeDecl, |
2702 | // isInline, isInlineSpecified, isConstexpr, |
2703 | // isInitCapture, isPrevDeclInSameScope, |
2704 | // EscapingByref, HasDeducedType, ImplicitParamKind, isObjCForDecl |
2705 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // VarKind (local enum) |
2706 | // Type Source Info |
2707 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Array)); |
2708 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc |
2709 | DeclVarAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2710 | |
2711 | // Abbreviation for DECL_CXX_METHOD |
2712 | DeclCXXMethodAbbrev = |
2713 | Stream.EmitAbbrev(Abbv: getCXXMethodAbbrev<FunctionDecl::TK_NonTemplate>()); |
2714 | DeclTemplateCXXMethodAbbrev = Stream.EmitAbbrev( |
2715 | Abbv: getCXXMethodAbbrev<FunctionDecl::TK_FunctionTemplate>()); |
2716 | DeclDependentNonTemplateCXXMethodAbbrev = Stream.EmitAbbrev( |
2717 | Abbv: getCXXMethodAbbrev<FunctionDecl::TK_DependentNonTemplate>()); |
2718 | DeclMemberSpecializedCXXMethodAbbrev = Stream.EmitAbbrev( |
2719 | Abbv: getCXXMethodAbbrev<FunctionDecl::TK_MemberSpecialization>()); |
2720 | DeclTemplateSpecializedCXXMethodAbbrev = Stream.EmitAbbrev( |
2721 | Abbv: getCXXMethodAbbrev<FunctionDecl::TK_FunctionTemplateSpecialization>()); |
2722 | DeclDependentSpecializationCXXMethodAbbrev = Stream.EmitAbbrev( |
2723 | Abbv: getCXXMethodAbbrev< |
2724 | FunctionDecl::TK_DependentFunctionTemplateSpecialization>()); |
2725 | |
2726 | // Abbreviation for DECL_TEMPLATE_TYPE_PARM |
2727 | Abv = std::make_shared<BitCodeAbbrev>(); |
2728 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_TEMPLATE_TYPE_PARM)); |
2729 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // hasTypeConstraint |
2730 | // Decl |
2731 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
2732 | 7)); // Packed DeclBits: ModuleOwnershipKind, |
2733 | // isReferenced, isUsed, AccessSpecifier. Other |
2734 | // higher bits should be 0: isImplicit, |
2735 | // HasStandaloneLexicalDC, HasAttrs, |
2736 | // TopLevelDeclInObjCContainer, isInvalidDecl |
2737 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
2738 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
2739 | // NamedDecl |
2740 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
2741 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
2742 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); |
2743 | // TypeDecl |
2744 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
2745 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref |
2746 | // TemplateTypeParmDecl |
2747 | Abv->Add( |
2748 | OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // wasDeclaredWithTypename |
2749 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // OwnsDefaultArg |
2750 | DeclTemplateTypeParmAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2751 | |
2752 | // Abbreviation for DECL_USING_SHADOW |
2753 | Abv = std::make_shared<BitCodeAbbrev>(); |
2754 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_USING_SHADOW)); |
2755 | // Redeclarable |
2756 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // No redeclaration |
2757 | // Decl |
2758 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, |
2759 | 12)); // Packed DeclBits: HasStandaloneLexicalDC, |
2760 | // isInvalidDecl, HasAttrs, isImplicit, isUsed, |
2761 | // isReferenced, TopLevelDeclInObjCContainer, |
2762 | // AccessSpecifier, ModuleOwnershipKind |
2763 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext |
2764 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID |
2765 | // NamedDecl |
2766 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // NameKind = Identifier |
2767 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name |
2768 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); |
2769 | // UsingShadowDecl |
2770 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TargetDecl |
2771 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS |
2772 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // UsingOrNextShadow |
2773 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, |
2774 | 6)); // InstantiatedFromUsingShadowDecl |
2775 | DeclUsingShadowAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2776 | |
2777 | // Abbreviation for EXPR_DECL_REF |
2778 | Abv = std::make_shared<BitCodeAbbrev>(); |
2779 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_DECL_REF)); |
2780 | // Stmt |
2781 | // Expr |
2782 | // PackingBits: DependenceKind, ValueKind. ObjectKind should be 0. |
2783 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7)); |
2784 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
2785 | // DeclRefExpr |
2786 | // Packing Bits: , HadMultipleCandidates, RefersToEnclosingVariableOrCapture, |
2787 | // IsImmediateEscalating, NonOdrUseReason. |
2788 | // GetDeclFound, HasQualifier and ExplicitTemplateArgs should be 0. |
2789 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); |
2790 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef |
2791 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location |
2792 | DeclRefExprAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2793 | |
2794 | // Abbreviation for EXPR_INTEGER_LITERAL |
2795 | Abv = std::make_shared<BitCodeAbbrev>(); |
2796 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL)); |
2797 | //Stmt |
2798 | // Expr |
2799 | // DependenceKind, ValueKind, ObjectKind |
2800 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); |
2801 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
2802 | // Integer Literal |
2803 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location |
2804 | Abv->Add(OpInfo: BitCodeAbbrevOp(32)); // Bit Width |
2805 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value |
2806 | IntegerLiteralAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2807 | |
2808 | // Abbreviation for EXPR_CHARACTER_LITERAL |
2809 | Abv = std::make_shared<BitCodeAbbrev>(); |
2810 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL)); |
2811 | //Stmt |
2812 | // Expr |
2813 | // DependenceKind, ValueKind, ObjectKind |
2814 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); |
2815 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
2816 | // Character Literal |
2817 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue |
2818 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location |
2819 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // getKind |
2820 | CharacterLiteralAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2821 | |
2822 | // Abbreviation for EXPR_IMPLICIT_CAST |
2823 | Abv = std::make_shared<BitCodeAbbrev>(); |
2824 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_IMPLICIT_CAST)); |
2825 | // Stmt |
2826 | // Expr |
2827 | // Packing Bits: DependenceKind, ValueKind, ObjectKind, |
2828 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); |
2829 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
2830 | // CastExpr |
2831 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // PathSize |
2832 | // Packing Bits: CastKind, StoredFPFeatures, isPartOfExplicitCast |
2833 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 9)); |
2834 | // ImplicitCastExpr |
2835 | ExprImplicitCastAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2836 | |
2837 | // Abbreviation for EXPR_BINARY_OPERATOR |
2838 | Abv = std::make_shared<BitCodeAbbrev>(); |
2839 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_BINARY_OPERATOR)); |
2840 | // Stmt |
2841 | // Expr |
2842 | // Packing Bits: DependenceKind. ValueKind and ObjectKind should |
2843 | // be 0 in this case. |
2844 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); |
2845 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
2846 | // BinaryOperator |
2847 | Abv->Add( |
2848 | OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // OpCode and HasFPFeatures |
2849 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
2850 | BinaryOperatorAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2851 | |
2852 | // Abbreviation for EXPR_COMPOUND_ASSIGN_OPERATOR |
2853 | Abv = std::make_shared<BitCodeAbbrev>(); |
2854 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_COMPOUND_ASSIGN_OPERATOR)); |
2855 | // Stmt |
2856 | // Expr |
2857 | // Packing Bits: DependenceKind. ValueKind and ObjectKind should |
2858 | // be 0 in this case. |
2859 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); |
2860 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
2861 | // BinaryOperator |
2862 | // Packing Bits: OpCode. The HasFPFeatures bit should be 0 |
2863 | Abv->Add( |
2864 | OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // OpCode and HasFPFeatures |
2865 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
2866 | // CompoundAssignOperator |
2867 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LHSType |
2868 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Result Type |
2869 | CompoundAssignOperatorAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2870 | |
2871 | // Abbreviation for EXPR_CALL |
2872 | Abv = std::make_shared<BitCodeAbbrev>(); |
2873 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_CALL)); |
2874 | // Stmt |
2875 | // Expr |
2876 | // Packing Bits: DependenceKind, ValueKind, ObjectKind, |
2877 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); |
2878 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
2879 | // CallExpr |
2880 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumArgs |
2881 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // ADLCallKind |
2882 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
2883 | CallExprAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2884 | |
2885 | // Abbreviation for EXPR_CXX_OPERATOR_CALL |
2886 | Abv = std::make_shared<BitCodeAbbrev>(); |
2887 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_CXX_OPERATOR_CALL)); |
2888 | // Stmt |
2889 | // Expr |
2890 | // Packing Bits: DependenceKind, ValueKind, ObjectKind, |
2891 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); |
2892 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
2893 | // CallExpr |
2894 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumArgs |
2895 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // ADLCallKind |
2896 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
2897 | // CXXOperatorCallExpr |
2898 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Operator Kind |
2899 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
2900 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
2901 | CXXOperatorCallExprAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2902 | |
2903 | // Abbreviation for EXPR_CXX_MEMBER_CALL |
2904 | Abv = std::make_shared<BitCodeAbbrev>(); |
2905 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::EXPR_CXX_MEMBER_CALL)); |
2906 | // Stmt |
2907 | // Expr |
2908 | // Packing Bits: DependenceKind, ValueKind, ObjectKind, |
2909 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10)); |
2910 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type |
2911 | // CallExpr |
2912 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumArgs |
2913 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // ADLCallKind |
2914 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
2915 | // CXXMemberCallExpr |
2916 | CXXMemberCallExprAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2917 | |
2918 | // Abbreviation for STMT_COMPOUND |
2919 | Abv = std::make_shared<BitCodeAbbrev>(); |
2920 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::STMT_COMPOUND)); |
2921 | // Stmt |
2922 | // CompoundStmt |
2923 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Num Stmts |
2924 | Abv->Add(OpInfo: BitCodeAbbrevOp(0)); // hasStoredFPFeatures |
2925 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
2926 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location |
2927 | CompoundStmtAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2928 | |
2929 | Abv = std::make_shared<BitCodeAbbrev>(); |
2930 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL)); |
2931 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
2932 | DeclContextLexicalAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2933 | |
2934 | Abv = std::make_shared<BitCodeAbbrev>(); |
2935 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE)); |
2936 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
2937 | DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2938 | |
2939 | Abv = std::make_shared<BitCodeAbbrev>(); |
2940 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_CONTEXT_MODULE_LOCAL_VISIBLE)); |
2941 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
2942 | DeclModuleLocalVisibleLookupAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2943 | |
2944 | Abv = std::make_shared<BitCodeAbbrev>(); |
2945 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_CONTEXT_TU_LOCAL_VISIBLE)); |
2946 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
2947 | DeclTULocalLookupAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2948 | |
2949 | Abv = std::make_shared<BitCodeAbbrev>(); |
2950 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_SPECIALIZATIONS)); |
2951 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
2952 | DeclSpecializationsAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2953 | |
2954 | Abv = std::make_shared<BitCodeAbbrev>(); |
2955 | Abv->Add(OpInfo: BitCodeAbbrevOp(serialization::DECL_PARTIAL_SPECIALIZATIONS)); |
2956 | Abv->Add(OpInfo: BitCodeAbbrevOp(BitCodeAbbrevOp::Blob)); |
2957 | DeclPartialSpecializationsAbbrev = Stream.EmitAbbrev(Abbv: std::move(Abv)); |
2958 | } |
2959 | |
2960 | /// isRequiredDecl - Check if this is a "required" Decl, which must be seen by |
2961 | /// consumers of the AST. |
2962 | /// |
2963 | /// Such decls will always be deserialized from the AST file, so we would like |
2964 | /// this to be as restrictive as possible. Currently the predicate is driven by |
2965 | /// code generation requirements, if other clients have a different notion of |
2966 | /// what is "required" then we may have to consider an alternate scheme where |
2967 | /// clients can iterate over the top-level decls and get information on them, |
2968 | /// without necessary deserializing them. We could explicitly require such |
2969 | /// clients to use a separate API call to "realize" the decl. This should be |
2970 | /// relatively painless since they would presumably only do it for top-level |
2971 | /// decls. |
2972 | static bool isRequiredDecl(const Decl *D, ASTContext &Context, |
2973 | Module *WritingModule) { |
2974 | // Named modules have different semantics than header modules. Every named |
2975 | // module units owns a translation unit. So the importer of named modules |
2976 | // doesn't need to deserilize everything ahead of time. |
2977 | if (WritingModule && WritingModule->isNamedModule()) { |
2978 | // The PragmaCommentDecl and PragmaDetectMismatchDecl are MSVC's extension. |
2979 | // And the behavior of MSVC for such cases will leak this to the module |
2980 | // users. Given pragma is not a standard thing, the compiler has the space |
2981 | // to do their own decision. Let's follow MSVC here. |
2982 | if (isa<PragmaCommentDecl, PragmaDetectMismatchDecl>(Val: D)) |
2983 | return true; |
2984 | return false; |
2985 | } |
2986 | |
2987 | // An ObjCMethodDecl is never considered as "required" because its |
2988 | // implementation container always is. |
2989 | |
2990 | // File scoped assembly or obj-c or OMP declare target implementation must be |
2991 | // seen. |
2992 | if (isa<FileScopeAsmDecl, TopLevelStmtDecl, ObjCImplDecl>(Val: D)) |
2993 | return true; |
2994 | |
2995 | if (WritingModule && isPartOfPerModuleInitializer(D)) { |
2996 | // These declarations are part of the module initializer, and are emitted |
2997 | // if and when the module is imported, rather than being emitted eagerly. |
2998 | return false; |
2999 | } |
3000 | |
3001 | return Context.DeclMustBeEmitted(D); |
3002 | } |
3003 | |
3004 | void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) { |
3005 | PrettyDeclStackTraceEntry CrashInfo(Context, D, SourceLocation(), |
3006 | "serializing" ); |
3007 | |
3008 | // Determine the ID for this declaration. |
3009 | LocalDeclID ID; |
3010 | assert(!D->isFromASTFile() && "should not be emitting imported decl" ); |
3011 | LocalDeclID &IDR = DeclIDs[D]; |
3012 | if (IDR.isInvalid()) |
3013 | IDR = NextDeclID++; |
3014 | |
3015 | ID = IDR; |
3016 | |
3017 | assert(ID >= FirstDeclID && "invalid decl ID" ); |
3018 | |
3019 | RecordData Record; |
3020 | ASTDeclWriter W(*this, Context, Record, GeneratingReducedBMI); |
3021 | |
3022 | // Build a record for this declaration |
3023 | W.Visit(D); |
3024 | |
3025 | // Emit this declaration to the bitstream. |
3026 | uint64_t Offset = W.Emit(D); |
3027 | |
3028 | // Record the offset for this declaration |
3029 | SourceLocation Loc = D->getLocation(); |
3030 | SourceLocationEncoding::RawLocEncoding RawLoc = |
3031 | getRawSourceLocationEncoding(Loc: getAdjustedLocation(Loc)); |
3032 | |
3033 | unsigned Index = ID.getRawValue() - FirstDeclID.getRawValue(); |
3034 | if (DeclOffsets.size() == Index) |
3035 | DeclOffsets.emplace_back(args&: RawLoc, args&: Offset, args&: DeclTypesBlockStartOffset); |
3036 | else if (DeclOffsets.size() < Index) { |
3037 | // FIXME: Can/should this happen? |
3038 | DeclOffsets.resize(new_size: Index+1); |
3039 | DeclOffsets[Index].setRawLoc(RawLoc); |
3040 | DeclOffsets[Index].setBitOffset(Offset, DeclTypesBlockStartOffset); |
3041 | } else { |
3042 | llvm_unreachable("declarations should be emitted in ID order" ); |
3043 | } |
3044 | |
3045 | SourceManager &SM = Context.getSourceManager(); |
3046 | if (Loc.isValid() && SM.isLocalSourceLocation(Loc)) |
3047 | associateDeclWithFile(D, ID); |
3048 | |
3049 | // Note declarations that should be deserialized eagerly so that we can add |
3050 | // them to a record in the AST file later. |
3051 | if (isRequiredDecl(D, Context, WritingModule)) |
3052 | AddDeclRef(D, Record&: EagerlyDeserializedDecls); |
3053 | } |
3054 | |
3055 | void ASTRecordWriter::AddFunctionDefinition(const FunctionDecl *FD) { |
3056 | // Switch case IDs are per function body. |
3057 | Writer->ClearSwitchCaseIDs(); |
3058 | |
3059 | assert(FD->doesThisDeclarationHaveABody()); |
3060 | bool ModulesCodegen = shouldFunctionGenerateHereOnly(FD); |
3061 | Record->push_back(Elt: ModulesCodegen); |
3062 | if (ModulesCodegen) |
3063 | Writer->AddDeclRef(FD, Writer->ModularCodegenDecls); |
3064 | if (auto *CD = dyn_cast<CXXConstructorDecl>(Val: FD)) { |
3065 | Record->push_back(Elt: CD->getNumCtorInitializers()); |
3066 | if (CD->getNumCtorInitializers()) |
3067 | AddCXXCtorInitializers(CtorInits: llvm::ArrayRef(CD->init_begin(), CD->init_end())); |
3068 | } |
3069 | AddStmt(S: FD->getBody()); |
3070 | } |
3071 | |