X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fmcs%2Fcs-parser.jay;h=b983dacf0582917c8d058ded794924aa4803c7a8;hb=2e76d1db7ed821511fd47739ac109b6dcbbcb880;hp=b30fc6224fb72f9df45ced19615d85b20bd2c59c;hpb=a5f6fb9ca2162a1b667ae3d4fdb50cf80f93d0f1;p=mono.git diff --git a/mcs/mcs/cs-parser.jay b/mcs/mcs/cs-parser.jay index b30fc6224fb..b983dacf058 100644 --- a/mcs/mcs/cs-parser.jay +++ b/mcs/mcs/cs-parser.jay @@ -6,7 +6,7 @@ // Ravi Pratap (ravi@ximian.com) // Marek Safar (marek.safar@gmail.com) // -// Licensed under the terms of the GNU GPL +// Dual Licensed under the terms of the GNU GPL and the MIT X11 license // // (C) 2001 Ximian, Inc (http://www.ximian.com) // (C) 2004 Novell, Inc @@ -16,23 +16,32 @@ // great spot to put an `error' because you can reproduce it with this input: // "public X { }" // -// Possible optimization: -// Run memory profiler with parsing only, and consider dropping -// arraylists where not needed. Some pieces can use linked lists. - using System.Text; using System.IO; using System; +using System.Collections.Generic; namespace Mono.CSharp { - using System.Collections; - /// /// The C# Parser /// - public class CSharpParser { + public class CSharpParser + { + [Flags] + enum ParameterModifierType + { + Ref = 1 << 1, + Out = 1 << 2, + This = 1 << 3, + Params = 1 << 4, + Arglist = 1 << 5, + DefaultValue = 1 << 6, + + All = Ref | Out | This | Params | Arglist | DefaultValue + } + NamespaceEntry current_namespace; TypeContainer current_container; DeclSpace current_class; @@ -65,12 +74,6 @@ namespace Mono.CSharp FullNamedExpression implicit_value_parameter_type; ParametersCompiled indexer_parameters; - /// - /// Hack to help create non-typed array initializer - /// - public static FullNamedExpression current_array_type; - FullNamedExpression pushed_current_array_type; - /// /// Used to determine if we are parsing the get/set pair /// of an indexer or a property @@ -82,12 +85,12 @@ namespace Mono.CSharp /// /// An out-of-band stack. /// - static Stack oob_stack; + static Stack oob_stack; /// /// Switch stack. /// - Stack switch_stack; + Stack switch_stack; /// /// Controls the verbosity of the errors produced by the parser @@ -118,9 +121,9 @@ namespace Mono.CSharp /// assembly and module attribute definitions are enabled bool global_attrs_enabled = true; bool has_get, has_set; - bool parameter_modifiers_not_allowed; - bool complex_parameters_modifiers_not_allowed; - bool arglist_allowed; + + ParameterModifierType valid_param_mod; + bool default_parameter_used; /// When using the interactive parser, this holds the @@ -132,11 +135,20 @@ namespace Mono.CSharp // public Undo undo; - // Stack - Stack linq_clause_blocks; + Stack linq_clause_blocks; // A counter to create new class names in interactive mode static int class_count; + + CompilerContext compiler; + + // + // Instead of allocating carrier array everytime we + // share the bucket for very common constructs which can never + // be recursive + // + static List parameters_bucket = new List (6); + static List variables_bucket = new List (6); %} %token EOF @@ -311,13 +323,7 @@ namespace Mono.CSharp %token OP_PTR %token OP_COALESCING -/* Numbers */ -%token LITERAL_INTEGER -%token LITERAL_FLOAT -%token LITERAL_DOUBLE -%token LITERAL_DECIMAL -%token LITERAL_CHARACTER -%token LITERAL_STRING +%token LITERAL %token IDENTIFIER %token OPEN_PARENS_LAMBDA @@ -403,15 +409,15 @@ extern_alias_directives extern_alias_directive : EXTERN_ALIAS IDENTIFIER IDENTIFIER SEMICOLON { - LocatedToken lt = (LocatedToken) $2; + var lt = (Tokenizer.LocatedToken) $2; string s = lt.Value; if (s != "alias"){ syntax_error (lt.Location, "`alias' expected"); } else if (RootContext.Version == LanguageVersion.ISO_1) { Report.FeatureIsNotAvailable (lt.Location, "external alias"); } else { - lt = (LocatedToken) $3; - current_namespace.AddUsingExternalAlias (lt.Value, lt.Location); + lt = (Tokenizer.LocatedToken) $3; + current_namespace.AddUsingExternalAlias (lt.Value, lt.Location, Report); } } | EXTERN_ALIAS error @@ -441,8 +447,8 @@ using_directive using_alias_directive : USING IDENTIFIER ASSIGN namespace_or_type_name SEMICOLON { - LocatedToken lt = (LocatedToken) $2; - current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, (Location) $1); + var lt = (Tokenizer.LocatedToken) $2; + current_namespace.AddUsingAlias (lt.Value, (MemberName) $4, GetLocation ($1)); } | USING error { CheckIdentifierToken (yyToken, GetLocation ($2)); @@ -453,7 +459,7 @@ using_alias_directive using_namespace_directive : USING namespace_name SEMICOLON { - current_namespace.AddUsing ((MemberName) $2, (Location) $1); + current_namespace.AddUsing ((MemberName) $2, GetLocation ($1)); } ; @@ -487,17 +493,18 @@ namespace_declaration qualified_identifier : IDENTIFIER { - LocatedToken lt = (LocatedToken) $1; + var lt = (Tokenizer.LocatedToken) $1; $$ = new MemberName (lt.Value, lt.Location); } | qualified_identifier DOT IDENTIFIER { - LocatedToken lt = (LocatedToken) $3; + var lt = (Tokenizer.LocatedToken) $3; $$ = new MemberName ((MemberName) $1, lt.Value, lt.Location); } | error { syntax_error (lexer.Location, "`.' expected"); + $$ = new MemberName ("", lexer.Location); } ; @@ -621,7 +628,7 @@ global_attributes if ($1 != null) { Attributes attrs = (Attributes)$1; if (global_attrs_enabled) { - CodeGen.Assembly.AddAttributes (attrs.Attrs); + CodeGen.Assembly.AddAttributes (attrs.Attrs, current_namespace); } else { foreach (Attribute a in attrs.Attrs) { Report.Error (1730, a.Location, "Assembly and module attributes must precede all other elements except using clauses and extern alias declarations"); @@ -650,14 +657,14 @@ attribute_sections : attribute_section { if (current_attr_target != String.Empty) { - ArrayList sect = (ArrayList) $1; + var sect = (List) $1; if (global_attrs_enabled) { if (current_attr_target == "module") { - current_container.Module.AddAttributes (sect); + current_container.Module.Compiled.AddAttributes (sect); $$ = null; } else if (current_attr_target != null && current_attr_target.Length > 0) { - CodeGen.Assembly.AddAttributes (sect); + CodeGen.Assembly.AddAttributes (sect, current_namespace); $$ = null; } else { $$ = new Attributes (sect); @@ -681,14 +688,14 @@ attribute_sections { if (current_attr_target != String.Empty) { Attributes attrs = $1 as Attributes; - ArrayList sect = (ArrayList) $2; + var sect = (List) $2; if (global_attrs_enabled) { if (current_attr_target == "module") { - current_container.Module.AddAttributes (sect); + current_container.Module.Compiled.AddAttributes (sect); $$ = null; } else if (current_attr_target == "assembly") { - CodeGen.Assembly.AddAttributes (sect); + CodeGen.Assembly.AddAttributes (sect, current_namespace); $$ = null; } else { if (attrs == null) @@ -732,7 +739,7 @@ attribute_target_specifier attribute_target : IDENTIFIER { - LocatedToken lt = (LocatedToken) $1; + var lt = (Tokenizer.LocatedToken) $1; $$ = CheckAttributeTarget (lt.Value, lt.Location); } | EVENT { $$ = "event"; } @@ -747,16 +754,12 @@ attribute_target attribute_list : attribute { - ArrayList attrs = new ArrayList (4); - attrs.Add ($1); - - $$ = attrs; - + $$ = new List (4) { (Attribute) $1 }; } | attribute_list COMMA attribute { - ArrayList attrs = (ArrayList) $1; - attrs.Add ($3); + var attrs = (List) $1; + attrs.Add ((Attribute) $3); $$ = attrs; } @@ -767,7 +770,7 @@ attribute { ++lexer.parsing_block; } - opt_attribute_arguments + opt_attribute_arguments { --lexer.parsing_block; MemberName mname = (MemberName) $1; @@ -776,20 +779,17 @@ attribute "'<' unexpected: attributes cannot be generic"); } - object [] arguments = (object []) $3; - MemberName left = mname.Left; - string identifier = mname.Name; - - Expression left_expr = left == null ? null : left.GetTypeExpression (); + Arguments [] arguments = (Arguments []) $3; + ATypeNameExpression expr = mname.GetTypeExpression (); if (current_attr_target == String.Empty) $$ = null; else if (global_attrs_enabled && (current_attr_target == "assembly" || current_attr_target == "module")) // FIXME: supply "nameEscaped" parameter here. $$ = new GlobalAttribute (current_namespace, current_attr_target, - left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location)); + expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location)); else - $$ = new Attribute (current_attr_target, left_expr, identifier, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location)); + $$ = new Attribute (current_attr_target, expr, arguments, mname.Location, lexer.IsEscapedIdentifier (mname.Location)); } ; @@ -807,79 +807,85 @@ opt_attribute_arguments attribute_arguments - : opt_positional_argument_list + : /* empty */ { $$ = null; } + | positional_or_named_argument { - if ($1 == null) - $$ = null; - else { - $$ = new object [] { $1, null }; - } + Arguments a = new Arguments (4); + a.Add ((Argument) $1); + $$ = new Arguments [] { a, null }; } - | positional_argument_list COMMA named_argument_list + | named_attribute_argument { - $$ = new object[] { $1, $3 }; + Arguments a = new Arguments (4); + a.Add ((Argument) $1); + $$ = new Arguments [] { null, a }; } - | named_argument_list + | attribute_arguments COMMA positional_or_named_argument { - $$ = new object [] { null, $1 }; + Arguments[] o = (Arguments[]) $1; + if (o [1] != null) { + Report.Error (1016, ((Argument) $3).Expr.Location, "Named attribute arguments must appear after the positional arguments"); + o [0] = new Arguments (4); + } + + Arguments args = ((Arguments) o [0]); + if (args.Count > 0 && !($3 is NamedArgument) && args [args.Count - 1] is NamedArgument) + Error_NamedArgumentExpected ((NamedArgument) args [args.Count - 1]); + + args.Add ((Argument) $3); } - ; - - -opt_positional_argument_list - : /* empty */ { $$ = null; } - | positional_argument_list - ; - -positional_argument_list - : expression + | attribute_arguments COMMA named_attribute_argument { - ArrayList args = new ArrayList (4); - args.Add (new Argument ((Expression) $1, Argument.AType.Expression)); + Arguments[] o = (Arguments[]) $1; + if (o [1] == null) { + o [1] = new Arguments (4); + } - $$ = args; + ((Arguments) o [1]).Add ((Argument) $3); } - | positional_argument_list COMMA expression - { - ArrayList args = (ArrayList) $1; - args.Add (new Argument ((Expression) $3, Argument.AType.Expression)); - - $$ = args; - } - ; + ; -named_argument_list - : named_argument +positional_or_named_argument + : expression { - ArrayList args = new ArrayList (4); - args.Add ($1); - - $$ = args; + $$ = new Argument ((Expression) $1); } - | named_argument_list COMMA named_argument - { - ArrayList args = (ArrayList) $1; - args.Add ($3); + | named_argument + ; - $$ = args; - } - | named_argument_list COMMA expression +named_attribute_argument + : IDENTIFIER ASSIGN expression { - Report.Error (1016, ((Expression) $3).Location, "Named attribute argument expected"); - $$ = null; + var lt = (Tokenizer.LocatedToken) $1; + $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3); } ; - + named_argument - : IDENTIFIER ASSIGN expression + : IDENTIFIER COLON opt_named_modifier expression { - // FIXME: keep location - $$ = new DictionaryEntry ( - ((LocatedToken) $1).Value, - new Argument ((Expression) $3, Argument.AType.Expression)); + if (RootContext.Version <= LanguageVersion.V_3) + Report.FeatureIsNotAvailable (GetLocation ($1), "named argument"); + + // Avoid boxing in common case (no modifier) + var arg_mod = $3 == null ? Argument.AType.None : (Argument.AType) $3; + + var lt = (Tokenizer.LocatedToken) $1; + $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $4, arg_mod); + } + ; + +opt_named_modifier + : /* empty */ { $$ = null; } + | REF + { + $$ = Argument.AType.Ref; + } + | OUT + { + $$ = Argument.AType.Out; } ; - class_body : OPEN_BRACE opt_class_member_declarations CLOSE_BRACE @@ -927,14 +933,14 @@ struct_declaration type_declaration_name { MemberName name = MakeName ((MemberName) $6); - push_current_class (new Struct (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3); + push_current_class (new Struct (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3); } opt_class_base opt_type_parameter_constraints_clauses { lexer.ConstraintsParsing = false; - current_class.SetParameterInfo ((ArrayList) $9); + current_class.SetParameterInfo ((List) $9); if (RootContext.Documentation != null) current_container.DocComment = Lexer.consume_doc_comment (); @@ -999,17 +1005,17 @@ constant_declaration constant_declarators SEMICOLON { - int modflags = (int) $2; - foreach (VariableDeclaration constant in (ArrayList) $5){ + var modflags = (Modifiers) $2; + foreach (VariableDeclaration constant in (List) $5){ Location l = constant.Location; if ((modflags & Modifiers.STATIC) != 0) { - Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + '.' + (string) constant.identifier); + Report.Error (504, l, "The constant `{0}' cannot be marked static", current_container.GetSignatureForError () + "." + (string) constant.identifier); continue; } Const c = new Const ( current_class, (FullNamedExpression) $4, (string) constant.identifier, - (Expression) constant.expression_or_array_initializer, modflags, + constant.GetInitializer ((FullNamedExpression) $4), modflags, (Attributes) $1, l); if (RootContext.Documentation != null) { @@ -1024,15 +1030,15 @@ constant_declaration constant_declarators : constant_declarator { - ArrayList constants = new ArrayList (4); + variables_bucket.Clear (); if ($1 != null) - constants.Add ($1); - $$ = constants; + variables_bucket.Add ($1); + $$ = variables_bucket; } | constant_declarators COMMA constant_declarator { if ($3 != null) { - ArrayList constants = (ArrayList) $1; + var constants = (List) $1; constants.Add ($3); } } @@ -1046,12 +1052,12 @@ constant_declarator constant_initializer { --lexer.parsing_block; - $$ = new VariableDeclaration ((LocatedToken) $1, $4); + $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $4); } | IDENTIFIER { // A const field requires a value to be provided - Report.Error (145, ((LocatedToken) $1).Location, "A const field requires a value to be provided"); + Report.Error (145, GetLocation ($1), "A const field requires a value to be provided"); $$ = null; } ; @@ -1072,14 +1078,12 @@ field_declaration if (type == TypeManager.system_void_expr) Report.Error (670, GetLocation ($3), "Fields cannot have void type"); - int mod = (int) $2; - - current_array_type = null; + var mod = (Modifiers) $2; - foreach (VariableMemberDeclaration var in (ArrayList) $4){ + foreach (VariableMemberDeclaration var in (List) $4){ Field field = new Field (current_class, type, mod, var.MemberName, (Attributes) $1); - field.Initializer = var.expression_or_array_initializer; + field.Initializer = var.GetInitializer (type); if (RootContext.Documentation != null) { field.DocComment = Lexer.consume_doc_comment (); @@ -1098,13 +1102,14 @@ field_declaration { FullNamedExpression type = (FullNamedExpression) $4; - int mod = (int) $2; - - current_array_type = null; + var mod = (Modifiers) $2; - foreach (VariableDeclaration var in (ArrayList) $5) { + foreach (VariableDeclaration var in (List) $5) { FixedField field = new FixedField (current_class, type, mod, var.identifier, - (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location); + var.GetInitializer (type), (Attributes) $1, var.Location); + + if (RootContext.Version < LanguageVersion.ISO_2) + Report.FeatureIsNotAvailable (GetLocation ($3), "fixed size buffers"); if (RootContext.Documentation != null) { field.DocComment = Lexer.consume_doc_comment (); @@ -1127,14 +1132,14 @@ field_declaration fixed_variable_declarators : fixed_variable_declarator { - ArrayList decl = new ArrayList (2); - decl.Add ($1); + var decl = new List (2); + decl.Add ((VariableDeclaration)$1); $$ = decl; } | fixed_variable_declarators COMMA fixed_variable_declarator { - ArrayList decls = (ArrayList) $1; - decls.Add ($3); + var decls = (List) $1; + decls.Add ((VariableDeclaration)$3); $$ = $1; } ; @@ -1142,12 +1147,12 @@ fixed_variable_declarators fixed_variable_declarator : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET { - $$ = new VariableDeclaration ((LocatedToken) $1, $3); + $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $3); } | IDENTIFIER OPEN_BRACKET CLOSE_BRACKET { Report.Error (443, lexer.Location, "Value or constant expected"); - $$ = new VariableDeclaration ((LocatedToken) $1, null); + $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, null); } ; @@ -1155,14 +1160,14 @@ fixed_variable_declarator local_variable_declarators : local_variable_declarator { - ArrayList decl = new ArrayList (4); + variables_bucket.Clear (); if ($1 != null) - decl.Add ($1); - $$ = decl; + variables_bucket.Add ($1); + $$ = variables_bucket; } | local_variable_declarators COMMA local_variable_declarator { - ArrayList decls = (ArrayList) $1; + var decls = (List) $1; decls.Add ($3); $$ = $1; } @@ -1171,11 +1176,11 @@ local_variable_declarators local_variable_declarator : IDENTIFIER ASSIGN local_variable_initializer { - $$ = new VariableDeclaration ((LocatedToken) $1, $3); + $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, (Expression) $3); } | IDENTIFIER { - $$ = new VariableDeclaration ((LocatedToken) $1, null); + $$ = new VariableDeclaration ((Tokenizer.LocatedToken) $1, null); } | IDENTIFIER variable_bad_array { @@ -1188,30 +1193,30 @@ local_variable_initializer | array_initializer | STACKALLOC simple_type OPEN_BRACKET expression CLOSE_BRACKET { - $$ = new StackAlloc ((Expression) $2, (Expression) $4, (Location) $1); + $$ = new StackAlloc ((Expression) $2, (Expression) $4, GetLocation ($1)); } | ARGLIST { - $$ = new ArglistAccess ((Location) $1); + $$ = new ArglistAccess (GetLocation ($1)); } | STACKALLOC simple_type { - Report.Error (1575, (Location) $1, "A stackalloc expression requires [] after type"); - $$ = new StackAlloc ((Expression) $2, null, (Location) $1); + Report.Error (1575, GetLocation ($1), "A stackalloc expression requires [] after type"); + $$ = new StackAlloc ((Expression) $2, null, GetLocation ($1)); } ; variable_declarators : variable_declarator { - ArrayList decl = new ArrayList (4); + variables_bucket.Clear (); if ($1 != null) - decl.Add ($1); - $$ = decl; + variables_bucket.Add ($1); + $$ = variables_bucket; } | variable_declarators COMMA variable_declarator { - ArrayList decls = (ArrayList) $1; + var decls = (List) $1; decls.Add ($3); $$ = $1; } @@ -1226,7 +1231,7 @@ variable_declarator variable_initializer { --lexer.parsing_block; - $$ = new VariableMemberDeclaration ((MemberName) $1, $4); + $$ = new VariableMemberDeclaration ((MemberName) $1, (Expression) $4); } | member_declaration_name { @@ -1264,7 +1269,7 @@ method_declaration method.Block = (ToplevelBlock) $3; current_container.AddMethod (method); - if (current_container.Kind == Kind.Interface && method.Block != null) { + if (current_container.Kind == MemberKind.Interface && method.Block != null) { Report.Error (531, method.Location, "`{0}': interface members cannot have a definition", method.GetSignatureForError ()); } @@ -1282,35 +1287,38 @@ method_header member_type method_declaration_name OPEN_PARENS { - arglist_allowed = true; + valid_param_mod = ParameterModifierType.All; } - opt_formal_parameter_list CLOSE_PARENS + opt_formal_parameter_list CLOSE_PARENS { lexer.ConstraintsParsing = true; } opt_type_parameter_constraints_clauses { lexer.ConstraintsParsing = false; - arglist_allowed = false; + valid_param_mod = 0; MemberName name = (MemberName) $4; current_local_parameters = (ParametersCompiled) $7; - if ($10 != null && name.TypeArguments == null) - Report.Error (80, lexer.Location, - "Constraints are not allowed on non-generic declarations"); - - Method method; - GenericMethod generic = null; if (name.TypeArguments != null) { generic = new GenericMethod (current_namespace, current_class, name, (FullNamedExpression) $3, current_local_parameters); - generic.SetParameterInfo ((ArrayList) $10); + generic.SetParameterInfo ((List) $10); + } else if ($10 != null) { + Report.Error (80, GetLocation ($10), + "Constraints are not allowed on non-generic declarations"); } - method = new Method (current_class, generic, (FullNamedExpression) $3, (int) $2, + Method method = new Method (current_class, generic, (FullNamedExpression) $3, (Modifiers) $2, name, current_local_parameters, (Attributes) $1); + + if ($10 != null && ((method.ModFlags & Modifiers.OVERRIDE) != 0 || method.IsExplicitImpl)) { + Report.Error (460, method.Location, + "`{0}': Cannot specify constraints for overrides and explicit interface implementation methods", + method.GetSignatureForError ()); + } current_generic_method = generic; @@ -1325,7 +1333,7 @@ method_header VOID method_declaration_name OPEN_PARENS { - arglist_allowed = true; + valid_param_mod = ParameterModifierType.All; } opt_formal_parameter_list CLOSE_PARENS { @@ -1334,7 +1342,7 @@ method_header opt_type_parameter_constraints_clauses { lexer.ConstraintsParsing = false; - arglist_allowed = false; + valid_param_mod = 0; MemberName name = (MemberName) $5; current_local_parameters = (ParametersCompiled) $8; @@ -1349,13 +1357,13 @@ method_header generic = new GenericMethod (current_namespace, current_class, name, TypeManager.system_void_expr, current_local_parameters); - generic.SetParameterInfo ((ArrayList) $11); + generic.SetParameterInfo ((List) $11); } - int modifiers = (int) $2; + var modifiers = (Modifiers) $2; - const int invalid_partial_mod = Modifiers.Accessibility | Modifiers.ABSTRACT | Modifiers.EXTERN | + const Modifiers invalid_partial_mod = Modifiers.AccessibilityMask | Modifiers.ABSTRACT | Modifiers.EXTERN | Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SEALED | Modifiers.VIRTUAL; if ((modifiers & invalid_partial_mod) != 0) { @@ -1388,7 +1396,7 @@ method_header { MemberName name = (MemberName) $5; Report.Error (1585, name.Location, - "Member modifier `{0}' must precede the member type and name", Modifiers.Name ((int) $4)); + "Member modifier `{0}' must precede the member type and name", ModifiersExtensions.Name ((Modifiers) $4)); Method method = new Method (current_class, null, TypeManager.system_void_expr, 0, name, (ParametersCompiled) $7, (Attributes) $1); @@ -1398,7 +1406,7 @@ method_header if (RootContext.Documentation != null) method.DocComment = Lexer.consume_doc_comment (); - $$ = null; + $$ = method; } ; @@ -1412,94 +1420,80 @@ opt_formal_parameter_list | formal_parameter_list ; -opt_parameter_list_no_mod - : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; } - | - { - parameter_modifiers_not_allowed = true; - } - formal_parameter_list - { - parameter_modifiers_not_allowed = false; - $$ = $2; - } - ; - formal_parameter_list : fixed_parameters { - ArrayList pars_list = (ArrayList) $1; - - Parameter [] pars = new Parameter [pars_list.Count]; - pars_list.CopyTo (pars); - - $$ = new ParametersCompiled (pars); + var pars_list = (List) $1; + $$ = new ParametersCompiled (compiler, pars_list.ToArray ()); } | fixed_parameters COMMA parameter_array { - ArrayList pars_list = (ArrayList) $1; - pars_list.Add ($3); + var pars_list = (List) $1; + pars_list.Add ((Parameter) $3); - Parameter [] pars = new Parameter [pars_list.Count]; - pars_list.CopyTo (pars); - - $$ = new ParametersCompiled (pars); + $$ = new ParametersCompiled (compiler, pars_list.ToArray ()); } | fixed_parameters COMMA arglist_modifier { - ArrayList pars_list = (ArrayList) $1; + var pars_list = (List) $1; pars_list.Add (new ArglistParameter (GetLocation ($3))); - - Parameter [] pars = new Parameter [pars_list.Count]; - pars_list.CopyTo (pars); - - $$ = new ParametersCompiled (pars, true); + $$ = new ParametersCompiled (compiler, pars_list.ToArray (), true); } | parameter_array COMMA error { if ($1 != null) Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list"); - $$ = null; + + $$ = new ParametersCompiled (compiler, new Parameter[] { (Parameter) $1 } ); } | fixed_parameters COMMA parameter_array COMMA error { if ($3 != null) Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list"); - $$ = null; + + var pars_list = (List) $1; + pars_list.Add (new ArglistParameter (GetLocation ($3))); + + $$ = new ParametersCompiled (compiler, pars_list.ToArray (), true); } | arglist_modifier COMMA error { - Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list"); - $$ = null; + Report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list"); + + $$ = new ParametersCompiled (compiler, new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true); } | fixed_parameters COMMA ARGLIST COMMA error { - Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list"); - $$ = null; + Report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list"); + + var pars_list = (List) $1; + pars_list.Add (new ArglistParameter (GetLocation ($3))); + + $$ = new ParametersCompiled (compiler, pars_list.ToArray (), true); } | parameter_array { - $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } ); + $$ = new ParametersCompiled (compiler, new Parameter[] { (Parameter) $1 } ); } | arglist_modifier { - $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter ((Location) $1) }, true); + $$ = new ParametersCompiled (compiler, new Parameter [] { new ArglistParameter (GetLocation ($1)) }, true); } ; fixed_parameters : fixed_parameter { - ArrayList pars = new ArrayList (4); + parameters_bucket.Clear (); Parameter p = (Parameter) $1; - pars.Add (p); + parameters_bucket.Add (p); default_parameter_used = p.HasDefaultValue; - $$ = pars; + $$ = parameters_bucket; } | fixed_parameters COMMA fixed_parameter { - ArrayList pars = (ArrayList) $1; + var pars = (List) $1; Parameter p = (Parameter) $3; if (p != null) { if (p.HasExtensionMethodModifier) @@ -1517,24 +1511,24 @@ fixed_parameters fixed_parameter : opt_attributes opt_parameter_modifier - type + parameter_type IDENTIFIER { - LocatedToken lt = (LocatedToken) $4; + var lt = (Tokenizer.LocatedToken) $4; $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location); } | opt_attributes opt_parameter_modifier - type + parameter_type IDENTIFIER OPEN_BRACKET CLOSE_BRACKET { - LocatedToken lt = (LocatedToken) $4; + var lt = (Tokenizer.LocatedToken) $4; Report.Error (1552, lt.Location, "Array type specifier, [], must appear before parameter name"); - $$ = null; + $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location); } | opt_attributes opt_parameter_modifier - type + parameter_type error { Location l = GetLocation ($4); @@ -1543,7 +1537,7 @@ fixed_parameter } | opt_attributes opt_parameter_modifier - type + parameter_type IDENTIFIER ASSIGN constant_expression @@ -1572,10 +1566,10 @@ fixed_parameter mod = Parameter.Modifier.NONE; } - if (complex_parameters_modifiers_not_allowed) + if ((valid_param_mod & ParameterModifierType.DefaultValue) == 0) Report.Error (1065, GetLocation ($6), "Optional parameter is not valid in this context"); - LocatedToken lt = (LocatedToken) $4; + var lt = (Tokenizer.LocatedToken) $4; $$ = new Parameter ((FullNamedExpression) $3, lt.Value, mod, (Attributes) $1, lt.Location); if ($6 != null) ((Parameter) $$).DefaultValue = (Expression) $6; @@ -1618,22 +1612,22 @@ parameter_modifiers parameter_modifier : REF { - if (parameter_modifiers_not_allowed) - Error_ParameterModifierNotValid ("ref", (Location)$1); + if ((valid_param_mod & ParameterModifierType.Ref) == 0) + Error_ParameterModifierNotValid ("ref", GetLocation ($1)); $$ = Parameter.Modifier.REF; } | OUT { - if (parameter_modifiers_not_allowed) - Error_ParameterModifierNotValid ("out", (Location)$1); + if ((valid_param_mod & ParameterModifierType.Out) == 0) + Error_ParameterModifierNotValid ("out", GetLocation ($1)); $$ = Parameter.Modifier.OUT; } | THIS { - if (parameter_modifiers_not_allowed) - Error_ParameterModifierNotValid ("this", (Location)$1); + if ((valid_param_mod & ParameterModifierType.This) == 0) + Error_ParameterModifierNotValid ("this", GetLocation ($1)); if (RootContext.Version <= LanguageVersion.ISO_2) Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods"); @@ -1645,14 +1639,14 @@ parameter_modifier parameter_array : opt_attributes params_modifier type IDENTIFIER { - LocatedToken lt = (LocatedToken) $4; + var lt = (Tokenizer.LocatedToken) $4; $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location); } | opt_attributes params_modifier type IDENTIFIER ASSIGN constant_expression { Report.Error (1751, GetLocation ($2), "Cannot specify a default value for a parameter array"); - LocatedToken lt = (LocatedToken) $4; + var lt = (Tokenizer.LocatedToken) $4; $$ = new ParamsParameter ((FullNamedExpression) $3, lt.Value, (Attributes) $1, lt.Location); } | opt_attributes params_modifier type error { @@ -1664,29 +1658,29 @@ parameter_array params_modifier : PARAMS { - if (complex_parameters_modifiers_not_allowed) - Report.Error (1670, ((Location) $1), "The `params' modifier is not allowed in current context"); + if ((valid_param_mod & ParameterModifierType.Params) == 0) + Report.Error (1670, (GetLocation ($1)), "The `params' modifier is not allowed in current context"); } | PARAMS parameter_modifier { Parameter.Modifier mod = (Parameter.Modifier)$2; if ((mod & Parameter.Modifier.This) != 0) { - Report.Error (1104, (Location)$1, "The parameter modifiers `this' and `params' cannot be used altogether"); + Report.Error (1104, GetLocation ($1), "The parameter modifiers `this' and `params' cannot be used altogether"); } else { - Report.Error (1611, (Location)$1, "The params parameter cannot be declared as ref or out"); + Report.Error (1611, GetLocation ($1), "The params parameter cannot be declared as ref or out"); } } | PARAMS params_modifier { - Error_DuplicateParameterModifier ((Location)$1, Parameter.Modifier.PARAMS); + Error_DuplicateParameterModifier (GetLocation ($1), Parameter.Modifier.PARAMS); } ; arglist_modifier : ARGLIST { - if (!arglist_allowed) - Report.Error (1669, (Location) $1, "__arglist is not valid in this context"); + if ((valid_param_mod & ParameterModifierType.Arglist) == 0) + Report.Error (1669, GetLocation ($1), "__arglist is not valid in this context"); } ; @@ -1720,7 +1714,7 @@ property_declaration MemberName name = (MemberName) $4; FullNamedExpression ptype = (FullNamedExpression) $3; - prop = new Property (current_class, ptype, (int) $2, + prop = new Property (current_class, ptype, (Modifiers) $2, name, (Attributes) $1, get_block, set_block, order, current_block); if (ptype == TypeManager.system_void_expr) @@ -1729,7 +1723,7 @@ property_declaration if (accessors == null) Report.Error (548, prop.Location, "`{0}': property or indexer must have at least one accessor", prop.GetSignatureForError ()); - if (current_container.Kind == Kind.Interface) { + if (current_container.Kind == MemberKind.Interface) { if (prop.Get.Block != null) Report.Error (531, prop.Location, "`{0}.get': interface members cannot have a definition", prop.GetSignatureForError ()); @@ -1800,7 +1794,7 @@ get_accessor_declaration Report.Error (1007, GetLocation ($3), "Property accessor already defined"); break; } - Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3); + Accessor accessor = new Accessor ((ToplevelBlock) $5, (Modifiers) $2, (Attributes) $1, current_local_parameters, GetLocation ($3)); has_get = true; current_local_parameters = null; lexer.PropertyParsing = true; @@ -1818,12 +1812,12 @@ set_accessor_declaration { Parameter implicit_value_parameter = new Parameter ( implicit_value_parameter_type, "value", - Parameter.Modifier.NONE, null, (Location) $3); + Parameter.Modifier.NONE, null, GetLocation ($3)); if (!parsing_indexer) { - current_local_parameters = new ParametersCompiled (new Parameter [] { implicit_value_parameter }); + current_local_parameters = new ParametersCompiled (compiler, new Parameter [] { implicit_value_parameter }); } else { - current_local_parameters = ParametersCompiled.MergeGenerated ( + current_local_parameters = ParametersCompiled.MergeGenerated (compiler, indexer_parameters, true, implicit_value_parameter, null); } @@ -1835,7 +1829,7 @@ set_accessor_declaration Report.Error (1007, GetLocation ($3), "Property accessor already defined"); break; } - Accessor accessor = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, current_local_parameters, (Location) $3); + Accessor accessor = new Accessor ((ToplevelBlock) $5, (Modifiers) $2, (Attributes) $1, current_local_parameters, GetLocation ($3)); has_set = true; current_local_parameters = null; lexer.PropertyParsing = true; @@ -1856,7 +1850,7 @@ accessor_body } | error { - Error_SyntaxError (1043, yyToken); + Error_SyntaxError (1043, yyToken, "Invalid accessor body"); $$ = null; } ; @@ -1872,14 +1866,14 @@ interface_declaration type_declaration_name { MemberName name = MakeName ((MemberName) $6); - push_current_class (new Interface (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3); + push_current_class (new Interface (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3); } opt_class_base opt_type_parameter_constraints_clauses { lexer.ConstraintsParsing = false; - current_class.SetParameterInfo ((ArrayList) $9); + current_class.SetParameterInfo ((List) $9); if (RootContext.Documentation != null) { current_container.DocComment = Lexer.consume_doc_comment (); @@ -1955,7 +1949,7 @@ operator_declaration OperatorDeclaration decl = (OperatorDeclaration) $3; Operator op = new Operator ( - current_class, decl.optype, decl.ret_type, (int) $2, + current_class, decl.optype, decl.ret_type, (Modifiers) $2, current_local_parameters, (ToplevelBlock) $5, (Attributes) $1, decl.location); @@ -1980,7 +1974,7 @@ operator_type : type_expression_or_array | VOID { - Report.Error (590, lexer.Location, "User-defined operators cannot return void"); + Report.Error (590, GetLocation ($1), "User-defined operators cannot return void"); $$ = TypeManager.system_void_expr; } ; @@ -1988,13 +1982,13 @@ operator_type operator_declarator : operator_type OPERATOR overloadable_operator OPEN_PARENS { - complex_parameters_modifiers_not_allowed = true; + valid_param_mod = ParameterModifierType.DefaultValue; } - opt_parameter_list_no_mod CLOSE_PARENS + opt_formal_parameter_list CLOSE_PARENS { - complex_parameters_modifiers_not_allowed = false; + valid_param_mod = 0; - Location loc = (Location) $2; + Location loc = GetLocation ($2); Operator.OpType op = (Operator.OpType) $3; current_local_parameters = (ParametersCompiled)$6; @@ -2063,13 +2057,13 @@ overloadable_operator conversion_operator_declarator : IMPLICIT OPERATOR type OPEN_PARENS { - complex_parameters_modifiers_not_allowed = true; + valid_param_mod = ParameterModifierType.DefaultValue; } - opt_parameter_list_no_mod CLOSE_PARENS + opt_formal_parameter_list CLOSE_PARENS { - complex_parameters_modifiers_not_allowed = false; + valid_param_mod = 0; - Location loc = (Location) $2; + Location loc = GetLocation ($2); current_local_parameters = (ParametersCompiled)$6; if (RootContext.Documentation != null) { @@ -2081,13 +2075,13 @@ conversion_operator_declarator } | EXPLICIT OPERATOR type OPEN_PARENS { - complex_parameters_modifiers_not_allowed = true; + valid_param_mod = ParameterModifierType.DefaultValue; } - opt_parameter_list_no_mod CLOSE_PARENS + opt_formal_parameter_list CLOSE_PARENS { - complex_parameters_modifiers_not_allowed = false; + valid_param_mod = 0; - Location loc = (Location) $2; + Location loc = GetLocation ($2); current_local_parameters = (ParametersCompiled)$6; if (RootContext.Documentation != null) { @@ -2100,11 +2094,13 @@ conversion_operator_declarator | IMPLICIT error { Error_SyntaxError (yyToken); + current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters; $$ = new OperatorDeclaration (Operator.OpType.Implicit, null, GetLocation ($1)); } | EXPLICIT error { Error_SyntaxError (yyToken); + current_local_parameters = ParametersCompiled.EmptyReadOnlyParameters; $$ = new OperatorDeclaration (Operator.OpType.Explicit, null, GetLocation ($1)); } ; @@ -2136,11 +2132,12 @@ constructor_declarator tmpComment = Lexer.consume_doc_comment (); Lexer.doc_state = XmlCommentState.Allowed; } - arglist_allowed = true; + + valid_param_mod = ParameterModifierType.All; } OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS { - arglist_allowed = false; + valid_param_mod = 0; current_local_parameters = (ParametersCompiled) $6; // @@ -2151,8 +2148,8 @@ constructor_declarator } opt_constructor_initializer { - LocatedToken lt = (LocatedToken) $3; - int mods = (int) $2; + var lt = (Tokenizer.LocatedToken) $3; + var mods = (Modifiers) $2; ConstructorInitializer ci = (ConstructorInitializer) $9; Constructor c = new Constructor (current_class, lt.Value, mods, @@ -2161,7 +2158,7 @@ constructor_declarator if (lt.Value != current_container.MemberName.Name) { Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type"); } else if ((mods & Modifiers.STATIC) != 0) { - if ((mods & Modifiers.Accessibility) != 0){ + if ((mods & Modifiers.AccessibilityMask) != 0){ Report.Error (515, c.Location, "`{0}': static constructor cannot have an access modifier", c.GetSignatureForError ()); @@ -2196,7 +2193,7 @@ constructor_initializer opt_argument_list CLOSE_PARENS { --lexer.parsing_block; - $$ = new ConstructorBaseInitializer ((ArrayList) $5, (Location) $2); + $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2)); } | COLON THIS OPEN_PARENS { @@ -2205,7 +2202,7 @@ constructor_initializer opt_argument_list CLOSE_PARENS { --lexer.parsing_block; - $$ = new ConstructorThisInitializer ((ArrayList) $5, (Location) $2); + $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2)); } | COLON error { Report.Error (1018, GetLocation ($1), "Keyword `this' or `base' expected"); @@ -2225,13 +2222,13 @@ destructor_declaration } IDENTIFIER OPEN_PARENS CLOSE_PARENS method_body { - LocatedToken lt = (LocatedToken) $5; + var lt = (Tokenizer.LocatedToken) $5; if (lt.Value != current_container.MemberName.Name){ Report.Error (574, lt.Location, "Name of destructor must match name of class"); - } else if (current_container.Kind != Kind.Class){ + } else if (current_container.Kind != MemberKind.Class){ Report.Error (575, lt.Location, "Only class types can contain destructor"); } else { - Destructor d = new Destructor (current_class, (int) $2, + Destructor d = new Destructor (current_class, (Modifiers) $2, ParametersCompiled.EmptyReadOnlyParameters, (Attributes) $1, lt.Location); if (RootContext.Documentation != null) d.DocComment = ConsumeStoredComment (); @@ -2249,18 +2246,14 @@ event_declaration opt_modifiers EVENT type variable_declarators SEMICOLON { - current_array_type = null; - foreach (VariableMemberDeclaration var in (ArrayList) $5) { + foreach (VariableMemberDeclaration var in (List) $5) { EventField e = new EventField ( - current_class, (FullNamedExpression) $4, (int) $2, var.MemberName, (Attributes) $1); + current_class, (FullNamedExpression) $4, (Modifiers) $2, var.MemberName, (Attributes) $1); - if (var.expression_or_array_initializer != null) { - if (current_container.Kind == Kind.Interface) { - Report.Error (68, e.Location, "`{0}': event in interface cannot have initializer", e.GetSignatureForError ()); - } - - e.Initializer = var.expression_or_array_initializer; + e.Initializer = var.GetInitializer ((FullNamedExpression) $4); + if (current_container.Kind == MemberKind.Interface && e.Initializer != null) { + Report.Error (68, e.Location, "`{0}': event in interface cannot have initializer", e.GetSignatureForError ()); } if (var.MemberName.Left != null) { @@ -2283,7 +2276,7 @@ event_declaration OPEN_BRACE { implicit_value_parameter_type = (FullNamedExpression) $4; - current_local_parameters = new ParametersCompiled ( + current_local_parameters = new ParametersCompiled (compiler, new Parameter (implicit_value_parameter_type, "value", Parameter.Modifier.NONE, null, GetLocation ($3))); @@ -2297,32 +2290,31 @@ event_declaration { MemberName name = (MemberName) $5; - if (current_container.Kind == Kind.Interface) { - Report.Error (69, (Location) $3, "Event in interface cannot have add or remove accessors"); + if (current_container.Kind == MemberKind.Interface) { + Report.Error (69, GetLocation ($3), "Event in interface cannot have add or remove accessors"); + $8 = new Accessors (null, null); + } else if ($8 == null) { + Report.Error (65, GetLocation ($3), "`{0}.{1}': event property must have both add and remove accessors", + current_container.GetSignatureForError (), name.GetSignatureForError ()); + $8 = new Accessors (null, null); } + + Accessors accessors = (Accessors) $8; - if ($8 == null){ - Report.Error (65, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors", - current_container.Name, name.GetSignatureForError ()); + if (accessors.get_or_add == null || accessors.set_or_remove == null) + // CS0073 is already reported, so no CS0065 here. $$ = null; - } else { - Accessors accessors = (Accessors) $8; - - if (accessors.get_or_add == null || accessors.set_or_remove == null) - // CS0073 is already reported, so no CS0065 here. - $$ = null; - else { - Event e = new EventProperty ( - current_class, (FullNamedExpression) $4, (int) $2, name, - (Attributes) $1, accessors.get_or_add, accessors.set_or_remove); - if (RootContext.Documentation != null) { - e.DocComment = Lexer.consume_doc_comment (); - Lexer.doc_state = XmlCommentState.Allowed; - } - - current_container.AddEvent (e); - implicit_value_parameter_type = null; + else { + Event e = new EventProperty ( + current_class, (FullNamedExpression) $4, (Modifiers) $2, name, + (Attributes) $1, accessors.get_or_add, accessors.set_or_remove); + if (RootContext.Documentation != null) { + e.DocComment = Lexer.consume_doc_comment (); + Lexer.doc_state = XmlCommentState.Allowed; } + + current_container.AddEvent (e); + implicit_value_parameter_type = null; } current_local_parameters = null; } @@ -2368,16 +2360,16 @@ add_accessor_declaration } block { - Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2); + Accessor accessor = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, GetLocation ($2)); lexer.EventParsing = true; $$ = accessor; } | opt_attributes ADD error { - Report.Error (73, (Location) $2, "An add or remove accessor must have a body"); + Report.Error (73, GetLocation ($2), "An add or remove accessor must have a body"); $$ = null; } | opt_attributes modifiers ADD { - Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations"); + Report.Error (1609, GetLocation ($3), "Modifiers cannot be placed on event accessor declarations"); $$ = null; } ; @@ -2389,33 +2381,34 @@ remove_accessor_declaration } block { - $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, (Location) $2); + $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, null, GetLocation ($2)); lexer.EventParsing = true; } | opt_attributes REMOVE error { - Report.Error (73, (Location) $2, "An add or remove accessor must have a body"); + Report.Error (73, GetLocation ($2), "An add or remove accessor must have a body"); $$ = null; } | opt_attributes modifiers REMOVE { - Report.Error (1609, (Location) $3, "Modifiers cannot be placed on event accessor declarations"); + Report.Error (1609, GetLocation ($3), "Modifiers cannot be placed on event accessor declarations"); $$ = null; } ; indexer_declaration : opt_attributes opt_modifiers - member_type indexer_declaration_name OPEN_BRACKET opt_parameter_list_no_mod CLOSE_BRACKET + member_type indexer_declaration_name OPEN_BRACKET + { + valid_param_mod = ParameterModifierType.Params | ParameterModifierType.DefaultValue; + } + opt_formal_parameter_list CLOSE_BRACKET OPEN_BRACE { + valid_param_mod = 0; implicit_value_parameter_type = (FullNamedExpression) $3; - indexer_parameters = (ParametersCompiled) $6; + indexer_parameters = (ParametersCompiled) $7; if (indexer_parameters.IsEmpty) { Report.Error (1551, GetLocation ($5), "Indexers must have at least one parameter"); - } else if (indexer_parameters.Count == 1) { - Parameter p = indexer_parameters [0]; - if (p.HasDefaultValue) - p.Warning_UselessOptionalParameter (); } if (RootContext.Documentation != null) { @@ -2435,13 +2428,13 @@ indexer_declaration } CLOSE_BRACE { - Accessors accessors = (Accessors) $10; + Accessors accessors = (Accessors) $11; Accessor get_block = accessors != null ? accessors.get_or_add : null; Accessor set_block = accessors != null ? accessors.set_or_remove : null; bool order = accessors != null ? accessors.declared_in_reverse : false; Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3, - (MemberName)$4, (int) $2, (ParametersCompiled) $6, (Attributes) $1, + (MemberName)$4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1, get_block, set_block, order); if ($3 == TypeManager.system_void_expr) @@ -2450,7 +2443,7 @@ indexer_declaration if (accessors == null) Report.Error (548, indexer.Location, "`{0}': property or indexer must have at least one accessor", indexer.GetSignatureForError ()); - if (current_container.Kind == Kind.Interface) { + if (current_container.Kind == MemberKind.Interface) { if (indexer.Get.Block != null) Report.Error (531, indexer.Location, "`{0}.get': interface members cannot have a definition", indexer.GetSignatureForError ()); @@ -2486,7 +2479,7 @@ enum_declaration } name = MakeName (name); - Enum e = new Enum (current_namespace, current_class, (TypeExpr) $5, (int) $2, + Enum e = new Enum (current_namespace, current_class, (TypeExpr) $5, (Modifiers) $2, name, (Attributes) $1); if (RootContext.Documentation != null) @@ -2494,9 +2487,9 @@ enum_declaration EnumMember em = null; - foreach (VariableDeclaration ev in (ArrayList) $7) { + foreach (VariableDeclaration ev in (IList) $7) { em = new EnumMember ( - e, em, ev.identifier, (Expression) ev.expression_or_array_initializer, + e, em, ev.identifier, ev.GetInitializer ((FullNamedExpression) $5), ev.OptAttributes, ev.Location); // if (RootContext.Documentation != null) @@ -2515,20 +2508,26 @@ enum_declaration ; opt_enum_base - : /* empty */ { $$ = TypeManager.system_int32_expr; } + : /* empty */ + { + $$ = TypeManager.system_int32_expr; + } | COLON type { if ($2 != TypeManager.system_int32_expr && $2 != TypeManager.system_uint32_expr && $2 != TypeManager.system_int64_expr && $2 != TypeManager.system_uint64_expr && $2 != TypeManager.system_int16_expr && $2 != TypeManager.system_uint16_expr && - $2 != TypeManager.system_byte_expr && $2 != TypeManager.system_sbyte_expr) - Enum.Error_1008 (GetLocation ($2)); + $2 != TypeManager.system_byte_expr && $2 != TypeManager.system_sbyte_expr) { + Enum.Error_1008 (GetLocation ($2), Report); + $2 = TypeManager.system_int32_expr; + } $$ = $2; } | COLON error { - Error_TypeExpected (lexer.Location); + Error_TypeExpected (GetLocation ($1)); + $$ = TypeManager.system_int32_expr; } ; @@ -2551,24 +2550,21 @@ enum_body ; opt_enum_member_declarations - : /* empty */ { $$ = new ArrayList (4); } + : /* empty */ { $$ = new VariableDeclaration [0]; } | enum_member_declarations opt_comma { $$ = $1; } ; enum_member_declarations : enum_member_declaration { - ArrayList l = new ArrayList (4); - - l.Add ($1); + var l = new List (4); + l.Add ((VariableDeclaration) $1); $$ = l; } | enum_member_declarations COMMA enum_member_declaration { - ArrayList l = (ArrayList) $1; - - l.Add ($3); - + var l = (List) $1; + l.Add ((VariableDeclaration) $3); $$ = l; } ; @@ -2577,7 +2573,7 @@ enum_member_declaration : opt_attributes IDENTIFIER { VariableDeclaration vd = new VariableDeclaration ( - (LocatedToken) $2, null, (Attributes) $1); + (Tokenizer.LocatedToken) $2, null, (Attributes) $1); if (RootContext.Documentation != null) { vd.DocComment = Lexer.consume_doc_comment (); @@ -2598,7 +2594,7 @@ enum_member_declaration { --lexer.parsing_block; VariableDeclaration vd = new VariableDeclaration ( - (LocatedToken) $2, $5, (Attributes) $1); + (Tokenizer.LocatedToken) $2, (Expression) $5, (Attributes) $1); if (RootContext.Documentation != null) vd.DocComment = ConsumeStoredComment (); @@ -2612,13 +2608,19 @@ delegate_declaration opt_modifiers DELEGATE member_type type_declaration_name - OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS + OPEN_PARENS { + valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out | ParameterModifierType.Params | ParameterModifierType.DefaultValue; + } + opt_formal_parameter_list CLOSE_PARENS + { + valid_param_mod = 0; + MemberName name = MakeName ((MemberName) $5); - ParametersCompiled p = (ParametersCompiled) $7; + ParametersCompiled p = (ParametersCompiled) $8; Delegate del = new Delegate (current_namespace, current_class, (FullNamedExpression) $4, - (int) $2, name, p, (Attributes) $1); + (Modifiers) $2, name, p, (Attributes) $1); if (RootContext.Documentation != null) { del.DocComment = Lexer.consume_doc_comment (); @@ -2635,7 +2637,7 @@ delegate_declaration } SEMICOLON { - current_delegate.SetParameterInfo ((ArrayList) $10); + current_delegate.SetParameterInfo ((List) $11); $$ = current_delegate; current_delegate = null; @@ -2650,9 +2652,9 @@ opt_nullable | INTERR_NULLABLE { if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2) - Report.FeatureIsNotSupported (lexer.Location, "nullable types"); + Report.FeatureIsNotSupported (GetLocation ($1), "nullable types"); else if (RootContext.Version < LanguageVersion.ISO_2) - Report.FeatureIsNotAvailable (lexer.Location, "nullable types"); + Report.FeatureIsNotAvailable (GetLocation ($1), "nullable types"); $$ = this; } @@ -2662,8 +2664,8 @@ namespace_or_type_name : member_name | qualified_alias_member IDENTIFIER opt_type_argument_list { - LocatedToken lt1 = (LocatedToken) $1; - LocatedToken lt2 = (LocatedToken) $2; + var lt1 = (Tokenizer.LocatedToken) $1; + var lt2 = (Tokenizer.LocatedToken) $2; $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location); } @@ -2673,7 +2675,7 @@ member_name : type_name | namespace_or_type_name DOT IDENTIFIER opt_type_argument_list { - LocatedToken lt = (LocatedToken) $3; + var lt = (Tokenizer.LocatedToken) $3; $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $4, lt.Location); } ; @@ -2681,7 +2683,7 @@ member_name type_name : IDENTIFIER opt_type_argument_list { - LocatedToken lt = (LocatedToken) $1; + var lt = (Tokenizer.LocatedToken) $1; $$ = new MemberName (lt.Value, (TypeArguments)$2, lt.Location); } ; @@ -2694,7 +2696,7 @@ opt_type_argument_list | OP_GENERICS_LT type_arguments OP_GENERICS_GT { if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2) - Report.FeatureIsNotSupported (lexer.Location, "generics"); + Report.FeatureIsNotSupported (GetLocation ($1), "generics"); else if (RootContext.Version < LanguageVersion.ISO_2) Report.FeatureIsNotAvailable (GetLocation ($1), "generics"); @@ -2733,7 +2735,7 @@ type_declaration_name opt_type_parameter_list { lexer.parsing_generic_declaration = false; - LocatedToken lt = (LocatedToken) $1; + var lt = (Tokenizer.LocatedToken) $1; $$ = new MemberName (lt.Value, (TypeArguments)$3, lt.Location); } ; @@ -2753,7 +2755,7 @@ method_declaration_name | explicit_interface IDENTIFIER opt_type_parameter_list { lexer.parsing_generic_declaration = false; - LocatedToken lt = (LocatedToken) $2; + var lt = (Tokenizer.LocatedToken) $2; $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location); } ; @@ -2774,19 +2776,19 @@ indexer_declaration_name explicit_interface : IDENTIFIER opt_type_argument_list DOT { - LocatedToken lt = (LocatedToken) $1; + var lt = (Tokenizer.LocatedToken) $1; $$ = new MemberName (lt.Value, (TypeArguments) $2, lt.Location); } | qualified_alias_member IDENTIFIER opt_type_argument_list DOT { - LocatedToken lt1 = (LocatedToken) $1; - LocatedToken lt2 = (LocatedToken) $2; + var lt1 = (Tokenizer.LocatedToken) $1; + var lt2 = (Tokenizer.LocatedToken) $2; $$ = new MemberName (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location); } | explicit_interface IDENTIFIER opt_type_argument_list DOT { - LocatedToken lt = (LocatedToken) $2; + var lt = (Tokenizer.LocatedToken) $2; $$ = new MemberName ((MemberName) $1, lt.Value, (TypeArguments) $3, lt.Location); } ; @@ -2796,7 +2798,7 @@ opt_type_parameter_list | OP_GENERICS_LT_DECL type_parameters OP_GENERICS_GT { if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2) - Report.FeatureIsNotSupported (lexer.Location, "generics"); + Report.FeatureIsNotSupported (GetLocation ($1), "generics"); else if (RootContext.Version < LanguageVersion.ISO_2) Report.FeatureIsNotAvailable (GetLocation ($1), "generics"); @@ -2822,7 +2824,7 @@ type_parameters type_parameter : opt_attributes opt_type_parameter_variance IDENTIFIER { - LocatedToken lt = (LocatedToken)$3; + var lt = (Tokenizer.LocatedToken)$3; $$ = new TypeParameterName (lt.Value, (Attributes)$1, (Variance) $2, lt.Location); } | error @@ -2861,7 +2863,7 @@ type : type_expression_or_array | VOID { - Expression.Error_VoidInvalidInTheContext (lexer.Location); + Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report); $$ = TypeManager.system_void_expr; } ; @@ -2870,17 +2872,26 @@ simple_type : type_expression | VOID { - Expression.Error_VoidInvalidInTheContext (lexer.Location); + Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report); + $$ = TypeManager.system_void_expr; + } + ; + +parameter_type + : type_expression_or_array + | VOID + { + Report.Error (1536, GetLocation ($1), "Invalid parameter type `void'"); $$ = TypeManager.system_void_expr; } - ; + ; type_expression_or_array : type_expression | type_expression rank_specifiers { string rank_specifiers = (string) $2; - $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers); + $$ = new ComposedCast ((FullNamedExpression) $1, rank_specifiers); } ; @@ -2892,8 +2903,8 @@ type_expression if ($2 != null) { $$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location); } else { - if (name.Left == null && name.Name == "var" && RootContext.Version > LanguageVersion.ISO_2) - $$ = current_array_type = new VarExpr (name.Location); + if (name.Left == null && name.Name == "var") + $$ = new VarExpr (name.Location); else $$ = name.GetTypeExpression (); } @@ -2914,21 +2925,21 @@ type_expression } | VOID STAR { - $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1); + $$ = new ComposedCast (TypeManager.system_void_expr, "*", GetLocation ($1)); } ; type_list : base_type_name { - ArrayList types = new ArrayList (2); - types.Add ($1); + var types = new List (2); + types.Add ((FullNamedExpression) $1); $$ = types; } | type_list COMMA base_type_name { - ArrayList types = (ArrayList) $1; - types.Add ($3); + var types = (List) $1; + types.Add ((FullNamedExpression) $3); $$ = types; } ; @@ -2936,13 +2947,15 @@ type_list base_type_name : type { - if ($1 is ComposedCast) + if ($1 is ComposedCast) { Report.Error (1521, GetLocation ($1), "Invalid base type `{0}'", ((ComposedCast)$1).GetSignatureForError ()); + } $$ = $1; } | error { Error_TypeExpected (lexer.Location); + $$ = null; } ; @@ -2994,11 +3007,11 @@ primary_expression_no_array_creation : literal | IDENTIFIER opt_type_argument_list { - LocatedToken lt = (LocatedToken) $1; - $$ = new SimpleName (MemberName.MakeName (lt.Value, (TypeArguments)$2), (TypeArguments)$2, lt.Location); + var lt = (Tokenizer.LocatedToken) $1; + $$ = new SimpleName (lt.Value, (TypeArguments)$2, lt.Location); } | IDENTIFIER GENERATE_COMPLETION { - LocatedToken lt = (LocatedToken) $1; + var lt = (Tokenizer.LocatedToken) $1; $$ = new CompletionSimpleName (MemberName.MakeName (lt.Value, null), lt.Location); } | parenthesized_expression @@ -3022,39 +3035,13 @@ primary_expression_no_array_creation literal : boolean_literal - | integer_literal - | real_literal - | LITERAL_CHARACTER { $$ = new CharLiteral ((char) lexer.Value, lexer.Location); } - | LITERAL_STRING { $$ = new StringLiteral ((string) lexer.Value, lexer.Location); } - | NULL { $$ = new NullLiteral (lexer.Location); } - ; - -real_literal - : LITERAL_FLOAT { $$ = new FloatLiteral ((float) lexer.Value, lexer.Location); } - | LITERAL_DOUBLE { $$ = new DoubleLiteral ((double) lexer.Value, lexer.Location); } - | LITERAL_DECIMAL { $$ = new DecimalLiteral ((decimal) lexer.Value, lexer.Location); } - ; - -integer_literal - : LITERAL_INTEGER { - object v = lexer.Value; - - if (v is int){ - $$ = new IntLiteral ((int) v, lexer.Location); - } else if (v is uint) - $$ = new UIntLiteral ((UInt32) v, lexer.Location); - else if (v is long) - $$ = new LongLiteral ((Int64) v, lexer.Location); - else if (v is ulong) - $$ = new ULongLiteral ((UInt64) v, lexer.Location); - else - Console.WriteLine ("OOPS. Unexpected result from scanner"); - } + | LITERAL + | NULL { $$ = new NullLiteral (GetLocation ($1)); } ; boolean_literal - : TRUE { $$ = new BoolLiteral (true, lexer.Location); } - | FALSE { $$ = new BoolLiteral (false, lexer.Location); } + : TRUE { $$ = new BoolLiteral (true, GetLocation ($1)); } + | FALSE { $$ = new BoolLiteral (false, GetLocation ($1)); } ; @@ -3066,9 +3053,18 @@ boolean_literal open_parens_any : OPEN_PARENS | OPEN_PARENS_CAST - | OPEN_PARENS_LAMBDA ; +// +// Use this production to accept closing parenthesis or +// performing completion +// +close_parens + : CLOSE_PARENS + | COMPLETE_COMPLETION + ; + + parenthesized_expression : OPEN_PARENS expression CLOSE_PARENS { @@ -3083,19 +3079,19 @@ parenthesized_expression member_access : primary_expression DOT IDENTIFIER opt_type_argument_list { - LocatedToken lt = (LocatedToken) $3; + var lt = (Tokenizer.LocatedToken) $3; $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location); } | predefined_type DOT IDENTIFIER opt_type_argument_list { - LocatedToken lt = (LocatedToken) $3; + var lt = (Tokenizer.LocatedToken) $3; // TODO: Location is wrong as some predefined types doesn't hold a location $$ = new MemberAccess ((Expression) $1, lt.Value, (TypeArguments) $4, lt.Location); } | qualified_alias_member IDENTIFIER opt_type_argument_list { - LocatedToken lt1 = (LocatedToken) $1; - LocatedToken lt2 = (LocatedToken) $2; + var lt1 = (Tokenizer.LocatedToken) $1; + var lt2 = (Tokenizer.LocatedToken) $2; $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (TypeArguments) $3, lt1.Location); } @@ -3103,7 +3099,7 @@ member_access $$ = new CompletionMemberAccess ((Expression) $1, null,GetLocation ($3)); } | primary_expression DOT IDENTIFIER GENERATE_COMPLETION { - LocatedToken lt = (LocatedToken) $3; + var lt = (Tokenizer.LocatedToken) $3; $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location); } | predefined_type DOT GENERATE_COMPLETION @@ -3112,15 +3108,15 @@ member_access $$ = new CompletionMemberAccess ((Expression) $1, null, lexer.Location); } | predefined_type DOT IDENTIFIER GENERATE_COMPLETION { - LocatedToken lt = (LocatedToken) $3; + var lt = (Tokenizer.LocatedToken) $3; $$ = new CompletionMemberAccess ((Expression) $1, lt.Value, lt.Location); } ; invocation_expression - : primary_expression open_parens_any opt_argument_list CLOSE_PARENS + : primary_expression open_parens_any opt_argument_list close_parens { - $$ = new Invocation ((Expression) $1, (ArrayList) $3); + $$ = new Invocation ((Expression) $1, (Arguments) $3); } ; @@ -3135,11 +3131,11 @@ object_or_collection_initializer if ($2 == null) $$ = CollectionOrObjectInitializers.Empty; else - $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1)); + $$ = new CollectionOrObjectInitializers ((List) $2, GetLocation ($1)); } | OPEN_BRACE member_initializer_list COMMA CLOSE_BRACE { - $$ = new CollectionOrObjectInitializers ((ArrayList) $2, GetLocation ($1)); + $$ = new CollectionOrObjectInitializers ((List) $2, GetLocation ($1)); } ; @@ -3152,16 +3148,16 @@ opt_member_initializer_list ; member_initializer_list - : member_initializer + : member_initializer { - ArrayList a = new ArrayList (); - a.Add ($1); + var a = new List (); + a.Add ((Expression) $1); $$ = a; } | member_initializer_list COMMA member_initializer { - ArrayList a = (ArrayList)$1; - a.Add ($3); + var a = (List)$1; + a.Add ((Expression) $3); $$ = a; } ; @@ -3169,7 +3165,7 @@ member_initializer_list member_initializer : IDENTIFIER ASSIGN initializer_value { - LocatedToken lt = $1 as LocatedToken; + var lt = (Tokenizer.LocatedToken) $1; $$ = new ElementInitializer (lt.Value, (Expression)$3, lt.Location); } | GENERATE_COMPLETION @@ -3185,11 +3181,12 @@ member_initializer } | OPEN_BRACE expression_list CLOSE_BRACE { - $$ = new CollectionElementInitializer ((ArrayList)$2, GetLocation ($1)); + $$ = new CollectionElementInitializer ((List)$2, GetLocation ($1)); } | OPEN_BRACE CLOSE_BRACE { Report.Error (1920, GetLocation ($1), "An element initializer cannot be empty"); + $$ = null; } ; @@ -3204,16 +3201,33 @@ opt_argument_list ; argument_list - : argument + : argument_or_named_argument { - ArrayList list = new ArrayList (4); - list.Add ($1); + Arguments list = new Arguments (4); + list.Add ((Argument) $1); $$ = list; } | argument_list COMMA argument { - ArrayList list = (ArrayList) $1; - list.Add ($3); + Arguments list = (Arguments) $1; + if (list [list.Count - 1] is NamedArgument) + Error_NamedArgumentExpected ((NamedArgument) list [list.Count - 1]); + + list.Add ((Argument) $3); + $$ = list; + } + | argument_list COMMA named_argument + { + Arguments list = (Arguments) $1; + NamedArgument a = (NamedArgument) $3; + for (int i = 0; i < list.Count; ++i) { + NamedArgument na = list [i] as NamedArgument; + if (na != null && na.Name == a.Name) + Report.Error (1740, na.Location, "Named argument `{0}' specified multiple times", + na.Name); + } + + list.Add (a); $$ = list; } | argument_list COMMA @@ -3221,7 +3235,7 @@ argument_list Report.Error (839, GetLocation ($2), "An argument is missing"); $$ = null; } - | COMMA argument + | COMMA argument_or_named_argument { Report.Error (839, GetLocation ($1), "An argument is missing"); $$ = null; @@ -3231,12 +3245,14 @@ argument_list argument : expression { - $$ = new Argument ((Expression) $1, Argument.AType.Expression); + $$ = new Argument ((Expression) $1); } | non_simple_argument - { - $$ = $1; - } + ; + +argument_or_named_argument + : argument + | named_argument ; non_simple_argument @@ -3248,38 +3264,33 @@ non_simple_argument { $$ = new Argument ((Expression) $2, Argument.AType.Out); } - | ARGLIST open_parens_any argument_list CLOSE_PARENS + | ARGLIST OPEN_PARENS argument_list CLOSE_PARENS { - ArrayList list = (ArrayList) $3; - Argument[] args = new Argument [list.Count]; - list.CopyTo (args, 0); - - Expression expr = new Arglist (args, (Location) $1); - $$ = new Argument (expr, Argument.AType.Expression); + $$ = new Argument (new Arglist ((Arguments) $3, GetLocation ($1))); } - | ARGLIST open_parens_any CLOSE_PARENS + | ARGLIST OPEN_PARENS CLOSE_PARENS { - $$ = new Argument (new Arglist ((Location) $1), Argument.AType.Expression); + $$ = new Argument (new Arglist (GetLocation ($1))); } | ARGLIST { - $$ = new Argument (new ArglistAccess ((Location) $1), Argument.AType.ArgList); + $$ = new Argument (new ArglistAccess (GetLocation ($1))); } ; variable_reference - : expression { note ("section 5.4"); $$ = $1; } + : expression ; element_access - : primary_expression_no_array_creation OPEN_BRACKET expression_list CLOSE_BRACKET + : primary_expression_no_array_creation OPEN_BRACKET expression_list_arguments CLOSE_BRACKET { - $$ = new ElementAccess ((Expression) $1, (ArrayList) $3); + $$ = new ElementAccess ((Expression) $1, (Arguments) $3); } - | array_creation_expression OPEN_BRACKET expression_list CLOSE_BRACKET + | array_creation_expression OPEN_BRACKET expression_list_arguments CLOSE_BRACKET { // LAMESPEC: Not allowed according to specification - $$ = new ElementAccess ((Expression) $1, (ArrayList) $3); + $$ = new ElementAccess ((Expression) $1, (Arguments) $3); } | primary_expression_no_array_creation rank_specifiers { @@ -3303,60 +3314,82 @@ element_access Error_ExpectingTypeName (expr); $$ = TypeManager.system_object_expr; } - - current_array_type = (FullNamedExpression)$$; } ; expression_list : expression { - ArrayList list = new ArrayList (4); - list.Add ($1); + var list = new List (4); + list.Add ((Expression) $1); $$ = list; } | expression_list COMMA expression { - ArrayList list = (ArrayList) $1; - list.Add ($3); + var list = (List) $1; + list.Add ((Expression) $3); $$ = list; } ; + +expression_list_arguments + : expression_list_argument + { + Arguments args = new Arguments (4); + args.Add ((Argument) $1); + $$ = args; + } + | expression_list_arguments COMMA expression_list_argument + { + Arguments args = (Arguments) $1; + args.Add ((Argument) $3); + $$ = args; + } + ; + +expression_list_argument + : expression + { + $$ = new Argument ((Expression) $1); + } + | named_argument + ; this_access : THIS { - $$ = new This (current_block, (Location) $1); + $$ = new This (current_block, GetLocation ($1)); } ; base_access : BASE DOT IDENTIFIER opt_type_argument_list { - LocatedToken lt = (LocatedToken) $3; + var lt = (Tokenizer.LocatedToken) $3; $$ = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location); } - | BASE OPEN_BRACKET expression_list CLOSE_BRACKET + | BASE OPEN_BRACKET expression_list_arguments CLOSE_BRACKET { - $$ = new BaseIndexerAccess ((ArrayList) $3, (Location) $1); + $$ = new BaseIndexerAccess ((Arguments) $3, GetLocation ($1)); } - | BASE error { - Report.Error (175, (Location) $1, "Use of keyword `base' is not valid in this context"); - $$ = null; + | BASE error + { + Error_SyntaxError (yyToken); + $$ = new BaseAccess (null, GetLocation ($2)); } ; post_increment_expression : primary_expression OP_INC { - $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1); + $$ = new UnaryMutator (UnaryMutator.Mode.PostIncrement, (Expression) $1, GetLocation ($2)); } ; post_decrement_expression : primary_expression OP_DEC { - $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1); + $$ = new UnaryMutator (UnaryMutator.Mode.PostDecrement, (Expression) $1, GetLocation ($2)); } ; @@ -3367,10 +3400,10 @@ object_or_delegate_creation_expression if (RootContext.Version <= LanguageVersion.ISO_2) Report.FeatureIsNotAvailable (GetLocation ($1), "object initializers"); - $$ = new NewInitialize ((Expression) $1, (ArrayList) $3, (CollectionOrObjectInitializers) $5, GetLocation ($1)); + $$ = new NewInitialize ((Expression) $1, (Arguments) $3, (CollectionOrObjectInitializers) $5, GetLocation ($1)); } else - $$ = new New ((Expression) $1, (ArrayList) $3, GetLocation ($1)); + $$ = new New ((Expression) $1, (Arguments) $3, GetLocation ($1)); } | new_expr_start object_or_collection_initializer { @@ -3386,23 +3419,26 @@ array_creation_expression opt_rank_specifier // shift/reduce on OPEN_BRACE opt_array_initializer { - $$ = new ArrayCreation ((FullNamedExpression) $1, (ArrayList) $3, (string) $5, (ArrayList) $6, GetLocation ($1)); + $$ = new ArrayCreation ((FullNamedExpression) $1, (List) $3, (string) $5, (ArrayInitializer) $6, GetLocation ($1)); } | new_expr_start rank_specifiers opt_array_initializer { if ($3 == null) Report.Error (1586, GetLocation ($1), "Array creation must have array size or array initializer"); - $$ = new ArrayCreation ((FullNamedExpression) $1, (string) $2, (ArrayList) $3, GetLocation ($1)); + $$ = new ArrayCreation ((FullNamedExpression) $1, (string) $2, (ArrayInitializer) $3, GetLocation ($1)); } | NEW rank_specifiers array_initializer { - $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, GetLocation ($1)); + if (RootContext.Version <= LanguageVersion.ISO_2) + Report.FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays"); + + $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayInitializer) $3, GetLocation ($1)); } | new_expr_start error { Report.Error (1526, GetLocation ($1), "A new expression requires () or [] after type"); - $$ = null; + $$ = new ArrayCreation ((FullNamedExpression) $1, "[]", null, GetLocation ($1)); } ; @@ -3422,11 +3458,11 @@ anonymous_type_expression : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE { if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2) - Report.FeatureIsNotSupported (lexer.Location, "anonymous types"); + Report.FeatureIsNotSupported (GetLocation ($1), "anonymous types"); else if (RootContext.Version <= LanguageVersion.ISO_2) Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types"); - $$ = new AnonymousTypeDeclaration ((ArrayList) $3, current_container, GetLocation ($1)); + $$ = new NewAnonymousType ((List) $3, current_container, GetLocation ($1)); } ; @@ -3443,14 +3479,14 @@ anonymous_type_parameters_opt anonymous_type_parameters : anonymous_type_parameter { - ArrayList a = new ArrayList (4); - a.Add ($1); + var a = new List (4); + a.Add ((AnonymousTypeParameter) $1); $$ = a; } | anonymous_type_parameters COMMA anonymous_type_parameter { - ArrayList a = (ArrayList) $1; - a.Add ($3); + var a = (List) $1; + a.Add ((AnonymousTypeParameter) $3); $$ = a; } ; @@ -3458,18 +3494,18 @@ anonymous_type_parameters anonymous_type_parameter : IDENTIFIER ASSIGN variable_initializer { - LocatedToken lt = (LocatedToken)$1; + var lt = (Tokenizer.LocatedToken)$1; $$ = new AnonymousTypeParameter ((Expression)$3, lt.Value, lt.Location); } | IDENTIFIER { - LocatedToken lt = (LocatedToken)$1; + var lt = (Tokenizer.LocatedToken)$1; $$ = new AnonymousTypeParameter (new SimpleName (lt.Value, lt.Location), lt.Value, lt.Location); } | BASE DOT IDENTIFIER opt_type_argument_list { - LocatedToken lt = (LocatedToken) $3; + var lt = (Tokenizer.LocatedToken) $3; BaseAccess ba = new BaseAccess (lt.Value, (TypeArguments) $4, lt.Location); $$ = new AnonymousTypeParameter (ba, lt.Value, lt.Location); } @@ -3480,8 +3516,9 @@ anonymous_type_parameter } | error { - Report.Error (746, lexer.Location, "Invalid anonymous type member declarator. " + - "Anonymous type members must be a member assignment, simple name or member access expression"); + Report.Error (746, lexer.Location, + "Invalid anonymous type member declarator. Anonymous type members must be a member assignment, simple name or member access expression"); + $$ = null; } ; @@ -3517,7 +3554,7 @@ rank_specifiers : rank_specifier | rank_specifier rank_specifiers { - $$ = (string) $2 + (string) $1; + $$ = (string) $1 + (string) $2; } ; @@ -3530,9 +3567,9 @@ rank_specifier { $$ = "[" + (string) $2 + "]"; } - | OPEN_BRACKET error CLOSE_BRACKET + | OPEN_BRACKET error { - ArrayCreation.Error_IncorrectArrayInitializer (GetLocation ($1)); + Error_SyntaxError (178, yyToken, "Invalid rank specifier"); $$ = "[]"; } ; @@ -3562,39 +3599,37 @@ opt_array_initializer array_initializer : OPEN_BRACE CLOSE_BRACE { - ArrayList list = new ArrayList (4); - $$ = list; + $$ = new ArrayInitializer (0, GetLocation ($1)); } | OPEN_BRACE variable_initializer_list opt_comma CLOSE_BRACE { - $$ = (ArrayList) $2; + $$ = new ArrayInitializer ((List) $2, GetLocation ($1)); } ; variable_initializer_list : variable_initializer { - ArrayList list = new ArrayList (4); - list.Add ($1); + var list = new List (4); + list.Add ((Expression) $1); $$ = list; } | variable_initializer_list COMMA variable_initializer { - ArrayList list = (ArrayList) $1; - list.Add ($3); + var list = (List) $1; + list.Add ((Expression) $3); $$ = list; } | error { Error_SyntaxError (yyToken); - $$ = new ArrayList (); + $$ = new List (); } ; typeof_expression : TYPEOF { - pushed_current_array_type = current_array_type; lexer.TypeOfParsing = true; } open_parens_any typeof_type_expression CLOSE_PARENS @@ -3602,10 +3637,9 @@ typeof_expression lexer.TypeOfParsing = false; Expression type = (Expression)$4; if (type == TypeManager.system_void_expr) - $$ = new TypeOfVoid ((Location) $1); + $$ = new TypeOfVoid (GetLocation ($1)); else - $$ = new TypeOf (type, (Location) $1); - current_array_type = pushed_current_array_type; + $$ = new TypeOf (type, GetLocation ($1)); } ; @@ -3622,35 +3656,35 @@ typeof_type_expression unbound_type_name : IDENTIFIER generic_dimension { - LocatedToken lt = (LocatedToken) $1; + var lt = (Tokenizer.LocatedToken) $1; - $$ = new SimpleName (MemberName.MakeName (lt.Value, (int)$2), lt.Location); + $$ = new SimpleName (lt.Value, (int) $2, lt.Location); } | qualified_alias_member IDENTIFIER generic_dimension { - LocatedToken lt1 = (LocatedToken) $1; - LocatedToken lt2 = (LocatedToken) $2; + var lt1 = (Tokenizer.LocatedToken) $1; + var lt2 = (Tokenizer.LocatedToken) $2; - $$ = new QualifiedAliasMember (lt1.Value, MemberName.MakeName (lt2.Value, (int) $3), lt1.Location); + $$ = new QualifiedAliasMember (lt1.Value, lt2.Value, (int) $3, lt1.Location); } | unbound_type_name DOT IDENTIFIER { - LocatedToken lt = (LocatedToken) $3; + var lt = (Tokenizer.LocatedToken) $3; $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location); } | unbound_type_name DOT IDENTIFIER generic_dimension { - LocatedToken lt = (LocatedToken) $3; + var lt = (Tokenizer.LocatedToken) $3; - $$ = new MemberAccess ((Expression) $1, MemberName.MakeName (lt.Value, (int) $4), lt.Location); + $$ = new MemberAccess ((Expression) $1, lt.Value, (int) $4, lt.Location); } | namespace_or_type_name DOT IDENTIFIER generic_dimension { - LocatedToken lt = (LocatedToken) $3; + var lt = (Tokenizer.LocatedToken) $3; MemberName name = (MemberName) $1; - $$ = new MemberAccess (name.GetTypeExpression (), MemberName.MakeName (lt.Value, (int) $4), lt.Location); + $$ = new MemberAccess (name.GetTypeExpression (), lt.Value, (int) $4, lt.Location); } ; @@ -3658,9 +3692,9 @@ generic_dimension : GENERIC_DIMENSION { if (RootContext.MetadataCompatibilityVersion < MetadataVersion.v2) - Report.FeatureIsNotSupported (lexer.Location, "generics"); + Report.FeatureIsNotSupported (GetLocation ($1), "generics"); else if (RootContext.Version < LanguageVersion.ISO_2) - Report.FeatureIsNotAvailable (lexer.Location, "generics"); + Report.FeatureIsNotAvailable (GetLocation ($1), "generics"); $$ = $1; } @@ -3669,7 +3703,7 @@ generic_dimension qualified_alias_member : IDENTIFIER DOUBLE_COLON { - LocatedToken lt = (LocatedToken) $1; + var lt = (Tokenizer.LocatedToken) $1; if (RootContext.Version == LanguageVersion.ISO_1) Report.FeatureIsNotAvailable (lt.Location, "namespace alias qualifier"); @@ -3679,21 +3713,21 @@ qualified_alias_member sizeof_expression : SIZEOF open_parens_any type CLOSE_PARENS { - $$ = new SizeOf ((Expression) $3, (Location) $1); + $$ = new SizeOf ((Expression) $3, GetLocation ($1)); } ; checked_expression : CHECKED open_parens_any expression CLOSE_PARENS { - $$ = new CheckedExpr ((Expression) $3, (Location) $1); + $$ = new CheckedExpr ((Expression) $3, GetLocation ($1)); } ; unchecked_expression : UNCHECKED open_parens_any expression CLOSE_PARENS { - $$ = new UnCheckedExpr ((Expression) $3, (Location) $1); + $$ = new UnCheckedExpr ((Expression) $3, GetLocation ($1)); } ; @@ -3701,7 +3735,7 @@ pointer_member_access : primary_expression OP_PTR IDENTIFIER { Expression deref; - LocatedToken lt = (LocatedToken) $3; + var lt = (Tokenizer.LocatedToken) $3; deref = new Indirection ((Expression) $1, lt.Location); $$ = new MemberAccess (deref, lt.Value); @@ -3711,7 +3745,7 @@ pointer_member_access anonymous_method_expression : DELEGATE opt_anonymous_method_signature { - start_anonymous (false, (ParametersCompiled) $2, (Location) $1); + start_anonymous (false, (ParametersCompiled) $2, GetLocation ($1)); } block { @@ -3730,11 +3764,11 @@ opt_anonymous_method_signature anonymous_method_signature : OPEN_PARENS { - complex_parameters_modifiers_not_allowed = true; + valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out; } opt_formal_parameter_list CLOSE_PARENS { - complex_parameters_modifiers_not_allowed = false; + valid_param_mod = 0; $$ = $3; } ; @@ -3743,7 +3777,7 @@ default_value_expression : DEFAULT open_parens_any type CLOSE_PARENS { if (RootContext.Version < LanguageVersion.ISO_2) - Report.FeatureIsNotAvailable (lexer.Location, "default value expression"); + Report.FeatureIsNotAvailable (GetLocation ($1), "default value expression"); $$ = new DefaultValueExpression ((Expression) $3, GetLocation ($1)); } @@ -3753,11 +3787,11 @@ unary_expression : primary_expression | BANG prefixed_unary_expression { - $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2); + $$ = new Unary (Unary.Operator.LogicalNot, (Expression) $2, GetLocation ($1)); } | TILDE prefixed_unary_expression { - $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2); + $$ = new Unary (Unary.Operator.OnesComplement, (Expression) $2, GetLocation ($1)); } | cast_expression ; @@ -3781,19 +3815,19 @@ prefixed_unary_expression : unary_expression | PLUS prefixed_unary_expression { - $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2); + $$ = new Unary (Unary.Operator.UnaryPlus, (Expression) $2, GetLocation ($1)); } | MINUS prefixed_unary_expression { - $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2); + $$ = new Unary (Unary.Operator.UnaryNegation, (Expression) $2, GetLocation ($1)); } | OP_INC prefixed_unary_expression { - $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2); + $$ = new UnaryMutator (UnaryMutator.Mode.PreIncrement, (Expression) $2, GetLocation ($1)); } | OP_DEC prefixed_unary_expression { - $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2); + $$ = new UnaryMutator (UnaryMutator.Mode.PreDecrement, (Expression) $2, GetLocation ($1)); } | STAR prefixed_unary_expression { @@ -3801,7 +3835,7 @@ prefixed_unary_expression } | BITWISE_AND prefixed_unary_expression { - $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2); + $$ = new Unary (Unary.Operator.AddressOf, (Expression) $2, GetLocation ($1)); } ; @@ -3810,17 +3844,17 @@ multiplicative_expression | multiplicative_expression STAR prefixed_unary_expression { $$ = new Binary (Binary.Operator.Multiply, - (Expression) $1, (Expression) $3); + (Expression) $1, (Expression) $3, GetLocation ($2)); } | multiplicative_expression DIV prefixed_unary_expression { $$ = new Binary (Binary.Operator.Division, - (Expression) $1, (Expression) $3); + (Expression) $1, (Expression) $3, GetLocation ($2)); } | multiplicative_expression PERCENT prefixed_unary_expression { $$ = new Binary (Binary.Operator.Modulus, - (Expression) $1, (Expression) $3); + (Expression) $1, (Expression) $3, GetLocation ($2)); } ; @@ -3829,24 +3863,24 @@ additive_expression | additive_expression PLUS multiplicative_expression { $$ = new Binary (Binary.Operator.Addition, - (Expression) $1, (Expression) $3); + (Expression) $1, (Expression) $3, GetLocation ($2)); } | additive_expression MINUS multiplicative_expression { - $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3); + $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2)); } | parenthesized_expression MINUS multiplicative_expression { // Shift/Reduce conflict - $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3); + $$ = new Binary (Binary.Operator.Subtraction, (Expression) $1, (Expression) $3, GetLocation ($2)); } | additive_expression AS type { - $$ = new As ((Expression) $1, (Expression) $3, (Location) $2); + $$ = new As ((Expression) $1, (Expression) $3, GetLocation ($2)); } | additive_expression IS type { - $$ = new Is ((Expression) $1, (Expression) $3, (Location) $2); + $$ = new Is ((Expression) $1, (Expression) $3, GetLocation ($2)); } ; @@ -3855,12 +3889,12 @@ shift_expression | shift_expression OP_SHIFT_LEFT additive_expression { $$ = new Binary (Binary.Operator.LeftShift, - (Expression) $1, (Expression) $3); + (Expression) $1, (Expression) $3, GetLocation ($2)); } | shift_expression OP_SHIFT_RIGHT additive_expression { $$ = new Binary (Binary.Operator.RightShift, - (Expression) $1, (Expression) $3); + (Expression) $1, (Expression) $3, GetLocation ($2)); } ; @@ -3869,22 +3903,22 @@ relational_expression | relational_expression OP_LT shift_expression { $$ = new Binary (Binary.Operator.LessThan, - (Expression) $1, (Expression) $3); + (Expression) $1, (Expression) $3, GetLocation ($2)); } | relational_expression OP_GT shift_expression { $$ = new Binary (Binary.Operator.GreaterThan, - (Expression) $1, (Expression) $3); + (Expression) $1, (Expression) $3, GetLocation ($2)); } | relational_expression OP_LE shift_expression { $$ = new Binary (Binary.Operator.LessThanOrEqual, - (Expression) $1, (Expression) $3); + (Expression) $1, (Expression) $3, GetLocation ($2)); } | relational_expression OP_GE shift_expression { $$ = new Binary (Binary.Operator.GreaterThanOrEqual, - (Expression) $1, (Expression) $3); + (Expression) $1, (Expression) $3, GetLocation ($2)); } ; @@ -3893,12 +3927,12 @@ equality_expression | equality_expression OP_EQ relational_expression { $$ = new Binary (Binary.Operator.Equality, - (Expression) $1, (Expression) $3); + (Expression) $1, (Expression) $3, GetLocation ($2)); } | equality_expression OP_NE relational_expression { $$ = new Binary (Binary.Operator.Inequality, - (Expression) $1, (Expression) $3); + (Expression) $1, (Expression) $3, GetLocation ($2)); } ; @@ -3907,7 +3941,7 @@ and_expression | and_expression BITWISE_AND equality_expression { $$ = new Binary (Binary.Operator.BitwiseAnd, - (Expression) $1, (Expression) $3); + (Expression) $1, (Expression) $3, GetLocation ($2)); } ; @@ -3916,7 +3950,7 @@ exclusive_or_expression | exclusive_or_expression CARRET and_expression { $$ = new Binary (Binary.Operator.ExclusiveOr, - (Expression) $1, (Expression) $3); + (Expression) $1, (Expression) $3, GetLocation ($2)); } ; @@ -3925,7 +3959,7 @@ inclusive_or_expression | inclusive_or_expression BITWISE_OR exclusive_or_expression { $$ = new Binary (Binary.Operator.BitwiseOr, - (Expression) $1, (Expression) $3); + (Expression) $1, (Expression) $3, GetLocation ($2)); } ; @@ -3934,7 +3968,7 @@ conditional_and_expression | conditional_and_expression OP_AND inclusive_or_expression { $$ = new Binary (Binary.Operator.LogicalAnd, - (Expression) $1, (Expression) $3); + (Expression) $1, (Expression) $3, GetLocation ($2)); } ; @@ -3943,7 +3977,7 @@ conditional_or_expression | conditional_or_expression OP_OR conditional_and_expression { $$ = new Binary (Binary.Operator.LogicalOr, - (Expression) $1, (Expression) $3); + (Expression) $1, (Expression) $3, GetLocation ($2)); } ; @@ -3954,7 +3988,7 @@ null_coalescing_expression if (RootContext.Version < LanguageVersion.ISO_2) Report.FeatureIsNotAvailable (GetLocation ($2), "null coalescing operator"); - $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, lexer.Location); + $$ = new Nullable.NullCoalescingOperator ((Expression) $1, (Expression) $3, GetLocation ($2)); } ; @@ -3962,7 +3996,7 @@ conditional_expression : null_coalescing_expression | null_coalescing_expression INTERR expression COLON expression { - $$ = new Conditional ((Expression) $1, (Expression) $3, (Expression) $5); + $$ = new Conditional (new BooleanExpression ((Expression) $1), (Expression) $3, (Expression) $5); } ; @@ -4026,14 +4060,14 @@ assignment_expression lambda_parameter_list : lambda_parameter { - ArrayList pars = new ArrayList (4); - pars.Add ($1); + var pars = new List (4); + pars.Add ((Parameter) $1); $$ = pars; } | lambda_parameter_list COMMA lambda_parameter { - ArrayList pars = (ArrayList) $1; + var pars = (List) $1; Parameter p = (Parameter)$3; if (pars[0].GetType () != p.GetType ()) { Report.Error (748, p.Location, "All lambda parameters must be typed either explicitly or implicitly"); @@ -4045,21 +4079,21 @@ lambda_parameter_list ; lambda_parameter - : parameter_modifier type IDENTIFIER + : parameter_modifier parameter_type IDENTIFIER { - LocatedToken lt = (LocatedToken) $3; + var lt = (Tokenizer.LocatedToken) $3; $$ = new Parameter ((FullNamedExpression) $2, lt.Value, (Parameter.Modifier) $1, null, lt.Location); } - | type IDENTIFIER + | parameter_type IDENTIFIER { - LocatedToken lt = (LocatedToken) $2; + var lt = (Tokenizer.LocatedToken) $2; $$ = new Parameter ((FullNamedExpression) $1, lt.Value, Parameter.Modifier.NONE, null, lt.Location); } | IDENTIFIER { - LocatedToken lt = (LocatedToken) $1; + var lt = (Tokenizer.LocatedToken) $1; $$ = new ImplicitLambdaParameter (lt.Value, lt.Location); } ; @@ -4067,8 +4101,8 @@ lambda_parameter opt_lambda_parameter_list : /* empty */ { $$ = ParametersCompiled.EmptyReadOnlyParameters; } | lambda_parameter_list { - ArrayList pars_list = (ArrayList) $1; - $$ = new ParametersCompiled ((Parameter[])pars_list.ToArray (typeof (Parameter))); + var pars_list = (List) $1; + $$ = new ParametersCompiled (compiler, pars_list.ToArray ()); } ; @@ -4090,21 +4124,29 @@ lambda_expression_body lambda_expression : IDENTIFIER ARROW { - LocatedToken lt = (LocatedToken) $1; + var lt = (Tokenizer.LocatedToken) $1; Parameter p = new ImplicitLambdaParameter (lt.Value, lt.Location); - start_anonymous (true, new ParametersCompiled (p), GetLocation ($1)); + start_anonymous (true, new ParametersCompiled (compiler, p), GetLocation ($1)); } lambda_expression_body { $$ = end_anonymous ((ToplevelBlock) $4); } - | OPEN_PARENS_LAMBDA opt_lambda_parameter_list CLOSE_PARENS ARROW + | OPEN_PARENS_LAMBDA + { + if (RootContext.Version <= LanguageVersion.ISO_2) + Report.FeatureIsNotAvailable (GetLocation ($1), "lambda expressions"); + + valid_param_mod = ParameterModifierType.Ref | ParameterModifierType.Out; + } + opt_lambda_parameter_list CLOSE_PARENS ARROW { - start_anonymous (true, (ParametersCompiled) $2, GetLocation ($1)); + valid_param_mod = 0; + start_anonymous (true, (ParametersCompiled) $3, GetLocation ($1)); } lambda_expression_body { - $$ = end_anonymous ((ToplevelBlock) $6); + $$ = end_anonymous ((ToplevelBlock) $7); } ; @@ -4116,7 +4158,7 @@ expression non_assignment_expression : conditional_expression | lambda_expression - | query_expression + | query_expression ; constant_expression @@ -4125,6 +4167,9 @@ constant_expression boolean_expression : expression + { + $$ = new BooleanExpression ((Expression) $1); + } ; // @@ -4141,14 +4186,14 @@ class_declaration type_declaration_name { MemberName name = MakeName ((MemberName) $6); - push_current_class (new Class (current_namespace, current_class, name, (int) $2, (Attributes) $1), $3); + push_current_class (new Class (current_namespace, current_class, name, (Modifiers) $2, (Attributes) $1), $3); } opt_class_base opt_type_parameter_constraints_clauses { lexer.ConstraintsParsing = false; - current_class.SetParameterInfo ((ArrayList) $9); + current_class.SetParameterInfo ((List) $9); if (RootContext.Documentation != null) { current_container.DocComment = Lexer.consume_doc_comment (); @@ -4183,14 +4228,14 @@ modifiers : modifier | modifiers modifier { - int m1 = (int) $1; - int m2 = (int) $2; + var m1 = (Modifiers) $1; + var m2 = (Modifiers) $2; if ((m1 & m2) != 0) { Location l = lexer.Location; - Report.Error (1004, l, "Duplicate `{0}' modifier", Modifiers.Name (m2)); + Report.Error (1004, l, "Duplicate `{0}' modifier", ModifiersExtensions.Name (m2)); } - $$ = (int) (m1 | m2); + $$ = m1 | m2; } ; @@ -4199,7 +4244,7 @@ modifier { $$ = Modifiers.NEW; if (current_container == RootContext.ToplevelTypes) - Report.Error (1530, lexer.Location, "Keyword `new' is not allowed on namespace elements"); + Report.Error (1530, GetLocation ($1), "Keyword `new' is not allowed on namespace elements"); } | PUBLIC { $$ = Modifiers.PUBLIC; } | PROTECTED { $$ = Modifiers.PROTECTED; } @@ -4222,29 +4267,37 @@ opt_class_base ; class_base - : COLON type_list { current_container.AddBasesForPart (current_class, (ArrayList) $2); } + : COLON type_list + { + current_container.AddBasesForPart (current_class, (List) $2); + } ; opt_type_parameter_constraints_clauses : /* empty */ { $$ = null; } | type_parameter_constraints_clauses - { $$ = $1; } + { + $$ = $1; + } ; type_parameter_constraints_clauses - : type_parameter_constraints_clause { - ArrayList constraints = new ArrayList (1); - constraints.Add ($1); + : type_parameter_constraints_clause + { + var constraints = new List (1); + constraints.Add ((Constraints) $1); $$ = constraints; } - | type_parameter_constraints_clauses type_parameter_constraints_clause { - ArrayList constraints = (ArrayList) $1; + | type_parameter_constraints_clauses type_parameter_constraints_clause + { + var constraints = (List) $1; Constraints new_constraint = (Constraints)$2; foreach (Constraints c in constraints) { - if (new_constraint.TypeParameter == c.TypeParameter) { - Report.Error (409, new_constraint.Location, "A constraint clause has already been specified for type parameter `{0}'", - new_constraint.TypeParameter); + if (new_constraint.TypeParameter.Value == c.TypeParameter.Value) { + Report.Error (409, new_constraint.Location, + "A constraint clause has already been specified for type parameter `{0}'", + new_constraint.TypeParameter.Value); } } @@ -4254,36 +4307,64 @@ type_parameter_constraints_clauses ; type_parameter_constraints_clause - : WHERE IDENTIFIER COLON type_parameter_constraints { - LocatedToken lt = (LocatedToken) $2; - $$ = new Constraints (lt.Value, (ArrayList) $4, lt.Location); + : WHERE IDENTIFIER COLON type_parameter_constraints + { + var lt = (Tokenizer.LocatedToken) $2; + $$ = new Constraints (new SimpleMemberName (lt.Value, lt.Location), (List) $4, GetLocation ($1)); } ; type_parameter_constraints - : type_parameter_constraint { - ArrayList constraints = new ArrayList (1); - constraints.Add ($1); + : type_parameter_constraint + { + var constraints = new List (1); + constraints.Add ((FullNamedExpression) $1); $$ = constraints; } - | type_parameter_constraints COMMA type_parameter_constraint { - ArrayList constraints = (ArrayList) $1; + | type_parameter_constraints COMMA type_parameter_constraint + { + var constraints = (List) $1; + var prev = constraints [constraints.Count - 1] as SpecialContraintExpr; + if (prev != null && (prev.Constraint & SpecialConstraint.Constructor) != 0) { + Report.Error (401, GetLocation ($2), "The `new()' constraint must be the last constraint specified"); + } + + prev = $3 as SpecialContraintExpr; + if (prev != null) { + if ((prev.Constraint & (SpecialConstraint.Class | SpecialConstraint.Struct)) != 0) { + Report.Error (449, prev.Location, "The `class' or `struct' constraint must be the first constraint specified"); + } else { + prev = constraints [0] as SpecialContraintExpr; + if (prev != null && (prev.Constraint & SpecialConstraint.Struct) != 0) { + Report.Error (451, GetLocation ($3), "The `new()' constraint cannot be used with the `struct' constraint"); + } + } + } - constraints.Add ($3); + constraints.Add ((FullNamedExpression) $3); $$ = constraints; } ; type_parameter_constraint : type - | NEW OPEN_PARENS CLOSE_PARENS { - $$ = SpecialConstraint.Constructor; + { + if ($1 is ComposedCast) + Report.Error (706, GetLocation ($1), "Invalid constraint type `{0}'", ((ComposedCast)$1).GetSignatureForError ()); + + $$ = $1; + } + | NEW OPEN_PARENS CLOSE_PARENS + { + $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1)); } - | CLASS { - $$ = SpecialConstraint.ReferenceType; + | CLASS + { + $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1)); } - | STRUCT { - $$ = SpecialConstraint.ValueType; + | STRUCT + { + $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1)); } ; @@ -4331,19 +4412,19 @@ block : OPEN_BRACE { ++lexer.parsing_block; - start_block ((Location) $1); + start_block (GetLocation ($1)); } opt_statement_list block_end { $$ = $4; - } + } ; block_end : CLOSE_BRACE { --lexer.parsing_block; - $$ = end_block ((Location) $1); + $$ = end_block (GetLocation ($1)); } | COMPLETE_COMPLETION { @@ -4362,7 +4443,7 @@ block_prepared opt_statement_list CLOSE_BRACE { --lexer.parsing_block; - $$ = end_block ((Location) $4); + $$ = end_block (GetLocation ($4)); } ; @@ -4466,14 +4547,14 @@ embedded_statement empty_statement : SEMICOLON { - $$ = EmptyStatement.Value; + $$ = new EmptyStatement (GetLocation ($1)); } ; labeled_statement : IDENTIFIER COLON { - LocatedToken lt = (LocatedToken) $1; + var lt = (Tokenizer.LocatedToken) $1; LabeledStatement labeled = new LabeledStatement (lt.Value, lt.Location); if (current_block.AddLabel (labeled)) @@ -4485,22 +4566,18 @@ labeled_statement declaration_statement : local_variable_declaration SEMICOLON { - current_array_type = null; if ($1 != null){ - DictionaryEntry de = (DictionaryEntry) $1; - Expression e = (Expression) de.Key; - - $$ = declare_local_variables (e, (ArrayList) de.Value, e.Location); + var de = (Tuple>) $1; + $$ = declare_local_variables (de.Item1, de.Item2, de.Item1.Location); } } | local_constant_declaration SEMICOLON { - current_array_type = null; if ($1 != null){ - DictionaryEntry de = (DictionaryEntry) $1; + var de = (Tuple>) $1; - $$ = declare_local_constants ((Expression) de.Key, (ArrayList) de.Value); + $$ = declare_local_constants (de.Item1, de.Item2); } } ; @@ -4542,8 +4619,8 @@ variable_type // if (rank_or_nullable.Length == 0) { SimpleName sn = expr as SimpleName; - if (sn != null && sn.Name == "var" && RootContext.Version > LanguageVersion.ISO_2) - $$ = current_array_type = new VarExpr (sn.Location); + if (sn != null && sn.Name == "var") + $$ = new VarExpr (sn.Location); else $$ = $1; } else { @@ -4559,11 +4636,11 @@ variable_type if ((string) $2 == "") $$ = $1; else - $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, (string) $2, lexer.Location); + $$ = new ComposedCast ((FullNamedExpression) $1, (string) $2, lexer.Location); } | VOID opt_rank_specifier { - Expression.Error_VoidInvalidInTheContext (lexer.Location); + Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report); $$ = TypeManager.system_void_expr; } ; @@ -4586,7 +4663,7 @@ local_variable_pointer_type } | VOID STAR { - $$ = new ComposedCast (TypeManager.system_void_expr, "*", (Location) $1); + $$ = new ComposedCast (TypeManager.system_void_expr, "*", GetLocation ($1)); } | local_variable_pointer_type STAR { @@ -4604,7 +4681,7 @@ local_variable_type if (rank == "") $$ = $1; else - $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank); + $$ = new ComposedCast ((FullNamedExpression) $1, rank); } else { $$ = null; } @@ -4616,10 +4693,14 @@ local_variable_declaration { if ($1 != null) { VarExpr ve = $1 as VarExpr; - if (ve != null) - ve.VariableInitializer = (ArrayList)$2; + if (ve != null) { + if (!((VariableDeclaration) ((List)$2) [0]).HasInitializer) + ve.VariableInitializersCount = 0; + else + ve.VariableInitializersCount = ((List)$2).Count; + } - $$ = new DictionaryEntry ($1, $2); + $$ = new Tuple> ((FullNamedExpression) $1, (List) $2); } else $$ = null; } @@ -4629,7 +4710,7 @@ local_constant_declaration : CONST variable_type constant_declarators { if ($2 != null) - $$ = new DictionaryEntry ($2, $3); + $$ = new Tuple> ((FullNamedExpression) $2, (List) $3); else $$ = null; } @@ -4654,7 +4735,7 @@ statement_expression { ExpressionStatement s = $1 as ExpressionStatement; if (s == null) { - ((Expression) $1).Error_InvalidExpressionStatement (); + Expression.Error_InvalidExpressionStatement (Report, GetLocation ($1)); s = EmptyExpressionStatement.Instance; } @@ -4679,7 +4760,7 @@ interactive_statement_expression | error { Error_SyntaxError (yyToken); - $$ = null; + $$ = new EmptyStatement (GetLocation ($1)); } ; @@ -4692,27 +4773,20 @@ if_statement : IF open_parens_any boolean_expression CLOSE_PARENS embedded_statement { - Location l = (Location) $1; - - $$ = new If ((Expression) $3, (Statement) $5, l); - - // FIXME: location for warning should be loc property of $5. - if ($5 == EmptyStatement.Value) - Report.Warning (642, 3, l, "Possible mistaken empty statement"); - + if ($5 is EmptyStatement) + Report.Warning (642, 3, GetLocation ($5), "Possible mistaken empty statement"); + + $$ = new If ((BooleanExpression) $3, (Statement) $5, GetLocation ($1)); } | IF open_parens_any boolean_expression CLOSE_PARENS embedded_statement ELSE embedded_statement { - Location l = (Location) $1; - - $$ = new If ((Expression) $3, (Statement) $5, (Statement) $7, l); + $$ = new If ((BooleanExpression) $3, (Statement) $5, (Statement) $7, GetLocation ($1)); - // FIXME: location for warning should be loc property of $5 and $7. - if ($5 == EmptyStatement.Value) - Report.Warning (642, 3, l, "Possible mistaken empty statement"); - if ($7 == EmptyStatement.Value) - Report.Warning (642, 3, l, "Possible mistaken empty statement"); + if ($5 is EmptyStatement) + Report.Warning (642, 3, GetLocation ($5), "Possible mistaken empty statement"); + if ($7 is EmptyStatement) + Report.Warning (642, 3, GetLocation ($7), "Possible mistaken empty statement"); } ; @@ -4720,13 +4794,13 @@ switch_statement : SWITCH open_parens_any { if (switch_stack == null) - switch_stack = new Stack (2); + switch_stack = new Stack (2); switch_stack.Push (current_block); } expression CLOSE_PARENS switch_block { - $$ = new Switch ((Expression) $4, (ArrayList) $6, (Location) $1); + $$ = new Switch ((Expression) $4, (List) $6, GetLocation ($1)); current_block = (Block) switch_stack.Pop (); } ; @@ -4744,7 +4818,7 @@ opt_switch_sections : /* empty */ { Report.Warning (1522, 1, lexer.Location, "Empty switch block"); - $$ = new ArrayList (); + $$ = new List (); } | switch_sections ; @@ -4752,16 +4826,16 @@ opt_switch_sections switch_sections : switch_section { - ArrayList sections = new ArrayList (4); + var sections = new List (4); - sections.Add ($1); + sections.Add ((SwitchSection) $1); $$ = sections; } | switch_sections switch_section { - ArrayList sections = (ArrayList) $1; + var sections = (List) $1; - sections.Add ($2); + sections.Add ((SwitchSection) $2); $$ = sections; } ; @@ -4773,22 +4847,22 @@ switch_section } statement_list { - $$ = new SwitchSection ((ArrayList) $1, current_block.Explicit); + $$ = new SwitchSection ((List) $1, current_block.Explicit); } ; switch_labels : switch_label { - ArrayList labels = new ArrayList (4); + var labels = new List (4); - labels.Add ($1); + labels.Add ((SwitchLabel) $1); $$ = labels; } | switch_labels switch_label { - ArrayList labels = (ArrayList) ($1); - labels.Add ($2); + var labels = (List) ($1); + labels.Add ((SwitchLabel) $2); $$ = labels; } @@ -4797,11 +4871,11 @@ switch_labels switch_label : CASE constant_expression COLON { - $$ = new SwitchLabel ((Expression) $2, (Location) $1); + $$ = new SwitchLabel ((Expression) $2, GetLocation ($1)); } | DEFAULT_COLON { - $$ = new SwitchLabel (null, (Location) $1); + $$ = new SwitchLabel (null, GetLocation ($1)); } ; @@ -4815,8 +4889,8 @@ iteration_statement while_statement : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement { - Location l = (Location) $1; - $$ = new While ((Expression) $3, (Statement) $5, l); + Location l = GetLocation ($1); + $$ = new While ((BooleanExpression) $3, (Statement) $5, l); } ; @@ -4824,9 +4898,9 @@ do_statement : DO embedded_statement WHILE open_parens_any boolean_expression CLOSE_PARENS SEMICOLON { - Location l = (Location) $1; + Location l = GetLocation ($1); - $$ = new Do ((Statement) $2, (Expression) $5, l); + $$ = new Do ((Statement) $2, (BooleanExpression) $5, l); } ; @@ -4837,13 +4911,12 @@ for_statement start_block (l); Block assign_block = current_block; - if ($3 is DictionaryEntry){ - DictionaryEntry de = (DictionaryEntry) $3; + if ($3 is Tuple>){ + var de = (Tuple>) $3; - Expression type = (Expression) de.Key; - ArrayList var_declarators = (ArrayList) de.Value; + var type = de.Item1; - foreach (VariableDeclaration decl in var_declarators){ + foreach (VariableDeclaration decl in de.Item2){ LocalInfo vi; @@ -4851,7 +4924,7 @@ for_statement if (vi == null) continue; - Expression expr = decl.expression_or_array_initializer; + Expression expr = decl.GetInitializer (type); LocalVariableReference var; var = new LocalVariableReference (assign_block, decl.identifier, l); @@ -4874,9 +4947,9 @@ for_statement opt_for_iterator CLOSE_PARENS embedded_statement { - Location l = (Location) $1; + Location l = GetLocation ($1); - For f = new For ((Statement) $5, (Expression) $6, (Statement) $8, (Statement) $10, l); + For f = new For ((Statement) $5, (BooleanExpression) $6, (Statement) $8, (Statement) $10, l); current_block.AddStatement (f); @@ -4885,7 +4958,7 @@ for_statement ; opt_for_initializer - : /* empty */ { $$ = EmptyStatement.Value; } + : /* empty */ { $$ = new EmptyStatement (lexer.Location); } | for_initializer ; @@ -4900,7 +4973,7 @@ opt_for_condition ; opt_for_iterator - : /* empty */ { $$ = EmptyStatement.Value; } + : /* empty */ { $$ = new EmptyStatement (lexer.Location); } | for_iterator ; @@ -4930,7 +5003,7 @@ statement_expression_list foreach_statement : FOREACH open_parens_any type IN expression CLOSE_PARENS { - Report.Error (230, (Location) $1, "Type and identifier are both required in a foreach statement"); + Report.Error (230, GetLocation ($1), "Type and identifier are both required in a foreach statement"); $$ = null; } | FOREACH open_parens_any type IDENTIFIER IN @@ -4939,7 +5012,7 @@ foreach_statement start_block (lexer.Location); Block foreach_block = current_block; - LocatedToken lt = (LocatedToken) $4; + var lt = (Tokenizer.LocatedToken) $4; Location l = lt.Location; LocalInfo vi = foreach_block.AddVariable ((Expression) $3, lt.Value, l); if (vi != null) { @@ -4957,7 +5030,7 @@ foreach_statement embedded_statement { LocalVariableReference v = (LocalVariableReference) $8; - Location l = (Location) $1; + Location l = GetLocation ($1); if (v != null) { Foreach f = new Foreach ((Expression) $3, v, (Expression) $6, (Statement) $9, l); @@ -4980,51 +5053,51 @@ jump_statement break_statement : BREAK SEMICOLON { - $$ = new Break ((Location) $1); + $$ = new Break (GetLocation ($1)); } ; continue_statement : CONTINUE SEMICOLON { - $$ = new Continue ((Location) $1); + $$ = new Continue (GetLocation ($1)); } ; goto_statement : GOTO IDENTIFIER SEMICOLON { - LocatedToken lt = (LocatedToken) $2; + var lt = (Tokenizer.LocatedToken) $2; $$ = new Goto (lt.Value, lt.Location); } | GOTO CASE constant_expression SEMICOLON { - $$ = new GotoCase ((Expression) $3, (Location) $1); + $$ = new GotoCase ((Expression) $3, GetLocation ($1)); } | GOTO DEFAULT SEMICOLON { - $$ = new GotoDefault ((Location) $1); + $$ = new GotoDefault (GetLocation ($1)); } ; return_statement : RETURN opt_expression SEMICOLON { - $$ = new Return ((Expression) $2, (Location) $1); + $$ = new Return ((Expression) $2, GetLocation ($1)); } ; throw_statement : THROW opt_expression SEMICOLON { - $$ = new Throw ((Expression) $2, (Location) $1); + $$ = new Throw ((Expression) $2, GetLocation ($1)); } ; yield_statement : IDENTIFIER RETURN expression SEMICOLON { - LocatedToken lt = (LocatedToken) $1; + var lt = (Tokenizer.LocatedToken) $1; string s = lt.Value; if (s != "yield"){ Report.Error (1003, lt.Location, "; expected"); @@ -5039,12 +5112,12 @@ yield_statement } | IDENTIFIER RETURN SEMICOLON { - Report.Error (1627, (Location) $2, "Expression expected after yield return"); + Report.Error (1627, GetLocation ($2), "Expression expected after yield return"); $$ = null; } | IDENTIFIER BREAK SEMICOLON { - LocatedToken lt = (LocatedToken) $1; + var lt = (Tokenizer.LocatedToken) $1; string s = lt.Value; if (s != "yield"){ Report.Error (1003, lt.Location, "; expected"); @@ -5068,19 +5141,19 @@ opt_expression try_statement : TRY block catch_clauses { - $$ = new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, false); + $$ = new TryCatch ((Block) $2, (List) $3, GetLocation ($1), false); } | TRY block FINALLY block { - $$ = new TryFinally ((Statement) $2, (Block) $4, (Location) $1); + $$ = new TryFinally ((Statement) $2, (Block) $4, GetLocation ($1)); } | TRY block catch_clauses FINALLY block { - $$ = new TryFinally (new TryCatch ((Block) $2, (ArrayList) $3, (Location) $1, true), (Block) $5, (Location) $1); + $$ = new TryFinally (new TryCatch ((Block) $2, (List) $3, GetLocation ($1), true), (Block) $5, GetLocation ($1)); } | TRY block error { - Report.Error (1524, (Location) $1, "Expected catch or finally"); + Report.Error (1524, GetLocation ($1), "Expected catch or finally"); $$ = null; } ; @@ -5088,16 +5161,25 @@ try_statement catch_clauses : catch_clause { - ArrayList l = new ArrayList (4); + var l = new List (2); - l.Add ($1); + l.Add ((Catch) $1); $$ = l; } | catch_clauses catch_clause { - ArrayList l = (ArrayList) $1; - - l.Add ($2); + var l = (List) $1; + + Catch c = (Catch) $2; + if (l [0].IsGeneral) { + Report.Error (1017, c.loc, "Try statement already has an empty catch block"); + } else { + if (c.IsGeneral) + l.Insert (0, c); + else + l.Add (c); + } + $$ = l; } ; @@ -5110,20 +5192,17 @@ opt_identifier catch_clause : CATCH opt_catch_args { - Expression type = null; - if ($2 != null) { - DictionaryEntry cc = (DictionaryEntry) $2; - type = (Expression) cc.Key; - LocatedToken lt = (LocatedToken) cc.Value; + var cc = (Tuple) $2; + var lt = cc.Item2; if (lt != null){ - ArrayList one = new ArrayList (4); + List one = new List (1); one.Add (new VariableDeclaration (lt, null)); start_block (lexer.Location); - current_block = declare_local_variables (type, one, lt.Location); + current_block = declare_local_variables (cc.Item1, one, lt.Location); } } } block { @@ -5132,9 +5211,9 @@ catch_clause Block var_block = null; if ($2 != null){ - DictionaryEntry cc = (DictionaryEntry) $2; - type = (Expression) cc.Key; - LocatedToken lt = (LocatedToken) cc.Value; + var cc = (Tuple) $2; + type = cc.Item1; + var lt = cc.Item2; if (lt != null){ id = lt.Value; @@ -5154,11 +5233,12 @@ opt_catch_args catch_args : open_parens_any type opt_identifier CLOSE_PARENS { - $$ = new DictionaryEntry ($2, $3); + $$ = new Tuple ((FullNamedExpression)$2, (Tokenizer.LocatedToken) $3); } | open_parens_any CLOSE_PARENS { Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected"); + $$ = null; } ; @@ -5179,7 +5259,7 @@ unchecked_statement unsafe_statement : UNSAFE { - RootContext.CheckUnsafeOption ((Location) $1); + RootContext.CheckUnsafeOption (GetLocation ($1), Report); } block { $$ = new Unsafe ((Block) $3); } @@ -5190,32 +5270,21 @@ fixed_statement type_and_void fixed_pointer_declarators CLOSE_PARENS { - ArrayList list = (ArrayList) $4; - Expression type = (Expression) $3; - Location l = (Location) $1; - int top = list.Count; - start_block (lexer.Location); - - for (int i = 0; i < top; i++){ - Pair p = (Pair) list [i]; - LocalInfo v; - - v = current_block.AddVariable (type, (string) p.First, l); - if (v == null) - continue; - - v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed); - v.Pinned = true; - p.First = v; - list [i] = p; - } } embedded_statement { - Location l = (Location) $1; - - Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l); + Expression type = (Expression) $3; + var list = (List>) $4; + Fixed f = new Fixed (type, + list.ConvertAll (i => { + var v = new KeyValuePair (current_block.AddVariable (type, i.Key.Value, i.Key.Location), i.Value); + if (v.Key != null) { + v.Key.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed); + v.Key.Pinned = true; + } + return v; + }), (Statement) $7, GetLocation ($1)); current_block.AddStatement (f); @@ -5225,16 +5294,16 @@ fixed_statement fixed_pointer_declarators : fixed_pointer_declarator { - ArrayList declarators = new ArrayList (4); + var declarators = new List> (2); if ($1 != null) - declarators.Add ($1); + declarators.Add ((KeyValuePair)$1); $$ = declarators; } | fixed_pointer_declarators COMMA fixed_pointer_declarator { - ArrayList declarators = (ArrayList) $1; + var declarators = (List>) $1; if ($3 != null) - declarators.Add ($3); + declarators.Add ((KeyValuePair)$3); $$ = declarators; } ; @@ -5242,13 +5311,12 @@ fixed_pointer_declarators fixed_pointer_declarator : IDENTIFIER ASSIGN expression { - LocatedToken lt = (LocatedToken) $1; - // FIXME: keep location - $$ = new Pair (lt.Value, $3); + var lt = (Tokenizer.LocatedToken) $1; + $$ = new KeyValuePair (lt, (Expression) $3); } | IDENTIFIER { - Report.Error (210, ((LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration"); + Report.Error (210, ((Tokenizer.LocatedToken) $1).Location, "You must provide an initializer in a fixed or using statement declaration"); $$ = null; } ; @@ -5260,7 +5328,7 @@ lock_statement } embedded_statement { - $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1); + $$ = new Lock ((Expression) $3, (Statement) $6, GetLocation ($1)); } ; @@ -5270,21 +5338,18 @@ using_statement start_block (lexer.Location); Block assign_block = current_block; - DictionaryEntry de = (DictionaryEntry) $3; - Location l = (Location) $1; - - Expression type = (Expression) de.Key; - ArrayList var_declarators = (ArrayList) de.Value; + var de = (Tuple>) $3; + Location l = GetLocation ($1); - Stack vars = new Stack (); + var vars = new Stack> (); - foreach (VariableDeclaration decl in var_declarators) { - LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location); + foreach (VariableDeclaration decl in de.Item2) { + LocalInfo vi = current_block.AddVariable (de.Item1, decl.identifier, decl.Location); if (vi == null) continue; vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using); - Expression expr = decl.expression_or_array_initializer; + Expression expr = decl.GetInitializer (de.Item1); if (expr == null) { Report.Error (210, l, "You must provide an initializer in a fixed or using statement declaration"); continue; @@ -5297,7 +5362,7 @@ using_statement // This is so that it is not a warning on using variables vi.Used = true; - vars.Push (new DictionaryEntry (var, expr)); + vars.Push (new Tuple (var, expr)); // Assign a = new SimpleAssign (var, expr, decl.Location); // assign_block.AddStatement (new StatementExpression (a)); @@ -5310,12 +5375,12 @@ using_statement embedded_statement { Statement stmt = (Statement) $6; - Stack vars = (Stack) $5; - Location l = (Location) $1; + var vars = (Stack>) $5; + Location l = GetLocation ($1); while (vars.Count > 0) { - DictionaryEntry de = (DictionaryEntry) vars.Pop (); - stmt = new Using ((Expression) de.Key, (Expression) de.Value, stmt, l); + var de = vars.Pop (); + stmt = new Using (de.Item1, de.Item2, stmt, l); } current_block.AddStatement (stmt); $$ = end_block (lexer.Location); @@ -5326,7 +5391,7 @@ using_statement } embedded_statement { - current_block.AddStatement (new UsingTemporary ((Expression) $3, (Statement) $6, (Location) $1)); + current_block.AddStatement (new UsingTemporary ((Expression) $3, (Statement) $6, GetLocation ($1))); $$ = end_block (lexer.Location); } ; @@ -5335,7 +5400,7 @@ using_statement // LINQ query_expression - : first_from_clause query_body + : first_from_clause query_body { lexer.query_parsing = false; @@ -5357,18 +5422,34 @@ query_expression current_block.SetEndLocation (lexer.Location); current_block = current_block.Parent; } + + // Bubble up COMPLETE_COMPLETION productions + | first_from_clause COMPLETE_COMPLETION { + lexer.query_parsing = false; + $$ = $1; + + current_block.SetEndLocation (lexer.Location); + current_block = current_block.Parent; + } + | nested_from_clause COMPLETE_COMPLETION { + $$ = $1; + current_block.SetEndLocation (lexer.Location); + current_block = current_block.Parent; + } ; first_from_clause : FROM_FIRST IDENTIFIER IN expression { $$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4)); - current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1)); + var lt = (Tokenizer.LocatedToken) $2; + current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)); } | FROM_FIRST type IDENTIFIER IN expression { + var lt = (Tokenizer.LocatedToken) $3; $$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5)); - current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, GetLocation ($1)); + current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)); } ; @@ -5376,50 +5457,55 @@ nested_from_clause : FROM IDENTIFIER IN expression { $$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4)); - current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1)); + var lt = (Tokenizer.LocatedToken) $2; + current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)); } | FROM type IDENTIFIER IN expression { $$ = new Linq.QueryExpression (current_block, new Linq.Cast ((FullNamedExpression)$2, (Expression)$5)); - current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, GetLocation ($1)); + var lt = (Tokenizer.LocatedToken) $3; + current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)); } ; from_clause : FROM IDENTIFIER IN { - current_block = new Linq.QueryBlock (current_block, GetLocation ($1)); + current_block = new Linq.QueryBlock (compiler, current_block, GetLocation ($1)); } expression { - LocatedToken lt = (LocatedToken) $2; - $$ = new Linq.SelectMany (current_block.Toplevel, lt, (Expression)$5); + var lt = (Tokenizer.LocatedToken) $2; + var sn = new SimpleMemberName (lt.Value, lt.Location); + $$ = new Linq.SelectMany (current_block.Toplevel, sn, (Expression)$5); current_block.SetEndLocation (lexer.Location); current_block = current_block.Parent; - ((Linq.QueryBlock)current_block).AddTransparentParameter (lt); + ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn); } | FROM type IDENTIFIER IN { - current_block = new Linq.QueryBlock (current_block, GetLocation ($1)); + current_block = new Linq.QueryBlock (compiler, current_block, GetLocation ($1)); } expression { - LocatedToken lt = (LocatedToken) $3; + var lt = (Tokenizer.LocatedToken) $3; + var sn = new SimpleMemberName (lt.Value, lt.Location); + FullNamedExpression type = (FullNamedExpression)$2; - $$ = new Linq.SelectMany (current_block.Toplevel, lt, new Linq.Cast (type, (FullNamedExpression)$6)); + $$ = new Linq.SelectMany (current_block.Toplevel, sn, new Linq.Cast (type, (FullNamedExpression)$6)); current_block.SetEndLocation (lexer.Location); current_block = current_block.Parent; - ((Linq.QueryBlock)current_block).AddTransparentParameter (lt); + ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn); } ; query_body - : opt_query_body_clauses select_or_group_clause opt_query_continuation + : opt_query_body_clauses select_or_group_clause opt_query_continuation { Linq.AQueryClause head = (Linq.AQueryClause)$2; @@ -5434,12 +5520,13 @@ query_body $$ = head; } + | opt_query_body_clauses COMPLETE_COMPLETION ; select_or_group_clause : SELECT { - current_block = new Linq.QueryBlock (current_block, lexer.Location); + current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location); } expression { @@ -5451,9 +5538,9 @@ select_or_group_clause | GROUP { if (linq_clause_blocks == null) - linq_clause_blocks = new Stack (); + linq_clause_blocks = new Stack (); - current_block = new Linq.QueryBlock (current_block, lexer.Location); + current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location); linq_clause_blocks.Push (current_block); } expression @@ -5461,7 +5548,7 @@ select_or_group_clause current_block.SetEndLocation (lexer.Location); current_block = current_block.Parent; - current_block = new Linq.QueryBlock (current_block, lexer.Location); + current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location); } BY expression { @@ -5488,7 +5575,7 @@ query_body_clauses query_body_clause : from_clause - | let_clause + | let_clause | where_clause | join_clause | orderby_clause @@ -5497,28 +5584,29 @@ query_body_clause let_clause : LET IDENTIFIER ASSIGN { - current_block = new Linq.QueryBlock (current_block, GetLocation ($1)); + current_block = new Linq.QueryBlock (compiler, current_block, GetLocation ($1)); } expression { - LocatedToken lt = (LocatedToken) $2; - $$ = new Linq.Let (current_block.Toplevel, current_container, lt, (Expression)$5); + var lt = (Tokenizer.LocatedToken) $2; + var sn = new SimpleMemberName (lt.Value, lt.Location); + $$ = new Linq.Let (current_block.Toplevel, current_container, sn, (Expression)$5); current_block.SetEndLocation (lexer.Location); current_block = current_block.Parent; - ((Linq.QueryBlock)current_block).AddTransparentParameter (lt); + ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn); } ; where_clause : WHERE { - current_block = new Linq.QueryBlock (current_block, lexer.Location); + current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location); } boolean_expression { - $$ = new Linq.Where (current_block.Toplevel, (Expression)$3, GetLocation ($1)); + $$ = new Linq.Where (current_block.Toplevel, (BooleanExpression)$3, GetLocation ($1)); current_block.SetEndLocation (lexer.Location); current_block = current_block.Parent; @@ -5529,9 +5617,9 @@ join_clause : JOIN IDENTIFIER IN { if (linq_clause_blocks == null) - linq_clause_blocks = new Stack (); + linq_clause_blocks = new Stack (); - current_block = new Linq.QueryBlock (current_block, lexer.Location); + current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location); linq_clause_blocks.Push (current_block); } expression ON @@ -5539,7 +5627,7 @@ join_clause current_block.SetEndLocation (lexer.Location); current_block = current_block.Parent; - current_block = new Linq.QueryBlock (current_block, lexer.Location); + current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location); linq_clause_blocks.Push (current_block); } expression EQUALS @@ -5548,37 +5636,42 @@ join_clause current_block.SetEndLocation (lexer.Location); current_block = current_block.Parent; - current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, lexer.Location); + var lt = (Tokenizer.LocatedToken) $2; + current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), lexer.Location); } expression opt_join_into { - LocatedToken lt = (LocatedToken) $2; + var lt = (Tokenizer.LocatedToken) $2; + var sn = new SimpleMemberName (lt.Value, lt.Location); + SimpleMemberName sn2 = null; ToplevelBlock outer_selector = (ToplevelBlock) linq_clause_blocks.Pop (); ToplevelBlock block = (ToplevelBlock) linq_clause_blocks.Pop (); if ($12 == null) { - $$ = new Linq.Join (block, lt, (Expression)$5, outer_selector, current_block.Toplevel, GetLocation ($1)); + $$ = new Linq.Join (block, sn, (Expression)$5, outer_selector, current_block.Toplevel, GetLocation ($1)); } else { - $$ = new Linq.GroupJoin (block, lt, (Expression)$5, outer_selector, current_block.Toplevel, - (LocatedToken) $12, GetLocation ($1)); + var lt2 = (Tokenizer.LocatedToken) $12; + sn2 = new SimpleMemberName (lt2.Value, lt2.Location); + $$ = new Linq.GroupJoin (block, sn, (Expression)$5, outer_selector, current_block.Toplevel, + sn2, GetLocation ($1)); } current_block.AddStatement (new ContextualReturn ((Expression) $11)); current_block.SetEndLocation (lexer.Location); current_block = current_block.Parent; - if ($12 == null) - ((Linq.QueryBlock)current_block).AddTransparentParameter (lt); + if (sn2 == null) + ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn); else - ((Linq.QueryBlock)current_block).AddTransparentParameter ((LocatedToken) $12); + ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn2); } | JOIN type IDENTIFIER IN { if (linq_clause_blocks == null) - linq_clause_blocks = new Stack (); + linq_clause_blocks = new Stack (); - current_block = new Linq.QueryBlock (current_block, lexer.Location); + current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location); linq_clause_blocks.Push (current_block); } expression ON @@ -5586,7 +5679,7 @@ join_clause current_block.SetEndLocation (lexer.Location); current_block = current_block.Parent; - current_block = new Linq.QueryBlock (current_block, lexer.Location); + current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location); linq_clause_blocks.Push (current_block); } expression EQUALS @@ -5595,30 +5688,35 @@ join_clause current_block.SetEndLocation (lexer.Location); current_block = current_block.Parent; - current_block = new Linq.QueryBlock (current_block, (LocatedToken) $3, lexer.Location); + var lt = (Tokenizer.LocatedToken) $3; + current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), lexer.Location); } expression opt_join_into { - LocatedToken lt = (LocatedToken) $3; + var lt = (Tokenizer.LocatedToken) $3; + var sn = new SimpleMemberName (lt.Value, lt.Location); + SimpleMemberName sn2 = null; ToplevelBlock outer_selector = (ToplevelBlock) linq_clause_blocks.Pop (); ToplevelBlock block = (ToplevelBlock) linq_clause_blocks.Pop (); Linq.Cast cast = new Linq.Cast ((FullNamedExpression)$2, (Expression)$6); if ($13 == null) { - $$ = new Linq.Join (block, lt, cast, outer_selector, current_block.Toplevel, GetLocation ($1)); + $$ = new Linq.Join (block, sn, cast, outer_selector, current_block.Toplevel, GetLocation ($1)); } else { - $$ = new Linq.GroupJoin (block, lt, cast, outer_selector, current_block.Toplevel, - (LocatedToken) $13, GetLocation ($1)); + var lt2 = (Tokenizer.LocatedToken) $13; + sn2 = new SimpleMemberName (lt2.Value, lt2.Location); + $$ = new Linq.GroupJoin (block, sn, cast, outer_selector, current_block.Toplevel, + sn2, GetLocation ($1)); } current_block.AddStatement (new ContextualReturn ((Expression) $12)); current_block.SetEndLocation (lexer.Location); current_block = current_block.Parent; - if ($13 == null) - ((Linq.QueryBlock)current_block).AddTransparentParameter (lt); + if (sn2 == null) + ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn); else - ((Linq.QueryBlock)current_block).AddTransparentParameter ((LocatedToken) $13); + ((Linq.QueryBlock)current_block).AddTransparentParameter (compiler, sn2); } ; @@ -5633,7 +5731,7 @@ opt_join_into orderby_clause : ORDERBY { - current_block = new Linq.QueryBlock (current_block, lexer.Location); + current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location); } orderings { @@ -5651,7 +5749,7 @@ orderings current_block.SetEndLocation (lexer.Location); current_block = current_block.Parent; - current_block = new Linq.QueryBlock (current_block, lexer.Location); + current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location); } orderings_then_by { @@ -5667,7 +5765,7 @@ orderings_then_by current_block.SetEndLocation (lexer.Location); current_block = current_block.Parent; - current_block = new Linq.QueryBlock (current_block, lexer.Location); + current_block = new Linq.QueryBlock (compiler, current_block, lexer.Location); } then_by { @@ -5717,8 +5815,10 @@ opt_query_continuation current_block.SetEndLocation (GetLocation ($1)); current_block = current_block.Parent; + + var lt = (Tokenizer.LocatedToken) $2; - current_block = new Linq.QueryBlock (current_block, (LocatedToken) $2, GetLocation ($1)); + current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)); } query_body { @@ -5748,7 +5848,7 @@ interactive_parsing push_current_class (new Class (current_namespace, current_class, new MemberName ("Class" + class_count++), Modifiers.PUBLIC, null), null); - ArrayList baseclass_list = new ArrayList (); + var baseclass_list = new List (); baseclass_list.Add (new TypeExpression (Evaluator.InteractiveBaseClass, lexer.Location)); current_container.AddBasesForPart (current_class, baseclass_list); @@ -5756,7 +5856,7 @@ interactive_parsing Parameter [] mpar = new Parameter [1]; mpar [0] = new Parameter (TypeManager.system_object_expr, "$retval", Parameter.Modifier.REF, null, Location.Null); - ParametersCompiled pars = new ParametersCompiled (mpar); + ParametersCompiled pars = new ParametersCompiled (compiler, mpar); current_local_parameters = pars; Method method = new Method ( current_class, @@ -5810,44 +5910,56 @@ close_brace_or_complete_completion // // A class used to pass around variable declarations and constants // -public class VariableDeclaration { +class VariableDeclaration { public string identifier; - public Expression expression_or_array_initializer; + Expression initializer; public Location Location; public Attributes OptAttributes; public string DocComment; - public VariableDeclaration (LocatedToken lt, object eoai, Attributes opt_attrs) + public VariableDeclaration (Tokenizer.LocatedToken lt, Expression initializer, Attributes opt_attrs) { this.identifier = lt.Value; - if (eoai is ArrayList) { - this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)eoai, lt.Location); - } else { - this.expression_or_array_initializer = (Expression)eoai; - } + this.initializer = initializer; this.Location = lt.Location; this.OptAttributes = opt_attrs; } - public VariableDeclaration (LocatedToken lt, object eoai) : this (lt, eoai, null) + public VariableDeclaration (Tokenizer.LocatedToken lt, Expression initializer) + : this (lt, initializer, null) { } + + public Expression GetInitializer (FullNamedExpression type) + { + if (initializer is ArrayInitializer) + return new ArrayCreation (type, "", (ArrayInitializer)initializer, Location); + + return initializer; + } + + public bool HasInitializer { + get { return initializer != null; } + } } class VariableMemberDeclaration { public readonly MemberName MemberName; - public Expression expression_or_array_initializer; + Expression initializer; - public VariableMemberDeclaration (MemberName mn, object initializer) + public VariableMemberDeclaration (MemberName mn, Expression initializer) { MemberName = mn; - - if (initializer is ArrayList) { - this.expression_or_array_initializer = new ArrayCreation (CSharpParser.current_array_type, "", (ArrayList)initializer, mn.Location); - } else { - this.expression_or_array_initializer = (Expression)initializer; - } + this.initializer = initializer; + } + + public Expression GetInitializer (FullNamedExpression type) + { + if (initializer is ArrayInitializer) + return new ArrayCreation (type, "", (ArrayInitializer)initializer, MemberName.Location); + + return initializer; } } @@ -5873,27 +5985,32 @@ void Error_ExpectingTypeName (Expression expr) if (expr is Invocation){ Report.Error (1002, expr.Location, "Expecting `;'"); } else { - expr.Error_InvalidExpressionStatement (); + Expression.Error_InvalidExpressionStatement (Report, expr.Location); } } -static void Error_ParameterModifierNotValid (string modifier, Location loc) +void Error_ParameterModifierNotValid (string modifier, Location loc) { Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context", modifier); } -static void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod) +void Error_DuplicateParameterModifier (Location loc, Parameter.Modifier mod) { Report.Error (1107, loc, "Duplicate parameter modifier `{0}'", Parameter.GetModifierSignature (mod)); } -static void Error_TypeExpected (Location loc) +void Error_TypeExpected (Location loc) { Report.Error (1031, loc, "Type expected"); } +void Error_NamedArgumentExpected (NamedArgument a) +{ + Report.Error (1738, a.Location, "Named arguments must appear after the positional arguments"); +} + void push_current_class (TypeContainer tc, object partial_token) { if (RootContext.EvalMode){ @@ -5939,10 +6056,9 @@ MakeName (MemberName class_name) } } -Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc) +Block declare_local_variables (FullNamedExpression type, List variable_declarators, Location loc) { Block implicit_block; - ArrayList inits = null; // // If we are doing interactive editing, we want variable declarations @@ -5966,13 +6082,17 @@ Block declare_local_variables (Expression type, ArrayList variable_declarators, foreach (VariableDeclaration decl in variable_declarators){ // We can not use the super-handy f.Initializer, because // multiple lines would force code to be executed out of sync - if (decl.expression_or_array_initializer != null){ + var init = decl.GetInitializer (type); + if (init != null){ string id = "$" + decl.identifier; - current_block.AddVariable (type, id, decl.Location); + LocalInfo vi = current_block.AddVariable (type, id, decl.Location); + + // Avoid warning about this variable not being used. + vi.Used = true; LocalVariableReference var; - var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, decl.Location); - Assign assign = new SimpleAssign (var, decl.expression_or_array_initializer, decl.Location); + var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, vi, decl.Location); + Assign assign = new SimpleAssign (var, init, decl.Location); current_block.AddStatement (new StatementExpression (assign)); assign = new SimpleAssign (new SimpleName (decl.identifier, decl.Location), var); current_block.AddStatement (new StatementExpression (assign)); @@ -6013,33 +6133,22 @@ Block declare_local_variables (Expression type, ArrayList variable_declarators, foreach (VariableDeclaration decl in variable_declarators){ if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) { - if (decl.expression_or_array_initializer != null){ - if (inits == null) - inits = new ArrayList (4); - inits.Add (decl); - } - } - } - - if (inits == null) - return implicit_block; - - foreach (VariableDeclaration decl in inits){ - Assign assign; - Expression expr = decl.expression_or_array_initializer; - - LocalVariableReference var; - var = new LocalVariableReference (implicit_block, decl.identifier, loc); + if (decl.HasInitializer){ + Assign assign; + + var lvr = new LocalVariableReference (implicit_block, decl.identifier, loc); - assign = new SimpleAssign (var, expr, decl.Location); + assign = new SimpleAssign (lvr, decl.GetInitializer (type), decl.Location); - implicit_block.AddStatement (new StatementExpression (assign)); + implicit_block.AddStatement (new StatementExpression (assign)); + } + } } return implicit_block; } -Block declare_local_constants (Expression type, ArrayList declarators) +Block declare_local_constants (FullNamedExpression type, List declarators) { Block implicit_block; @@ -6049,7 +6158,7 @@ Block declare_local_constants (Expression type, ArrayList declarators) implicit_block = current_block; foreach (VariableDeclaration decl in declarators){ - implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location); + implicit_block.AddConstant (type, decl.identifier, decl.GetInitializer (type), decl.Location); } return implicit_block; @@ -6089,11 +6198,6 @@ void syntax_error (Location l, string msg) Report.Error (1003, l, "Syntax error, " + msg); } -void note (string s) -{ - // Used to put annotations -} - Tokenizer lexer; public Tokenizer Lexer { @@ -6104,49 +6208,55 @@ public Tokenizer Lexer { static CSharpParser () { - oob_stack = new Stack (); + oob_stack = new Stack (); } -public CSharpParser (SeekableStreamReader reader, CompilationUnit file) +public CSharpParser (SeekableStreamReader reader, CompilationUnit file, CompilerContext ctx) { if (RootContext.EvalMode) undo = new Undo (); this.file = file; + this.compiler = ctx; current_namespace = new NamespaceEntry (null, file, null); current_class = current_namespace.SlaveDeclSpace; current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes oob_stack.Clear (); - lexer = new Tokenizer (reader, file); + lexer = new Tokenizer (reader, file, ctx); + + use_global_stacks = true; } public void parse () { eof_token = Token.EOF; - + Tokenizer.LocatedToken.Initialize (); + try { if (yacc_verbose_flag > 1) yyparse (lexer, new yydebug.yyDebugSimple ()); else yyparse (lexer); + + Tokenizer tokenizer = lexer as Tokenizer; + tokenizer.cleanup (); } catch (Exception e){ if (e is yyParser.yyUnexpectedEof) UnexpectedEOF = true; - else if (yacc_verbose_flag > 0) - Console.WriteLine (e); + if (e is yyParser.yyException) Report.Error (-25, lexer.Location, "Parsing error"); + else if (yacc_verbose_flag > 0) + throw; // Used by compiler-tester to test internal errors else - Report.Error (-32, lexer.Location, "Internal compiler error during parsing, Run with -v for details"); + Report.Error (589, lexer.Location, "Internal compiler error during parsing"); } - Tokenizer tokenizer = lexer as Tokenizer; - tokenizer.cleanup (); if (RootContext.ToplevelTypes.NamespaceEntry != null) throw new InternalErrorException ("who set it?"); } -static void CheckToken (int error, int yyToken, string msg, Location loc) +void CheckToken (int error, int yyToken, string msg, Location loc) { if (yyToken >= Token.FIRST_KEYWORD && yyToken <= Token.LAST_KEYWORD) Report.Error (error, loc, "{0}: `{1}' is a keyword", msg, GetTokenName (yyToken)); @@ -6169,21 +6279,25 @@ string ConsumeStoredComment () Location GetLocation (object obj) { - if (obj is MemberCore) - return ((MemberCore) obj).Location; + if (obj is Tokenizer.LocatedToken) + return ((Tokenizer.LocatedToken) obj).Location; if (obj is MemberName) return ((MemberName) obj).Location; - if (obj is LocatedToken) - return ((LocatedToken) obj).Location; - if (obj is Location) - return (Location) obj; + +// if (obj is Expression) +// return ((Expression) obj).Location; + return lexer.Location; } +Report Report { + get { return compiler.Report; } +} + void start_block (Location loc) { if (current_block == null || parsing_anonymous_method) { - current_block = new ToplevelBlock (current_block, current_local_parameters, current_generic_method, loc); + current_block = new ToplevelBlock (compiler, current_block, current_local_parameters, current_generic_method, loc); parsing_anonymous_method = false; } else { current_block = new ExplicitBlock (current_block, loc, Location.Null); @@ -6245,10 +6359,10 @@ public NamespaceEntry CurrentNamespace { void Error_SyntaxError (int token) { - Error_SyntaxError (0, token); + Error_SyntaxError (0, token, "Unexpected symbol"); } -void Error_SyntaxError (int error_code, int token) +void Error_SyntaxError (int error_code, int token, string msg) { string symbol = GetSymbolName (token); string expecting = GetExpecting (); @@ -6261,16 +6375,16 @@ void Error_SyntaxError (int error_code, int token) } if (expecting != null) - Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}', expecting {1}", - symbol, expecting); + Report.Error (error_code, lexer.Location, "{2} `{0}', expecting {1}", + symbol, expecting, msg); else - Report.Error (error_code, lexer.Location, "Unexpected symbol `{0}'", symbol); + Report.Error (error_code, lexer.Location, "{1} `{0}'", symbol, msg); } string GetExpecting () { int [] tokens = yyExpectingTokens (yyExpectingState); - ArrayList names = new ArrayList (tokens.Length); + var names = new List (tokens.Length); bool has_type = false; bool has_identifier = false; for (int i = 0; i < tokens.Length; i++){ @@ -6309,7 +6423,7 @@ string GetExpecting () sb.Append ("or "); sb.Append ('`'); sb.Append (names [i]); - sb.Append (last ? "'" : "', "); + sb.Append (last ? "'" : count < 3 ? "' " : "', "); } return sb.ToString (); } @@ -6318,15 +6432,10 @@ string GetExpecting () string GetSymbolName (int token) { switch (token){ - case Token.LITERAL_FLOAT: - case Token.LITERAL_INTEGER: - case Token.LITERAL_DOUBLE: - case Token.LITERAL_DECIMAL: - case Token.LITERAL_CHARACTER: - case Token.LITERAL_STRING: - return lexer.Value.ToString (); + case Token.LITERAL: + return ((Constant)lexer.Value).GetValue ().ToString (); case Token.IDENTIFIER: - return ((LocatedToken)lexer.Value).Value; + return ((Tokenizer.LocatedToken)lexer.Value).Value; case Token.BOOL: return "bool"; @@ -6692,12 +6801,7 @@ static string GetTokenName (int token) return "?"; case Token.DOUBLE_COLON: return "::"; - case Token.LITERAL_FLOAT: - case Token.LITERAL_INTEGER: - case Token.LITERAL_DOUBLE: - case Token.LITERAL_DECIMAL: - case Token.LITERAL_CHARACTER: - case Token.LITERAL_STRING: + case Token.LITERAL: return "value"; case Token.IDENTIFIER: return "identifier";