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