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_DECLBASE_H
0014 #define LLVM_CLANG_AST_DECLBASE_H
0015
0016 #include "clang/AST/ASTDumperUtils.h"
0017 #include "clang/AST/AttrIterator.h"
0018 #include "clang/AST/DeclID.h"
0019 #include "clang/AST/DeclarationName.h"
0020 #include "clang/AST/SelectorLocationsKind.h"
0021 #include "clang/Basic/IdentifierTable.h"
0022 #include "clang/Basic/LLVM.h"
0023 #include "clang/Basic/LangOptions.h"
0024 #include "clang/Basic/SourceLocation.h"
0025 #include "clang/Basic/Specifiers.h"
0026 #include "llvm/ADT/ArrayRef.h"
0027 #include "llvm/ADT/PointerIntPair.h"
0028 #include "llvm/ADT/PointerUnion.h"
0029 #include "llvm/ADT/iterator.h"
0030 #include "llvm/ADT/iterator_range.h"
0031 #include "llvm/Support/Casting.h"
0032 #include "llvm/Support/Compiler.h"
0033 #include "llvm/Support/PrettyStackTrace.h"
0034 #include "llvm/Support/VersionTuple.h"
0035 #include <algorithm>
0036 #include <cassert>
0037 #include <cstddef>
0038 #include <iterator>
0039 #include <string>
0040 #include <type_traits>
0041 #include <utility>
0042
0043 namespace clang {
0044
0045 class ASTContext;
0046 class ASTMutationListener;
0047 class Attr;
0048 class BlockDecl;
0049 class DeclContext;
0050 class ExternalSourceSymbolAttr;
0051 class FunctionDecl;
0052 class FunctionType;
0053 class IdentifierInfo;
0054 enum class Linkage : unsigned char;
0055 class LinkageSpecDecl;
0056 class Module;
0057 class NamedDecl;
0058 class ObjCContainerDecl;
0059 class ObjCMethodDecl;
0060 struct PrintingPolicy;
0061 class RecordDecl;
0062 class SourceManager;
0063 class Stmt;
0064 class StoredDeclsMap;
0065 class TemplateDecl;
0066 class TemplateParameterList;
0067 class TranslationUnitDecl;
0068 class UsingDirectiveDecl;
0069
0070
0071
0072 enum AvailabilityResult {
0073 AR_Available = 0,
0074 AR_NotYetIntroduced,
0075 AR_Deprecated,
0076 AR_Unavailable
0077 };
0078
0079
0080
0081
0082
0083
0084
0085
0086 class alignas(8) Decl {
0087 public:
0088
0089 enum Kind {
0090 #define DECL(DERIVED, BASE) DERIVED,
0091 #define ABSTRACT_DECL(DECL)
0092 #define DECL_RANGE(BASE, START, END) \
0093 first##BASE = START, last##BASE = END,
0094 #define LAST_DECL_RANGE(BASE, START, END) \
0095 first##BASE = START, last##BASE = END
0096 #include "clang/AST/DeclNodes.inc"
0097 };
0098
0099
0100
0101
0102 struct EmptyShell {};
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115 enum IdentifierNamespace {
0116
0117 IDNS_Label = 0x0001,
0118
0119
0120
0121
0122
0123
0124
0125 IDNS_Tag = 0x0002,
0126
0127
0128
0129
0130 IDNS_Type = 0x0004,
0131
0132
0133
0134
0135
0136 IDNS_Member = 0x0008,
0137
0138
0139
0140 IDNS_Namespace = 0x0010,
0141
0142
0143
0144 IDNS_Ordinary = 0x0020,
0145
0146
0147 IDNS_ObjCProtocol = 0x0040,
0148
0149
0150
0151
0152 IDNS_OrdinaryFriend = 0x0080,
0153
0154
0155
0156
0157 IDNS_TagFriend = 0x0100,
0158
0159
0160
0161
0162
0163 IDNS_Using = 0x0200,
0164
0165
0166
0167
0168 IDNS_NonMemberOperator = 0x0400,
0169
0170
0171
0172
0173
0174
0175 IDNS_LocalExtern = 0x0800,
0176
0177
0178 IDNS_OMPReduction = 0x1000,
0179
0180
0181 IDNS_OMPMapper = 0x2000,
0182 };
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198 enum ObjCDeclQualifier {
0199 OBJC_TQ_None = 0x0,
0200 OBJC_TQ_In = 0x1,
0201 OBJC_TQ_Inout = 0x2,
0202 OBJC_TQ_Out = 0x4,
0203 OBJC_TQ_Bycopy = 0x8,
0204 OBJC_TQ_Byref = 0x10,
0205 OBJC_TQ_Oneway = 0x20,
0206
0207
0208
0209
0210 OBJC_TQ_CSNullability = 0x40
0211 };
0212
0213
0214
0215
0216 enum class ModuleOwnershipKind : unsigned char {
0217
0218 Unowned,
0219
0220
0221
0222
0223
0224
0225 Visible,
0226
0227
0228
0229 VisibleWhenImported,
0230
0231
0232
0233
0234 ReachableWhenImported,
0235
0236
0237
0238
0239
0240 ModulePrivate
0241 };
0242
0243 protected:
0244
0245
0246
0247
0248
0249 llvm::PointerIntPair<Decl *, 3, ModuleOwnershipKind> NextInContextAndBits;
0250
0251 private:
0252 friend class DeclContext;
0253
0254 struct MultipleDC {
0255 DeclContext *SemanticDC;
0256 DeclContext *LexicalDC;
0257 };
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272 llvm::PointerUnion<DeclContext*, MultipleDC*> DeclCtx;
0273
0274 bool isInSemaDC() const { return isa<DeclContext *>(DeclCtx); }
0275 bool isOutOfSemaDC() const { return isa<MultipleDC *>(DeclCtx); }
0276
0277 MultipleDC *getMultipleDC() const { return cast<MultipleDC *>(DeclCtx); }
0278
0279 DeclContext *getSemanticDC() const { return cast<DeclContext *>(DeclCtx); }
0280
0281
0282 SourceLocation Loc;
0283
0284
0285 LLVM_PREFERRED_TYPE(Kind)
0286 unsigned DeclKind : 7;
0287
0288
0289 LLVM_PREFERRED_TYPE(bool)
0290 unsigned InvalidDecl : 1;
0291
0292
0293 LLVM_PREFERRED_TYPE(bool)
0294 unsigned HasAttrs : 1;
0295
0296
0297
0298 LLVM_PREFERRED_TYPE(bool)
0299 unsigned Implicit : 1;
0300
0301
0302
0303 LLVM_PREFERRED_TYPE(bool)
0304 unsigned Used : 1;
0305
0306
0307
0308
0309
0310 LLVM_PREFERRED_TYPE(bool)
0311 unsigned Referenced : 1;
0312
0313
0314
0315
0316 LLVM_PREFERRED_TYPE(bool)
0317 unsigned TopLevelDeclInObjCContainer : 1;
0318
0319
0320 static bool StatisticsEnabled;
0321
0322 protected:
0323 friend class ASTDeclMerger;
0324 friend class ASTDeclReader;
0325 friend class ASTDeclWriter;
0326 friend class ASTNodeImporter;
0327 friend class ASTReader;
0328 friend class CXXClassMemberWrapper;
0329 friend class LinkageComputer;
0330 friend class RecordDecl;
0331 template<typename decl_type> friend class Redeclarable;
0332
0333
0334
0335 LLVM_PREFERRED_TYPE(AccessSpecifier)
0336 unsigned Access : 2;
0337
0338
0339 LLVM_PREFERRED_TYPE(bool)
0340 unsigned FromASTFile : 1;
0341
0342
0343 LLVM_PREFERRED_TYPE(IdentifierNamespace)
0344 unsigned IdentifierNamespace : 14;
0345
0346
0347 LLVM_PREFERRED_TYPE(Linkage)
0348 mutable unsigned CacheValidAndLinkage : 3;
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359 void *operator new(std::size_t Size, const ASTContext &Ctx, GlobalDeclID ID,
0360 std::size_t Extra = 0);
0361
0362
0363 void *operator new(std::size_t Size, const ASTContext &Ctx,
0364 DeclContext *Parent, std::size_t Extra = 0);
0365
0366 private:
0367 bool AccessDeclContextCheck() const;
0368
0369
0370
0371 static ModuleOwnershipKind getModuleOwnershipKindForChildOf(DeclContext *DC) {
0372 if (DC) {
0373 auto *D = cast<Decl>(DC);
0374 auto MOK = D->getModuleOwnershipKind();
0375 if (MOK != ModuleOwnershipKind::Unowned &&
0376 (!D->isFromASTFile() || D->hasLocalOwningModuleStorage()))
0377 return MOK;
0378
0379
0380 }
0381 return ModuleOwnershipKind::Unowned;
0382 }
0383
0384 public:
0385 Decl() = delete;
0386 Decl(const Decl&) = delete;
0387 Decl(Decl &&) = delete;
0388 Decl &operator=(const Decl&) = delete;
0389 Decl &operator=(Decl&&) = delete;
0390
0391 protected:
0392 Decl(Kind DK, DeclContext *DC, SourceLocation L)
0393 : NextInContextAndBits(nullptr, getModuleOwnershipKindForChildOf(DC)),
0394 DeclCtx(DC), Loc(L), DeclKind(DK), InvalidDecl(false), HasAttrs(false),
0395 Implicit(false), Used(false), Referenced(false),
0396 TopLevelDeclInObjCContainer(false), Access(AS_none), FromASTFile(0),
0397 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
0398 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
0399 if (StatisticsEnabled) add(DK);
0400 }
0401
0402 Decl(Kind DK, EmptyShell Empty)
0403 : DeclKind(DK), InvalidDecl(false), HasAttrs(false), Implicit(false),
0404 Used(false), Referenced(false), TopLevelDeclInObjCContainer(false),
0405 Access(AS_none), FromASTFile(0),
0406 IdentifierNamespace(getIdentifierNamespaceForKind(DK)),
0407 CacheValidAndLinkage(llvm::to_underlying(Linkage::Invalid)) {
0408 if (StatisticsEnabled) add(DK);
0409 }
0410
0411 virtual ~Decl();
0412
0413
0414 void updateOutOfDate(IdentifierInfo &II) const;
0415
0416 Linkage getCachedLinkage() const {
0417 return static_cast<Linkage>(CacheValidAndLinkage);
0418 }
0419
0420 void setCachedLinkage(Linkage L) const {
0421 CacheValidAndLinkage = llvm::to_underlying(L);
0422 }
0423
0424 bool hasCachedLinkage() const {
0425 return CacheValidAndLinkage;
0426 }
0427
0428 public:
0429
0430 virtual SourceRange getSourceRange() const LLVM_READONLY {
0431 return SourceRange(getLocation(), getLocation());
0432 }
0433
0434 SourceLocation getBeginLoc() const LLVM_READONLY {
0435 return getSourceRange().getBegin();
0436 }
0437
0438 SourceLocation getEndLoc() const LLVM_READONLY {
0439 return getSourceRange().getEnd();
0440 }
0441
0442 SourceLocation getLocation() const { return Loc; }
0443 void setLocation(SourceLocation L) { Loc = L; }
0444
0445 Kind getKind() const { return static_cast<Kind>(DeclKind); }
0446 const char *getDeclKindName() const;
0447
0448 Decl *getNextDeclInContext() { return NextInContextAndBits.getPointer(); }
0449 const Decl *getNextDeclInContext() const {return NextInContextAndBits.getPointer();}
0450
0451 DeclContext *getDeclContext() {
0452 if (isInSemaDC())
0453 return getSemanticDC();
0454 return getMultipleDC()->SemanticDC;
0455 }
0456 const DeclContext *getDeclContext() const {
0457 return const_cast<Decl*>(this)->getDeclContext();
0458 }
0459
0460
0461
0462
0463 DeclContext *getNonTransparentDeclContext();
0464 const DeclContext *getNonTransparentDeclContext() const {
0465 return const_cast<Decl *>(this)->getNonTransparentDeclContext();
0466 }
0467
0468
0469
0470
0471
0472
0473 Decl *getNonClosureContext();
0474 const Decl *getNonClosureContext() const {
0475 return const_cast<Decl*>(this)->getNonClosureContext();
0476 }
0477
0478 TranslationUnitDecl *getTranslationUnitDecl();
0479 const TranslationUnitDecl *getTranslationUnitDecl() const {
0480 return const_cast<Decl*>(this)->getTranslationUnitDecl();
0481 }
0482
0483 bool isInAnonymousNamespace() const;
0484
0485 bool isInStdNamespace() const;
0486
0487
0488 bool isFileContextDecl() const;
0489
0490
0491
0492
0493
0494 static bool isFlexibleArrayMemberLike(
0495 ASTContext &Context, const Decl *D, QualType Ty,
0496 LangOptions::StrictFlexArraysLevelKind StrictFlexArraysLevel,
0497 bool IgnoreTemplateOrMacroSubstitution);
0498
0499 ASTContext &getASTContext() const LLVM_READONLY;
0500
0501
0502
0503 const LangOptions &getLangOpts() const LLVM_READONLY;
0504
0505 void setAccess(AccessSpecifier AS) {
0506 Access = AS;
0507 assert(AccessDeclContextCheck());
0508 }
0509
0510 AccessSpecifier getAccess() const {
0511 assert(AccessDeclContextCheck());
0512 return AccessSpecifier(Access);
0513 }
0514
0515
0516
0517 AccessSpecifier getAccessUnsafe() const {
0518 return AccessSpecifier(Access);
0519 }
0520
0521 bool hasAttrs() const { return HasAttrs; }
0522
0523 void setAttrs(const AttrVec& Attrs) {
0524 return setAttrsImpl(Attrs, getASTContext());
0525 }
0526
0527 AttrVec &getAttrs() {
0528 return const_cast<AttrVec&>(const_cast<const Decl*>(this)->getAttrs());
0529 }
0530
0531 const AttrVec &getAttrs() const;
0532 void dropAttrs();
0533 void addAttr(Attr *A);
0534
0535 using attr_iterator = AttrVec::const_iterator;
0536 using attr_range = llvm::iterator_range<attr_iterator>;
0537
0538 attr_range attrs() const {
0539 return attr_range(attr_begin(), attr_end());
0540 }
0541
0542 attr_iterator attr_begin() const {
0543 return hasAttrs() ? getAttrs().begin() : nullptr;
0544 }
0545 attr_iterator attr_end() const {
0546 return hasAttrs() ? getAttrs().end() : nullptr;
0547 }
0548
0549 template <typename... Ts> void dropAttrs() {
0550 if (!HasAttrs) return;
0551
0552 AttrVec &Vec = getAttrs();
0553 llvm::erase_if(Vec, [](Attr *A) { return isa<Ts...>(A); });
0554
0555 if (Vec.empty())
0556 HasAttrs = false;
0557 }
0558
0559 template <typename T> void dropAttr() { dropAttrs<T>(); }
0560
0561 template <typename T>
0562 llvm::iterator_range<specific_attr_iterator<T>> specific_attrs() const {
0563 return llvm::make_range(specific_attr_begin<T>(), specific_attr_end<T>());
0564 }
0565
0566 template <typename T>
0567 specific_attr_iterator<T> specific_attr_begin() const {
0568 return specific_attr_iterator<T>(attr_begin());
0569 }
0570
0571 template <typename T>
0572 specific_attr_iterator<T> specific_attr_end() const {
0573 return specific_attr_iterator<T>(attr_end());
0574 }
0575
0576 template<typename T> T *getAttr() const {
0577 return hasAttrs() ? getSpecificAttr<T>(getAttrs()) : nullptr;
0578 }
0579
0580 template<typename T> bool hasAttr() const {
0581 return hasAttrs() && hasSpecificAttr<T>(getAttrs());
0582 }
0583
0584
0585
0586 unsigned getMaxAlignment() const;
0587
0588
0589
0590 void setInvalidDecl(bool Invalid = true);
0591 bool isInvalidDecl() const { return (bool) InvalidDecl; }
0592
0593
0594
0595
0596 bool isImplicit() const { return Implicit; }
0597 void setImplicit(bool I = true) { Implicit = I; }
0598
0599
0600
0601
0602
0603
0604
0605 bool isUsed(bool CheckUsedAttr = true) const;
0606
0607
0608
0609
0610
0611 void setIsUsed() { getCanonicalDecl()->Used = true; }
0612
0613
0614
0615
0616
0617 void markUsed(ASTContext &C);
0618
0619
0620 bool isReferenced() const;
0621
0622
0623
0624 bool isThisDeclarationReferenced() const { return Referenced; }
0625
0626 void setReferenced(bool R = true) { Referenced = R; }
0627
0628
0629
0630
0631 bool isTopLevelDeclInObjCContainer() const {
0632 return TopLevelDeclInObjCContainer;
0633 }
0634
0635 void setTopLevelDeclInObjCContainer(bool V = true) {
0636 TopLevelDeclInObjCContainer = V;
0637 }
0638
0639
0640
0641 ExternalSourceSymbolAttr *getExternalSourceSymbolAttr() const;
0642
0643
0644
0645 bool isModulePrivate() const {
0646 return getModuleOwnershipKind() == ModuleOwnershipKind::ModulePrivate;
0647 }
0648
0649
0650
0651
0652
0653
0654
0655
0656
0657
0658
0659
0660
0661 bool isInExportDeclContext() const;
0662
0663 bool isInvisibleOutsideTheOwningModule() const {
0664 return getModuleOwnershipKind() > ModuleOwnershipKind::VisibleWhenImported;
0665 }
0666
0667
0668 bool isInAnotherModuleUnit() const;
0669
0670
0671 bool isInCurrentModuleUnit() const;
0672
0673
0674
0675 bool shouldEmitInExternalSource() const;
0676
0677
0678 bool isFromExplicitGlobalModule() const;
0679
0680
0681 bool isFromGlobalModule() const;
0682
0683
0684 bool isInNamedModule() const;
0685
0686
0687 bool isFromHeaderUnit() const;
0688
0689
0690
0691 bool hasDefiningAttr() const;
0692
0693
0694 const Attr *getDefiningAttr() const;
0695
0696 protected:
0697
0698
0699 void setModulePrivate() {
0700
0701
0702 if (getModuleOwnershipKind() == ModuleOwnershipKind::Unowned)
0703 return;
0704 setModuleOwnershipKind(ModuleOwnershipKind::ModulePrivate);
0705 }
0706
0707 public:
0708
0709
0710
0711 void setFromASTFile() {
0712 FromASTFile = true;
0713 }
0714
0715
0716
0717 void setOwningModuleID(unsigned ID);
0718
0719 public:
0720
0721
0722
0723
0724
0725
0726
0727
0728
0729
0730
0731
0732
0733
0734
0735
0736
0737 AvailabilityResult
0738 getAvailability(std::string *Message = nullptr,
0739 VersionTuple EnclosingVersion = VersionTuple(),
0740 StringRef *RealizedPlatform = nullptr) const;
0741
0742
0743
0744
0745
0746
0747
0748 VersionTuple getVersionIntroduced() const;
0749
0750
0751
0752
0753
0754
0755 bool isDeprecated(std::string *Message = nullptr) const {
0756 return getAvailability(Message) == AR_Deprecated;
0757 }
0758
0759
0760
0761
0762
0763
0764 bool isUnavailable(std::string *Message = nullptr) const {
0765 return getAvailability(Message) == AR_Unavailable;
0766 }
0767
0768
0769
0770
0771
0772
0773
0774 bool isWeakImported() const;
0775
0776
0777
0778
0779
0780
0781
0782 bool canBeWeakImported(bool &IsDefinition) const;
0783
0784
0785
0786 bool isFromASTFile() const { return FromASTFile; }
0787
0788
0789
0790 GlobalDeclID getGlobalID() const;
0791
0792
0793
0794 unsigned getOwningModuleID() const;
0795
0796 private:
0797 Module *getOwningModuleSlow() const;
0798
0799 protected:
0800 bool hasLocalOwningModuleStorage() const;
0801
0802 public:
0803
0804
0805 Module *getImportedOwningModule() const {
0806 if (!isFromASTFile() || !hasOwningModule())
0807 return nullptr;
0808
0809 return getOwningModuleSlow();
0810 }
0811
0812
0813
0814 Module *getLocalOwningModule() const {
0815 if (isFromASTFile() || !hasOwningModule())
0816 return nullptr;
0817
0818 assert(hasLocalOwningModuleStorage() &&
0819 "owned local decl but no local module storage");
0820 return reinterpret_cast<Module *const *>(this)[-1];
0821 }
0822 void setLocalOwningModule(Module *M) {
0823 assert(!isFromASTFile() && hasOwningModule() &&
0824 hasLocalOwningModuleStorage() &&
0825 "should not have a cached owning module");
0826 reinterpret_cast<Module **>(this)[-1] = M;
0827 }
0828
0829
0830 bool hasOwningModule() const {
0831 return getModuleOwnershipKind() != ModuleOwnershipKind::Unowned;
0832 }
0833
0834
0835 Module *getOwningModule() const {
0836 return isFromASTFile() ? getImportedOwningModule() : getLocalOwningModule();
0837 }
0838
0839
0840
0841 Module *getTopLevelOwningNamedModule() const;
0842
0843
0844
0845 Module *getOwningModuleForLinkage() const;
0846
0847
0848
0849
0850
0851
0852 bool isUnconditionallyVisible() const {
0853 return (int)getModuleOwnershipKind() <= (int)ModuleOwnershipKind::Visible;
0854 }
0855
0856 bool isReachable() const {
0857 return (int)getModuleOwnershipKind() <=
0858 (int)ModuleOwnershipKind::ReachableWhenImported;
0859 }
0860
0861
0862
0863 void setVisibleDespiteOwningModule() {
0864 if (!isUnconditionallyVisible())
0865 setModuleOwnershipKind(ModuleOwnershipKind::Visible);
0866 }
0867
0868
0869 ModuleOwnershipKind getModuleOwnershipKind() const {
0870 return NextInContextAndBits.getInt();
0871 }
0872
0873
0874 void setModuleOwnershipKind(ModuleOwnershipKind MOK) {
0875 assert(!(getModuleOwnershipKind() == ModuleOwnershipKind::Unowned &&
0876 MOK != ModuleOwnershipKind::Unowned && !isFromASTFile() &&
0877 !hasLocalOwningModuleStorage()) &&
0878 "no storage available for owning module for this declaration");
0879 NextInContextAndBits.setInt(MOK);
0880 }
0881
0882 unsigned getIdentifierNamespace() const {
0883 return IdentifierNamespace;
0884 }
0885
0886 bool isInIdentifierNamespace(unsigned NS) const {
0887 return getIdentifierNamespace() & NS;
0888 }
0889
0890 static unsigned getIdentifierNamespaceForKind(Kind DK);
0891
0892 bool hasTagIdentifierNamespace() const {
0893 return isTagIdentifierNamespace(getIdentifierNamespace());
0894 }
0895
0896 static bool isTagIdentifierNamespace(unsigned NS) {
0897
0898 return (NS & ~IDNS_TagFriend) == (IDNS_Tag | IDNS_Type);
0899 }
0900
0901
0902
0903
0904
0905
0906
0907
0908
0909
0910
0911 DeclContext *getLexicalDeclContext() {
0912 if (isInSemaDC())
0913 return getSemanticDC();
0914 return getMultipleDC()->LexicalDC;
0915 }
0916 const DeclContext *getLexicalDeclContext() const {
0917 return const_cast<Decl*>(this)->getLexicalDeclContext();
0918 }
0919
0920
0921
0922 virtual bool isOutOfLine() const;
0923
0924
0925
0926 void setDeclContext(DeclContext *DC);
0927
0928 void setLexicalDeclContext(DeclContext *DC);
0929
0930
0931
0932 bool isTemplated() const;
0933
0934
0935
0936 unsigned getTemplateDepth() const;
0937
0938
0939
0940
0941
0942 bool isDefinedOutsideFunctionOrMethod() const {
0943 return getParentFunctionOrMethod() == nullptr;
0944 }
0945
0946
0947
0948
0949
0950
0951
0952
0953
0954
0955
0956
0957
0958 bool isInLocalScopeForInstantiation() const;
0959
0960
0961
0962 const DeclContext *
0963 getParentFunctionOrMethod(bool LexicalParent = false) const;
0964 DeclContext *getParentFunctionOrMethod(bool LexicalParent = false) {
0965 return const_cast<DeclContext *>(
0966 const_cast<const Decl *>(this)->getParentFunctionOrMethod(
0967 LexicalParent));
0968 }
0969
0970
0971 virtual Decl *getCanonicalDecl() { return this; }
0972 const Decl *getCanonicalDecl() const {
0973 return const_cast<Decl*>(this)->getCanonicalDecl();
0974 }
0975
0976
0977 bool isCanonicalDecl() const { return getCanonicalDecl() == this; }
0978
0979 protected:
0980
0981
0982
0983
0984 virtual Decl *getNextRedeclarationImpl() { return this; }
0985
0986
0987
0988 virtual Decl *getPreviousDeclImpl() { return nullptr; }
0989
0990
0991
0992 virtual Decl *getMostRecentDeclImpl() { return this; }
0993
0994 public:
0995
0996 class redecl_iterator {
0997
0998 Decl *Current = nullptr;
0999 Decl *Starter;
1000
1001 public:
1002 using value_type = Decl *;
1003 using reference = const value_type &;
1004 using pointer = const value_type *;
1005 using iterator_category = std::forward_iterator_tag;
1006 using difference_type = std::ptrdiff_t;
1007
1008 redecl_iterator() = default;
1009 explicit redecl_iterator(Decl *C) : Current(C), Starter(C) {}
1010
1011 reference operator*() const { return Current; }
1012 value_type operator->() const { return Current; }
1013
1014 redecl_iterator& operator++() {
1015 assert(Current && "Advancing while iterator has reached end");
1016
1017 Decl *Next = Current->getNextRedeclarationImpl();
1018 assert(Next && "Should return next redeclaration or itself, never null!");
1019 Current = (Next != Starter) ? Next : nullptr;
1020 return *this;
1021 }
1022
1023 redecl_iterator operator++(int) {
1024 redecl_iterator tmp(*this);
1025 ++(*this);
1026 return tmp;
1027 }
1028
1029 friend bool operator==(redecl_iterator x, redecl_iterator y) {
1030 return x.Current == y.Current;
1031 }
1032
1033 friend bool operator!=(redecl_iterator x, redecl_iterator y) {
1034 return x.Current != y.Current;
1035 }
1036 };
1037
1038 using redecl_range = llvm::iterator_range<redecl_iterator>;
1039
1040
1041
1042 redecl_range redecls() const {
1043 return redecl_range(redecls_begin(), redecls_end());
1044 }
1045
1046 redecl_iterator redecls_begin() const {
1047 return redecl_iterator(const_cast<Decl *>(this));
1048 }
1049
1050 redecl_iterator redecls_end() const { return redecl_iterator(); }
1051
1052
1053
1054 Decl *getPreviousDecl() { return getPreviousDeclImpl(); }
1055
1056
1057
1058 const Decl *getPreviousDecl() const {
1059 return const_cast<Decl *>(this)->getPreviousDeclImpl();
1060 }
1061
1062
1063 bool isFirstDecl() const {
1064 return getPreviousDecl() == nullptr;
1065 }
1066
1067
1068
1069 Decl *getMostRecentDecl() { return getMostRecentDeclImpl(); }
1070
1071
1072
1073 const Decl *getMostRecentDecl() const {
1074 return const_cast<Decl *>(this)->getMostRecentDeclImpl();
1075 }
1076
1077
1078
1079
1080 virtual Stmt* getBody() const { return nullptr; }
1081
1082
1083
1084
1085
1086 virtual bool hasBody() const { return getBody() != nullptr; }
1087
1088
1089
1090 SourceLocation getBodyRBrace() const;
1091
1092
1093 static void add(Kind k);
1094 static void EnableStatistics();
1095 static void PrintStats();
1096
1097
1098
1099 bool isTemplateParameter() const;
1100
1101
1102
1103 bool isTemplateParameterPack() const;
1104
1105
1106 bool isParameterPack() const;
1107
1108
1109 bool isTemplateDecl() const;
1110
1111
1112 bool isFunctionOrFunctionTemplate() const {
1113 return (DeclKind >= Decl::firstFunction &&
1114 DeclKind <= Decl::lastFunction) ||
1115 DeclKind == FunctionTemplate;
1116 }
1117
1118
1119
1120
1121
1122
1123
1124 TemplateDecl *getDescribedTemplate() const;
1125
1126
1127
1128 const TemplateParameterList *getDescribedTemplateParams() const;
1129
1130
1131
1132 FunctionDecl *getAsFunction() LLVM_READONLY;
1133
1134 const FunctionDecl *getAsFunction() const {
1135 return const_cast<Decl *>(this)->getAsFunction();
1136 }
1137
1138
1139
1140
1141
1142
1143
1144 void setLocalExternDecl() {
1145 Decl *Prev = getPreviousDecl();
1146 IdentifierNamespace &= ~IDNS_Ordinary;
1147
1148
1149
1150
1151 assert((IdentifierNamespace & ~(IDNS_OrdinaryFriend | IDNS_Tag)) == 0 &&
1152 "namespace is not ordinary");
1153
1154 IdentifierNamespace |= IDNS_LocalExtern;
1155 if (Prev && Prev->getIdentifierNamespace() & IDNS_Ordinary)
1156 IdentifierNamespace |= IDNS_Ordinary;
1157 }
1158
1159
1160
1161
1162 bool isLocalExternDecl() const {
1163 return IdentifierNamespace & IDNS_LocalExtern;
1164 }
1165
1166
1167
1168
1169
1170
1171
1172
1173 void setObjectOfFriendDecl(bool PerformFriendInjection = false) {
1174 unsigned OldNS = IdentifierNamespace;
1175 assert((OldNS & (IDNS_Tag | IDNS_Ordinary |
1176 IDNS_TagFriend | IDNS_OrdinaryFriend |
1177 IDNS_LocalExtern | IDNS_NonMemberOperator)) &&
1178 "namespace includes neither ordinary nor tag");
1179 assert(!(OldNS & ~(IDNS_Tag | IDNS_Ordinary | IDNS_Type |
1180 IDNS_TagFriend | IDNS_OrdinaryFriend |
1181 IDNS_LocalExtern | IDNS_NonMemberOperator)) &&
1182 "namespace includes other than ordinary or tag");
1183
1184 Decl *Prev = getPreviousDecl();
1185 IdentifierNamespace &= ~(IDNS_Ordinary | IDNS_Tag | IDNS_Type);
1186
1187 if (OldNS & (IDNS_Tag | IDNS_TagFriend)) {
1188 IdentifierNamespace |= IDNS_TagFriend;
1189 if (PerformFriendInjection ||
1190 (Prev && Prev->getIdentifierNamespace() & IDNS_Tag))
1191 IdentifierNamespace |= IDNS_Tag | IDNS_Type;
1192 }
1193
1194 if (OldNS & (IDNS_Ordinary | IDNS_OrdinaryFriend |
1195 IDNS_LocalExtern | IDNS_NonMemberOperator)) {
1196 IdentifierNamespace |= IDNS_OrdinaryFriend;
1197 if (PerformFriendInjection ||
1198 (Prev && Prev->getIdentifierNamespace() & IDNS_Ordinary))
1199 IdentifierNamespace |= IDNS_Ordinary;
1200 }
1201 }
1202
1203
1204
1205
1206
1207 void clearIdentifierNamespace() { IdentifierNamespace = 0; }
1208
1209 enum FriendObjectKind {
1210 FOK_None,
1211 FOK_Declared,
1212 FOK_Undeclared
1213 };
1214
1215
1216
1217
1218
1219 FriendObjectKind getFriendObjectKind() const {
1220 unsigned mask =
1221 (IdentifierNamespace & (IDNS_TagFriend | IDNS_OrdinaryFriend));
1222 if (!mask) return FOK_None;
1223 return (IdentifierNamespace & (IDNS_Tag | IDNS_Ordinary) ? FOK_Declared
1224 : FOK_Undeclared);
1225 }
1226
1227
1228 void setNonMemberOperator() {
1229 assert(getKind() == Function || getKind() == FunctionTemplate);
1230 assert((IdentifierNamespace & IDNS_Ordinary) &&
1231 "visible non-member operators should be in ordinary namespace");
1232 IdentifierNamespace |= IDNS_NonMemberOperator;
1233 }
1234
1235 static bool classofKind(Kind K) { return true; }
1236 static DeclContext *castToDeclContext(const Decl *);
1237 static Decl *castFromDeclContext(const DeclContext *);
1238
1239 void print(raw_ostream &Out, unsigned Indentation = 0,
1240 bool PrintInstantiation = false) const;
1241 void print(raw_ostream &Out, const PrintingPolicy &Policy,
1242 unsigned Indentation = 0, bool PrintInstantiation = false) const;
1243 static void printGroup(Decl** Begin, unsigned NumDecls,
1244 raw_ostream &Out, const PrintingPolicy &Policy,
1245 unsigned Indentation = 0);
1246
1247
1248 void dump() const;
1249
1250
1251 void dumpColor() const;
1252
1253 void dump(raw_ostream &Out, bool Deserialize = false,
1254 ASTDumpOutputFormat OutputFormat = ADOF_Default) const;
1255
1256
1257 int64_t getID() const;
1258
1259
1260
1261
1262
1263
1264
1265 const FunctionType *getFunctionType(bool BlocksToo = true) const;
1266
1267
1268
1269 bool isFunctionPointerType() const;
1270
1271 private:
1272 void setAttrsImpl(const AttrVec& Attrs, ASTContext &Ctx);
1273 void setDeclContextsImpl(DeclContext *SemaDC, DeclContext *LexicalDC,
1274 ASTContext &Ctx);
1275
1276 protected:
1277 ASTMutationListener *getASTMutationListener() const;
1278 };
1279
1280
1281 inline bool declaresSameEntity(const Decl *D1, const Decl *D2) {
1282 if (!D1 || !D2)
1283 return false;
1284
1285 if (D1 == D2)
1286 return true;
1287
1288 return D1->getCanonicalDecl() == D2->getCanonicalDecl();
1289 }
1290
1291
1292
1293 class PrettyStackTraceDecl : public llvm::PrettyStackTraceEntry {
1294 const Decl *TheDecl;
1295 SourceLocation Loc;
1296 SourceManager &SM;
1297 const char *Message;
1298
1299 public:
1300 PrettyStackTraceDecl(const Decl *theDecl, SourceLocation L,
1301 SourceManager &sm, const char *Msg)
1302 : TheDecl(theDecl), Loc(L), SM(sm), Message(Msg) {}
1303
1304 void print(raw_ostream &OS) const override;
1305 };
1306 }
1307
1308
1309
1310 namespace llvm {
1311 template <> struct PointerLikeTypeTraits<::clang::NamedDecl *> {
1312 static inline void *getAsVoidPointer(::clang::NamedDecl *P) { return P; }
1313 static inline ::clang::NamedDecl *getFromVoidPointer(void *P) {
1314 return static_cast<::clang::NamedDecl *>(P);
1315 }
1316 static constexpr int NumLowBitsAvailable = 3;
1317 };
1318 }
1319
1320 namespace clang {
1321
1322 class DeclListNode {
1323 friend class ASTContext;
1324 friend class StoredDeclsList;
1325 public:
1326 using Decls = llvm::PointerUnion<NamedDecl*, DeclListNode*>;
1327 class iterator {
1328 friend class DeclContextLookupResult;
1329 friend class StoredDeclsList;
1330
1331 Decls Ptr;
1332 iterator(Decls Node) : Ptr(Node) { }
1333 public:
1334 using difference_type = ptrdiff_t;
1335 using value_type = NamedDecl*;
1336 using pointer = void;
1337 using reference = value_type;
1338 using iterator_category = std::forward_iterator_tag;
1339
1340 iterator() = default;
1341
1342 reference operator*() const {
1343 assert(Ptr && "dereferencing end() iterator");
1344 if (DeclListNode *CurNode = dyn_cast<DeclListNode *>(Ptr))
1345 return CurNode->D;
1346 return cast<NamedDecl *>(Ptr);
1347 }
1348 void operator->() const { }
1349 bool operator==(const iterator &X) const { return Ptr == X.Ptr; }
1350 bool operator!=(const iterator &X) const { return Ptr != X.Ptr; }
1351 inline iterator &operator++() {
1352 assert(!Ptr.isNull() && "Advancing empty iterator");
1353
1354 if (DeclListNode *CurNode = dyn_cast<DeclListNode *>(Ptr))
1355 Ptr = CurNode->Rest;
1356 else
1357 Ptr = nullptr;
1358 return *this;
1359 }
1360 iterator operator++(int) {
1361 iterator temp = *this;
1362 ++(*this);
1363 return temp;
1364 }
1365
1366 iterator end() { return iterator(); }
1367 };
1368 private:
1369 NamedDecl *D = nullptr;
1370 Decls Rest = nullptr;
1371 DeclListNode(NamedDecl *ND) : D(ND) {}
1372 };
1373
1374
1375 class DeclContextLookupResult {
1376 using Decls = DeclListNode::Decls;
1377
1378
1379 Decls Result;
1380
1381 public:
1382 DeclContextLookupResult() = default;
1383 DeclContextLookupResult(Decls Result) : Result(Result) {}
1384
1385 using iterator = DeclListNode::iterator;
1386 using const_iterator = iterator;
1387 using reference = iterator::reference;
1388
1389 iterator begin() { return iterator(Result); }
1390 iterator end() { return iterator(); }
1391 const_iterator begin() const {
1392 return const_cast<DeclContextLookupResult*>(this)->begin();
1393 }
1394 const_iterator end() const { return iterator(); }
1395
1396 bool empty() const { return Result.isNull(); }
1397 bool isSingleResult() const { return isa_and_present<NamedDecl *>(Result); }
1398 reference front() const { return *begin(); }
1399
1400
1401
1402
1403
1404 template<class T> T *find_first() const {
1405 for (auto *D : *this)
1406 if (T *Decl = dyn_cast<T>(D))
1407 return Decl;
1408
1409 return nullptr;
1410 }
1411 };
1412
1413
1414 enum class DeductionCandidate : unsigned char {
1415 Normal,
1416 Copy,
1417 Aggregate,
1418 };
1419
1420 enum class RecordArgPassingKind;
1421 enum class OMPDeclareReductionInitKind;
1422 enum class ObjCImplementationControl;
1423 enum class LinkageSpecLanguageIDs;
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442 class DeclContext {
1443
1444 friend class ASTDeclReader;
1445
1446 friend class ASTDeclWriter;
1447
1448
1449 friend class ExternalASTSource;
1450
1451 friend class DependentDiagnostic;
1452
1453
1454 friend class ASTWriter;
1455
1456 protected:
1457 enum { NumOdrHashBits = 25 };
1458
1459
1460
1461
1462
1463
1464
1465 class DeclContextBitfields {
1466 friend class DeclContext;
1467
1468 LLVM_PREFERRED_TYPE(Decl::Kind)
1469 uint64_t DeclKind : 7;
1470
1471
1472
1473
1474 LLVM_PREFERRED_TYPE(bool)
1475 mutable uint64_t ExternalLexicalStorage : 1;
1476
1477
1478
1479
1480 LLVM_PREFERRED_TYPE(bool)
1481 mutable uint64_t ExternalVisibleStorage : 1;
1482
1483
1484
1485
1486
1487 LLVM_PREFERRED_TYPE(bool)
1488 mutable uint64_t NeedToReconcileExternalVisibleStorage : 1;
1489
1490
1491
1492 LLVM_PREFERRED_TYPE(bool)
1493 mutable uint64_t HasLazyLocalLexicalLookups : 1;
1494
1495
1496
1497 LLVM_PREFERRED_TYPE(bool)
1498 mutable uint64_t HasLazyExternalLexicalLookups : 1;
1499
1500
1501
1502
1503 LLVM_PREFERRED_TYPE(bool)
1504 mutable uint64_t UseQualifiedLookup : 1;
1505 };
1506
1507
1508 enum { NumDeclContextBits = 13 };
1509
1510
1511
1512
1513 class NamespaceDeclBitfields {
1514 friend class NamespaceDecl;
1515
1516 LLVM_PREFERRED_TYPE(DeclContextBitfields)
1517 uint64_t : NumDeclContextBits;
1518
1519
1520 LLVM_PREFERRED_TYPE(bool)
1521 uint64_t IsInline : 1;
1522
1523
1524 LLVM_PREFERRED_TYPE(bool)
1525 uint64_t IsNested : 1;
1526 };
1527
1528
1529 enum { NumNamespaceDeclBits = NumDeclContextBits + 2 };
1530
1531
1532
1533
1534 class TagDeclBitfields {
1535 friend class TagDecl;
1536
1537 LLVM_PREFERRED_TYPE(DeclContextBitfields)
1538 uint64_t : NumDeclContextBits;
1539
1540
1541 LLVM_PREFERRED_TYPE(TagTypeKind)
1542 uint64_t TagDeclKind : 3;
1543
1544
1545
1546
1547 LLVM_PREFERRED_TYPE(bool)
1548 uint64_t IsCompleteDefinition : 1;
1549
1550
1551 LLVM_PREFERRED_TYPE(bool)
1552 uint64_t IsBeingDefined : 1;
1553
1554
1555
1556 LLVM_PREFERRED_TYPE(bool)
1557 uint64_t IsEmbeddedInDeclarator : 1;
1558
1559
1560 LLVM_PREFERRED_TYPE(bool)
1561 uint64_t IsFreeStanding : 1;
1562
1563
1564
1565
1566
1567 LLVM_PREFERRED_TYPE(bool)
1568 uint64_t MayHaveOutOfDateDef : 1;
1569
1570
1571
1572 LLVM_PREFERRED_TYPE(bool)
1573 uint64_t IsCompleteDefinitionRequired : 1;
1574
1575
1576
1577 LLVM_PREFERRED_TYPE(bool)
1578 uint64_t IsThisDeclarationADemotedDefinition : 1;
1579 };
1580
1581
1582 enum { NumTagDeclBits = NumDeclContextBits + 10 };
1583
1584
1585
1586
1587 class EnumDeclBitfields {
1588 friend class EnumDecl;
1589
1590 LLVM_PREFERRED_TYPE(TagDeclBitfields)
1591 uint64_t : NumTagDeclBits;
1592
1593
1594
1595 uint64_t NumPositiveBits : 8;
1596
1597
1598
1599 uint64_t NumNegativeBits : 8;
1600
1601
1602
1603 LLVM_PREFERRED_TYPE(bool)
1604 uint64_t IsScoped : 1;
1605
1606
1607
1608
1609
1610 LLVM_PREFERRED_TYPE(bool)
1611 uint64_t IsScopedUsingClassTag : 1;
1612
1613
1614
1615 LLVM_PREFERRED_TYPE(bool)
1616 uint64_t IsFixed : 1;
1617
1618
1619 LLVM_PREFERRED_TYPE(bool)
1620 uint64_t HasODRHash : 1;
1621 };
1622
1623
1624 enum { NumEnumDeclBits = NumTagDeclBits + 20 };
1625
1626
1627
1628
1629 class RecordDeclBitfields {
1630 friend class RecordDecl;
1631
1632 LLVM_PREFERRED_TYPE(TagDeclBitfields)
1633 uint64_t : NumTagDeclBits;
1634
1635
1636
1637
1638 LLVM_PREFERRED_TYPE(bool)
1639 uint64_t HasFlexibleArrayMember : 1;
1640
1641
1642 LLVM_PREFERRED_TYPE(bool)
1643 uint64_t AnonymousStructOrUnion : 1;
1644
1645
1646
1647 LLVM_PREFERRED_TYPE(bool)
1648 uint64_t HasObjectMember : 1;
1649
1650
1651
1652 LLVM_PREFERRED_TYPE(bool)
1653 uint64_t HasVolatileMember : 1;
1654
1655
1656
1657
1658
1659 LLVM_PREFERRED_TYPE(bool)
1660 mutable uint64_t LoadedFieldsFromExternalStorage : 1;
1661
1662
1663 LLVM_PREFERRED_TYPE(bool)
1664 uint64_t NonTrivialToPrimitiveDefaultInitialize : 1;
1665 LLVM_PREFERRED_TYPE(bool)
1666 uint64_t NonTrivialToPrimitiveCopy : 1;
1667 LLVM_PREFERRED_TYPE(bool)
1668 uint64_t NonTrivialToPrimitiveDestroy : 1;
1669
1670
1671
1672
1673 LLVM_PREFERRED_TYPE(bool)
1674 uint64_t HasNonTrivialToPrimitiveDefaultInitializeCUnion : 1;
1675 LLVM_PREFERRED_TYPE(bool)
1676 uint64_t HasNonTrivialToPrimitiveDestructCUnion : 1;
1677 LLVM_PREFERRED_TYPE(bool)
1678 uint64_t HasNonTrivialToPrimitiveCopyCUnion : 1;
1679
1680
1681
1682
1683
1684
1685 LLVM_PREFERRED_TYPE(bool)
1686 uint64_t HasUninitializedExplicitInitFields : 1;
1687
1688
1689 LLVM_PREFERRED_TYPE(bool)
1690 uint64_t ParamDestroyedInCallee : 1;
1691
1692
1693 LLVM_PREFERRED_TYPE(RecordArgPassingKind)
1694 uint64_t ArgPassingRestrictions : 2;
1695
1696
1697 LLVM_PREFERRED_TYPE(bool)
1698 uint64_t IsRandomized : 1;
1699
1700
1701
1702 uint64_t ODRHash : NumOdrHashBits;
1703 };
1704
1705
1706 enum { NumRecordDeclBits = NumTagDeclBits + 41 };
1707
1708
1709
1710
1711 class OMPDeclareReductionDeclBitfields {
1712 friend class OMPDeclareReductionDecl;
1713
1714 LLVM_PREFERRED_TYPE(DeclContextBitfields)
1715 uint64_t : NumDeclContextBits;
1716
1717
1718
1719 LLVM_PREFERRED_TYPE(OMPDeclareReductionInitKind)
1720 uint64_t InitializerKind : 2;
1721 };
1722
1723
1724
1725 enum { NumOMPDeclareReductionDeclBits = NumDeclContextBits + 2 };
1726
1727
1728
1729
1730
1731 class FunctionDeclBitfields {
1732 friend class FunctionDecl;
1733
1734 friend class CXXDeductionGuideDecl;
1735
1736 LLVM_PREFERRED_TYPE(DeclContextBitfields)
1737 uint64_t : NumDeclContextBits;
1738
1739 LLVM_PREFERRED_TYPE(StorageClass)
1740 uint64_t SClass : 3;
1741 LLVM_PREFERRED_TYPE(bool)
1742 uint64_t IsInline : 1;
1743 LLVM_PREFERRED_TYPE(bool)
1744 uint64_t IsInlineSpecified : 1;
1745
1746 LLVM_PREFERRED_TYPE(bool)
1747 uint64_t IsVirtualAsWritten : 1;
1748 LLVM_PREFERRED_TYPE(bool)
1749 uint64_t IsPureVirtual : 1;
1750 LLVM_PREFERRED_TYPE(bool)
1751 uint64_t HasInheritedPrototype : 1;
1752 LLVM_PREFERRED_TYPE(bool)
1753 uint64_t HasWrittenPrototype : 1;
1754 LLVM_PREFERRED_TYPE(bool)
1755 uint64_t IsDeleted : 1;
1756
1757 LLVM_PREFERRED_TYPE(bool)
1758 uint64_t IsTrivial : 1;
1759
1760
1761
1762
1763 LLVM_PREFERRED_TYPE(bool)
1764 uint64_t IsTrivialForCall : 1;
1765
1766 LLVM_PREFERRED_TYPE(bool)
1767 uint64_t IsDefaulted : 1;
1768 LLVM_PREFERRED_TYPE(bool)
1769 uint64_t IsExplicitlyDefaulted : 1;
1770 LLVM_PREFERRED_TYPE(bool)
1771 uint64_t HasDefaultedOrDeletedInfo : 1;
1772
1773
1774
1775
1776 LLVM_PREFERRED_TYPE(bool)
1777 uint64_t IsIneligibleOrNotSelected : 1;
1778
1779 LLVM_PREFERRED_TYPE(bool)
1780 uint64_t HasImplicitReturnZero : 1;
1781 LLVM_PREFERRED_TYPE(bool)
1782 uint64_t IsLateTemplateParsed : 1;
1783 LLVM_PREFERRED_TYPE(bool)
1784 uint64_t IsInstantiatedFromMemberTemplate : 1;
1785
1786
1787 LLVM_PREFERRED_TYPE(ConstexprSpecKind)
1788 uint64_t ConstexprKind : 2;
1789 LLVM_PREFERRED_TYPE(bool)
1790 uint64_t BodyContainsImmediateEscalatingExpression : 1;
1791
1792 LLVM_PREFERRED_TYPE(bool)
1793 uint64_t InstantiationIsPending : 1;
1794
1795
1796 LLVM_PREFERRED_TYPE(bool)
1797 uint64_t UsesSEHTry : 1;
1798
1799
1800
1801 LLVM_PREFERRED_TYPE(bool)
1802 uint64_t HasSkippedBody : 1;
1803
1804
1805
1806 LLVM_PREFERRED_TYPE(bool)
1807 uint64_t WillHaveBody : 1;
1808
1809
1810
1811 LLVM_PREFERRED_TYPE(bool)
1812 uint64_t IsMultiVersion : 1;
1813
1814
1815
1816
1817 LLVM_PREFERRED_TYPE(DeductionCandidate)
1818 uint64_t DeductionCandidateKind : 2;
1819
1820
1821 LLVM_PREFERRED_TYPE(bool)
1822 uint64_t HasODRHash : 1;
1823
1824
1825 LLVM_PREFERRED_TYPE(bool)
1826 uint64_t UsesFPIntrin : 1;
1827
1828
1829
1830 LLVM_PREFERRED_TYPE(bool)
1831 uint64_t FriendConstraintRefersToEnclosingTemplate : 1;
1832 };
1833
1834
1835 enum { NumFunctionDeclBits = NumDeclContextBits + 32 };
1836
1837
1838
1839
1840 class CXXConstructorDeclBitfields {
1841 friend class CXXConstructorDecl;
1842
1843 LLVM_PREFERRED_TYPE(FunctionDeclBitfields)
1844 uint64_t : NumFunctionDeclBits;
1845
1846
1847
1848
1849
1850
1851 uint64_t NumCtorInitializers : 16;
1852 LLVM_PREFERRED_TYPE(bool)
1853 uint64_t IsInheritingConstructor : 1;
1854
1855
1856 LLVM_PREFERRED_TYPE(bool)
1857 uint64_t HasTrailingExplicitSpecifier : 1;
1858
1859
1860 LLVM_PREFERRED_TYPE(bool)
1861 uint64_t IsSimpleExplicit : 1;
1862 };
1863
1864
1865 enum { NumCXXConstructorDeclBits = NumFunctionDeclBits + 19 };
1866
1867
1868
1869
1870 class ObjCMethodDeclBitfields {
1871 friend class ObjCMethodDecl;
1872
1873
1874 LLVM_PREFERRED_TYPE(DeclContextBitfields)
1875 uint64_t : NumDeclContextBits;
1876
1877
1878
1879
1880 LLVM_PREFERRED_TYPE(ObjCMethodFamily)
1881 mutable uint64_t Family : ObjCMethodFamilyBitWidth;
1882
1883
1884 LLVM_PREFERRED_TYPE(bool)
1885 uint64_t IsInstance : 1;
1886 LLVM_PREFERRED_TYPE(bool)
1887 uint64_t IsVariadic : 1;
1888
1889
1890 LLVM_PREFERRED_TYPE(bool)
1891 uint64_t IsPropertyAccessor : 1;
1892
1893
1894 LLVM_PREFERRED_TYPE(bool)
1895 uint64_t IsSynthesizedAccessorStub : 1;
1896
1897
1898 LLVM_PREFERRED_TYPE(bool)
1899 uint64_t IsDefined : 1;
1900
1901
1902 LLVM_PREFERRED_TYPE(bool)
1903 uint64_t IsRedeclaration : 1;
1904
1905
1906 LLVM_PREFERRED_TYPE(bool)
1907 mutable uint64_t HasRedeclaration : 1;
1908
1909
1910 LLVM_PREFERRED_TYPE(ObjCImplementationControl)
1911 uint64_t DeclImplementation : 2;
1912
1913
1914 LLVM_PREFERRED_TYPE(Decl::ObjCDeclQualifier)
1915 uint64_t objcDeclQualifier : 7;
1916
1917
1918 LLVM_PREFERRED_TYPE(bool)
1919 uint64_t RelatedResultType : 1;
1920
1921
1922
1923 LLVM_PREFERRED_TYPE(SelectorLocationsKind)
1924 uint64_t SelLocsKind : 2;
1925
1926
1927
1928
1929
1930
1931
1932
1933 LLVM_PREFERRED_TYPE(bool)
1934 uint64_t IsOverriding : 1;
1935
1936
1937 LLVM_PREFERRED_TYPE(bool)
1938 uint64_t HasSkippedBody : 1;
1939 };
1940
1941
1942 enum { NumObjCMethodDeclBits = NumDeclContextBits + 24 };
1943
1944
1945
1946
1947 class ObjCContainerDeclBitfields {
1948 friend class ObjCContainerDecl;
1949
1950 LLVM_PREFERRED_TYPE(DeclContextBitfields)
1951 uint32_t : NumDeclContextBits;
1952
1953
1954
1955 SourceLocation AtStart;
1956 };
1957
1958
1959
1960
1961 enum { NumObjCContainerDeclBits = 64 };
1962
1963
1964
1965
1966 class LinkageSpecDeclBitfields {
1967 friend class LinkageSpecDecl;
1968
1969 LLVM_PREFERRED_TYPE(DeclContextBitfields)
1970 uint64_t : NumDeclContextBits;
1971
1972
1973 LLVM_PREFERRED_TYPE(LinkageSpecLanguageIDs)
1974 uint64_t Language : 3;
1975
1976
1977
1978
1979
1980 LLVM_PREFERRED_TYPE(bool)
1981 uint64_t HasBraces : 1;
1982 };
1983
1984
1985 enum { NumLinkageSpecDeclBits = NumDeclContextBits + 4 };
1986
1987
1988
1989
1990 class BlockDeclBitfields {
1991 friend class BlockDecl;
1992
1993 LLVM_PREFERRED_TYPE(DeclContextBitfields)
1994 uint64_t : NumDeclContextBits;
1995
1996 LLVM_PREFERRED_TYPE(bool)
1997 uint64_t IsVariadic : 1;
1998 LLVM_PREFERRED_TYPE(bool)
1999 uint64_t CapturesCXXThis : 1;
2000 LLVM_PREFERRED_TYPE(bool)
2001 uint64_t BlockMissingReturnType : 1;
2002 LLVM_PREFERRED_TYPE(bool)
2003 uint64_t IsConversionFromLambda : 1;
2004
2005
2006
2007 LLVM_PREFERRED_TYPE(bool)
2008 uint64_t DoesNotEscape : 1;
2009
2010
2011
2012
2013 LLVM_PREFERRED_TYPE(bool)
2014 uint64_t CanAvoidCopyToHeap : 1;
2015 };
2016
2017
2018 enum { NumBlockDeclBits = NumDeclContextBits + 5 };
2019
2020
2021
2022
2023
2024
2025
2026 mutable StoredDeclsMap *LookupPtr = nullptr;
2027
2028 protected:
2029
2030
2031
2032
2033
2034
2035
2036
2037 union {
2038 DeclContextBitfields DeclContextBits;
2039 NamespaceDeclBitfields NamespaceDeclBits;
2040 TagDeclBitfields TagDeclBits;
2041 EnumDeclBitfields EnumDeclBits;
2042 RecordDeclBitfields RecordDeclBits;
2043 OMPDeclareReductionDeclBitfields OMPDeclareReductionDeclBits;
2044 FunctionDeclBitfields FunctionDeclBits;
2045 CXXConstructorDeclBitfields CXXConstructorDeclBits;
2046 ObjCMethodDeclBitfields ObjCMethodDeclBits;
2047 ObjCContainerDeclBitfields ObjCContainerDeclBits;
2048 LinkageSpecDeclBitfields LinkageSpecDeclBits;
2049 BlockDeclBitfields BlockDeclBits;
2050
2051 static_assert(sizeof(DeclContextBitfields) <= 8,
2052 "DeclContextBitfields is larger than 8 bytes!");
2053 static_assert(sizeof(NamespaceDeclBitfields) <= 8,
2054 "NamespaceDeclBitfields is larger than 8 bytes!");
2055 static_assert(sizeof(TagDeclBitfields) <= 8,
2056 "TagDeclBitfields is larger than 8 bytes!");
2057 static_assert(sizeof(EnumDeclBitfields) <= 8,
2058 "EnumDeclBitfields is larger than 8 bytes!");
2059 static_assert(sizeof(RecordDeclBitfields) <= 8,
2060 "RecordDeclBitfields is larger than 8 bytes!");
2061 static_assert(sizeof(OMPDeclareReductionDeclBitfields) <= 8,
2062 "OMPDeclareReductionDeclBitfields is larger than 8 bytes!");
2063 static_assert(sizeof(FunctionDeclBitfields) <= 8,
2064 "FunctionDeclBitfields is larger than 8 bytes!");
2065 static_assert(sizeof(CXXConstructorDeclBitfields) <= 8,
2066 "CXXConstructorDeclBitfields is larger than 8 bytes!");
2067 static_assert(sizeof(ObjCMethodDeclBitfields) <= 8,
2068 "ObjCMethodDeclBitfields is larger than 8 bytes!");
2069 static_assert(sizeof(ObjCContainerDeclBitfields) <= 8,
2070 "ObjCContainerDeclBitfields is larger than 8 bytes!");
2071 static_assert(sizeof(LinkageSpecDeclBitfields) <= 8,
2072 "LinkageSpecDeclBitfields is larger than 8 bytes!");
2073 static_assert(sizeof(BlockDeclBitfields) <= 8,
2074 "BlockDeclBitfields is larger than 8 bytes!");
2075 };
2076
2077
2078
2079 mutable Decl *FirstDecl = nullptr;
2080
2081
2082
2083
2084
2085 mutable Decl *LastDecl = nullptr;
2086
2087
2088
2089
2090 static std::pair<Decl *, Decl *>
2091 BuildDeclChain(ArrayRef<Decl*> Decls, bool FieldsAlreadyLoaded);
2092
2093 DeclContext(Decl::Kind K);
2094
2095 public:
2096 ~DeclContext();
2097
2098
2099
2100 bool hasValidDeclKind() const;
2101
2102 Decl::Kind getDeclKind() const {
2103 return static_cast<Decl::Kind>(DeclContextBits.DeclKind);
2104 }
2105
2106 const char *getDeclKindName() const;
2107
2108
2109 DeclContext *getParent() {
2110 return cast<Decl>(this)->getDeclContext();
2111 }
2112 const DeclContext *getParent() const {
2113 return const_cast<DeclContext*>(this)->getParent();
2114 }
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125 DeclContext *getLexicalParent() {
2126 return cast<Decl>(this)->getLexicalDeclContext();
2127 }
2128 const DeclContext *getLexicalParent() const {
2129 return const_cast<DeclContext*>(this)->getLexicalParent();
2130 }
2131
2132 DeclContext *getLookupParent();
2133
2134 const DeclContext *getLookupParent() const {
2135 return const_cast<DeclContext*>(this)->getLookupParent();
2136 }
2137
2138 ASTContext &getParentASTContext() const {
2139 return cast<Decl>(this)->getASTContext();
2140 }
2141
2142 bool isClosure() const { return getDeclKind() == Decl::Block; }
2143
2144
2145
2146 const BlockDecl *getInnermostBlockDecl() const;
2147
2148 bool isObjCContainer() const {
2149 switch (getDeclKind()) {
2150 case Decl::ObjCCategory:
2151 case Decl::ObjCCategoryImpl:
2152 case Decl::ObjCImplementation:
2153 case Decl::ObjCInterface:
2154 case Decl::ObjCProtocol:
2155 return true;
2156 default:
2157 return false;
2158 }
2159 }
2160
2161 bool isFunctionOrMethod() const {
2162 switch (getDeclKind()) {
2163 case Decl::Block:
2164 case Decl::Captured:
2165 case Decl::ObjCMethod:
2166 case Decl::TopLevelStmt:
2167 return true;
2168 default:
2169 return getDeclKind() >= Decl::firstFunction &&
2170 getDeclKind() <= Decl::lastFunction;
2171 }
2172 }
2173
2174
2175 bool isLookupContext() const {
2176 return !isFunctionOrMethod() && getDeclKind() != Decl::LinkageSpec &&
2177 getDeclKind() != Decl::Export;
2178 }
2179
2180 bool isFileContext() const {
2181 return getDeclKind() == Decl::TranslationUnit ||
2182 getDeclKind() == Decl::Namespace;
2183 }
2184
2185 bool isTranslationUnit() const {
2186 return getDeclKind() == Decl::TranslationUnit;
2187 }
2188
2189 bool isRecord() const {
2190 return getDeclKind() >= Decl::firstRecord &&
2191 getDeclKind() <= Decl::lastRecord;
2192 }
2193
2194 bool isRequiresExprBody() const {
2195 return getDeclKind() == Decl::RequiresExprBody;
2196 }
2197
2198 bool isNamespace() const { return getDeclKind() == Decl::Namespace; }
2199
2200 bool isStdNamespace() const;
2201
2202 bool isInlineNamespace() const;
2203
2204
2205
2206 bool isDependentContext() const;
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223 bool isTransparentContext() const;
2224
2225
2226
2227 bool isExternCContext() const;
2228
2229
2230 const LinkageSpecDecl *getExternCContext() const;
2231
2232
2233
2234 bool isExternCXXContext() const;
2235
2236
2237
2238 bool Equals(const DeclContext *DC) const {
2239 return DC && this->getPrimaryContext() == DC->getPrimaryContext();
2240 }
2241
2242
2243
2244 bool Encloses(const DeclContext *DC) const;
2245
2246
2247
2248
2249 Decl *getNonClosureAncestor();
2250 const Decl *getNonClosureAncestor() const {
2251 return const_cast<DeclContext*>(this)->getNonClosureAncestor();
2252 }
2253
2254
2255 DeclContext *getNonTransparentContext();
2256 const DeclContext *getNonTransparentContext() const {
2257 return const_cast<DeclContext *>(this)->getNonTransparentContext();
2258 }
2259
2260
2261
2262
2263
2264
2265
2266 DeclContext *getPrimaryContext();
2267 const DeclContext *getPrimaryContext() const {
2268 return const_cast<DeclContext*>(this)->getPrimaryContext();
2269 }
2270
2271
2272
2273
2274 DeclContext *getRedeclContext();
2275 const DeclContext *getRedeclContext() const {
2276 return const_cast<DeclContext *>(this)->getRedeclContext();
2277 }
2278
2279
2280 DeclContext *getEnclosingNamespaceContext();
2281 const DeclContext *getEnclosingNamespaceContext() const {
2282 return const_cast<DeclContext *>(this)->getEnclosingNamespaceContext();
2283 }
2284
2285
2286 RecordDecl *getOuterLexicalRecordContext();
2287 const RecordDecl *getOuterLexicalRecordContext() const {
2288 return const_cast<DeclContext *>(this)->getOuterLexicalRecordContext();
2289 }
2290
2291
2292
2293
2294
2295
2296
2297 bool InEnclosingNamespaceSetOf(const DeclContext *NS) const;
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322 void collectAllContexts(SmallVectorImpl<DeclContext *> &Contexts);
2323
2324
2325
2326 class decl_iterator {
2327
2328 Decl *Current = nullptr;
2329
2330 public:
2331 using value_type = Decl *;
2332 using reference = const value_type &;
2333 using pointer = const value_type *;
2334 using iterator_category = std::forward_iterator_tag;
2335 using difference_type = std::ptrdiff_t;
2336
2337 decl_iterator() = default;
2338 explicit decl_iterator(Decl *C) : Current(C) {}
2339
2340 reference operator*() const { return Current; }
2341
2342
2343 value_type operator->() const { return Current; }
2344
2345 decl_iterator& operator++() {
2346 Current = Current->getNextDeclInContext();
2347 return *this;
2348 }
2349
2350 decl_iterator operator++(int) {
2351 decl_iterator tmp(*this);
2352 ++(*this);
2353 return tmp;
2354 }
2355
2356 friend bool operator==(decl_iterator x, decl_iterator y) {
2357 return x.Current == y.Current;
2358 }
2359
2360 friend bool operator!=(decl_iterator x, decl_iterator y) {
2361 return x.Current != y.Current;
2362 }
2363 };
2364
2365 using decl_range = llvm::iterator_range<decl_iterator>;
2366
2367
2368
2369 decl_range decls() const { return decl_range(decls_begin(), decls_end()); }
2370 decl_iterator decls_begin() const;
2371 decl_iterator decls_end() const { return decl_iterator(); }
2372 bool decls_empty() const;
2373
2374
2375
2376
2377 decl_range noload_decls() const {
2378 return decl_range(noload_decls_begin(), noload_decls_end());
2379 }
2380 decl_iterator noload_decls_begin() const { return decl_iterator(FirstDecl); }
2381 decl_iterator noload_decls_end() const { return decl_iterator(); }
2382
2383
2384
2385
2386
2387
2388 template<typename SpecificDecl>
2389 class specific_decl_iterator {
2390
2391
2392
2393 DeclContext::decl_iterator Current;
2394
2395
2396
2397
2398 void SkipToNextDecl() {
2399 while (*Current && !isa<SpecificDecl>(*Current))
2400 ++Current;
2401 }
2402
2403 public:
2404 using value_type = SpecificDecl *;
2405
2406
2407 using reference = void;
2408 using pointer = void;
2409 using difference_type =
2410 std::iterator_traits<DeclContext::decl_iterator>::difference_type;
2411 using iterator_category = std::forward_iterator_tag;
2412
2413 specific_decl_iterator() = default;
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423 explicit specific_decl_iterator(DeclContext::decl_iterator C) : Current(C) {
2424 SkipToNextDecl();
2425 }
2426
2427 value_type operator*() const { return cast<SpecificDecl>(*Current); }
2428
2429
2430 value_type operator->() const { return **this; }
2431
2432 specific_decl_iterator& operator++() {
2433 ++Current;
2434 SkipToNextDecl();
2435 return *this;
2436 }
2437
2438 specific_decl_iterator operator++(int) {
2439 specific_decl_iterator tmp(*this);
2440 ++(*this);
2441 return tmp;
2442 }
2443
2444 friend bool operator==(const specific_decl_iterator& x,
2445 const specific_decl_iterator& y) {
2446 return x.Current == y.Current;
2447 }
2448
2449 friend bool operator!=(const specific_decl_iterator& x,
2450 const specific_decl_iterator& y) {
2451 return x.Current != y.Current;
2452 }
2453 };
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464 template<typename SpecificDecl, bool (SpecificDecl::*Acceptable)() const>
2465 class filtered_decl_iterator {
2466
2467
2468
2469 DeclContext::decl_iterator Current;
2470
2471
2472
2473
2474 void SkipToNextDecl() {
2475 while (*Current &&
2476 (!isa<SpecificDecl>(*Current) ||
2477 (Acceptable && !(cast<SpecificDecl>(*Current)->*Acceptable)())))
2478 ++Current;
2479 }
2480
2481 public:
2482 using value_type = SpecificDecl *;
2483
2484
2485 using reference = void;
2486 using pointer = void;
2487 using difference_type =
2488 std::iterator_traits<DeclContext::decl_iterator>::difference_type;
2489 using iterator_category = std::forward_iterator_tag;
2490
2491 filtered_decl_iterator() = default;
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501 explicit filtered_decl_iterator(DeclContext::decl_iterator C) : Current(C) {
2502 SkipToNextDecl();
2503 }
2504
2505 value_type operator*() const { return cast<SpecificDecl>(*Current); }
2506 value_type operator->() const { return cast<SpecificDecl>(*Current); }
2507
2508 filtered_decl_iterator& operator++() {
2509 ++Current;
2510 SkipToNextDecl();
2511 return *this;
2512 }
2513
2514 filtered_decl_iterator operator++(int) {
2515 filtered_decl_iterator tmp(*this);
2516 ++(*this);
2517 return tmp;
2518 }
2519
2520 friend bool operator==(const filtered_decl_iterator& x,
2521 const filtered_decl_iterator& y) {
2522 return x.Current == y.Current;
2523 }
2524
2525 friend bool operator!=(const filtered_decl_iterator& x,
2526 const filtered_decl_iterator& y) {
2527 return x.Current != y.Current;
2528 }
2529 };
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543 void addDecl(Decl *D);
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553 void addDeclInternal(Decl *D);
2554
2555
2556
2557
2558
2559
2560
2561 void addHiddenDecl(Decl *D);
2562
2563
2564 void removeDecl(Decl *D);
2565
2566
2567 bool containsDecl(Decl *D) const;
2568
2569
2570
2571 bool containsDeclAndLoad(Decl *D) const;
2572
2573 using lookup_result = DeclContextLookupResult;
2574 using lookup_iterator = lookup_result::iterator;
2575
2576
2577
2578
2579
2580
2581 lookup_result lookup(DeclarationName Name) const;
2582
2583
2584
2585
2586 lookup_result noload_lookup(DeclarationName Name);
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597 void localUncachedLookup(DeclarationName Name,
2598 SmallVectorImpl<NamedDecl *> &Results);
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614 void makeDeclVisibleInContext(NamedDecl *D);
2615
2616
2617
2618 class all_lookups_iterator;
2619
2620 using lookups_range = llvm::iterator_range<all_lookups_iterator>;
2621
2622 lookups_range lookups() const;
2623
2624
2625 lookups_range noload_lookups(bool PreserveInternalState) const;
2626
2627
2628 all_lookups_iterator lookups_begin() const;
2629 all_lookups_iterator lookups_end() const;
2630
2631
2632
2633
2634 all_lookups_iterator noload_lookups_begin() const;
2635 all_lookups_iterator noload_lookups_end() const;
2636
2637 struct udir_iterator;
2638
2639 using udir_iterator_base =
2640 llvm::iterator_adaptor_base<udir_iterator, lookup_iterator,
2641 typename lookup_iterator::iterator_category,
2642 UsingDirectiveDecl *>;
2643
2644 struct udir_iterator : udir_iterator_base {
2645 udir_iterator(lookup_iterator I) : udir_iterator_base(I) {}
2646
2647 UsingDirectiveDecl *operator*() const;
2648 };
2649
2650 using udir_range = llvm::iterator_range<udir_iterator>;
2651
2652 udir_range using_directives() const;
2653
2654
2655 class ddiag_iterator;
2656
2657 using ddiag_range = llvm::iterator_range<DeclContext::ddiag_iterator>;
2658
2659 inline ddiag_range ddiags() const;
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669 void setMustBuildLookupTable() {
2670 assert(this == getPrimaryContext() &&
2671 "should only be called on primary context");
2672 DeclContextBits.HasLazyExternalLexicalLookups = true;
2673 }
2674
2675
2676
2677 StoredDeclsMap *getLookupPtr() const { return LookupPtr; }
2678
2679
2680 StoredDeclsMap *buildLookup();
2681
2682
2683
2684 bool hasExternalLexicalStorage() const {
2685 return DeclContextBits.ExternalLexicalStorage;
2686 }
2687
2688
2689
2690 void setHasExternalLexicalStorage(bool ES = true) const {
2691 DeclContextBits.ExternalLexicalStorage = ES;
2692 }
2693
2694
2695
2696 bool hasExternalVisibleStorage() const {
2697 return DeclContextBits.ExternalVisibleStorage;
2698 }
2699
2700
2701
2702 void setHasExternalVisibleStorage(bool ES = true) const {
2703 DeclContextBits.ExternalVisibleStorage = ES;
2704 if (ES && LookupPtr)
2705 DeclContextBits.NeedToReconcileExternalVisibleStorage = true;
2706 }
2707
2708
2709
2710 bool isDeclInLexicalTraversal(const Decl *D) const {
2711 return D && (D->NextInContextAndBits.getPointer() || D == FirstDecl ||
2712 D == LastDecl);
2713 }
2714
2715 void setUseQualifiedLookup(bool use = true) const {
2716 DeclContextBits.UseQualifiedLookup = use;
2717 }
2718
2719 bool shouldUseQualifiedLookup() const {
2720 return DeclContextBits.UseQualifiedLookup;
2721 }
2722
2723 static bool classof(const Decl *D);
2724 static bool classof(const DeclContext *D) { return true; }
2725
2726 void dumpAsDecl() const;
2727 void dumpAsDecl(const ASTContext *Ctx) const;
2728 void dumpDeclContext() const;
2729 void dumpLookups() const;
2730 void dumpLookups(llvm::raw_ostream &OS, bool DumpDecls = false,
2731 bool Deserialize = false) const;
2732
2733 private:
2734 lookup_result lookupImpl(DeclarationName Name,
2735 const DeclContext *OriginalLookupDC) const;
2736
2737
2738
2739
2740
2741 bool hasNeedToReconcileExternalVisibleStorage() const {
2742 return DeclContextBits.NeedToReconcileExternalVisibleStorage;
2743 }
2744
2745
2746
2747
2748
2749 void setNeedToReconcileExternalVisibleStorage(bool Need = true) const {
2750 DeclContextBits.NeedToReconcileExternalVisibleStorage = Need;
2751 }
2752
2753
2754
2755 bool hasLazyLocalLexicalLookups() const {
2756 return DeclContextBits.HasLazyLocalLexicalLookups;
2757 }
2758
2759
2760
2761 void setHasLazyLocalLexicalLookups(bool HasLLLL = true) const {
2762 DeclContextBits.HasLazyLocalLexicalLookups = HasLLLL;
2763 }
2764
2765
2766
2767 bool hasLazyExternalLexicalLookups() const {
2768 return DeclContextBits.HasLazyExternalLexicalLookups;
2769 }
2770
2771
2772
2773 void setHasLazyExternalLexicalLookups(bool HasLELL = true) const {
2774 DeclContextBits.HasLazyExternalLexicalLookups = HasLELL;
2775 }
2776
2777 void reconcileExternalVisibleStorage() const;
2778 bool LoadLexicalDeclsFromExternalStorage() const;
2779
2780 StoredDeclsMap *CreateStoredDeclsMap(ASTContext &C) const;
2781
2782 void loadLazyLocalLexicalLookups();
2783 void buildLookupImpl(DeclContext *DCtx, bool Internal);
2784 void makeDeclVisibleInContextWithFlags(NamedDecl *D, bool Internal,
2785 bool Rediscoverable);
2786 void makeDeclVisibleInContextImpl(NamedDecl *D, bool Internal);
2787 };
2788
2789 inline bool Decl::isTemplateParameter() const {
2790 return getKind() == TemplateTypeParm || getKind() == NonTypeTemplateParm ||
2791 getKind() == TemplateTemplateParm;
2792 }
2793
2794
2795 template <class ToTy,
2796 bool IsKnownSubtype = ::std::is_base_of<DeclContext, ToTy>::value>
2797 struct cast_convert_decl_context {
2798 static const ToTy *doit(const DeclContext *Val) {
2799 return static_cast<const ToTy*>(Decl::castFromDeclContext(Val));
2800 }
2801
2802 static ToTy *doit(DeclContext *Val) {
2803 return static_cast<ToTy*>(Decl::castFromDeclContext(Val));
2804 }
2805 };
2806
2807
2808 template <class ToTy>
2809 struct cast_convert_decl_context<ToTy, true> {
2810 static const ToTy *doit(const DeclContext *Val) {
2811 return static_cast<const ToTy*>(Val);
2812 }
2813
2814 static ToTy *doit(DeclContext *Val) {
2815 return static_cast<ToTy*>(Val);
2816 }
2817 };
2818
2819 }
2820
2821 namespace llvm {
2822
2823
2824 template <typename To>
2825 struct isa_impl<To, ::clang::DeclContext> {
2826 static bool doit(const ::clang::DeclContext &Val) {
2827 return To::classofKind(Val.getDeclKind());
2828 }
2829 };
2830
2831
2832 template<class ToTy>
2833 struct cast_convert_val<ToTy,
2834 const ::clang::DeclContext,const ::clang::DeclContext> {
2835 static const ToTy &doit(const ::clang::DeclContext &Val) {
2836 return *::clang::cast_convert_decl_context<ToTy>::doit(&Val);
2837 }
2838 };
2839
2840 template<class ToTy>
2841 struct cast_convert_val<ToTy, ::clang::DeclContext, ::clang::DeclContext> {
2842 static ToTy &doit(::clang::DeclContext &Val) {
2843 return *::clang::cast_convert_decl_context<ToTy>::doit(&Val);
2844 }
2845 };
2846
2847 template<class ToTy>
2848 struct cast_convert_val<ToTy,
2849 const ::clang::DeclContext*, const ::clang::DeclContext*> {
2850 static const ToTy *doit(const ::clang::DeclContext *Val) {
2851 return ::clang::cast_convert_decl_context<ToTy>::doit(Val);
2852 }
2853 };
2854
2855 template<class ToTy>
2856 struct cast_convert_val<ToTy, ::clang::DeclContext*, ::clang::DeclContext*> {
2857 static ToTy *doit(::clang::DeclContext *Val) {
2858 return ::clang::cast_convert_decl_context<ToTy>::doit(Val);
2859 }
2860 };
2861
2862
2863 template<class FromTy>
2864 struct cast_convert_val< ::clang::DeclContext, FromTy, FromTy> {
2865 static ::clang::DeclContext &doit(const FromTy &Val) {
2866 return *FromTy::castToDeclContext(&Val);
2867 }
2868 };
2869
2870 template<class FromTy>
2871 struct cast_convert_val< ::clang::DeclContext, FromTy*, FromTy*> {
2872 static ::clang::DeclContext *doit(const FromTy *Val) {
2873 return FromTy::castToDeclContext(Val);
2874 }
2875 };
2876
2877 template<class FromTy>
2878 struct cast_convert_val< const ::clang::DeclContext, FromTy, FromTy> {
2879 static const ::clang::DeclContext &doit(const FromTy &Val) {
2880 return *FromTy::castToDeclContext(&Val);
2881 }
2882 };
2883
2884 template<class FromTy>
2885 struct cast_convert_val< const ::clang::DeclContext, FromTy*, FromTy*> {
2886 static const ::clang::DeclContext *doit(const FromTy *Val) {
2887 return FromTy::castToDeclContext(Val);
2888 }
2889 };
2890
2891 }
2892
2893 #endif