@@ -334,7 +334,7 @@ class alignas(1 << DeclAlignInBits) Decl {
334
334
IsUserAccessible : 1
335
335
);
336
336
337
- SWIFT_INLINE_BITFIELD (AbstractStorageDecl, ValueDecl, 1 +1 +1 +1 +2 +1 +1 ,
337
+ SWIFT_INLINE_BITFIELD (AbstractStorageDecl, ValueDecl, 1 +1 +1 +1 +2 +1 +1 + 1 ,
338
338
// / Whether the getter is mutating.
339
339
IsGetterMutating : 1 ,
340
340
@@ -353,14 +353,14 @@ class alignas(1 << DeclAlignInBits) Decl {
353
353
// / Whether a keypath component can directly reference this storage,
354
354
// / or if it must use the overridden declaration instead.
355
355
HasComputedValidKeyPathComponent : 1 ,
356
- ValidKeyPathComponent : 1
357
- );
358
-
359
- SWIFT_INLINE_BITFIELD (VarDecl, AbstractStorageDecl, 1 +4 +1 +1 +1 +1 ,
356
+ ValidKeyPathComponent : 1 ,
357
+
360
358
// / Whether this property is a type property (currently unfortunately
361
359
// / called 'static').
362
- IsStatic : 1 ,
360
+ IsStatic : 1
361
+ );
363
362
363
+ SWIFT_INLINE_BITFIELD (VarDecl, AbstractStorageDecl, 4 +1 +1 +1 +1 ,
364
364
// / The specifier associated with this variable or parameter. This
365
365
// / determines the storage semantics of the value e.g. mutability.
366
366
Specifier : 4 ,
@@ -393,6 +393,10 @@ class alignas(1 << DeclAlignInBits) Decl {
393
393
// / Information about a symbolic default argument, like #file.
394
394
defaultArgumentKind : NumDefaultArgumentKindBits
395
395
);
396
+
397
+ SWIFT_INLINE_BITFIELD (SubscriptDecl, VarDecl, 2 ,
398
+ StaticSpelling : 2
399
+ );
396
400
397
401
SWIFT_INLINE_BITFIELD (EnumElementDecl, ValueDecl, 1 ,
398
402
// / The ResilienceExpansion to use for default arguments.
@@ -4283,15 +4287,17 @@ class AbstractStorageDecl : public ValueDecl {
4283
4287
}
4284
4288
4285
4289
protected:
4286
- AbstractStorageDecl (DeclKind Kind, DeclContext *DC, DeclName Name,
4287
- SourceLoc NameLoc, StorageIsMutable_t supportsMutation)
4290
+ AbstractStorageDecl (DeclKind Kind, bool IsStatic, DeclContext *DC,
4291
+ DeclName Name, SourceLoc NameLoc,
4292
+ StorageIsMutable_t supportsMutation)
4288
4293
: ValueDecl(Kind, DC, Name, NameLoc) {
4289
4294
Bits.AbstractStorageDecl .HasStorage = true ;
4290
4295
Bits.AbstractStorageDecl .SupportsMutation = supportsMutation;
4291
4296
Bits.AbstractStorageDecl .IsGetterMutating = false ;
4292
4297
Bits.AbstractStorageDecl .IsSetterMutating = true ;
4293
4298
Bits.AbstractStorageDecl .OpaqueReadOwnership =
4294
4299
unsigned (OpaqueReadOwnership::Owned);
4300
+ Bits.AbstractStorageDecl .IsStatic = IsStatic;
4295
4301
}
4296
4302
4297
4303
void setSupportsMutationIfStillStored (StorageIsMutable_t supportsMutation) {
@@ -4312,9 +4318,16 @@ class AbstractStorageDecl : public ValueDecl {
4312
4318
// / attribute.
4313
4319
bool isTransparent () const ;
4314
4320
4315
- // / Determine whether this storage is a static member, if it
4316
- // / is a member. Currently only variables can be static.
4317
- inline bool isStatic () const ; // defined in this header
4321
+ // / Is this a type ('static') variable?
4322
+ bool isStatic () const {
4323
+ return Bits.AbstractStorageDecl .IsStatic ;
4324
+ }
4325
+ void setStatic (bool IsStatic) {
4326
+ Bits.AbstractStorageDecl .IsStatic = IsStatic;
4327
+ }
4328
+
4329
+ // / \returns the way 'static'/'class' should be spelled for this declaration.
4330
+ StaticSpellingKind getCorrectStaticSpelling () const ;
4318
4331
4319
4332
// / Return the interface type of the stored value.
4320
4333
Type getValueInterfaceType () const ;
@@ -4612,10 +4625,9 @@ class VarDecl : public AbstractStorageDecl {
4612
4625
4613
4626
VarDecl (DeclKind Kind, bool IsStatic, Specifier Sp, bool IsCaptureList,
4614
4627
SourceLoc NameLoc, Identifier Name, DeclContext *DC)
4615
- : AbstractStorageDecl(Kind, DC, Name, NameLoc,
4628
+ : AbstractStorageDecl(Kind, IsStatic, DC, Name, NameLoc,
4616
4629
StorageIsMutable_t (!isImmutableSpecifier(Sp)))
4617
4630
{
4618
- Bits.VarDecl .IsStatic = IsStatic;
4619
4631
Bits.VarDecl .Specifier = static_cast <unsigned >(Sp);
4620
4632
Bits.VarDecl .IsCaptureList = IsCaptureList;
4621
4633
Bits.VarDecl .IsDebuggerVar = false ;
@@ -4794,14 +4806,6 @@ class VarDecl : public AbstractStorageDecl {
4794
4806
return getSpecifier () == Specifier::InOut;
4795
4807
}
4796
4808
4797
-
4798
- // / Is this a type ('static') variable?
4799
- bool isStatic () const { return Bits.VarDecl .IsStatic ; }
4800
- void setStatic (bool IsStatic) { Bits.VarDecl .IsStatic = IsStatic; }
4801
-
4802
- // / \returns the way 'static'/'class' should be spelled for this declaration.
4803
- StaticSpellingKind getCorrectStaticSpelling () const ;
4804
-
4805
4809
bool isImmutable () const {
4806
4810
return isImmutableSpecifier (getSpecifier ());
4807
4811
}
@@ -5110,24 +5114,40 @@ enum class ObjCSubscriptKind {
5110
5114
// / signatures (indices and element type) are distinct.
5111
5115
// /
5112
5116
class SubscriptDecl : public GenericContext , public AbstractStorageDecl {
5117
+ SourceLoc StaticLoc;
5113
5118
SourceLoc ArrowLoc;
5114
5119
ParameterList *Indices;
5115
5120
TypeLoc ElementTy;
5116
5121
5117
5122
public:
5118
- SubscriptDecl (DeclName Name, SourceLoc SubscriptLoc, ParameterList *Indices,
5123
+ SubscriptDecl (DeclName Name,
5124
+ SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
5125
+ SourceLoc SubscriptLoc, ParameterList *Indices,
5119
5126
SourceLoc ArrowLoc, TypeLoc ElementTy, DeclContext *Parent,
5120
5127
GenericParamList *GenericParams)
5121
5128
: GenericContext(DeclContextKind::SubscriptDecl, Parent),
5122
- AbstractStorageDecl (DeclKind::Subscript, Parent, Name, SubscriptLoc,
5129
+ AbstractStorageDecl (DeclKind::Subscript,
5130
+ StaticSpelling != StaticSpellingKind::None,
5131
+ Parent, Name, SubscriptLoc,
5123
5132
/* will be overwritten*/ StorageIsNotMutable),
5124
- ArrowLoc(ArrowLoc), Indices(nullptr ), ElementTy(ElementTy) {
5133
+ StaticLoc(StaticLoc), ArrowLoc(ArrowLoc),
5134
+ Indices(nullptr ), ElementTy(ElementTy) {
5135
+ Bits.SubscriptDecl .StaticSpelling = static_cast <unsigned >(StaticSpelling);
5125
5136
setIndices (Indices);
5126
5137
setGenericParams (GenericParams);
5127
5138
}
5128
5139
5140
+ // / \returns the way 'static'/'class' was spelled in the source.
5141
+ StaticSpellingKind getStaticSpelling () const {
5142
+ return static_cast <StaticSpellingKind>(Bits.SubscriptDecl .StaticSpelling );
5143
+ }
5144
+
5145
+ SourceLoc getStaticLoc () const { return StaticLoc; }
5129
5146
SourceLoc getSubscriptLoc () const { return getNameLoc (); }
5130
- SourceLoc getStartLoc () const { return getSubscriptLoc (); }
5147
+
5148
+ SourceLoc getStartLoc () const {
5149
+ return getStaticLoc ().isValid () ? getStaticLoc () : getSubscriptLoc ();
5150
+ }
5131
5151
SourceRange getSourceRange () const ;
5132
5152
SourceRange getSignatureSourceRange () const ;
5133
5153
@@ -6825,15 +6845,6 @@ AbstractStorageDecl::overwriteSetterAccess(AccessLevel accessLevel) {
6825
6845
mutableAddressor->overwriteAccess (accessLevel);
6826
6846
}
6827
6847
6828
- inline bool AbstractStorageDecl::isStatic () const {
6829
- if (auto var = dyn_cast<VarDecl>(this )) {
6830
- return var->isStatic ();
6831
- }
6832
-
6833
- // Currently, subscripts are never static.
6834
- return false ;
6835
- }
6836
-
6837
6848
// / Constructors and destructors always have a 'self' parameter,
6838
6849
// / which is stored in an instance member. Functions only have a
6839
6850
// / 'self' if they are declared inside of a nominal type or extension,
0 commit comments