From: Marek Safar Date: Mon, 31 Jul 2017 14:58:14 +0000 (+0200) Subject: [mcs] Implements C#7 expression bodied members enhancement X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mono.git;a=commitdiff_plain;h=9a1d66fa3a9103fb8a6e0eb81a3a80d7df71511d [mcs] Implements C#7 expression bodied members enhancement --- diff --git a/mcs/errors/cs1525-23.cs b/mcs/errors/cs1525-23.cs index 8a97e05efb1..aa5ffc64e48 100644 --- a/mcs/errors/cs1525-23.cs +++ b/mcs/errors/cs1525-23.cs @@ -1,4 +1,4 @@ -// CS1525: Unexpected symbol `public', expecting `:', `;', or `{' +// CS1525: Unexpected symbol `public', expecting `:', `;', `{', or `=>' // Line: 5 class TorrentEditor { diff --git a/mcs/mcs/cs-parser.jay b/mcs/mcs/cs-parser.jay index 514113a6bf7..5f885a77763 100644 --- a/mcs/mcs/cs-parser.jay +++ b/mcs/mcs/cs-parser.jay @@ -1337,7 +1337,7 @@ method_declaration // Was added earlier in the case of body being eof for full ast } - method_body_expression_block + method_body { Method method = (Method) $1; method.Block = (ToplevelBlock) $3; @@ -1492,16 +1492,38 @@ method_header } ; -method_body_expression_block - : method_body - | expression_block - ; - method_body : block + | expression_block | SEMICOLON { $$ = null; } ; +destructor_body + : method_body + ; + +constructor_body + : block_prepared + | SEMICOLON { current_block = null; $$ = null; } + | ARROW + { + if (lang_version < LanguageVersion.V_7) { + FeatureIsNotAvailable (GetLocation ($1), "expression body constructor"); + } + + ++lexer.parsing_block; + } + expression SEMICOLON + { + lexer.parsing_block = 0; + current_block.AddStatement (new ContextualReturn ((Expression) $3)); + var b = end_block (GetLocation ($4)); + b.IsCompilerGenerated = true; + $$ = b; + current_block = null; + } + ; + expression_block : ARROW { @@ -2197,7 +2219,7 @@ operator_declaration : opt_attributes opt_modifiers operator_declarator { } - method_body_expression_block + method_body { OperatorDeclaration decl = (OperatorDeclaration) $3; if (decl != null) { @@ -2464,11 +2486,6 @@ constructor_declarator } ; -constructor_body - : block_prepared - | SEMICOLON { current_block = null; $$ = null; } - ; - opt_constructor_initializer : /* Empty */ | constructor_initializer @@ -2518,7 +2535,7 @@ destructor_declaration current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters; } - IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body + IDENTIFIER OPEN_PARENS CLOSE_PARENS destructor_body { var lt = (LocatedToken) $5; if (lt.Value != current_container.MemberName.Name){ diff --git a/mcs/tests/test-expression-bodied-04.cs b/mcs/tests/test-expression-bodied-04.cs new file mode 100644 index 00000000000..815eabc3c1a --- /dev/null +++ b/mcs/tests/test-expression-bodied-04.cs @@ -0,0 +1,16 @@ +// Introduced in C#7 + +class VV +{ + VV () => Test (); + + ~VV () => Test (); + + void Test () + { + } + + public static void Main () + { + } +} \ No newline at end of file diff --git a/mcs/tests/ver-il-net_4_x.xml b/mcs/tests/ver-il-net_4_x.xml index 5eac11969e1..221283df2e4 100644 --- a/mcs/tests/ver-il-net_4_x.xml +++ b/mcs/tests/ver-il-net_4_x.xml @@ -68783,6 +68783,22 @@ + + + + 19 + + + 2 + + + 2 + + + 13 + + +