@@ -1516,7 +1516,7 @@ declaration_statement
1516
1516
1517
1517
// Source: §13.6.2 Local variable declarations
1518
1518
local_variable_declaration
1519
- : ('ref' 'readonly'?) ? local_variable_type local_variable_declarators
1519
+ : ref_kind ? local_variable_type local_variable_declarators
1520
1520
;
1521
1521
1522
1522
local_variable_type
@@ -1555,16 +1555,18 @@ constant_declarator
1555
1555
1556
1556
// Source: §13.6.4 Local function declarations
1557
1557
local_function_declaration
1558
- : local_function_header local_function_body
1558
+ : local_function_modifier* return_type local_function_header local_function_body
1559
+ | ref_kind ref_return_type local_function_header ref_local_function_body
1559
1560
;
1560
1561
1561
1562
local_function_header
1562
- : local_function_modifier* ('ref' 'readonly'?)? return_type identifier type_parameter_list?
1563
- '(' formal_parameter_list? ')' type_parameter_constraints_clause*
1563
+ : identifier '(' formal_parameter_list? ')'
1564
+ | identifier type_parameter_list '(' formal_parameter_list? ')' type_parameter_constraints_clause*
1564
1565
;
1566
+
1565
1567
local_function_modifier
1566
1568
: 'async'
1567
- | ' unsafe'
1569
+ | unsafe_modifier // unsafe code support
1568
1570
;
1569
1571
1570
1572
local_function_body
@@ -1573,6 +1575,11 @@ local_function_body
1573
1575
| '=>' expression ';'
1574
1576
;
1575
1577
1578
+ ref_local_function_body
1579
+ : block
1580
+ | '=>' 'ref' variable_reference ';'
1581
+ ;
1582
+
1576
1583
// Source: §13.7 Expression statements
1577
1584
expression_statement
1578
1585
: statement_expression ';'
@@ -1668,7 +1675,7 @@ statement_expression_list
1668
1675
1669
1676
// Source: §13.9.5 The foreach statement
1670
1677
foreach_statement
1671
- : 'foreach' '(' ('ref' 'readonly'?) ? local_variable_type identifier 'in'
1678
+ : 'foreach' '(' ref_kind ? local_variable_type identifier 'in'
1672
1679
expression ')' embedded_statement
1673
1680
;
1674
1681
@@ -1978,16 +1985,35 @@ variable_declarator
1978
1985
1979
1986
// Source: §15.6.1 General
1980
1987
method_declaration
1981
- : method_header method_body
1988
+ : attributes? method_modifiers return_type method_header method_body
1989
+ | attributes? ref_method_modifiers ref_kind ref_return_type method_header ref_method_body
1990
+ ;
1991
+
1992
+ method_modifiers
1993
+ : method_modifier* 'partial'?
1994
+ ;
1995
+
1996
+ ref_kind
1997
+ : 'ref'
1998
+ | 'ref' 'readonly'
1999
+ ;
2000
+
2001
+ ref_method_modifiers
2002
+ : ref_method_modifier*
1982
2003
;
1983
2004
1984
2005
method_header
1985
- : attributes? method_modifier* 'partial'? ('ref' 'readonly'?)?
1986
- return_type member_name type_parameter_list?
1987
- '(' formal_parameter_list? ')' type_parameter_constraints_clause*
2006
+ : member_name '(' formal_parameter_list? ')'
2007
+ | member_name type_parameter_list '(' formal_parameter_list? ')' type_parameter_constraints_clause*
1988
2008
;
1989
2009
1990
2010
method_modifier
2011
+ : ref_method_modifier
2012
+ | 'async'
2013
+ | unsafe_modifier // unsafe code support
2014
+ ;
2015
+
2016
+ ref_method_modifier
1991
2017
: 'new'
1992
2018
| 'public'
1993
2019
| 'protected'
@@ -1999,15 +2025,17 @@ method_modifier
1999
2025
| 'override'
2000
2026
| 'abstract'
2001
2027
| 'extern'
2002
- | 'async'
2003
- | unsafe_modifier // unsafe code support
2004
2028
;
2005
2029
2006
2030
return_type
2007
- : type
2031
+ : ref_return_type
2008
2032
| 'void'
2009
2033
;
2010
2034
2035
+ ref_return_type
2036
+ : type
2037
+ ;
2038
+
2011
2039
member_name
2012
2040
: identifier
2013
2041
| interface_type '.' identifier
@@ -2020,6 +2048,12 @@ method_body
2020
2048
| ';'
2021
2049
;
2022
2050
2051
+ ref_method_body
2052
+ : block
2053
+ | '=>' 'ref' variable_reference ';'
2054
+ | ';'
2055
+ ;
2056
+
2023
2057
// Source: §15.6.2.1 General
2024
2058
formal_parameter_list
2025
2059
: fixed_parameters
@@ -2056,8 +2090,8 @@ parameter_array
2056
2090
2057
2091
// Source: §15.7.1 General
2058
2092
property_declaration
2059
- : attributes? property_modifier* ('ref' 'readonly'?)? type
2060
- member_name property_body
2093
+ : attributes? property_modifier* type member_name property_body
2094
+ | attributes? property_modifier* ref_kind type member_name ref_property_body
2061
2095
;
2062
2096
2063
2097
property_modifier
@@ -2084,6 +2118,11 @@ property_initializer
2084
2118
: '=' variable_initializer ';'
2085
2119
;
2086
2120
2121
+ ref_property_body
2122
+ : '{' ref_get_accessor_declaration '}'
2123
+ | '=>' 'ref' variable_reference ';'
2124
+ ;
2125
+
2087
2126
// Source: §15.7.3 Accessors
2088
2127
accessor_declarations
2089
2128
: get_accessor_declaration set_accessor_declaration?
@@ -2114,6 +2153,16 @@ accessor_body
2114
2153
| ';'
2115
2154
;
2116
2155
2156
+ ref_get_accessor_declaration
2157
+ : attributes? accessor_modifier? 'get' ref_accessor_body
2158
+ ;
2159
+
2160
+ ref_accessor_body
2161
+ : block
2162
+ | '=>' 'ref' variable_reference ';'
2163
+ | ';'
2164
+ ;
2165
+
2117
2166
// Source: §15.8.1 General
2118
2167
event_declaration
2119
2168
: attributes? event_modifier* 'event' type variable_declarators ';'
@@ -2149,9 +2198,10 @@ remove_accessor_declaration
2149
2198
: attributes? 'remove' block
2150
2199
;
2151
2200
2152
- // Source: §15.9 Indexers
2201
+ // Source: §15.9.1 General
2153
2202
indexer_declaration
2154
2203
: attributes? indexer_modifier* indexer_declarator indexer_body
2204
+ | attributes? indexer_modifier* ref_kind indexer_declarator ref_indexer_body
2155
2205
;
2156
2206
2157
2207
indexer_modifier
@@ -2169,15 +2219,20 @@ indexer_modifier
2169
2219
;
2170
2220
2171
2221
indexer_declarator
2172
- : ('ref' 'readonly'?)? type 'this' '[' formal_parameter_list ']'
2173
- | ('ref' 'readonly'?)? type interface_type '.' 'this' '[' formal_parameter_list ']'
2222
+ : type 'this' '[' formal_parameter_list ']'
2223
+ | type interface_type '.' 'this' '[' formal_parameter_list ']'
2174
2224
;
2175
2225
2176
2226
indexer_body
2177
2227
: '{' accessor_declarations '}'
2178
2228
| '=>' expression ';'
2179
2229
;
2180
2230
2231
+ ref_indexer_body
2232
+ : '{' ref_get_accessor_declaration '}'
2233
+ | '=>' 'ref' variable_reference ';'
2234
+ ;
2235
+
2181
2236
// Source: §15.10.1 General
2182
2237
operator_declaration
2183
2238
: attributes? operator_modifier+ operator_declarator operator_body
@@ -2404,32 +2459,43 @@ interface_member_declaration
2404
2459
2405
2460
// Source: §18.4.2 Interface methods
2406
2461
interface_method_declaration
2407
- : attributes? 'new'? return_type identifier type_parameter_list?
2408
- '(' formal_parameter_list? ')' type_parameter_constraints_clause* ';'
2462
+ : attributes? 'new'? return_type interface_method_header
2463
+ | attributes? 'new'? ref_kind ref_return_type interface_method_header
2464
+ ;
2465
+
2466
+ interface_method_header
2467
+ : identifier '(' formal_parameter_list? ')' ';'
2468
+ | identifier type_parameter_list '(' formal_parameter_list? ')' type_parameter_constraints_clause* ';'
2409
2469
;
2410
2470
2411
2471
// Source: §18.4.3 Interface properties
2412
2472
interface_property_declaration
2413
2473
: attributes? 'new'? type identifier '{' interface_accessors '}'
2474
+ | attributes? 'new'? ref_kind type identifier '{' ref_interface_accessor '}'
2414
2475
;
2415
2476
2416
- // Source: §18.4.3 Interface properties
2417
2477
interface_accessors
2418
2478
: attributes? 'get' ';'
2419
2479
| attributes? 'set' ';'
2420
2480
| attributes? 'get' ';' attributes? 'set' ';'
2421
2481
| attributes? 'set' ';' attributes? 'get' ';'
2422
2482
;
2423
2483
2484
+ ref_interface_accessor
2485
+ : attributes? 'get' ';'
2486
+ ;
2487
+
2424
2488
// Source: §18.4.4 Interface events
2425
2489
interface_event_declaration
2426
2490
: attributes? 'new'? 'event' type identifier ';'
2427
2491
;
2428
2492
2429
2493
// Source: §18.4.5 Interface indexers
2430
- interface_indexer_declaration:
2431
- attributes? 'new'? type 'this' '[' formal_parameter_list ']'
2432
- '{' interface_accessors '}'
2494
+ interface_indexer_declaration
2495
+ : attributes? 'new'? type 'this' '[' formal_parameter_list ']'
2496
+ '{' interface_accessors '}'
2497
+ | attributes? 'new'? ref_kind type 'this' '[' formal_parameter_list ']'
2498
+ '{' ref_interface_accessor '}'
2433
2499
;
2434
2500
2435
2501
// Source: §19.2 Enum declarations
@@ -2472,17 +2538,26 @@ enum_member_declaration
2472
2538
2473
2539
// Source: §20.2 Delegate declarations
2474
2540
delegate_declaration
2475
- : attributes? delegate_modifier* 'delegate' ('ref' 'readonly'?)? return_type identifier variant_type_parameter_list?
2476
- '(' formal_parameter_list? ')' type_parameter_constraints_clause* ';'
2541
+ : attributes? delegate_modifier* 'delegate' return_type delegate_header
2542
+ | attributes? ref_delegate_modifier* 'delegate' ref_kind ref_return_type delegate_header
2543
+ ;
2544
+
2545
+ delegate_header
2546
+ : identifier '(' formal_parameter_list? ')' ';'
2547
+ | identifier variant_type_parameter_list '(' formal_parameter_list? ')' type_parameter_constraints_clause* ';'
2477
2548
;
2478
2549
2479
2550
delegate_modifier
2551
+ : ref_delegate_modifier
2552
+ | unsafe_modifier // unsafe code support
2553
+ ;
2554
+
2555
+ ref_delegate_modifier
2480
2556
: 'new'
2481
2557
| 'public'
2482
2558
| 'protected'
2483
2559
| 'internal'
2484
2560
| 'private'
2485
- | unsafe_modifier // unsafe code support
2486
2561
;
2487
2562
2488
2563
// Source: §22.3 Attribute specification
0 commit comments