opt_modifiers
opt_partial
STRUCT
- {
- }
type_declaration_name
- {
+ {
+ var mods = (Modifiers) $2;
+ if ((mods & Modifiers.READONLY) != 0 && lang_version < LanguageVersion.V_7_2) {
+ FeatureIsNotAvailable (GetLocation ($4), "readonly structs");
+ }
+
lexer.ConstraintsParsing = true;
valid_param_mod = ParameterModifierType.PrimaryConstructor;
- push_current_container (new Struct (current_container, (MemberName) $6, (Modifiers) $2, (Attributes) $1), $3);
+ push_current_container (new Struct (current_container, (MemberName) $5, mods, (Attributes) $1), $3);
}
opt_primary_parameters
opt_class_base
valid_param_mod = 0;
lexer.ConstraintsParsing = false;
- if ($8 != null)
- current_type.PrimaryConstructorParameters = (ParametersCompiled) $8;
+ if ($7 != null)
+ current_type.PrimaryConstructorParameters = (ParametersCompiled) $7;
- if ($10 != null)
- current_container.SetConstraints ((List<Constraints>) $10);
+ if ($9 != null)
+ current_container.SetConstraints ((List<Constraints>) $9);
if (doc_support)
current_container.PartialContainer.DocComment = Lexer.consume_doc_comment ();
}
opt_semicolon
{
- if ($16 == null) {
- lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15));
+ if ($15 == null) {
+ lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14));
} else {
- lbag.AppendToMember (current_container, GetLocation ($12), GetLocation ($15), GetLocation ($17));
+ lbag.AppendToMember (current_container, GetLocation ($11), GetLocation ($14), GetLocation ($16));
}
$$ = pop_current_class ();
}
field_declaration
: opt_attributes
opt_modifiers
- member_type IDENTIFIER
+ ref_member_type IDENTIFIER
{
lexer.parsing_generic_declaration = false;
}
;
+ref_member_type
+ : member_type
+ {
+ $$ = $1;
+ }
+ | REF
+ {
+ lexer.parsing_generic_declaration = true;
+ }
+ type
+ {
+ if (lang_version < LanguageVersion.V_7) {
+ FeatureIsNotAvailable (GetLocation ($1), "byref locals and returns");
+ }
+
+ $$ = new ReferenceTypeExpr ((FullNamedExpression) $3, GetLocation ($1));
+ }
+ ;
+
method_header
: opt_attributes
opt_modifiers
- member_type
+ ref_member_type
method_declaration_name OPEN_PARENS
{
valid_param_mod = ParameterModifierType.All;
}
| opt_attributes
opt_modifiers
- member_type
+ ref_member_type
modifiers method_declaration_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
{
MemberName name = (MemberName) $5;
}
| opt_attributes
opt_modifiers
- member_type
+ ref_member_type
method_declaration_name error
{
Error_SyntaxError (yyToken);
++lexer.parsing_block;
start_block (GetLocation ($1));
}
- expression SEMICOLON
+ lambda_arrow_expression SEMICOLON
{
lexer.parsing_block = 0;
current_block.AddStatement (new ContextualReturn ((Expression) $3));
property_declaration
: opt_attributes
opt_modifiers
- member_type
+ ref_member_type
member_declaration_name
{
lexer.parsing_generic_declaration = false;
if (doc_support)
current_property.DocComment = ConsumeStoredComment ();
+
+ if ($3 is ReferenceTypeExpr) {
+ if (current_property.Get == null) {
+ report.Error (8146, GetLocation ($4), "`{0}': property and indexer which return by reference must have a get accessor", current_property.GetSignatureForError ());
+ }
+
+ if (current_property.Set != null) {
+ report.Error (8147, GetLocation ($4), "`{0}': property and indexer which return by reference cannot have set accessors", current_property.GetSignatureForError ());
+ }
+ }
}
CLOSE_BRACE
{
}
| opt_attributes
opt_modifiers
- member_type
+ ref_member_type
member_declaration_name
{
lexer.parsing_generic_declaration = false;
indexer_declaration
: opt_attributes opt_modifiers
- member_type indexer_declaration_name OPEN_BRACKET
+ ref_member_type indexer_declaration_name OPEN_BRACKET
{
valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue;
}
if (doc_support)
current_property.DocComment = ConsumeStoredComment ();
+
+ if ($3 is ReferenceTypeExpr) {
+ if (current_property.Get == null) {
+ report.Error (8146, GetLocation ($4), "`{0}': property and indexer which return by reference must have a get accessor", current_property.GetSignatureForError ());
+ }
+
+ if (current_property.Set != null) {
+ report.Error (8147, GetLocation ($4), "`{0}': property and indexer which return by reference cannot have set accessors", current_property.GetSignatureForError ());
+ }
+ }
current_property = null;
}
: opt_attributes
opt_modifiers
DELEGATE
- member_type type_declaration_name
+ ref_member_type type_declaration_name
OPEN_PARENS
{
valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue;
: {
start_block (Location.Null);
}
- expression // All expressions must handle error or current block won't be restored and breaking ast completely
+ lambda_arrow_expression // All expressions must handle error or current block won't be restored and breaking ast completely
{
Block b = end_block (Location.Null);
b.IsCompilerGenerated = true;
}
;
+lambda_arrow_expression
+ : expression
+ | reference_expression
+ ;
+
expression_or_error
: expression
| error
current_variable = null;
lbag.AddLocation ($$, GetLocation ($1), GetLocation ($7));
}
+ | REF variable_type identifier_inside_body
+ {
+ if (lang_version < LanguageVersion.V_7) {
+ FeatureIsNotAvailable (GetLocation ($1), "byref locals and returns");
+ }
+
+ var lt = (LocatedToken) $3;
+ var li = new LocalVariable (current_block, lt.Value, LocalVariable.Flags.ByRef, lt.Location);
+ current_block.AddLocalName (li);
+ current_variable = new BlockVariable ((FullNamedExpression) $2, li);
+ }
+ opt_local_variable_initializer opt_variable_declarators SEMICOLON
+ {
+ $$ = current_variable;
+ current_variable = null;
+ if ($5 != null) {
+ lbag.AddLocation ($$, PopLocation (), GetLocation ($7));
+ } else {
+ report.Error (8174, GetLocation ($3), "A declaration of a by-reference variable must have an initializer");
+ lbag.AddLocation ($$, GetLocation ($7));
+ }
+ }
;
opt_local_variable_initializer
report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type");
$$ = new StackAlloc ((Expression) $2, null, GetLocation ($1));
}
+ | reference_expression
+ ;
+
+reference_expression
+ : REF expression
+ {
+ if (lang_version < LanguageVersion.V_7) {
+ FeatureIsNotAvailable (GetLocation ($1), "byref locals and returns");
+ }
+
+ $$ = new ReferenceExpression ((Expression) $2, GetLocation ($1));
+ }
;
expression_statement
$$ = new Return ((Expression) $2, GetLocation ($1));
lbag.AddStatement ($$, GetLocation ($3));
}
+ | RETURN reference_expression SEMICOLON
+ {
+ $$ = new Return ((Expression) $2, GetLocation ($1));
+ lbag.AddStatement ($$, GetLocation ($3));
+ }
| RETURN expression error
{
Error_SyntaxError (yyToken);