File indexing completed on 2026-05-10 08:36:31
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef LLVM_CLANG_AST_DECL_H
0014 #define LLVM_CLANG_AST_DECL_H
0015
0016 #include "clang/AST/APNumericStorage.h"
0017 #include "clang/AST/APValue.h"
0018 #include "clang/AST/ASTContextAllocate.h"
0019 #include "clang/AST/DeclAccessPair.h"
0020 #include "clang/AST/DeclBase.h"
0021 #include "clang/AST/DeclarationName.h"
0022 #include "clang/AST/ExternalASTSource.h"
0023 #include "clang/AST/NestedNameSpecifier.h"
0024 #include "clang/AST/Redeclarable.h"
0025 #include "clang/AST/Type.h"
0026 #include "clang/Basic/AddressSpaces.h"
0027 #include "clang/Basic/Diagnostic.h"
0028 #include "clang/Basic/IdentifierTable.h"
0029 #include "clang/Basic/LLVM.h"
0030 #include "clang/Basic/Linkage.h"
0031 #include "clang/Basic/OperatorKinds.h"
0032 #include "clang/Basic/PartialDiagnostic.h"
0033 #include "clang/Basic/PragmaKinds.h"
0034 #include "clang/Basic/SourceLocation.h"
0035 #include "clang/Basic/Specifiers.h"
0036 #include "clang/Basic/Visibility.h"
0037 #include "llvm/ADT/APSInt.h"
0038 #include "llvm/ADT/ArrayRef.h"
0039 #include "llvm/ADT/PointerIntPair.h"
0040 #include "llvm/ADT/PointerUnion.h"
0041 #include "llvm/ADT/StringRef.h"
0042 #include "llvm/ADT/iterator_range.h"
0043 #include "llvm/Support/Casting.h"
0044 #include "llvm/Support/Compiler.h"
0045 #include "llvm/Support/TrailingObjects.h"
0046 #include <cassert>
0047 #include <cstddef>
0048 #include <cstdint>
0049 #include <optional>
0050 #include <string>
0051 #include <utility>
0052
0053 namespace clang {
0054
0055 class ASTContext;
0056 struct ASTTemplateArgumentListInfo;
0057 class CompoundStmt;
0058 class DependentFunctionTemplateSpecializationInfo;
0059 class EnumDecl;
0060 class Expr;
0061 class FunctionTemplateDecl;
0062 class FunctionTemplateSpecializationInfo;
0063 class FunctionTypeLoc;
0064 class LabelStmt;
0065 class MemberSpecializationInfo;
0066 class Module;
0067 class NamespaceDecl;
0068 class ParmVarDecl;
0069 class RecordDecl;
0070 class Stmt;
0071 class StringLiteral;
0072 class TagDecl;
0073 class TemplateArgumentList;
0074 class TemplateArgumentListInfo;
0075 class TemplateParameterList;
0076 class TypeAliasTemplateDecl;
0077 class UnresolvedSetImpl;
0078 class VarTemplateDecl;
0079 enum class ImplicitParamKind;
0080
0081
0082 class TranslationUnitDecl : public Decl,
0083 public DeclContext,
0084 public Redeclarable<TranslationUnitDecl> {
0085 using redeclarable_base = Redeclarable<TranslationUnitDecl>;
0086
0087 TranslationUnitDecl *getNextRedeclarationImpl() override {
0088 return getNextRedeclaration();
0089 }
0090
0091 TranslationUnitDecl *getPreviousDeclImpl() override {
0092 return getPreviousDecl();
0093 }
0094
0095 TranslationUnitDecl *getMostRecentDeclImpl() override {
0096 return getMostRecentDecl();
0097 }
0098
0099 ASTContext &Ctx;
0100
0101
0102
0103 NamespaceDecl *AnonymousNamespace = nullptr;
0104
0105 explicit TranslationUnitDecl(ASTContext &ctx);
0106
0107 virtual void anchor();
0108
0109 public:
0110 using redecl_range = redeclarable_base::redecl_range;
0111 using redecl_iterator = redeclarable_base::redecl_iterator;
0112
0113 using redeclarable_base::getMostRecentDecl;
0114 using redeclarable_base::getPreviousDecl;
0115 using redeclarable_base::isFirstDecl;
0116 using redeclarable_base::redecls;
0117 using redeclarable_base::redecls_begin;
0118 using redeclarable_base::redecls_end;
0119
0120 ASTContext &getASTContext() const { return Ctx; }
0121
0122 NamespaceDecl *getAnonymousNamespace() const { return AnonymousNamespace; }
0123 void setAnonymousNamespace(NamespaceDecl *D);
0124
0125 static TranslationUnitDecl *Create(ASTContext &C);
0126
0127
0128 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
0129 static bool classofKind(Kind K) { return K == TranslationUnit; }
0130 static DeclContext *castToDeclContext(const TranslationUnitDecl *D) {
0131 return static_cast<DeclContext *>(const_cast<TranslationUnitDecl*>(D));
0132 }
0133 static TranslationUnitDecl *castFromDeclContext(const DeclContext *DC) {
0134 return static_cast<TranslationUnitDecl *>(const_cast<DeclContext*>(DC));
0135 }
0136
0137
0138 TranslationUnitDecl *getCanonicalDecl() override { return getFirstDecl(); }
0139 const TranslationUnitDecl *getCanonicalDecl() const { return getFirstDecl(); }
0140 };
0141
0142
0143
0144 class PragmaCommentDecl final
0145 : public Decl,
0146 private llvm::TrailingObjects<PragmaCommentDecl, char> {
0147 friend class ASTDeclReader;
0148 friend class ASTDeclWriter;
0149 friend TrailingObjects;
0150
0151 PragmaMSCommentKind CommentKind;
0152
0153 PragmaCommentDecl(TranslationUnitDecl *TU, SourceLocation CommentLoc,
0154 PragmaMSCommentKind CommentKind)
0155 : Decl(PragmaComment, TU, CommentLoc), CommentKind(CommentKind) {}
0156
0157 virtual void anchor();
0158
0159 public:
0160 static PragmaCommentDecl *Create(const ASTContext &C, TranslationUnitDecl *DC,
0161 SourceLocation CommentLoc,
0162 PragmaMSCommentKind CommentKind,
0163 StringRef Arg);
0164 static PragmaCommentDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
0165 unsigned ArgSize);
0166
0167 PragmaMSCommentKind getCommentKind() const { return CommentKind; }
0168
0169 StringRef getArg() const { return getTrailingObjects<char>(); }
0170
0171
0172 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
0173 static bool classofKind(Kind K) { return K == PragmaComment; }
0174 };
0175
0176
0177
0178 class PragmaDetectMismatchDecl final
0179 : public Decl,
0180 private llvm::TrailingObjects<PragmaDetectMismatchDecl, char> {
0181 friend class ASTDeclReader;
0182 friend class ASTDeclWriter;
0183 friend TrailingObjects;
0184
0185 size_t ValueStart;
0186
0187 PragmaDetectMismatchDecl(TranslationUnitDecl *TU, SourceLocation Loc,
0188 size_t ValueStart)
0189 : Decl(PragmaDetectMismatch, TU, Loc), ValueStart(ValueStart) {}
0190
0191 virtual void anchor();
0192
0193 public:
0194 static PragmaDetectMismatchDecl *Create(const ASTContext &C,
0195 TranslationUnitDecl *DC,
0196 SourceLocation Loc, StringRef Name,
0197 StringRef Value);
0198 static PragmaDetectMismatchDecl *
0199 CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NameValueSize);
0200
0201 StringRef getName() const { return getTrailingObjects<char>(); }
0202 StringRef getValue() const { return getTrailingObjects<char>() + ValueStart; }
0203
0204
0205 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
0206 static bool classofKind(Kind K) { return K == PragmaDetectMismatch; }
0207 };
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226 class ExternCContextDecl : public Decl, public DeclContext {
0227 explicit ExternCContextDecl(TranslationUnitDecl *TU)
0228 : Decl(ExternCContext, TU, SourceLocation()),
0229 DeclContext(ExternCContext) {}
0230
0231 virtual void anchor();
0232
0233 public:
0234 static ExternCContextDecl *Create(const ASTContext &C,
0235 TranslationUnitDecl *TU);
0236
0237
0238 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
0239 static bool classofKind(Kind K) { return K == ExternCContext; }
0240 static DeclContext *castToDeclContext(const ExternCContextDecl *D) {
0241 return static_cast<DeclContext *>(const_cast<ExternCContextDecl*>(D));
0242 }
0243 static ExternCContextDecl *castFromDeclContext(const DeclContext *DC) {
0244 return static_cast<ExternCContextDecl *>(const_cast<DeclContext*>(DC));
0245 }
0246 };
0247
0248
0249
0250
0251
0252
0253 class NamedDecl : public Decl {
0254
0255
0256
0257 DeclarationName Name;
0258
0259 virtual void anchor();
0260
0261 private:
0262 NamedDecl *getUnderlyingDeclImpl() LLVM_READONLY;
0263
0264 protected:
0265 NamedDecl(Kind DK, DeclContext *DC, SourceLocation L, DeclarationName N)
0266 : Decl(DK, DC, L), Name(N) {}
0267
0268 public:
0269
0270
0271
0272
0273
0274 IdentifierInfo *getIdentifier() const { return Name.getAsIdentifierInfo(); }
0275
0276
0277
0278
0279
0280 StringRef getName() const {
0281 assert(Name.isIdentifier() && "Name is not a simple identifier");
0282 return getIdentifier() ? getIdentifier()->getName() : "";
0283 }
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296 std::string getNameAsString() const { return Name.getAsString(); }
0297
0298
0299
0300 virtual void printName(raw_ostream &OS, const PrintingPolicy &Policy) const;
0301
0302 void printName(raw_ostream &OS) const;
0303
0304
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317
0318
0319 DeclarationName getDeclName() const { return Name; }
0320
0321
0322 void setDeclName(DeclarationName N) { Name = N; }
0323
0324
0325
0326
0327
0328
0329
0330
0331
0332 void printQualifiedName(raw_ostream &OS) const;
0333 void printQualifiedName(raw_ostream &OS, const PrintingPolicy &Policy) const;
0334
0335
0336
0337
0338
0339 void printNestedNameSpecifier(raw_ostream &OS) const;
0340 void printNestedNameSpecifier(raw_ostream &OS,
0341 const PrintingPolicy &Policy) const;
0342
0343
0344 std::string getQualifiedNameAsString() const;
0345
0346
0347
0348
0349
0350
0351
0352 virtual void getNameForDiagnostic(raw_ostream &OS,
0353 const PrintingPolicy &Policy,
0354 bool Qualified) const;
0355
0356
0357
0358
0359
0360
0361
0362
0363
0364
0365
0366 bool declarationReplaces(const NamedDecl *OldD,
0367 bool IsKnownNewer = true) const;
0368
0369
0370 bool hasLinkage() const;
0371
0372 using Decl::isModulePrivate;
0373 using Decl::setModulePrivate;
0374
0375
0376 bool isCXXClassMember() const {
0377 const DeclContext *DC = getDeclContext();
0378
0379
0380
0381
0382 if (isa<EnumDecl>(DC))
0383 DC = DC->getRedeclContext();
0384
0385 return DC->isRecord();
0386 }
0387
0388
0389
0390 bool isCXXInstanceMember() const;
0391
0392
0393
0394 ReservedIdentifierStatus isReserved(const LangOptions &LangOpts) const;
0395
0396
0397
0398
0399
0400
0401 Linkage getLinkageInternal() const;
0402
0403
0404
0405 Linkage getFormalLinkage() const;
0406
0407
0408 bool hasExternalFormalLinkage() const {
0409 return isExternalFormalLinkage(getLinkageInternal());
0410 }
0411
0412 bool isExternallyVisible() const {
0413 return clang::isExternallyVisible(getLinkageInternal());
0414 }
0415
0416
0417
0418 bool isExternallyDeclarable() const {
0419 return isExternallyVisible() && !getOwningModuleForLinkage();
0420 }
0421
0422
0423 Visibility getVisibility() const {
0424 return getLinkageAndVisibility().getVisibility();
0425 }
0426
0427
0428 LinkageInfo getLinkageAndVisibility() const;
0429
0430
0431 enum ExplicitVisibilityKind {
0432
0433
0434
0435 VisibilityForType,
0436
0437
0438
0439
0440 VisibilityForValue
0441 };
0442
0443
0444
0445 std::optional<Visibility>
0446 getExplicitVisibility(ExplicitVisibilityKind kind) const;
0447
0448
0449
0450 bool isLinkageValid() const;
0451
0452
0453
0454
0455
0456
0457
0458 bool hasLinkageBeenComputed() const {
0459 return hasCachedLinkage();
0460 }
0461
0462 bool isPlaceholderVar(const LangOptions &LangOpts) const;
0463
0464
0465
0466 NamedDecl *getUnderlyingDecl() {
0467
0468 if (this->getKind() != UsingShadow &&
0469 this->getKind() != ConstructorUsingShadow &&
0470 this->getKind() != ObjCCompatibleAlias &&
0471 this->getKind() != NamespaceAlias)
0472 return this;
0473
0474 return getUnderlyingDeclImpl();
0475 }
0476 const NamedDecl *getUnderlyingDecl() const {
0477 return const_cast<NamedDecl*>(this)->getUnderlyingDecl();
0478 }
0479
0480 NamedDecl *getMostRecentDecl() {
0481 return cast<NamedDecl>(static_cast<Decl *>(this)->getMostRecentDecl());
0482 }
0483 const NamedDecl *getMostRecentDecl() const {
0484 return const_cast<NamedDecl*>(this)->getMostRecentDecl();
0485 }
0486
0487 ObjCStringFormatFamily getObjCFStringFormattingFamily() const;
0488
0489 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
0490 static bool classofKind(Kind K) { return K >= firstNamed && K <= lastNamed; }
0491 };
0492
0493 inline raw_ostream &operator<<(raw_ostream &OS, const NamedDecl &ND) {
0494 ND.printName(OS);
0495 return OS;
0496 }
0497
0498
0499
0500
0501
0502
0503 class LabelDecl : public NamedDecl {
0504 LabelStmt *TheStmt;
0505 StringRef MSAsmName;
0506 bool MSAsmNameResolved = false;
0507
0508
0509
0510
0511 SourceLocation LocStart;
0512
0513 LabelDecl(DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II,
0514 LabelStmt *S, SourceLocation StartL)
0515 : NamedDecl(Label, DC, IdentL, II), TheStmt(S), LocStart(StartL) {}
0516
0517 void anchor() override;
0518
0519 public:
0520 static LabelDecl *Create(ASTContext &C, DeclContext *DC,
0521 SourceLocation IdentL, IdentifierInfo *II);
0522 static LabelDecl *Create(ASTContext &C, DeclContext *DC,
0523 SourceLocation IdentL, IdentifierInfo *II,
0524 SourceLocation GnuLabelL);
0525 static LabelDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
0526
0527 LabelStmt *getStmt() const { return TheStmt; }
0528 void setStmt(LabelStmt *T) { TheStmt = T; }
0529
0530 bool isGnuLocal() const { return LocStart != getLocation(); }
0531 void setLocStart(SourceLocation L) { LocStart = L; }
0532
0533 SourceRange getSourceRange() const override LLVM_READONLY {
0534 return SourceRange(LocStart, getLocation());
0535 }
0536
0537 bool isMSAsmLabel() const { return !MSAsmName.empty(); }
0538 bool isResolvedMSAsmLabel() const { return isMSAsmLabel() && MSAsmNameResolved; }
0539 void setMSAsmLabel(StringRef Name);
0540 StringRef getMSAsmLabel() const { return MSAsmName; }
0541 void setMSAsmLabelResolved() { MSAsmNameResolved = true; }
0542
0543
0544 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
0545 static bool classofKind(Kind K) { return K == Label; }
0546 };
0547
0548
0549 class NamespaceDecl : public NamedDecl,
0550 public DeclContext,
0551 public Redeclarable<NamespaceDecl> {
0552
0553
0554 SourceLocation LocStart;
0555
0556
0557 SourceLocation RBraceLoc;
0558
0559
0560 NamespaceDecl *AnonymousNamespace = nullptr;
0561
0562 NamespaceDecl(ASTContext &C, DeclContext *DC, bool Inline,
0563 SourceLocation StartLoc, SourceLocation IdLoc,
0564 IdentifierInfo *Id, NamespaceDecl *PrevDecl, bool Nested);
0565
0566 using redeclarable_base = Redeclarable<NamespaceDecl>;
0567
0568 NamespaceDecl *getNextRedeclarationImpl() override;
0569 NamespaceDecl *getPreviousDeclImpl() override;
0570 NamespaceDecl *getMostRecentDeclImpl() override;
0571
0572 public:
0573 friend class ASTDeclReader;
0574 friend class ASTDeclWriter;
0575
0576 static NamespaceDecl *Create(ASTContext &C, DeclContext *DC, bool Inline,
0577 SourceLocation StartLoc, SourceLocation IdLoc,
0578 IdentifierInfo *Id, NamespaceDecl *PrevDecl,
0579 bool Nested);
0580
0581 static NamespaceDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
0582
0583 using redecl_range = redeclarable_base::redecl_range;
0584 using redecl_iterator = redeclarable_base::redecl_iterator;
0585
0586 using redeclarable_base::redecls_begin;
0587 using redeclarable_base::redecls_end;
0588 using redeclarable_base::redecls;
0589 using redeclarable_base::getPreviousDecl;
0590 using redeclarable_base::getMostRecentDecl;
0591 using redeclarable_base::isFirstDecl;
0592
0593
0594
0595
0596
0597
0598
0599
0600
0601
0602 bool isAnonymousNamespace() const {
0603 return !getIdentifier();
0604 }
0605
0606
0607 bool isInline() const { return NamespaceDeclBits.IsInline; }
0608
0609
0610 void setInline(bool Inline) { NamespaceDeclBits.IsInline = Inline; }
0611
0612
0613
0614
0615
0616 bool isNested() const { return NamespaceDeclBits.IsNested; }
0617
0618
0619 void setNested(bool Nested) { NamespaceDeclBits.IsNested = Nested; }
0620
0621
0622 bool isRedundantInlineQualifierFor(DeclarationName Name) const {
0623 if (!isInline())
0624 return false;
0625 auto X = lookup(Name);
0626
0627
0628 auto Y = getParent()->getNonTransparentContext()->lookup(Name);
0629 return std::distance(X.begin(), X.end()) ==
0630 std::distance(Y.begin(), Y.end());
0631 }
0632
0633
0634 NamespaceDecl *getAnonymousNamespace() const {
0635 return getFirstDecl()->AnonymousNamespace;
0636 }
0637
0638 void setAnonymousNamespace(NamespaceDecl *D) {
0639 getFirstDecl()->AnonymousNamespace = D;
0640 }
0641
0642
0643 NamespaceDecl *getCanonicalDecl() override { return getFirstDecl(); }
0644 const NamespaceDecl *getCanonicalDecl() const { return getFirstDecl(); }
0645
0646 SourceRange getSourceRange() const override LLVM_READONLY {
0647 return SourceRange(LocStart, RBraceLoc);
0648 }
0649
0650 SourceLocation getBeginLoc() const LLVM_READONLY { return LocStart; }
0651 SourceLocation getRBraceLoc() const { return RBraceLoc; }
0652 void setLocStart(SourceLocation L) { LocStart = L; }
0653 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
0654
0655
0656 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
0657 static bool classofKind(Kind K) { return K == Namespace; }
0658 static DeclContext *castToDeclContext(const NamespaceDecl *D) {
0659 return static_cast<DeclContext *>(const_cast<NamespaceDecl*>(D));
0660 }
0661 static NamespaceDecl *castFromDeclContext(const DeclContext *DC) {
0662 return static_cast<NamespaceDecl *>(const_cast<DeclContext*>(DC));
0663 }
0664 };
0665
0666 class VarDecl;
0667
0668
0669
0670
0671 class ValueDecl : public NamedDecl {
0672 QualType DeclType;
0673
0674 void anchor() override;
0675
0676 protected:
0677 ValueDecl(Kind DK, DeclContext *DC, SourceLocation L,
0678 DeclarationName N, QualType T)
0679 : NamedDecl(DK, DC, L, N), DeclType(T) {}
0680
0681 public:
0682 QualType getType() const { return DeclType; }
0683 void setType(QualType newType) { DeclType = newType; }
0684
0685
0686
0687 bool isWeak() const;
0688
0689
0690
0691
0692 bool isInitCapture() const;
0693
0694
0695
0696 VarDecl *getPotentiallyDecomposedVarDecl();
0697 const VarDecl *getPotentiallyDecomposedVarDecl() const {
0698 return const_cast<ValueDecl *>(this)->getPotentiallyDecomposedVarDecl();
0699 }
0700
0701
0702 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
0703 static bool classofKind(Kind K) { return K >= firstValue && K <= lastValue; }
0704 };
0705
0706
0707
0708 struct QualifierInfo {
0709 NestedNameSpecifierLoc QualifierLoc;
0710
0711
0712
0713
0714
0715 unsigned NumTemplParamLists = 0;
0716
0717
0718
0719
0720
0721
0722 TemplateParameterList** TemplParamLists = nullptr;
0723
0724 QualifierInfo() = default;
0725 QualifierInfo(const QualifierInfo &) = delete;
0726 QualifierInfo& operator=(const QualifierInfo &) = delete;
0727
0728
0729 void setTemplateParameterListsInfo(ASTContext &Context,
0730 ArrayRef<TemplateParameterList *> TPLists);
0731 };
0732
0733
0734
0735 class DeclaratorDecl : public ValueDecl {
0736
0737
0738
0739 struct ExtInfo : public QualifierInfo {
0740 TypeSourceInfo *TInfo = nullptr;
0741 Expr *TrailingRequiresClause = nullptr;
0742 };
0743
0744 llvm::PointerUnion<TypeSourceInfo *, ExtInfo *> DeclInfo;
0745
0746
0747
0748 SourceLocation InnerLocStart;
0749
0750 bool hasExtInfo() const { return isa<ExtInfo *>(DeclInfo); }
0751 ExtInfo *getExtInfo() { return cast<ExtInfo *>(DeclInfo); }
0752 const ExtInfo *getExtInfo() const { return cast<ExtInfo *>(DeclInfo); }
0753
0754 protected:
0755 DeclaratorDecl(Kind DK, DeclContext *DC, SourceLocation L,
0756 DeclarationName N, QualType T, TypeSourceInfo *TInfo,
0757 SourceLocation StartL)
0758 : ValueDecl(DK, DC, L, N, T), DeclInfo(TInfo), InnerLocStart(StartL) {}
0759
0760 public:
0761 friend class ASTDeclReader;
0762 friend class ASTDeclWriter;
0763
0764 TypeSourceInfo *getTypeSourceInfo() const {
0765 return hasExtInfo() ? getExtInfo()->TInfo
0766 : cast<TypeSourceInfo *>(DeclInfo);
0767 }
0768
0769 void setTypeSourceInfo(TypeSourceInfo *TI) {
0770 if (hasExtInfo())
0771 getExtInfo()->TInfo = TI;
0772 else
0773 DeclInfo = TI;
0774 }
0775
0776
0777 SourceLocation getInnerLocStart() const { return InnerLocStart; }
0778 void setInnerLocStart(SourceLocation L) { InnerLocStart = L; }
0779
0780
0781
0782 SourceLocation getOuterLocStart() const;
0783
0784 SourceRange getSourceRange() const override LLVM_READONLY;
0785
0786 SourceLocation getBeginLoc() const LLVM_READONLY {
0787 return getOuterLocStart();
0788 }
0789
0790
0791
0792 NestedNameSpecifier *getQualifier() const {
0793 return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
0794 : nullptr;
0795 }
0796
0797
0798
0799
0800 NestedNameSpecifierLoc getQualifierLoc() const {
0801 return hasExtInfo() ? getExtInfo()->QualifierLoc
0802 : NestedNameSpecifierLoc();
0803 }
0804
0805 void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
0806
0807
0808
0809
0810 Expr *getTrailingRequiresClause() {
0811 return hasExtInfo() ? getExtInfo()->TrailingRequiresClause
0812 : nullptr;
0813 }
0814
0815 const Expr *getTrailingRequiresClause() const {
0816 return hasExtInfo() ? getExtInfo()->TrailingRequiresClause
0817 : nullptr;
0818 }
0819
0820 void setTrailingRequiresClause(Expr *TrailingRequiresClause);
0821
0822 unsigned getNumTemplateParameterLists() const {
0823 return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0;
0824 }
0825
0826 TemplateParameterList *getTemplateParameterList(unsigned index) const {
0827 assert(index < getNumTemplateParameterLists());
0828 return getExtInfo()->TemplParamLists[index];
0829 }
0830
0831 void setTemplateParameterListsInfo(ASTContext &Context,
0832 ArrayRef<TemplateParameterList *> TPLists);
0833
0834 SourceLocation getTypeSpecStartLoc() const;
0835 SourceLocation getTypeSpecEndLoc() const;
0836
0837
0838 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
0839 static bool classofKind(Kind K) {
0840 return K >= firstDeclarator && K <= lastDeclarator;
0841 }
0842 };
0843
0844
0845
0846
0847 struct EvaluatedStmt {
0848
0849 bool WasEvaluated : 1;
0850
0851
0852 bool IsEvaluating : 1;
0853
0854
0855
0856
0857
0858 bool HasConstantInitialization : 1;
0859
0860
0861
0862
0863
0864
0865 bool HasConstantDestruction : 1;
0866
0867
0868
0869 bool HasICEInit : 1;
0870 bool CheckedForICEInit : 1;
0871
0872 LazyDeclStmtPtr Value;
0873 APValue Evaluated;
0874
0875 EvaluatedStmt()
0876 : WasEvaluated(false), IsEvaluating(false),
0877 HasConstantInitialization(false), HasConstantDestruction(false),
0878 HasICEInit(false), CheckedForICEInit(false) {}
0879 };
0880
0881
0882 class VarDecl : public DeclaratorDecl, public Redeclarable<VarDecl> {
0883 public:
0884
0885 enum InitializationStyle {
0886
0887 CInit,
0888
0889
0890 CallInit,
0891
0892
0893 ListInit,
0894
0895
0896 ParenListInit
0897 };
0898
0899
0900 enum TLSKind {
0901
0902 TLS_None,
0903
0904
0905 TLS_Static,
0906
0907
0908 TLS_Dynamic
0909 };
0910
0911
0912
0913
0914 static const char *getStorageClassSpecifierString(StorageClass SC);
0915
0916 protected:
0917
0918
0919
0920
0921
0922
0923
0924 using InitType = llvm::PointerUnion<Stmt *, EvaluatedStmt *>;
0925
0926
0927
0928 mutable InitType Init;
0929
0930 private:
0931 friend class ASTDeclReader;
0932 friend class ASTNodeImporter;
0933 friend class StmtIteratorBase;
0934
0935 class VarDeclBitfields {
0936 friend class ASTDeclReader;
0937 friend class VarDecl;
0938
0939 LLVM_PREFERRED_TYPE(StorageClass)
0940 unsigned SClass : 3;
0941 LLVM_PREFERRED_TYPE(ThreadStorageClassSpecifier)
0942 unsigned TSCSpec : 2;
0943 LLVM_PREFERRED_TYPE(InitializationStyle)
0944 unsigned InitStyle : 2;
0945
0946
0947
0948 LLVM_PREFERRED_TYPE(bool)
0949 unsigned ARCPseudoStrong : 1;
0950 };
0951 enum { NumVarDeclBits = 8 };
0952
0953 protected:
0954 enum { NumParameterIndexBits = 8 };
0955
0956 enum DefaultArgKind {
0957 DAK_None,
0958 DAK_Unparsed,
0959 DAK_Uninstantiated,
0960 DAK_Normal
0961 };
0962
0963 enum { NumScopeDepthOrObjCQualsBits = 7 };
0964
0965 class ParmVarDeclBitfields {
0966 friend class ASTDeclReader;
0967 friend class ParmVarDecl;
0968
0969 LLVM_PREFERRED_TYPE(VarDeclBitfields)
0970 unsigned : NumVarDeclBits;
0971
0972
0973
0974 LLVM_PREFERRED_TYPE(bool)
0975 unsigned HasInheritedDefaultArg : 1;
0976
0977
0978
0979
0980
0981 LLVM_PREFERRED_TYPE(DefaultArgKind)
0982 unsigned DefaultArgKind : 2;
0983
0984
0985 LLVM_PREFERRED_TYPE(bool)
0986 unsigned IsKNRPromoted : 1;
0987
0988
0989 LLVM_PREFERRED_TYPE(bool)
0990 unsigned IsObjCMethodParam : 1;
0991
0992
0993
0994
0995
0996 unsigned ScopeDepthOrObjCQuals : NumScopeDepthOrObjCQualsBits;
0997
0998
0999
1000 unsigned ParameterIndex : NumParameterIndexBits;
1001 };
1002
1003 class NonParmVarDeclBitfields {
1004 friend class ASTDeclReader;
1005 friend class ImplicitParamDecl;
1006 friend class VarDecl;
1007
1008 LLVM_PREFERRED_TYPE(VarDeclBitfields)
1009 unsigned : NumVarDeclBits;
1010
1011
1012
1013
1014 LLVM_PREFERRED_TYPE(bool)
1015 unsigned IsThisDeclarationADemotedDefinition : 1;
1016
1017
1018
1019 LLVM_PREFERRED_TYPE(bool)
1020 unsigned ExceptionVar : 1;
1021
1022
1023
1024
1025 LLVM_PREFERRED_TYPE(bool)
1026 unsigned NRVOVariable : 1;
1027
1028
1029
1030 LLVM_PREFERRED_TYPE(bool)
1031 unsigned CXXForRangeDecl : 1;
1032
1033
1034 LLVM_PREFERRED_TYPE(bool)
1035 unsigned ObjCForDecl : 1;
1036
1037
1038 LLVM_PREFERRED_TYPE(bool)
1039 unsigned IsInline : 1;
1040
1041
1042 LLVM_PREFERRED_TYPE(bool)
1043 unsigned IsInlineSpecified : 1;
1044
1045
1046 LLVM_PREFERRED_TYPE(bool)
1047 unsigned IsConstexpr : 1;
1048
1049
1050
1051 LLVM_PREFERRED_TYPE(bool)
1052 unsigned IsInitCapture : 1;
1053
1054
1055
1056
1057 LLVM_PREFERRED_TYPE(bool)
1058 unsigned PreviousDeclInSameBlockScope : 1;
1059
1060
1061
1062 LLVM_PREFERRED_TYPE(ImplicitParamKind)
1063 unsigned ImplicitParamKind : 3;
1064
1065 LLVM_PREFERRED_TYPE(bool)
1066 unsigned EscapingByref : 1;
1067
1068 LLVM_PREFERRED_TYPE(bool)
1069 unsigned IsCXXCondDecl : 1;
1070 };
1071
1072 union {
1073 unsigned AllBits;
1074 VarDeclBitfields VarDeclBits;
1075 ParmVarDeclBitfields ParmVarDeclBits;
1076 NonParmVarDeclBitfields NonParmVarDeclBits;
1077 };
1078
1079 VarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1080 SourceLocation IdLoc, const IdentifierInfo *Id, QualType T,
1081 TypeSourceInfo *TInfo, StorageClass SC);
1082
1083 using redeclarable_base = Redeclarable<VarDecl>;
1084
1085 VarDecl *getNextRedeclarationImpl() override {
1086 return getNextRedeclaration();
1087 }
1088
1089 VarDecl *getPreviousDeclImpl() override {
1090 return getPreviousDecl();
1091 }
1092
1093 VarDecl *getMostRecentDeclImpl() override {
1094 return getMostRecentDecl();
1095 }
1096
1097 public:
1098 using redecl_range = redeclarable_base::redecl_range;
1099 using redecl_iterator = redeclarable_base::redecl_iterator;
1100
1101 using redeclarable_base::redecls_begin;
1102 using redeclarable_base::redecls_end;
1103 using redeclarable_base::redecls;
1104 using redeclarable_base::getPreviousDecl;
1105 using redeclarable_base::getMostRecentDecl;
1106 using redeclarable_base::isFirstDecl;
1107
1108 static VarDecl *Create(ASTContext &C, DeclContext *DC,
1109 SourceLocation StartLoc, SourceLocation IdLoc,
1110 const IdentifierInfo *Id, QualType T,
1111 TypeSourceInfo *TInfo, StorageClass S);
1112
1113 static VarDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
1114
1115 SourceRange getSourceRange() const override LLVM_READONLY;
1116
1117
1118
1119 StorageClass getStorageClass() const {
1120 return (StorageClass) VarDeclBits.SClass;
1121 }
1122 void setStorageClass(StorageClass SC);
1123
1124 void setTSCSpec(ThreadStorageClassSpecifier TSC) {
1125 VarDeclBits.TSCSpec = TSC;
1126 assert(VarDeclBits.TSCSpec == TSC && "truncation");
1127 }
1128 ThreadStorageClassSpecifier getTSCSpec() const {
1129 return static_cast<ThreadStorageClassSpecifier>(VarDeclBits.TSCSpec);
1130 }
1131 TLSKind getTLSKind() const;
1132
1133
1134
1135 bool hasLocalStorage() const {
1136 if (getStorageClass() == SC_None) {
1137
1138
1139
1140
1141 if (getType().getAddressSpace() == LangAS::opencl_constant)
1142 return false;
1143
1144 return !isFileVarDecl() && getTSCSpec() == TSCS_unspecified;
1145 }
1146
1147
1148 if (getStorageClass() == SC_Register && !isLocalVarDeclOrParm())
1149 return false;
1150
1151
1152
1153
1154 return getStorageClass() >= SC_Auto;
1155 }
1156
1157
1158
1159 bool isStaticLocal() const {
1160 return (getStorageClass() == SC_Static ||
1161
1162 (getStorageClass() == SC_None && getTSCSpec() == TSCS_thread_local))
1163 && !isFileVarDecl();
1164 }
1165
1166
1167
1168 bool hasExternalStorage() const {
1169 return getStorageClass() == SC_Extern ||
1170 getStorageClass() == SC_PrivateExtern;
1171 }
1172
1173
1174
1175
1176
1177 bool hasGlobalStorage() const { return !hasLocalStorage(); }
1178
1179
1180 StorageDuration getStorageDuration() const {
1181 return hasLocalStorage() ? SD_Automatic :
1182 getTSCSpec() ? SD_Thread : SD_Static;
1183 }
1184
1185
1186 LanguageLinkage getLanguageLinkage() const;
1187
1188
1189 bool isExternC() const;
1190
1191
1192
1193 bool isInExternCContext() const;
1194
1195
1196
1197 bool isInExternCXXContext() const;
1198
1199
1200
1201
1202
1203
1204 bool isLocalVarDecl() const {
1205 if (getKind() != Decl::Var && getKind() != Decl::Decomposition)
1206 return false;
1207 if (const DeclContext *DC = getLexicalDeclContext())
1208 return DC->getRedeclContext()->isFunctionOrMethod();
1209 return false;
1210 }
1211
1212
1213 bool isLocalVarDeclOrParm() const {
1214 return isLocalVarDecl() || getKind() == Decl::ParmVar;
1215 }
1216
1217
1218 bool isFunctionOrMethodVarDecl() const {
1219 if (getKind() != Decl::Var && getKind() != Decl::Decomposition)
1220 return false;
1221 const DeclContext *DC = getLexicalDeclContext()->getRedeclContext();
1222 return DC->isFunctionOrMethod() && DC->getDeclKind() != Decl::Block;
1223 }
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234 bool isStaticDataMember() const {
1235
1236 return getKind() != Decl::ParmVar && getDeclContext()->isRecord();
1237 }
1238
1239 VarDecl *getCanonicalDecl() override;
1240 const VarDecl *getCanonicalDecl() const {
1241 return const_cast<VarDecl*>(this)->getCanonicalDecl();
1242 }
1243
1244 enum DefinitionKind {
1245
1246 DeclarationOnly,
1247
1248
1249 TentativeDefinition,
1250
1251
1252 Definition
1253 };
1254
1255
1256
1257
1258 DefinitionKind isThisDeclarationADefinition(ASTContext &) const;
1259 DefinitionKind isThisDeclarationADefinition() const {
1260 return isThisDeclarationADefinition(getASTContext());
1261 }
1262
1263
1264 DefinitionKind hasDefinition(ASTContext &) const;
1265 DefinitionKind hasDefinition() const {
1266 return hasDefinition(getASTContext());
1267 }
1268
1269
1270
1271 VarDecl *getActingDefinition();
1272 const VarDecl *getActingDefinition() const {
1273 return const_cast<VarDecl*>(this)->getActingDefinition();
1274 }
1275
1276
1277 VarDecl *getDefinition(ASTContext &);
1278 const VarDecl *getDefinition(ASTContext &C) const {
1279 return const_cast<VarDecl*>(this)->getDefinition(C);
1280 }
1281 VarDecl *getDefinition() {
1282 return getDefinition(getASTContext());
1283 }
1284 const VarDecl *getDefinition() const {
1285 return const_cast<VarDecl*>(this)->getDefinition();
1286 }
1287
1288
1289
1290 bool isOutOfLine() const override;
1291
1292
1293 bool isFileVarDecl() const {
1294 Kind K = getKind();
1295 if (K == ParmVar || K == ImplicitParam)
1296 return false;
1297
1298 if (getLexicalDeclContext()->getRedeclContext()->isFileContext())
1299 return true;
1300
1301 if (isStaticDataMember())
1302 return true;
1303
1304 return false;
1305 }
1306
1307
1308
1309 const Expr *getAnyInitializer() const {
1310 const VarDecl *D;
1311 return getAnyInitializer(D);
1312 }
1313
1314
1315
1316 const Expr *getAnyInitializer(const VarDecl *&D) const;
1317
1318 bool hasInit() const;
1319 const Expr *getInit() const {
1320 return const_cast<VarDecl *>(this)->getInit();
1321 }
1322 Expr *getInit();
1323
1324
1325 Stmt **getInitAddress();
1326
1327 void setInit(Expr *I);
1328
1329
1330
1331
1332 VarDecl *getInitializingDeclaration();
1333 const VarDecl *getInitializingDeclaration() const {
1334 return const_cast<VarDecl *>(this)->getInitializingDeclaration();
1335 }
1336
1337
1338
1339
1340
1341
1342
1343
1344 bool mightBeUsableInConstantExpressions(const ASTContext &C) const;
1345
1346
1347
1348
1349 bool isUsableInConstantExpressions(const ASTContext &C) const;
1350
1351 EvaluatedStmt *ensureEvaluatedStmt() const;
1352 EvaluatedStmt *getEvaluatedStmt() const;
1353
1354
1355
1356
1357 APValue *evaluateValue() const;
1358
1359 private:
1360 APValue *evaluateValueImpl(SmallVectorImpl<PartialDiagnosticAt> &Notes,
1361 bool IsConstantInitialization) const;
1362
1363 public:
1364
1365
1366
1367 APValue *getEvaluatedValue() const;
1368
1369
1370
1371
1372
1373
1374
1375 bool evaluateDestruction(SmallVectorImpl<PartialDiagnosticAt> &Notes) const;
1376
1377
1378
1379
1380
1381
1382
1383 bool hasConstantInitialization() const;
1384
1385
1386
1387
1388 bool hasICEInitializer(const ASTContext &Context) const;
1389
1390
1391
1392
1393 bool checkForConstantInitialization(
1394 SmallVectorImpl<PartialDiagnosticAt> &Notes) const;
1395
1396 void setInitStyle(InitializationStyle Style) {
1397 VarDeclBits.InitStyle = Style;
1398 }
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410 InitializationStyle getInitStyle() const {
1411 return static_cast<InitializationStyle>(VarDeclBits.InitStyle);
1412 }
1413
1414
1415 bool isDirectInit() const {
1416 return getInitStyle() != CInit;
1417 }
1418
1419
1420 bool isThisDeclarationADemotedDefinition() const {
1421 return isa<ParmVarDecl>(this) ? false :
1422 NonParmVarDeclBits.IsThisDeclarationADemotedDefinition;
1423 }
1424
1425
1426
1427
1428
1429
1430 void demoteThisDefinitionToDeclaration() {
1431 assert(isThisDeclarationADefinition() && "Not a definition!");
1432 assert(!isa<ParmVarDecl>(this) && "Cannot demote ParmVarDecls!");
1433 NonParmVarDeclBits.IsThisDeclarationADemotedDefinition = 1;
1434 }
1435
1436
1437
1438 bool isExceptionVariable() const {
1439 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.ExceptionVar;
1440 }
1441 void setExceptionVariable(bool EV) {
1442 assert(!isa<ParmVarDecl>(this));
1443 NonParmVarDeclBits.ExceptionVar = EV;
1444 }
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456 bool isNRVOVariable() const {
1457 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.NRVOVariable;
1458 }
1459 void setNRVOVariable(bool NRVO) {
1460 assert(!isa<ParmVarDecl>(this));
1461 NonParmVarDeclBits.NRVOVariable = NRVO;
1462 }
1463
1464
1465
1466 bool isCXXForRangeDecl() const {
1467 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.CXXForRangeDecl;
1468 }
1469 void setCXXForRangeDecl(bool FRD) {
1470 assert(!isa<ParmVarDecl>(this));
1471 NonParmVarDeclBits.CXXForRangeDecl = FRD;
1472 }
1473
1474
1475
1476 bool isObjCForDecl() const {
1477 return NonParmVarDeclBits.ObjCForDecl;
1478 }
1479
1480 void setObjCForDecl(bool FRD) {
1481 NonParmVarDeclBits.ObjCForDecl = FRD;
1482 }
1483
1484
1485
1486
1487
1488
1489
1490
1491 bool isARCPseudoStrong() const { return VarDeclBits.ARCPseudoStrong; }
1492 void setARCPseudoStrong(bool PS) { VarDeclBits.ARCPseudoStrong = PS; }
1493
1494
1495 bool isInline() const {
1496 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsInline;
1497 }
1498 bool isInlineSpecified() const {
1499 return isa<ParmVarDecl>(this) ? false
1500 : NonParmVarDeclBits.IsInlineSpecified;
1501 }
1502 void setInlineSpecified() {
1503 assert(!isa<ParmVarDecl>(this));
1504 NonParmVarDeclBits.IsInline = true;
1505 NonParmVarDeclBits.IsInlineSpecified = true;
1506 }
1507 void setImplicitlyInline() {
1508 assert(!isa<ParmVarDecl>(this));
1509 NonParmVarDeclBits.IsInline = true;
1510 }
1511
1512
1513 bool isConstexpr() const {
1514 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsConstexpr;
1515 }
1516 void setConstexpr(bool IC) {
1517 assert(!isa<ParmVarDecl>(this));
1518 NonParmVarDeclBits.IsConstexpr = IC;
1519 }
1520
1521
1522 bool isInitCapture() const {
1523 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsInitCapture;
1524 }
1525 void setInitCapture(bool IC) {
1526 assert(!isa<ParmVarDecl>(this));
1527 NonParmVarDeclBits.IsInitCapture = IC;
1528 }
1529
1530
1531
1532 bool isParameterPack() const;
1533
1534
1535
1536 bool isPreviousDeclInSameBlockScope() const {
1537 return isa<ParmVarDecl>(this)
1538 ? false
1539 : NonParmVarDeclBits.PreviousDeclInSameBlockScope;
1540 }
1541 void setPreviousDeclInSameBlockScope(bool Same) {
1542 assert(!isa<ParmVarDecl>(this));
1543 NonParmVarDeclBits.PreviousDeclInSameBlockScope = Same;
1544 }
1545
1546
1547
1548
1549 bool isEscapingByref() const;
1550
1551
1552
1553 bool isNonEscapingByref() const;
1554
1555 void setEscapingByref() {
1556 NonParmVarDeclBits.EscapingByref = true;
1557 }
1558
1559 bool isCXXCondDecl() const {
1560 return isa<ParmVarDecl>(this) ? false : NonParmVarDeclBits.IsCXXCondDecl;
1561 }
1562
1563 void setCXXCondDecl() {
1564 assert(!isa<ParmVarDecl>(this));
1565 NonParmVarDeclBits.IsCXXCondDecl = true;
1566 }
1567
1568
1569 bool hasDependentAlignment() const;
1570
1571
1572
1573 VarDecl *getTemplateInstantiationPattern() const;
1574
1575
1576
1577
1578 VarDecl *getInstantiatedFromStaticDataMember() const;
1579
1580
1581
1582
1583 TemplateSpecializationKind getTemplateSpecializationKind() const;
1584
1585
1586
1587
1588 TemplateSpecializationKind
1589 getTemplateSpecializationKindForInstantiation() const;
1590
1591
1592
1593
1594 SourceLocation getPointOfInstantiation() const;
1595
1596
1597
1598
1599 MemberSpecializationInfo *getMemberSpecializationInfo() const;
1600
1601
1602
1603 void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
1604 SourceLocation PointOfInstantiation = SourceLocation());
1605
1606
1607
1608 void setInstantiationOfStaticDataMember(VarDecl *VD,
1609 TemplateSpecializationKind TSK);
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622 VarTemplateDecl *getDescribedVarTemplate() const;
1623
1624 void setDescribedVarTemplate(VarTemplateDecl *Template);
1625
1626
1627
1628
1629 bool isKnownToBeDefined() const;
1630
1631
1632
1633 bool isNoDestroy(const ASTContext &) const;
1634
1635
1636
1637 QualType::DestructionKind needsDestruction(const ASTContext &Ctx) const;
1638
1639
1640
1641
1642
1643
1644
1645 bool hasFlexibleArrayInit(const ASTContext &Ctx) const;
1646
1647
1648
1649
1650
1651 CharUnits getFlexibleArrayInitChars(const ASTContext &Ctx) const;
1652
1653
1654 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1655 static bool classofKind(Kind K) { return K >= firstVar && K <= lastVar; }
1656 };
1657
1658
1659
1660
1661 enum class ImplicitParamKind {
1662
1663 ObjCSelf,
1664
1665
1666 ObjCCmd,
1667
1668
1669 CXXThis,
1670
1671
1672 CXXVTT,
1673
1674
1675 CapturedContext,
1676
1677
1678 ThreadPrivateVar,
1679
1680
1681 Other,
1682 };
1683
1684 class ImplicitParamDecl : public VarDecl {
1685 void anchor() override;
1686
1687 public:
1688
1689 static ImplicitParamDecl *Create(ASTContext &C, DeclContext *DC,
1690 SourceLocation IdLoc, IdentifierInfo *Id,
1691 QualType T, ImplicitParamKind ParamKind);
1692 static ImplicitParamDecl *Create(ASTContext &C, QualType T,
1693 ImplicitParamKind ParamKind);
1694
1695 static ImplicitParamDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
1696
1697 ImplicitParamDecl(ASTContext &C, DeclContext *DC, SourceLocation IdLoc,
1698 const IdentifierInfo *Id, QualType Type,
1699 ImplicitParamKind ParamKind)
1700 : VarDecl(ImplicitParam, C, DC, IdLoc, IdLoc, Id, Type,
1701 nullptr, SC_None) {
1702 NonParmVarDeclBits.ImplicitParamKind = llvm::to_underlying(ParamKind);
1703 setImplicit();
1704 }
1705
1706 ImplicitParamDecl(ASTContext &C, QualType Type, ImplicitParamKind ParamKind)
1707 : VarDecl(ImplicitParam, C, nullptr, SourceLocation(),
1708 SourceLocation(), nullptr, Type,
1709 nullptr, SC_None) {
1710 NonParmVarDeclBits.ImplicitParamKind = llvm::to_underlying(ParamKind);
1711 setImplicit();
1712 }
1713
1714
1715 ImplicitParamKind getParameterKind() const {
1716 return static_cast<ImplicitParamKind>(NonParmVarDeclBits.ImplicitParamKind);
1717 }
1718
1719
1720 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1721 static bool classofKind(Kind K) { return K == ImplicitParam; }
1722 };
1723
1724
1725 class ParmVarDecl : public VarDecl {
1726 public:
1727 enum { MaxFunctionScopeDepth = 255 };
1728 enum { MaxFunctionScopeIndex = 255 };
1729
1730 protected:
1731 ParmVarDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
1732 SourceLocation IdLoc, const IdentifierInfo *Id, QualType T,
1733 TypeSourceInfo *TInfo, StorageClass S, Expr *DefArg)
1734 : VarDecl(DK, C, DC, StartLoc, IdLoc, Id, T, TInfo, S) {
1735 assert(ParmVarDeclBits.HasInheritedDefaultArg == false);
1736 assert(ParmVarDeclBits.DefaultArgKind == DAK_None);
1737 assert(ParmVarDeclBits.IsKNRPromoted == false);
1738 assert(ParmVarDeclBits.IsObjCMethodParam == false);
1739 setDefaultArg(DefArg);
1740 }
1741
1742 public:
1743 static ParmVarDecl *Create(ASTContext &C, DeclContext *DC,
1744 SourceLocation StartLoc, SourceLocation IdLoc,
1745 const IdentifierInfo *Id, QualType T,
1746 TypeSourceInfo *TInfo, StorageClass S,
1747 Expr *DefArg);
1748
1749 static ParmVarDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
1750
1751 SourceRange getSourceRange() const override LLVM_READONLY;
1752
1753 void setObjCMethodScopeInfo(unsigned parameterIndex) {
1754 ParmVarDeclBits.IsObjCMethodParam = true;
1755 setParameterIndex(parameterIndex);
1756 }
1757
1758 void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex) {
1759 assert(!ParmVarDeclBits.IsObjCMethodParam);
1760
1761 ParmVarDeclBits.ScopeDepthOrObjCQuals = scopeDepth;
1762 assert(ParmVarDeclBits.ScopeDepthOrObjCQuals == scopeDepth
1763 && "truncation!");
1764
1765 setParameterIndex(parameterIndex);
1766 }
1767
1768 bool isObjCMethodParameter() const {
1769 return ParmVarDeclBits.IsObjCMethodParam;
1770 }
1771
1772
1773 bool isDestroyedInCallee() const;
1774
1775 unsigned getFunctionScopeDepth() const {
1776 if (ParmVarDeclBits.IsObjCMethodParam) return 0;
1777 return ParmVarDeclBits.ScopeDepthOrObjCQuals;
1778 }
1779
1780 static constexpr unsigned getMaxFunctionScopeDepth() {
1781 return (1u << NumScopeDepthOrObjCQualsBits) - 1;
1782 }
1783
1784
1785 unsigned getFunctionScopeIndex() const {
1786 return getParameterIndex();
1787 }
1788
1789 ObjCDeclQualifier getObjCDeclQualifier() const {
1790 if (!ParmVarDeclBits.IsObjCMethodParam) return OBJC_TQ_None;
1791 return ObjCDeclQualifier(ParmVarDeclBits.ScopeDepthOrObjCQuals);
1792 }
1793 void setObjCDeclQualifier(ObjCDeclQualifier QTVal) {
1794 assert(ParmVarDeclBits.IsObjCMethodParam);
1795 ParmVarDeclBits.ScopeDepthOrObjCQuals = QTVal;
1796 }
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806 bool isKNRPromoted() const {
1807 return ParmVarDeclBits.IsKNRPromoted;
1808 }
1809 void setKNRPromoted(bool promoted) {
1810 ParmVarDeclBits.IsKNRPromoted = promoted;
1811 }
1812
1813 bool isExplicitObjectParameter() const {
1814 return ExplicitObjectParameterIntroducerLoc.isValid();
1815 }
1816
1817 void setExplicitObjectParameterLoc(SourceLocation Loc) {
1818 ExplicitObjectParameterIntroducerLoc = Loc;
1819 }
1820
1821 SourceLocation getExplicitObjectParamThisLoc() const {
1822 return ExplicitObjectParameterIntroducerLoc;
1823 }
1824
1825 Expr *getDefaultArg();
1826 const Expr *getDefaultArg() const {
1827 return const_cast<ParmVarDecl *>(this)->getDefaultArg();
1828 }
1829
1830 void setDefaultArg(Expr *defarg);
1831
1832
1833
1834 SourceRange getDefaultArgRange() const;
1835 void setUninstantiatedDefaultArg(Expr *arg);
1836 Expr *getUninstantiatedDefaultArg();
1837 const Expr *getUninstantiatedDefaultArg() const {
1838 return const_cast<ParmVarDecl *>(this)->getUninstantiatedDefaultArg();
1839 }
1840
1841
1842
1843 bool hasDefaultArg() const;
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854 bool hasUnparsedDefaultArg() const {
1855 return ParmVarDeclBits.DefaultArgKind == DAK_Unparsed;
1856 }
1857
1858 bool hasUninstantiatedDefaultArg() const {
1859 return ParmVarDeclBits.DefaultArgKind == DAK_Uninstantiated;
1860 }
1861
1862
1863
1864
1865
1866 void setUnparsedDefaultArg() {
1867 ParmVarDeclBits.DefaultArgKind = DAK_Unparsed;
1868 }
1869
1870 bool hasInheritedDefaultArg() const {
1871 return ParmVarDeclBits.HasInheritedDefaultArg;
1872 }
1873
1874 void setHasInheritedDefaultArg(bool I = true) {
1875 ParmVarDeclBits.HasInheritedDefaultArg = I;
1876 }
1877
1878 QualType getOriginalType() const;
1879
1880
1881
1882
1883
1884 void setOwningFunction(DeclContext *FD) { setDeclContext(FD); }
1885
1886
1887 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
1888 static bool classofKind(Kind K) { return K == ParmVar; }
1889
1890 private:
1891 friend class ASTDeclReader;
1892
1893 enum { ParameterIndexSentinel = (1 << NumParameterIndexBits) - 1 };
1894 SourceLocation ExplicitObjectParameterIntroducerLoc;
1895
1896 void setParameterIndex(unsigned parameterIndex) {
1897 if (parameterIndex >= ParameterIndexSentinel) {
1898 setParameterIndexLarge(parameterIndex);
1899 return;
1900 }
1901
1902 ParmVarDeclBits.ParameterIndex = parameterIndex;
1903 assert(ParmVarDeclBits.ParameterIndex == parameterIndex && "truncation!");
1904 }
1905 unsigned getParameterIndex() const {
1906 unsigned d = ParmVarDeclBits.ParameterIndex;
1907 return d == ParameterIndexSentinel ? getParameterIndexLarge() : d;
1908 }
1909
1910 void setParameterIndexLarge(unsigned parameterIndex);
1911 unsigned getParameterIndexLarge() const;
1912 };
1913
1914 enum class MultiVersionKind {
1915 None,
1916 Target,
1917 CPUSpecific,
1918 CPUDispatch,
1919 TargetClones,
1920 TargetVersion
1921 };
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933 class FunctionDecl : public DeclaratorDecl,
1934 public DeclContext,
1935 public Redeclarable<FunctionDecl> {
1936
1937
1938 public:
1939
1940 enum TemplatedKind {
1941
1942 TK_NonTemplate,
1943
1944 TK_FunctionTemplate,
1945
1946
1947 TK_MemberSpecialization,
1948
1949
1950
1951 TK_FunctionTemplateSpecialization,
1952
1953
1954 TK_DependentFunctionTemplateSpecialization,
1955
1956 TK_DependentNonTemplate
1957
1958 };
1959
1960
1961 class DefaultedOrDeletedFunctionInfo final
1962 : llvm::TrailingObjects<DefaultedOrDeletedFunctionInfo, DeclAccessPair,
1963 StringLiteral *> {
1964 friend TrailingObjects;
1965 unsigned NumLookups;
1966 bool HasDeletedMessage;
1967
1968 size_t numTrailingObjects(OverloadToken<DeclAccessPair>) const {
1969 return NumLookups;
1970 }
1971
1972 public:
1973 static DefaultedOrDeletedFunctionInfo *
1974 Create(ASTContext &Context, ArrayRef<DeclAccessPair> Lookups,
1975 StringLiteral *DeletedMessage = nullptr);
1976
1977
1978
1979 ArrayRef<DeclAccessPair> getUnqualifiedLookups() const {
1980 return {getTrailingObjects<DeclAccessPair>(), NumLookups};
1981 }
1982
1983 StringLiteral *getDeletedMessage() const {
1984 return HasDeletedMessage ? *getTrailingObjects<StringLiteral *>()
1985 : nullptr;
1986 }
1987
1988 void setDeletedMessage(StringLiteral *Message);
1989 };
1990
1991 private:
1992
1993
1994
1995 ParmVarDecl **ParamInfo = nullptr;
1996
1997
1998
1999 union {
2000
2001 LazyDeclStmtPtr Body;
2002
2003 DefaultedOrDeletedFunctionInfo *DefaultedOrDeletedInfo;
2004 };
2005
2006 unsigned ODRHash;
2007
2008
2009
2010
2011
2012
2013
2014
2015 SourceLocation EndRangeLoc;
2016
2017 SourceLocation DefaultKWLoc;
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033 llvm::PointerUnion<NamedDecl *, MemberSpecializationInfo *,
2034 FunctionTemplateSpecializationInfo *,
2035 DependentFunctionTemplateSpecializationInfo *>
2036 TemplateOrSpecialization;
2037
2038
2039
2040 DeclarationNameLoc DNLoc;
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063 void setFunctionTemplateSpecialization(
2064 ASTContext &C, FunctionTemplateDecl *Template,
2065 TemplateArgumentList *TemplateArgs, void *InsertPos,
2066 TemplateSpecializationKind TSK,
2067 const TemplateArgumentListInfo *TemplateArgsAsWritten,
2068 SourceLocation PointOfInstantiation);
2069
2070
2071
2072 void setInstantiationOfMemberFunction(ASTContext &C, FunctionDecl *FD,
2073 TemplateSpecializationKind TSK);
2074
2075 void setParams(ASTContext &C, ArrayRef<ParmVarDecl *> NewParamInfo);
2076
2077
2078
2079
2080 bool isDeletedBit() const { return FunctionDeclBits.IsDeleted; }
2081
2082
2083 bool hasODRHash() const { return FunctionDeclBits.HasODRHash; }
2084
2085
2086 void setHasODRHash(bool B = true) { FunctionDeclBits.HasODRHash = B; }
2087
2088 protected:
2089 FunctionDecl(Kind DK, ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
2090 const DeclarationNameInfo &NameInfo, QualType T,
2091 TypeSourceInfo *TInfo, StorageClass S, bool UsesFPIntrin,
2092 bool isInlineSpecified, ConstexprSpecKind ConstexprKind,
2093 Expr *TrailingRequiresClause = nullptr);
2094
2095 using redeclarable_base = Redeclarable<FunctionDecl>;
2096
2097 FunctionDecl *getNextRedeclarationImpl() override {
2098 return getNextRedeclaration();
2099 }
2100
2101 FunctionDecl *getPreviousDeclImpl() override {
2102 return getPreviousDecl();
2103 }
2104
2105 FunctionDecl *getMostRecentDeclImpl() override {
2106 return getMostRecentDecl();
2107 }
2108
2109 public:
2110 friend class ASTDeclReader;
2111 friend class ASTDeclWriter;
2112
2113 using redecl_range = redeclarable_base::redecl_range;
2114 using redecl_iterator = redeclarable_base::redecl_iterator;
2115
2116 using redeclarable_base::redecls_begin;
2117 using redeclarable_base::redecls_end;
2118 using redeclarable_base::redecls;
2119 using redeclarable_base::getPreviousDecl;
2120 using redeclarable_base::getMostRecentDecl;
2121 using redeclarable_base::isFirstDecl;
2122
2123 static FunctionDecl *
2124 Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
2125 SourceLocation NLoc, DeclarationName N, QualType T,
2126 TypeSourceInfo *TInfo, StorageClass SC, bool UsesFPIntrin = false,
2127 bool isInlineSpecified = false, bool hasWrittenPrototype = true,
2128 ConstexprSpecKind ConstexprKind = ConstexprSpecKind::Unspecified,
2129 Expr *TrailingRequiresClause = nullptr) {
2130 DeclarationNameInfo NameInfo(N, NLoc);
2131 return FunctionDecl::Create(C, DC, StartLoc, NameInfo, T, TInfo, SC,
2132 UsesFPIntrin, isInlineSpecified,
2133 hasWrittenPrototype, ConstexprKind,
2134 TrailingRequiresClause);
2135 }
2136
2137 static FunctionDecl *
2138 Create(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
2139 const DeclarationNameInfo &NameInfo, QualType T, TypeSourceInfo *TInfo,
2140 StorageClass SC, bool UsesFPIntrin, bool isInlineSpecified,
2141 bool hasWrittenPrototype, ConstexprSpecKind ConstexprKind,
2142 Expr *TrailingRequiresClause);
2143
2144 static FunctionDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
2145
2146 DeclarationNameInfo getNameInfo() const {
2147 return DeclarationNameInfo(getDeclName(), getLocation(), DNLoc);
2148 }
2149
2150 void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy,
2151 bool Qualified) const override;
2152
2153 void setRangeEnd(SourceLocation E) { EndRangeLoc = E; }
2154
2155 void setDeclarationNameLoc(DeclarationNameLoc L) { DNLoc = L; }
2156
2157
2158 SourceLocation getEllipsisLoc() const {
2159 const auto *FPT = getType()->getAs<FunctionProtoType>();
2160 if (FPT && FPT->isVariadic())
2161 return FPT->getEllipsisLoc();
2162 return SourceLocation();
2163 }
2164
2165 SourceRange getSourceRange() const override LLVM_READONLY;
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186 bool hasBody(const FunctionDecl *&Definition) const;
2187
2188 bool hasBody() const override {
2189 const FunctionDecl* Definition;
2190 return hasBody(Definition);
2191 }
2192
2193
2194
2195 bool hasTrivialBody() const;
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208 bool isDefined(const FunctionDecl *&Definition,
2209 bool CheckForPendingFriendDefinition = false) const;
2210
2211 bool isDefined() const {
2212 const FunctionDecl* Definition;
2213 return isDefined(Definition);
2214 }
2215
2216
2217 FunctionDecl *getDefinition() {
2218 const FunctionDecl *Definition;
2219 if (isDefined(Definition))
2220 return const_cast<FunctionDecl *>(Definition);
2221 return nullptr;
2222 }
2223 const FunctionDecl *getDefinition() const {
2224 return const_cast<FunctionDecl *>(this)->getDefinition();
2225 }
2226
2227
2228
2229
2230
2231
2232
2233 Stmt *getBody(const FunctionDecl *&Definition) const;
2234
2235 Stmt *getBody() const override {
2236 const FunctionDecl* Definition;
2237 return getBody(Definition);
2238 }
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249 bool isThisDeclarationADefinition() const {
2250 return isDeletedAsWritten() || isDefaulted() ||
2251 doesThisDeclarationHaveABody() || hasSkippedBody() ||
2252 willHaveBody() || hasDefiningAttr();
2253 }
2254
2255
2256
2257
2258 bool isThisDeclarationInstantiatedFromAFriendDefinition() const;
2259
2260
2261 bool doesThisDeclarationHaveABody() const {
2262 return (!FunctionDeclBits.HasDefaultedOrDeletedInfo && Body) ||
2263 isLateTemplateParsed();
2264 }
2265
2266 void setBody(Stmt *B);
2267 void setLazyBody(uint64_t Offset) {
2268 FunctionDeclBits.HasDefaultedOrDeletedInfo = false;
2269 Body = LazyDeclStmtPtr(Offset);
2270 }
2271
2272 void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info);
2273 DefaultedOrDeletedFunctionInfo *getDefalutedOrDeletedInfo() const;
2274
2275
2276 bool isVariadic() const;
2277
2278
2279 bool isVirtualAsWritten() const {
2280 return FunctionDeclBits.IsVirtualAsWritten;
2281 }
2282
2283
2284 void setVirtualAsWritten(bool V) { FunctionDeclBits.IsVirtualAsWritten = V; }
2285
2286
2287
2288 bool isPureVirtual() const { return FunctionDeclBits.IsPureVirtual; }
2289 void setIsPureVirtual(bool P = true);
2290
2291
2292 bool isLateTemplateParsed() const {
2293 return FunctionDeclBits.IsLateTemplateParsed;
2294 }
2295
2296
2297 void setLateTemplateParsed(bool ILT = true) {
2298 FunctionDeclBits.IsLateTemplateParsed = ILT;
2299 }
2300
2301 bool isInstantiatedFromMemberTemplate() const {
2302 return FunctionDeclBits.IsInstantiatedFromMemberTemplate;
2303 }
2304 void setInstantiatedFromMemberTemplate(bool Val = true) {
2305 FunctionDeclBits.IsInstantiatedFromMemberTemplate = Val;
2306 }
2307
2308
2309
2310
2311
2312 bool isTrivial() const { return FunctionDeclBits.IsTrivial; }
2313 void setTrivial(bool IT) { FunctionDeclBits.IsTrivial = IT; }
2314
2315 bool isTrivialForCall() const { return FunctionDeclBits.IsTrivialForCall; }
2316 void setTrivialForCall(bool IT) { FunctionDeclBits.IsTrivialForCall = IT; }
2317
2318
2319
2320 bool isDefaulted() const { return FunctionDeclBits.IsDefaulted; }
2321 void setDefaulted(bool D = true) { FunctionDeclBits.IsDefaulted = D; }
2322
2323
2324 bool isExplicitlyDefaulted() const {
2325 return FunctionDeclBits.IsExplicitlyDefaulted;
2326 }
2327
2328
2329 void setExplicitlyDefaulted(bool ED = true) {
2330 FunctionDeclBits.IsExplicitlyDefaulted = ED;
2331 }
2332
2333 SourceLocation getDefaultLoc() const {
2334 return isExplicitlyDefaulted() ? DefaultKWLoc : SourceLocation();
2335 }
2336
2337 void setDefaultLoc(SourceLocation NewLoc) {
2338 assert((NewLoc.isInvalid() || isExplicitlyDefaulted()) &&
2339 "Can't set default loc is function isn't explicitly defaulted");
2340 DefaultKWLoc = NewLoc;
2341 }
2342
2343
2344
2345 bool isUserProvided() const {
2346 auto *DeclAsWritten = this;
2347 if (FunctionDecl *Pattern = getTemplateInstantiationPattern())
2348 DeclAsWritten = Pattern;
2349 return !(DeclAsWritten->isDeleted() ||
2350 DeclAsWritten->getCanonicalDecl()->isDefaulted());
2351 }
2352
2353 bool isIneligibleOrNotSelected() const {
2354 return FunctionDeclBits.IsIneligibleOrNotSelected;
2355 }
2356 void setIneligibleOrNotSelected(bool II) {
2357 FunctionDeclBits.IsIneligibleOrNotSelected = II;
2358 }
2359
2360
2361
2362
2363 bool hasImplicitReturnZero() const {
2364 return FunctionDeclBits.HasImplicitReturnZero;
2365 }
2366
2367
2368
2369
2370 void setHasImplicitReturnZero(bool IRZ) {
2371 FunctionDeclBits.HasImplicitReturnZero = IRZ;
2372 }
2373
2374
2375
2376
2377
2378 bool hasPrototype() const {
2379 return hasWrittenPrototype() || hasInheritedPrototype();
2380 }
2381
2382
2383 bool hasWrittenPrototype() const {
2384 return FunctionDeclBits.HasWrittenPrototype;
2385 }
2386
2387
2388 void setHasWrittenPrototype(bool P = true) {
2389 FunctionDeclBits.HasWrittenPrototype = P;
2390 }
2391
2392
2393
2394 bool hasInheritedPrototype() const {
2395 return FunctionDeclBits.HasInheritedPrototype;
2396 }
2397
2398
2399
2400 void setHasInheritedPrototype(bool P = true) {
2401 FunctionDeclBits.HasInheritedPrototype = P;
2402 }
2403
2404
2405 bool isConstexpr() const {
2406 return getConstexprKind() != ConstexprSpecKind::Unspecified;
2407 }
2408 void setConstexprKind(ConstexprSpecKind CSK) {
2409 FunctionDeclBits.ConstexprKind = static_cast<uint64_t>(CSK);
2410 }
2411 ConstexprSpecKind getConstexprKind() const {
2412 return static_cast<ConstexprSpecKind>(FunctionDeclBits.ConstexprKind);
2413 }
2414 bool isConstexprSpecified() const {
2415 return getConstexprKind() == ConstexprSpecKind::Constexpr;
2416 }
2417 bool isConsteval() const {
2418 return getConstexprKind() == ConstexprSpecKind::Consteval;
2419 }
2420
2421 void setBodyContainsImmediateEscalatingExpressions(bool Set) {
2422 FunctionDeclBits.BodyContainsImmediateEscalatingExpression = Set;
2423 }
2424
2425 bool BodyContainsImmediateEscalatingExpressions() const {
2426 return FunctionDeclBits.BodyContainsImmediateEscalatingExpression;
2427 }
2428
2429 bool isImmediateEscalating() const;
2430
2431
2432
2433
2434 bool isImmediateFunction() const;
2435
2436
2437
2438
2439
2440
2441
2442 bool instantiationIsPending() const {
2443 return FunctionDeclBits.InstantiationIsPending;
2444 }
2445
2446
2447
2448 void setInstantiationIsPending(bool IC) {
2449 FunctionDeclBits.InstantiationIsPending = IC;
2450 }
2451
2452
2453 bool usesSEHTry() const { return FunctionDeclBits.UsesSEHTry; }
2454 void setUsesSEHTry(bool UST) { FunctionDeclBits.UsesSEHTry = UST; }
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475 bool isDeleted() const {
2476 return getCanonicalDecl()->FunctionDeclBits.IsDeleted;
2477 }
2478
2479 bool isDeletedAsWritten() const {
2480 return FunctionDeclBits.IsDeleted && !isDefaulted();
2481 }
2482
2483 void setDeletedAsWritten(bool D = true, StringLiteral *Message = nullptr);
2484
2485
2486
2487 bool isMain() const;
2488
2489
2490
2491 bool isMSVCRTEntryPoint() const;
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506 bool isReservedGlobalPlacementOperator() const;
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529 bool isReplaceableGlobalAllocationFunction(
2530 std::optional<unsigned> *AlignmentParam = nullptr,
2531 bool *IsNothrow = nullptr) const;
2532
2533
2534 bool isInlineBuiltinDeclaration() const;
2535
2536
2537 bool isDestroyingOperatorDelete() const;
2538
2539
2540 LanguageLinkage getLanguageLinkage() const;
2541
2542
2543
2544 bool isExternC() const;
2545
2546
2547
2548 bool isInExternCContext() const;
2549
2550
2551
2552 bool isInExternCXXContext() const;
2553
2554
2555 bool isGlobal() const;
2556
2557
2558
2559 bool isNoReturn() const;
2560
2561
2562 bool hasSkippedBody() const { return FunctionDeclBits.HasSkippedBody; }
2563 void setHasSkippedBody(bool Skipped = true) {
2564 FunctionDeclBits.HasSkippedBody = Skipped;
2565 }
2566
2567
2568 bool willHaveBody() const { return FunctionDeclBits.WillHaveBody; }
2569 void setWillHaveBody(bool V = true) { FunctionDeclBits.WillHaveBody = V; }
2570
2571
2572 bool isMultiVersion() const {
2573 return getCanonicalDecl()->FunctionDeclBits.IsMultiVersion;
2574 }
2575
2576
2577
2578 void setIsMultiVersion(bool V = true) {
2579 getCanonicalDecl()->FunctionDeclBits.IsMultiVersion = V;
2580 }
2581
2582
2583
2584 void setFriendConstraintRefersToEnclosingTemplate(bool V = true) {
2585 getCanonicalDecl()
2586 ->FunctionDeclBits.FriendConstraintRefersToEnclosingTemplate = V;
2587 }
2588
2589
2590 bool FriendConstraintRefersToEnclosingTemplate() const {
2591 return getCanonicalDecl()
2592 ->FunctionDeclBits.FriendConstraintRefersToEnclosingTemplate;
2593 }
2594
2595
2596
2597 bool isMemberLikeConstrainedFriend() const;
2598
2599
2600
2601
2602 MultiVersionKind getMultiVersionKind() const;
2603
2604
2605
2606
2607 bool isCPUDispatchMultiVersion() const;
2608
2609
2610 bool isCPUSpecificMultiVersion() const;
2611
2612
2613
2614 bool isTargetMultiVersion() const;
2615
2616
2617
2618 bool isTargetMultiVersionDefault() const;
2619
2620
2621
2622 bool isTargetClonesMultiVersion() const;
2623
2624
2625
2626 bool isTargetVersionMultiVersion() const;
2627
2628
2629
2630
2631
2632
2633
2634 void getAssociatedConstraints(SmallVectorImpl<const Expr *> &AC) const {
2635 if (auto *TRC = getTrailingRequiresClause())
2636 AC.push_back(TRC);
2637 }
2638
2639
2640 StringLiteral *getDeletedMessage() const {
2641 return FunctionDeclBits.HasDefaultedOrDeletedInfo
2642 ? DefaultedOrDeletedInfo->getDeletedMessage()
2643 : nullptr;
2644 }
2645
2646 void setPreviousDeclaration(FunctionDecl * PrevDecl);
2647
2648 FunctionDecl *getCanonicalDecl() override;
2649 const FunctionDecl *getCanonicalDecl() const {
2650 return const_cast<FunctionDecl*>(this)->getCanonicalDecl();
2651 }
2652
2653 unsigned getBuiltinID(bool ConsiderWrapperFunctions = false) const;
2654
2655
2656 ArrayRef<ParmVarDecl *> parameters() const {
2657 return {ParamInfo, getNumParams()};
2658 }
2659 MutableArrayRef<ParmVarDecl *> parameters() {
2660 return {ParamInfo, getNumParams()};
2661 }
2662
2663
2664 using param_iterator = MutableArrayRef<ParmVarDecl *>::iterator;
2665 using param_const_iterator = ArrayRef<ParmVarDecl *>::const_iterator;
2666
2667 bool param_empty() const { return parameters().empty(); }
2668 param_iterator param_begin() { return parameters().begin(); }
2669 param_iterator param_end() { return parameters().end(); }
2670 param_const_iterator param_begin() const { return parameters().begin(); }
2671 param_const_iterator param_end() const { return parameters().end(); }
2672 size_t param_size() const { return parameters().size(); }
2673
2674
2675
2676
2677 unsigned getNumParams() const;
2678
2679 const ParmVarDecl *getParamDecl(unsigned i) const {
2680 assert(i < getNumParams() && "Illegal param #");
2681 return ParamInfo[i];
2682 }
2683 ParmVarDecl *getParamDecl(unsigned i) {
2684 assert(i < getNumParams() && "Illegal param #");
2685 return ParamInfo[i];
2686 }
2687 void setParams(ArrayRef<ParmVarDecl *> NewParamInfo) {
2688 setParams(getASTContext(), NewParamInfo);
2689 }
2690
2691
2692
2693
2694 unsigned getMinRequiredArguments() const;
2695
2696
2697
2698
2699 unsigned getMinRequiredExplicitArguments() const;
2700
2701 bool hasCXXExplicitFunctionObjectParameter() const;
2702
2703 unsigned getNumNonObjectParams() const;
2704
2705 const ParmVarDecl *getNonObjectParameter(unsigned I) const {
2706 return getParamDecl(hasCXXExplicitFunctionObjectParameter() ? I + 1 : I);
2707 }
2708
2709 ParmVarDecl *getNonObjectParameter(unsigned I) {
2710 return getParamDecl(hasCXXExplicitFunctionObjectParameter() ? I + 1 : I);
2711 }
2712
2713
2714
2715
2716
2717
2718
2719 bool hasOneParamOrDefaultArgs() const;
2720
2721
2722
2723
2724
2725 FunctionTypeLoc getFunctionTypeLoc() const;
2726
2727 QualType getReturnType() const {
2728 return getType()->castAs<FunctionType>()->getReturnType();
2729 }
2730
2731
2732
2733
2734 SourceRange getReturnTypeSourceRange() const;
2735
2736
2737
2738
2739
2740 SourceRange getParametersSourceRange() const;
2741
2742
2743
2744 QualType getDeclaredReturnType() const {
2745 auto *TSI = getTypeSourceInfo();
2746 QualType T = TSI ? TSI->getType() : getType();
2747 return T->castAs<FunctionType>()->getReturnType();
2748 }
2749
2750
2751 ExceptionSpecificationType getExceptionSpecType() const {
2752 auto *TSI = getTypeSourceInfo();
2753 QualType T = TSI ? TSI->getType() : getType();
2754 const auto *FPT = T->getAs<FunctionProtoType>();
2755 return FPT ? FPT->getExceptionSpecType() : EST_None;
2756 }
2757
2758
2759
2760 SourceRange getExceptionSpecSourceRange() const;
2761
2762
2763 QualType getCallResultType() const {
2764 return getType()->castAs<FunctionType>()->getCallResultType(
2765 getASTContext());
2766 }
2767
2768
2769
2770 StorageClass getStorageClass() const {
2771 return static_cast<StorageClass>(FunctionDeclBits.SClass);
2772 }
2773
2774
2775 void setStorageClass(StorageClass SClass) {
2776 FunctionDeclBits.SClass = SClass;
2777 }
2778
2779
2780
2781 bool isInlineSpecified() const { return FunctionDeclBits.IsInlineSpecified; }
2782
2783
2784 void setInlineSpecified(bool I) {
2785 FunctionDeclBits.IsInlineSpecified = I;
2786 FunctionDeclBits.IsInline = I;
2787 }
2788
2789
2790
2791 bool UsesFPIntrin() const { return FunctionDeclBits.UsesFPIntrin; }
2792
2793
2794
2795 void setUsesFPIntrin(bool I) { FunctionDeclBits.UsesFPIntrin = I; }
2796
2797
2798 void setImplicitlyInline(bool I = true) { FunctionDeclBits.IsInline = I; }
2799
2800
2801
2802
2803 bool isInlined() const { return FunctionDeclBits.IsInline; }
2804
2805 bool isInlineDefinitionExternallyVisible() const;
2806
2807 bool isMSExternInline() const;
2808
2809 bool doesDeclarationForceExternallyVisibleDefinition() const;
2810
2811 bool isStatic() const { return getStorageClass() == SC_Static; }
2812
2813
2814
2815 bool isOverloadedOperator() const {
2816 return getOverloadedOperator() != OO_None;
2817 }
2818
2819 OverloadedOperatorKind getOverloadedOperator() const;
2820
2821 const IdentifierInfo *getLiteralIdentifier() const;
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844 FunctionDecl *getInstantiatedFromMemberFunction() const;
2845
2846
2847 TemplatedKind getTemplatedKind() const;
2848
2849
2850
2851
2852 MemberSpecializationInfo *getMemberSpecializationInfo() const;
2853
2854
2855
2856 void setInstantiationOfMemberFunction(FunctionDecl *FD,
2857 TemplateSpecializationKind TSK) {
2858 setInstantiationOfMemberFunction(getASTContext(), FD, TSK);
2859 }
2860
2861
2862
2863
2864 void setInstantiatedFromDecl(FunctionDecl *FD);
2865
2866 FunctionDecl *getInstantiatedFromDecl() const;
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880 FunctionTemplateDecl *getDescribedFunctionTemplate() const;
2881
2882 void setDescribedFunctionTemplate(FunctionTemplateDecl *Template);
2883
2884
2885
2886 bool isFunctionTemplateSpecialization() const;
2887
2888
2889
2890
2891 FunctionTemplateSpecializationInfo *getTemplateSpecializationInfo() const;
2892
2893
2894
2895
2896 bool isImplicitlyInstantiable() const;
2897
2898
2899
2900 bool isTemplateInstantiation() const;
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910 FunctionDecl *
2911 getTemplateInstantiationPattern(bool ForDefinition = true) const;
2912
2913
2914
2915
2916
2917
2918 FunctionTemplateDecl *getPrimaryTemplate() const;
2919
2920
2921
2922
2923
2924
2925 const TemplateArgumentList *getTemplateSpecializationArgs() const;
2926
2927
2928
2929
2930
2931
2932
2933
2934 const ASTTemplateArgumentListInfo*
2935 getTemplateSpecializationArgsAsWritten() const;
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956 void setFunctionTemplateSpecialization(
2957 FunctionTemplateDecl *Template, TemplateArgumentList *TemplateArgs,
2958 void *InsertPos,
2959 TemplateSpecializationKind TSK = TSK_ImplicitInstantiation,
2960 TemplateArgumentListInfo *TemplateArgsAsWritten = nullptr,
2961 SourceLocation PointOfInstantiation = SourceLocation()) {
2962 setFunctionTemplateSpecialization(getASTContext(), Template, TemplateArgs,
2963 InsertPos, TSK, TemplateArgsAsWritten,
2964 PointOfInstantiation);
2965 }
2966
2967
2968
2969 void setDependentTemplateSpecialization(
2970 ASTContext &Context, const UnresolvedSetImpl &Templates,
2971 const TemplateArgumentListInfo *TemplateArgs);
2972
2973 DependentFunctionTemplateSpecializationInfo *
2974 getDependentSpecializationInfo() const;
2975
2976
2977
2978 TemplateSpecializationKind getTemplateSpecializationKind() const;
2979
2980
2981
2982 TemplateSpecializationKind
2983 getTemplateSpecializationKindForInstantiation() const;
2984
2985
2986
2987 void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
2988 SourceLocation PointOfInstantiation = SourceLocation());
2989
2990
2991
2992
2993
2994
2995
2996 SourceLocation getPointOfInstantiation() const;
2997
2998
2999
3000 bool isOutOfLine() const override;
3001
3002
3003
3004
3005
3006 unsigned getMemoryFunctionKind() const;
3007
3008
3009
3010 unsigned getODRHash();
3011
3012
3013
3014 unsigned getODRHash() const;
3015
3016 FunctionEffectsRef getFunctionEffects() const {
3017
3018
3019
3020 if (const auto *FPT =
3021 getMostRecentDecl()->getType()->getAs<FunctionProtoType>())
3022 return FPT->getFunctionEffects();
3023 return {};
3024 }
3025
3026
3027 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3028 static bool classofKind(Kind K) {
3029 return K >= firstFunction && K <= lastFunction;
3030 }
3031 static DeclContext *castToDeclContext(const FunctionDecl *D) {
3032 return static_cast<DeclContext *>(const_cast<FunctionDecl*>(D));
3033 }
3034 static FunctionDecl *castFromDeclContext(const DeclContext *DC) {
3035 return static_cast<FunctionDecl *>(const_cast<DeclContext*>(DC));
3036 }
3037 };
3038
3039
3040 class FieldDecl : public DeclaratorDecl, public Mergeable<FieldDecl> {
3041
3042
3043
3044
3045 enum InitStorageKind {
3046
3047
3048
3049 ISK_NoInit = (unsigned) ICIS_NoInit,
3050
3051
3052
3053 ISK_InClassCopyInit = (unsigned) ICIS_CopyInit,
3054
3055
3056
3057 ISK_InClassListInit = (unsigned) ICIS_ListInit,
3058
3059
3060
3061 ISK_CapturedVLAType,
3062 };
3063
3064 LLVM_PREFERRED_TYPE(bool)
3065 unsigned BitField : 1;
3066 LLVM_PREFERRED_TYPE(bool)
3067 unsigned Mutable : 1;
3068 LLVM_PREFERRED_TYPE(InitStorageKind)
3069 unsigned StorageKind : 2;
3070 mutable unsigned CachedFieldIndex : 28;
3071
3072
3073
3074 struct InitAndBitWidthStorage {
3075 LazyDeclStmtPtr Init;
3076 Expr *BitWidth;
3077 };
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088 union {
3089
3090 LazyDeclStmtPtr Init;
3091
3092 Expr *BitWidth;
3093
3094 InitAndBitWidthStorage *InitAndBitWidth;
3095
3096 const VariableArrayType *CapturedVLAType;
3097 };
3098
3099 protected:
3100 FieldDecl(Kind DK, DeclContext *DC, SourceLocation StartLoc,
3101 SourceLocation IdLoc, const IdentifierInfo *Id, QualType T,
3102 TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
3103 InClassInitStyle InitStyle)
3104 : DeclaratorDecl(DK, DC, IdLoc, Id, T, TInfo, StartLoc), BitField(false),
3105 Mutable(Mutable), StorageKind((InitStorageKind)InitStyle),
3106 CachedFieldIndex(0), Init() {
3107 if (BW)
3108 setBitWidth(BW);
3109 }
3110
3111 public:
3112 friend class ASTDeclReader;
3113 friend class ASTDeclWriter;
3114
3115 static FieldDecl *Create(const ASTContext &C, DeclContext *DC,
3116 SourceLocation StartLoc, SourceLocation IdLoc,
3117 const IdentifierInfo *Id, QualType T,
3118 TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
3119 InClassInitStyle InitStyle);
3120
3121 static FieldDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3122
3123
3124
3125 unsigned getFieldIndex() const {
3126 const FieldDecl *Canonical = getCanonicalDecl();
3127 if (Canonical->CachedFieldIndex == 0) {
3128 Canonical->setCachedFieldIndex();
3129 assert(Canonical->CachedFieldIndex != 0);
3130 }
3131 return Canonical->CachedFieldIndex - 1;
3132 }
3133
3134 private:
3135
3136 void setCachedFieldIndex() const;
3137
3138 public:
3139
3140 bool isMutable() const { return Mutable; }
3141
3142
3143 bool isBitField() const { return BitField; }
3144
3145
3146 bool isUnnamedBitField() const { return isBitField() && !getDeclName(); }
3147
3148
3149
3150
3151
3152 bool isAnonymousStructOrUnion() const;
3153
3154
3155
3156 Expr *getBitWidth() const {
3157 if (!BitField)
3158 return nullptr;
3159 return hasInClassInitializer() ? InitAndBitWidth->BitWidth : BitWidth;
3160 }
3161
3162
3163
3164
3165
3166 unsigned getBitWidthValue() const;
3167
3168
3169
3170 void setBitWidth(Expr *Width) {
3171 assert(!hasCapturedVLAType() && !BitField &&
3172 "bit width or captured type already set");
3173 assert(Width && "no bit width specified");
3174 if (hasInClassInitializer())
3175 InitAndBitWidth =
3176 new (getASTContext()) InitAndBitWidthStorage{Init, Width};
3177 else
3178 BitWidth = Width;
3179 BitField = true;
3180 }
3181
3182
3183
3184 void removeBitWidth() {
3185 assert(isBitField() && "no bitfield width to remove");
3186 if (hasInClassInitializer()) {
3187
3188 auto ExistingInit = InitAndBitWidth->Init;
3189 Init = ExistingInit;
3190 }
3191 BitField = false;
3192 }
3193
3194
3195
3196
3197 bool isZeroLengthBitField() const;
3198
3199
3200
3201
3202 bool isZeroSize(const ASTContext &Ctx) const;
3203
3204
3205
3206 bool isPotentiallyOverlapping() const;
3207
3208
3209 InClassInitStyle getInClassInitStyle() const {
3210 return (StorageKind == ISK_CapturedVLAType ? ICIS_NoInit
3211 : (InClassInitStyle)StorageKind);
3212 }
3213
3214
3215 bool hasInClassInitializer() const {
3216 return getInClassInitStyle() != ICIS_NoInit;
3217 }
3218
3219
3220
3221 bool hasNonNullInClassInitializer() const {
3222 return hasInClassInitializer() && (BitField ? InitAndBitWidth->Init : Init);
3223 }
3224
3225
3226
3227
3228 Expr *getInClassInitializer() const;
3229
3230
3231 void setInClassInitializer(Expr *NewInit);
3232
3233
3234
3235 const FieldDecl *findCountedByField() const;
3236
3237 private:
3238 void setLazyInClassInitializer(LazyDeclStmtPtr NewInit);
3239
3240 public:
3241
3242 void removeInClassInitializer() {
3243 assert(hasInClassInitializer() && "no initializer to remove");
3244 StorageKind = ISK_NoInit;
3245 if (BitField) {
3246
3247 Expr *ExistingBitWidth = InitAndBitWidth->BitWidth;
3248 BitWidth = ExistingBitWidth;
3249 }
3250 }
3251
3252
3253
3254 bool hasCapturedVLAType() const {
3255 return StorageKind == ISK_CapturedVLAType;
3256 }
3257
3258
3259 const VariableArrayType *getCapturedVLAType() const {
3260 return hasCapturedVLAType() ? CapturedVLAType : nullptr;
3261 }
3262
3263
3264 void setCapturedVLAType(const VariableArrayType *VLAType);
3265
3266
3267
3268
3269
3270
3271 const RecordDecl *getParent() const {
3272 return dyn_cast<RecordDecl>(getDeclContext());
3273 }
3274
3275 RecordDecl *getParent() {
3276 return dyn_cast<RecordDecl>(getDeclContext());
3277 }
3278
3279 SourceRange getSourceRange() const override LLVM_READONLY;
3280
3281
3282 FieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
3283 const FieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
3284
3285
3286 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3287 static bool classofKind(Kind K) { return K >= firstField && K <= lastField; }
3288
3289 void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
3290 };
3291
3292
3293
3294
3295
3296 class EnumConstantDecl : public ValueDecl,
3297 public Mergeable<EnumConstantDecl>,
3298 public APIntStorage {
3299 Stmt *Init;
3300 bool IsUnsigned;
3301
3302 protected:
3303 EnumConstantDecl(const ASTContext &C, DeclContext *DC, SourceLocation L,
3304 IdentifierInfo *Id, QualType T, Expr *E,
3305 const llvm::APSInt &V);
3306
3307 public:
3308 friend class StmtIteratorBase;
3309
3310 static EnumConstantDecl *Create(ASTContext &C, EnumDecl *DC,
3311 SourceLocation L, IdentifierInfo *Id,
3312 QualType T, Expr *E,
3313 const llvm::APSInt &V);
3314 static EnumConstantDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3315
3316 const Expr *getInitExpr() const { return (const Expr*) Init; }
3317 Expr *getInitExpr() { return (Expr*) Init; }
3318 llvm::APSInt getInitVal() const {
3319 return llvm::APSInt(getValue(), IsUnsigned);
3320 }
3321
3322 void setInitExpr(Expr *E) { Init = (Stmt*) E; }
3323 void setInitVal(const ASTContext &C, const llvm::APSInt &V) {
3324 setValue(C, V);
3325 IsUnsigned = V.isUnsigned();
3326 }
3327
3328 SourceRange getSourceRange() const override LLVM_READONLY;
3329
3330
3331 EnumConstantDecl *getCanonicalDecl() override { return getFirstDecl(); }
3332 const EnumConstantDecl *getCanonicalDecl() const { return getFirstDecl(); }
3333
3334
3335 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3336 static bool classofKind(Kind K) { return K == EnumConstant; }
3337 };
3338
3339
3340
3341 class IndirectFieldDecl : public ValueDecl,
3342 public Mergeable<IndirectFieldDecl> {
3343 NamedDecl **Chaining;
3344 unsigned ChainingSize;
3345
3346 IndirectFieldDecl(ASTContext &C, DeclContext *DC, SourceLocation L,
3347 DeclarationName N, QualType T,
3348 MutableArrayRef<NamedDecl *> CH);
3349
3350 void anchor() override;
3351
3352 public:
3353 friend class ASTDeclReader;
3354
3355 static IndirectFieldDecl *Create(ASTContext &C, DeclContext *DC,
3356 SourceLocation L, const IdentifierInfo *Id,
3357 QualType T,
3358 llvm::MutableArrayRef<NamedDecl *> CH);
3359
3360 static IndirectFieldDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3361
3362 using chain_iterator = ArrayRef<NamedDecl *>::const_iterator;
3363
3364 ArrayRef<NamedDecl *> chain() const {
3365 return llvm::ArrayRef(Chaining, ChainingSize);
3366 }
3367 chain_iterator chain_begin() const { return chain().begin(); }
3368 chain_iterator chain_end() const { return chain().end(); }
3369
3370 unsigned getChainingSize() const { return ChainingSize; }
3371
3372 FieldDecl *getAnonField() const {
3373 assert(chain().size() >= 2);
3374 return cast<FieldDecl>(chain().back());
3375 }
3376
3377 VarDecl *getVarDecl() const {
3378 assert(chain().size() >= 2);
3379 return dyn_cast<VarDecl>(chain().front());
3380 }
3381
3382 IndirectFieldDecl *getCanonicalDecl() override { return getFirstDecl(); }
3383 const IndirectFieldDecl *getCanonicalDecl() const { return getFirstDecl(); }
3384
3385
3386 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3387 static bool classofKind(Kind K) { return K == IndirectField; }
3388 };
3389
3390
3391 class TypeDecl : public NamedDecl {
3392 friend class ASTContext;
3393 friend class ASTReader;
3394
3395
3396
3397
3398
3399 mutable const Type *TypeForDecl = nullptr;
3400
3401
3402 SourceLocation LocStart;
3403
3404 void anchor() override;
3405
3406 protected:
3407 TypeDecl(Kind DK, DeclContext *DC, SourceLocation L, const IdentifierInfo *Id,
3408 SourceLocation StartL = SourceLocation())
3409 : NamedDecl(DK, DC, L, Id), LocStart(StartL) {}
3410
3411 public:
3412
3413
3414
3415
3416 const Type *getTypeForDecl() const { return TypeForDecl; }
3417 void setTypeForDecl(const Type *TD) { TypeForDecl = TD; }
3418
3419 SourceLocation getBeginLoc() const LLVM_READONLY { return LocStart; }
3420 void setLocStart(SourceLocation L) { LocStart = L; }
3421 SourceRange getSourceRange() const override LLVM_READONLY {
3422 if (LocStart.isValid())
3423 return SourceRange(LocStart, getLocation());
3424 else
3425 return SourceRange(getLocation());
3426 }
3427
3428
3429 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3430 static bool classofKind(Kind K) { return K >= firstType && K <= lastType; }
3431 };
3432
3433
3434 class TypedefNameDecl : public TypeDecl, public Redeclarable<TypedefNameDecl> {
3435 struct alignas(8) ModedTInfo {
3436 TypeSourceInfo *first;
3437 QualType second;
3438 };
3439
3440
3441
3442 mutable llvm::PointerIntPair<
3443 llvm::PointerUnion<TypeSourceInfo *, ModedTInfo *>, 2>
3444 MaybeModedTInfo;
3445
3446 void anchor() override;
3447
3448 protected:
3449 TypedefNameDecl(Kind DK, ASTContext &C, DeclContext *DC,
3450 SourceLocation StartLoc, SourceLocation IdLoc,
3451 const IdentifierInfo *Id, TypeSourceInfo *TInfo)
3452 : TypeDecl(DK, DC, IdLoc, Id, StartLoc), redeclarable_base(C),
3453 MaybeModedTInfo(TInfo, 0) {}
3454
3455 using redeclarable_base = Redeclarable<TypedefNameDecl>;
3456
3457 TypedefNameDecl *getNextRedeclarationImpl() override {
3458 return getNextRedeclaration();
3459 }
3460
3461 TypedefNameDecl *getPreviousDeclImpl() override {
3462 return getPreviousDecl();
3463 }
3464
3465 TypedefNameDecl *getMostRecentDeclImpl() override {
3466 return getMostRecentDecl();
3467 }
3468
3469 public:
3470 using redecl_range = redeclarable_base::redecl_range;
3471 using redecl_iterator = redeclarable_base::redecl_iterator;
3472
3473 using redeclarable_base::redecls_begin;
3474 using redeclarable_base::redecls_end;
3475 using redeclarable_base::redecls;
3476 using redeclarable_base::getPreviousDecl;
3477 using redeclarable_base::getMostRecentDecl;
3478 using redeclarable_base::isFirstDecl;
3479
3480 bool isModed() const {
3481 return isa<ModedTInfo *>(MaybeModedTInfo.getPointer());
3482 }
3483
3484 TypeSourceInfo *getTypeSourceInfo() const {
3485 return isModed() ? cast<ModedTInfo *>(MaybeModedTInfo.getPointer())->first
3486 : cast<TypeSourceInfo *>(MaybeModedTInfo.getPointer());
3487 }
3488
3489 QualType getUnderlyingType() const {
3490 return isModed() ? cast<ModedTInfo *>(MaybeModedTInfo.getPointer())->second
3491 : cast<TypeSourceInfo *>(MaybeModedTInfo.getPointer())
3492 ->getType();
3493 }
3494
3495 void setTypeSourceInfo(TypeSourceInfo *newType) {
3496 MaybeModedTInfo.setPointer(newType);
3497 }
3498
3499 void setModedTypeSourceInfo(TypeSourceInfo *unmodedTSI, QualType modedTy) {
3500 MaybeModedTInfo.setPointer(new (getASTContext(), 8)
3501 ModedTInfo({unmodedTSI, modedTy}));
3502 }
3503
3504
3505 TypedefNameDecl *getCanonicalDecl() override { return getFirstDecl(); }
3506 const TypedefNameDecl *getCanonicalDecl() const { return getFirstDecl(); }
3507
3508
3509
3510
3511
3512
3513 TagDecl *getAnonDeclWithTypedefName(bool AnyRedecl = false) const;
3514
3515
3516
3517 bool isTransparentTag() const {
3518 if (MaybeModedTInfo.getInt())
3519 return MaybeModedTInfo.getInt() & 0x2;
3520 return isTransparentTagSlow();
3521 }
3522
3523
3524 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3525 static bool classofKind(Kind K) {
3526 return K >= firstTypedefName && K <= lastTypedefName;
3527 }
3528
3529 private:
3530 bool isTransparentTagSlow() const;
3531 };
3532
3533
3534
3535 class TypedefDecl : public TypedefNameDecl {
3536 TypedefDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3537 SourceLocation IdLoc, const IdentifierInfo *Id,
3538 TypeSourceInfo *TInfo)
3539 : TypedefNameDecl(Typedef, C, DC, StartLoc, IdLoc, Id, TInfo) {}
3540
3541 public:
3542 static TypedefDecl *Create(ASTContext &C, DeclContext *DC,
3543 SourceLocation StartLoc, SourceLocation IdLoc,
3544 const IdentifierInfo *Id, TypeSourceInfo *TInfo);
3545 static TypedefDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3546
3547 SourceRange getSourceRange() const override LLVM_READONLY;
3548
3549
3550 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3551 static bool classofKind(Kind K) { return K == Typedef; }
3552 };
3553
3554
3555
3556 class TypeAliasDecl : public TypedefNameDecl {
3557
3558 TypeAliasTemplateDecl *Template;
3559
3560 TypeAliasDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3561 SourceLocation IdLoc, const IdentifierInfo *Id,
3562 TypeSourceInfo *TInfo)
3563 : TypedefNameDecl(TypeAlias, C, DC, StartLoc, IdLoc, Id, TInfo),
3564 Template(nullptr) {}
3565
3566 public:
3567 static TypeAliasDecl *Create(ASTContext &C, DeclContext *DC,
3568 SourceLocation StartLoc, SourceLocation IdLoc,
3569 const IdentifierInfo *Id, TypeSourceInfo *TInfo);
3570 static TypeAliasDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3571
3572 SourceRange getSourceRange() const override LLVM_READONLY;
3573
3574 TypeAliasTemplateDecl *getDescribedAliasTemplate() const { return Template; }
3575 void setDescribedAliasTemplate(TypeAliasTemplateDecl *TAT) { Template = TAT; }
3576
3577
3578 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3579 static bool classofKind(Kind K) { return K == TypeAlias; }
3580 };
3581
3582
3583 class TagDecl : public TypeDecl,
3584 public DeclContext,
3585 public Redeclarable<TagDecl> {
3586
3587
3588 public:
3589
3590 using TagKind = TagTypeKind;
3591
3592 private:
3593 SourceRange BraceRange;
3594
3595
3596
3597 using ExtInfo = QualifierInfo;
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607 llvm::PointerUnion<TypedefNameDecl *, ExtInfo *> TypedefNameDeclOrQualifier;
3608
3609 bool hasExtInfo() const { return isa<ExtInfo *>(TypedefNameDeclOrQualifier); }
3610 ExtInfo *getExtInfo() { return cast<ExtInfo *>(TypedefNameDeclOrQualifier); }
3611 const ExtInfo *getExtInfo() const {
3612 return cast<ExtInfo *>(TypedefNameDeclOrQualifier);
3613 }
3614
3615 protected:
3616 TagDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
3617 SourceLocation L, IdentifierInfo *Id, TagDecl *PrevDecl,
3618 SourceLocation StartL);
3619
3620 using redeclarable_base = Redeclarable<TagDecl>;
3621
3622 TagDecl *getNextRedeclarationImpl() override {
3623 return getNextRedeclaration();
3624 }
3625
3626 TagDecl *getPreviousDeclImpl() override {
3627 return getPreviousDecl();
3628 }
3629
3630 TagDecl *getMostRecentDeclImpl() override {
3631 return getMostRecentDecl();
3632 }
3633
3634
3635
3636
3637 void completeDefinition();
3638
3639
3640 void setBeingDefined(bool V = true) { TagDeclBits.IsBeingDefined = V; }
3641
3642
3643
3644
3645
3646 void setMayHaveOutOfDateDef(bool V = true) {
3647 TagDeclBits.MayHaveOutOfDateDef = V;
3648 }
3649
3650 public:
3651 friend class ASTDeclReader;
3652 friend class ASTDeclWriter;
3653
3654 using redecl_range = redeclarable_base::redecl_range;
3655 using redecl_iterator = redeclarable_base::redecl_iterator;
3656
3657 using redeclarable_base::redecls_begin;
3658 using redeclarable_base::redecls_end;
3659 using redeclarable_base::redecls;
3660 using redeclarable_base::getPreviousDecl;
3661 using redeclarable_base::getMostRecentDecl;
3662 using redeclarable_base::isFirstDecl;
3663
3664 SourceRange getBraceRange() const { return BraceRange; }
3665 void setBraceRange(SourceRange R) { BraceRange = R; }
3666
3667
3668
3669 SourceLocation getInnerLocStart() const { return getBeginLoc(); }
3670
3671
3672
3673 SourceLocation getOuterLocStart() const;
3674 SourceRange getSourceRange() const override LLVM_READONLY;
3675
3676 TagDecl *getCanonicalDecl() override;
3677 const TagDecl *getCanonicalDecl() const {
3678 return const_cast<TagDecl*>(this)->getCanonicalDecl();
3679 }
3680
3681
3682
3683 bool isThisDeclarationADefinition() const {
3684 return isCompleteDefinition();
3685 }
3686
3687
3688 bool isCompleteDefinition() const { return TagDeclBits.IsCompleteDefinition; }
3689
3690
3691 void setCompleteDefinition(bool V = true) {
3692 TagDeclBits.IsCompleteDefinition = V;
3693 }
3694
3695
3696
3697 bool isCompleteDefinitionRequired() const {
3698 return TagDeclBits.IsCompleteDefinitionRequired;
3699 }
3700
3701
3702
3703 void setCompleteDefinitionRequired(bool V = true) {
3704 TagDeclBits.IsCompleteDefinitionRequired = V;
3705 }
3706
3707
3708 bool isBeingDefined() const { return TagDeclBits.IsBeingDefined; }
3709
3710
3711
3712 bool isEmbeddedInDeclarator() const {
3713 return TagDeclBits.IsEmbeddedInDeclarator;
3714 }
3715
3716
3717
3718 void setEmbeddedInDeclarator(bool isInDeclarator) {
3719 TagDeclBits.IsEmbeddedInDeclarator = isInDeclarator;
3720 }
3721
3722
3723 bool isFreeStanding() const { return TagDeclBits.IsFreeStanding; }
3724
3725
3726 void setFreeStanding(bool isFreeStanding = true) {
3727 TagDeclBits.IsFreeStanding = isFreeStanding;
3728 }
3729
3730
3731
3732
3733
3734 bool mayHaveOutOfDateDef() const { return TagDeclBits.MayHaveOutOfDateDef; }
3735
3736
3737
3738
3739 bool isDependentType() const { return isDependentContext(); }
3740
3741
3742
3743
3744
3745
3746 bool isThisDeclarationADemotedDefinition() const {
3747 return TagDeclBits.IsThisDeclarationADemotedDefinition;
3748 }
3749
3750
3751
3752 void demoteThisDefinitionToDeclaration() {
3753 assert(isCompleteDefinition() &&
3754 "Should demote definitions only, not forward declarations");
3755 setCompleteDefinition(false);
3756 TagDeclBits.IsThisDeclarationADemotedDefinition = true;
3757 }
3758
3759
3760
3761
3762
3763
3764 void startDefinition();
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774 TagDecl *getDefinition() const;
3775
3776 StringRef getKindName() const {
3777 return TypeWithKeyword::getTagTypeKindName(getTagKind());
3778 }
3779
3780 TagKind getTagKind() const {
3781 return static_cast<TagKind>(TagDeclBits.TagDeclKind);
3782 }
3783
3784 void setTagKind(TagKind TK) {
3785 TagDeclBits.TagDeclKind = llvm::to_underlying(TK);
3786 }
3787
3788 bool isStruct() const { return getTagKind() == TagTypeKind::Struct; }
3789 bool isInterface() const { return getTagKind() == TagTypeKind::Interface; }
3790 bool isClass() const { return getTagKind() == TagTypeKind::Class; }
3791 bool isUnion() const { return getTagKind() == TagTypeKind::Union; }
3792 bool isEnum() const { return getTagKind() == TagTypeKind::Enum; }
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809 bool hasNameForLinkage() const {
3810 return (getDeclName() || getTypedefNameForAnonDecl());
3811 }
3812
3813 TypedefNameDecl *getTypedefNameForAnonDecl() const {
3814 return hasExtInfo() ? nullptr
3815 : cast<TypedefNameDecl *>(TypedefNameDeclOrQualifier);
3816 }
3817
3818 void setTypedefNameForAnonDecl(TypedefNameDecl *TDD);
3819
3820
3821
3822 NestedNameSpecifier *getQualifier() const {
3823 return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
3824 : nullptr;
3825 }
3826
3827
3828
3829
3830 NestedNameSpecifierLoc getQualifierLoc() const {
3831 return hasExtInfo() ? getExtInfo()->QualifierLoc
3832 : NestedNameSpecifierLoc();
3833 }
3834
3835 void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc);
3836
3837 unsigned getNumTemplateParameterLists() const {
3838 return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0;
3839 }
3840
3841 TemplateParameterList *getTemplateParameterList(unsigned i) const {
3842 assert(i < getNumTemplateParameterLists());
3843 return getExtInfo()->TemplParamLists[i];
3844 }
3845
3846 using TypeDecl::printName;
3847 void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
3848
3849 void setTemplateParameterListsInfo(ASTContext &Context,
3850 ArrayRef<TemplateParameterList *> TPLists);
3851
3852
3853 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
3854 static bool classofKind(Kind K) { return K >= firstTag && K <= lastTag; }
3855
3856 static DeclContext *castToDeclContext(const TagDecl *D) {
3857 return static_cast<DeclContext *>(const_cast<TagDecl*>(D));
3858 }
3859
3860 static TagDecl *castFromDeclContext(const DeclContext *DC) {
3861 return static_cast<TagDecl *>(const_cast<DeclContext*>(DC));
3862 }
3863 };
3864
3865
3866
3867
3868 class EnumDecl : public TagDecl {
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886 llvm::PointerUnion<const Type *, TypeSourceInfo *> IntegerType;
3887
3888
3889
3890
3891
3892 QualType PromotionType;
3893
3894
3895
3896
3897 MemberSpecializationInfo *SpecializationInfo = nullptr;
3898
3899
3900
3901
3902 unsigned ODRHash;
3903
3904 EnumDecl(ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
3905 SourceLocation IdLoc, IdentifierInfo *Id, EnumDecl *PrevDecl,
3906 bool Scoped, bool ScopedUsingClassTag, bool Fixed);
3907
3908 void anchor() override;
3909
3910 void setInstantiationOfMemberEnum(ASTContext &C, EnumDecl *ED,
3911 TemplateSpecializationKind TSK);
3912
3913
3914
3915 void setNumPositiveBits(unsigned Num) {
3916 EnumDeclBits.NumPositiveBits = Num;
3917 assert(EnumDeclBits.NumPositiveBits == Num && "can't store this bitcount");
3918 }
3919
3920
3921
3922 void setNumNegativeBits(unsigned Num) { EnumDeclBits.NumNegativeBits = Num; }
3923
3924 public:
3925
3926
3927 void setScoped(bool Scoped = true) { EnumDeclBits.IsScoped = Scoped; }
3928
3929
3930
3931
3932
3933 void setScopedUsingClassTag(bool ScopedUCT = true) {
3934 EnumDeclBits.IsScopedUsingClassTag = ScopedUCT;
3935 }
3936
3937
3938
3939 void setFixed(bool Fixed = true) { EnumDeclBits.IsFixed = Fixed; }
3940
3941 private:
3942
3943 bool hasODRHash() const { return EnumDeclBits.HasODRHash; }
3944 void setHasODRHash(bool Hash = true) { EnumDeclBits.HasODRHash = Hash; }
3945
3946 public:
3947 friend class ASTDeclReader;
3948
3949 EnumDecl *getCanonicalDecl() override {
3950 return cast<EnumDecl>(TagDecl::getCanonicalDecl());
3951 }
3952 const EnumDecl *getCanonicalDecl() const {
3953 return const_cast<EnumDecl*>(this)->getCanonicalDecl();
3954 }
3955
3956 EnumDecl *getPreviousDecl() {
3957 return cast_or_null<EnumDecl>(
3958 static_cast<TagDecl *>(this)->getPreviousDecl());
3959 }
3960 const EnumDecl *getPreviousDecl() const {
3961 return const_cast<EnumDecl*>(this)->getPreviousDecl();
3962 }
3963
3964 EnumDecl *getMostRecentDecl() {
3965 return cast<EnumDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
3966 }
3967 const EnumDecl *getMostRecentDecl() const {
3968 return const_cast<EnumDecl*>(this)->getMostRecentDecl();
3969 }
3970
3971 EnumDecl *getDefinition() const {
3972 return cast_or_null<EnumDecl>(TagDecl::getDefinition());
3973 }
3974
3975 static EnumDecl *Create(ASTContext &C, DeclContext *DC,
3976 SourceLocation StartLoc, SourceLocation IdLoc,
3977 IdentifierInfo *Id, EnumDecl *PrevDecl,
3978 bool IsScoped, bool IsScopedUsingClassTag,
3979 bool IsFixed);
3980 static EnumDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
3981
3982
3983
3984 SourceRange getSourceRange() const override LLVM_READONLY;
3985
3986
3987
3988
3989
3990
3991 void completeDefinition(QualType NewType,
3992 QualType PromotionType,
3993 unsigned NumPositiveBits,
3994 unsigned NumNegativeBits);
3995
3996
3997 using enumerator_iterator = specific_decl_iterator<EnumConstantDecl>;
3998 using enumerator_range =
3999 llvm::iterator_range<specific_decl_iterator<EnumConstantDecl>>;
4000
4001 enumerator_range enumerators() const {
4002 return enumerator_range(enumerator_begin(), enumerator_end());
4003 }
4004
4005 enumerator_iterator enumerator_begin() const {
4006 const EnumDecl *E = getDefinition();
4007 if (!E)
4008 E = this;
4009 return enumerator_iterator(E->decls_begin());
4010 }
4011
4012 enumerator_iterator enumerator_end() const {
4013 const EnumDecl *E = getDefinition();
4014 if (!E)
4015 E = this;
4016 return enumerator_iterator(E->decls_end());
4017 }
4018
4019
4020 QualType getPromotionType() const { return PromotionType; }
4021
4022
4023 void setPromotionType(QualType T) { PromotionType = T; }
4024
4025
4026
4027
4028 QualType getIntegerType() const {
4029 if (!IntegerType)
4030 return QualType();
4031 if (const Type *T = dyn_cast<const Type *>(IntegerType))
4032 return QualType(T, 0);
4033 return cast<TypeSourceInfo *>(IntegerType)->getType().getUnqualifiedType();
4034 }
4035
4036
4037 void setIntegerType(QualType T) { IntegerType = T.getTypePtrOrNull(); }
4038
4039
4040 void setIntegerTypeSourceInfo(TypeSourceInfo *TInfo) { IntegerType = TInfo; }
4041
4042
4043
4044 TypeSourceInfo *getIntegerTypeSourceInfo() const {
4045 return dyn_cast_if_present<TypeSourceInfo *>(IntegerType);
4046 }
4047
4048
4049
4050 SourceRange getIntegerTypeRange() const LLVM_READONLY;
4051
4052
4053
4054 unsigned getNumPositiveBits() const { return EnumDeclBits.NumPositiveBits; }
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065 unsigned getNumNegativeBits() const { return EnumDeclBits.NumNegativeBits; }
4066
4067
4068
4069
4070 void getValueRange(llvm::APInt &Max, llvm::APInt &Min) const;
4071
4072
4073 bool isScoped() const { return EnumDeclBits.IsScoped; }
4074
4075
4076 bool isScopedUsingClassTag() const {
4077 return EnumDeclBits.IsScopedUsingClassTag;
4078 }
4079
4080
4081
4082 bool isFixed() const { return EnumDeclBits.IsFixed; }
4083
4084 unsigned getODRHash();
4085
4086
4087 bool isComplete() const {
4088
4089
4090 return isCompleteDefinition() || IntegerType;
4091 }
4092
4093
4094
4095 bool isClosed() const;
4096
4097
4098
4099 bool isClosedFlag() const;
4100
4101
4102
4103 bool isClosedNonFlag() const;
4104
4105
4106
4107 EnumDecl *getTemplateInstantiationPattern() const;
4108
4109
4110
4111
4112 EnumDecl *getInstantiatedFromMemberEnum() const;
4113
4114
4115
4116
4117 TemplateSpecializationKind getTemplateSpecializationKind() const;
4118
4119
4120
4121 void setTemplateSpecializationKind(TemplateSpecializationKind TSK,
4122 SourceLocation PointOfInstantiation = SourceLocation());
4123
4124
4125
4126
4127 MemberSpecializationInfo *getMemberSpecializationInfo() const {
4128 return SpecializationInfo;
4129 }
4130
4131
4132
4133 void setInstantiationOfMemberEnum(EnumDecl *ED,
4134 TemplateSpecializationKind TSK) {
4135 setInstantiationOfMemberEnum(getASTContext(), ED, TSK);
4136 }
4137
4138 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4139 static bool classofKind(Kind K) { return K == Enum; }
4140 };
4141
4142
4143
4144
4145
4146 enum class RecordArgPassingKind {
4147
4148 CanPassInRegs,
4149
4150
4151
4152
4153
4154
4155
4156
4157 CannotPassInRegs,
4158
4159
4160
4161
4162 CanNeverPassInRegs
4163 };
4164
4165
4166
4167
4168
4169 class RecordDecl : public TagDecl {
4170
4171
4172 public:
4173 friend class DeclContext;
4174 friend class ASTDeclReader;
4175
4176 protected:
4177 RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
4178 SourceLocation StartLoc, SourceLocation IdLoc,
4179 IdentifierInfo *Id, RecordDecl *PrevDecl);
4180
4181 public:
4182 static RecordDecl *Create(const ASTContext &C, TagKind TK, DeclContext *DC,
4183 SourceLocation StartLoc, SourceLocation IdLoc,
4184 IdentifierInfo *Id, RecordDecl* PrevDecl = nullptr);
4185 static RecordDecl *CreateDeserialized(const ASTContext &C, GlobalDeclID ID);
4186
4187 RecordDecl *getPreviousDecl() {
4188 return cast_or_null<RecordDecl>(
4189 static_cast<TagDecl *>(this)->getPreviousDecl());
4190 }
4191 const RecordDecl *getPreviousDecl() const {
4192 return const_cast<RecordDecl*>(this)->getPreviousDecl();
4193 }
4194
4195 RecordDecl *getMostRecentDecl() {
4196 return cast<RecordDecl>(static_cast<TagDecl *>(this)->getMostRecentDecl());
4197 }
4198 const RecordDecl *getMostRecentDecl() const {
4199 return const_cast<RecordDecl*>(this)->getMostRecentDecl();
4200 }
4201
4202 bool hasFlexibleArrayMember() const {
4203 return RecordDeclBits.HasFlexibleArrayMember;
4204 }
4205
4206 void setHasFlexibleArrayMember(bool V) {
4207 RecordDeclBits.HasFlexibleArrayMember = V;
4208 }
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221 bool isAnonymousStructOrUnion() const {
4222 return RecordDeclBits.AnonymousStructOrUnion;
4223 }
4224
4225 void setAnonymousStructOrUnion(bool Anon) {
4226 RecordDeclBits.AnonymousStructOrUnion = Anon;
4227 }
4228
4229 bool hasObjectMember() const { return RecordDeclBits.HasObjectMember; }
4230 void setHasObjectMember(bool val) { RecordDeclBits.HasObjectMember = val; }
4231
4232 bool hasVolatileMember() const { return RecordDeclBits.HasVolatileMember; }
4233
4234 void setHasVolatileMember(bool val) {
4235 RecordDeclBits.HasVolatileMember = val;
4236 }
4237
4238 bool hasLoadedFieldsFromExternalStorage() const {
4239 return RecordDeclBits.LoadedFieldsFromExternalStorage;
4240 }
4241
4242 void setHasLoadedFieldsFromExternalStorage(bool val) const {
4243 RecordDeclBits.LoadedFieldsFromExternalStorage = val;
4244 }
4245
4246
4247 bool isNonTrivialToPrimitiveDefaultInitialize() const {
4248 return RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize;
4249 }
4250
4251 void setNonTrivialToPrimitiveDefaultInitialize(bool V) {
4252 RecordDeclBits.NonTrivialToPrimitiveDefaultInitialize = V;
4253 }
4254
4255 bool isNonTrivialToPrimitiveCopy() const {
4256 return RecordDeclBits.NonTrivialToPrimitiveCopy;
4257 }
4258
4259 void setNonTrivialToPrimitiveCopy(bool V) {
4260 RecordDeclBits.NonTrivialToPrimitiveCopy = V;
4261 }
4262
4263 bool isNonTrivialToPrimitiveDestroy() const {
4264 return RecordDeclBits.NonTrivialToPrimitiveDestroy;
4265 }
4266
4267 void setNonTrivialToPrimitiveDestroy(bool V) {
4268 RecordDeclBits.NonTrivialToPrimitiveDestroy = V;
4269 }
4270
4271 bool hasNonTrivialToPrimitiveDefaultInitializeCUnion() const {
4272 return RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion;
4273 }
4274
4275 void setHasNonTrivialToPrimitiveDefaultInitializeCUnion(bool V) {
4276 RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion = V;
4277 }
4278
4279 bool hasNonTrivialToPrimitiveDestructCUnion() const {
4280 return RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion;
4281 }
4282
4283 void setHasNonTrivialToPrimitiveDestructCUnion(bool V) {
4284 RecordDeclBits.HasNonTrivialToPrimitiveDestructCUnion = V;
4285 }
4286
4287 bool hasNonTrivialToPrimitiveCopyCUnion() const {
4288 return RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion;
4289 }
4290
4291 void setHasNonTrivialToPrimitiveCopyCUnion(bool V) {
4292 RecordDeclBits.HasNonTrivialToPrimitiveCopyCUnion = V;
4293 }
4294
4295 bool hasUninitializedExplicitInitFields() const {
4296 return RecordDeclBits.HasUninitializedExplicitInitFields;
4297 }
4298
4299 void setHasUninitializedExplicitInitFields(bool V) {
4300 RecordDeclBits.HasUninitializedExplicitInitFields = V;
4301 }
4302
4303
4304
4305
4306 bool canPassInRegisters() const {
4307 return getArgPassingRestrictions() == RecordArgPassingKind::CanPassInRegs;
4308 }
4309
4310 RecordArgPassingKind getArgPassingRestrictions() const {
4311 return static_cast<RecordArgPassingKind>(
4312 RecordDeclBits.ArgPassingRestrictions);
4313 }
4314
4315 void setArgPassingRestrictions(RecordArgPassingKind Kind) {
4316 RecordDeclBits.ArgPassingRestrictions = llvm::to_underlying(Kind);
4317 }
4318
4319 bool isParamDestroyedInCallee() const {
4320 return RecordDeclBits.ParamDestroyedInCallee;
4321 }
4322
4323 void setParamDestroyedInCallee(bool V) {
4324 RecordDeclBits.ParamDestroyedInCallee = V;
4325 }
4326
4327 bool isRandomized() const { return RecordDeclBits.IsRandomized; }
4328
4329 void setIsRandomized(bool V) { RecordDeclBits.IsRandomized = V; }
4330
4331 void reorderDecls(const SmallVectorImpl<Decl *> &Decls);
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346 bool isInjectedClassName() const;
4347
4348
4349
4350 bool isLambda() const;
4351
4352
4353
4354 bool isCapturedRecord() const;
4355
4356
4357
4358 void setCapturedRecord();
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368 RecordDecl *getDefinition() const {
4369 return cast_or_null<RecordDecl>(TagDecl::getDefinition());
4370 }
4371
4372
4373
4374
4375 bool isOrContainsUnion() const;
4376
4377
4378
4379
4380 using field_iterator = specific_decl_iterator<FieldDecl>;
4381 using field_range = llvm::iterator_range<specific_decl_iterator<FieldDecl>>;
4382
4383 field_range fields() const { return field_range(field_begin(), field_end()); }
4384 field_iterator field_begin() const;
4385
4386 field_iterator field_end() const {
4387 return field_iterator(decl_iterator());
4388 }
4389
4390
4391 bool field_empty() const {
4392 return field_begin() == field_end();
4393 }
4394
4395
4396 virtual void completeDefinition();
4397
4398 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4399 static bool classofKind(Kind K) {
4400 return K >= firstRecord && K <= lastRecord;
4401 }
4402
4403
4404
4405
4406 bool isMsStruct(const ASTContext &C) const;
4407
4408
4409
4410
4411 bool mayInsertExtraPadding(bool EmitRemark = false) const;
4412
4413
4414
4415 const FieldDecl *findFirstNamedDataMember() const;
4416
4417
4418 unsigned getODRHash();
4419
4420 private:
4421
4422 void LoadFieldsFromExternalStorage() const;
4423
4424
4425 bool hasODRHash() const { return RecordDeclBits.ODRHash; }
4426 void setODRHash(unsigned Hash) { RecordDeclBits.ODRHash = Hash; }
4427 };
4428
4429 class FileScopeAsmDecl : public Decl {
4430 StringLiteral *AsmString;
4431 SourceLocation RParenLoc;
4432
4433 FileScopeAsmDecl(DeclContext *DC, StringLiteral *asmstring,
4434 SourceLocation StartL, SourceLocation EndL)
4435 : Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {}
4436
4437 virtual void anchor();
4438
4439 public:
4440 static FileScopeAsmDecl *Create(ASTContext &C, DeclContext *DC,
4441 StringLiteral *Str, SourceLocation AsmLoc,
4442 SourceLocation RParenLoc);
4443
4444 static FileScopeAsmDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
4445
4446 SourceLocation getAsmLoc() const { return getLocation(); }
4447 SourceLocation getRParenLoc() const { return RParenLoc; }
4448 void setRParenLoc(SourceLocation L) { RParenLoc = L; }
4449 SourceRange getSourceRange() const override LLVM_READONLY {
4450 return SourceRange(getAsmLoc(), getRParenLoc());
4451 }
4452
4453 const StringLiteral *getAsmString() const { return AsmString; }
4454 StringLiteral *getAsmString() { return AsmString; }
4455 void setAsmString(StringLiteral *Asm) { AsmString = Asm; }
4456
4457 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4458 static bool classofKind(Kind K) { return K == FileScopeAsm; }
4459 };
4460
4461
4462
4463
4464
4465
4466 class TopLevelStmtDecl : public Decl, public DeclContext {
4467 friend class ASTDeclReader;
4468 friend class ASTDeclWriter;
4469
4470 Stmt *Statement = nullptr;
4471 bool IsSemiMissing = false;
4472
4473 TopLevelStmtDecl(DeclContext *DC, SourceLocation L, Stmt *S)
4474 : Decl(TopLevelStmt, DC, L), DeclContext(TopLevelStmt), Statement(S) {}
4475
4476 virtual void anchor();
4477
4478 public:
4479 static TopLevelStmtDecl *Create(ASTContext &C, Stmt *Statement);
4480 static TopLevelStmtDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
4481
4482 SourceRange getSourceRange() const override LLVM_READONLY;
4483 Stmt *getStmt() { return Statement; }
4484 const Stmt *getStmt() const { return Statement; }
4485 void setStmt(Stmt *S);
4486 bool isSemiMissing() const { return IsSemiMissing; }
4487 void setSemiMissing(bool Missing = true) { IsSemiMissing = Missing; }
4488
4489 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4490 static bool classofKind(Kind K) { return K == TopLevelStmt; }
4491
4492 static DeclContext *castToDeclContext(const TopLevelStmtDecl *D) {
4493 return static_cast<DeclContext *>(const_cast<TopLevelStmtDecl *>(D));
4494 }
4495 static TopLevelStmtDecl *castFromDeclContext(const DeclContext *DC) {
4496 return static_cast<TopLevelStmtDecl *>(const_cast<DeclContext *>(DC));
4497 }
4498 };
4499
4500
4501
4502
4503 class BlockDecl : public Decl, public DeclContext {
4504
4505
4506 public:
4507
4508
4509 class Capture {
4510 enum {
4511 flag_isByRef = 0x1,
4512 flag_isNested = 0x2
4513 };
4514
4515
4516 llvm::PointerIntPair<VarDecl*, 2> VariableAndFlags;
4517
4518
4519
4520
4521 Expr *CopyExpr;
4522
4523 public:
4524 Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
4525 : VariableAndFlags(variable,
4526 (byRef ? flag_isByRef : 0) | (nested ? flag_isNested : 0)),
4527 CopyExpr(copy) {}
4528
4529
4530 VarDecl *getVariable() const { return VariableAndFlags.getPointer(); }
4531
4532
4533
4534 bool isByRef() const { return VariableAndFlags.getInt() & flag_isByRef; }
4535
4536 bool isEscapingByref() const {
4537 return getVariable()->isEscapingByref();
4538 }
4539
4540 bool isNonEscapingByref() const {
4541 return getVariable()->isNonEscapingByref();
4542 }
4543
4544
4545
4546 bool isNested() const { return VariableAndFlags.getInt() & flag_isNested; }
4547
4548 bool hasCopyExpr() const { return CopyExpr != nullptr; }
4549 Expr *getCopyExpr() const { return CopyExpr; }
4550 void setCopyExpr(Expr *e) { CopyExpr = e; }
4551 };
4552
4553 private:
4554
4555
4556
4557 ParmVarDecl **ParamInfo = nullptr;
4558 unsigned NumParams = 0;
4559
4560 Stmt *Body = nullptr;
4561 TypeSourceInfo *SignatureAsWritten = nullptr;
4562
4563 const Capture *Captures = nullptr;
4564 unsigned NumCaptures = 0;
4565
4566 unsigned ManglingNumber = 0;
4567 Decl *ManglingContextDecl = nullptr;
4568
4569 protected:
4570 BlockDecl(DeclContext *DC, SourceLocation CaretLoc);
4571
4572 public:
4573 static BlockDecl *Create(ASTContext &C, DeclContext *DC, SourceLocation L);
4574 static BlockDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
4575
4576 SourceLocation getCaretLocation() const { return getLocation(); }
4577
4578 bool isVariadic() const { return BlockDeclBits.IsVariadic; }
4579 void setIsVariadic(bool value) { BlockDeclBits.IsVariadic = value; }
4580
4581 CompoundStmt *getCompoundBody() const { return (CompoundStmt*) Body; }
4582 Stmt *getBody() const override { return (Stmt*) Body; }
4583 void setBody(CompoundStmt *B) { Body = (Stmt*) B; }
4584
4585 void setSignatureAsWritten(TypeSourceInfo *Sig) { SignatureAsWritten = Sig; }
4586 TypeSourceInfo *getSignatureAsWritten() const { return SignatureAsWritten; }
4587
4588
4589 ArrayRef<ParmVarDecl *> parameters() const {
4590 return {ParamInfo, getNumParams()};
4591 }
4592 MutableArrayRef<ParmVarDecl *> parameters() {
4593 return {ParamInfo, getNumParams()};
4594 }
4595
4596
4597 using param_iterator = MutableArrayRef<ParmVarDecl *>::iterator;
4598 using param_const_iterator = ArrayRef<ParmVarDecl *>::const_iterator;
4599
4600 bool param_empty() const { return parameters().empty(); }
4601 param_iterator param_begin() { return parameters().begin(); }
4602 param_iterator param_end() { return parameters().end(); }
4603 param_const_iterator param_begin() const { return parameters().begin(); }
4604 param_const_iterator param_end() const { return parameters().end(); }
4605 size_t param_size() const { return parameters().size(); }
4606
4607 unsigned getNumParams() const { return NumParams; }
4608
4609 const ParmVarDecl *getParamDecl(unsigned i) const {
4610 assert(i < getNumParams() && "Illegal param #");
4611 return ParamInfo[i];
4612 }
4613 ParmVarDecl *getParamDecl(unsigned i) {
4614 assert(i < getNumParams() && "Illegal param #");
4615 return ParamInfo[i];
4616 }
4617
4618 void setParams(ArrayRef<ParmVarDecl *> NewParamInfo);
4619
4620
4621
4622 bool hasCaptures() const { return NumCaptures || capturesCXXThis(); }
4623
4624
4625
4626 unsigned getNumCaptures() const { return NumCaptures; }
4627
4628 using capture_const_iterator = ArrayRef<Capture>::const_iterator;
4629
4630 ArrayRef<Capture> captures() const { return {Captures, NumCaptures}; }
4631
4632 capture_const_iterator capture_begin() const { return captures().begin(); }
4633 capture_const_iterator capture_end() const { return captures().end(); }
4634
4635 bool capturesCXXThis() const { return BlockDeclBits.CapturesCXXThis; }
4636 void setCapturesCXXThis(bool B = true) { BlockDeclBits.CapturesCXXThis = B; }
4637
4638 bool blockMissingReturnType() const {
4639 return BlockDeclBits.BlockMissingReturnType;
4640 }
4641
4642 void setBlockMissingReturnType(bool val = true) {
4643 BlockDeclBits.BlockMissingReturnType = val;
4644 }
4645
4646 bool isConversionFromLambda() const {
4647 return BlockDeclBits.IsConversionFromLambda;
4648 }
4649
4650 void setIsConversionFromLambda(bool val = true) {
4651 BlockDeclBits.IsConversionFromLambda = val;
4652 }
4653
4654 bool doesNotEscape() const { return BlockDeclBits.DoesNotEscape; }
4655 void setDoesNotEscape(bool B = true) { BlockDeclBits.DoesNotEscape = B; }
4656
4657 bool canAvoidCopyToHeap() const {
4658 return BlockDeclBits.CanAvoidCopyToHeap;
4659 }
4660 void setCanAvoidCopyToHeap(bool B = true) {
4661 BlockDeclBits.CanAvoidCopyToHeap = B;
4662 }
4663
4664 bool capturesVariable(const VarDecl *var) const;
4665
4666 void setCaptures(ASTContext &Context, ArrayRef<Capture> Captures,
4667 bool CapturesCXXThis);
4668
4669 unsigned getBlockManglingNumber() const { return ManglingNumber; }
4670
4671 Decl *getBlockManglingContextDecl() const { return ManglingContextDecl; }
4672
4673 void setBlockMangling(unsigned Number, Decl *Ctx) {
4674 ManglingNumber = Number;
4675 ManglingContextDecl = Ctx;
4676 }
4677
4678 SourceRange getSourceRange() const override LLVM_READONLY;
4679
4680 FunctionEffectsRef getFunctionEffects() const {
4681 if (const TypeSourceInfo *TSI = getSignatureAsWritten())
4682 if (const auto *FPT = TSI->getType()->getAs<FunctionProtoType>())
4683 return FPT->getFunctionEffects();
4684 return {};
4685 }
4686
4687
4688 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4689 static bool classofKind(Kind K) { return K == Block; }
4690 static DeclContext *castToDeclContext(const BlockDecl *D) {
4691 return static_cast<DeclContext *>(const_cast<BlockDecl*>(D));
4692 }
4693 static BlockDecl *castFromDeclContext(const DeclContext *DC) {
4694 return static_cast<BlockDecl *>(const_cast<DeclContext*>(DC));
4695 }
4696 };
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707 class OutlinedFunctionDecl final
4708 : public Decl,
4709 public DeclContext,
4710 private llvm::TrailingObjects<OutlinedFunctionDecl, ImplicitParamDecl *> {
4711 private:
4712
4713 unsigned NumParams;
4714
4715
4716 llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
4717
4718 explicit OutlinedFunctionDecl(DeclContext *DC, unsigned NumParams);
4719
4720 ImplicitParamDecl *const *getParams() const {
4721 return getTrailingObjects<ImplicitParamDecl *>();
4722 }
4723
4724 ImplicitParamDecl **getParams() {
4725 return getTrailingObjects<ImplicitParamDecl *>();
4726 }
4727
4728 public:
4729 friend class ASTDeclReader;
4730 friend class ASTDeclWriter;
4731 friend TrailingObjects;
4732
4733 static OutlinedFunctionDecl *Create(ASTContext &C, DeclContext *DC,
4734 unsigned NumParams);
4735 static OutlinedFunctionDecl *
4736 CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NumParams);
4737
4738 Stmt *getBody() const override;
4739 void setBody(Stmt *B);
4740
4741 bool isNothrow() const;
4742 void setNothrow(bool Nothrow = true);
4743
4744 unsigned getNumParams() const { return NumParams; }
4745
4746 ImplicitParamDecl *getParam(unsigned i) const {
4747 assert(i < NumParams);
4748 return getParams()[i];
4749 }
4750 void setParam(unsigned i, ImplicitParamDecl *P) {
4751 assert(i < NumParams);
4752 getParams()[i] = P;
4753 }
4754
4755
4756 using parameter_const_iterator = const ImplicitParamDecl *const *;
4757 using parameter_const_range = llvm::iterator_range<parameter_const_iterator>;
4758 parameter_const_range parameters() const {
4759 return {param_begin(), param_end()};
4760 }
4761 parameter_const_iterator param_begin() const { return getParams(); }
4762 parameter_const_iterator param_end() const { return getParams() + NumParams; }
4763
4764
4765 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4766 static bool classofKind(Kind K) { return K == OutlinedFunction; }
4767 static DeclContext *castToDeclContext(const OutlinedFunctionDecl *D) {
4768 return static_cast<DeclContext *>(const_cast<OutlinedFunctionDecl *>(D));
4769 }
4770 static OutlinedFunctionDecl *castFromDeclContext(const DeclContext *DC) {
4771 return static_cast<OutlinedFunctionDecl *>(const_cast<DeclContext *>(DC));
4772 }
4773 };
4774
4775
4776 class CapturedDecl final
4777 : public Decl,
4778 public DeclContext,
4779 private llvm::TrailingObjects<CapturedDecl, ImplicitParamDecl *> {
4780 protected:
4781 size_t numTrailingObjects(OverloadToken<ImplicitParamDecl>) {
4782 return NumParams;
4783 }
4784
4785 private:
4786
4787 unsigned NumParams;
4788
4789
4790 unsigned ContextParam;
4791
4792
4793 llvm::PointerIntPair<Stmt *, 1, bool> BodyAndNothrow;
4794
4795 explicit CapturedDecl(DeclContext *DC, unsigned NumParams);
4796
4797 ImplicitParamDecl *const *getParams() const {
4798 return getTrailingObjects<ImplicitParamDecl *>();
4799 }
4800
4801 ImplicitParamDecl **getParams() {
4802 return getTrailingObjects<ImplicitParamDecl *>();
4803 }
4804
4805 public:
4806 friend class ASTDeclReader;
4807 friend class ASTDeclWriter;
4808 friend TrailingObjects;
4809
4810 static CapturedDecl *Create(ASTContext &C, DeclContext *DC,
4811 unsigned NumParams);
4812 static CapturedDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
4813 unsigned NumParams);
4814
4815 Stmt *getBody() const override;
4816 void setBody(Stmt *B);
4817
4818 bool isNothrow() const;
4819 void setNothrow(bool Nothrow = true);
4820
4821 unsigned getNumParams() const { return NumParams; }
4822
4823 ImplicitParamDecl *getParam(unsigned i) const {
4824 assert(i < NumParams);
4825 return getParams()[i];
4826 }
4827 void setParam(unsigned i, ImplicitParamDecl *P) {
4828 assert(i < NumParams);
4829 getParams()[i] = P;
4830 }
4831
4832
4833 ArrayRef<ImplicitParamDecl *> parameters() const {
4834 return {getParams(), getNumParams()};
4835 }
4836 MutableArrayRef<ImplicitParamDecl *> parameters() {
4837 return {getParams(), getNumParams()};
4838 }
4839
4840
4841 ImplicitParamDecl *getContextParam() const {
4842 assert(ContextParam < NumParams);
4843 return getParam(ContextParam);
4844 }
4845 void setContextParam(unsigned i, ImplicitParamDecl *P) {
4846 assert(i < NumParams);
4847 ContextParam = i;
4848 setParam(i, P);
4849 }
4850 unsigned getContextParamPosition() const { return ContextParam; }
4851
4852 using param_iterator = ImplicitParamDecl *const *;
4853 using param_range = llvm::iterator_range<param_iterator>;
4854
4855
4856 param_iterator param_begin() const { return getParams(); }
4857
4858 param_iterator param_end() const { return getParams() + NumParams; }
4859
4860
4861 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4862 static bool classofKind(Kind K) { return K == Captured; }
4863 static DeclContext *castToDeclContext(const CapturedDecl *D) {
4864 return static_cast<DeclContext *>(const_cast<CapturedDecl *>(D));
4865 }
4866 static CapturedDecl *castFromDeclContext(const DeclContext *DC) {
4867 return static_cast<CapturedDecl *>(const_cast<DeclContext *>(DC));
4868 }
4869 };
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891 class ImportDecl final : public Decl,
4892 llvm::TrailingObjects<ImportDecl, SourceLocation> {
4893 friend class ASTContext;
4894 friend class ASTDeclReader;
4895 friend class ASTReader;
4896 friend TrailingObjects;
4897
4898
4899 Module *ImportedModule = nullptr;
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909 llvm::PointerIntPair<ImportDecl *, 1, bool> NextLocalImportAndComplete;
4910
4911 ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
4912 ArrayRef<SourceLocation> IdentifierLocs);
4913
4914 ImportDecl(DeclContext *DC, SourceLocation StartLoc, Module *Imported,
4915 SourceLocation EndLoc);
4916
4917 ImportDecl(EmptyShell Empty) : Decl(Import, Empty) {}
4918
4919 bool isImportComplete() const { return NextLocalImportAndComplete.getInt(); }
4920
4921 void setImportComplete(bool C) { NextLocalImportAndComplete.setInt(C); }
4922
4923
4924
4925 ImportDecl *getNextLocalImport() const {
4926 return NextLocalImportAndComplete.getPointer();
4927 }
4928
4929 void setNextLocalImport(ImportDecl *Import) {
4930 NextLocalImportAndComplete.setPointer(Import);
4931 }
4932
4933 public:
4934
4935 static ImportDecl *Create(ASTContext &C, DeclContext *DC,
4936 SourceLocation StartLoc, Module *Imported,
4937 ArrayRef<SourceLocation> IdentifierLocs);
4938
4939
4940
4941 static ImportDecl *CreateImplicit(ASTContext &C, DeclContext *DC,
4942 SourceLocation StartLoc, Module *Imported,
4943 SourceLocation EndLoc);
4944
4945
4946 static ImportDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID,
4947 unsigned NumLocations);
4948
4949
4950 Module *getImportedModule() const { return ImportedModule; }
4951
4952
4953
4954
4955
4956
4957 ArrayRef<SourceLocation> getIdentifierLocs() const;
4958
4959 SourceRange getSourceRange() const override LLVM_READONLY;
4960
4961 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
4962 static bool classofKind(Kind K) { return K == Import; }
4963 };
4964
4965
4966
4967
4968
4969
4970
4971 class ExportDecl final : public Decl, public DeclContext {
4972 virtual void anchor();
4973
4974 private:
4975 friend class ASTDeclReader;
4976
4977
4978 SourceLocation RBraceLoc;
4979
4980 ExportDecl(DeclContext *DC, SourceLocation ExportLoc)
4981 : Decl(Export, DC, ExportLoc), DeclContext(Export),
4982 RBraceLoc(SourceLocation()) {}
4983
4984 public:
4985 static ExportDecl *Create(ASTContext &C, DeclContext *DC,
4986 SourceLocation ExportLoc);
4987 static ExportDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
4988
4989 SourceLocation getExportLoc() const { return getLocation(); }
4990 SourceLocation getRBraceLoc() const { return RBraceLoc; }
4991 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
4992
4993 bool hasBraces() const { return RBraceLoc.isValid(); }
4994
4995 SourceLocation getEndLoc() const LLVM_READONLY {
4996 if (hasBraces())
4997 return RBraceLoc;
4998
4999
5000 return decls_empty() ? getLocation() : decls_begin()->getEndLoc();
5001 }
5002
5003 SourceRange getSourceRange() const override LLVM_READONLY {
5004 return SourceRange(getLocation(), getEndLoc());
5005 }
5006
5007 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5008 static bool classofKind(Kind K) { return K == Export; }
5009 static DeclContext *castToDeclContext(const ExportDecl *D) {
5010 return static_cast<DeclContext *>(const_cast<ExportDecl*>(D));
5011 }
5012 static ExportDecl *castFromDeclContext(const DeclContext *DC) {
5013 return static_cast<ExportDecl *>(const_cast<DeclContext*>(DC));
5014 }
5015 };
5016
5017
5018 class EmptyDecl : public Decl {
5019 EmptyDecl(DeclContext *DC, SourceLocation L) : Decl(Empty, DC, L) {}
5020
5021 virtual void anchor();
5022
5023 public:
5024 static EmptyDecl *Create(ASTContext &C, DeclContext *DC,
5025 SourceLocation L);
5026 static EmptyDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
5027
5028 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5029 static bool classofKind(Kind K) { return K == Empty; }
5030 };
5031
5032
5033 class HLSLBufferDecl final : public NamedDecl, public DeclContext {
5034
5035 SourceLocation LBraceLoc;
5036
5037 SourceLocation RBraceLoc;
5038
5039 SourceLocation KwLoc;
5040
5041 bool IsCBuffer;
5042
5043 HLSLBufferDecl(DeclContext *DC, bool CBuffer, SourceLocation KwLoc,
5044 IdentifierInfo *ID, SourceLocation IDLoc,
5045 SourceLocation LBrace);
5046
5047 public:
5048 static HLSLBufferDecl *Create(ASTContext &C, DeclContext *LexicalParent,
5049 bool CBuffer, SourceLocation KwLoc,
5050 IdentifierInfo *ID, SourceLocation IDLoc,
5051 SourceLocation LBrace);
5052 static HLSLBufferDecl *CreateDeserialized(ASTContext &C, GlobalDeclID ID);
5053
5054 SourceRange getSourceRange() const override LLVM_READONLY {
5055 return SourceRange(getLocStart(), RBraceLoc);
5056 }
5057 SourceLocation getLocStart() const LLVM_READONLY { return KwLoc; }
5058 SourceLocation getLBraceLoc() const { return LBraceLoc; }
5059 SourceLocation getRBraceLoc() const { return RBraceLoc; }
5060 void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
5061 bool isCBuffer() const { return IsCBuffer; }
5062
5063
5064 static bool classof(const Decl *D) { return classofKind(D->getKind()); }
5065 static bool classofKind(Kind K) { return K == HLSLBuffer; }
5066 static DeclContext *castToDeclContext(const HLSLBufferDecl *D) {
5067 return static_cast<DeclContext *>(const_cast<HLSLBufferDecl *>(D));
5068 }
5069 static HLSLBufferDecl *castFromDeclContext(const DeclContext *DC) {
5070 return static_cast<HLSLBufferDecl *>(const_cast<DeclContext *>(DC));
5071 }
5072
5073 friend class ASTDeclReader;
5074 friend class ASTDeclWriter;
5075 };
5076
5077
5078
5079 inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &PD,
5080 const NamedDecl *ND) {
5081 PD.AddTaggedVal(reinterpret_cast<uint64_t>(ND),
5082 DiagnosticsEngine::ak_nameddecl);
5083 return PD;
5084 }
5085
5086 template<typename decl_type>
5087 void Redeclarable<decl_type>::setPreviousDecl(decl_type *PrevDecl) {
5088
5089
5090 assert(RedeclLink.isFirst() &&
5091 "setPreviousDecl on a decl already in a redeclaration chain");
5092
5093 if (PrevDecl) {
5094
5095
5096
5097 First = PrevDecl->getFirstDecl();
5098 assert(First->RedeclLink.isFirst() && "Expected first");
5099 decl_type *MostRecent = First->getNextRedeclaration();
5100 RedeclLink = PreviousDeclLink(cast<decl_type>(MostRecent));
5101
5102
5103
5104 static_cast<decl_type*>(this)->IdentifierNamespace |=
5105 MostRecent->getIdentifierNamespace() &
5106 (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
5107 } else {
5108
5109 First = static_cast<decl_type*>(this);
5110 }
5111
5112
5113 First->RedeclLink.setLatest(static_cast<decl_type*>(this));
5114
5115 assert(!isa<NamedDecl>(static_cast<decl_type*>(this)) ||
5116 cast<NamedDecl>(static_cast<decl_type*>(this))->isLinkageValid());
5117 }
5118
5119
5120
5121
5122
5123
5124
5125 inline bool IsEnumDeclComplete(EnumDecl *ED) {
5126 return ED->isComplete();
5127 }
5128
5129
5130
5131
5132
5133 inline bool IsEnumDeclScoped(EnumDecl *ED) {
5134 return ED->isScoped();
5135 }
5136
5137
5138
5139
5140 static constexpr StringRef getOpenMPVariantManglingSeparatorStr() {
5141 return "$ompvariant";
5142 }
5143
5144
5145
5146 bool IsArmStreamingFunction(const FunctionDecl *FD,
5147 bool IncludeLocallyStreaming);
5148
5149
5150 bool hasArmZAState(const FunctionDecl *FD);
5151
5152
5153 bool hasArmZT0State(const FunctionDecl *FD);
5154
5155 }
5156
5157 #endif