X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fmcs%2Fcs-parser.jay;h=b983dacf0582917c8d058ded794924aa4803c7a8;hb=2e76d1db7ed821511fd47739ac109b6dcbbcb880;hp=f1e016c4191b275c800935c083535020345f0bbe;hpb=e8f945c6c9c3f714a3fe5f00bcf535330fa7c308;p=mono.git diff --git a/mcs/mcs/cs-parser.jay b/mcs/mcs/cs-parser.jay index f1e016c4191..b983dacf058 100644 --- a/mcs/mcs/cs-parser.jay +++ b/mcs/mcs/cs-parser.jay @@ -16,19 +16,14 @@ // 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 /// @@ -79,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 @@ -96,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 @@ -146,13 +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 @@ -327,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 @@ -419,14 +409,14 @@ 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; + lt = (Tokenizer.LocatedToken) $3; current_namespace.AddUsingExternalAlias (lt.Value, lt.Location, Report); } } @@ -457,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)); @@ -469,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)); } ; @@ -503,12 +493,12 @@ 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 @@ -667,7 +657,7 @@ 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") { @@ -698,7 +688,7 @@ 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") { @@ -749,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"; } @@ -764,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; } @@ -870,20 +856,36 @@ positional_or_named_argument named_attribute_argument : IDENTIFIER ASSIGN expression { - $$ = new NamedArgument ((LocatedToken) $1, (Expression) $3); + var lt = (Tokenizer.LocatedToken) $1; + $$ = new NamedArgument (lt.Value, lt.Location, (Expression) $3); } ; named_argument - : IDENTIFIER COLON expression + : IDENTIFIER COLON opt_named_modifier expression { if (RootContext.Version <= LanguageVersion.V_3) Report.FeatureIsNotAvailable (GetLocation ($1), "named argument"); - $$ = new NamedArgument ((LocatedToken) $1, (Expression) $3); - } - ; - + // 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 @@ -931,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 (); @@ -1003,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) { @@ -1028,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); } } @@ -1050,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; } ; @@ -1076,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 (); @@ -1102,13 +1102,14 @@ field_declaration { FullNamedExpression type = (FullNamedExpression) $4; - int mod = (int) $2; + var mod = (Modifiers) $2; - current_array_type = null; - - 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 (); @@ -1131,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; } ; @@ -1146,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); } ; @@ -1159,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; } @@ -1175,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 { @@ -1192,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; } @@ -1230,7 +1231,7 @@ variable_declarator variable_initializer { --lexer.parsing_block; - $$ = new VariableMemberDeclaration ((MemberName) $1, $4); + $$ = new VariableMemberDeclaration ((MemberName) $1, (Expression) $4); } | member_declaration_name { @@ -1268,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 ()); } @@ -1299,22 +1300,25 @@ method_header 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; @@ -1353,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) { @@ -1392,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); @@ -1419,94 +1423,77 @@ opt_formal_parameter_list 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); - - Parameter [] pars = new Parameter [pars_list.Count]; - pars_list.CopyTo (pars); + var pars_list = (List) $1; + pars_list.Add ((Parameter) $3); - $$ = 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"); - $$ = new ParametersCompiled (new Parameter[] { (Parameter) $1 } ); + $$ = 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"); - - ArrayList pars_list = (ArrayList) $1; - pars_list.Add (new ArglistParameter (GetLocation ($3))); - Parameter [] pars = new Parameter [pars_list.Count]; - pars_list.CopyTo (pars); + var pars_list = (List) $1; + pars_list.Add (new ArglistParameter (GetLocation ($3))); - $$ = new ParametersCompiled (pars, true); + $$ = 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"); + Report.Error (257, GetLocation ($1), "An __arglist parameter must be the last parameter in a formal parameter list"); - $$ = new ParametersCompiled (new Parameter [] { new ArglistParameter ((Location) $1) }, true); + $$ = 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"); - - ArrayList pars_list = (ArrayList) $1; - pars_list.Add (new ArglistParameter (GetLocation ($3))); + Report.Error (257, GetLocation ($3), "An __arglist parameter must be the last parameter in a formal parameter list"); - Parameter [] pars = new Parameter [pars_list.Count]; - pars_list.CopyTo (pars); + var pars_list = (List) $1; + pars_list.Add (new ArglistParameter (GetLocation ($3))); - $$ = new ParametersCompiled (pars, true); + $$ = 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) @@ -1527,7 +1514,7 @@ fixed_parameter 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 @@ -1535,7 +1522,7 @@ fixed_parameter 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"); $$ = new Parameter ((FullNamedExpression) $3, lt.Value, (Parameter.Modifier) $2, (Attributes) $1, lt.Location); } @@ -1582,7 +1569,7 @@ fixed_parameter 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; @@ -1626,21 +1613,21 @@ parameter_modifier : REF { if ((valid_param_mod & ParameterModifierType.Ref) == 0) - Error_ParameterModifierNotValid ("ref", (Location)$1); + Error_ParameterModifierNotValid ("ref", GetLocation ($1)); $$ = Parameter.Modifier.REF; } | OUT { if ((valid_param_mod & ParameterModifierType.Out) == 0) - Error_ParameterModifierNotValid ("out", (Location)$1); + Error_ParameterModifierNotValid ("out", GetLocation ($1)); $$ = Parameter.Modifier.OUT; } | THIS { if ((valid_param_mod & ParameterModifierType.This) == 0) - Error_ParameterModifierNotValid ("this", (Location)$1); + Error_ParameterModifierNotValid ("this", GetLocation ($1)); if (RootContext.Version <= LanguageVersion.ISO_2) Report.FeatureIsNotAvailable (GetLocation ($1), "extension methods"); @@ -1652,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 { @@ -1672,20 +1659,20 @@ params_modifier : PARAMS { if ((valid_param_mod & ParameterModifierType.Params) == 0) - Report.Error (1670, ((Location) $1), "The `params' modifier is not allowed in current context"); + 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); } ; @@ -1693,7 +1680,7 @@ arglist_modifier : ARGLIST { if ((valid_param_mod & ParameterModifierType.Arglist) == 0) - Report.Error (1669, (Location) $1, "__arglist is not valid in this context"); + Report.Error (1669, GetLocation ($1), "__arglist is not valid in this context"); } ; @@ -1727,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) @@ -1736,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 ()); @@ -1807,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; @@ -1825,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); } @@ -1842,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; @@ -1879,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 (); @@ -1962,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); @@ -1987,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; } ; @@ -2001,7 +1988,7 @@ operator_declarator { valid_param_mod = 0; - Location loc = (Location) $2; + Location loc = GetLocation ($2); Operator.OpType op = (Operator.OpType) $3; current_local_parameters = (ParametersCompiled)$6; @@ -2076,7 +2063,7 @@ conversion_operator_declarator { valid_param_mod = 0; - Location loc = (Location) $2; + Location loc = GetLocation ($2); current_local_parameters = (ParametersCompiled)$6; if (RootContext.Documentation != null) { @@ -2094,7 +2081,7 @@ conversion_operator_declarator { valid_param_mod = 0; - Location loc = (Location) $2; + Location loc = GetLocation ($2); current_local_parameters = (ParametersCompiled)$6; if (RootContext.Documentation != null) { @@ -2161,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, @@ -2171,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 ()); @@ -2206,7 +2193,7 @@ constructor_initializer opt_argument_list CLOSE_PARENS { --lexer.parsing_block; - $$ = new ConstructorBaseInitializer ((Arguments) $5, (Location) $2); + $$ = new ConstructorBaseInitializer ((Arguments) $5, GetLocation ($2)); } | COLON THIS OPEN_PARENS { @@ -2215,7 +2202,7 @@ constructor_initializer opt_argument_list CLOSE_PARENS { --lexer.parsing_block; - $$ = new ConstructorThisInitializer ((Arguments) $5, (Location) $2); + $$ = new ConstructorThisInitializer ((Arguments) $5, GetLocation ($2)); } | COLON error { Report.Error (1018, GetLocation ($1), "Keyword `this' or `base' expected"); @@ -2235,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 (); @@ -2259,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) { @@ -2293,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))); @@ -2307,11 +2290,11 @@ 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, (Location) $3, "`{0}.{1}': event property must have both add and remove accessors", + 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); } @@ -2323,7 +2306,7 @@ event_declaration $$ = null; else { Event e = new EventProperty ( - current_class, (FullNamedExpression) $4, (int) $2, name, + 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 (); @@ -2377,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; } ; @@ -2398,15 +2381,15 @@ 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; } ; @@ -2451,7 +2434,7 @@ indexer_declaration bool order = accessors != null ? accessors.declared_in_reverse : false; Indexer indexer = new Indexer (current_class, (FullNamedExpression) $3, - (MemberName)$4, (int) $2, (ParametersCompiled) $7, (Attributes) $1, + (MemberName)$4, (Modifiers) $2, (ParametersCompiled) $7, (Attributes) $1, get_block, set_block, order); if ($3 == TypeManager.system_void_expr) @@ -2460,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 ()); @@ -2496,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) @@ -2504,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) @@ -2543,7 +2526,7 @@ opt_enum_base } | COLON error { - Error_TypeExpected (lexer.Location); + Error_TypeExpected (GetLocation ($1)); $$ = TypeManager.system_int32_expr; } ; @@ -2567,24 +2550,21 @@ enum_body ; opt_enum_member_declarations - : /* empty */ { $$ = new ArrayList (0); } + : /* 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; } ; @@ -2593,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 (); @@ -2614,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 (); @@ -2640,7 +2620,7 @@ delegate_declaration 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 (); @@ -2657,7 +2637,7 @@ delegate_declaration } SEMICOLON { - current_delegate.SetParameterInfo ((ArrayList) $11); + current_delegate.SetParameterInfo ((List) $11); $$ = current_delegate; current_delegate = null; @@ -2672,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; } @@ -2684,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); } @@ -2695,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); } ; @@ -2703,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); } ; @@ -2716,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"); @@ -2755,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); } ; @@ -2775,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); } ; @@ -2796,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); } ; @@ -2818,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"); @@ -2844,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 @@ -2883,7 +2863,7 @@ type : type_expression_or_array | VOID { - Expression.Error_VoidInvalidInTheContext (lexer.Location, Report); + Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report); $$ = TypeManager.system_void_expr; } ; @@ -2892,7 +2872,7 @@ simple_type : type_expression | VOID { - Expression.Error_VoidInvalidInTheContext (lexer.Location, Report); + Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report); $$ = TypeManager.system_void_expr; } ; @@ -2901,7 +2881,7 @@ parameter_type : type_expression_or_array | VOID { - Report.Error (1536, lexer.Location, "Invalid parameter type `void'"); + Report.Error (1536, GetLocation ($1), "Invalid parameter type `void'"); $$ = TypeManager.system_void_expr; } ; @@ -2911,7 +2891,7 @@ type_expression_or_array | type_expression rank_specifiers { string rank_specifiers = (string) $2; - $$ = current_array_type = new ComposedCast ((FullNamedExpression) $1, rank_specifiers); + $$ = new ComposedCast ((FullNamedExpression) $1, rank_specifiers); } ; @@ -2924,7 +2904,7 @@ type_expression $$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location); } else { if (name.Left == null && name.Name == "var") - $$ = current_array_type = new VarExpr (name.Location); + $$ = new VarExpr (name.Location); else $$ = name.GetTypeExpression (); } @@ -2945,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; } ; @@ -2967,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; } ; @@ -3025,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 @@ -3053,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)); } ; @@ -3097,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 { @@ -3114,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); } @@ -3134,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 @@ -3143,13 +3108,13 @@ 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, (Arguments) $3); } @@ -3166,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)); } ; @@ -3183,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; } ; @@ -3200,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 @@ -3216,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; } ; @@ -3256,9 +3222,9 @@ argument_list NamedArgument a = (NamedArgument) $3; for (int i = 0; i < list.Count; ++i) { NamedArgument na = list [i] as NamedArgument; - if (na != null && na.Name.Value == a.Name.Value) - Report.Error (1740, na.Name.Location, "Named argument `{0}' specified multiple times", - na.Name.Value); + if (na != null && na.Name == a.Name) + Report.Error (1740, na.Location, "Named argument `{0}' specified multiple times", + na.Name); } list.Add (a); @@ -3298,17 +3264,17 @@ 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 { - $$ = new Argument (new Arglist ((Arguments) $3, (Location) $1)); + $$ = 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)); + $$ = new Argument (new Arglist (GetLocation ($1))); } | ARGLIST { - $$ = new Argument (new ArglistAccess ((Location) $1)); + $$ = new Argument (new ArglistAccess (GetLocation ($1))); } ; @@ -3348,22 +3314,20 @@ 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; } ; @@ -3394,19 +3358,19 @@ expression_list_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_arguments CLOSE_BRACKET { - $$ = new BaseIndexerAccess ((Arguments) $3, (Location) $1); + $$ = new BaseIndexerAccess ((Arguments) $3, GetLocation ($1)); } | BASE error { @@ -3418,14 +3382,14 @@ base_access 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)); } ; @@ -3455,21 +3419,21 @@ 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 { if (RootContext.Version <= LanguageVersion.ISO_2) Report.FeatureIsNotAvailable (GetLocation ($1), "implicitly typed arrays"); - $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayList) $3, GetLocation ($1)); + $$ = new ImplicitlyTypedArrayCreation ((string) $2, (ArrayInitializer) $3, GetLocation ($1)); } | new_expr_start error { @@ -3494,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 NewAnonymousType ((ArrayList) $3, current_container, GetLocation ($1)); + $$ = new NewAnonymousType ((List) $3, current_container, GetLocation ($1)); } ; @@ -3515,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; } ; @@ -3530,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); } @@ -3552,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; } ; @@ -3589,7 +3554,7 @@ rank_specifiers : rank_specifier | rank_specifier rank_specifiers { - $$ = (string) $2 + (string) $1; + $$ = (string) $1 + (string) $2; } ; @@ -3634,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 @@ -3674,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)); } ; @@ -3694,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); } ; @@ -3730,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; } @@ -3741,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"); @@ -3751,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)); } ; @@ -3773,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); @@ -3783,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 { @@ -3815,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)); } @@ -3825,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 ; @@ -3853,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 { @@ -3873,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)); } ; @@ -3882,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)); } ; @@ -3901,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)); } ; @@ -3927,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)); } ; @@ -3941,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)); } ; @@ -3965,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)); } ; @@ -3979,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)); } ; @@ -3988,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)); } ; @@ -3997,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)); } ; @@ -4006,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)); } ; @@ -4015,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)); } ; @@ -4026,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)); } ; @@ -4098,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"); @@ -4119,19 +4081,19 @@ lambda_parameter_list lambda_parameter : 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); } | 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); } ; @@ -4139,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 ()); } ; @@ -4162,9 +4124,9 @@ 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 { @@ -4172,6 +4134,9 @@ lambda_expression } | 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 @@ -4193,7 +4158,7 @@ expression non_assignment_expression : conditional_expression | lambda_expression - | query_expression + | query_expression ; constant_expression @@ -4221,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 (); @@ -4263,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; } ; @@ -4279,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; } @@ -4302,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); } } @@ -4334,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; } - | CLASS { - $$ = SpecialConstraint.ReferenceType; + | NEW OPEN_PARENS CLOSE_PARENS + { + $$ = new SpecialContraintExpr (SpecialConstraint.Constructor, GetLocation ($1)); } - | STRUCT { - $$ = SpecialConstraint.ValueType; + | CLASS + { + $$ = new SpecialContraintExpr (SpecialConstraint.Class, GetLocation ($1)); + } + | STRUCT + { + $$ = new SpecialContraintExpr (SpecialConstraint.Struct, GetLocation ($1)); } ; @@ -4411,7 +4412,7 @@ block : OPEN_BRACE { ++lexer.parsing_block; - start_block ((Location) $1); + start_block (GetLocation ($1)); } opt_statement_list block_end { @@ -4423,7 +4424,7 @@ block_end : CLOSE_BRACE { --lexer.parsing_block; - $$ = end_block ((Location) $1); + $$ = end_block (GetLocation ($1)); } | COMPLETE_COMPLETION { @@ -4442,7 +4443,7 @@ block_prepared opt_statement_list CLOSE_BRACE { --lexer.parsing_block; - $$ = end_block ((Location) $4); + $$ = end_block (GetLocation ($4)); } ; @@ -4546,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)) @@ -4565,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); } } ; @@ -4623,7 +4620,7 @@ variable_type if (rank_or_nullable.Length == 0) { SimpleName sn = expr as SimpleName; if (sn != null && sn.Name == "var") - $$ = current_array_type = new VarExpr (sn.Location); + $$ = new VarExpr (sn.Location); else $$ = $1; } else { @@ -4639,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, Report); + Expression.Error_VoidInvalidInTheContext (GetLocation ($1), Report); $$ = TypeManager.system_void_expr; } ; @@ -4666,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 { @@ -4684,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; } @@ -4696,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; } @@ -4709,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; } @@ -4759,7 +4760,7 @@ interactive_statement_expression | error { Error_SyntaxError (yyToken); - $$ = null; + $$ = new EmptyStatement (GetLocation ($1)); } ; @@ -4772,27 +4773,20 @@ if_statement : IF open_parens_any boolean_expression CLOSE_PARENS embedded_statement { - Location l = (Location) $1; - - $$ = new If ((BooleanExpression) $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 ((BooleanExpression) $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"); } ; @@ -4800,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 (); } ; @@ -4824,7 +4818,7 @@ opt_switch_sections : /* empty */ { Report.Warning (1522, 1, lexer.Location, "Empty switch block"); - $$ = new ArrayList (); + $$ = new List (); } | switch_sections ; @@ -4832,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; } ; @@ -4853,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; } @@ -4877,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)); } ; @@ -4895,7 +4889,7 @@ iteration_statement while_statement : WHILE open_parens_any boolean_expression CLOSE_PARENS embedded_statement { - Location l = (Location) $1; + Location l = GetLocation ($1); $$ = new While ((BooleanExpression) $3, (Statement) $5, l); } ; @@ -4904,7 +4898,7 @@ 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, (BooleanExpression) $5, l); } @@ -4917,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; @@ -4931,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); @@ -4954,7 +4947,7 @@ for_statement opt_for_iterator CLOSE_PARENS embedded_statement { - Location l = (Location) $1; + Location l = GetLocation ($1); For f = new For ((Statement) $5, (BooleanExpression) $6, (Statement) $8, (Statement) $10, l); @@ -4965,7 +4958,7 @@ for_statement ; opt_for_initializer - : /* empty */ { $$ = EmptyStatement.Value; } + : /* empty */ { $$ = new EmptyStatement (lexer.Location); } | for_initializer ; @@ -4980,7 +4973,7 @@ opt_for_condition ; opt_for_iterator - : /* empty */ { $$ = EmptyStatement.Value; } + : /* empty */ { $$ = new EmptyStatement (lexer.Location); } | for_iterator ; @@ -5010,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 @@ -5019,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) { @@ -5037,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); @@ -5060,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"); @@ -5119,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"); @@ -5148,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; } ; @@ -5168,23 +5161,23 @@ 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; + var l = (List) $1; Catch c = (Catch) $2; - if (((Catch) l [0]).IsGeneral) { + if (l [0].IsGeneral) { Report.Error (1017, c.loc, "Try statement already has an empty catch block"); } else { if (c.IsGeneral) - l.Insert (0, $2); + l.Insert (0, c); else - l.Add ($2); + l.Add (c); } $$ = l; @@ -5199,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 { @@ -5221,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; @@ -5243,7 +5233,7 @@ 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 { @@ -5269,7 +5259,7 @@ unchecked_statement unsafe_statement : UNSAFE { - RootContext.CheckUnsafeOption ((Location) $1, Report); + RootContext.CheckUnsafeOption (GetLocation ($1), Report); } block { $$ = new Unsafe ((Block) $3); } @@ -5280,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); @@ -5315,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; } ; @@ -5332,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; } ; @@ -5350,7 +5328,7 @@ lock_statement } embedded_statement { - $$ = new Lock ((Expression) $3, (Statement) $6, (Location) $1); + $$ = new Lock ((Expression) $3, (Statement) $6, GetLocation ($1)); } ; @@ -5360,21 +5338,18 @@ using_statement start_block (lexer.Location); Block assign_block = current_block; - DictionaryEntry de = (DictionaryEntry) $3; - Location l = (Location) $1; + var de = (Tuple>) $3; + Location l = GetLocation ($1); - Expression type = (Expression) de.Key; - ArrayList var_declarators = (ArrayList) de.Value; + var vars = new Stack> (); - Stack 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; @@ -5387,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)); @@ -5400,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); @@ -5416,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); } ; @@ -5425,7 +5400,7 @@ using_statement // LINQ query_expression - : first_from_clause query_body + : first_from_clause query_body { lexer.query_parsing = false; @@ -5447,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 (compiler, 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 (compiler, current_block, (LocatedToken) $3, GetLocation ($1)); + current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)); } ; @@ -5466,12 +5457,14 @@ nested_from_clause : FROM IDENTIFIER IN expression { $$ = new Linq.QueryExpression (current_block, new Linq.QueryStartClause ((Expression)$4)); - current_block = new Linq.QueryBlock (compiler, 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 (compiler, 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)); } ; @@ -5482,13 +5475,14 @@ from_clause } 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 { @@ -5496,20 +5490,22 @@ from_clause } 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; @@ -5524,6 +5520,7 @@ query_body $$ = head; } + | opt_query_body_clauses COMPLETE_COMPLETION ; select_or_group_clause @@ -5541,7 +5538,7 @@ 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 (compiler, current_block, lexer.Location); linq_clause_blocks.Push (current_block); @@ -5578,7 +5575,7 @@ query_body_clauses query_body_clause : from_clause - | let_clause + | let_clause | where_clause | join_clause | orderby_clause @@ -5591,13 +5588,14 @@ let_clause } 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); } ; @@ -5619,7 +5617,7 @@ 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 (compiler, current_block, lexer.Location); linq_clause_blocks.Push (current_block); @@ -5638,35 +5636,40 @@ join_clause current_block.SetEndLocation (lexer.Location); current_block = current_block.Parent; - current_block = new Linq.QueryBlock (compiler, 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 (compiler, current_block, lexer.Location); linq_clause_blocks.Push (current_block); @@ -5685,30 +5688,35 @@ join_clause current_block.SetEndLocation (lexer.Location); current_block = current_block.Parent; - current_block = new Linq.QueryBlock (compiler, 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); } ; @@ -5807,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 (compiler, current_block, (LocatedToken) $2, GetLocation ($1)); + current_block = new Linq.QueryBlock (compiler, current_block, new SimpleMemberName (lt.Value, lt.Location), GetLocation ($1)); } query_body { @@ -5838,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); @@ -5846,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, @@ -5900,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; } } @@ -5986,7 +6008,7 @@ void Error_TypeExpected (Location loc) void Error_NamedArgumentExpected (NamedArgument a) { - Report.Error (1738, a.Name.Location, "Named arguments must appear after the positional arguments"); + Report.Error (1738, a.Location, "Named arguments must appear after the positional arguments"); } void push_current_class (TypeContainer tc, object partial_token) @@ -6034,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 @@ -6061,7 +6082,8 @@ 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; LocalInfo vi = current_block.AddVariable (type, id, decl.Location); @@ -6070,7 +6092,7 @@ Block declare_local_variables (Expression type, ArrayList variable_declarators, LocalVariableReference var; var = new LocalVariableReferenceWithClassSideEffect (current_container, decl.identifier, current_block, id, vi, decl.Location); - Assign assign = new SimpleAssign (var, decl.expression_or_array_initializer, 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)); @@ -6111,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; @@ -6147,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; @@ -6197,7 +6208,7 @@ public Tokenizer Lexer { static CSharpParser () { - oob_stack = new Stack (); + oob_stack = new Stack (); } public CSharpParser (SeekableStreamReader reader, CompilationUnit file, CompilerContext ctx) @@ -6212,11 +6223,14 @@ public CSharpParser (SeekableStreamReader reader, CompilationUnit file, Compiler current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes oob_stack.Clear (); 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) @@ -6265,14 +6279,14 @@ 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; } @@ -6370,7 +6384,7 @@ void Error_SyntaxError (int error_code, int token, string 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++){ @@ -6418,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"; @@ -6792,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";