File indexing completed on 2026-05-10 08:36:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef LLVM_CLANG_AST_DECLCXX_H
0016 #define LLVM_CLANG_AST_DECLCXX_H
0017
0018 #include "clang/AST/ASTUnresolvedSet.h"
0019 #include "clang/AST/Decl.h"
0020 #include "clang/AST/DeclBase.h"
0021 #include "clang/AST/DeclarationName.h"
0022 #include "clang/AST/Expr.h"
0023 #include "clang/AST/ExternalASTSource.h"
0024 #include "clang/AST/LambdaCapture.h"
0025 #include "clang/AST/NestedNameSpecifier.h"
0026 #include "clang/AST/Redeclarable.h"
0027 #include "clang/AST/Stmt.h"
0028 #include "clang/AST/Type.h"
0029 #include "clang/AST/TypeLoc.h"
0030 #include "clang/AST/UnresolvedSet.h"
0031 #include "clang/Basic/LLVM.h"
0032 #include "clang/Basic/Lambda.h"
0033 #include "clang/Basic/LangOptions.h"
0034 #include "clang/Basic/OperatorKinds.h"
0035 #include "clang/Basic/SourceLocation.h"
0036 #include "clang/Basic/Specifiers.h"
0037 #include "llvm/ADT/ArrayRef.h"
0038 #include "llvm/ADT/DenseMap.h"
0039 #include "llvm/ADT/PointerIntPair.h"
0040 #include "llvm/ADT/PointerUnion.h"
0041 #include "llvm/ADT/STLExtras.h"
0042 #include "llvm/ADT/TinyPtrVector.h"
0043 #include "llvm/ADT/iterator_range.h"
0044 #include "llvm/Support/Casting.h"
0045 #include "llvm/Support/Compiler.h"
0046 #include "llvm/Support/PointerLikeTypeTraits.h"
0047 #include "llvm/Support/TrailingObjects.h"
0048 #include <cassert>
0049 #include <cstddef>
0050 #include <iterator>
0051 #include <memory>
0052 #include <vector>
0053
0054 namespace clang {
0055
0056 class ASTContext;
0057 class ClassTemplateDecl;
0058 class ConstructorUsingShadowDecl;
0059 class CXXBasePath;
0060 class CXXBasePaths;
0061 class CXXConstructorDecl;
0062 class CXXDestructorDecl;
0063 class CXXFinalOverriderMap;
0064 class CXXIndirectPrimaryBaseSet;
0065 class CXXMethodDecl;
0066 class DecompositionDecl;
0067 class FriendDecl;
0068 class FunctionTemplateDecl;
0069 class IdentifierInfo;
0070 class MemberSpecializationInfo;
0071 class BaseUsingDecl;
0072 class TemplateDecl;
0073 class TemplateParameterList;
0074 class UsingDecl;
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086 class AccessSpecDecl : public Decl {
0087
0088 SourceLocation ColonLoc;
0089
0090 AccessSpecDecl(AccessSpecifier AS, DeclContext *DC,
0091 SourceLocation ASLoc, SourceLocation ColonLoc)
0092 : Decl(AccessSpec, DC, ASLoc), ColonLoc(ColonLoc) {
0093 setAccess(AS);
0094 }
0095
0096 AccessSpecDecl(EmptyShell Empty) : Decl(AccessSpec, Empty) {}
0097
0098 virtual void anchor();
0099
0100 public:
0101
0102 SourceLocation getAccessSpecifierLoc() const { return getLocation(); }
0103
0104
0105 void setAccessSpecifierLoc(SourceLocation ASLoc) { setLocation(ASLoc); }
0106
0107
0108 SourceLocation getColonLoc() const { return ColonLoc; }
0109
0110
0111 void setColonLoc(SourceLocation CLoc) { ColonLoc = CLoc; }
0112
0113 SourceRange getSourceRange() const override LLVM_READONLY {
0114 return SourceRange(getAccessSpecifierLoc(), getColonLoc());
0115 }
0116
0117 static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
0118 DeclContext *DC, SourceLocation ASLoc,
0119 SourceLocation ColonLoc) {
0120 return new (C, DC) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
0121 }
0122
0123 static AccessSpecDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
0124
0125
0126 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
0127 static bool classofKind(Kind K) { return K == AccessSpec; }
0128 };
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146 class CXXBaseSpecifier {
0147
0148
0149
0150 SourceRange Range;
0151
0152
0153
0154 SourceLocation EllipsisLoc;
0155
0156
0157 LLVM_PREFERRED_TYPE(bool)
0158 unsigned Virtual : 1;
0159
0160
0161
0162
0163
0164 LLVM_PREFERRED_TYPE(bool)
0165 unsigned BaseOfClass : 1;
0166
0167
0168
0169
0170
0171 LLVM_PREFERRED_TYPE(AccessSpecifier)
0172 unsigned Access : 2;
0173
0174
0175
0176 LLVM_PREFERRED_TYPE(bool)
0177 unsigned InheritConstructors : 1;
0178
0179
0180
0181
0182
0183 TypeSourceInfo *BaseTypeInfo;
0184
0185 public:
0186 CXXBaseSpecifier() = default;
0187 CXXBaseSpecifier(SourceRange R, bool V, bool BC, AccessSpecifier A,
0188 TypeSourceInfo *TInfo, SourceLocation EllipsisLoc)
0189 : Range(R), EllipsisLoc(EllipsisLoc), Virtual(V), BaseOfClass(BC),
0190 Access(A), InheritConstructors(false), BaseTypeInfo(TInfo) {}
0191
0192
0193 SourceRange getSourceRange() const LLVM_READONLY { return Range; }
0194 SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
0195 SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
0196
0197
0198 SourceLocation getBaseTypeLoc() const LLVM_READONLY {
0199 return BaseTypeInfo->getTypeLoc().getBeginLoc();
0200 }
0201
0202
0203 bool isVirtual() const { return Virtual; }
0204
0205
0206
0207 bool isBaseOfClass() const { return BaseOfClass; }
0208
0209
0210 bool isPackExpansion() const { return EllipsisLoc.isValid(); }
0211
0212
0213 bool getInheritConstructors() const { return InheritConstructors; }
0214
0215
0216 void setInheritConstructors(bool Inherit = true) {
0217 InheritConstructors = Inherit;
0218 }
0219
0220
0221 SourceLocation getEllipsisLoc() const {
0222 return EllipsisLoc;
0223 }
0224
0225
0226
0227
0228
0229
0230 AccessSpecifier getAccessSpecifier() const {
0231 if ((AccessSpecifier)Access == AS_none)
0232 return BaseOfClass? AS_private : AS_public;
0233 else
0234 return (AccessSpecifier)Access;
0235 }
0236
0237
0238
0239
0240
0241
0242 AccessSpecifier getAccessSpecifierAsWritten() const {
0243 return (AccessSpecifier)Access;
0244 }
0245
0246
0247
0248
0249 QualType getType() const {
0250 return BaseTypeInfo->getType().getUnqualifiedType();
0251 }
0252
0253
0254 TypeSourceInfo *getTypeSourceInfo() const { return BaseTypeInfo; }
0255 };
0256
0257
0258 class CXXRecordDecl : public RecordDecl {
0259 friend class ASTDeclMerger;
0260 friend class ASTDeclReader;
0261 friend class ASTDeclWriter;
0262 friend class ASTNodeImporter;
0263 friend class ASTReader;
0264 friend class ASTRecordWriter;
0265 friend class ASTWriter;
0266 friend class DeclContext;
0267 friend class LambdaExpr;
0268 friend class ODRDiagsEmitter;
0269
0270 friend void FunctionDecl::setIsPureVirtual(bool);
0271 friend void TagDecl::startDefinition();
0272
0273
0274 enum SpecialMemberFlags {
0275 SMF_DefaultConstructor = 0x1,
0276 SMF_CopyConstructor = 0x2,
0277 SMF_MoveConstructor = 0x4,
0278 SMF_CopyAssignment = 0x8,
0279 SMF_MoveAssignment = 0x10,
0280 SMF_Destructor = 0x20,
0281 SMF_All = 0x3f
0282 };
0283
0284 public:
0285 enum LambdaDependencyKind {
0286 LDK_Unknown = 0,
0287 LDK_AlwaysDependent,
0288 LDK_NeverDependent,
0289 };
0290
0291 private:
0292 struct DefinitionData {
0293 #define FIELD(Name, Width, Merge) \
0294 unsigned Name : Width;
0295 #include "CXXRecordDeclDefinitionBits.def"
0296
0297
0298 LLVM_PREFERRED_TYPE(bool)
0299 unsigned IsLambda : 1;
0300
0301
0302 LLVM_PREFERRED_TYPE(bool)
0303 unsigned IsParsingBaseSpecifiers : 1;
0304
0305
0306
0307 LLVM_PREFERRED_TYPE(bool)
0308 unsigned ComputedVisibleConversions : 1;
0309
0310 LLVM_PREFERRED_TYPE(bool)
0311 unsigned HasODRHash : 1;
0312
0313
0314 unsigned ODRHash = 0;
0315
0316
0317 unsigned NumBases = 0;
0318
0319
0320 unsigned NumVBases = 0;
0321
0322
0323
0324
0325 LazyCXXBaseSpecifiersPtr Bases;
0326
0327
0328 LazyCXXBaseSpecifiersPtr VBases;
0329
0330
0331
0332
0333
0334 LazyASTUnresolvedSet Conversions;
0335
0336
0337
0338
0339
0340
0341 LazyASTUnresolvedSet VisibleConversions;
0342
0343
0344 CXXRecordDecl *Definition;
0345
0346
0347
0348
0349
0350 LazyDeclPtr FirstFriend;
0351
0352 DefinitionData(CXXRecordDecl *D);
0353
0354
0355 CXXBaseSpecifier *getBases() const {
0356 if (!Bases.isOffset())
0357 return Bases.get(nullptr);
0358 return getBasesSlowCase();
0359 }
0360
0361
0362 CXXBaseSpecifier *getVBases() const {
0363 if (!VBases.isOffset())
0364 return VBases.get(nullptr);
0365 return getVBasesSlowCase();
0366 }
0367
0368 ArrayRef<CXXBaseSpecifier> bases() const {
0369 return llvm::ArrayRef(getBases(), NumBases);
0370 }
0371
0372 ArrayRef<CXXBaseSpecifier> vbases() const {
0373 return llvm::ArrayRef(getVBases(), NumVBases);
0374 }
0375
0376 private:
0377 CXXBaseSpecifier *getBasesSlowCase() const;
0378 CXXBaseSpecifier *getVBasesSlowCase() const;
0379 };
0380
0381 struct DefinitionData *DefinitionData;
0382
0383
0384 struct LambdaDefinitionData : public DefinitionData {
0385 using Capture = LambdaCapture;
0386
0387
0388
0389
0390
0391
0392
0393
0394
0395 LLVM_PREFERRED_TYPE(LambdaDependencyKind)
0396 unsigned DependencyKind : 2;
0397
0398
0399 LLVM_PREFERRED_TYPE(bool)
0400 unsigned IsGenericLambda : 1;
0401
0402
0403 LLVM_PREFERRED_TYPE(LambdaCaptureDefault)
0404 unsigned CaptureDefault : 2;
0405
0406
0407 unsigned NumCaptures : 15;
0408
0409
0410 unsigned NumExplicitCaptures : 12;
0411
0412
0413 LLVM_PREFERRED_TYPE(bool)
0414 unsigned HasKnownInternalLinkage : 1;
0415
0416
0417
0418 unsigned ManglingNumber : 31;
0419
0420
0421
0422 unsigned IndexInContext;
0423
0424
0425
0426
0427
0428 LazyDeclPtr ContextDecl;
0429
0430
0431
0432
0433
0434 llvm::TinyPtrVector<Capture*> Captures;
0435
0436
0437 TypeSourceInfo *MethodTyInfo;
0438
0439 LambdaDefinitionData(CXXRecordDecl *D, TypeSourceInfo *Info, unsigned DK,
0440 bool IsGeneric, LambdaCaptureDefault CaptureDefault)
0441 : DefinitionData(D), DependencyKind(DK), IsGenericLambda(IsGeneric),
0442 CaptureDefault(CaptureDefault), NumCaptures(0),
0443 NumExplicitCaptures(0), HasKnownInternalLinkage(0), ManglingNumber(0),
0444 IndexInContext(0), MethodTyInfo(Info) {
0445 IsLambda = true;
0446
0447
0448
0449 Aggregate = false;
0450 PlainOldData = false;
0451 }
0452
0453
0454 void AddCaptureList(ASTContext &Ctx, Capture *CaptureList);
0455 };
0456
0457 struct DefinitionData *dataPtr() const {
0458
0459 getMostRecentDecl();
0460 return DefinitionData;
0461 }
0462
0463 struct DefinitionData &data() const {
0464 auto *DD = dataPtr();
0465 assert(DD && "queried property of class with no definition");
0466 return *DD;
0467 }
0468
0469 struct LambdaDefinitionData &getLambdaData() const {
0470
0471
0472 auto *DD = DefinitionData;
0473 assert(DD && DD->IsLambda && "queried lambda property of non-lambda class");
0474 return static_cast<LambdaDefinitionData&>(*DD);
0475 }
0476
0477
0478
0479
0480
0481
0482
0483
0484
0485
0486 llvm::PointerUnion<ClassTemplateDecl *, MemberSpecializationInfo *>
0487 TemplateOrInstantiation;
0488
0489
0490
0491 void addedClassSubobject(CXXRecordDecl *Base);
0492
0493
0494
0495
0496
0497
0498 void addedMember(Decl *D);
0499
0500 void markedVirtualFunctionPure();
0501
0502
0503
0504 FriendDecl *getFirstFriend() const;
0505
0506
0507
0508
0509 bool hasSubobjectAtOffsetZeroOfEmptyBaseType(ASTContext &Ctx,
0510 const CXXRecordDecl *X);
0511
0512 protected:
0513 CXXRecordDecl(Kind K, TagKind TK, const ASTContext &C, DeclContext *DC,
0514 SourceLocation StartLoc, SourceLocation IdLoc,
0515 IdentifierInfo *Id, CXXRecordDecl *PrevDecl);
0516
0517 public:
0518
0519 using base_class_iterator = CXXBaseSpecifier *;
0520
0521
0522 using base_class_const_iterator = const CXXBaseSpecifier *;
0523
0524 CXXRecordDecl *getCanonicalDecl() override {
0525 return cast<CXXRecordDecl>(RecordDecl::getCanonicalDecl());
0526 }
0527
0528 const CXXRecordDecl *getCanonicalDecl() const {
0529 return const_cast<CXXRecordDecl*>(this)->getCanonicalDecl();
0530 }
0531
0532 CXXRecordDecl *getPreviousDecl() {
0533 return cast_or_null<CXXRecordDecl>(
0534 static_cast<RecordDecl *>(this)->getPreviousDecl());
0535 }
0536
0537 const CXXRecordDecl *getPreviousDecl() const {
0538 return const_cast<CXXRecordDecl*>(this)->getPreviousDecl();
0539 }
0540
0541 CXXRecordDecl *getMostRecentDecl() {
0542 return cast<CXXRecordDecl>(
0543 static_cast<RecordDecl *>(this)->getMostRecentDecl());
0544 }
0545
0546 const CXXRecordDecl *getMostRecentDecl() const {
0547 return const_cast<CXXRecordDecl*>(this)->getMostRecentDecl();
0548 }
0549
0550 CXXRecordDecl *getMostRecentNonInjectedDecl() {
0551 CXXRecordDecl *Recent =
0552 static_cast<CXXRecordDecl *>(this)->getMostRecentDecl();
0553 while (Recent->isInjectedClassName()) {
0554
0555 assert(Recent->getPreviousDecl());
0556 Recent = Recent->getPreviousDecl();
0557 }
0558 return Recent;
0559 }
0560
0561 const CXXRecordDecl *getMostRecentNonInjectedDecl() const {
0562 return const_cast<CXXRecordDecl*>(this)->getMostRecentNonInjectedDecl();
0563 }
0564
0565 CXXRecordDecl *getDefinition() const {
0566
0567
0568 auto *DD = DefinitionData ? DefinitionData : dataPtr();
0569 return DD ? DD->Definition : nullptr;
0570 }
0571
0572 bool hasDefinition() const { return DefinitionData || dataPtr(); }
0573
0574 static CXXRecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
0575 SourceLocation StartLoc, SourceLocation IdLoc,
0576 IdentifierInfo *Id,
0577 CXXRecordDecl *PrevDecl = nullptr,
0578 bool DelayTypeCreation = false);
0579 static CXXRecordDecl *CreateLambda(const ASTContext &C, DeclContext *DC,
0580 TypeSourceInfo *Info, SourceLocation Loc,
0581 unsigned DependencyKind, bool IsGeneric,
0582 LambdaCaptureDefault CaptureDefault);
0583 static CXXRecordDecl *CreateDeserialized(const ASTContext &C,
0584 GlobalDeclID ID);
0585
0586 bool isDynamicClass() const {
0587 return data().Polymorphic || data().NumVBases != 0;
0588 }
0589
0590
0591
0592 bool mayBeDynamicClass() const {
0593 return !hasDefinition() || isDynamicClass() || hasAnyDependentBases();
0594 }
0595
0596
0597
0598 bool mayBeNonDynamicClass() const {
0599 return !hasDefinition() || !isDynamicClass() || hasAnyDependentBases();
0600 }
0601
0602 void setIsParsingBaseSpecifiers() { data().IsParsingBaseSpecifiers = true; }
0603
0604 bool isParsingBaseSpecifiers() const {
0605 return data().IsParsingBaseSpecifiers;
0606 }
0607
0608 unsigned getODRHash() const;
0609
0610
0611 void setBases(CXXBaseSpecifier const * const *Bases, unsigned NumBases);
0612
0613
0614 unsigned getNumBases() const { return data().NumBases; }
0615
0616 using base_class_range = llvm::iterator_range<base_class_iterator>;
0617 using base_class_const_range =
0618 llvm::iterator_range<base_class_const_iterator>;
0619
0620 base_class_range bases() {
0621 return base_class_range(bases_begin(), bases_end());
0622 }
0623 base_class_const_range bases() const {
0624 return base_class_const_range(bases_begin(), bases_end());
0625 }
0626
0627 base_class_iterator bases_begin() { return data().getBases(); }
0628 base_class_const_iterator bases_begin() const { return data().getBases(); }
0629 base_class_iterator bases_end() { return bases_begin() + data().NumBases; }
0630 base_class_const_iterator bases_end() const {
0631 return bases_begin() + data().NumBases;
0632 }
0633
0634
0635 unsigned getNumVBases() const { return data().NumVBases; }
0636
0637 base_class_range vbases() {
0638 return base_class_range(vbases_begin(), vbases_end());
0639 }
0640 base_class_const_range vbases() const {
0641 return base_class_const_range(vbases_begin(), vbases_end());
0642 }
0643
0644 base_class_iterator vbases_begin() { return data().getVBases(); }
0645 base_class_const_iterator vbases_begin() const { return data().getVBases(); }
0646 base_class_iterator vbases_end() { return vbases_begin() + data().NumVBases; }
0647 base_class_const_iterator vbases_end() const {
0648 return vbases_begin() + data().NumVBases;
0649 }
0650
0651
0652
0653 bool hasAnyDependentBases() const;
0654
0655
0656
0657
0658 using method_iterator = specific_decl_iterator<CXXMethodDecl>;
0659 using method_range =
0660 llvm::iterator_range<specific_decl_iterator<CXXMethodDecl>>;
0661
0662 method_range methods() const {
0663 return method_range(method_begin(), method_end());
0664 }
0665
0666
0667
0668 method_iterator method_begin() const {
0669 return method_iterator(decls_begin());
0670 }
0671
0672
0673 method_iterator method_end() const {
0674 return method_iterator(decls_end());
0675 }
0676
0677
0678 using ctor_iterator = specific_decl_iterator<CXXConstructorDecl>;
0679 using ctor_range =
0680 llvm::iterator_range<specific_decl_iterator<CXXConstructorDecl>>;
0681
0682 ctor_range ctors() const { return ctor_range(ctor_begin(), ctor_end()); }
0683
0684 ctor_iterator ctor_begin() const {
0685 return ctor_iterator(decls_begin());
0686 }
0687
0688 ctor_iterator ctor_end() const {
0689 return ctor_iterator(decls_end());
0690 }
0691
0692
0693
0694 class friend_iterator;
0695 using friend_range = llvm::iterator_range<friend_iterator>;
0696
0697 friend_range friends() const;
0698 friend_iterator friend_begin() const;
0699 friend_iterator friend_end() const;
0700 void pushFriendDecl(FriendDecl *FD);
0701
0702
0703 bool hasFriends() const {
0704 return data().FirstFriend.isValid();
0705 }
0706
0707
0708
0709 bool defaultedCopyConstructorIsDeleted() const {
0710 assert((!needsOverloadResolutionForCopyConstructor() ||
0711 (data().DeclaredSpecialMembers & SMF_CopyConstructor)) &&
0712 "this property has not yet been computed by Sema");
0713 return data().DefaultedCopyConstructorIsDeleted;
0714 }
0715
0716
0717
0718 bool defaultedMoveConstructorIsDeleted() const {
0719 assert((!needsOverloadResolutionForMoveConstructor() ||
0720 (data().DeclaredSpecialMembers & SMF_MoveConstructor)) &&
0721 "this property has not yet been computed by Sema");
0722 return data().DefaultedMoveConstructorIsDeleted;
0723 }
0724
0725
0726 bool defaultedDestructorIsDeleted() const {
0727 assert((!needsOverloadResolutionForDestructor() ||
0728 (data().DeclaredSpecialMembers & SMF_Destructor)) &&
0729 "this property has not yet been computed by Sema");
0730 return data().DefaultedDestructorIsDeleted;
0731 }
0732
0733
0734
0735 bool hasSimpleCopyConstructor() const {
0736 return !hasUserDeclaredCopyConstructor() &&
0737 !data().DefaultedCopyConstructorIsDeleted;
0738 }
0739
0740
0741
0742 bool hasSimpleMoveConstructor() const {
0743 return !hasUserDeclaredMoveConstructor() && hasMoveConstructor() &&
0744 !data().DefaultedMoveConstructorIsDeleted;
0745 }
0746
0747
0748
0749 bool hasSimpleCopyAssignment() const {
0750 return !hasUserDeclaredCopyAssignment() &&
0751 !data().DefaultedCopyAssignmentIsDeleted;
0752 }
0753
0754
0755
0756 bool hasSimpleMoveAssignment() const {
0757 return !hasUserDeclaredMoveAssignment() && hasMoveAssignment() &&
0758 !data().DefaultedMoveAssignmentIsDeleted;
0759 }
0760
0761
0762
0763 bool hasSimpleDestructor() const {
0764 return !hasUserDeclaredDestructor() &&
0765 !data().DefaultedDestructorIsDeleted;
0766 }
0767
0768
0769 bool hasDefaultConstructor() const {
0770 return (data().DeclaredSpecialMembers & SMF_DefaultConstructor) ||
0771 needsImplicitDefaultConstructor();
0772 }
0773
0774
0775
0776
0777
0778 bool needsImplicitDefaultConstructor() const {
0779 return (!data().UserDeclaredConstructor &&
0780 !(data().DeclaredSpecialMembers & SMF_DefaultConstructor) &&
0781 (!isLambda() || lambdaIsDefaultConstructibleAndAssignable())) ||
0782
0783
0784
0785 (data().HasInheritedDefaultConstructor &&
0786 !(data().DeclaredSpecialMembers & SMF_DefaultConstructor));
0787 }
0788
0789
0790
0791
0792 bool hasUserDeclaredConstructor() const {
0793 return data().UserDeclaredConstructor;
0794 }
0795
0796
0797
0798 bool hasUserProvidedDefaultConstructor() const {
0799 return data().UserProvidedDefaultConstructor;
0800 }
0801
0802
0803
0804
0805 bool hasUserDeclaredCopyConstructor() const {
0806 return data().UserDeclaredSpecialMembers & SMF_CopyConstructor;
0807 }
0808
0809
0810
0811 bool needsImplicitCopyConstructor() const {
0812 return !(data().DeclaredSpecialMembers & SMF_CopyConstructor);
0813 }
0814
0815
0816
0817 bool needsOverloadResolutionForCopyConstructor() const {
0818
0819
0820
0821
0822
0823
0824 if (data().UserDeclaredSpecialMembers &
0825 (SMF_MoveConstructor | SMF_MoveAssignment))
0826 return true;
0827 return data().NeedOverloadResolutionForCopyConstructor;
0828 }
0829
0830
0831
0832 bool implicitCopyConstructorHasConstParam() const {
0833 return data().ImplicitCopyConstructorCanHaveConstParamForNonVBase &&
0834 (isAbstract() ||
0835 data().ImplicitCopyConstructorCanHaveConstParamForVBase);
0836 }
0837
0838
0839
0840 bool hasCopyConstructorWithConstParam() const {
0841 return data().HasDeclaredCopyConstructorWithConstParam ||
0842 (needsImplicitCopyConstructor() &&
0843 implicitCopyConstructorHasConstParam());
0844 }
0845
0846
0847
0848
0849
0850
0851 bool hasUserDeclaredMoveOperation() const {
0852 return data().UserDeclaredSpecialMembers &
0853 (SMF_MoveConstructor | SMF_MoveAssignment);
0854 }
0855
0856
0857
0858 bool hasUserDeclaredMoveConstructor() const {
0859 return data().UserDeclaredSpecialMembers & SMF_MoveConstructor;
0860 }
0861
0862
0863 bool hasMoveConstructor() const {
0864 return (data().DeclaredSpecialMembers & SMF_MoveConstructor) ||
0865 needsImplicitMoveConstructor();
0866 }
0867
0868
0869
0870 void setImplicitCopyConstructorIsDeleted() {
0871 assert((data().DefaultedCopyConstructorIsDeleted ||
0872 needsOverloadResolutionForCopyConstructor()) &&
0873 "Copy constructor should not be deleted");
0874 data().DefaultedCopyConstructorIsDeleted = true;
0875 }
0876
0877
0878
0879 void setImplicitMoveConstructorIsDeleted() {
0880 assert((data().DefaultedMoveConstructorIsDeleted ||
0881 needsOverloadResolutionForMoveConstructor()) &&
0882 "move constructor should not be deleted");
0883 data().DefaultedMoveConstructorIsDeleted = true;
0884 }
0885
0886
0887
0888 void setImplicitDestructorIsDeleted() {
0889 assert((data().DefaultedDestructorIsDeleted ||
0890 needsOverloadResolutionForDestructor()) &&
0891 "destructor should not be deleted");
0892 data().DefaultedDestructorIsDeleted = true;
0893
0894
0895
0896
0897
0898
0899 data().DefaultedDestructorIsConstexpr = data().NumVBases == 0;
0900 }
0901
0902
0903
0904 bool needsImplicitMoveConstructor() const {
0905 return !(data().DeclaredSpecialMembers & SMF_MoveConstructor) &&
0906 !hasUserDeclaredCopyConstructor() &&
0907 !hasUserDeclaredCopyAssignment() &&
0908 !hasUserDeclaredMoveAssignment() &&
0909 !hasUserDeclaredDestructor();
0910 }
0911
0912
0913
0914 bool needsOverloadResolutionForMoveConstructor() const {
0915 return data().NeedOverloadResolutionForMoveConstructor;
0916 }
0917
0918
0919
0920
0921
0922 bool hasUserDeclaredCopyAssignment() const {
0923 return data().UserDeclaredSpecialMembers & SMF_CopyAssignment;
0924 }
0925
0926
0927
0928 void setImplicitCopyAssignmentIsDeleted() {
0929 assert((data().DefaultedCopyAssignmentIsDeleted ||
0930 needsOverloadResolutionForCopyAssignment()) &&
0931 "copy assignment should not be deleted");
0932 data().DefaultedCopyAssignmentIsDeleted = true;
0933 }
0934
0935
0936
0937 bool needsImplicitCopyAssignment() const {
0938 return !(data().DeclaredSpecialMembers & SMF_CopyAssignment);
0939 }
0940
0941
0942
0943 bool needsOverloadResolutionForCopyAssignment() const {
0944
0945
0946
0947
0948
0949
0950 if (data().UserDeclaredSpecialMembers &
0951 (SMF_MoveConstructor | SMF_MoveAssignment))
0952 return true;
0953 return data().NeedOverloadResolutionForCopyAssignment;
0954 }
0955
0956
0957
0958 bool implicitCopyAssignmentHasConstParam() const {
0959 return data().ImplicitCopyAssignmentHasConstParam;
0960 }
0961
0962
0963
0964
0965 bool hasCopyAssignmentWithConstParam() const {
0966 return data().HasDeclaredCopyAssignmentWithConstParam ||
0967 (needsImplicitCopyAssignment() &&
0968 implicitCopyAssignmentHasConstParam());
0969 }
0970
0971
0972
0973 bool hasUserDeclaredMoveAssignment() const {
0974 return data().UserDeclaredSpecialMembers & SMF_MoveAssignment;
0975 }
0976
0977
0978 bool hasMoveAssignment() const {
0979 return (data().DeclaredSpecialMembers & SMF_MoveAssignment) ||
0980 needsImplicitMoveAssignment();
0981 }
0982
0983
0984
0985 void setImplicitMoveAssignmentIsDeleted() {
0986 assert((data().DefaultedMoveAssignmentIsDeleted ||
0987 needsOverloadResolutionForMoveAssignment()) &&
0988 "move assignment should not be deleted");
0989 data().DefaultedMoveAssignmentIsDeleted = true;
0990 }
0991
0992
0993
0994
0995 bool needsImplicitMoveAssignment() const {
0996 return !(data().DeclaredSpecialMembers & SMF_MoveAssignment) &&
0997 !hasUserDeclaredCopyConstructor() &&
0998 !hasUserDeclaredCopyAssignment() &&
0999 !hasUserDeclaredMoveConstructor() &&
1000 !hasUserDeclaredDestructor() &&
1001 (!isLambda() || lambdaIsDefaultConstructibleAndAssignable());
1002 }
1003
1004
1005
1006 bool needsOverloadResolutionForMoveAssignment() const {
1007 return data().NeedOverloadResolutionForMoveAssignment;
1008 }
1009
1010
1011
1012
1013 bool hasUserDeclaredDestructor() const {
1014 return data().UserDeclaredSpecialMembers & SMF_Destructor;
1015 }
1016
1017
1018
1019 bool needsImplicitDestructor() const {
1020 return !(data().DeclaredSpecialMembers & SMF_Destructor);
1021 }
1022
1023
1024
1025 bool needsOverloadResolutionForDestructor() const {
1026 return data().NeedOverloadResolutionForDestructor;
1027 }
1028
1029
1030 bool isLambda() const {
1031
1032 auto *DD = DefinitionData;
1033 return DD && DD->IsLambda;
1034 }
1035
1036
1037
1038
1039 bool isGenericLambda() const;
1040
1041
1042
1043 bool lambdaIsDefaultConstructibleAndAssignable() const;
1044
1045
1046
1047 CXXMethodDecl *getLambdaCallOperator() const;
1048
1049
1050
1051 FunctionTemplateDecl *getDependentLambdaCallOperator() const;
1052
1053
1054
1055
1056
1057
1058
1059
1060 CXXMethodDecl *getLambdaStaticInvoker() const;
1061 CXXMethodDecl *getLambdaStaticInvoker(CallingConv CC) const;
1062
1063
1064
1065
1066 TemplateParameterList *getGenericLambdaTemplateParameterList() const;
1067
1068
1069 ArrayRef<NamedDecl *> getLambdaExplicitTemplateParameters() const;
1070
1071 LambdaCaptureDefault getLambdaCaptureDefault() const {
1072 assert(isLambda());
1073 return static_cast<LambdaCaptureDefault>(getLambdaData().CaptureDefault);
1074 }
1075
1076 bool isCapturelessLambda() const {
1077 if (!isLambda())
1078 return false;
1079 return getLambdaCaptureDefault() == LCD_None && capture_size() == 0;
1080 }
1081
1082
1083 void setCaptures(ASTContext &Context, ArrayRef<LambdaCapture> Captures);
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102 void
1103 getCaptureFields(llvm::DenseMap<const ValueDecl *, FieldDecl *> &Captures,
1104 FieldDecl *&ThisCapture) const;
1105
1106 using capture_const_iterator = const LambdaCapture *;
1107 using capture_const_range = llvm::iterator_range<capture_const_iterator>;
1108
1109 capture_const_range captures() const {
1110 return capture_const_range(captures_begin(), captures_end());
1111 }
1112
1113 capture_const_iterator captures_begin() const {
1114 if (!isLambda()) return nullptr;
1115 LambdaDefinitionData &LambdaData = getLambdaData();
1116 return LambdaData.Captures.empty() ? nullptr : LambdaData.Captures.front();
1117 }
1118
1119 capture_const_iterator captures_end() const {
1120 return isLambda() ? captures_begin() + getLambdaData().NumCaptures
1121 : nullptr;
1122 }
1123
1124 unsigned capture_size() const { return getLambdaData().NumCaptures; }
1125
1126 const LambdaCapture *getCapture(unsigned I) const {
1127 assert(isLambda() && I < capture_size() && "invalid index for capture");
1128 return captures_begin() + I;
1129 }
1130
1131 using conversion_iterator = UnresolvedSetIterator;
1132
1133 conversion_iterator conversion_begin() const {
1134 return data().Conversions.get(getASTContext()).begin();
1135 }
1136
1137 conversion_iterator conversion_end() const {
1138 return data().Conversions.get(getASTContext()).end();
1139 }
1140
1141
1142
1143
1144 void removeConversion(const NamedDecl *Old);
1145
1146
1147
1148 llvm::iterator_range<conversion_iterator>
1149 getVisibleConversionFunctions() const;
1150
1151
1152
1153
1154
1155 bool isAggregate() const { return data().Aggregate; }
1156
1157
1158
1159
1160 bool hasInClassInitializer() const { return data().HasInClassInitializer; }
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170 bool hasUninitializedReferenceMember() const {
1171 return !isUnion() && !hasUserDeclaredConstructor() &&
1172 data().HasUninitializedReferenceMember;
1173 }
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183 bool isPOD() const { return data().PlainOldData; }
1184
1185
1186
1187 bool isCLike() const;
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198 bool isEmpty() const { return data().Empty; }
1199
1200 void setInitMethod(bool Val) { data().HasInitMethod = Val; }
1201 bool hasInitMethod() const { return data().HasInitMethod; }
1202
1203 bool hasPrivateFields() const {
1204 return data().HasPrivateFields;
1205 }
1206
1207 bool hasProtectedFields() const {
1208 return data().HasProtectedFields;
1209 }
1210
1211
1212 bool hasDirectFields() const {
1213 auto &D = data();
1214 return D.HasPublicFields || D.HasProtectedFields || D.HasPrivateFields;
1215 }
1216
1217
1218
1219
1220
1221
1222 const CXXRecordDecl *getStandardLayoutBaseWithFields() const;
1223
1224
1225
1226 bool isPolymorphic() const { return data().Polymorphic; }
1227
1228
1229
1230
1231
1232
1233 bool isAbstract() const { return data().Abstract; }
1234
1235
1236
1237 bool isStandardLayout() const { return data().IsStandardLayout; }
1238
1239
1240
1241 bool isCXX11StandardLayout() const { return data().IsCXX11StandardLayout; }
1242
1243
1244
1245 bool hasMutableFields() const { return data().HasMutableFields; }
1246
1247
1248 bool hasVariantMembers() const { return data().HasVariantMembers; }
1249
1250
1251
1252 bool hasTrivialDefaultConstructor() const {
1253 return hasDefaultConstructor() &&
1254 (data().HasTrivialSpecialMembers & SMF_DefaultConstructor);
1255 }
1256
1257
1258
1259 bool hasNonTrivialDefaultConstructor() const {
1260 return (data().DeclaredNonTrivialSpecialMembers & SMF_DefaultConstructor) ||
1261 (needsImplicitDefaultConstructor() &&
1262 !(data().HasTrivialSpecialMembers & SMF_DefaultConstructor));
1263 }
1264
1265
1266
1267 bool hasConstexprNonCopyMoveConstructor() const {
1268 return data().HasConstexprNonCopyMoveConstructor ||
1269 (needsImplicitDefaultConstructor() &&
1270 defaultedDefaultConstructorIsConstexpr());
1271 }
1272
1273
1274
1275 bool defaultedDefaultConstructorIsConstexpr() const {
1276 return data().DefaultedDefaultConstructorIsConstexpr &&
1277 (!isUnion() || hasInClassInitializer() || !hasVariantMembers() ||
1278 getLangOpts().CPlusPlus20);
1279 }
1280
1281
1282 bool hasConstexprDefaultConstructor() const {
1283 return data().HasConstexprDefaultConstructor ||
1284 (needsImplicitDefaultConstructor() &&
1285 defaultedDefaultConstructorIsConstexpr());
1286 }
1287
1288
1289
1290 bool hasTrivialCopyConstructor() const {
1291 return data().HasTrivialSpecialMembers & SMF_CopyConstructor;
1292 }
1293
1294 bool hasTrivialCopyConstructorForCall() const {
1295 return data().HasTrivialSpecialMembersForCall & SMF_CopyConstructor;
1296 }
1297
1298
1299
1300 bool hasNonTrivialCopyConstructor() const {
1301 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyConstructor ||
1302 !hasTrivialCopyConstructor();
1303 }
1304
1305 bool hasNonTrivialCopyConstructorForCall() const {
1306 return (data().DeclaredNonTrivialSpecialMembersForCall &
1307 SMF_CopyConstructor) ||
1308 !hasTrivialCopyConstructorForCall();
1309 }
1310
1311
1312
1313 bool hasTrivialMoveConstructor() const {
1314 return hasMoveConstructor() &&
1315 (data().HasTrivialSpecialMembers & SMF_MoveConstructor);
1316 }
1317
1318 bool hasTrivialMoveConstructorForCall() const {
1319 return hasMoveConstructor() &&
1320 (data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor);
1321 }
1322
1323
1324
1325 bool hasNonTrivialMoveConstructor() const {
1326 return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveConstructor) ||
1327 (needsImplicitMoveConstructor() &&
1328 !(data().HasTrivialSpecialMembers & SMF_MoveConstructor));
1329 }
1330
1331 bool hasNonTrivialMoveConstructorForCall() const {
1332 return (data().DeclaredNonTrivialSpecialMembersForCall &
1333 SMF_MoveConstructor) ||
1334 (needsImplicitMoveConstructor() &&
1335 !(data().HasTrivialSpecialMembersForCall & SMF_MoveConstructor));
1336 }
1337
1338
1339
1340 bool hasTrivialCopyAssignment() const {
1341 return data().HasTrivialSpecialMembers & SMF_CopyAssignment;
1342 }
1343
1344
1345
1346 bool hasNonTrivialCopyAssignment() const {
1347 return data().DeclaredNonTrivialSpecialMembers & SMF_CopyAssignment ||
1348 !hasTrivialCopyAssignment();
1349 }
1350
1351
1352
1353 bool hasTrivialMoveAssignment() const {
1354 return hasMoveAssignment() &&
1355 (data().HasTrivialSpecialMembers & SMF_MoveAssignment);
1356 }
1357
1358
1359
1360 bool hasNonTrivialMoveAssignment() const {
1361 return (data().DeclaredNonTrivialSpecialMembers & SMF_MoveAssignment) ||
1362 (needsImplicitMoveAssignment() &&
1363 !(data().HasTrivialSpecialMembers & SMF_MoveAssignment));
1364 }
1365
1366
1367
1368 bool defaultedDestructorIsConstexpr() const {
1369 return data().DefaultedDestructorIsConstexpr &&
1370 getLangOpts().CPlusPlus20;
1371 }
1372
1373
1374 bool hasConstexprDestructor() const;
1375
1376
1377
1378 bool hasTrivialDestructor() const {
1379 return data().HasTrivialSpecialMembers & SMF_Destructor;
1380 }
1381
1382 bool hasTrivialDestructorForCall() const {
1383 return data().HasTrivialSpecialMembersForCall & SMF_Destructor;
1384 }
1385
1386
1387
1388 bool hasNonTrivialDestructor() const {
1389 return !(data().HasTrivialSpecialMembers & SMF_Destructor);
1390 }
1391
1392 bool hasNonTrivialDestructorForCall() const {
1393 return !(data().HasTrivialSpecialMembersForCall & SMF_Destructor);
1394 }
1395
1396 void setHasTrivialSpecialMemberForCall() {
1397 data().HasTrivialSpecialMembersForCall =
1398 (SMF_CopyConstructor | SMF_MoveConstructor | SMF_Destructor);
1399 }
1400
1401
1402
1403 bool allowConstDefaultInit() const {
1404 return !data().HasUninitializedFields ||
1405 !(data().HasDefaultedDefaultConstructor ||
1406 needsImplicitDefaultConstructor());
1407 }
1408
1409
1410
1411
1412
1413
1414 bool hasIrrelevantDestructor() const {
1415 return data().HasIrrelevantDestructor;
1416 }
1417
1418
1419
1420 bool hasNonLiteralTypeFieldsOrBases() const {
1421 return data().HasNonLiteralTypeFieldsOrBases;
1422 }
1423
1424
1425
1426 bool hasInheritedConstructor() const {
1427 return data().HasInheritedConstructor;
1428 }
1429
1430
1431
1432 bool hasInheritedAssignment() const {
1433 return data().HasInheritedAssignment;
1434 }
1435
1436
1437
1438 bool isTriviallyCopyable() const;
1439
1440
1441 bool isTriviallyCopyConstructible() const;
1442
1443
1444
1445
1446
1447
1448 bool isTrivial() const {
1449 return isTriviallyCopyable() && hasTrivialDefaultConstructor();
1450 }
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467 bool isLiteral() const;
1468
1469
1470 bool isStructural() const {
1471 return isLiteral() && data().StructuralIfLiteral;
1472 }
1473
1474
1475
1476
1477
1478
1479
1480
1481 void addedSelectedDestructor(CXXDestructorDecl *DD);
1482
1483
1484
1485 void addedEligibleSpecialMemberFunction(const CXXMethodDecl *MD, unsigned SMKind);
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506 CXXRecordDecl *getInstantiatedFromMemberClass() const;
1507
1508
1509
1510
1511 MemberSpecializationInfo *getMemberSpecializationInfo() const;
1512
1513
1514
1515 void setInstantiationOfMemberClass(CXXRecordDecl *RD,
1516 TemplateSpecializationKind TSK);
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529 ClassTemplateDecl *getDescribedClassTemplate() const;
1530
1531 void setDescribedClassTemplate(ClassTemplateDecl *Template);
1532
1533
1534
1535
1536 TemplateSpecializationKind getTemplateSpecializationKind() const;
1537
1538
1539 void setTemplateSpecializationKind(TemplateSpecializationKind TSK);
1540
1541
1542
1543 const CXXRecordDecl *getTemplateInstantiationPattern() const;
1544
1545 CXXRecordDecl *getTemplateInstantiationPattern() {
1546 return const_cast<CXXRecordDecl *>(const_cast<const CXXRecordDecl *>(this)
1547 ->getTemplateInstantiationPattern());
1548 }
1549
1550
1551 CXXDestructorDecl *getDestructor() const;
1552
1553
1554
1555 bool isAnyDestructorNoReturn() const { return data().IsAnyDestructorNoReturn; }
1556
1557
1558
1559 bool isHLSLIntangible() const { return data().IsHLSLIntangible; }
1560
1561
1562
1563 const FunctionDecl *isLocalClass() const {
1564 if (const auto *RD = dyn_cast<CXXRecordDecl>(getDeclContext()))
1565 return RD->isLocalClass();
1566
1567 return dyn_cast<FunctionDecl>(getDeclContext());
1568 }
1569
1570 FunctionDecl *isLocalClass() {
1571 return const_cast<FunctionDecl*>(
1572 const_cast<const CXXRecordDecl*>(this)->isLocalClass());
1573 }
1574
1575
1576
1577 bool isCurrentInstantiation(const DeclContext *CurContext) const;
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589 bool isDerivedFrom(const CXXRecordDecl *Base) const;
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607 bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const;
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622 bool isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const;
1623
1624
1625
1626 bool isProvablyNotDerivedFrom(const CXXRecordDecl *Base) const;
1627
1628
1629
1630
1631
1632
1633 using ForallBasesCallback =
1634 llvm::function_ref<bool(const CXXRecordDecl *BaseDefinition)>;
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644 bool forallBases(ForallBasesCallback BaseMatches) const;
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656 using BaseMatchesCallback =
1657 llvm::function_ref<bool(const CXXBaseSpecifier *Specifier,
1658 CXXBasePath &Path)>;
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681 bool lookupInBases(BaseMatchesCallback BaseMatches, CXXBasePaths &Paths,
1682 bool LookupInDependent = false) const;
1683
1684
1685
1686
1687
1688
1689
1690
1691 static bool FindBaseClass(const CXXBaseSpecifier *Specifier,
1692 CXXBasePath &Path, const CXXRecordDecl *BaseRecord);
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703 static bool FindVirtualBaseClass(const CXXBaseSpecifier *Specifier,
1704 CXXBasePath &Path,
1705 const CXXRecordDecl *BaseRecord);
1706
1707
1708
1709
1710 void getFinalOverriders(CXXFinalOverriderMap &FinaOverriders) const;
1711
1712
1713 void getIndirectPrimaryBases(CXXIndirectPrimaryBaseSet& Bases) const;
1714
1715
1716
1717
1718
1719
1720
1721 bool hasMemberName(DeclarationName N) const;
1722
1723
1724
1725
1726
1727 std::vector<const NamedDecl *>
1728 lookupDependentName(DeclarationName Name,
1729 llvm::function_ref<bool(const NamedDecl *ND)> Filter);
1730
1731
1732
1733
1734 void viewInheritance(ASTContext& Context) const;
1735
1736
1737
1738 static AccessSpecifier MergeAccess(AccessSpecifier PathAccess,
1739 AccessSpecifier DeclAccess) {
1740 assert(DeclAccess != AS_none);
1741 if (DeclAccess == AS_private) return AS_none;
1742 return (PathAccess > DeclAccess ? PathAccess : DeclAccess);
1743 }
1744
1745
1746
1747 void finishedDefaultedOrDeletedMember(CXXMethodDecl *MD);
1748
1749 void setTrivialForCallFlags(CXXMethodDecl *MD);
1750
1751
1752 void completeDefinition() override;
1753
1754
1755
1756
1757
1758
1759
1760
1761 void completeDefinition(CXXFinalOverriderMap *FinalOverriders);
1762
1763
1764
1765
1766
1767
1768
1769
1770 bool mayBeAbstract() const;
1771
1772
1773
1774 bool isEffectivelyFinal() const;
1775
1776
1777
1778
1779
1780
1781
1782 unsigned getLambdaManglingNumber() const {
1783 assert(isLambda() && "Not a lambda closure type!");
1784 return getLambdaData().ManglingNumber;
1785 }
1786
1787
1788
1789 bool hasKnownLambdaInternalLinkage() const {
1790 assert(isLambda() && "Not a lambda closure type!");
1791 return getLambdaData().HasKnownInternalLinkage;
1792 }
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803 Decl *getLambdaContextDecl() const;
1804
1805
1806
1807 unsigned getLambdaIndexInContext() const {
1808 assert(isLambda() && "Not a lambda closure type!");
1809 return getLambdaData().IndexInContext;
1810 }
1811
1812
1813 struct LambdaNumbering {
1814 Decl *ContextDecl = nullptr;
1815 unsigned IndexInContext = 0;
1816 unsigned ManglingNumber = 0;
1817 unsigned DeviceManglingNumber = 0;
1818 bool HasKnownInternalLinkage = false;
1819 };
1820
1821
1822 void setLambdaNumbering(LambdaNumbering Numbering);
1823
1824
1825 LambdaNumbering getLambdaNumbering() const {
1826 return {getLambdaContextDecl(), getLambdaIndexInContext(),
1827 getLambdaManglingNumber(), getDeviceLambdaManglingNumber(),
1828 hasKnownLambdaInternalLinkage()};
1829 }
1830
1831
1832 unsigned getDeviceLambdaManglingNumber() const;
1833
1834
1835 MSInheritanceModel getMSInheritanceModel() const;
1836
1837
1838 MSInheritanceModel calculateInheritanceModel() const;
1839
1840
1841
1842
1843
1844
1845
1846 bool nullFieldOffsetIsZero() const;
1847
1848
1849
1850 MSVtorDispMode getMSVtorDispMode() const;
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863 bool isDependentLambda() const {
1864 return isLambda() && getLambdaData().DependencyKind == LDK_AlwaysDependent;
1865 }
1866
1867 bool isNeverDependentLambda() const {
1868 return isLambda() && getLambdaData().DependencyKind == LDK_NeverDependent;
1869 }
1870
1871 unsigned getLambdaDependencyKind() const {
1872 if (!isLambda())
1873 return LDK_Unknown;
1874 return getLambdaData().DependencyKind;
1875 }
1876
1877 TypeSourceInfo *getLambdaTypeInfo() const {
1878 return getLambdaData().MethodTyInfo;
1879 }
1880
1881 void setLambdaTypeInfo(TypeSourceInfo *TS) {
1882 assert(DefinitionData && DefinitionData->IsLambda &&
1883 "setting lambda property of non-lambda class");
1884 auto &DL = static_cast<LambdaDefinitionData &>(*DefinitionData);
1885 DL.MethodTyInfo = TS;
1886 }
1887
1888 void setLambdaDependencyKind(unsigned Kind) {
1889 getLambdaData().DependencyKind = Kind;
1890 }
1891
1892 void setLambdaIsGeneric(bool IsGeneric) {
1893 assert(DefinitionData && DefinitionData->IsLambda &&
1894 "setting lambda property of non-lambda class");
1895 auto &DL = static_cast<LambdaDefinitionData &>(*DefinitionData);
1896 DL.IsGenericLambda = IsGeneric;
1897 }
1898
1899
1900
1901 bool isInterfaceLike() const;
1902
1903 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1904 static bool classofKind(Kind K) {
1905 return K >= firstCXXRecord && K <= lastCXXRecord;
1906 }
1907 void markAbstract() { data().Abstract = true; }
1908 };
1909
1910
1911
1912 class ExplicitSpecifier {
1913 llvm::PointerIntPair<Expr *, 2, ExplicitSpecKind> ExplicitSpec{
1914 nullptr, ExplicitSpecKind::ResolvedFalse};
1915
1916 public:
1917 ExplicitSpecifier() = default;
1918 ExplicitSpecifier(Expr *Expression, ExplicitSpecKind Kind)
1919 : ExplicitSpec(Expression, Kind) {}
1920 ExplicitSpecKind getKind() const { return ExplicitSpec.getInt(); }
1921 const Expr *getExpr() const { return ExplicitSpec.getPointer(); }
1922 Expr *getExpr() { return ExplicitSpec.getPointer(); }
1923
1924
1925 bool isSpecified() const {
1926 return ExplicitSpec.getInt() != ExplicitSpecKind::ResolvedFalse ||
1927 ExplicitSpec.getPointer();
1928 }
1929
1930
1931
1932 bool isEquivalent(const ExplicitSpecifier Other) const;
1933
1934
1935
1936 bool isExplicit() const {
1937 return ExplicitSpec.getInt() == ExplicitSpecKind::ResolvedTrue;
1938 }
1939
1940
1941 bool isInvalid() const {
1942 return ExplicitSpec.getInt() == ExplicitSpecKind::Unresolved &&
1943 !ExplicitSpec.getPointer();
1944 }
1945 void setKind(ExplicitSpecKind Kind) { ExplicitSpec.setInt(Kind); }
1946 void setExpr(Expr *E) { ExplicitSpec.setPointer(E); }
1947
1948 static ExplicitSpecifier getFromDecl(FunctionDecl *Function);
1949 static const ExplicitSpecifier getFromDecl(const FunctionDecl *Function) {
1950 return getFromDecl(const_cast<FunctionDecl *>(Function));
1951 }
1952 static ExplicitSpecifier Invalid() {
1953 return ExplicitSpecifier(nullptr, ExplicitSpecKind::Unresolved);
1954 }
1955 };
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967 class CXXDeductionGuideDecl : public FunctionDecl {
1968 void anchor() override;
1969
1970 public:
1971
1972
1973
1974 enum class SourceDeductionGuideKind : uint8_t {
1975 None,
1976 Alias,
1977 };
1978
1979 private:
1980 CXXDeductionGuideDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1981 ExplicitSpecifier ES,
1982 const DeclarationNameInfo &NameInfo, QualType T,
1983 TypeSourceInfo *TInfo, SourceLocation EndLocation,
1984 CXXConstructorDecl *Ctor, DeductionCandidate Kind,
1985 Expr *TrailingRequiresClause,
1986 const CXXDeductionGuideDecl *GeneratedFrom,
1987 SourceDeductionGuideKind SourceKind)
1988 : FunctionDecl(CXXDeductionGuide, C, DC, StartLoc, NameInfo, T, TInfo,
1989 SC_None, false, false, ConstexprSpecKind::Unspecified,
1990 TrailingRequiresClause),
1991 Ctor(Ctor), ExplicitSpec(ES),
1992 SourceDeductionGuide(GeneratedFrom, SourceKind) {
1993 if (EndLocation.isValid())
1994 setRangeEnd(EndLocation);
1995 setDeductionCandidateKind(Kind);
1996 }
1997
1998 CXXConstructorDecl *Ctor;
1999 ExplicitSpecifier ExplicitSpec;
2000
2001
2002
2003 llvm::PointerIntPair<const CXXDeductionGuideDecl *, 2,
2004 SourceDeductionGuideKind>
2005 SourceDeductionGuide;
2006 void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; }
2007
2008 public:
2009 friend class ASTDeclReader;
2010 friend class ASTDeclWriter;
2011
2012 static CXXDeductionGuideDecl *
2013 Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
2014 ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T,
2015 TypeSourceInfo *TInfo, SourceLocation EndLocation,
2016 CXXConstructorDecl *Ctor = nullptr,
2017 DeductionCandidate Kind = DeductionCandidate::Normal,
2018 Expr *TrailingRequiresClause = nullptr,
2019 const CXXDeductionGuideDecl *SourceDG = nullptr,
2020 SourceDeductionGuideKind SK = SourceDeductionGuideKind::None);
2021
2022 static CXXDeductionGuideDecl *CreateDeserialized(ASTContext &C,
2023 GlobalDeclID ID);
2024
2025 ExplicitSpecifier getExplicitSpecifier() { return ExplicitSpec; }
2026 const ExplicitSpecifier getExplicitSpecifier() const { return ExplicitSpec; }
2027
2028
2029 bool isExplicit() const { return ExplicitSpec.isExplicit(); }
2030
2031
2032 TemplateDecl *getDeducedTemplate() const {
2033 return getDeclName().getCXXDeductionGuideTemplate();
2034 }
2035
2036
2037
2038 CXXConstructorDecl *getCorrespondingConstructor() const { return Ctor; }
2039
2040
2041
2042
2043 const CXXDeductionGuideDecl *getSourceDeductionGuide() const {
2044 return SourceDeductionGuide.getPointer();
2045 }
2046
2047 void setSourceDeductionGuide(CXXDeductionGuideDecl *DG) {
2048 SourceDeductionGuide.setPointer(DG);
2049 }
2050
2051 SourceDeductionGuideKind getSourceDeductionGuideKind() const {
2052 return SourceDeductionGuide.getInt();
2053 }
2054
2055 void setSourceDeductionGuideKind(SourceDeductionGuideKind SK) {
2056 SourceDeductionGuide.setInt(SK);
2057 }
2058
2059 void setDeductionCandidateKind(DeductionCandidate K) {
2060 FunctionDeclBits.DeductionCandidateKind = static_cast<unsigned char>(K);
2061 }
2062
2063 DeductionCandidate getDeductionCandidateKind() const {
2064 return static_cast<DeductionCandidate>(
2065 FunctionDeclBits.DeductionCandidateKind);
2066 }
2067
2068
2069 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2070 static bool classofKind(Kind K) { return K == CXXDeductionGuide; }
2071 };
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086 class RequiresExprBodyDecl : public Decl, public DeclContext {
2087 RequiresExprBodyDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc)
2088 : Decl(RequiresExprBody, DC, StartLoc), DeclContext(RequiresExprBody) {}
2089
2090 public:
2091 friend class ASTDeclReader;
2092 friend class ASTDeclWriter;
2093
2094 static RequiresExprBodyDecl *Create(ASTContext &C, DeclContext *DC,
2095 SourceLocation StartLoc);
2096
2097 static RequiresExprBodyDecl *CreateDeserialized(ASTContext &C,
2098 GlobalDeclID ID);
2099
2100
2101 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2102 static bool classofKind(Kind K) { return K == RequiresExprBody; }
2103
2104 static DeclContext *castToDeclContext(const RequiresExprBodyDecl *D) {
2105 return static_cast<DeclContext *>(const_cast<RequiresExprBodyDecl *>(D));
2106 }
2107
2108 static RequiresExprBodyDecl *castFromDeclContext(const DeclContext *DC) {
2109 return static_cast<RequiresExprBodyDecl *>(const_cast<DeclContext *>(DC));
2110 }
2111 };
2112
2113
2114
2115
2116
2117 class CXXMethodDecl : public FunctionDecl {
2118 void anchor() override;
2119
2120 protected:
2121 CXXMethodDecl(Kind DK, ASTContext &C, CXXRecordDecl *RD,
2122 SourceLocation StartLoc, const DeclarationNameInfo &NameInfo,
2123 QualType T, TypeSourceInfo *TInfo, StorageClass SC,
2124 bool UsesFPIntrin, bool isInline,
2125 ConstexprSpecKind ConstexprKind, SourceLocation EndLocation,
2126 Expr *TrailingRequiresClause = nullptr)
2127 : FunctionDecl(DK, C, RD, StartLoc, NameInfo, T, TInfo, SC, UsesFPIntrin,
2128 isInline, ConstexprKind, TrailingRequiresClause) {
2129 if (EndLocation.isValid())
2130 setRangeEnd(EndLocation);
2131 }
2132
2133 public:
2134 static CXXMethodDecl *
2135 Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2136 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2137 StorageClass SC, bool UsesFPIntrin, bool isInline,
2138 ConstexprSpecKind ConstexprKind, SourceLocation EndLocation,
2139 Expr *TrailingRequiresClause = nullptr);
2140
2141 static CXXMethodDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
2142
2143 bool isStatic() const;
2144 bool isInstance() const { return !isStatic(); }
2145
2146
2147
2148
2149
2150 bool isExplicitObjectMemberFunction() const;
2151
2152
2153
2154
2155 bool isImplicitObjectMemberFunction() const;
2156
2157
2158
2159 static bool isStaticOverloadedOperator(OverloadedOperatorKind OOK) {
2160
2161
2162
2163
2164
2165 return OOK == OO_New || OOK == OO_Array_New || OOK == OO_Delete ||
2166 OOK == OO_Array_Delete;
2167 }
2168
2169 bool isConst() const { return getType()->castAs<FunctionType>()->isConst(); }
2170 bool isVolatile() const { return getType()->castAs<FunctionType>()->isVolatile(); }
2171
2172 bool isVirtual() const {
2173 CXXMethodDecl *CD = const_cast<CXXMethodDecl*>(this)->getCanonicalDecl();
2174
2175
2176
2177 if (CD->isVirtualAsWritten() || CD->isPureVirtual())
2178 return true;
2179
2180 return CD->size_overridden_methods() != 0;
2181 }
2182
2183
2184
2185
2186
2187
2188 CXXMethodDecl *getDevirtualizedMethod(const Expr *Base, bool IsAppleKext);
2189
2190 const CXXMethodDecl *getDevirtualizedMethod(const Expr *Base,
2191 bool IsAppleKext) const {
2192 return const_cast<CXXMethodDecl *>(this)->getDevirtualizedMethod(
2193 Base, IsAppleKext);
2194 }
2195
2196
2197
2198
2199
2200
2201
2202
2203 bool isUsualDeallocationFunction(
2204 SmallVectorImpl<const FunctionDecl *> &PreventedBy) const;
2205
2206
2207
2208 bool isCopyAssignmentOperator() const;
2209
2210
2211 bool isMoveAssignmentOperator() const;
2212
2213 CXXMethodDecl *getCanonicalDecl() override {
2214 return cast<CXXMethodDecl>(FunctionDecl::getCanonicalDecl());
2215 }
2216 const CXXMethodDecl *getCanonicalDecl() const {
2217 return const_cast<CXXMethodDecl*>(this)->getCanonicalDecl();
2218 }
2219
2220 CXXMethodDecl *getMostRecentDecl() {
2221 return cast<CXXMethodDecl>(
2222 static_cast<FunctionDecl *>(this)->getMostRecentDecl());
2223 }
2224 const CXXMethodDecl *getMostRecentDecl() const {
2225 return const_cast<CXXMethodDecl*>(this)->getMostRecentDecl();
2226 }
2227
2228 void addOverriddenMethod(const CXXMethodDecl *MD);
2229
2230 using method_iterator = const CXXMethodDecl *const *;
2231
2232 method_iterator begin_overridden_methods() const;
2233 method_iterator end_overridden_methods() const;
2234 unsigned size_overridden_methods() const;
2235
2236 using overridden_method_range = llvm::iterator_range<
2237 llvm::TinyPtrVector<const CXXMethodDecl *>::const_iterator>;
2238
2239 overridden_method_range overridden_methods() const;
2240
2241
2242
2243 const CXXRecordDecl *getParent() const {
2244 return cast<CXXRecordDecl>(FunctionDecl::getParent());
2245 }
2246
2247
2248
2249 CXXRecordDecl *getParent() {
2250 return const_cast<CXXRecordDecl *>(
2251 cast<CXXRecordDecl>(FunctionDecl::getParent()));
2252 }
2253
2254
2255
2256
2257
2258
2259
2260 QualType getThisType() const;
2261
2262
2263
2264
2265
2266 QualType getFunctionObjectParameterReferenceType() const;
2267 QualType getFunctionObjectParameterType() const {
2268 return getFunctionObjectParameterReferenceType().getNonReferenceType();
2269 }
2270
2271 unsigned getNumExplicitParams() const {
2272 return getNumParams() - (isExplicitObjectMemberFunction() ? 1 : 0);
2273 }
2274
2275 static QualType getThisType(const FunctionProtoType *FPT,
2276 const CXXRecordDecl *Decl);
2277
2278 Qualifiers getMethodQualifiers() const {
2279 return getType()->castAs<FunctionProtoType>()->getMethodQuals();
2280 }
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293 RefQualifierKind getRefQualifier() const {
2294 return getType()->castAs<FunctionProtoType>()->getRefQualifier();
2295 }
2296
2297 bool hasInlineBody() const;
2298
2299
2300
2301
2302
2303
2304
2305
2306 bool isLambdaStaticInvoker() const;
2307
2308
2309
2310
2311
2312
2313 CXXMethodDecl *
2314 getCorrespondingMethodInClass(const CXXRecordDecl *RD,
2315 bool MayBeBase = false);
2316
2317 const CXXMethodDecl *
2318 getCorrespondingMethodInClass(const CXXRecordDecl *RD,
2319 bool MayBeBase = false) const {
2320 return const_cast<CXXMethodDecl *>(this)
2321 ->getCorrespondingMethodInClass(RD, MayBeBase);
2322 }
2323
2324
2325
2326 CXXMethodDecl *getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD,
2327 bool MayBeBase = false);
2328 const CXXMethodDecl *
2329 getCorrespondingMethodDeclaredInClass(const CXXRecordDecl *RD,
2330 bool MayBeBase = false) const {
2331 return const_cast<CXXMethodDecl *>(this)
2332 ->getCorrespondingMethodDeclaredInClass(RD, MayBeBase);
2333 }
2334
2335
2336 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2337 static bool classofKind(Kind K) {
2338 return K >= firstCXXMethod && K <= lastCXXMethod;
2339 }
2340 };
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357 class CXXCtorInitializer final {
2358
2359
2360
2361 llvm::PointerUnion<TypeSourceInfo *, FieldDecl *, IndirectFieldDecl *>
2362 Initializee;
2363
2364
2365
2366 Stmt *Init;
2367
2368
2369
2370
2371
2372
2373
2374 SourceLocation MemberOrEllipsisLocation;
2375
2376
2377 SourceLocation LParenLoc;
2378
2379
2380 SourceLocation RParenLoc;
2381
2382
2383
2384 LLVM_PREFERRED_TYPE(bool)
2385 unsigned IsDelegating : 1;
2386
2387
2388
2389 LLVM_PREFERRED_TYPE(bool)
2390 unsigned IsVirtual : 1;
2391
2392
2393
2394 LLVM_PREFERRED_TYPE(bool)
2395 unsigned IsWritten : 1;
2396
2397
2398
2399 unsigned SourceOrder : 13;
2400
2401 public:
2402
2403 explicit
2404 CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo, bool IsVirtual,
2405 SourceLocation L, Expr *Init, SourceLocation R,
2406 SourceLocation EllipsisLoc);
2407
2408
2409 explicit
2410 CXXCtorInitializer(ASTContext &Context, FieldDecl *Member,
2411 SourceLocation MemberLoc, SourceLocation L, Expr *Init,
2412 SourceLocation R);
2413
2414
2415 explicit
2416 CXXCtorInitializer(ASTContext &Context, IndirectFieldDecl *Member,
2417 SourceLocation MemberLoc, SourceLocation L, Expr *Init,
2418 SourceLocation R);
2419
2420
2421 explicit
2422 CXXCtorInitializer(ASTContext &Context, TypeSourceInfo *TInfo,
2423 SourceLocation L, Expr *Init, SourceLocation R);
2424
2425
2426 int64_t getID(const ASTContext &Context) const;
2427
2428
2429 bool isBaseInitializer() const {
2430 return isa<TypeSourceInfo *>(Initializee) && !IsDelegating;
2431 }
2432
2433
2434
2435 bool isMemberInitializer() const { return isa<FieldDecl *>(Initializee); }
2436
2437 bool isAnyMemberInitializer() const {
2438 return isMemberInitializer() || isIndirectMemberInitializer();
2439 }
2440
2441 bool isIndirectMemberInitializer() const {
2442 return isa<IndirectFieldDecl *>(Initializee);
2443 }
2444
2445
2446
2447
2448
2449
2450
2451 bool isInClassMemberInitializer() const {
2452 return Init->getStmtClass() == Stmt::CXXDefaultInitExprClass;
2453 }
2454
2455
2456
2457 bool isDelegatingInitializer() const {
2458 return isa<TypeSourceInfo *>(Initializee) && IsDelegating;
2459 }
2460
2461
2462 bool isPackExpansion() const {
2463 return isBaseInitializer() && MemberOrEllipsisLocation.isValid();
2464 }
2465
2466
2467 SourceLocation getEllipsisLoc() const {
2468 if (!isPackExpansion())
2469 return {};
2470 return MemberOrEllipsisLocation;
2471 }
2472
2473
2474
2475
2476 TypeLoc getBaseClassLoc() const;
2477
2478
2479
2480 const Type *getBaseClass() const;
2481
2482
2483 bool isBaseVirtual() const {
2484 assert(isBaseInitializer() && "Must call this on base initializer!");
2485
2486 return IsVirtual;
2487 }
2488
2489
2490
2491 TypeSourceInfo *getTypeSourceInfo() const {
2492 return Initializee.dyn_cast<TypeSourceInfo *>();
2493 }
2494
2495
2496
2497 FieldDecl *getMember() const {
2498 if (isMemberInitializer())
2499 return cast<FieldDecl *>(Initializee);
2500 return nullptr;
2501 }
2502
2503 FieldDecl *getAnyMember() const {
2504 if (isMemberInitializer())
2505 return cast<FieldDecl *>(Initializee);
2506 if (isIndirectMemberInitializer())
2507 return cast<IndirectFieldDecl *>(Initializee)->getAnonField();
2508 return nullptr;
2509 }
2510
2511 IndirectFieldDecl *getIndirectMember() const {
2512 if (isIndirectMemberInitializer())
2513 return cast<IndirectFieldDecl *>(Initializee);
2514 return nullptr;
2515 }
2516
2517 SourceLocation getMemberLocation() const {
2518 return MemberOrEllipsisLocation;
2519 }
2520
2521
2522 SourceLocation getSourceLocation() const;
2523
2524
2525 SourceRange getSourceRange() const LLVM_READONLY;
2526
2527
2528
2529 bool isWritten() const { return IsWritten; }
2530
2531
2532
2533 int getSourceOrder() const {
2534 return IsWritten ? static_cast<int>(SourceOrder) : -1;
2535 }
2536
2537
2538
2539
2540
2541
2542
2543
2544 void setSourceOrder(int Pos) {
2545 assert(!IsWritten &&
2546 "setSourceOrder() used on implicit initializer");
2547 assert(SourceOrder == 0 &&
2548 "calling twice setSourceOrder() on the same initializer");
2549 assert(Pos >= 0 &&
2550 "setSourceOrder() used to make an initializer implicit");
2551 IsWritten = true;
2552 SourceOrder = static_cast<unsigned>(Pos);
2553 }
2554
2555 SourceLocation getLParenLoc() const { return LParenLoc; }
2556 SourceLocation getRParenLoc() const { return RParenLoc; }
2557
2558
2559 Expr *getInit() const { return static_cast<Expr *>(Init); }
2560 };
2561
2562
2563 class InheritedConstructor {
2564 ConstructorUsingShadowDecl *Shadow = nullptr;
2565 CXXConstructorDecl *BaseCtor = nullptr;
2566
2567 public:
2568 InheritedConstructor() = default;
2569 InheritedConstructor(ConstructorUsingShadowDecl *Shadow,
2570 CXXConstructorDecl *BaseCtor)
2571 : Shadow(Shadow), BaseCtor(BaseCtor) {}
2572
2573 explicit operator bool() const { return Shadow; }
2574
2575 ConstructorUsingShadowDecl *getShadowDecl() const { return Shadow; }
2576 CXXConstructorDecl *getConstructor() const { return BaseCtor; }
2577 };
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589 class CXXConstructorDecl final
2590 : public CXXMethodDecl,
2591 private llvm::TrailingObjects<CXXConstructorDecl, InheritedConstructor,
2592 ExplicitSpecifier> {
2593
2594
2595
2596
2597
2598
2599 LazyCXXCtorInitializersPtr CtorInitializers;
2600
2601 CXXConstructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2602 const DeclarationNameInfo &NameInfo, QualType T,
2603 TypeSourceInfo *TInfo, ExplicitSpecifier ES,
2604 bool UsesFPIntrin, bool isInline,
2605 bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind,
2606 InheritedConstructor Inherited,
2607 Expr *TrailingRequiresClause);
2608
2609 void anchor() override;
2610
2611 size_t numTrailingObjects(OverloadToken<InheritedConstructor>) const {
2612 return CXXConstructorDeclBits.IsInheritingConstructor;
2613 }
2614 size_t numTrailingObjects(OverloadToken<ExplicitSpecifier>) const {
2615 return CXXConstructorDeclBits.HasTrailingExplicitSpecifier;
2616 }
2617
2618 ExplicitSpecifier getExplicitSpecifierInternal() const {
2619 if (CXXConstructorDeclBits.HasTrailingExplicitSpecifier)
2620 return *getTrailingObjects<ExplicitSpecifier>();
2621 return ExplicitSpecifier(
2622 nullptr, CXXConstructorDeclBits.IsSimpleExplicit
2623 ? ExplicitSpecKind::ResolvedTrue
2624 : ExplicitSpecKind::ResolvedFalse);
2625 }
2626
2627 enum TrailingAllocKind {
2628 TAKInheritsConstructor = 1,
2629 TAKHasTailExplicit = 1 << 1,
2630 };
2631
2632 uint64_t getTrailingAllocKind() const {
2633 return numTrailingObjects(OverloadToken<InheritedConstructor>()) |
2634 (numTrailingObjects(OverloadToken<ExplicitSpecifier>()) << 1);
2635 }
2636
2637 public:
2638 friend class ASTDeclReader;
2639 friend class ASTDeclWriter;
2640 friend TrailingObjects;
2641
2642 static CXXConstructorDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
2643 uint64_t AllocKind);
2644 static CXXConstructorDecl *
2645 Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2646 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2647 ExplicitSpecifier ES, bool UsesFPIntrin, bool isInline,
2648 bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind,
2649 InheritedConstructor Inherited = InheritedConstructor(),
2650 Expr *TrailingRequiresClause = nullptr);
2651
2652 void setExplicitSpecifier(ExplicitSpecifier ES) {
2653 assert((!ES.getExpr() ||
2654 CXXConstructorDeclBits.HasTrailingExplicitSpecifier) &&
2655 "cannot set this explicit specifier. no trail-allocated space for "
2656 "explicit");
2657 if (ES.getExpr())
2658 *getCanonicalDecl()->getTrailingObjects<ExplicitSpecifier>() = ES;
2659 else
2660 CXXConstructorDeclBits.IsSimpleExplicit = ES.isExplicit();
2661 }
2662
2663 ExplicitSpecifier getExplicitSpecifier() {
2664 return getCanonicalDecl()->getExplicitSpecifierInternal();
2665 }
2666 const ExplicitSpecifier getExplicitSpecifier() const {
2667 return getCanonicalDecl()->getExplicitSpecifierInternal();
2668 }
2669
2670
2671 bool isExplicit() const { return getExplicitSpecifier().isExplicit(); }
2672
2673
2674 using init_iterator = CXXCtorInitializer **;
2675
2676
2677 using init_const_iterator = CXXCtorInitializer *const *;
2678
2679 using init_range = llvm::iterator_range<init_iterator>;
2680 using init_const_range = llvm::iterator_range<init_const_iterator>;
2681
2682 init_range inits() { return init_range(init_begin(), init_end()); }
2683 init_const_range inits() const {
2684 return init_const_range(init_begin(), init_end());
2685 }
2686
2687
2688 init_iterator init_begin() {
2689 const auto *ConstThis = this;
2690 return const_cast<init_iterator>(ConstThis->init_begin());
2691 }
2692
2693
2694 init_const_iterator init_begin() const;
2695
2696
2697 init_iterator init_end() {
2698 return init_begin() + getNumCtorInitializers();
2699 }
2700
2701
2702 init_const_iterator init_end() const {
2703 return init_begin() + getNumCtorInitializers();
2704 }
2705
2706 using init_reverse_iterator = std::reverse_iterator<init_iterator>;
2707 using init_const_reverse_iterator =
2708 std::reverse_iterator<init_const_iterator>;
2709
2710 init_reverse_iterator init_rbegin() {
2711 return init_reverse_iterator(init_end());
2712 }
2713 init_const_reverse_iterator init_rbegin() const {
2714 return init_const_reverse_iterator(init_end());
2715 }
2716
2717 init_reverse_iterator init_rend() {
2718 return init_reverse_iterator(init_begin());
2719 }
2720 init_const_reverse_iterator init_rend() const {
2721 return init_const_reverse_iterator(init_begin());
2722 }
2723
2724
2725
2726 unsigned getNumCtorInitializers() const {
2727 return CXXConstructorDeclBits.NumCtorInitializers;
2728 }
2729
2730 void setNumCtorInitializers(unsigned numCtorInitializers) {
2731 CXXConstructorDeclBits.NumCtorInitializers = numCtorInitializers;
2732
2733
2734
2735 assert(CXXConstructorDeclBits.NumCtorInitializers ==
2736 numCtorInitializers && "NumCtorInitializers overflow!");
2737 }
2738
2739 void setCtorInitializers(CXXCtorInitializer **Initializers) {
2740 CtorInitializers = Initializers;
2741 }
2742
2743
2744 bool isDelegatingConstructor() const {
2745 return (getNumCtorInitializers() == 1) &&
2746 init_begin()[0]->isDelegatingInitializer();
2747 }
2748
2749
2750 CXXConstructorDecl *getTargetConstructor() const;
2751
2752
2753
2754
2755 bool isDefaultConstructor() const;
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770 bool isCopyConstructor(unsigned &TypeQuals) const;
2771
2772
2773
2774
2775 bool isCopyConstructor() const {
2776 unsigned TypeQuals = 0;
2777 return isCopyConstructor(TypeQuals);
2778 }
2779
2780
2781
2782
2783
2784
2785 bool isMoveConstructor(unsigned &TypeQuals) const;
2786
2787
2788
2789 bool isMoveConstructor() const {
2790 unsigned TypeQuals = 0;
2791 return isMoveConstructor(TypeQuals);
2792 }
2793
2794
2795
2796
2797
2798 bool isCopyOrMoveConstructor(unsigned &TypeQuals) const;
2799
2800
2801 bool isCopyOrMoveConstructor() const {
2802 unsigned Quals;
2803 return isCopyOrMoveConstructor(Quals);
2804 }
2805
2806
2807
2808
2809 bool isConvertingConstructor(bool AllowExplicit) const;
2810
2811
2812
2813
2814 bool isSpecializationCopyingObject() const;
2815
2816
2817
2818 bool isInheritingConstructor() const {
2819 return CXXConstructorDeclBits.IsInheritingConstructor;
2820 }
2821
2822
2823
2824 void setInheritingConstructor(bool isIC = true) {
2825 CXXConstructorDeclBits.IsInheritingConstructor = isIC;
2826 }
2827
2828
2829 InheritedConstructor getInheritedConstructor() const {
2830 return isInheritingConstructor() ?
2831 *getTrailingObjects<InheritedConstructor>() : InheritedConstructor();
2832 }
2833
2834 CXXConstructorDecl *getCanonicalDecl() override {
2835 return cast<CXXConstructorDecl>(FunctionDecl::getCanonicalDecl());
2836 }
2837 const CXXConstructorDecl *getCanonicalDecl() const {
2838 return const_cast<CXXConstructorDecl*>(this)->getCanonicalDecl();
2839 }
2840
2841
2842 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2843 static bool classofKind(Kind K) { return K == CXXConstructor; }
2844 };
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856 class CXXDestructorDecl : public CXXMethodDecl {
2857 friend class ASTDeclReader;
2858 friend class ASTDeclWriter;
2859
2860
2861
2862 FunctionDecl *OperatorDelete = nullptr;
2863 Expr *OperatorDeleteThisArg = nullptr;
2864
2865 CXXDestructorDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2866 const DeclarationNameInfo &NameInfo, QualType T,
2867 TypeSourceInfo *TInfo, bool UsesFPIntrin, bool isInline,
2868 bool isImplicitlyDeclared, ConstexprSpecKind ConstexprKind,
2869 Expr *TrailingRequiresClause = nullptr)
2870 : CXXMethodDecl(CXXDestructor, C, RD, StartLoc, NameInfo, T, TInfo,
2871 SC_None, UsesFPIntrin, isInline, ConstexprKind,
2872 SourceLocation(), TrailingRequiresClause) {
2873 setImplicit(isImplicitlyDeclared);
2874 }
2875
2876 void anchor() override;
2877
2878 public:
2879 static CXXDestructorDecl *
2880 Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2881 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2882 bool UsesFPIntrin, bool isInline, bool isImplicitlyDeclared,
2883 ConstexprSpecKind ConstexprKind,
2884 Expr *TrailingRequiresClause = nullptr);
2885 static CXXDestructorDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
2886
2887 void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg);
2888
2889 const FunctionDecl *getOperatorDelete() const {
2890 return getCanonicalDecl()->OperatorDelete;
2891 }
2892
2893 Expr *getOperatorDeleteThisArg() const {
2894 return getCanonicalDecl()->OperatorDeleteThisArg;
2895 }
2896
2897
2898
2899
2900 bool isCalledByDelete(const FunctionDecl *OpDel = nullptr) const;
2901
2902 CXXDestructorDecl *getCanonicalDecl() override {
2903 return cast<CXXDestructorDecl>(FunctionDecl::getCanonicalDecl());
2904 }
2905 const CXXDestructorDecl *getCanonicalDecl() const {
2906 return const_cast<CXXDestructorDecl*>(this)->getCanonicalDecl();
2907 }
2908
2909
2910 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2911 static bool classofKind(Kind K) { return K == CXXDestructor; }
2912 };
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924 class CXXConversionDecl : public CXXMethodDecl {
2925 CXXConversionDecl(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2926 const DeclarationNameInfo &NameInfo, QualType T,
2927 TypeSourceInfo *TInfo, bool UsesFPIntrin, bool isInline,
2928 ExplicitSpecifier ES, ConstexprSpecKind ConstexprKind,
2929 SourceLocation EndLocation,
2930 Expr *TrailingRequiresClause = nullptr)
2931 : CXXMethodDecl(CXXConversion, C, RD, StartLoc, NameInfo, T, TInfo,
2932 SC_None, UsesFPIntrin, isInline, ConstexprKind,
2933 EndLocation, TrailingRequiresClause),
2934 ExplicitSpec(ES) {}
2935 void anchor() override;
2936
2937 ExplicitSpecifier ExplicitSpec;
2938
2939 public:
2940 friend class ASTDeclReader;
2941 friend class ASTDeclWriter;
2942
2943 static CXXConversionDecl *
2944 Create(ASTContext &C, CXXRecordDecl *RD, SourceLocation StartLoc,
2945 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2946 bool UsesFPIntrin, bool isInline, ExplicitSpecifier ES,
2947 ConstexprSpecKind ConstexprKind, SourceLocation EndLocation,
2948 Expr *TrailingRequiresClause = nullptr);
2949 static CXXConversionDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
2950
2951 ExplicitSpecifier getExplicitSpecifier() {
2952 return getCanonicalDecl()->ExplicitSpec;
2953 }
2954
2955 const ExplicitSpecifier getExplicitSpecifier() const {
2956 return getCanonicalDecl()->ExplicitSpec;
2957 }
2958
2959
2960 bool isExplicit() const { return getExplicitSpecifier().isExplicit(); }
2961 void setExplicitSpecifier(ExplicitSpecifier ES) { ExplicitSpec = ES; }
2962
2963
2964 QualType getConversionType() const {
2965 return getType()->castAs<FunctionType>()->getReturnType();
2966 }
2967
2968
2969
2970 bool isLambdaToBlockPointerConversion() const;
2971
2972 CXXConversionDecl *getCanonicalDecl() override {
2973 return cast<CXXConversionDecl>(FunctionDecl::getCanonicalDecl());
2974 }
2975 const CXXConversionDecl *getCanonicalDecl() const {
2976 return const_cast<CXXConversionDecl*>(this)->getCanonicalDecl();
2977 }
2978
2979
2980 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
2981 static bool classofKind(Kind K) { return K == CXXConversion; }
2982 };
2983
2984
2985
2986
2987
2988 enum class LinkageSpecLanguageIDs { C = 1, CXX = 2 };
2989
2990
2991
2992
2993
2994
2995
2996 class LinkageSpecDecl : public Decl, public DeclContext {
2997 virtual void anchor();
2998
2999
3000
3001
3002 SourceLocation ExternLoc;
3003
3004
3005 SourceLocation RBraceLoc;
3006
3007 LinkageSpecDecl(DeclContext *DC, SourceLocation ExternLoc,
3008 SourceLocation LangLoc, LinkageSpecLanguageIDs lang,
3009 bool HasBraces);
3010
3011 public:
3012 static LinkageSpecDecl *Create(ASTContext &C, DeclContext *DC,
3013 SourceLocation ExternLoc,
3014 SourceLocation LangLoc,
3015 LinkageSpecLanguageIDs Lang, bool HasBraces);
3016 static LinkageSpecDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3017
3018
3019 LinkageSpecLanguageIDs getLanguage() const {
3020 return static_cast<LinkageSpecLanguageIDs>(LinkageSpecDeclBits.Language);
3021 }
3022
3023
3024 void setLanguage(LinkageSpecLanguageIDs L) {
3025 LinkageSpecDeclBits.Language = llvm::to_underlying(L);
3026 }
3027
3028
3029
3030 bool hasBraces() const {
3031 assert(!RBraceLoc.isValid() || LinkageSpecDeclBits.HasBraces);
3032 return LinkageSpecDeclBits.HasBraces;
3033 }
3034
3035 SourceLocation getExternLoc() const { return ExternLoc; }
3036 SourceLocation getRBraceLoc() const { return RBraceLoc; }
3037 void setExternLoc(SourceLocation L) { ExternLoc = L; }
3038 void setRBraceLoc(SourceLocation L) {
3039 RBraceLoc = L;
3040 LinkageSpecDeclBits.HasBraces = RBraceLoc.isValid();
3041 }
3042
3043 SourceLocation getEndLoc() const LLVM_READONLY {
3044 if (hasBraces())
3045 return getRBraceLoc();
3046
3047
3048 return decls_empty() ? getLocation() : decls_begin()->getEndLoc();
3049 }
3050
3051 SourceRange getSourceRange() const override LLVM_READONLY {
3052 return SourceRange(ExternLoc, getEndLoc());
3053 }
3054
3055 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3056 static bool classofKind(Kind K) { return K == LinkageSpec; }
3057
3058 static DeclContext *castToDeclContext(const LinkageSpecDecl *D) {
3059 return static_cast<DeclContext *>(const_cast<LinkageSpecDecl*>(D));
3060 }
3061
3062 static LinkageSpecDecl *castFromDeclContext(const DeclContext *DC) {
3063 return static_cast<LinkageSpecDecl *>(const_cast<DeclContext*>(DC));
3064 }
3065 };
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077 class UsingDirectiveDecl : public NamedDecl {
3078
3079 SourceLocation UsingLoc;
3080
3081
3082 SourceLocation NamespaceLoc;
3083
3084
3085 NestedNameSpecifierLoc QualifierLoc;
3086
3087
3088 NamedDecl *NominatedNamespace;
3089
3090
3091
3092 DeclContext *CommonAncestor;
3093
3094 UsingDirectiveDecl(DeclContext *DC, SourceLocation UsingLoc,
3095 SourceLocation NamespcLoc,
3096 NestedNameSpecifierLoc QualifierLoc,
3097 SourceLocation IdentLoc,
3098 NamedDecl *Nominated,
3099 DeclContext *CommonAncestor)
3100 : NamedDecl(UsingDirective, DC, IdentLoc, getName()), UsingLoc(UsingLoc),
3101 NamespaceLoc(NamespcLoc), QualifierLoc(QualifierLoc),
3102 NominatedNamespace(Nominated), CommonAncestor(CommonAncestor) {}
3103
3104
3105
3106
3107
3108 static DeclarationName getName() {
3109 return DeclarationName::getUsingDirectiveName();
3110 }
3111
3112 void anchor() override;
3113
3114 public:
3115 friend class ASTDeclReader;
3116
3117
3118 friend class DeclContext;
3119
3120
3121
3122 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3123
3124
3125
3126 NestedNameSpecifier *getQualifier() const {
3127 return QualifierLoc.getNestedNameSpecifier();
3128 }
3129
3130 NamedDecl *getNominatedNamespaceAsWritten() { return NominatedNamespace; }
3131 const NamedDecl *getNominatedNamespaceAsWritten() const {
3132 return NominatedNamespace;
3133 }
3134
3135
3136 NamespaceDecl *getNominatedNamespace();
3137
3138 const NamespaceDecl *getNominatedNamespace() const {
3139 return const_cast<UsingDirectiveDecl*>(this)->getNominatedNamespace();
3140 }
3141
3142
3143
3144 DeclContext *getCommonAncestor() { return CommonAncestor; }
3145 const DeclContext *getCommonAncestor() const { return CommonAncestor; }
3146
3147
3148 SourceLocation getUsingLoc() const { return UsingLoc; }
3149
3150
3151
3152 SourceLocation getNamespaceKeyLocation() const { return NamespaceLoc; }
3153
3154
3155 SourceLocation getIdentLocation() const { return getLocation(); }
3156
3157 static UsingDirectiveDecl *Create(ASTContext &C, DeclContext *DC,
3158 SourceLocation UsingLoc,
3159 SourceLocation NamespaceLoc,
3160 NestedNameSpecifierLoc QualifierLoc,
3161 SourceLocation IdentLoc,
3162 NamedDecl *Nominated,
3163 DeclContext *CommonAncestor);
3164 static UsingDirectiveDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3165
3166 SourceRange getSourceRange() const override LLVM_READONLY {
3167 return SourceRange(UsingLoc, getLocation());
3168 }
3169
3170 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3171 static bool classofKind(Kind K) { return K == UsingDirective; }
3172 };
3173
3174
3175
3176
3177
3178
3179
3180
3181 class NamespaceAliasDecl : public NamedDecl,
3182 public Redeclarable<NamespaceAliasDecl> {
3183 friend class ASTDeclReader;
3184
3185
3186 SourceLocation NamespaceLoc;
3187
3188
3189
3190
3191 SourceLocation IdentLoc;
3192
3193
3194 NestedNameSpecifierLoc QualifierLoc;
3195
3196
3197
3198 NamedDecl *Namespace;
3199
3200 NamespaceAliasDecl(ASTContext &C, DeclContext *DC,
3201 SourceLocation NamespaceLoc, SourceLocation AliasLoc,
3202 IdentifierInfo *Alias, NestedNameSpecifierLoc QualifierLoc,
3203 SourceLocation IdentLoc, NamedDecl *Namespace)
3204 : NamedDecl(NamespaceAlias, DC, AliasLoc, Alias), redeclarable_base(C),
3205 NamespaceLoc(NamespaceLoc), IdentLoc(IdentLoc),
3206 QualifierLoc(QualifierLoc), Namespace(Namespace) {}
3207
3208 void anchor() override;
3209
3210 using redeclarable_base = Redeclarable<NamespaceAliasDecl>;
3211
3212 NamespaceAliasDecl *getNextRedeclarationImpl() override;
3213 NamespaceAliasDecl *getPreviousDeclImpl() override;
3214 NamespaceAliasDecl *getMostRecentDeclImpl() override;
3215
3216 public:
3217 static NamespaceAliasDecl *Create(ASTContext &C, DeclContext *DC,
3218 SourceLocation NamespaceLoc,
3219 SourceLocation AliasLoc,
3220 IdentifierInfo *Alias,
3221 NestedNameSpecifierLoc QualifierLoc,
3222 SourceLocation IdentLoc,
3223 NamedDecl *Namespace);
3224
3225 static NamespaceAliasDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3226
3227 using redecl_range = redeclarable_base::redecl_range;
3228 using redecl_iterator = redeclarable_base::redecl_iterator;
3229
3230 using redeclarable_base::redecls_begin;
3231 using redeclarable_base::redecls_end;
3232 using redeclarable_base::redecls;
3233 using redeclarable_base::getPreviousDecl;
3234 using redeclarable_base::getMostRecentDecl;
3235
3236 NamespaceAliasDecl *getCanonicalDecl() override {
3237 return getFirstDecl();
3238 }
3239 const NamespaceAliasDecl *getCanonicalDecl() const {
3240 return getFirstDecl();
3241 }
3242
3243
3244
3245 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3246
3247
3248
3249 NestedNameSpecifier *getQualifier() const {
3250 return QualifierLoc.getNestedNameSpecifier();
3251 }
3252
3253
3254 NamespaceDecl *getNamespace() {
3255 if (auto *AD = dyn_cast<NamespaceAliasDecl>(Namespace))
3256 return AD->getNamespace();
3257
3258 return cast<NamespaceDecl>(Namespace);
3259 }
3260
3261 const NamespaceDecl *getNamespace() const {
3262 return const_cast<NamespaceAliasDecl *>(this)->getNamespace();
3263 }
3264
3265
3266
3267 SourceLocation getAliasLoc() const { return getLocation(); }
3268
3269
3270 SourceLocation getNamespaceLoc() const { return NamespaceLoc; }
3271
3272
3273 SourceLocation getTargetNameLoc() const { return IdentLoc; }
3274
3275
3276
3277 NamedDecl *getAliasedNamespace() const { return Namespace; }
3278
3279 SourceRange getSourceRange() const override LLVM_READONLY {
3280 return SourceRange(NamespaceLoc, IdentLoc);
3281 }
3282
3283 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3284 static bool classofKind(Kind K) { return K == NamespaceAlias; }
3285 };
3286
3287
3288
3289 class LifetimeExtendedTemporaryDecl final
3290 : public Decl,
3291 public Mergeable<LifetimeExtendedTemporaryDecl> {
3292 friend class MaterializeTemporaryExpr;
3293 friend class ASTDeclReader;
3294
3295 Stmt *ExprWithTemporary = nullptr;
3296
3297
3298
3299 ValueDecl *ExtendingDecl = nullptr;
3300 unsigned ManglingNumber;
3301
3302 mutable APValue *Value = nullptr;
3303
3304 virtual void anchor();
3305
3306 LifetimeExtendedTemporaryDecl(Expr *Temp, ValueDecl *EDecl, unsigned Mangling)
3307 : Decl(Decl::LifetimeExtendedTemporary, EDecl->getDeclContext(),
3308 EDecl->getLocation()),
3309 ExprWithTemporary(Temp), ExtendingDecl(EDecl),
3310 ManglingNumber(Mangling) {}
3311
3312 LifetimeExtendedTemporaryDecl(EmptyShell)
3313 : Decl(Decl::LifetimeExtendedTemporary, EmptyShell{}) {}
3314
3315 public:
3316 static LifetimeExtendedTemporaryDecl *Create(Expr *Temp, ValueDecl *EDec,
3317 unsigned Mangling) {
3318 return new (EDec->getASTContext(), EDec->getDeclContext())
3319 LifetimeExtendedTemporaryDecl(Temp, EDec, Mangling);
3320 }
3321 static LifetimeExtendedTemporaryDecl *CreateDeserialized(ASTContext &C,
3322 GlobalDeclID ID) {
3323 return new (C, ID) LifetimeExtendedTemporaryDecl(EmptyShell{});
3324 }
3325
3326 ValueDecl *getExtendingDecl() { return ExtendingDecl; }
3327 const ValueDecl *getExtendingDecl() const { return ExtendingDecl; }
3328
3329
3330 StorageDuration getStorageDuration() const;
3331
3332
3333
3334
3335
3336
3337 Expr *getTemporaryExpr() { return cast<Expr>(ExprWithTemporary); }
3338 const Expr *getTemporaryExpr() const { return cast<Expr>(ExprWithTemporary); }
3339
3340 unsigned getManglingNumber() const { return ManglingNumber; }
3341
3342
3343
3344 APValue *getOrCreateValue(bool MayCreate) const;
3345
3346 APValue *getValue() const { return Value; }
3347
3348
3349 Stmt::child_range childrenExpr() {
3350 return Stmt::child_range(&ExprWithTemporary, &ExprWithTemporary + 1);
3351 }
3352
3353 Stmt::const_child_range childrenExpr() const {
3354 return Stmt::const_child_range(&ExprWithTemporary, &ExprWithTemporary + 1);
3355 }
3356
3357 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3358 static bool classofKind(Kind K) {
3359 return K == Decl::LifetimeExtendedTemporary;
3360 }
3361 };
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382 class UsingShadowDecl : public NamedDecl, public Redeclarable<UsingShadowDecl> {
3383 friend class BaseUsingDecl;
3384
3385
3386 NamedDecl *Underlying = nullptr;
3387
3388
3389
3390 NamedDecl *UsingOrNextShadow = nullptr;
3391
3392 void anchor() override;
3393
3394 using redeclarable_base = Redeclarable<UsingShadowDecl>;
3395
3396 UsingShadowDecl *getNextRedeclarationImpl() override {
3397 return getNextRedeclaration();
3398 }
3399
3400 UsingShadowDecl *getPreviousDeclImpl() override {
3401 return getPreviousDecl();
3402 }
3403
3404 UsingShadowDecl *getMostRecentDeclImpl() override {
3405 return getMostRecentDecl();
3406 }
3407
3408 protected:
3409 UsingShadowDecl(Kind K, ASTContext &C, DeclContext *DC, SourceLocation Loc,
3410 DeclarationName Name, BaseUsingDecl *Introducer,
3411 NamedDecl *Target);
3412 UsingShadowDecl(Kind K, ASTContext &C, EmptyShell);
3413
3414 public:
3415 friend class ASTDeclReader;
3416 friend class ASTDeclWriter;
3417
3418 static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
3419 SourceLocation Loc, DeclarationName Name,
3420 BaseUsingDecl *Introducer, NamedDecl *Target) {
3421 return new (C, DC)
3422 UsingShadowDecl(UsingShadow, C, DC, Loc, Name, Introducer, Target);
3423 }
3424
3425 static UsingShadowDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3426
3427 using redecl_range = redeclarable_base::redecl_range;
3428 using redecl_iterator = redeclarable_base::redecl_iterator;
3429
3430 using redeclarable_base::redecls_begin;
3431 using redeclarable_base::redecls_end;
3432 using redeclarable_base::redecls;
3433 using redeclarable_base::getPreviousDecl;
3434 using redeclarable_base::getMostRecentDecl;
3435 using redeclarable_base::isFirstDecl;
3436
3437 UsingShadowDecl *getCanonicalDecl() override {
3438 return getFirstDecl();
3439 }
3440 const UsingShadowDecl *getCanonicalDecl() const {
3441 return getFirstDecl();
3442 }
3443
3444
3445
3446 NamedDecl *getTargetDecl() const { return Underlying; }
3447
3448
3449
3450 void setTargetDecl(NamedDecl *ND) {
3451 assert(ND && "Target decl is null!");
3452 Underlying = ND;
3453
3454
3455 IdentifierNamespace =
3456 ND->getIdentifierNamespace() &
3457 ~(IDNS_OrdinaryFriend | IDNS_TagFriend | IDNS_LocalExtern);
3458 }
3459
3460
3461
3462 BaseUsingDecl *getIntroducer() const;
3463
3464
3465
3466 UsingShadowDecl *getNextUsingShadowDecl() const {
3467 return dyn_cast_or_null<UsingShadowDecl>(UsingOrNextShadow);
3468 }
3469
3470 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3471 static bool classofKind(Kind K) {
3472 return K == Decl::UsingShadow || K == Decl::ConstructorUsingShadow;
3473 }
3474 };
3475
3476
3477
3478
3479 class BaseUsingDecl : public NamedDecl {
3480
3481
3482
3483
3484
3485 llvm::PointerIntPair<UsingShadowDecl *, 1, bool> FirstUsingShadow;
3486
3487 protected:
3488 BaseUsingDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
3489 : NamedDecl(DK, DC, L, N), FirstUsingShadow(nullptr, false) {}
3490
3491 private:
3492 void anchor() override;
3493
3494 protected:
3495
3496 bool getShadowFlag() const { return FirstUsingShadow.getInt(); }
3497
3498
3499 void setShadowFlag(bool V) { FirstUsingShadow.setInt(V); }
3500
3501 public:
3502 friend class ASTDeclReader;
3503 friend class ASTDeclWriter;
3504
3505
3506
3507 class shadow_iterator {
3508
3509 UsingShadowDecl *Current = nullptr;
3510
3511 public:
3512 using value_type = UsingShadowDecl *;
3513 using reference = UsingShadowDecl *;
3514 using pointer = UsingShadowDecl *;
3515 using iterator_category = std::forward_iterator_tag;
3516 using difference_type = std::ptrdiff_t;
3517
3518 shadow_iterator() = default;
3519 explicit shadow_iterator(UsingShadowDecl *C) : Current(C) {}
3520
3521 reference operator*() const { return Current; }
3522 pointer operator->() const { return Current; }
3523
3524 shadow_iterator &operator++() {
3525 Current = Current->getNextUsingShadowDecl();
3526 return *this;
3527 }
3528
3529 shadow_iterator operator++(int) {
3530 shadow_iterator tmp(*this);
3531 ++(*this);
3532 return tmp;
3533 }
3534
3535 friend bool operator==(shadow_iterator x, shadow_iterator y) {
3536 return x.Current == y.Current;
3537 }
3538 friend bool operator!=(shadow_iterator x, shadow_iterator y) {
3539 return x.Current != y.Current;
3540 }
3541 };
3542
3543 using shadow_range = llvm::iterator_range<shadow_iterator>;
3544
3545 shadow_range shadows() const {
3546 return shadow_range(shadow_begin(), shadow_end());
3547 }
3548
3549 shadow_iterator shadow_begin() const {
3550 return shadow_iterator(FirstUsingShadow.getPointer());
3551 }
3552
3553 shadow_iterator shadow_end() const { return shadow_iterator(); }
3554
3555
3556
3557 unsigned shadow_size() const {
3558 return std::distance(shadow_begin(), shadow_end());
3559 }
3560
3561 void addShadowDecl(UsingShadowDecl *S);
3562 void removeShadowDecl(UsingShadowDecl *S);
3563
3564 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3565 static bool classofKind(Kind K) { return K == Using || K == UsingEnum; }
3566 };
3567
3568
3569
3570
3571
3572
3573
3574 class UsingDecl : public BaseUsingDecl, public Mergeable<UsingDecl> {
3575
3576 SourceLocation UsingLocation;
3577
3578
3579 NestedNameSpecifierLoc QualifierLoc;
3580
3581
3582
3583 DeclarationNameLoc DNLoc;
3584
3585 UsingDecl(DeclContext *DC, SourceLocation UL,
3586 NestedNameSpecifierLoc QualifierLoc,
3587 const DeclarationNameInfo &NameInfo, bool HasTypenameKeyword)
3588 : BaseUsingDecl(Using, DC, NameInfo.getLoc(), NameInfo.getName()),
3589 UsingLocation(UL), QualifierLoc(QualifierLoc),
3590 DNLoc(NameInfo.getInfo()) {
3591 setShadowFlag(HasTypenameKeyword);
3592 }
3593
3594 void anchor() override;
3595
3596 public:
3597 friend class ASTDeclReader;
3598 friend class ASTDeclWriter;
3599
3600
3601 SourceLocation getUsingLoc() const { return UsingLocation; }
3602
3603
3604 void setUsingLoc(SourceLocation L) { UsingLocation = L; }
3605
3606
3607
3608 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3609
3610
3611 NestedNameSpecifier *getQualifier() const {
3612 return QualifierLoc.getNestedNameSpecifier();
3613 }
3614
3615 DeclarationNameInfo getNameInfo() const {
3616 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
3617 }
3618
3619
3620 bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
3621
3622
3623 bool hasTypename() const { return getShadowFlag(); }
3624
3625
3626 void setTypename(bool TN) { setShadowFlag(TN); }
3627
3628 static UsingDecl *Create(ASTContext &C, DeclContext *DC,
3629 SourceLocation UsingL,
3630 NestedNameSpecifierLoc QualifierLoc,
3631 const DeclarationNameInfo &NameInfo,
3632 bool HasTypenameKeyword);
3633
3634 static UsingDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3635
3636 SourceRange getSourceRange() const override LLVM_READONLY;
3637
3638
3639 UsingDecl *getCanonicalDecl() override {
3640 return cast<UsingDecl>(getFirstDecl());
3641 }
3642 const UsingDecl *getCanonicalDecl() const {
3643 return cast<UsingDecl>(getFirstDecl());
3644 }
3645
3646 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3647 static bool classofKind(Kind K) { return K == Using; }
3648 };
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660 class ConstructorUsingShadowDecl final : public UsingShadowDecl {
3661
3662
3663
3664 ConstructorUsingShadowDecl *NominatedBaseClassShadowDecl = nullptr;
3665
3666
3667
3668
3669
3670 ConstructorUsingShadowDecl *ConstructedBaseClassShadowDecl = nullptr;
3671
3672
3673
3674
3675 LLVM_PREFERRED_TYPE(bool)
3676 unsigned IsVirtual : 1;
3677
3678 ConstructorUsingShadowDecl(ASTContext &C, DeclContext *DC, SourceLocation Loc,
3679 UsingDecl *Using, NamedDecl *Target,
3680 bool TargetInVirtualBase)
3681 : UsingShadowDecl(ConstructorUsingShadow, C, DC, Loc,
3682 Using->getDeclName(), Using,
3683 Target->getUnderlyingDecl()),
3684 NominatedBaseClassShadowDecl(
3685 dyn_cast<ConstructorUsingShadowDecl>(Target)),
3686 ConstructedBaseClassShadowDecl(NominatedBaseClassShadowDecl),
3687 IsVirtual(TargetInVirtualBase) {
3688
3689
3690
3691 if (NominatedBaseClassShadowDecl &&
3692 NominatedBaseClassShadowDecl->constructsVirtualBase()) {
3693 ConstructedBaseClassShadowDecl =
3694 NominatedBaseClassShadowDecl->ConstructedBaseClassShadowDecl;
3695 IsVirtual = true;
3696 }
3697 }
3698
3699 ConstructorUsingShadowDecl(ASTContext &C, EmptyShell Empty)
3700 : UsingShadowDecl(ConstructorUsingShadow, C, Empty), IsVirtual(false) {}
3701
3702 void anchor() override;
3703
3704 public:
3705 friend class ASTDeclReader;
3706 friend class ASTDeclWriter;
3707
3708 static ConstructorUsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
3709 SourceLocation Loc,
3710 UsingDecl *Using, NamedDecl *Target,
3711 bool IsVirtual);
3712 static ConstructorUsingShadowDecl *CreateDeserialized(ASTContext &C,
3713 GlobalDeclID ID);
3714
3715
3716
3717 UsingDecl *getIntroducer() const {
3718 return cast<UsingDecl>(UsingShadowDecl::getIntroducer());
3719 }
3720
3721
3722
3723
3724 const CXXRecordDecl *getParent() const {
3725 return cast<CXXRecordDecl>(getDeclContext());
3726 }
3727 CXXRecordDecl *getParent() {
3728 return cast<CXXRecordDecl>(getDeclContext());
3729 }
3730
3731
3732
3733
3734
3735 ConstructorUsingShadowDecl *getNominatedBaseClassShadowDecl() const {
3736 return NominatedBaseClassShadowDecl;
3737 }
3738
3739
3740
3741 ConstructorUsingShadowDecl *getConstructedBaseClassShadowDecl() const {
3742 return ConstructedBaseClassShadowDecl;
3743 }
3744
3745
3746
3747 CXXRecordDecl *getNominatedBaseClass() const;
3748
3749
3750
3751 CXXRecordDecl *getConstructedBaseClass() const {
3752 return cast<CXXRecordDecl>((ConstructedBaseClassShadowDecl
3753 ? ConstructedBaseClassShadowDecl
3754 : getTargetDecl())
3755 ->getDeclContext());
3756 }
3757
3758
3759
3760 bool constructsVirtualBase() const {
3761 return IsVirtual;
3762 }
3763
3764 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3765 static bool classofKind(Kind K) { return K == ConstructorUsingShadow; }
3766 };
3767
3768
3769
3770
3771
3772
3773
3774
3775 class UsingEnumDecl : public BaseUsingDecl, public Mergeable<UsingEnumDecl> {
3776
3777 SourceLocation UsingLocation;
3778
3779 SourceLocation EnumLocation;
3780
3781 TypeSourceInfo *EnumType;
3782
3783 UsingEnumDecl(DeclContext *DC, DeclarationName DN, SourceLocation UL,
3784 SourceLocation EL, SourceLocation NL, TypeSourceInfo *EnumType)
3785 : BaseUsingDecl(UsingEnum, DC, NL, DN), UsingLocation(UL), EnumLocation(EL),
3786 EnumType(EnumType){}
3787
3788 void anchor() override;
3789
3790 public:
3791 friend class ASTDeclReader;
3792 friend class ASTDeclWriter;
3793
3794
3795 SourceLocation getUsingLoc() const { return UsingLocation; }
3796 void setUsingLoc(SourceLocation L) { UsingLocation = L; }
3797
3798
3799 SourceLocation getEnumLoc() const { return EnumLocation; }
3800 void setEnumLoc(SourceLocation L) { EnumLocation = L; }
3801 NestedNameSpecifier *getQualifier() const {
3802 return getQualifierLoc().getNestedNameSpecifier();
3803 }
3804 NestedNameSpecifierLoc getQualifierLoc() const {
3805 if (auto ETL = EnumType->getTypeLoc().getAs<ElaboratedTypeLoc>())
3806 return ETL.getQualifierLoc();
3807 return NestedNameSpecifierLoc();
3808 }
3809
3810 TypeLoc getEnumTypeLoc() const {
3811 return EnumType->getTypeLoc();
3812 }
3813 TypeSourceInfo *getEnumType() const {
3814 return EnumType;
3815 }
3816 void setEnumType(TypeSourceInfo *TSI) { EnumType = TSI; }
3817
3818 public:
3819 EnumDecl *getEnumDecl() const { return cast<EnumDecl>(EnumType->getType()->getAsTagDecl()); }
3820
3821 static UsingEnumDecl *Create(ASTContext &C, DeclContext *DC,
3822 SourceLocation UsingL, SourceLocation EnumL,
3823 SourceLocation NameL, TypeSourceInfo *EnumType);
3824
3825 static UsingEnumDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3826
3827 SourceRange getSourceRange() const override LLVM_READONLY;
3828
3829
3830 UsingEnumDecl *getCanonicalDecl() override {
3831 return cast<UsingEnumDecl>(getFirstDecl());
3832 }
3833 const UsingEnumDecl *getCanonicalDecl() const {
3834 return cast<UsingEnumDecl>(getFirstDecl());
3835 }
3836
3837 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3838 static bool classofKind(Kind K) { return K == UsingEnum; }
3839 };
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854 class UsingPackDecl final
3855 : public NamedDecl, public Mergeable<UsingPackDecl>,
3856 private llvm::TrailingObjects<UsingPackDecl, NamedDecl *> {
3857
3858
3859 NamedDecl *InstantiatedFrom;
3860
3861
3862 unsigned NumExpansions;
3863
3864 UsingPackDecl(DeclContext *DC, NamedDecl *InstantiatedFrom,
3865 ArrayRef<NamedDecl *> UsingDecls)
3866 : NamedDecl(UsingPack, DC,
3867 InstantiatedFrom ? InstantiatedFrom->getLocation()
3868 : SourceLocation(),
3869 InstantiatedFrom ? InstantiatedFrom->getDeclName()
3870 : DeclarationName()),
3871 InstantiatedFrom(InstantiatedFrom), NumExpansions(UsingDecls.size()) {
3872 std::uninitialized_copy(UsingDecls.begin(), UsingDecls.end(),
3873 getTrailingObjects<NamedDecl *>());
3874 }
3875
3876 void anchor() override;
3877
3878 public:
3879 friend class ASTDeclReader;
3880 friend class ASTDeclWriter;
3881 friend TrailingObjects;
3882
3883
3884
3885
3886 NamedDecl *getInstantiatedFromUsingDecl() const { return InstantiatedFrom; }
3887
3888
3889
3890 ArrayRef<NamedDecl *> expansions() const {
3891 return llvm::ArrayRef(getTrailingObjects<NamedDecl *>(), NumExpansions);
3892 }
3893
3894 static UsingPackDecl *Create(ASTContext &C, DeclContext *DC,
3895 NamedDecl *InstantiatedFrom,
3896 ArrayRef<NamedDecl *> UsingDecls);
3897
3898 static UsingPackDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
3899 unsigned NumExpansions);
3900
3901 SourceRange getSourceRange() const override LLVM_READONLY {
3902 return InstantiatedFrom->getSourceRange();
3903 }
3904
3905 UsingPackDecl *getCanonicalDecl() override { return getFirstDecl(); }
3906 const UsingPackDecl *getCanonicalDecl() const { return getFirstDecl(); }
3907
3908 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3909 static bool classofKind(Kind K) { return K == UsingPack; }
3910 };
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923 class UnresolvedUsingValueDecl : public ValueDecl,
3924 public Mergeable<UnresolvedUsingValueDecl> {
3925
3926 SourceLocation UsingLocation;
3927
3928
3929 SourceLocation EllipsisLoc;
3930
3931
3932 NestedNameSpecifierLoc QualifierLoc;
3933
3934
3935
3936 DeclarationNameLoc DNLoc;
3937
3938 UnresolvedUsingValueDecl(DeclContext *DC, QualType Ty,
3939 SourceLocation UsingLoc,
3940 NestedNameSpecifierLoc QualifierLoc,
3941 const DeclarationNameInfo &NameInfo,
3942 SourceLocation EllipsisLoc)
3943 : ValueDecl(UnresolvedUsingValue, DC,
3944 NameInfo.getLoc(), NameInfo.getName(), Ty),
3945 UsingLocation(UsingLoc), EllipsisLoc(EllipsisLoc),
3946 QualifierLoc(QualifierLoc), DNLoc(NameInfo.getInfo()) {}
3947
3948 void anchor() override;
3949
3950 public:
3951 friend class ASTDeclReader;
3952 friend class ASTDeclWriter;
3953
3954
3955 SourceLocation getUsingLoc() const { return UsingLocation; }
3956
3957
3958 void setUsingLoc(SourceLocation L) { UsingLocation = L; }
3959
3960
3961 bool isAccessDeclaration() const { return UsingLocation.isInvalid(); }
3962
3963
3964
3965 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
3966
3967
3968 NestedNameSpecifier *getQualifier() const {
3969 return QualifierLoc.getNestedNameSpecifier();
3970 }
3971
3972 DeclarationNameInfo getNameInfo() const {
3973 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
3974 }
3975
3976
3977 bool isPackExpansion() const {
3978 return EllipsisLoc.isValid();
3979 }
3980
3981
3982 SourceLocation getEllipsisLoc() const {
3983 return EllipsisLoc;
3984 }
3985
3986 static UnresolvedUsingValueDecl *
3987 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
3988 NestedNameSpecifierLoc QualifierLoc,
3989 const DeclarationNameInfo &NameInfo, SourceLocation EllipsisLoc);
3990
3991 static UnresolvedUsingValueDecl *CreateDeserialized(ASTContext &C,
3992 GlobalDeclID ID);
3993
3994 SourceRange getSourceRange() const override LLVM_READONLY;
3995
3996
3997 UnresolvedUsingValueDecl *getCanonicalDecl() override {
3998 return getFirstDecl();
3999 }
4000 const UnresolvedUsingValueDecl *getCanonicalDecl() const {
4001 return getFirstDecl();
4002 }
4003
4004 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4005 static bool classofKind(Kind K) { return K == UnresolvedUsingValue; }
4006 };
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019 class UnresolvedUsingTypenameDecl
4020 : public TypeDecl,
4021 public Mergeable<UnresolvedUsingTypenameDecl> {
4022 friend class ASTDeclReader;
4023
4024
4025 SourceLocation TypenameLocation;
4026
4027
4028 SourceLocation EllipsisLoc;
4029
4030
4031 NestedNameSpecifierLoc QualifierLoc;
4032
4033 UnresolvedUsingTypenameDecl(DeclContext *DC, SourceLocation UsingLoc,
4034 SourceLocation TypenameLoc,
4035 NestedNameSpecifierLoc QualifierLoc,
4036 SourceLocation TargetNameLoc,
4037 IdentifierInfo *TargetName,
4038 SourceLocation EllipsisLoc)
4039 : TypeDecl(UnresolvedUsingTypename, DC, TargetNameLoc, TargetName,
4040 UsingLoc),
4041 TypenameLocation(TypenameLoc), EllipsisLoc(EllipsisLoc),
4042 QualifierLoc(QualifierLoc) {}
4043
4044 void anchor() override;
4045
4046 public:
4047
4048 SourceLocation getUsingLoc() const { return getBeginLoc(); }
4049
4050
4051 SourceLocation getTypenameLoc() const { return TypenameLocation; }
4052
4053
4054
4055 NestedNameSpecifierLoc getQualifierLoc() const { return QualifierLoc; }
4056
4057
4058 NestedNameSpecifier *getQualifier() const {
4059 return QualifierLoc.getNestedNameSpecifier();
4060 }
4061
4062 DeclarationNameInfo getNameInfo() const {
4063 return DeclarationNameInfo(getDeclName(), getLocation());
4064 }
4065
4066
4067 bool isPackExpansion() const {
4068 return EllipsisLoc.isValid();
4069 }
4070
4071
4072 SourceLocation getEllipsisLoc() const {
4073 return EllipsisLoc;
4074 }
4075
4076 static UnresolvedUsingTypenameDecl *
4077 Create(ASTContext &C, DeclContext *DC, SourceLocation UsingLoc,
4078 SourceLocation TypenameLoc, NestedNameSpecifierLoc QualifierLoc,
4079 SourceLocation TargetNameLoc, DeclarationName TargetName,
4080 SourceLocation EllipsisLoc);
4081
4082 static UnresolvedUsingTypenameDecl *CreateDeserialized(ASTContext &C,
4083 GlobalDeclID ID);
4084
4085
4086 UnresolvedUsingTypenameDecl *getCanonicalDecl() override {
4087 return getFirstDecl();
4088 }
4089 const UnresolvedUsingTypenameDecl *getCanonicalDecl() const {
4090 return getFirstDecl();
4091 }
4092
4093 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4094 static bool classofKind(Kind K) { return K == UnresolvedUsingTypename; }
4095 };
4096
4097
4098
4099
4100
4101
4102 class UnresolvedUsingIfExistsDecl final : public NamedDecl {
4103 UnresolvedUsingIfExistsDecl(DeclContext *DC, SourceLocation Loc,
4104 DeclarationName Name);
4105
4106 void anchor() override;
4107
4108 public:
4109 static UnresolvedUsingIfExistsDecl *Create(ASTContext &Ctx, DeclContext *DC,
4110 SourceLocation Loc,
4111 DeclarationName Name);
4112 static UnresolvedUsingIfExistsDecl *CreateDeserialized(ASTContext &Ctx,
4113 GlobalDeclID ID);
4114
4115 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4116 static bool classofKind(Kind K) { return K == Decl::UnresolvedUsingIfExists; }
4117 };
4118
4119
4120 class StaticAssertDecl : public Decl {
4121 llvm::PointerIntPair<Expr *, 1, bool> AssertExprAndFailed;
4122 Expr *Message;
4123 SourceLocation RParenLoc;
4124
4125 StaticAssertDecl(DeclContext *DC, SourceLocation StaticAssertLoc,
4126 Expr *AssertExpr, Expr *Message, SourceLocation RParenLoc,
4127 bool Failed)
4128 : Decl(StaticAssert, DC, StaticAssertLoc),
4129 AssertExprAndFailed(AssertExpr, Failed), Message(Message),
4130 RParenLoc(RParenLoc) {}
4131
4132 virtual void anchor();
4133
4134 public:
4135 friend class ASTDeclReader;
4136
4137 static StaticAssertDecl *Create(ASTContext &C, DeclContext *DC,
4138 SourceLocation StaticAssertLoc,
4139 Expr *AssertExpr, Expr *Message,
4140 SourceLocation RParenLoc, bool Failed);
4141 static StaticAssertDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
4142
4143 Expr *getAssertExpr() { return AssertExprAndFailed.getPointer(); }
4144 const Expr *getAssertExpr() const { return AssertExprAndFailed.getPointer(); }
4145
4146 Expr *getMessage() { return Message; }
4147 const Expr *getMessage() const { return Message; }
4148
4149 bool isFailed() const { return AssertExprAndFailed.getInt(); }
4150
4151 SourceLocation getRParenLoc() const { return RParenLoc; }
4152
4153 SourceRange getSourceRange() const override LLVM_READONLY {
4154 return SourceRange(getLocation(), getRParenLoc());
4155 }
4156
4157 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4158 static bool classofKind(Kind K) { return K == StaticAssert; }
4159 };
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169 class BindingDecl : public ValueDecl {
4170
4171 ValueDecl *Decomp;
4172
4173
4174
4175
4176 Expr *Binding = nullptr;
4177
4178 BindingDecl(DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id)
4179 : ValueDecl(Decl::Binding, DC, IdLoc, Id, QualType()) {}
4180
4181 void anchor() override;
4182
4183 public:
4184 friend class ASTDeclReader;
4185
4186 static BindingDecl *Create(ASTContext &C, DeclContext *DC,
4187 SourceLocation IdLoc, IdentifierInfo *Id);
4188 static BindingDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
4189
4190
4191
4192
4193 Expr *getBinding() const { return Binding; }
4194
4195
4196
4197 ValueDecl *getDecomposedDecl() const { return Decomp; }
4198
4199
4200
4201 VarDecl *getHoldingVar() const;
4202
4203
4204
4205
4206 void setBinding(QualType DeclaredType, Expr *Binding) {
4207 setType(DeclaredType);
4208 this->Binding = Binding;
4209 }
4210
4211
4212 void setDecomposedDecl(ValueDecl *Decomposed) { Decomp = Decomposed; }
4213
4214 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4215 static bool classofKind(Kind K) { return K == Decl::Binding; }
4216 };
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226 class DecompositionDecl final
4227 : public VarDecl,
4228 private llvm::TrailingObjects<DecompositionDecl, BindingDecl *> {
4229
4230 unsigned NumBindings;
4231
4232 DecompositionDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
4233 SourceLocation LSquareLoc, QualType T,
4234 TypeSourceInfo *TInfo, StorageClass SC,
4235 ArrayRef<BindingDecl *> Bindings)
4236 : VarDecl(Decomposition, C, DC, StartLoc, LSquareLoc, nullptr, T, TInfo,
4237 SC),
4238 NumBindings(Bindings.size()) {
4239 std::uninitialized_copy(Bindings.begin(), Bindings.end(),
4240 getTrailingObjects<BindingDecl *>());
4241 for (auto *B : Bindings)
4242 B->setDecomposedDecl(this);
4243 }
4244
4245 void anchor() override;
4246
4247 public:
4248 friend class ASTDeclReader;
4249 friend TrailingObjects;
4250
4251 static DecompositionDecl *Create(ASTContext &C, DeclContext *DC,
4252 SourceLocation StartLoc,
4253 SourceLocation LSquareLoc,
4254 QualType T, TypeSourceInfo *TInfo,
4255 StorageClass S,
4256 ArrayRef<BindingDecl *> Bindings);
4257 static DecompositionDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
4258 unsigned NumBindings);
4259
4260 ArrayRef<BindingDecl *> bindings() const {
4261 return llvm::ArrayRef(getTrailingObjects<BindingDecl *>(), NumBindings);
4262 }
4263
4264 void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
4265
4266 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4267 static bool classofKind(Kind K) { return K == Decomposition; }
4268 };
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297 class MSPropertyDecl : public DeclaratorDecl {
4298 IdentifierInfo *GetterId, *SetterId;
4299
4300 MSPropertyDecl(DeclContext *DC, SourceLocation L, DeclarationName N,
4301 QualType T, TypeSourceInfo *TInfo, SourceLocation StartL,
4302 IdentifierInfo *Getter, IdentifierInfo *Setter)
4303 : DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL),
4304 GetterId(Getter), SetterId(Setter) {}
4305
4306 void anchor() override;
4307 public:
4308 friend class ASTDeclReader;
4309
4310 static MSPropertyDecl *Create(ASTContext &C, DeclContext *DC,
4311 SourceLocation L, DeclarationName N, QualType T,
4312 TypeSourceInfo *TInfo, SourceLocation StartL,
4313 IdentifierInfo *Getter, IdentifierInfo *Setter);
4314 static MSPropertyDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
4315
4316 static bool classof(const Decl *D) { return D->getKind() == MSProperty; }
4317
4318 bool hasGetter() const { return GetterId != nullptr; }
4319 IdentifierInfo* getGetterId() const { return GetterId; }
4320 bool hasSetter() const { return SetterId != nullptr; }
4321 IdentifierInfo* getSetterId() const { return SetterId; }
4322 };
4323
4324
4325
4326 struct MSGuidDeclParts {
4327
4328 uint32_t Part1;
4329
4330 uint16_t Part2;
4331
4332 uint16_t Part3;
4333
4334 uint8_t Part4And5[8];
4335
4336 uint64_t getPart4And5AsUint64() const {
4337 uint64_t Val;
4338 memcpy(&Val, &Part4And5, sizeof(Part4And5));
4339 return Val;
4340 }
4341 };
4342
4343
4344
4345
4346
4347
4348
4349 class MSGuidDecl : public ValueDecl,
4350 public Mergeable<MSGuidDecl>,
4351 public llvm::FoldingSetNode {
4352 public:
4353 using Parts = MSGuidDeclParts;
4354
4355 private:
4356
4357 Parts PartVal;
4358
4359
4360
4361 mutable APValue APVal;
4362
4363 void anchor() override;
4364
4365 MSGuidDecl(DeclContext *DC, QualType T, Parts P);
4366
4367 static MSGuidDecl *Create(const ASTContext &C, QualType T, Parts P);
4368 static MSGuidDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
4369
4370
4371 friend class ASTContext;
4372 friend class ASTReader;
4373 friend class ASTDeclReader;
4374
4375 public:
4376
4377 void printName(llvm::raw_ostream &OS,
4378 const PrintingPolicy &Policy) const override;
4379
4380
4381 Parts getParts() const { return PartVal; }
4382
4383
4384
4385
4386 APValue &getAsAPValue() const;
4387
4388 static void Profile(llvm::FoldingSetNodeID &ID, Parts P) {
4389 ID.AddInteger(P.Part1);
4390 ID.AddInteger(P.Part2);
4391 ID.AddInteger(P.Part3);
4392 ID.AddInteger(P.getPart4And5AsUint64());
4393 }
4394 void Profile(llvm::FoldingSetNodeID &ID) { Profile(ID, PartVal); }
4395
4396 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4397 static bool classofKind(Kind K) { return K == Decl::MSGuid; }
4398 };
4399
4400
4401
4402
4403
4404
4405
4406 class UnnamedGlobalConstantDecl : public ValueDecl,
4407 public Mergeable<UnnamedGlobalConstantDecl>,
4408 public llvm::FoldingSetNode {
4409
4410
4411 APValue Value;
4412
4413 void anchor() override;
4414
4415 UnnamedGlobalConstantDecl(const ASTContext &C, DeclContext *DC, QualType T,
4416 const APValue &Val);
4417
4418 static UnnamedGlobalConstantDecl *Create(const ASTContext &C, QualType T,
4419 const APValue &APVal);
4420 static UnnamedGlobalConstantDecl *CreateDeserialized(ASTContext &C,
4421 GlobalDeclID ID);
4422
4423
4424
4425 friend class ASTContext;
4426 friend class ASTReader;
4427 friend class ASTDeclReader;
4428
4429 public:
4430
4431 void printName(llvm::raw_ostream &OS,
4432 const PrintingPolicy &Policy) const override;
4433
4434 const APValue &getValue() const { return Value; }
4435
4436 static void Profile(llvm::FoldingSetNodeID &ID, QualType Ty,
4437 const APValue &APVal) {
4438 Ty.Profile(ID);
4439 APVal.Profile(ID);
4440 }
4441 void Profile(llvm::FoldingSetNodeID &ID) {
4442 Profile(ID, getType(), getValue());
4443 }
4444
4445 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4446 static bool classofKind(Kind K) { return K == Decl::UnnamedGlobalConstant; }
4447 };
4448
4449
4450
4451 const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
4452 AccessSpecifier AS);
4453
4454 }
4455
4456 #endif