@@ -241,7 +241,18 @@ struct expression_node
241
241
}
242
242
};
243
243
244
- enum class passing_style { in=0 , copy, inout, out, move, forward };
244
+ enum class passing_style { in=0 , copy, inout, out, move, forward, invalid };
245
+ auto to_passing_style (token const & t) -> passing_style {
246
+ if (t.type () == lexeme::Identifier) {
247
+ if (t == " in" ) { return passing_style::in; }
248
+ if (t == " copy" ) { return passing_style::copy; }
249
+ if (t == " inout" ) { return passing_style::inout; }
250
+ if (t == " out" ) { return passing_style::out; }
251
+ if (t == " move" ) { return passing_style::move; }
252
+ if (t == " forward" ) { return passing_style::forward; }
253
+ }
254
+ return passing_style::invalid;
255
+ }
245
256
auto to_string_view (passing_style pass) -> std::string_view {
246
257
switch (pass) {
247
258
break ;case passing_style::in : return " in" ;
@@ -1549,14 +1560,7 @@ class parser
1549
1560
return n;
1550
1561
}
1551
1562
1552
- if (curr ().type () == lexeme::DecimalLiteral ||
1553
- curr ().type () == lexeme::FloatLiteral ||
1554
- curr ().type () == lexeme::StringLiteral ||
1555
- curr ().type () == lexeme::CharacterLiteral ||
1556
- curr ().type () == lexeme::BinaryLiteral ||
1557
- curr ().type () == lexeme::HexadecimalLiteral
1558
- )
1559
- {
1563
+ if (is_literal (curr ().type ())) {
1560
1564
n->expr = &curr ();
1561
1565
next ();
1562
1566
return n;
@@ -2047,16 +2051,11 @@ class parser
2047
2051
n->open_paren = open_paren;
2048
2052
n->inside_initializer = inside_initializer;
2049
2053
2050
- if (curr ().type () == lexeme::Identifier && curr () == " out" ) {
2051
- pass = passing_style::out;
2052
- next ();
2053
- }
2054
- else if (curr ().type () == lexeme::Identifier && curr () == " move" ) {
2055
- pass = passing_style::move;
2056
- next ();
2057
- }
2058
- else if (curr ().type () == lexeme::Identifier && curr () == " forward" ) {
2059
- pass = passing_style::forward;
2054
+ if (auto dir = to_passing_style (curr ());
2055
+ dir == passing_style::out || dir == passing_style::move || dir == passing_style::forward
2056
+ )
2057
+ {
2058
+ pass = dir;
2060
2059
next ();
2061
2060
}
2062
2061
auto x = expression ();
@@ -2072,16 +2071,11 @@ class parser
2072
2071
while (curr ().type () == lexeme::Comma) {
2073
2072
next ();
2074
2073
pass = passing_style::in;
2075
- if (curr ().type () == lexeme::Identifier && curr () == " out" ) {
2076
- pass = passing_style::out;
2077
- next ();
2078
- }
2079
- else if (curr ().type () == lexeme::Identifier && curr () == " move" ) {
2080
- pass = passing_style::move;
2081
- next ();
2082
- }
2083
- else if (curr ().type () == lexeme::Identifier && curr () == " forward" ) {
2084
- pass = passing_style::forward;
2074
+ if (auto dir = to_passing_style (curr ());
2075
+ dir == passing_style::out || dir == passing_style::move || dir == passing_style::forward
2076
+ )
2077
+ {
2078
+ pass = dir;
2085
2079
next ();
2086
2080
}
2087
2081
auto expr = expression ();
@@ -2959,51 +2953,31 @@ class parser
2959
2953
n->pass = returns ? passing_style::out : passing_style::in;
2960
2954
n->pos = curr ().position ();
2961
2955
2962
- if (curr (). type () == lexeme::Identifier ) {
2963
- if (curr () == " in " ) {
2964
- if (returns ) {
2956
+ if (auto dir = to_passing_style ( curr ()); dir != passing_style::invalid ) {
2957
+ if (returns ) {
2958
+ if (dir == passing_style::in ) {
2965
2959
error (" a return value cannot be 'in'" );
2966
2960
return {};
2967
2961
}
2968
- n->pass = passing_style::in;
2969
- next ();
2970
- }
2971
- else if (curr () == " copy" ) {
2972
- if (returns) {
2962
+ if (dir == passing_style::copy) {
2973
2963
error (" a return value cannot be 'copy'" );
2974
2964
return {};
2975
2965
}
2976
- n->pass = passing_style::copy;
2977
- next ();
2978
- }
2979
- else if (curr () == " inout" ) {
2980
- if (returns) {
2966
+ if (dir == passing_style::inout) {
2981
2967
error (" a return value cannot be 'inout'" );
2982
2968
return {};
2983
2969
}
2984
- n->pass = passing_style::inout;
2985
- next ();
2986
- }
2987
- else if (curr () == " out" ) {
2988
- if (!named) {
2989
- error (" (temporary alpha limitation) an unnamed function cannot have an 'out' parameter" );
2990
- return {};
2991
- }
2992
- n->pass = passing_style::out;
2993
- next ();
2994
- }
2995
- else if (curr () == " move" ) {
2996
- if (returns) {
2970
+ if (dir == passing_style::move) {
2997
2971
error (" a return value cannot be 'move' (it is implicitly 'move'-out)" );
2998
2972
return {};
2999
2973
}
3000
- n->pass = passing_style::move;
3001
- next ();
3002
2974
}
3003
- else if (curr () == " forward " ) {
3004
- n-> pass = passing_style::forward ;
3005
- next () ;
2975
+ if (!named && dir == passing_style::out ) {
2976
+ error ( " (temporary alpha limitation) an unnamed function cannot have an 'out' parameter " ) ;
2977
+ return {} ;
3006
2978
}
2979
+ n->pass = dir;
2980
+ next ();
3007
2981
}
3008
2982
3009
2983
if (curr ().type () == lexeme::Identifier) {
0 commit comments