@@ -1712,7 +1712,9 @@ class ExtensionDecl final : public GenericContext, public Decl,
1712
1712
return D->getKind () == DeclKind::Extension;
1713
1713
}
1714
1714
static bool classof (const DeclContext *C) {
1715
- return C->getContextKind () == DeclContextKind::ExtensionDecl;
1715
+ if (auto D = C->getAsDeclOrDeclExtensionContext ())
1716
+ return classof (D);
1717
+ return false ;
1716
1718
}
1717
1719
static bool classof (const IterableDeclContext *C) {
1718
1720
return C->getIterableContextKind ()
@@ -2003,7 +2005,9 @@ class TopLevelCodeDecl : public DeclContext, public Decl {
2003
2005
return D->getKind () == DeclKind::TopLevelCode;
2004
2006
}
2005
2007
static bool classof (const DeclContext *C) {
2006
- return C->getContextKind () == DeclContextKind::TopLevelCodeDecl;
2008
+ if (auto D = C->getAsDeclOrDeclExtensionContext ())
2009
+ return classof (D);
2010
+ return false ;
2007
2011
}
2008
2012
2009
2013
using DeclContext::operator new ;
@@ -2465,7 +2469,9 @@ class GenericTypeDecl : public GenericContext, public TypeDecl {
2465
2469
using TypeDecl::getDeclaredInterfaceType;
2466
2470
2467
2471
static bool classof (const DeclContext *C) {
2468
- return C->getContextKind () == DeclContextKind::GenericTypeDecl;
2472
+ if (auto D = C->getAsDeclOrDeclExtensionContext ())
2473
+ return classof (D);
2474
+ return false ;
2469
2475
}
2470
2476
static bool classof (const Decl *D) {
2471
2477
return D->getKind () >= DeclKind::First_GenericTypeDecl &&
@@ -2533,8 +2539,9 @@ class TypeAliasDecl : public GenericTypeDecl {
2533
2539
return D->getKind () == DeclKind::TypeAlias;
2534
2540
}
2535
2541
static bool classof (const DeclContext *C) {
2536
- auto GTD = dyn_cast<GenericTypeDecl>(C);
2537
- return GTD && classof (GTD);
2542
+ if (auto D = C->getAsDeclOrDeclExtensionContext ())
2543
+ return classof (D);
2544
+ return false ;
2538
2545
}
2539
2546
};
2540
2547
@@ -3038,8 +3045,9 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
3038
3045
}
3039
3046
3040
3047
static bool classof (const DeclContext *C) {
3041
- auto GTD = dyn_cast<GenericTypeDecl>(C);
3042
- return GTD && classof (GTD);
3048
+ if (auto D = C->getAsDeclOrDeclExtensionContext ())
3049
+ return classof (D);
3050
+ return false ;
3043
3051
}
3044
3052
static bool classof (const IterableDeclContext *C) {
3045
3053
return C->getIterableContextKind ()
@@ -3183,8 +3191,9 @@ class EnumDecl final : public NominalTypeDecl {
3183
3191
return D->getKind () == DeclKind::Enum;
3184
3192
}
3185
3193
static bool classof (const DeclContext *C) {
3186
- auto GTD = dyn_cast<GenericTypeDecl>(C);
3187
- return GTD && classof (static_cast <const Decl*>(GTD));
3194
+ if (auto D = C->getAsDeclOrDeclExtensionContext ())
3195
+ return classof (D);
3196
+ return false ;
3188
3197
}
3189
3198
static bool classof (const IterableDeclContext *C) {
3190
3199
auto NTD = dyn_cast<NominalTypeDecl>(C);
@@ -3252,8 +3261,9 @@ class StructDecl final : public NominalTypeDecl {
3252
3261
return D->getKind () == DeclKind::Struct;
3253
3262
}
3254
3263
static bool classof (const DeclContext *C) {
3255
- auto GTD = dyn_cast<GenericTypeDecl>(C);
3256
- return GTD && classof (static_cast <const Decl*>(GTD));
3264
+ if (auto D = C->getAsDeclOrDeclExtensionContext ())
3265
+ return classof (D);
3266
+ return false ;
3257
3267
}
3258
3268
static bool classof (const IterableDeclContext *C) {
3259
3269
auto NTD = dyn_cast<NominalTypeDecl>(C);
@@ -3509,8 +3519,9 @@ class ClassDecl final : public NominalTypeDecl {
3509
3519
return D->getKind () == DeclKind::Class;
3510
3520
}
3511
3521
static bool classof (const DeclContext *C) {
3512
- auto GTD = dyn_cast<GenericTypeDecl>(C);
3513
- return GTD && classof (static_cast <const Decl*>(GTD));
3522
+ if (auto D = C->getAsDeclOrDeclExtensionContext ())
3523
+ return classof (D);
3524
+ return false ;
3514
3525
}
3515
3526
static bool classof (const IterableDeclContext *C) {
3516
3527
auto NTD = dyn_cast<NominalTypeDecl>(C);
@@ -3827,8 +3838,9 @@ class ProtocolDecl final : public NominalTypeDecl {
3827
3838
return D->getKind () == DeclKind::Protocol;
3828
3839
}
3829
3840
static bool classof (const DeclContext *C) {
3830
- auto GTD = dyn_cast<GenericTypeDecl>(C);
3831
- return GTD && classof (static_cast <const Decl*>(GTD));
3841
+ if (auto D = C->getAsDeclOrDeclExtensionContext ())
3842
+ return classof (D);
3843
+ return false ;
3832
3844
}
3833
3845
static bool classof (const IterableDeclContext *C) {
3834
3846
auto NTD = dyn_cast<NominalTypeDecl>(C);
@@ -4847,7 +4859,9 @@ class SubscriptDecl : public GenericContext, public AbstractStorageDecl {
4847
4859
}
4848
4860
4849
4861
static bool classof (const DeclContext *DC) {
4850
- return DC->getContextKind () == DeclContextKind::SubscriptDecl;
4862
+ if (auto D = DC->getAsDeclOrDeclExtensionContext ())
4863
+ return classof (D);
4864
+ return false ;
4851
4865
}
4852
4866
4853
4867
using DeclContext::operator new ;
@@ -5230,7 +5244,9 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
5230
5244
}
5231
5245
5232
5246
static bool classof (const DeclContext *DC) {
5233
- return DC->getContextKind () == DeclContextKind::AbstractFunctionDecl;
5247
+ if (auto D = DC->getAsDeclOrDeclExtensionContext ())
5248
+ return classof (D);
5249
+ return false ;
5234
5250
}
5235
5251
5236
5252
// / True if the declaration is forced to be statically dispatched.
@@ -5496,8 +5512,8 @@ class FuncDecl : public AbstractFunctionDecl {
5496
5512
return classof (static_cast <const Decl*>(D));
5497
5513
}
5498
5514
static bool classof (const DeclContext *DC) {
5499
- if (auto fn = dyn_cast<AbstractFunctionDecl>(DC ))
5500
- return classof (fn );
5515
+ if (auto D = DC-> getAsDeclOrDeclExtensionContext ( ))
5516
+ return classof (D );
5501
5517
return false ;
5502
5518
}
5503
5519
@@ -5617,8 +5633,8 @@ class AccessorDecl final : public FuncDecl {
5617
5633
return classof (static_cast <const Decl*>(D));
5618
5634
}
5619
5635
static bool classof (const DeclContext *DC) {
5620
- if (auto fn = dyn_cast<AbstractFunctionDecl>(DC ))
5621
- return classof (fn );
5636
+ if (auto D = DC-> getAsDeclOrDeclExtensionContext ( ))
5637
+ return classof (D );
5622
5638
return false ;
5623
5639
}
5624
5640
};
@@ -6036,8 +6052,8 @@ class ConstructorDecl : public AbstractFunctionDecl {
6036
6052
return classof (static_cast <const Decl*>(D));
6037
6053
}
6038
6054
static bool classof (const DeclContext *DC) {
6039
- if (auto fn = dyn_cast<AbstractFunctionDecl>(DC ))
6040
- return classof (fn );
6055
+ if (auto D = DC-> getAsDeclOrDeclExtensionContext ( ))
6056
+ return classof (D );
6041
6057
return false ;
6042
6058
}
6043
6059
};
@@ -6080,8 +6096,8 @@ class DestructorDecl : public AbstractFunctionDecl {
6080
6096
return classof (static_cast <const Decl*>(D));
6081
6097
}
6082
6098
static bool classof (const DeclContext *DC) {
6083
- if (auto fn = dyn_cast<AbstractFunctionDecl>(DC ))
6084
- return classof (fn );
6099
+ if (auto D = DC-> getAsDeclOrDeclExtensionContext ( ))
6100
+ return classof (D );
6085
6101
return false ;
6086
6102
}
6087
6103
};
@@ -6584,6 +6600,12 @@ inline const GenericContext *Decl::getAsGenericContext() const {
6584
6600
}
6585
6601
}
6586
6602
6603
+ inline bool DeclContext::isExtensionContext () const {
6604
+ if (auto D = getAsDeclOrDeclExtensionContext ())
6605
+ return ExtensionDecl::classof (D);
6606
+ return false ;
6607
+ }
6608
+
6587
6609
inline bool DeclContext::classof (const Decl *D) {
6588
6610
switch (D->getKind ()) { //
6589
6611
default : return false ;
0 commit comments