@@ -37,20 +37,25 @@ public enum OperatorType
37
37
LogicalNot ,
38
38
OnesComplement ,
39
39
Increment ,
40
+ CheckedIncrement ,
40
41
Decrement ,
42
+ CheckedDecrement ,
41
43
True ,
42
44
False ,
43
45
44
- // Unary and Binary operators
45
- Addition ,
46
- Subtraction ,
47
-
48
46
UnaryPlus ,
49
47
UnaryNegation ,
48
+ CheckedUnaryNegation ,
50
49
51
50
// Binary operators
51
+ Addition ,
52
+ CheckedAddition ,
53
+ Subtraction ,
54
+ CheckedSubtraction ,
52
55
Multiply ,
56
+ CheckedMultiply ,
53
57
Division ,
58
+ CheckedDivision ,
54
59
Modulus ,
55
60
BitwiseAnd ,
56
61
BitwiseOr ,
@@ -67,12 +72,14 @@ public enum OperatorType
67
72
68
73
// Implicit and Explicit
69
74
Implicit ,
70
- Explicit
75
+ Explicit ,
76
+ CheckedExplicit
71
77
}
72
78
73
79
public class OperatorDeclaration : EntityDeclaration
74
80
{
75
81
public static readonly TokenRole OperatorKeywordRole = new TokenRole ( "operator" ) ;
82
+ public static readonly TokenRole CheckedKeywordRole = new TokenRole ( "checked" ) ;
76
83
77
84
// Unary operators
78
85
public static readonly TokenRole LogicalNotRole = new TokenRole ( "!" ) ;
@@ -110,19 +117,26 @@ public class OperatorDeclaration : EntityDeclaration
110
117
111
118
static OperatorDeclaration ( )
112
119
{
113
- names = new string [ ( int ) OperatorType . Explicit + 1 ] [ ] ;
120
+ names = new string [ ( int ) OperatorType . CheckedExplicit + 1 ] [ ] ;
114
121
names [ ( int ) OperatorType . LogicalNot ] = new string [ ] { "!" , "op_LogicalNot" } ;
115
122
names [ ( int ) OperatorType . OnesComplement ] = new string [ ] { "~" , "op_OnesComplement" } ;
116
123
names [ ( int ) OperatorType . Increment ] = new string [ ] { "++" , "op_Increment" } ;
124
+ names [ ( int ) OperatorType . CheckedIncrement ] = new string [ ] { "++" , "op_CheckedIncrement" } ;
117
125
names [ ( int ) OperatorType . Decrement ] = new string [ ] { "--" , "op_Decrement" } ;
126
+ names [ ( int ) OperatorType . CheckedDecrement ] = new string [ ] { "--" , "op_CheckedDecrement" } ;
118
127
names [ ( int ) OperatorType . True ] = new string [ ] { "true" , "op_True" } ;
119
128
names [ ( int ) OperatorType . False ] = new string [ ] { "false" , "op_False" } ;
120
- names [ ( int ) OperatorType . Addition ] = new string [ ] { "+" , "op_Addition" } ;
121
- names [ ( int ) OperatorType . Subtraction ] = new string [ ] { "-" , "op_Subtraction" } ;
122
129
names [ ( int ) OperatorType . UnaryPlus ] = new string [ ] { "+" , "op_UnaryPlus" } ;
123
130
names [ ( int ) OperatorType . UnaryNegation ] = new string [ ] { "-" , "op_UnaryNegation" } ;
131
+ names [ ( int ) OperatorType . CheckedUnaryNegation ] = new string [ ] { "-" , "op_CheckedUnaryNegation" } ;
132
+ names [ ( int ) OperatorType . Addition ] = new string [ ] { "+" , "op_Addition" } ;
133
+ names [ ( int ) OperatorType . CheckedAddition ] = new string [ ] { "+" , "op_CheckedAddition" } ;
134
+ names [ ( int ) OperatorType . Subtraction ] = new string [ ] { "-" , "op_Subtraction" } ;
135
+ names [ ( int ) OperatorType . CheckedSubtraction ] = new string [ ] { "-" , "op_CheckedSubtraction" } ;
124
136
names [ ( int ) OperatorType . Multiply ] = new string [ ] { "*" , "op_Multiply" } ;
137
+ names [ ( int ) OperatorType . CheckedMultiply ] = new string [ ] { "*" , "op_CheckedMultiply" } ;
125
138
names [ ( int ) OperatorType . Division ] = new string [ ] { "/" , "op_Division" } ;
139
+ names [ ( int ) OperatorType . CheckedDivision ] = new string [ ] { "/" , "op_CheckedDivision" } ;
126
140
names [ ( int ) OperatorType . Modulus ] = new string [ ] { "%" , "op_Modulus" } ;
127
141
names [ ( int ) OperatorType . BitwiseAnd ] = new string [ ] { "&" , "op_BitwiseAnd" } ;
128
142
names [ ( int ) OperatorType . BitwiseOr ] = new string [ ] { "|" , "op_BitwiseOr" } ;
@@ -138,6 +152,7 @@ static OperatorDeclaration()
138
152
names [ ( int ) OperatorType . LessThanOrEqual ] = new string [ ] { "<=" , "op_LessThanOrEqual" } ;
139
153
names [ ( int ) OperatorType . Implicit ] = new string [ ] { "implicit" , "op_Implicit" } ;
140
154
names [ ( int ) OperatorType . Explicit ] = new string [ ] { "explicit" , "op_Explicit" } ;
155
+ names [ ( int ) OperatorType . CheckedExplicit ] = new string [ ] { "explicit" , "op_CheckedExplicit" } ;
141
156
}
142
157
143
158
public override SymbolKind SymbolKind {
@@ -202,24 +217,31 @@ public static TokenRole GetRole(OperatorType type)
202
217
case OperatorType . OnesComplement :
203
218
return OnesComplementRole ;
204
219
case OperatorType . Increment :
220
+ case OperatorType . CheckedIncrement :
205
221
return IncrementRole ;
206
222
case OperatorType . Decrement :
223
+ case OperatorType . CheckedDecrement :
207
224
return DecrementRole ;
208
225
case OperatorType . True :
209
226
return TrueRole ;
210
227
case OperatorType . False :
211
228
return FalseRole ;
212
229
213
230
case OperatorType . Addition :
231
+ case OperatorType . CheckedAddition :
214
232
case OperatorType . UnaryPlus :
215
233
return AdditionRole ;
216
234
case OperatorType . Subtraction :
235
+ case OperatorType . CheckedSubtraction :
217
236
case OperatorType . UnaryNegation :
237
+ case OperatorType . CheckedUnaryNegation :
218
238
return SubtractionRole ;
219
239
220
240
case OperatorType . Multiply :
241
+ case OperatorType . CheckedMultiply :
221
242
return MultiplyRole ;
222
243
case OperatorType . Division :
244
+ case OperatorType . CheckedDivision :
223
245
return DivisionRole ;
224
246
case OperatorType . Modulus :
225
247
return ModulusRole ;
@@ -251,6 +273,7 @@ public static TokenRole GetRole(OperatorType type)
251
273
case OperatorType . Implicit :
252
274
return ImplicitRole ;
253
275
case OperatorType . Explicit :
276
+ case OperatorType . CheckedExplicit :
254
277
return ExplicitRole ;
255
278
256
279
default :
@@ -269,7 +292,26 @@ public static string GetName(OperatorType? type)
269
292
}
270
293
271
294
/// <summary>
272
- /// Gets the token for the operator type ("+", "implicit", etc.)
295
+ /// Gets whether the operator type is a C# 11 "operator checked".
296
+ /// </summary>
297
+ public static bool IsChecked ( OperatorType type )
298
+ {
299
+ return type switch {
300
+ OperatorType . CheckedAddition => true ,
301
+ OperatorType . CheckedSubtraction => true ,
302
+ OperatorType . CheckedMultiply => true ,
303
+ OperatorType . CheckedDivision => true ,
304
+ OperatorType . CheckedUnaryNegation => true ,
305
+ OperatorType . CheckedIncrement => true ,
306
+ OperatorType . CheckedDecrement => true ,
307
+ OperatorType . CheckedExplicit => true ,
308
+ _ => false ,
309
+ } ;
310
+ }
311
+
312
+ /// <summary>
313
+ /// Gets the token for the operator type ("+", "implicit", etc.).
314
+ /// Does not include the "checked" modifier.
273
315
/// </summary>
274
316
public static string GetToken ( OperatorType type )
275
317
{
0 commit comments