13#ifndef LLVM_CLANG_AST_DECL_H
14#define LLVM_CLANG_AST_DECL_H
37#include "llvm/ADT/APSInt.h"
38#include "llvm/ADT/ArrayRef.h"
39#include "llvm/ADT/PointerIntPair.h"
40#include "llvm/ADT/PointerUnion.h"
41#include "llvm/ADT/StringRef.h"
42#include "llvm/ADT/iterator_range.h"
43#include "llvm/Support/Casting.h"
44#include "llvm/Support/Compiler.h"
45#include "llvm/Support/TrailingObjects.h"
56struct ASTTemplateArgumentListInfo;
58class DependentFunctionTemplateSpecializationInfo;
61class FunctionTemplateDecl;
62class FunctionTemplateSpecializationInfo;
65class MemberSpecializationInfo;
73class TemplateArgumentList;
74class TemplateArgumentListInfo;
75class TemplateParameterList;
76class TypeAliasTemplateDecl;
77class UnresolvedSetImpl;
107 virtual void anchor();
142 private llvm::TrailingObjects<PragmaCommentDecl, char> {
145 friend TrailingObjects;
151 :
Decl(PragmaComment, TU, CommentLoc), CommentKind(CommentKind) {}
153 virtual void anchor();
165 StringRef
getArg()
const {
return getTrailingObjects<char>(); }
176 private llvm::TrailingObjects<PragmaDetectMismatchDecl, char> {
179 friend TrailingObjects;
185 :
Decl(PragmaDetectMismatch, TU,
Loc), ValueStart(ValueStart) {}
187 virtual void anchor();
197 StringRef
getName()
const {
return getTrailingObjects<char>(); }
198 StringRef
getValue()
const {
return getTrailingObjects<char>() + ValueStart; }
227 virtual void anchor();
255 virtual void anchor();
258 NamedDecl *getUnderlyingDeclImpl() LLVM_READONLY;
262 :
Decl(DK, DC, L), Name(N) {}
277 assert(Name.isIdentifier() &&
"Name is not a simple identifier");
363 bool IsKnownNewer =
true)
const;
378 if (isa<EnumDecl>(DC))
441 std::optional<Visibility>
464 if (this->
getKind() != UsingShadow &&
465 this->
getKind() != ConstructorUsingShadow &&
466 this->
getKind() != ObjCCompatibleAlias &&
467 this->
getKind() != NamespaceAlias)
470 return getUnderlyingDeclImpl();
502 bool MSAsmNameResolved =
false;
511 :
NamedDecl(
Label, DC, IdentL, II), TheStmt(S), LocStart(StartL) {}
513 void anchor()
override;
625 return std::distance(
X.begin(),
X.end()) ==
626 std::distance(Y.begin(), Y.end());
670 void anchor()
override;
737 Expr *TrailingRequiresClause =
nullptr;
740 llvm::PointerUnion<TypeSourceInfo *, ExtInfo *> DeclInfo;
746 bool hasExtInfo()
const {
return DeclInfo.is<ExtInfo*>(); }
747 ExtInfo *getExtInfo() {
return DeclInfo.get<ExtInfo*>(); }
748 const ExtInfo *getExtInfo()
const {
return DeclInfo.get<ExtInfo*>(); }
754 :
ValueDecl(DK, DC, L, N,
T), DeclInfo(TInfo), InnerLocStart(StartL) {}
762 ? getExtInfo()->TInfo
768 getExtInfo()->TInfo = TI;
790 return hasExtInfo() ? getExtInfo()->QualifierLoc.getNestedNameSpecifier()
798 return hasExtInfo() ? getExtInfo()->QualifierLoc
808 return hasExtInfo() ? getExtInfo()->TrailingRequiresClause
813 return hasExtInfo() ? getExtInfo()->TrailingRequiresClause
820 return hasExtInfo() ? getExtInfo()->NumTemplParamLists : 0;
825 return getExtInfo()->TemplParamLists[index];
837 return K >= firstDeclarator && K <= lastDeclarator;
921 using InitType = llvm::PointerUnion<Stmt *, EvaluatedStmt *>;
932 class VarDeclBitfields {
939 unsigned TSCSpec : 2;
941 unsigned InitStyle : 2;
945 LLVM_PREFERRED_TYPE(
bool)
946 unsigned ARCPseudoStrong : 1;
948 enum { NumVarDeclBits = 8 };
966 LLVM_PREFERRED_TYPE(VarDeclBitfields)
971 LLVM_PREFERRED_TYPE(
bool)
972 unsigned HasInheritedDefaultArg : 1;
982 LLVM_PREFERRED_TYPE(
bool)
983 unsigned IsKNRPromoted : 1;
986 LLVM_PREFERRED_TYPE(
bool)
987 unsigned IsObjCMethodParam : 1;
1005 LLVM_PREFERRED_TYPE(VarDeclBitfields)
1011 LLVM_PREFERRED_TYPE(
bool)
1012 unsigned IsThisDeclarationADemotedDefinition : 1;
1016 LLVM_PREFERRED_TYPE(
bool)
1017 unsigned ExceptionVar : 1;
1022 LLVM_PREFERRED_TYPE(
bool)
1023 unsigned NRVOVariable : 1;
1027 LLVM_PREFERRED_TYPE(
bool)
1028 unsigned CXXForRangeDecl : 1;
1031 LLVM_PREFERRED_TYPE(
bool)
1032 unsigned ObjCForDecl : 1;
1035 LLVM_PREFERRED_TYPE(
bool)
1036 unsigned IsInline : 1;
1039 LLVM_PREFERRED_TYPE(
bool)
1040 unsigned IsInlineSpecified : 1;
1043 LLVM_PREFERRED_TYPE(
bool)
1044 unsigned IsConstexpr : 1;
1048 LLVM_PREFERRED_TYPE(
bool)
1049 unsigned IsInitCapture : 1;
1054 LLVM_PREFERRED_TYPE(
bool)
1055 unsigned PreviousDeclInSameBlockScope : 1;
1062 LLVM_PREFERRED_TYPE(
bool)
1063 unsigned EscapingByref : 1;
1065 LLVM_PREFERRED_TYPE(
bool)
1066 unsigned IsCXXCondDecl : 1;
1123 assert(
VarDeclBits.TSCSpec == TSC &&
"truncation");
1205 return DC->getRedeclContext()->isFunctionOrMethod();
1292 if (K == ParmVar || K == ImplicitParam)
1358 bool IsConstantInitialization)
const;
1418 return isa<ParmVarDecl>(
this) ?
false :
1429 assert(!isa<ParmVarDecl>(
this) &&
"Cannot demote ParmVarDecls!");
1439 assert(!isa<ParmVarDecl>(
this));
1457 assert(!isa<ParmVarDecl>(
this));
1467 assert(!isa<ParmVarDecl>(
this));
1496 return isa<ParmVarDecl>(
this) ?
false
1500 assert(!isa<ParmVarDecl>(
this));
1505 assert(!isa<ParmVarDecl>(
this));
1514 assert(!isa<ParmVarDecl>(
this));
1523 assert(!isa<ParmVarDecl>(
this));
1534 return isa<ParmVarDecl>(
this)
1539 assert(!isa<ParmVarDecl>(
this));
1561 assert(!isa<ParmVarDecl>(
this));
1682 void anchor()
override;
1731 :
VarDecl(DK,
C, DC, StartLoc, IdLoc,
Id,
T, TInfo, S) {
1752 setParameterIndex(parameterIndex);
1762 setParameterIndex(parameterIndex);
1783 return getParameterIndex();
1811 return ExplicitObjectParameterIntroducerLoc.
isValid();
1815 ExplicitObjectParameterIntroducerLoc =
Loc;
1819 return ExplicitObjectParameterIntroducerLoc;
1893 void setParameterIndex(
unsigned parameterIndex) {
1894 if (parameterIndex >= ParameterIndexSentinel) {
1895 setParameterIndexLarge(parameterIndex);
1900 assert(
ParmVarDeclBits.ParameterIndex == parameterIndex &&
"truncation!");
1902 unsigned getParameterIndex()
const {
1904 return d == ParameterIndexSentinel ? getParameterIndexLarge() : d;
1907 void setParameterIndexLarge(
unsigned parameterIndex);
1908 unsigned getParameterIndexLarge()
const;
1959 : llvm::TrailingObjects<DefaultedOrDeletedFunctionInfo, DeclAccessPair,
1961 friend TrailingObjects;
1962 unsigned NumLookups;
1963 bool HasDeletedMessage;
1965 size_t numTrailingObjects(OverloadToken<DeclAccessPair>)
const {
1977 return {getTrailingObjects<DeclAccessPair>(), NumLookups};
1981 return HasDeletedMessage ? *getTrailingObjects<StringLiteral *>()
2033 TemplateOrSpecialization;
2060 void setFunctionTemplateSpecialization(
2087 const DeclarationNameInfo &NameInfo, QualType
T,
2090 Expr *TrailingRequiresClause =
nullptr);
2126 Expr *TrailingRequiresClause =
nullptr) {
2131 TrailingRequiresClause);
2139 Expr *TrailingRequiresClause);
2157 if (FPT && FPT->isVariadic())
2206 bool CheckForPendingFriendDefinition =
false)
const;
2329 "Can't set default loc is function isn't explicitly defaulted");
2330 DefaultKWLoc = NewLoc;
2336 auto *DeclAsWritten =
this;
2338 DeclAsWritten = Pattern;
2339 return !(DeclAsWritten->isDeleted() ||
2340 DeclAsWritten->getCanonicalDecl()->isDefaulted());
2520 std::optional<unsigned> *AlignmentParam =
nullptr,
2521 bool *IsNothrow =
nullptr)
const;
2643 unsigned getBuiltinID(
bool ConsiderWrapperFunctions =
false)
const;
2671 return ParamInfo[i];
2675 return ParamInfo[i];
2952 setFunctionTemplateSpecialization(
getASTContext(), Template, TemplateArgs,
2953 InsertPos, TSK, TemplateArgsAsWritten,
2954 PointOfInstantiation);
3010 if (
const auto *FPT =
3012 return FPT->getFunctionEffects();
3019 return K >= firstFunction && K <= lastFunction;
3035 enum InitStorageKind {
3051 ISK_CapturedVLAType,
3054 LLVM_PREFERRED_TYPE(
bool)
3055 unsigned BitField : 1;
3056 LLVM_PREFERRED_TYPE(
bool)
3057 unsigned Mutable : 1;
3058 LLVM_PREFERRED_TYPE(InitStorageKind)
3059 unsigned StorageKind : 2;
3060 mutable unsigned CachedFieldIndex : 28;
3064 struct InitAndBitWidthStorage {
3095 Mutable(Mutable), StorageKind((InitStorageKind)InitStyle),
3096 CachedFieldIndex(0),
Init() {
3148 "bit width or captured type already set");
3149 assert(Width &&
"no bit width specified");
3161 assert(
isBitField() &&
"no bitfield width to remove");
3165 Init = ExistingInit;
3186 return (StorageKind == ISK_CapturedVLAType ?
ICIS_NoInit
3216 StorageKind = ISK_NoInit;
3227 return StorageKind == ISK_CapturedVLAType;
3277 const llvm::APSInt &
V);
3285 const llvm::APSInt &
V);
3291 return llvm::APSInt(
getValue(), IsUnsigned);
3297 IsUnsigned =
V.isUnsigned();
3316 unsigned ChainingSize;
3322 void anchor()
override;
3345 assert(
chain().size() >= 2);
3346 return cast<FieldDecl>(
chain().back());
3350 assert(
chain().size() >= 2);
3351 return dyn_cast<VarDecl>(
chain().front());
3370 mutable const Type *TypeForDecl =
nullptr;
3375 void anchor()
override;
3406 struct alignas(8) ModedTInfo {
3413 mutable llvm::PointerIntPair<
3414 llvm::PointerUnion<TypeSourceInfo *, ModedTInfo *>, 2>
3417 void anchor()
override;
3424 MaybeModedTInfo(TInfo, 0) {}
3452 return MaybeModedTInfo.getPointer().is<ModedTInfo *>();
3456 return isModed() ? MaybeModedTInfo.getPointer().get<ModedTInfo *>()->first
3461 return isModed() ? MaybeModedTInfo.getPointer().get<ModedTInfo *>()->second
3462 : MaybeModedTInfo.getPointer()
3468 MaybeModedTInfo.setPointer(newType);
3473 ModedTInfo({unmodedTSI, modedTy}));
3490 if (MaybeModedTInfo.getInt())
3491 return MaybeModedTInfo.getInt() & 0x2;
3492 return isTransparentTagSlow();
3498 return K >= firstTypedefName && K <= lastTypedefName;
3502 bool isTransparentTagSlow()
const;
3536 Template(
nullptr) {}
3579 llvm::PointerUnion<TypedefNameDecl *, ExtInfo *> TypedefNameDeclOrQualifier;
3581 bool hasExtInfo()
const {
return TypedefNameDeclOrQualifier.is<
ExtInfo *>(); }
3582 ExtInfo *getExtInfo() {
return TypedefNameDeclOrQualifier.get<ExtInfo *>(); }
3583 const ExtInfo *getExtInfo()
const {
3584 return TypedefNameDeclOrQualifier.get<ExtInfo *>();
3589 SourceLocation L, IdentifierInfo *
Id, TagDecl *PrevDecl,
3590 SourceLocation StartL);
3691 TagDeclBits.IsEmbeddedInDeclarator = isInDeclarator;
3719 return TagDeclBits.IsThisDeclarationADemotedDefinition;
3726 "Should demote definitions only, not forward declarations");
3728 TagDeclBits.IsThisDeclarationADemotedDefinition =
true;
3757 TagDeclBits.TagDeclKind = llvm::to_underlying(TK);
3786 return hasExtInfo() ? nullptr
3858 llvm::PointerUnion<const Type *, TypeSourceInfo *> IntegerType;
3878 bool Scoped,
bool ScopedUsingClassTag,
bool Fixed);
3880 void anchor()
override;
3887 void setNumPositiveBits(
unsigned Num) {
3889 assert(
EnumDeclBits.NumPositiveBits == Num &&
"can't store this bitcount");
3894 void setNumNegativeBits(
unsigned Num) {
EnumDeclBits.NumNegativeBits = Num; }
3915 bool hasODRHash()
const {
return EnumDeclBits.HasODRHash; }
3916 void setHasODRHash(
bool Hash =
true) {
EnumDeclBits.HasODRHash = Hash; }
3929 return cast_or_null<EnumDecl>(
3950 bool IsScoped,
bool IsScopedUsingClassTag,
3965 unsigned NumPositiveBits,
3966 unsigned NumNegativeBits);
4003 if (
const Type *
T = IntegerType.dyn_cast<
const Type*>())
4005 return IntegerType.get<
TypeSourceInfo*>()->getType().getUnqualifiedType();
4100 return SpecializationInfo;
4160 return cast_or_null<RecordDecl>(
4244 return RecordDeclBits.HasNonTrivialToPrimitiveDefaultInitializeCUnion;
4345 using field_range = llvm::iterator_range<specific_decl_iterator<FieldDecl>>;
4364 return K >= firstRecord && K <= lastRecord;
4386 void LoadFieldsFromExternalStorage()
const;
4390 void setODRHash(
unsigned Hash) {
RecordDeclBits.ODRHash = Hash; }
4399 :
Decl(FileScopeAsm, DC, StartL), AsmString(asmstring), RParenLoc(EndL) {}
4401 virtual void anchor();
4434 Stmt *Statement =
nullptr;
4435 bool IsSemiMissing =
false;
4438 :
Decl(TopLevelStmt, DC, L),
DeclContext(TopLevelStmt), Statement(S) {}
4440 virtual void anchor();
4480 llvm::PointerIntPair<VarDecl*, 2> VariableAndFlags;
4489 : VariableAndFlags(variable,
4490 (byRef ? flag_isByRef : 0) | (nested ? flag_isNested : 0)),
4498 bool isByRef()
const {
return VariableAndFlags.getInt() & flag_isByRef; }