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