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 // Store (what we currently believe to be) the key function to avoid
1533 // deserializing every method so we can compute it.
1534 if (D->isCompleteDefinition())
1535 Record.AddDeclRef(Context.getCurrentKeyFunction(D));
1536
1538}
1539
1542 if (D->isCanonicalDecl()) {
1543 Record.push_back(D->size_overridden_methods());
1544 for (const CXXMethodDecl *MD : D->overridden_methods())
1545 Record.AddDeclRef(MD);
1546 } else {
1547 // We only need to record overridden methods once for the canonical decl.
1548 Record.push_back(0);
1549 }
1550
1551 if (D->getDeclContext() == D->getLexicalDeclContext() &&
1552 D->getFirstDecl() == D->getMostRecentDecl() && !D->isInvalidDecl() &&
1554 D->getDeclName().getNameKind() == DeclarationName::Identifier &&
1555 !D->hasExtInfo() && !D->isExplicitlyDefaulted()) {
1556 if (D->getTemplatedKind() == FunctionDecl::TK_NonTemplate ||
1557 D->getTemplatedKind() == FunctionDecl::TK_FunctionTemplate ||
1558 D->getTemplatedKind() == FunctionDecl::TK_MemberSpecialization ||
1559 D->getTemplatedKind() == FunctionDecl::TK_DependentNonTemplate)
1560 AbbrevToUse = Writer.getDeclCXXMethodAbbrev(D->getTemplatedKind());
1561 else if (D->getTemplatedKind() ==
1564 D->getTemplateSpecializationInfo();
1565
1566 if (FTSInfo->TemplateArguments->size() == 1) {
1567 const TemplateArgument &TA = FTSInfo->TemplateArguments->get(0);
1568 if (TA.getKind() == TemplateArgument::Type &&
1569 !FTSInfo->TemplateArgumentsAsWritten &&
1570 !FTSInfo->getMemberSpecializationInfo())
1571 AbbrevToUse = Writer.getDeclCXXMethodAbbrev(D->getTemplatedKind());
1572 }
1573 } else if (D->getTemplatedKind() ==
1576 D->getDependentSpecializationInfo();
1577 if (!DFTSInfo->TemplateArgumentsAsWritten)
1578 AbbrevToUse = Writer.getDeclCXXMethodAbbrev(D->getTemplatedKind());
1579 }
1580 }
1581
1583}
1584
1586 static_assert(DeclContext::NumCXXConstructorDeclBits == 64,
1587 "You need to update the serializer after you change the "
1588 "CXXConstructorDeclBits");
1589
1590 Record.push_back(D->getTrailingAllocKind());
1591 addExplicitSpecifier(D->getExplicitSpecifier(), Record);
1592 if (auto Inherited = D->getInheritedConstructor()) {
1593 Record.AddDeclRef(Inherited.getShadowDecl());
1594 Record.AddDeclRef(Inherited.getConstructor());
1595 }
1596
1599}
1600
1603
1604 Record.AddDeclRef(D->getOperatorDelete());
1605 if (D->getOperatorDelete())
1606 Record.AddStmt(D->getOperatorDeleteThisArg());
1607
1609}
1610
1612 addExplicitSpecifier(D->getExplicitSpecifier(), Record);
1615}
1616
1618 VisitDecl(D);
1619 Record.push_back(Writer.getSubmoduleID(D->getImportedModule()));
1620 ArrayRef<SourceLocation> IdentifierLocs = D->getIdentifierLocs();
1621 Record.push_back(!IdentifierLocs.empty());
1622 if (IdentifierLocs.empty()) {
1623 Record.AddSourceLocation(D->getEndLoc());
1624 Record.push_back(1);
1625 } else {
1626 for (unsigned I = 0, N = IdentifierLocs.size(); I != N; ++I)
1627 Record.AddSourceLocation(IdentifierLocs[I]);
1628 Record.push_back(IdentifierLocs.size());
1629 }
1630 // Note: the number of source locations must always be the last element in
1631 // the record.
1633}
1634
1636 VisitDecl(D);
1637 Record.AddSourceLocation(D->getColonLoc());
1639}
1640
1642 // Record the number of friend type template parameter lists here
1643 // so as to simplify memory allocation during deserialization.
1644 Record.push_back(D->NumTPLists);
1645 VisitDecl(D);
1646 bool hasFriendDecl = D->Friend.is<NamedDecl*>();
1647 Record.push_back(hasFriendDecl);
1648 if (hasFriendDecl)
1649 Record.AddDeclRef(D->getFriendDecl());
1650 else
1651 Record.AddTypeSourceInfo(D->getFriendType());
1652 for (unsigned i = 0; i < D->NumTPLists; ++i)
1653 Record.AddTemplateParameterList(D->getFriendTypeTemplateParameterList(i));
1654 Record.AddDeclRef(D->getNextFriend());
1655 Record.push_back(D->UnsupportedFriend);
1656 Record.AddSourceLocation(D->FriendLoc);
1658}
1659
1661 VisitDecl(D);
1662 Record.push_back(D->getNumTemplateParameters());
1663 for (unsigned i = 0, e = D->getNumTemplateParameters(); i != e; ++i)
1664 Record.AddTemplateParameterList(D->getTemplateParameterList(i));
1665 Record.push_back(D->getFriendDecl() != nullptr);
1666 if (D->getFriendDecl())
1667 Record.AddDeclRef(D->getFriendDecl());
1668 else
1669 Record.AddTypeSourceInfo(D->getFriendType());
1670 Record.AddSourceLocation(D->getFriendLoc());
1672}
1673
1676
1677 Record.AddTemplateParameterList(D->getTemplateParameters());
1678 Record.AddDeclRef(D->getTemplatedDecl());
1679}
1680
1683 Record.AddStmt(D->getConstraintExpr());
1685}
1686
1689 Record.push_back(D->getTemplateArguments().size());
1690 VisitDecl(D);
1691 for (const TemplateArgument &Arg : D->getTemplateArguments())
1692 Record.AddTemplateArgument(Arg);
1694}
1695
1698}
1699
1702
1703 // Emit data to initialize CommonOrPrev before VisitTemplateDecl so that
1704 // getCommonPtr() can be used while this is still initializing.
1705 if (D->isFirstDecl()) {
1706 // This declaration owns the 'common' pointer, so serialize that data now.
1707 Record.AddDeclRef(D->getInstantiatedFromMemberTemplate());
1708 if (D->getInstantiatedFromMemberTemplate())
1709 Record.push_back(D->isMemberSpecialization());
1710 }
1711
1713 Record.push_back(D->getIdentifierNamespace());
1714}
1715
1718
1719 if (D->isFirstDecl())
1721
1722 // Force emitting the corresponding deduction guide in reduced BMI mode.
1723 // Otherwise, the deduction guide may be optimized out incorrectly.
1724 if (Writer.isGeneratingReducedBMI()) {
1725 auto Name = Context.DeclarationNames.getCXXDeductionGuideName(D);
1726 for (auto *DG : D->getDeclContext()->noload_lookup(Name))
1727 Writer.GetDeclRef(DG->getCanonicalDecl());
1728 }
1729
1731}
1732
1735 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1736
1738
1739 llvm::PointerUnion<ClassTemplateDecl *,
1741 = D->getSpecializedTemplateOrPartial();
1742 if (Decl *InstFromD = InstFrom.dyn_cast<ClassTemplateDecl *>()) {
1743 Record.AddDeclRef(InstFromD);
1744 } else {
1745 Record.AddDeclRef(InstFrom.get<ClassTemplatePartialSpecializationDecl *>());
1746 Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
1747 }
1748
1749 Record.AddTemplateArgumentList(&D->getTemplateArgs());
1750 Record.AddSourceLocation(D->getPointOfInstantiation());
1751 Record.push_back(D->getSpecializationKind());
1752 Record.push_back(D->isCanonicalDecl());
1753
1754 if (D->isCanonicalDecl()) {
1755 // When reading, we'll add it to the folding set of the following template.
1756 Record.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl());
1757 }
1758
1759 bool ExplicitInstantiation =
1760 D->getTemplateSpecializationKind() ==
1762 D->getTemplateSpecializationKind() == TSK_ExplicitInstantiationDefinition;
1763 Record.push_back(ExplicitInstantiation);
1764 if (ExplicitInstantiation) {
1765 Record.AddSourceLocation(D->getExternKeywordLoc());
1766 Record.AddSourceLocation(D->getTemplateKeywordLoc());
1767 }
1768
1769 const ASTTemplateArgumentListInfo *ArgsWritten =
1770 D->getTemplateArgsAsWritten();
1771 Record.push_back(!!ArgsWritten);
1772 if (ArgsWritten)
1773 Record.AddASTTemplateArgumentListInfo(ArgsWritten);
1774
1776}
1777
1780 Record.AddTemplateParameterList(D->getTemplateParameters());
1781
1783
1784 // These are read/set from/to the first declaration.
1785 if (D->getPreviousDecl() == nullptr) {
1786 Record.AddDeclRef(D->getInstantiatedFromMember());
1787 Record.push_back(D->isMemberSpecialization());
1788 }
1789
1791}
1792
1795
1796 if (D->isFirstDecl())
1799}
1800
1803 RegisterTemplateSpecialization(D->getSpecializedTemplate(), D);
1804
1805 llvm::PointerUnion<VarTemplateDecl *, VarTemplatePartialSpecializationDecl *>
1806 InstFrom = D->getSpecializedTemplateOrPartial();
1807 if (Decl *InstFromD = InstFrom.dyn_cast<VarTemplateDecl *>()) {
1808 Record.AddDeclRef(InstFromD);
1809 } else {
1810 Record.AddDeclRef(InstFrom.get<VarTemplatePartialSpecializationDecl *>());
1811 Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
1812 }
1813
1814 bool ExplicitInstantiation =
1815 D->getTemplateSpecializationKind() ==
1817 D->getTemplateSpecializationKind() == TSK_ExplicitInstantiationDefinition;
1818 Record.push_back(ExplicitInstantiation);
1819 if (ExplicitInstantiation) {
1820 Record.AddSourceLocation(D->getExternKeywordLoc());
1821 Record.AddSourceLocation(D->getTemplateKeywordLoc());
1822 }
1823
1824 const ASTTemplateArgumentListInfo *ArgsWritten =
1825 D->getTemplateArgsAsWritten();
1826 Record.push_back(!!ArgsWritten);
1827 if (ArgsWritten)
1828 Record.AddASTTemplateArgumentListInfo(ArgsWritten);
1829
1830 Record.AddTemplateArgumentList(&D->getTemplateArgs());
1831 Record.AddSourceLocation(D->getPointOfInstantiation());
1832 Record.push_back(D->getSpecializationKind());
1833 Record.push_back(D->IsCompleteDefinition);
1834
1835 VisitVarDecl(D);
1836
1837 Record.push_back(D->isCanonicalDecl());
1838
1839 if (D->isCanonicalDecl()) {
1840 // When reading, we'll add it to the folding set of the following template.
1841 Record.AddDeclRef(D->getSpecializedTemplate()->getCanonicalDecl());
1842 }
1843
1845}
1846
1849 Record.AddTemplateParameterList(D->getTemplateParameters());
1850
1852
1853 // These are read/set from/to the first declaration.
1854 if (D->getPreviousDecl() == nullptr) {
1855 Record.AddDeclRef(D->getInstantiatedFromMember());
1856 Record.push_back(D->isMemberSpecialization());
1857 }
1858
1860}
1861
1864
1865 if (D->isFirstDecl())
1868}
1869
1871 Record.push_back(D->hasTypeConstraint());
1873
1874 Record.push_back(D->wasDeclaredWithTypename());
1875
1876 const TypeConstraint *TC = D->getTypeConstraint();
1877 assert((bool)TC == D->hasTypeConstraint());
1878 if (TC) {
1879 auto *CR = TC->getConceptReference();
1880 Record.push_back(CR != nullptr);
1881 if (CR)
1882 Record.AddConceptReference(CR);
1884 Record.push_back(D->isExpandedParameterPack());
1885 if (D->isExpandedParameterPack())
1886 Record.push_back(D->getNumExpansionParameters());
1887 }
1888
1889 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1890 !D->defaultArgumentWasInherited();
1891 Record.push_back(OwnsDefaultArg);
1892 if (OwnsDefaultArg)
1893 Record.AddTemplateArgumentLoc(D->getDefaultArgument());
1894
1895 if (!TC && !OwnsDefaultArg &&
1897 !D->isInvalidDecl() && !D->hasAttrs() &&
1899 D->getDeclName().getNameKind() == DeclarationName::Identifier)
1900 AbbrevToUse = Writer.getDeclTemplateTypeParmAbbrev();
1901
1903}
1904
1906 // For an expanded parameter pack, record the number of expansion types here
1907 // so that it's easier for deserialization to allocate the right amount of
1908 // memory.
1909 Expr *TypeConstraint = D->getPlaceholderTypeConstraint();
1910 Record.push_back(!!TypeConstraint);
1911 if (D->isExpandedParameterPack())
1912 Record.push_back(D->getNumExpansionTypes());
1913
1915 // TemplateParmPosition.
1916 Record.push_back(D->getDepth());
1917 Record.push_back(D->getPosition());
1918 if (TypeConstraint)
1919 Record.AddStmt(TypeConstraint);
1920
1921 if (D->isExpandedParameterPack()) {
1922 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
1923 Record.AddTypeRef(D->getExpansionType(I));
1924 Record.AddTypeSourceInfo(D->getExpansionTypeSourceInfo(I));
1925 }
1926
1928 } else {
1929 // Rest of NonTypeTemplateParmDecl.
1930 Record.push_back(D->isParameterPack());
1931 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1932 !D->defaultArgumentWasInherited();
1933 Record.push_back(OwnsDefaultArg);
1934 if (OwnsDefaultArg)
1935 Record.AddTemplateArgumentLoc(D->getDefaultArgument());
1937 }
1938}
1939
1941 // For an expanded parameter pack, record the number of expansion types here
1942 // so that it's easier for deserialization to allocate the right amount of
1943 // memory.
1944 if (D->isExpandedParameterPack())
1945 Record.push_back(D->getNumExpansionTemplateParameters());
1946
1948 Record.push_back(D->wasDeclaredWithTypename());
1949 // TemplateParmPosition.
1950 Record.push_back(D->getDepth());
1951 Record.push_back(D->getPosition());
1952
1953 if (D->isExpandedParameterPack()) {
1954 for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
1955 I != N; ++I)
1956 Record.AddTemplateParameterList(D->getExpansionTemplateParameters(I));
1958 } else {
1959 // Rest of TemplateTemplateParmDecl.
1960 Record.push_back(D->isParameterPack());
1961 bool OwnsDefaultArg = D->hasDefaultArgument() &&
1962 !D->defaultArgumentWasInherited();
1963 Record.push_back(OwnsDefaultArg);
1964 if (OwnsDefaultArg)
1965 Record.AddTemplateArgumentLoc(D->getDefaultArgument());
1967 }
1968}
1969
1973}
1974
1976 VisitDecl(D);
1977 Record.AddStmt(D->getAssertExpr());
1978 Record.push_back(D->isFailed());
1979 Record.AddStmt(D->getMessage());
1980 Record.AddSourceLocation(D->getRParenLoc());
1982}
1983
1984/// Emit the DeclContext part of a declaration context decl.
1986 static_assert(DeclContext::NumDeclContextBits == 13,
1987 "You need to update the serializer after you change the "
1988 "DeclContextBits");
1989
1990 uint64_t LexicalOffset = 0;
1991 uint64_t VisibleOffset = 0;
1992
1993 if (Writer.isGeneratingReducedBMI() && isa<NamespaceDecl>(DC) &&
1994 cast<NamespaceDecl>(DC)->isFromExplicitGlobalModule()) {
1995 // In reduced BMI, delay writing lexical and visible block for namespace
1996 // in the global module fragment. See the comments of DelayedNamespace for
1997 // details.
1998 Writer.DelayedNamespace.push_back(cast<NamespaceDecl>(DC));
1999 } else {
2000 LexicalOffset = Writer.WriteDeclContextLexicalBlock(Context, DC);
2001 VisibleOffset = Writer.WriteDeclContextVisibleBlock(Context, DC);
2002 }
2003
2004 Record.AddOffset(LexicalOffset);
2005 Record.AddOffset(VisibleOffset);
2006}
2007
2009 assert(IsLocalDecl(D) && "expected a local declaration");
2010
2011 const Decl *Canon = D->getCanonicalDecl();
2012 if (IsLocalDecl(Canon))
2013 return Canon;
2014
2015 const Decl *&CacheEntry = FirstLocalDeclCache[Canon];
2016 if (CacheEntry)
2017 return CacheEntry;
2018
2019 for (const Decl *Redecl = D; Redecl; Redecl = Redecl->getPreviousDecl())
2020 if (IsLocalDecl(Redecl))
2021 D = Redecl;
2022 return CacheEntry = D;
2023}
2024
2025template <typename T>
2027 T *First = D->getFirstDecl();
2028 T *MostRecent = First->getMostRecentDecl();
2029 T *DAsT = static_cast<T *>(D);
2030 if (MostRecent != First) {
2031 assert(isRedeclarableDeclKind(DAsT->getKind()) &&
2032 "Not considered redeclarable?");
2033
2034 Record.AddDeclRef(First);
2035
2036 // Write out a list of local redeclarations of this declaration if it's the
2037 // first local declaration in the chain.
2038 const Decl *FirstLocal = Writer.getFirstLocalDecl(DAsT);
2039 if (DAsT == FirstLocal) {
2040 // Emit a list of all imported first declarations so that we can be sure
2041 // that all redeclarations visible to this module are before D in the
2042 // redecl chain.
2043 unsigned I = Record.size();
2044 Record.push_back(0);
2045 if (Writer.Chain)
2046 AddFirstDeclFromEachModule(DAsT, /*IncludeLocal*/false);
2047 // This is the number of imported first declarations + 1.
2048 Record[I] = Record.size() - I;
2049
2050 // Collect the set of local redeclarations of this declaration, from
2051 // newest to oldest.
2052 ASTWriter::RecordData LocalRedecls;
2053 ASTRecordWriter LocalRedeclWriter(Record, LocalRedecls);
2054 for (const Decl *Prev = FirstLocal->getMostRecentDecl();
2055 Prev != FirstLocal; Prev = Prev->getPreviousDecl())
2056 if (!Prev->isFromASTFile())
2057 LocalRedeclWriter.AddDeclRef(Prev);
2058
2059 // If we have any redecls, write them now as a separate record preceding
2060 // the declaration itself.
2061 if (LocalRedecls.empty())
2062 Record.push_back(0);
2063 else
2064 Record.AddOffset(LocalRedeclWriter.Emit(LOCAL_REDECLARATIONS));
2065 } else {
2066 Record.push_back(0);
2067 Record.AddDeclRef(FirstLocal);
2068 }
2069
2070 // Make sure that we serialize both the previous and the most-recent
2071 // declarations, which (transitively) ensures that all declarations in the
2072 // chain get serialized.
2073 //
2074 // FIXME: This is not correct; when we reach an imported declaration we
2075 // won't emit its previous declaration.
2076 (void)Writer.GetDeclRef(D->getPreviousDecl());
2077 (void)Writer.GetDeclRef(MostRecent);
2078 } else {
2079 // We use the sentinel value 0 to indicate an only declaration.
2080 Record.push_back(0);
2081 }
2082}
2083
2087 Record.push_back(D->isCBuffer());
2088 Record.AddSourceLocation(D->getLocStart());
2089 Record.AddSourceLocation(D->getLBraceLoc());
2090 Record.AddSourceLocation(D->getRBraceLoc());
2091
2093}
2094
2096 Record.writeOMPChildren(D->Data);
2097 VisitDecl(D);
2099}
2100
2102 Record.writeOMPChildren(D->Data);
2103 VisitDecl(D);
2105}
2106
2108 Record.writeOMPChildren(D->Data);
2109 VisitDecl(D);
2111}
2112
2114 static_assert(DeclContext::NumOMPDeclareReductionDeclBits == 15,
2115 "You need to update the serializer after you change the "
2116 "NumOMPDeclareReductionDeclBits");
2117
2119 Record.AddSourceLocation(D->getBeginLoc());
2120 Record.AddStmt(D->getCombinerIn());
2121 Record.AddStmt(D->getCombinerOut());
2122 Record.AddStmt(D->getCombiner());
2123 Record.AddStmt(D->getInitOrig());
2124 Record.AddStmt(D->getInitPriv());
2125 Record.AddStmt(D->getInitializer());
2126 Record.push_back(llvm::to_underlying(D->getInitializerKind()));
2127 Record.AddDeclRef(D->getPrevDeclInScope());
2129}
2130
2132 Record.writeOMPChildren(D->Data);
2134 Record.AddDeclarationName(D->getVarName());
2135 Record.AddDeclRef(D->getPrevDeclInScope());
2137}
2138
2140 VisitVarDecl(D);
2142}
2143
2144//===----------------------------------------------------------------------===//
2145// ASTWriter Implementation
2146//===----------------------------------------------------------------------===//
2147
2148namespace {
2149template <FunctionDecl::TemplatedKind Kind>
2150std::shared_ptr<llvm::BitCodeAbbrev>
2151getFunctionDeclAbbrev(serialization::DeclCode Code) {
2152 using namespace llvm;
2153
2154 auto Abv = std::make_shared<BitCodeAbbrev>();
2155 Abv->Add(BitCodeAbbrevOp(Code));
2156 // RedeclarableDecl
2157 Abv->Add(BitCodeAbbrevOp(0)); // CanonicalDecl
2158 Abv->Add(BitCodeAbbrevOp(Kind));
2159 if constexpr (Kind == FunctionDecl::TK_NonTemplate) {
2160
2161 } else if constexpr (Kind == FunctionDecl::TK_FunctionTemplate) {
2162 // DescribedFunctionTemplate
2163 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
2164 } else if constexpr (Kind == FunctionDecl::TK_DependentNonTemplate) {
2165 // Instantiated From Decl
2166 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
2167 } else if constexpr (Kind == FunctionDecl::TK_MemberSpecialization) {
2168 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedFrom
2169 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2170 3)); // TemplateSpecializationKind
2171 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Specialized Location
2172 } else if constexpr (Kind ==
2174 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Template
2175 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2176 3)); // TemplateSpecializationKind
2177 Abv->Add(BitCodeAbbrevOp(1)); // Template Argument Size
2178 Abv->Add(BitCodeAbbrevOp(TemplateArgument::Type)); // Template Argument Kind
2179 Abv->Add(
2180 BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Template Argument Type
2181 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // Is Defaulted
2182 Abv->Add(BitCodeAbbrevOp(0)); // TemplateArgumentsAsWritten
2183 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
2184 Abv->Add(BitCodeAbbrevOp(0));
2185 Abv->Add(
2186 BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Canonical Decl of template
2187 } else if constexpr (Kind == FunctionDecl::
2189 // Candidates of specialization
2190 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2191 Abv->Add(BitCodeAbbrevOp(0)); // TemplateArgumentsAsWritten
2192 } else {
2193 llvm_unreachable("Unknown templated kind?");
2194 }
2195 // Decl
2196 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2197 8)); // Packed DeclBits: ModuleOwnershipKind,
2198 // isUsed, isReferenced, AccessSpecifier,
2199 // isImplicit
2200 //
2201 // The following bits should be 0:
2202 // HasStandaloneLexicalDC, HasAttrs,
2203 // TopLevelDeclInObjCContainer,
2204 // isInvalidDecl
2205 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2206 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2207 // NamedDecl
2208 Abv->Add(BitCodeAbbrevOp(DeclarationName::Identifier)); // NameKind
2209 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Identifier
2210 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2211 // ValueDecl
2212 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2213 // DeclaratorDecl
2214 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerLocStart
2215 Abv->Add(BitCodeAbbrevOp(0)); // HasExtInfo
2216 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
2217 // FunctionDecl
2218 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS
2219 Abv->Add(BitCodeAbbrevOp(
2220 BitCodeAbbrevOp::Fixed,
2221 28)); // Packed Function Bits: StorageClass, Inline, InlineSpecified,
2222 // VirtualAsWritten, Pure, HasInheritedProto, HasWrittenProto,
2223 // Deleted, Trivial, TrivialForCall, Defaulted, ExplicitlyDefaulted,
2224 // IsIneligibleOrNotSelected, ImplicitReturnZero, Constexpr,
2225 // UsesSEHTry, SkippedBody, MultiVersion, LateParsed,
2226 // FriendConstraintRefersToEnclosingTemplate, Linkage,
2227 // ShouldSkipCheckingODR
2228 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LocEnd
2229 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); // ODRHash
2230 // This Array slurps the rest of the record. Fortunately we want to encode
2231 // (nearly) all the remaining (variable number of) fields in the same way.
2232 //
2233 // This is:
2234 // NumParams and Params[] from FunctionDecl, and
2235 // NumOverriddenMethods, OverriddenMethods[] from CXXMethodDecl.
2236 //
2237 // Add an AbbrevOp for 'size then elements' and use it here.
2238 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2239 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
2240 return Abv;
2241}
2242
2243template <FunctionDecl::TemplatedKind Kind>
2244std::shared_ptr<llvm::BitCodeAbbrev> getCXXMethodAbbrev() {
2245 return getFunctionDeclAbbrev<Kind>(serialization::DECL_CXX_METHOD);
2246}
2247} // namespace
2248
2249void ASTWriter::WriteDeclAbbrevs() {
2250 using namespace llvm;
2251
2252 std::shared_ptr<BitCodeAbbrev> Abv;
2253
2254 // Abbreviation for DECL_FIELD
2255 Abv = std::make_shared<BitCodeAbbrev>();
2256 Abv->Add(BitCodeAbbrevOp(serialization::DECL_FIELD));
2257 // Decl
2258 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2259 7)); // Packed DeclBits: ModuleOwnershipKind,
2260 // isUsed, isReferenced, AccessSpecifier,
2261 //
2262 // The following bits should be 0:
2263 // isImplicit, HasStandaloneLexicalDC, HasAttrs,
2264 // TopLevelDeclInObjCContainer,
2265 // isInvalidDecl
2266 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2267 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2268 // NamedDecl
2269 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2270 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2271 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2272 // ValueDecl
2273 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2274 // DeclaratorDecl
2275 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
2276 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
2277 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
2278 // FieldDecl
2279 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
2280 Abv->Add(BitCodeAbbrevOp(0)); // StorageKind
2281 // Type Source Info
2282 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2283 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
2284 DeclFieldAbbrev = Stream.EmitAbbrev(std::move(Abv));
2285
2286 // Abbreviation for DECL_OBJC_IVAR
2287 Abv = std::make_shared<BitCodeAbbrev>();
2288 Abv->Add(BitCodeAbbrevOp(serialization::DECL_OBJC_IVAR));
2289 // Decl
2290 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2291 12)); // Packed DeclBits: HasStandaloneLexicalDC,
2292 // isInvalidDecl, HasAttrs, isImplicit, isUsed,
2293 // isReferenced, TopLevelDeclInObjCContainer,
2294 // AccessSpecifier, ModuleOwnershipKind
2295 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2296 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2297 // NamedDecl
2298 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2299 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2300 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2301 // ValueDecl
2302 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2303 // DeclaratorDecl
2304 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
2305 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
2306 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
2307 // FieldDecl
2308 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
2309 Abv->Add(BitCodeAbbrevOp(0)); // InitStyle
2310 // ObjC Ivar
2311 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl
2312 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize
2313 // Type Source Info
2314 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2315 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
2316 DeclObjCIvarAbbrev = Stream.EmitAbbrev(std::move(Abv));
2317
2318 // Abbreviation for DECL_ENUM
2319 Abv = std::make_shared<BitCodeAbbrev>();
2320 Abv->Add(BitCodeAbbrevOp(serialization::DECL_ENUM));
2321 // Redeclarable
2322 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
2323 // Decl
2324 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2325 7)); // Packed DeclBits: ModuleOwnershipKind,
2326 // isUsed, isReferenced, AccessSpecifier,
2327 //
2328 // The following bits should be 0:
2329 // isImplicit, HasStandaloneLexicalDC, HasAttrs,
2330 // TopLevelDeclInObjCContainer,
2331 // isInvalidDecl
2332 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2333 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2334 // NamedDecl
2335 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2336 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2337 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2338 // TypeDecl
2339 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2340 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
2341 // TagDecl
2342 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
2343 Abv->Add(BitCodeAbbrevOp(
2344 BitCodeAbbrevOp::Fixed,
2345 9)); // Packed Tag Decl Bits: getTagKind, isCompleteDefinition,
2346 // EmbeddedInDeclarator, IsFreeStanding,
2347 // isCompleteDefinitionRequired, ExtInfoKind
2348 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
2349 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
2350 // EnumDecl
2351 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // AddTypeRef
2352 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IntegerType
2353 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getPromotionType
2354 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 20)); // Enum Decl Bits
2355 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32));// ODRHash
2356 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InstantiatedMembEnum
2357 // DC
2358 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
2359 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
2360 DeclEnumAbbrev = Stream.EmitAbbrev(std::move(Abv));
2361
2362 // Abbreviation for DECL_RECORD
2363 Abv = std::make_shared<BitCodeAbbrev>();
2364 Abv->Add(BitCodeAbbrevOp(serialization::DECL_RECORD));
2365 // Redeclarable
2366 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
2367 // Decl
2368 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2369 7)); // Packed DeclBits: ModuleOwnershipKind,
2370 // isUsed, isReferenced, AccessSpecifier,
2371 //
2372 // The following bits should be 0:
2373 // isImplicit, HasStandaloneLexicalDC, HasAttrs,
2374 // TopLevelDeclInObjCContainer,
2375 // isInvalidDecl
2376 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2377 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2378 // NamedDecl
2379 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2380 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2381 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2382 // TypeDecl
2383 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2384 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
2385 // TagDecl
2386 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // IdentifierNamespace
2387 Abv->Add(BitCodeAbbrevOp(
2388 BitCodeAbbrevOp::Fixed,
2389 9)); // Packed Tag Decl Bits: getTagKind, isCompleteDefinition,
2390 // EmbeddedInDeclarator, IsFreeStanding,
2391 // isCompleteDefinitionRequired, ExtInfoKind
2392 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
2393 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SourceLocation
2394 // RecordDecl
2395 Abv->Add(BitCodeAbbrevOp(
2396 BitCodeAbbrevOp::Fixed,
2397 13)); // Packed Record Decl Bits: FlexibleArrayMember,
2398 // AnonymousStructUnion, hasObjectMember, hasVolatileMember,
2399 // isNonTrivialToPrimitiveDefaultInitialize,
2400 // isNonTrivialToPrimitiveCopy, isNonTrivialToPrimitiveDestroy,
2401 // hasNonTrivialToPrimitiveDefaultInitializeCUnion,
2402 // hasNonTrivialToPrimitiveDestructCUnion,
2403 // hasNonTrivialToPrimitiveCopyCUnion, isParamDestroyedInCallee,
2404 // getArgPassingRestrictions
2405 // ODRHash
2406 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 26));
2407
2408 // DC
2409 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LexicalOffset
2410 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // VisibleOffset
2411 DeclRecordAbbrev = Stream.EmitAbbrev(std::move(Abv));
2412
2413 // Abbreviation for DECL_PARM_VAR
2414 Abv = std::make_shared<BitCodeAbbrev>();
2415 Abv->Add(BitCodeAbbrevOp(serialization::DECL_PARM_VAR));
2416 // Redeclarable
2417 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
2418 // Decl
2419 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2420 8)); // Packed DeclBits: ModuleOwnershipKind, isUsed,
2421 // isReferenced, AccessSpecifier,
2422 // HasStandaloneLexicalDC, HasAttrs, isImplicit,
2423 // TopLevelDeclInObjCContainer,
2424 // isInvalidDecl,
2425 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2426 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2427 // NamedDecl
2428 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2429 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2430 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2431 // ValueDecl
2432 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2433 // DeclaratorDecl
2434 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
2435 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
2436 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
2437 // VarDecl
2438 Abv->Add(
2439 BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2440 12)); // Packed Var Decl bits: SClass, TSCSpec, InitStyle,
2441 // isARCPseudoStrong, Linkage, ModulesCodegen
2442 Abv->Add(BitCodeAbbrevOp(0)); // VarKind (local enum)
2443 // ParmVarDecl
2444 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // ScopeIndex
2445 Abv->Add(BitCodeAbbrevOp(
2446 BitCodeAbbrevOp::Fixed,
2447 19)); // Packed Parm Var Decl bits: IsObjCMethodParameter, ScopeDepth,
2448 // ObjCDeclQualifier, KNRPromoted,
2449 // HasInheritedDefaultArg, HasUninstantiatedDefaultArg
2450 // Type Source Info
2451 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2452 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
2453 DeclParmVarAbbrev = Stream.EmitAbbrev(std::move(Abv));
2454
2455 // Abbreviation for DECL_TYPEDEF
2456 Abv = std::make_shared<BitCodeAbbrev>();
2457 Abv->Add(BitCodeAbbrevOp(serialization::DECL_TYPEDEF));
2458 // Redeclarable
2459 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
2460 // Decl
2461 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2462 7)); // Packed DeclBits: ModuleOwnershipKind,
2463 // isReferenced, isUsed, AccessSpecifier. Other
2464 // higher bits should be 0: isImplicit,
2465 // HasStandaloneLexicalDC, HasAttrs,
2466 // TopLevelDeclInObjCContainer, isInvalidDecl
2467 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2468 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2469 // NamedDecl
2470 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2471 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2472 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2473 // TypeDecl
2474 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2475 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
2476 // TypedefDecl
2477 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2478 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
2479 DeclTypedefAbbrev = Stream.EmitAbbrev(std::move(Abv));
2480
2481 // Abbreviation for DECL_VAR
2482 Abv = std::make_shared<BitCodeAbbrev>();
2483 Abv->Add(BitCodeAbbrevOp(serialization::DECL_VAR));
2484 // Redeclarable
2485 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
2486 // Decl
2487 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2488 12)); // Packed DeclBits: HasStandaloneLexicalDC,
2489 // isInvalidDecl, HasAttrs, isImplicit, isUsed,
2490 // isReferenced, TopLevelDeclInObjCContainer,
2491 // AccessSpecifier, ModuleOwnershipKind
2492 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2493 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2494 // NamedDecl
2495 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2496 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2497 Abv->Add(BitCodeAbbrevOp(0)); // AnonDeclNumber
2498 // ValueDecl
2499 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2500 // DeclaratorDecl
2501 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
2502 Abv->Add(BitCodeAbbrevOp(0)); // hasExtInfo
2503 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
2504 // VarDecl
2505 Abv->Add(BitCodeAbbrevOp(
2506 BitCodeAbbrevOp::Fixed,
2507 21)); // Packed Var Decl bits: Linkage, ModulesCodegen,
2508 // SClass, TSCSpec, InitStyle,
2509 // isARCPseudoStrong, IsThisDeclarationADemotedDefinition,
2510 // isExceptionVariable, isNRVOVariable, isCXXForRangeDecl,
2511 // isInline, isInlineSpecified, isConstexpr,
2512 // isInitCapture, isPrevDeclInSameScope,
2513 // EscapingByref, HasDeducedType, ImplicitParamKind, isObjCForDecl
2514 Abv->Add(BitCodeAbbrevOp(0)); // VarKind (local enum)
2515 // Type Source Info
2516 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
2517 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
2518 DeclVarAbbrev = Stream.EmitAbbrev(std::move(Abv));
2519
2520 // Abbreviation for DECL_CXX_METHOD
2521 DeclCXXMethodAbbrev =
2522 Stream.EmitAbbrev(getCXXMethodAbbrev<FunctionDecl::TK_NonTemplate>());
2523 DeclTemplateCXXMethodAbbrev = Stream.EmitAbbrev(
2524 getCXXMethodAbbrev<FunctionDecl::TK_FunctionTemplate>());
2525 DeclDependentNonTemplateCXXMethodAbbrev = Stream.EmitAbbrev(
2526 getCXXMethodAbbrev<FunctionDecl::TK_DependentNonTemplate>());
2527 DeclMemberSpecializedCXXMethodAbbrev = Stream.EmitAbbrev(
2528 getCXXMethodAbbrev<FunctionDecl::TK_MemberSpecialization>());
2529 DeclTemplateSpecializedCXXMethodAbbrev = Stream.EmitAbbrev(
2530 getCXXMethodAbbrev<FunctionDecl::TK_FunctionTemplateSpecialization>());
2531 DeclDependentSpecializationCXXMethodAbbrev = Stream.EmitAbbrev(
2532 getCXXMethodAbbrev<
2534
2535 // Abbreviation for DECL_TEMPLATE_TYPE_PARM
2536 Abv = std::make_shared<BitCodeAbbrev>();
2537 Abv->Add(BitCodeAbbrevOp(serialization::DECL_TEMPLATE_TYPE_PARM));
2538 Abv->Add(BitCodeAbbrevOp(0)); // hasTypeConstraint
2539 // Decl
2540 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2541 7)); // Packed DeclBits: ModuleOwnershipKind,
2542 // isReferenced, isUsed, AccessSpecifier. Other
2543 // higher bits should be 0: isImplicit,
2544 // HasStandaloneLexicalDC, HasAttrs,
2545 // TopLevelDeclInObjCContainer, isInvalidDecl
2546 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2547 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2548 // NamedDecl
2549 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2550 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2551 Abv->Add(BitCodeAbbrevOp(0));
2552 // TypeDecl
2553 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2554 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Ref
2555 // TemplateTypeParmDecl
2556 Abv->Add(
2557 BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // wasDeclaredWithTypename
2558 Abv->Add(BitCodeAbbrevOp(0)); // OwnsDefaultArg
2559 DeclTemplateTypeParmAbbrev = Stream.EmitAbbrev(std::move(Abv));
2560
2561 // Abbreviation for DECL_USING_SHADOW
2562 Abv = std::make_shared<BitCodeAbbrev>();
2563 Abv->Add(BitCodeAbbrevOp(serialization::DECL_USING_SHADOW));
2564 // Redeclarable
2565 Abv->Add(BitCodeAbbrevOp(0)); // No redeclaration
2566 // Decl
2567 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed,
2568 12)); // Packed DeclBits: HasStandaloneLexicalDC,
2569 // isInvalidDecl, HasAttrs, isImplicit, isUsed,
2570 // isReferenced, TopLevelDeclInObjCContainer,
2571 // AccessSpecifier, ModuleOwnershipKind
2572 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclContext
2573 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // SubmoduleID
2574 // NamedDecl
2575 Abv->Add(BitCodeAbbrevOp(0)); // NameKind = Identifier
2576 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Name
2577 Abv->Add(BitCodeAbbrevOp(0));
2578 // UsingShadowDecl
2579 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TargetDecl
2580 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS
2581 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // UsingOrNextShadow
2582 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR,
2583 6)); // InstantiatedFromUsingShadowDecl
2584 DeclUsingShadowAbbrev = Stream.EmitAbbrev(std::move(Abv));
2585
2586 // Abbreviation for EXPR_DECL_REF
2587 Abv = std::make_shared<BitCodeAbbrev>();
2588 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_DECL_REF));
2589 // Stmt
2590 // Expr
2591 // PackingBits: DependenceKind, ValueKind. ObjectKind should be 0.
2592 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 7));
2593 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2594 // DeclRefExpr
2595 // Packing Bits: , HadMultipleCandidates, RefersToEnclosingVariableOrCapture,
2596 // IsImmediateEscalating, NonOdrUseReason.
2597 // GetDeclFound, HasQualifier and ExplicitTemplateArgs should be 0.
2598 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5));
2599 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // DeclRef
2600 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2601 DeclRefExprAbbrev = Stream.EmitAbbrev(std::move(Abv));
2602
2603 // Abbreviation for EXPR_INTEGER_LITERAL
2604 Abv = std::make_shared<BitCodeAbbrev>();
2605 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_INTEGER_LITERAL));
2606 //Stmt
2607 // Expr
2608 // DependenceKind, ValueKind, ObjectKind
2609 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10));
2610 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2611 // Integer Literal
2612 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2613 Abv->Add(BitCodeAbbrevOp(32)); // Bit Width
2614 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value
2615 IntegerLiteralAbbrev = Stream.EmitAbbrev(std::move(Abv));
2616
2617 // Abbreviation for EXPR_CHARACTER_LITERAL
2618 Abv = std::make_shared<BitCodeAbbrev>();
2619 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CHARACTER_LITERAL));
2620 //Stmt
2621 // Expr
2622 // DependenceKind, ValueKind, ObjectKind
2623 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10));
2624 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2625 // Character Literal
2626 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue
2627 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location
2628 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // getKind
2629 CharacterLiteralAbbrev = Stream.EmitAbbrev(std::move(Abv));
2630
2631 // Abbreviation for EXPR_IMPLICIT_CAST
2632 Abv = std::make_shared<BitCodeAbbrev>();
2633 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_IMPLICIT_CAST));
2634 // Stmt
2635 // Expr
2636 // Packing Bits: DependenceKind, ValueKind, ObjectKind,
2637 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10));
2638 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2639 // CastExpr
2640 Abv->Add(BitCodeAbbrevOp(0)); // PathSize
2641 // Packing Bits: CastKind, StoredFPFeatures, isPartOfExplicitCast
2642 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 9));
2643 // ImplicitCastExpr
2644 ExprImplicitCastAbbrev = Stream.EmitAbbrev(std::move(Abv));
2645
2646 // Abbreviation for EXPR_BINARY_OPERATOR
2647 Abv = std::make_shared<BitCodeAbbrev>();
2648 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_BINARY_OPERATOR));
2649 // Stmt
2650 // Expr
2651 // Packing Bits: DependenceKind. ValueKind and ObjectKind should
2652 // be 0 in this case.
2653 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5));
2654 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2655 // BinaryOperator
2656 Abv->Add(
2657 BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // OpCode and HasFPFeatures
2658 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2659 BinaryOperatorAbbrev = Stream.EmitAbbrev(std::move(Abv));
2660
2661 // Abbreviation for EXPR_COMPOUND_ASSIGN_OPERATOR
2662 Abv = std::make_shared<BitCodeAbbrev>();
2663 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_COMPOUND_ASSIGN_OPERATOR));
2664 // Stmt
2665 // Expr
2666 // Packing Bits: DependenceKind. ValueKind and ObjectKind should
2667 // be 0 in this case.
2668 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5));
2669 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2670 // BinaryOperator
2671 // Packing Bits: OpCode. The HasFPFeatures bit should be 0
2672 Abv->Add(
2673 BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // OpCode and HasFPFeatures
2674 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2675 // CompoundAssignOperator
2676 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // LHSType
2677 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Result Type
2678 CompoundAssignOperatorAbbrev = Stream.EmitAbbrev(std::move(Abv));
2679
2680 // Abbreviation for EXPR_CALL
2681 Abv = std::make_shared<BitCodeAbbrev>();
2682 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CALL));
2683 // Stmt
2684 // Expr
2685 // Packing Bits: DependenceKind, ValueKind, ObjectKind,
2686 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10));
2687 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2688 // CallExpr
2689 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumArgs
2690 Abv->Add(BitCodeAbbrevOp(0)); // ADLCallKind
2691 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2692 CallExprAbbrev = Stream.EmitAbbrev(std::move(Abv));
2693
2694 // Abbreviation for EXPR_CXX_OPERATOR_CALL
2695 Abv = std::make_shared<BitCodeAbbrev>();
2696 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CXX_OPERATOR_CALL));
2697 // Stmt
2698 // Expr
2699 // Packing Bits: DependenceKind, ValueKind, ObjectKind,
2700 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10));
2701 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2702 // CallExpr
2703 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumArgs
2704 Abv->Add(BitCodeAbbrevOp(0)); // ADLCallKind
2705 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2706 // CXXOperatorCallExpr
2707 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Operator Kind
2708 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2709 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2710 CXXOperatorCallExprAbbrev = Stream.EmitAbbrev(std::move(Abv));
2711
2712 // Abbreviation for EXPR_CXX_MEMBER_CALL
2713 Abv = std::make_shared<BitCodeAbbrev>();
2714 Abv->Add(BitCodeAbbrevOp(serialization::EXPR_CXX_MEMBER_CALL));
2715 // Stmt
2716 // Expr
2717 // Packing Bits: DependenceKind, ValueKind, ObjectKind,
2718 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 10));
2719 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type
2720 // CallExpr
2721 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // NumArgs
2722 Abv->Add(BitCodeAbbrevOp(0)); // ADLCallKind
2723 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2724 // CXXMemberCallExpr
2725 CXXMemberCallExprAbbrev = Stream.EmitAbbrev(std::move(Abv));
2726
2727 // Abbreviation for STMT_COMPOUND
2728 Abv = std::make_shared<BitCodeAbbrev>();
2729 Abv->Add(BitCodeAbbrevOp(serialization::STMT_COMPOUND));
2730 // Stmt
2731 // CompoundStmt
2732 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Num Stmts
2733 Abv->Add(BitCodeAbbrevOp(0)); // hasStoredFPFeatures
2734 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2735 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2736 CompoundStmtAbbrev = Stream.EmitAbbrev(std::move(Abv));
2737
2738 Abv = std::make_shared<BitCodeAbbrev>();
2739 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_LEXICAL));
2740 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2741 DeclContextLexicalAbbrev = Stream.EmitAbbrev(std::move(Abv));
2742
2743 Abv = std::make_shared<BitCodeAbbrev>();
2744 Abv->Add(BitCodeAbbrevOp(serialization::DECL_CONTEXT_VISIBLE));
2745 Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Blob));
2746 DeclContextVisibleLookupAbbrev = Stream.EmitAbbrev(std::move(Abv));
2747}
2748
2749/// isRequiredDecl - Check if this is a "required" Decl, which must be seen by
2750/// consumers of the AST.
2751///
2752/// Such decls will always be deserialized from the AST file, so we would like
2753/// this to be as restrictive as possible. Currently the predicate is driven by
2754/// code generation requirements, if other clients have a different notion of
2755/// what is "required" then we may have to consider an alternate scheme where
2756/// clients can iterate over the top-level decls and get information on them,
2757/// without necessary deserializing them. We could explicitly require such
2758/// clients to use a separate API call to "realize" the decl. This should be
2759/// relatively painless since they would presumably only do it for top-level
2760/// decls.
2761static bool isRequiredDecl(const Decl *D, ASTContext &Context,
2762 Module *WritingModule) {
2763 // Named modules have different semantics than header modules. Every named
2764 // module units owns a translation unit. So the importer of named modules
2765 // doesn't need to deserilize everything ahead of time.
2766 if (WritingModule && WritingModule->isNamedModule()) {
2767 // The PragmaCommentDecl and PragmaDetectMismatchDecl are MSVC's extension.
2768 // And the behavior of MSVC for such cases will leak this to the module
2769 // users. Given pragma is not a standard thing, the compiler has the space
2770 // to do their own decision. Let's follow MSVC here.
2771 if (isa<PragmaCommentDecl, PragmaDetectMismatchDecl>(D))
2772 return true;
2773 return false;
2774 }
2775
2776 // An ObjCMethodDecl is never considered as "required" because its
2777 // implementation container always is.
2778
2779 // File scoped assembly or obj-c or OMP declare target implementation must be
2780 // seen.
2781 if (isa<FileScopeAsmDecl, TopLevelStmtDecl, ObjCImplDecl>(D))
2782 return true;
2783
2784 if (WritingModule && isPartOfPerModuleInitializer(D)) {
2785 // These declarations are part of the module initializer, and are emitted
2786 // if and when the module is imported, rather than being emitted eagerly.
2787 return false;
2788 }
2789
2790 return Context.DeclMustBeEmitted(D);
2791}
2792
2793void ASTWriter::WriteDecl(ASTContext &Context, Decl *D) {
2794 PrettyDeclStackTraceEntry CrashInfo(Context, D, SourceLocation(),
2795 "serializing");
2796
2797 // Determine the ID for this declaration.
2799 assert(!D->isFromASTFile() && "should not be emitting imported decl");
2800 LocalDeclID &IDR = DeclIDs[D];
2801 if (IDR.isInvalid())
2802 IDR = NextDeclID++;
2803
2804 ID = IDR;
2805
2806 assert(ID >= FirstDeclID && "invalid decl ID");
2807
2809 ASTDeclWriter W(*this, Context, Record, GeneratingReducedBMI);
2810
2811 // Build a record for this declaration
2812 W.Visit(D);
2813
2814 // Emit this declaration to the bitstream.
2815 uint64_t Offset = W.Emit(D);
2816
2817 // Record the offset for this declaration
2820 getRawSourceLocationEncoding(getAdjustedLocation(Loc));
2821
2822 unsigned Index = ID.getRawValue() - FirstDeclID.getRawValue();
2823 if (DeclOffsets.size() == Index)
2824 DeclOffsets.emplace_back(RawLoc, Offset, DeclTypesBlockStartOffset);
2825 else if (DeclOffsets.size() < Index) {
2826 // FIXME: Can/should this happen?
2827 DeclOffsets.resize(Index+1);
2828 DeclOffsets[Index].setRawLoc(RawLoc);
2829 DeclOffsets[Index].setBitOffset(Offset, DeclTypesBlockStartOffset);
2830 } else {
2831 llvm_unreachable("declarations should be emitted in ID order");
2832 }
2833
2834 SourceManager &SM = Context.getSourceManager();
2835 if (Loc.isValid() && SM.isLocalSourceLocation(Loc))
2836 associateDeclWithFile(D, ID);
2837
2838 // Note declarations that should be deserialized eagerly so that we can add
2839 // them to a record in the AST file later.
2840 if (isRequiredDecl(D, Context, WritingModule))
2841 AddDeclRef(D, EagerlyDeserializedDecls);
2842}
2843
2845 // Switch case IDs are per function body.
2846 Writer->ClearSwitchCaseIDs();
2847
2848 assert(FD->doesThisDeclarationHaveABody());
2849 bool ModulesCodegen = false;
2850 if (!FD->isDependentContext()) {
2851 std::optional<GVALinkage> Linkage;
2852 if (Writer->WritingModule &&
2853 Writer->WritingModule->isInterfaceOrPartition()) {
2854 // When building a C++20 module interface unit or a partition unit, a
2855 // strong definition in the module interface is provided by the
2856 // compilation of that unit, not by its users. (Inline functions are still
2857 // emitted in module users.)
2858 Linkage = Writer->Context->GetGVALinkageForFunction(FD);
2859 ModulesCodegen = *Linkage >= GVA_StrongExternal;
2860 }
2861 if (Writer->Context->getLangOpts().ModulesCodegen ||
2862 (FD->hasAttr<DLLExportAttr>() &&
2863 Writer->Context->getLangOpts().BuildingPCHWithObjectFile)) {
2864
2865 // Under -fmodules-codegen, codegen is performed for all non-internal,
2866 // non-always_inline functions, unless they are available elsewhere.
2867 if (!FD->hasAttr<AlwaysInlineAttr>()) {
2868 if (!Linkage)
2869 Linkage = Writer->Context->GetGVALinkageForFunction(FD);
2870 ModulesCodegen =
2872 }
2873 }
2874 }
2875 Record->push_back(ModulesCodegen);
2876 if (ModulesCodegen)
2877 Writer->AddDeclRef(FD, Writer->ModularCodegenDecls);
2878 if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
2879 Record->push_back(CD->getNumCtorInitializers());
2880 if (CD->getNumCtorInitializers())
2881 AddCXXCtorInitializers(llvm::ArrayRef(CD->init_begin(), CD->init_end()));
2882 }
2883 AddStmt(FD->getBody());
2884}
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:758
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:186
SourceManager & getSourceManager()
Definition: ASTContext.h:720
NamedDecl * getInstantiatedFromUsingDecl(NamedDecl *Inst)
If the given using decl Inst is an instantiation of another (possibly unresolved) using decl,...
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:663
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:796
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:1224
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:7718
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:6534
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:800
unsigned getDeclTemplateTypeParmAbbrev() const
Definition: ASTWriter.h:824
unsigned getDeclObjCIvarAbbrev() const
Definition: ASTWriter.h:806
unsigned getDeclTypedefAbbrev() const
Definition: ASTWriter.h:802
bool hasChain() const
Definition: ASTWriter.h:843
unsigned getDeclUsingShadowAbbrev() const
Definition: ASTWriter.h:827
bool isGeneratingReducedBMI() const
Definition: ASTWriter.h:852
unsigned getDeclVarAbbrev() const
Definition: ASTWriter.h:803
unsigned getDeclEnumAbbrev() const
Definition: ASTWriter.h:805
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:727
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:6198
unsigned getDeclCXXMethodAbbrev(FunctionDecl::TemplatedKind Kind) const
Definition: ASTWriter.h:807
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:5968
SmallVector< uint64_t, 64 > RecordData
Definition: ASTWriter.h:94
unsigned getAnonymousDeclarationNumber(const NamedDecl *D)
Definition: ASTWriter.cpp:6306
unsigned getDeclFieldAbbrev() const
Definition: ASTWriter.h:804
unsigned getDeclRecordAbbrev() const
Definition: ASTWriter.h:801
void AddDeclRef(const Decl *D, RecordDataImpl &Record)
Emit a reference to a declaration.
Definition: ASTWriter.cpp:6194
Represents an access specifier followed by colon ':'.
Definition: DeclCXX.h:86
A binding in a decomposition declaration.
Definition: DeclCXX.h:4107
A simple helper class to pack several bits in order into (a) 32 bit integer(s).
Definition: ASTWriter.h:995
void addBit(bool Value)
Definition: ASTWriter.h:1015
void addBits(uint32_t Value, uint32_t BitsWidth)
Definition: ASTWriter.h:1016
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4467
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2535
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2862
Represents a C++ deduction guide declaration.
Definition: DeclCXX.h:1952
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2799
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2060
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
static bool classofKind(Kind K)
Definition: DeclCXX.h:1889
Represents the body of a CapturedStmt, and serves as its DeclContext.
Definition: Decl.h:4666
unsigned getNumParams() const
Definition: Decl.h:4708
unsigned getContextParamPosition() const
Definition: Decl.h:4737
bool isNothrow() const
Definition: Decl.cpp:5431
ImplicitParamDecl * getParam(unsigned i) const
Definition: Decl.h:4710
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:3598
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:1425
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1309
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:1893
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:1040
Decl * getMostRecentDecl()
Retrieve the most recent declaration that declares the same entity as this declaration (which may be ...
Definition: DeclBase.h:1055
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:441
bool isModulePrivate() const
Whether this declaration was marked as being private to the module in which it was defined.
Definition: DeclBase.h:648
bool hasAttrs() const
Definition: DeclBase.h:524
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:599
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:855
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:1066
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:963
Module * getOwningModule() const
Get the module that owns this declaration (for visibility purposes).
Definition: DeclBase.h:825
bool isFirstDecl() const
True if this is the first declaration in its redeclaration chain.
Definition: DeclBase.h:1049
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
Definition: DeclBase.h:776
bool isInvalidDecl() const
Definition: DeclBase.h:594
unsigned getIdentifierNamespace() const
Definition: DeclBase.h:868
SourceLocation getLocation() const
Definition: DeclBase.h:445
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:634
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:454
AccessSpecifier getAccess() const
Definition: DeclBase.h:513
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:437
AttrVec & getAttrs()
Definition: DeclBase.h:530
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:897
bool hasAttr() const
Definition: DeclBase.h:583
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:957
Kind getKind() const
Definition: DeclBase.h:448
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:4166
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:4905
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3270
Represents an enum.
Definition: Decl.h:3840
Store information needed for an explicit specifier.
Definition: DeclCXX.h:1897
ExplicitSpecKind getKind() const
Definition: DeclCXX.h:1905
const Expr * getExpr() const
Definition: DeclCXX.h:1906
Represents a standard C++ module export declaration.
Definition: Decl.h:4858
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:4920
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4779
Represents a field injected from an anonymous union/struct into the parent scope.
Definition: Decl.h:3314
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:3229
Represents a linkage specification.
Definition: DeclCXX.h:2934
A global _GUID constant.
Definition: DeclCXX.h:4289
An instance of this class represents the declaration of a property member.
Definition: DeclCXX.h:4235
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:3120
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:2028
static bool classofKind(Kind K)
Definition: DeclObjC.h:2049
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2326
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition: DeclObjC.h:2542
ObjCCompatibleAliasDecl - Represents alias of a class.
Definition: DeclObjC.h:2772
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:2594
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1950
static bool classofKind(Kind K)
Definition: DeclObjC.h:2013
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:2802
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2082
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:4141
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:2029
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:4058
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:3557
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:4430
The top declaration context.
Definition: Decl.h:84
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:3528
Declaration of an alias template.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
Definition: ASTConcept.h:228
Expr * getImmediatelyDeclaredConstraint() const
Get the immediately-declared constraint expression introduced by this type-constraint,...
Definition: ASTConcept.h:243
ConceptReference * getConceptReference() const
Definition: ASTConcept.h:247
Represents a declaration of a type.
Definition: Decl.h:3363
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition: Decl.h:3507
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3405
An artificial decl, representing a global anonymous constant value which is uniquified by value withi...
Definition: DeclCXX.h:4346
This node is generated when a using-declaration that was annotated with attribute((using_if_exists)) ...
Definition: DeclCXX.h:4040
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3959
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3862
Represents a C++ using-declaration.
Definition: DeclCXX.h:3512
Represents C++ using-directive.
Definition: DeclCXX.h:3015
Represents a C++ using-enum-declaration.
Definition: DeclCXX.h:3713
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition: DeclCXX.h:3794
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3320
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:1199
DeclCode
Record codes for each kind of declaration.
Definition: ASTBitCodes.h:1207
@ DECL_EMPTY
An EmptyDecl record.
Definition: ASTBitCodes.h:1455
@ DECL_CAPTURED
A CapturedDecl record.
Definition: ASTBitCodes.h:1296
@ DECL_CXX_RECORD
A CXXRecordDecl record.
Definition: ASTBitCodes.h:1357
@ DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION
A VarTemplatePartialSpecializationDecl record.
Definition: ASTBitCodes.h:1399
@ DECL_OMP_ALLOCATE
An OMPAllocateDcl record.
Definition: ASTBitCodes.h:1452
@ DECL_MS_PROPERTY
A MSPropertyDecl record.
Definition: ASTBitCodes.h:1263
@ DECL_OMP_DECLARE_MAPPER
An OMPDeclareMapperDecl record.
Definition: ASTBitCodes.h:1476
@ DECL_TOP_LEVEL_STMT_DECL
A TopLevelStmtDecl record.
Definition: ASTBitCodes.h:1290
@ DECL_REQUIRES_EXPR_BODY
A RequiresExprBodyDecl record.
Definition: ASTBitCodes.h:1461
@ DECL_STATIC_ASSERT
A StaticAssertDecl record.
Definition: ASTBitCodes.h:1423
@ DECL_INDIRECTFIELD
A IndirectFieldDecl record.
Definition: ASTBitCodes.h:1432
@ DECL_TEMPLATE_TEMPLATE_PARM
A TemplateTemplateParmDecl record.
Definition: ASTBitCodes.h:1411
@ DECL_IMPORT
An ImportDecl recording a module import.
Definition: ASTBitCodes.h:1443
@ DECL_UNNAMED_GLOBAL_CONSTANT
A UnnamedGlobalConstantDecl record.
Definition: ASTBitCodes.h:1482
@ DECL_ACCESS_SPEC
An AccessSpecDecl record.
Definition: ASTBitCodes.h:1375
@ DECL_OBJC_TYPE_PARAM
An ObjCTypeParamDecl record.
Definition: ASTBitCodes.h:1464
@ DECL_OBJC_CATEGORY_IMPL
A ObjCCategoryImplDecl record.
Definition: ASTBitCodes.h:1245
@ DECL_ENUM_CONSTANT
An EnumConstantDecl record.
Definition: ASTBitCodes.h:1221
@ DECL_PARM_VAR
A ParmVarDecl record.
Definition: ASTBitCodes.h:1278
@ DECL_TYPEDEF
A TypedefDecl record.
Definition: ASTBitCodes.h:1209
@ DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK
A TemplateTemplateParmDecl record that stores an expanded template template parameter pack.
Definition: ASTBitCodes.h:1440
@ DECL_HLSL_BUFFER
A HLSLBufferDecl record.
Definition: ASTBitCodes.h:1485
@ DECL_NAMESPACE_ALIAS
A NamespaceAliasDecl record.
Definition: ASTBitCodes.h:1324
@ DECL_TYPEALIAS
A TypeAliasDecl record.
Definition: ASTBitCodes.h:1212
@ DECL_FUNCTION_TEMPLATE
A FunctionTemplateDecl record.
Definition: ASTBitCodes.h:1402
@ DECL_MS_GUID
A MSGuidDecl record.
Definition: ASTBitCodes.h:1266
@ DECL_UNRESOLVED_USING_TYPENAME
An UnresolvedUsingTypenameDecl record.
Definition: ASTBitCodes.h:1348
@ DECL_CLASS_TEMPLATE_SPECIALIZATION
A ClassTemplateSpecializationDecl record.
Definition: ASTBitCodes.h:1387
@ DECL_FILE_SCOPE_ASM
A FileScopeAsmDecl record.
Definition: ASTBitCodes.h:1287
@ DECL_CXX_CONSTRUCTOR
A CXXConstructorDecl record.
Definition: ASTBitCodes.h:1366
@ DECL_CXX_CONVERSION
A CXXConversionDecl record.
Definition: ASTBitCodes.h:1372
@ DECL_FIELD
A FieldDecl record.
Definition: ASTBitCodes.h:1260
@ DECL_LINKAGE_SPEC
A LinkageSpecDecl record.
Definition: ASTBitCodes.h:1351
@ DECL_NAMESPACE
A NamespaceDecl record.
Definition: ASTBitCodes.h:1321
@ DECL_NON_TYPE_TEMPLATE_PARM
A NonTypeTemplateParmDecl record.
Definition: ASTBitCodes.h:1408
@ DECL_USING_PACK
A UsingPackDecl record.
Definition: ASTBitCodes.h:1333
@ DECL_FUNCTION
A FunctionDecl record.
Definition: ASTBitCodes.h:1224
@ DECL_USING_DIRECTIVE
A UsingDirecitveDecl record.
Definition: ASTBitCodes.h:1342
@ DECL_RECORD
A RecordDecl record.
Definition: ASTBitCodes.h:1218
@ DECL_CONTEXT_LEXICAL
A record that stores the set of declarations that are lexically stored within a given DeclContext.
Definition: ASTBitCodes.h:1306
@ DECL_BLOCK
A BlockDecl record.
Definition: ASTBitCodes.h:1293
@ DECL_UNRESOLVED_USING_VALUE
An UnresolvedUsingValueDecl record.
Definition: ASTBitCodes.h:1345
@ DECL_TYPE_ALIAS_TEMPLATE
A TypeAliasTemplateDecl record.
Definition: ASTBitCodes.h:1414
@ DECL_OBJC_CATEGORY
A ObjCCategoryDecl record.
Definition: ASTBitCodes.h:1242
@ DECL_VAR
A VarDecl record.
Definition: ASTBitCodes.h:1272
@ DECL_UNRESOLVED_USING_IF_EXISTS
An UnresolvedUsingIfExistsDecl record.
Definition: ASTBitCodes.h:1420
@ DECL_USING
A UsingDecl record.
Definition: ASTBitCodes.h:1327
@ DECL_OBJC_PROTOCOL
A ObjCProtocolDecl record.
Definition: ASTBitCodes.h:1233
@ DECL_TEMPLATE_TYPE_PARM
A TemplateTypeParmDecl record.
Definition: ASTBitCodes.h:1405
@ DECL_VAR_TEMPLATE_SPECIALIZATION
A VarTemplateSpecializationDecl record.
Definition: ASTBitCodes.h:1396
@ DECL_OBJC_IMPLEMENTATION
A ObjCImplementationDecl record.
Definition: ASTBitCodes.h:1248
@ DECL_LABEL
A LabelDecl record.
Definition: ASTBitCodes.h:1318
@ DECL_OBJC_COMPATIBLE_ALIAS
A ObjCCompatibleAliasDecl record.
Definition: ASTBitCodes.h:1251
@ DECL_CONSTRUCTOR_USING_SHADOW
A ConstructorUsingShadowDecl record.
Definition: ASTBitCodes.h:1339
@ DECL_USING_ENUM
A UsingEnumDecl record.
Definition: ASTBitCodes.h:1330
@ DECL_FRIEND_TEMPLATE
A FriendTemplateDecl record.
Definition: ASTBitCodes.h:1381
@ DECL_PRAGMA_DETECT_MISMATCH
A PragmaDetectMismatchDecl record.
Definition: ASTBitCodes.h:1473
@ DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK
A NonTypeTemplateParmDecl record that stores an expanded non-type template parameter pack.
Definition: ASTBitCodes.h:1436
@ DECL_OBJC_AT_DEFS_FIELD
A ObjCAtDefsFieldDecl record.
Definition: ASTBitCodes.h:1239
@ DECL_IMPLICIT_PARAM
An ImplicitParamDecl record.
Definition: ASTBitCodes.h:1275
@ DECL_FRIEND
A FriendDecl record.
Definition: ASTBitCodes.h:1378
@ DECL_CXX_METHOD
A CXXMethodDecl record.
Definition: ASTBitCodes.h:1363
@ DECL_EXPORT
An ExportDecl record.
Definition: ASTBitCodes.h:1354
@ DECL_BINDING
A BindingDecl record.
Definition: ASTBitCodes.h:1284
@ DECL_PRAGMA_COMMENT
A PragmaCommentDecl record.
Definition: ASTBitCodes.h:1470
@ DECL_ENUM
An EnumDecl record.
Definition: ASTBitCodes.h:1215
@ DECL_DECOMPOSITION
A DecompositionDecl record.
Definition: ASTBitCodes.h:1281
@ DECL_OMP_DECLARE_REDUCTION
An OMPDeclareReductionDecl record.
Definition: ASTBitCodes.h:1479
@ DECL_OMP_THREADPRIVATE
An OMPThreadPrivateDecl record.
Definition: ASTBitCodes.h:1446
@ DECL_OBJC_METHOD
A ObjCMethodDecl record.
Definition: ASTBitCodes.h:1227
@ DECL_CXX_DESTRUCTOR
A CXXDestructorDecl record.
Definition: ASTBitCodes.h:1369
@ DECL_OMP_CAPTUREDEXPR
An OMPCapturedExprDecl record.
Definition: ASTBitCodes.h:1467
@ DECL_CLASS_TEMPLATE
A ClassTemplateDecl record.
Definition: ASTBitCodes.h:1384
@ DECL_USING_SHADOW
A UsingShadowDecl record.
Definition: ASTBitCodes.h:1336
@ DECL_CONCEPT
A ConceptDecl record.
Definition: ASTBitCodes.h:1417
@ DECL_CXX_DEDUCTION_GUIDE
A CXXDeductionGuideDecl record.
Definition: ASTBitCodes.h:1360
@ DECL_OMP_REQUIRES
An OMPRequiresDecl record.
Definition: ASTBitCodes.h:1449
@ DECL_OBJC_IVAR
A ObjCIvarDecl record.
Definition: ASTBitCodes.h:1236
@ DECL_OBJC_PROPERTY
A ObjCPropertyDecl record.
Definition: ASTBitCodes.h:1254
@ DECL_TEMPLATE_PARAM_OBJECT
A TemplateParamObjectDecl record.
Definition: ASTBitCodes.h:1269
@ DECL_OBJC_INTERFACE
A ObjCInterfaceDecl record.
Definition: ASTBitCodes.h:1230
@ DECL_VAR_TEMPLATE
A VarTemplateDecl record.
Definition: ASTBitCodes.h:1393
@ DECL_LIFETIME_EXTENDED_TEMPORARY
An LifetimeExtendedTemporaryDecl record.
Definition: ASTBitCodes.h:1458
@ DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION
A ClassTemplatePartialSpecializationDecl record.
Definition: ASTBitCodes.h:1390
@ DECL_IMPLICIT_CONCEPT_SPECIALIZATION
An ImplicitConceptSpecializationDecl record.
Definition: ASTBitCodes.h:1488
@ DECL_CONTEXT_VISIBLE
A record that stores the set of declarations that are visible from a given DeclContext.
Definition: ASTBitCodes.h:1315
@ DECL_OBJC_PROPERTY_IMPL
A ObjCPropertyImplDecl record.
Definition: ASTBitCodes.h:1257
@ EXPR_COMPOUND_ASSIGN_OPERATOR
A CompoundAssignOperator record.
Definition: ASTBitCodes.h:1626
@ EXPR_CXX_OPERATOR_CALL
A CXXOperatorCallExpr record.
Definition: ASTBitCodes.h:1784
@ EXPR_IMPLICIT_CAST
An ImplicitCastExpr record.
Definition: ASTBitCodes.h:1632
@ EXPR_CHARACTER_LITERAL
A CharacterLiteral record.
Definition: ASTBitCodes.h:1593
@ STMT_COMPOUND
A CompoundStmt record.
Definition: ASTBitCodes.h:1515
@ EXPR_CALL
A CallExpr record.
Definition: ASTBitCodes.h:1617
@ EXPR_BINARY_OPERATOR
A BinaryOperator record.
Definition: ASTBitCodes.h:1623
@ EXPR_DECL_REF
A DeclRefExpr record.
Definition: ASTBitCodes.h:1578
@ EXPR_INTEGER_LITERAL
An IntegerLiteral record.
Definition: ASTBitCodes.h:1581
@ EXPR_CXX_MEMBER_CALL
A CXXMemberCallExpr record.
Definition: ASTBitCodes.h:1787
bool isRedeclarableDeclKind(unsigned Kind)
Determine whether the given declaration kind is redeclarable.
Definition: ASTCommon.cpp:360
bool needsAnonymousDeclarationNumber(const NamedDecl *D)
Determine whether the given declaration needs an anonymous declaration number.
Definition: ASTCommon.cpp:464
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:328
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:203
@ TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
Definition: Specifiers.h:199
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:191
@ AS_none
Definition: Specifiers.h:124
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:6401
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:4264
uint16_t Part2
...-89ab-...
Definition: DeclCXX.h:4268
uint32_t Part1
{01234567-...
Definition: DeclCXX.h:4266
uint16_t Part3
...-cdef-...
Definition: DeclCXX.h:4270
uint8_t Part4And5[8]
...-0123-456789abcdef}
Definition: DeclCXX.h:4272
static DeclType * getDecl(EntryType *D)
Definition: DeclTemplate.h:736