@@ -111,6 +111,17 @@ enum class CircularityCheck {
111
111
Checked
112
112
};
113
113
114
+ // / Describes which spelling was used in the source for the 'static' or 'class'
115
+ // / keyword.
116
+ enum class StaticSpellingKind : uint8_t {
117
+ None,
118
+ KeywordStatic,
119
+ KeywordClass,
120
+ };
121
+
122
+ // / Diagnostic printing of \c StaticSpellingKind.
123
+ llvm::raw_ostream &operator <<(llvm::raw_ostream &OS, StaticSpellingKind SSK);
124
+
114
125
// / Decl - Base class for all declarations in Swift.
115
126
class alignas (8 ) Decl {
116
127
// alignas(8) because we use three tag bits on Decl*.
@@ -142,13 +153,16 @@ class alignas(8) Decl {
142
153
// / \brief Whether this pattern binding declares static variables.
143
154
unsigned IsStatic : 1 ;
144
155
156
+ // / \brief Whether 'static' or 'class' was used.
157
+ unsigned StaticSpelling : 2 ;
158
+
145
159
// / \brief Whether this pattern binding declares a variable with storage.
146
160
unsigned HasStorage : 1 ;
147
161
148
162
// / \brief Whether this pattern binding appears in a conditional statement.
149
163
unsigned Conditional : 1 ;
150
164
};
151
- enum { NumPatternBindingDeclBits = NumDeclBits + 3 };
165
+ enum { NumPatternBindingDeclBits = NumDeclBits + 5 };
152
166
static_assert (NumPatternBindingDeclBits <= 32 , " fits in an unsigned" );
153
167
154
168
class ValueDeclBitfields {
@@ -165,8 +179,8 @@ class alignas(8) Decl {
165
179
166
180
// / \brief Whether this property is a type property (currently unfortunately
167
181
// / called 'static').
168
- unsigned Static : 1 ;
169
-
182
+ unsigned IsStatic : 1 ;
183
+
170
184
// / \brief Whether this is a 'let' property, which can only be initialized
171
185
// / in its declaration, and never assigned to, making it immutable.
172
186
unsigned IsLet : 1 ;
@@ -200,13 +214,17 @@ class alignas(8) Decl {
200
214
unsigned : NumAbstractFunctionDeclBits;
201
215
202
216
// / Whether this function is a 'static' method.
203
- unsigned Static : 1 ;
217
+ unsigned IsStatic : 1 ;
218
+
219
+ // / \brief Whether 'static' or 'class' was used.
220
+ unsigned StaticSpelling : 2 ;
221
+
204
222
// / Whether this function is a 'mutating' method.
205
223
unsigned Mutating : 1 ;
206
224
// / Whether this function has a \c DynamicSelf return type.
207
225
unsigned HasDynamicSelf : 1 ;
208
226
};
209
- enum { NumFuncDeclBits = NumAbstractFunctionDeclBits + 3 };
227
+ enum { NumFuncDeclBits = NumAbstractFunctionDeclBits + 5 };
210
228
static_assert (NumFuncDeclBits <= 32 , " fits in an unsigned" );
211
229
212
230
class ConstructorDeclBitfields {
@@ -1252,15 +1270,18 @@ class PatternBindingDecl : public Decl {
1252
1270
friend class Decl ;
1253
1271
1254
1272
public:
1255
- PatternBindingDecl (SourceLoc StaticLoc,
1256
- SourceLoc VarLoc, Pattern *Pat, Expr *E,
1273
+ PatternBindingDecl (SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
1274
+ SourceLoc VarLoc,
1275
+ Pattern *Pat, Expr *E,
1257
1276
bool hasStorage,
1258
1277
bool isConditional,
1259
1278
DeclContext *Parent)
1260
1279
: Decl(DeclKind::PatternBinding, Parent),
1261
1280
StaticLoc (StaticLoc), VarLoc(VarLoc), Pat(Pat),
1262
1281
InitAndChecked(E, false ) {
1263
1282
PatternBindingDeclBits.IsStatic = StaticLoc.isValid ();
1283
+ PatternBindingDeclBits.StaticSpelling =
1284
+ static_cast <unsigned >(StaticSpelling);
1264
1285
PatternBindingDeclBits.HasStorage = hasStorage;
1265
1286
PatternBindingDeclBits.Conditional = isConditional;
1266
1287
}
@@ -1292,6 +1313,13 @@ class PatternBindingDecl : public Decl {
1292
1313
bool isStatic () const { return PatternBindingDeclBits.IsStatic ; }
1293
1314
void setStatic (bool s) { PatternBindingDeclBits.IsStatic = s; }
1294
1315
SourceLoc getStaticLoc () const { return StaticLoc; }
1316
+ // / \returns the way 'static'/'class' was spelled in the source.
1317
+ StaticSpellingKind getStaticSpelling () const {
1318
+ return static_cast <StaticSpellingKind>(
1319
+ PatternBindingDeclBits.StaticSpelling );
1320
+ }
1321
+ // / \returns the way 'static'/'class' should be spelled for this declaration.
1322
+ StaticSpellingKind getCorrectStaticSpelling () const ;
1295
1323
1296
1324
static bool classof (const Decl *D) {
1297
1325
return D->getKind () == DeclKind::PatternBinding;
@@ -2633,7 +2661,7 @@ class VarDecl : public AbstractStorageDecl {
2633
2661
VarDecl (bool IsStatic, bool IsLet, SourceLoc NameLoc, Identifier Name,
2634
2662
Type Ty, DeclContext *DC)
2635
2663
: AbstractStorageDecl(DeclKind::Var, DC, Name, NameLoc) {
2636
- VarDeclBits.Static = IsStatic;
2664
+ VarDeclBits.IsStatic = IsStatic;
2637
2665
VarDeclBits.IsLet = IsLet;
2638
2666
VarDeclBits.IsDebuggerVar = false ;
2639
2667
setType (Ty);
@@ -2670,8 +2698,11 @@ class VarDecl : public AbstractStorageDecl {
2670
2698
bool isAnonClosureParam () const ;
2671
2699
2672
2700
// / Is this a type ('static') variable?
2673
- bool isStatic () const { return VarDeclBits.Static ; }
2674
- void setStatic (bool IsStatic) { VarDeclBits.Static = IsStatic; }
2701
+ bool isStatic () const { return VarDeclBits.IsStatic ; }
2702
+ void setStatic (bool IsStatic) { VarDeclBits.IsStatic = IsStatic; }
2703
+
2704
+ // / \returns the way 'static'/'class' should be spelled for this declaration.
2705
+ StaticSpellingKind getCorrectStaticSpelling () const ;
2675
2706
2676
2707
// / Is this an immutable 'let' property?
2677
2708
bool isLet () const { return VarDeclBits.IsLet ; }
@@ -3053,14 +3084,16 @@ class FuncDecl : public AbstractFunctionDecl {
3053
3084
FuncDecl *OverriddenDecl;
3054
3085
OperatorDecl *Operator;
3055
3086
3056
- FuncDecl (SourceLoc StaticLoc, SourceLoc FuncLoc, Identifier Name,
3087
+ FuncDecl (SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
3088
+ SourceLoc FuncLoc, Identifier Name,
3057
3089
SourceLoc NameLoc, unsigned NumParamPatterns,
3058
3090
GenericParamList *GenericParams, Type Ty, DeclContext *Parent)
3059
3091
: AbstractFunctionDecl(DeclKind::Func, Parent, Name, NameLoc,
3060
3092
NumParamPatterns, GenericParams),
3061
3093
StaticLoc (StaticLoc), FuncLoc(FuncLoc),
3062
3094
OverriddenDecl(nullptr ), Operator(nullptr ) {
3063
- FuncDeclBits.Static = StaticLoc.isValid () || getName ().isOperator ();
3095
+ FuncDeclBits.IsStatic = StaticLoc.isValid () || getName ().isOperator ();
3096
+ FuncDeclBits.StaticSpelling = static_cast <unsigned >(StaticSpelling);
3064
3097
assert (NumParamPatterns > 0 && " Must have at least an empty tuple arg" );
3065
3098
setType (Ty);
3066
3099
FuncDeclBits.Mutating = false ;
@@ -3070,27 +3103,35 @@ class FuncDecl : public AbstractFunctionDecl {
3070
3103
public:
3071
3104
// / Factory function only for use by deserialization.
3072
3105
static FuncDecl *createDeserialized (ASTContext &Context, SourceLoc StaticLoc,
3106
+ StaticSpellingKind StaticSpelling,
3073
3107
SourceLoc FuncLoc, Identifier Name,
3074
3108
SourceLoc NameLoc,
3075
3109
GenericParamList *GenericParams, Type Ty,
3076
3110
unsigned NumParamPatterns,
3077
3111
DeclContext *Parent);
3078
3112
3079
3113
static FuncDecl *create (ASTContext &Context, SourceLoc StaticLoc,
3114
+ StaticSpellingKind StaticSpelling,
3080
3115
SourceLoc FuncLoc, Identifier Name, SourceLoc NameLoc,
3081
3116
GenericParamList *GenericParams, Type Ty,
3082
3117
ArrayRef<Pattern *> ArgParams,
3083
3118
ArrayRef<Pattern *> BodyParams,
3084
3119
TypeLoc FnRetType, DeclContext *Parent);
3085
3120
3086
3121
bool isStatic () const {
3087
- return FuncDeclBits.Static ;
3122
+ return FuncDeclBits.IsStatic ;
3123
+ }
3124
+ // / \returns the way 'static'/'class' was spelled in the source.
3125
+ StaticSpellingKind getStaticSpelling () const {
3126
+ return static_cast <StaticSpellingKind>(FuncDeclBits.StaticSpelling );
3088
3127
}
3128
+ // / \returns the way 'static'/'class' should be spelled for this declaration.
3129
+ StaticSpellingKind getCorrectStaticSpelling () const ;
3089
3130
bool isMutating () const {
3090
3131
return FuncDeclBits.Mutating ;
3091
3132
}
3092
- void setStatic (bool Static = true ) {
3093
- FuncDeclBits.Static = Static ;
3133
+ void setStatic (bool IsStatic = true ) {
3134
+ FuncDeclBits.IsStatic = IsStatic ;
3094
3135
}
3095
3136
void setMutating (bool Mutating = true ) {
3096
3137
FuncDeclBits.Mutating = Mutating;
0 commit comments