**** Merged r45106 from MCS ****
[mono.git] / mcs / gmcs / cs-parser.jay
index 1c6a364090d44298ab2f4734512be6d9d419bac9..06a28d3720836dc77878610a274d24e38e913586 100644 (file)
@@ -97,6 +97,8 @@ namespace Mono.CSharp
                
                /// assembly and module attribute definition is enabled
                bool global_attrs_enabled = true;
+               bool has_get, has_set;
+
 %}
 
 %token EOF
@@ -348,7 +350,7 @@ using_alias_directive
 using_namespace_directive
        : USING namespace_name SEMICOLON 
          {
-               current_namespace.Using ((string) $2, lexer.Location);
+               current_namespace.Using ((MemberName) $2, lexer.Location);
           }
        ;
 
@@ -361,19 +363,13 @@ namespace_declaration
        : opt_attributes NAMESPACE namespace_or_type_name
        {
                if ($1 != null) {
-                       Report.Error(1518, Lexer.Location, "Attributes cannot be applied to namespaces."
-                                       + " Expected class, delegate, enum, interface, or struct");
+                       Report.Error(1671, Lexer.Location, "A namespace declaration cannot have modifiers or attributes");
                }
 
                MemberName name = (MemberName) $3;
 
                if (name.TypeArguments != null)
                        syntax_error (lexer.Location, "namespace name expected");
-               else if ((current_namespace.Parent != null) && (name.Left != null)) {
-                       Report.Error (134, lexer.Location,
-                                     "Cannot use qualified namespace names in nested " +
-                                     "namespace declarations");
-               }
 
                current_namespace = new NamespaceEntry (
                        current_namespace, file, name.GetName (), lexer.Location);
@@ -401,7 +397,7 @@ namespace_name
                if (name.TypeArguments != null)
                        syntax_error (lexer.Location, "namespace name expected");
 
-               $$ = name.GetName ();
+               $$ = name;
          }
        ;
 
@@ -414,8 +410,6 @@ namespace_body
          opt_using_directives
          opt_namespace_member_declarations
          CLOSE_BRACE
-         {
-         }
        ;
 
 opt_using_directives
@@ -436,25 +430,13 @@ namespace_member_declarations
 namespace_member_declaration
        : type_declaration
          {
-               string name = "";
-               int mod_flags;
-
-               if ($1 is Class){
-                       Class c = (Class) $1;
-                       mod_flags = c.ModFlags;
-                       name = c.Name;
-               } else if ($1 is Struct){
-                       Struct s = (Struct) $1;
-                       mod_flags = s.ModFlags;
-                       name = s.Name;
-               } else
-                       break;
+               if ($1 != null) {
+                       DeclSpace ds = (DeclSpace)$1;
 
-               if ((mod_flags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
-                       Report.Error (
-                               1527, lexer.Location, 
-                               "Namespace elements cant be explicitly " +
-                               "declared private or protected in `" + name + "'");
+                       if ((ds.ModFlags & (Modifiers.PRIVATE|Modifiers.PROTECTED)) != 0){
+                               Report.Error (1527, lexer.Location, 
+                               "Namespace elements cannot be explicitly declared as private, protected or protected internal");
+                       }
                }
                current_namespace.DeclarationFound = true;
          }
@@ -635,7 +617,7 @@ attribute
                Expression left_expr = left == null ? null : left.GetTypeExpression (loc);
 
                if (current_attr_target == "assembly" || current_attr_target == "module")
-                       $$ = new GlobalAttribute (current_container, current_attr_target,
+                       $$ = new GlobalAttribute (current_class, current_attr_target,
                                                  left_expr, identifier, (ArrayList) $3, loc);
                else
                        $$ = new Attribute (current_attr_target, left_expr, identifier, (ArrayList) $3, loc);
@@ -772,43 +754,44 @@ struct_declaration
        : opt_attributes
          opt_modifiers
          opt_partial
-         STRUCT member_name
+         STRUCT
+         {
+               lexer.ConstraintsParsing = true;
+         }
+         member_name
          { 
-               MemberName name = MakeName ((MemberName) $5);
+               MemberName name = MakeName ((MemberName) $6);
                bool partial = (bool) $3;
 
                if (partial) {
                        ClassPart part = PartialContainer.CreatePart (
-                               current_namespace, current_container, name, (int) $2,
+                               current_namespace, current_class, name, (int) $2,
                                (Attributes) $1, Kind.Struct, lexer.Location);
 
                        current_container = part.PartialContainer;
                        current_class = part;
                } else {
                        current_class = new Struct (
-                               current_namespace, current_container, name, (int) $2,
+                               current_namespace, current_class, name, (int) $2,
                                (Attributes) $1, lexer.Location);
 
+                       current_container.AddClassOrStruct (current_class);
                        current_container = current_class;
-                       RootContext.Tree.RecordDecl (name.GetName (true), current_class);
+                       RootContext.Tree.RecordDecl (name, current_class);
                }
-
-               lexer.ConstraintsParsing = true;
          }
          opt_class_base
          opt_type_parameter_constraints_clauses
          {
                lexer.ConstraintsParsing = false;
 
-               if ($7 != null)
-                       current_class.Bases = (ArrayList) $7;
+               if ($8 != null)
+                       current_class.Bases = (ArrayList) $8;
 
-               current_class.SetParameterInfo ((ArrayList) $8);
+               current_class.SetParameterInfo ((ArrayList) $9);
 
                if (RootContext.Documentation != null)
                        current_class.DocComment = Lexer.consume_doc_comment ();
-
-               current_class.Register ();
          }
          struct_body
          {
@@ -817,10 +800,7 @@ struct_declaration
          }
          opt_semicolon
          {
-               $$ = current_class;
-
-               current_container = current_container.Parent;
-               current_class = current_container;
+               $$ = pop_current_class ();
          }
        | opt_attributes opt_modifiers opt_partial STRUCT error {
                CheckIdentifierToken (yyToken);
@@ -935,11 +915,9 @@ field_declaration
                int mod = (int) $2;
 
                foreach (VariableDeclaration var in (ArrayList) $4){
-                       Location l = var.Location;
-
                        Field field = new Field (current_class, type, mod, var.identifier, 
                                                 var.expression_or_array_initializer, 
-                                                (Attributes) $1, l);
+                                                (Attributes) $1, var.Location);
 
                        if (RootContext.Documentation != null) {
                                field.DocComment = Lexer.consume_doc_comment ();
@@ -948,6 +926,27 @@ field_declaration
                        current_container.AddField (field);
                }
          }
+       | opt_attributes
+         opt_modifiers
+         FIXED
+         type 
+         fixed_variable_declarators
+         SEMICOLON
+         { 
+                       Expression type = (Expression) $4;
+                       int mod = (int) $2;
+
+                       foreach (VariableDeclaration var in (ArrayList) $5) {
+                               FixedField field = new FixedField (current_class, type, mod, var.identifier,
+                                       (Expression)var.expression_or_array_initializer, (Attributes) $1, var.Location);
+
+                               if (RootContext.Documentation != null) {
+                                       field.DocComment = Lexer.consume_doc_comment ();
+                                       Lexer.doc_state = XmlCommentState.Allowed;
+                               }
+                               current_container.AddField (field);
+                       }
+         }
        | opt_attributes
          opt_modifiers
          VOID  
@@ -957,11 +956,34 @@ field_declaration
          }
        ;
 
+fixed_variable_declarators
+       : fixed_variable_declarator
+               {
+                       ArrayList decl = new ArrayList (2);
+                       decl.Add ($1);
+                       $$ = decl;
+               }
+       | fixed_variable_declarators COMMA fixed_variable_declarator
+               {
+                       ArrayList decls = (ArrayList) $1;
+                       decls.Add ($3);
+                       $$ = $1;
+               }
+       ;
+
+fixed_variable_declarator
+       : IDENTIFIER OPEN_BRACKET expression CLOSE_BRACKET
+               {
+                       $$ = new VariableDeclaration ((string) $1, $3, lexer.Location);
+               }
+       ;
+
 variable_declarators
        : variable_declarator 
          {
                ArrayList decl = new ArrayList (4);
-               decl.Add ($1);
+               if ($1 != null)
+                       decl.Add ($1);
                $$ = decl;
          }
        | variable_declarators COMMA variable_declarator
@@ -981,6 +1003,12 @@ variable_declarator
          {
                $$ = new VariableDeclaration ((string) $1, null, lexer.Location);
          }
+       | IDENTIFIER OPEN_BRACKET opt_expression CLOSE_BRACKET
+         {
+               Report.Error (650, lexer.Location, "Syntax error, bad array declarator. To declare a managed array the rank specifier precedes the variable's identifier. " +
+                       "To declare a fixed size buffer field, use the fixed keyword before the field type");
+               $$ = null;
+         }
        ;
 
 variable_initializer
@@ -1156,7 +1184,7 @@ formal_parameter_list
                Parameter [] pars = new Parameter [pars_list.Count];
                pars_list.CopyTo (pars);
 
-               $$ = new Parameters (pars, null, lexer.Location); 
+               $$ = new Parameters (pars, null); 
          } 
        | fixed_parameters COMMA parameter_array
          {
@@ -1165,7 +1193,7 @@ formal_parameter_list
                Parameter [] pars = new Parameter [pars_list.Count];
                pars_list.CopyTo (pars);
 
-               $$ = new Parameters (pars, (Parameter) $3, lexer.Location); 
+               $$ = new Parameters (pars, (Parameter) $3); 
          }
        | fixed_parameters COMMA ARGLIST
          {
@@ -1174,15 +1202,25 @@ formal_parameter_list
                Parameter [] pars = new Parameter [pars_list.Count];
                pars_list.CopyTo (pars);
 
-               $$ = new Parameters (pars, true, lexer.Location);
+               $$ = new Parameters (pars, true);
+         }
+       | parameter_array COMMA fixed_parameters
+         {
+               Report.Error (231, lexer.Location, "A params parameter must be the last parameter in a formal parameter list");
+               $$ = null;
+         }
+       | ARGLIST COMMA fixed_parameters
+         {
+               Report.Error (257, lexer.Location, "An __arglist parameter must be the last parameter in a formal parameter list");
+               $$ = null;
          }
        | parameter_array 
          {
-               $$ = new Parameters (null, (Parameter) $1, lexer.Location);
+               $$ = new Parameters (null, (Parameter) $1);
          }
        | ARGLIST
          {
-               $$ = new Parameters (null, true, lexer.Location);
+               $$ = new Parameters (null, true);
          }
        ;
 
@@ -1209,7 +1247,15 @@ fixed_parameter
          type
          IDENTIFIER
          {
-               $$ = new Parameter ((Expression) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
+               $$ = new Parameter ((Expression) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1, lexer.Location);
+         }
+       | opt_attributes
+         opt_parameter_modifier
+         type
+         IDENTIFIER OPEN_BRACKET CLOSE_BRACKET
+         {
+               Report.Error (1552, lexer.Location, "Array type specifier, [], must appear before parameter name");
+               $$ = null;
          }
        | opt_attributes
          opt_parameter_modifier
@@ -1250,7 +1296,7 @@ parameter_modifier
 parameter_array
        : opt_attributes PARAMS type IDENTIFIER
          { 
-               $$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
+               $$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1, lexer.Location);
                note ("type must be a single-dimension array type"); 
          }
        | opt_attributes PARAMS parameter_modifier type IDENTIFIER 
@@ -1286,9 +1332,13 @@ property_declaration
          accessor_declarations 
          {
                lexer.PropertyParsing = false;
+               has_get = has_set = false;
          }
          CLOSE_BRACE
          { 
+               if ($8 == null)
+                       break;
+
                Property prop;
                Pair pair = (Pair) $8;
                Accessor get_block = (Accessor) pair.First;
@@ -1300,7 +1350,7 @@ property_declaration
                if (name.TypeArguments != null)
                        syntax_error (lexer.Location, "a property can't have type arguments");
 
-               prop = new Property (current_container, (Expression) $3, (int) $2, false,
+               prop = new Property (current_class, (Expression) $3, (int) $2, false,
                                     name, (Attributes) $1, get_block, set_block, loc);
                if (SimpleIteratorContainer.Simple.Yields)
                        prop.SetYields ();
@@ -1316,26 +1366,33 @@ property_declaration
        ;
 
 accessor_declarations
-       : get_accessor_declaration opt_set_accessor_declaration
-         { 
-               $$ = new Pair ($1, $2);
-         }
-       | set_accessor_declaration opt_get_accessor_declaration
+       : get_accessor_declaration
+        {
+               $$ = new Pair ($1, null);
+        }
+       | get_accessor_declaration accessor_declarations
+        { 
+               Pair pair = (Pair) $2;
+               pair.First = $1;
+               $$ = pair;
+        }
+       | set_accessor_declaration
+        {
+               $$ = new Pair (null, $1);
+        }
+       | set_accessor_declaration accessor_declarations
+        { 
+               Pair pair = (Pair) $2;
+               pair.Second = $1;
+               $$ = pair;
+        }
+       | error
          {
-               $$ = new Pair ($2, $1);
+               Report.Error (1014, lexer.Location, "A get or set accessor expected");
+               $$ = null;
          }
        ;
 
-opt_get_accessor_declaration
-       : /* empty */                   { $$ = null; }
-       | get_accessor_declaration
-       ;
-
-opt_set_accessor_declaration
-       : /* empty */                   { $$ = null; }
-       | set_accessor_declaration
-       ;
-
 get_accessor_declaration
        : opt_attributes opt_modifiers GET
          {
@@ -1349,7 +1406,12 @@ get_accessor_declaration
          }
           accessor_body
          {
+               if (has_get) {
+                       Report.Error (1007, lexer.Location, "Property accessor already defined");
+                       break;
+               }
                $$ = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, lexer.Location);
+               has_get = true;
                current_local_parameters = null;
                lexer.PropertyParsing = true;
 
@@ -1365,12 +1427,12 @@ set_accessor_declaration
                Parameter [] args;
                Parameter implicit_value_parameter = new Parameter (
                        implicit_value_parameter_type, "value", 
-                       Parameter.Modifier.NONE, null);
+                       Parameter.Modifier.NONE, null, lexer.Location);
 
                if (parsing_indexer == false) {
                        args  = new Parameter [1];
                        args [0] = implicit_value_parameter;
-                       current_local_parameters = new Parameters (args, null, lexer.Location);
+                       current_local_parameters = new Parameters (args, null);
                } else {
                        Parameter [] fpars = indexer_parameters.FixedParameters;
 
@@ -1383,14 +1445,19 @@ set_accessor_declaration
                        } else 
                                args = null;
                        current_local_parameters = new Parameters (
-                               args, indexer_parameters.ArrayParameter, lexer.Location);
+                               args, indexer_parameters.ArrayParameter);
                }
                
                lexer.PropertyParsing = false;
          }
          accessor_body
          {
+               if (has_set) {
+                       Report.Error (1007, lexer.Location, "Property accessor already defined");
+                       break;
+               }
                $$ = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, lexer.Location);
+               has_set = true;
                current_local_parameters = null;
                lexer.PropertyParsing = true;
 
@@ -1409,45 +1476,46 @@ interface_declaration
        : opt_attributes
          opt_modifiers
          opt_partial
-         INTERFACE member_name
+         INTERFACE
          {
-               MemberName name = MakeName ((MemberName) $5);
+               lexer.ConstraintsParsing = true;
+         }
+         member_name
+         {
+               MemberName name = MakeName ((MemberName) $6);
                bool partial = (bool) $3;
 
                if (partial) {
                        ClassPart part = PartialContainer.CreatePart (
-                               current_namespace, current_container, name, (int) $2,
+                               current_namespace, current_class, name, (int) $2,
                                (Attributes) $1, Kind.Interface, lexer.Location);
 
                        current_container = part.PartialContainer;
                        current_class = part;
                } else {
                        current_class = new Interface (
-                               current_namespace, current_container, name, (int) $2,
+                               current_namespace, current_class, name, (int) $2,
                                (Attributes) $1, lexer.Location);
 
+                       current_container.AddInterface (current_class);
                        current_container = current_class;
-                       RootContext.Tree.RecordDecl (name.GetName (true), current_class);
+                       RootContext.Tree.RecordDecl (name, current_class);
                }
-
-               lexer.ConstraintsParsing = true;
          }
          opt_class_base
          opt_type_parameter_constraints_clauses
          {
                lexer.ConstraintsParsing = false;
 
-               if ($7 != null)
-                       current_class.Bases = (ArrayList) $7;
+               if ($8 != null)
+                       current_class.Bases = (ArrayList) $8;
 
-               current_class.SetParameterInfo ((ArrayList) $8);
+               current_class.SetParameterInfo ((ArrayList) $9);
 
                if (RootContext.Documentation != null) {
                        current_class.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
-
-               current_class.Register ();
          }
          interface_body
          { 
@@ -1456,10 +1524,7 @@ interface_declaration
          }
          opt_semicolon 
          {
-               $$ = current_class;
-
-               current_container = current_container.Parent;
-               current_class = current_container;
+               $$ = pop_current_class ();
          }
        | opt_attributes opt_modifiers opt_partial INTERFACE error {
                CheckIdentifierToken (yyToken);
@@ -1485,6 +1550,9 @@ interface_member_declarations
 interface_member_declaration
        : interface_method_declaration          
          { 
+               if ($1 == null)
+                       break;
+
                Method m = (Method) $1;
 
                if (m.IsExplicitImpl)
@@ -1498,6 +1566,9 @@ interface_member_declaration
          }
        | interface_property_declaration        
          { 
+               if ($1 == null)
+                       break;
+
                Property p = (Property) $1;
 
                if (p.IsExplicitImpl)
@@ -1526,6 +1597,9 @@ interface_member_declaration
          }
        | interface_indexer_declaration
          { 
+               if ($1 == null)
+                       break;
+
                Indexer i = (Indexer) $1;
 
                if (i.IsExplicitImpl)
@@ -1557,6 +1631,10 @@ interface_member_declaration
          {
                Report.Error (524, lexer.Location, "Interfaces can not declare interfaces");
          } 
+       | constant_declaration
+         {
+               Report.Error (525, lexer.Location, "Interfaces cannot contain constants");
+         }
        ;
 
 opt_new
@@ -1627,6 +1705,19 @@ interface_method_declaration
                if (RootContext.Documentation != null)
                        ((Method) $$).DocComment = Lexer.consume_doc_comment ();
          }
+       | opt_attributes opt_new type namespace_or_type_name
+         OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+         {
+               lexer.ConstraintsParsing = true;
+         }
+         opt_type_parameter_constraints_clauses
+         OPEN_BRACE opt_statement_list CLOSE_BRACE
+         {
+               lexer.ConstraintsParsing = false;
+               Report.Error (531, lexer.Location, "'{0}': interface members cannot have a definition", $4);
+               $$ = null;
+         }
+
        ;
 
 interface_property_declaration
@@ -1639,6 +1730,14 @@ interface_property_declaration
          { lexer.PropertyParsing = false; }
          CLOSE_BRACE
          {
+               if ($3 == TypeManager.system_void_expr) {
+                       Report.Error (547, lexer.Location, "'{0}': property cannot have void type", $4);
+                       break;
+               }
+
+               if ($7 == null)
+                       break;
+
                 InterfaceAccessorInfo pinfo = (InterfaceAccessorInfo) $7;
 
                $$ = new Property (current_class, (Expression) $3, (int) $2, true,
@@ -1658,12 +1757,21 @@ interface_property_declaration
 interface_accessors
        : opt_attributes opt_modifiers GET SEMICOLON    
        { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null, (int) $2, 0, lexer.Location, lexer.Location); }
+       | opt_attributes opt_modifiers GET OPEN_BRACE
+        {  
+               Report.Error (531, lexer.Location, "'{0}': interface members cannot have a definition", ".get");
+               $$ = null;
+        }
        | opt_attributes opt_modifiers SET SEMICOLON            
        { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1, 0, (int) $2, lexer.Location, lexer.Location); }
        | opt_attributes opt_modifiers GET SEMICOLON opt_attributes opt_modifiers SET SEMICOLON 
          { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $5, (int) $2, (int) $6, lexer.Location, lexer.Location); }
        | opt_attributes opt_modifiers SET SEMICOLON opt_attributes opt_modifiers GET SEMICOLON
          { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $5, (Attributes) $1, (int) $6, (int) $2, lexer.Location, lexer.Location); }
+       |
+         {
+               Report.Error (548, lexer.Location, "'{0}' : property or indexer must have at least one accessor", "");
+         }
        ;
 
 interface_event_declaration
@@ -1683,8 +1791,16 @@ interface_event_declaration
                Report.Error (68, lexer.Location, "Event declarations on interfaces can not be initialized.");
                $$ = null;
          }
-       | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE event_accessor_declarations CLOSE_BRACE {
-               Report.Error (69, lexer.Location, "Event accessors not valid on interfaces");
+       | opt_attributes opt_new EVENT type IDENTIFIER OPEN_BRACE
+       {
+               lexer.EventParsing = true;
+       }
+       event_accessor_declarations
+       {
+               lexer.EventParsing = false;
+       }
+       CLOSE_BRACE {
+               Report.Error (69, lexer.Location, "Event in interface cannot have add or remove accessors");
                $$ = null;
          }
        ;
@@ -1698,6 +1814,9 @@ interface_indexer_declaration
          { lexer.PropertyParsing = false; }
          CLOSE_BRACE
          {
+               if ($10 == null)
+                       break;
+
                InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
 
                $$ = new Indexer (current_class, (Expression) $3,
@@ -1716,17 +1835,20 @@ operator_declaration
          }
          operator_body
          {
+               if ($3 == null)
+                       break;
+
                OperatorDeclaration decl = (OperatorDeclaration) $3;
                
                Parameter [] param_list = new Parameter [decl.arg2type != null ? 2 : 1];
 
-               param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null);
+               param_list[0] = new Parameter (decl.arg1type, decl.arg1name, Parameter.Modifier.NONE, null, decl.location);
                if (decl.arg2type != null)
-                       param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null);
+                       param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null, decl.location);
 
                Operator op = new Operator (
                        current_class, decl.optype, decl.ret_type, (int) $2, 
-                       new Parameters (param_list, null, decl.location),
+                       new Parameters (param_list, null),
                        (ToplevelBlock) $5, (Attributes) $1, decl.location);
 
                if (RootContext.Documentation != null) {
@@ -1765,9 +1887,9 @@ operator_declarator
                Parameter [] pars = new Parameter [1];
                Expression type = (Expression) $5;
 
-               pars [0] = new Parameter (type, (string) $6, Parameter.Modifier.NONE, null);
+               pars [0] = new Parameter (type, (string) $6, Parameter.Modifier.NONE, null, lexer.Location);
 
-               current_local_parameters = new Parameters (pars, null, lexer.Location);
+               current_local_parameters = new Parameters (pars, null);
 
                if (RootContext.Documentation != null) {
                        tmpComment = Lexer.consume_doc_comment ();
@@ -1790,10 +1912,10 @@ operator_declarator
                Expression typeL = (Expression) $5;
                Expression typeR = (Expression) $8;
 
-              pars [0] = new Parameter (typeL, (string) $6, Parameter.Modifier.NONE, null);
-              pars [1] = new Parameter (typeR, (string) $9, Parameter.Modifier.NONE, null);
+              pars [0] = new Parameter (typeL, (string) $6, Parameter.Modifier.NONE, null, lexer.Location);
+              pars [1] = new Parameter (typeR, (string) $9, Parameter.Modifier.NONE, null, lexer.Location);
 
-              current_local_parameters = new Parameters (pars, null, lexer.Location);
+              current_local_parameters = new Parameters (pars, null);
 
                if (RootContext.Documentation != null) {
                        tmpComment = Lexer.consume_doc_comment ();
@@ -1805,6 +1927,22 @@ operator_declarator
                                             typeR, (string) $9, lexer.Location);
         }
        | conversion_operator_declarator
+       | type OPERATOR overloadable_operator
+         OPEN_PARENS 
+               type IDENTIFIER COMMA
+               type IDENTIFIER COMMA
+               type IDENTIFIER
+         CLOSE_PARENS
+       {
+               Report.Error (1534, lexer.Location, "Overloaded binary operator '{0}' takes two parameters", $3);
+               $$ = null;
+       }
+       | type OPERATOR overloadable_operator 
+         OPEN_PARENS CLOSE_PARENS
+       {
+               Report.Error (1535, lexer.Location, "Overloaded unary operator '{0}' takes one parameter", $3);
+               $$ = null;
+       }
        ;
 
 overloadable_operator
@@ -1840,9 +1978,9 @@ conversion_operator_declarator
          {
                Parameter [] pars = new Parameter [1];
 
-               pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
+               pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null, lexer.Location);
 
-               current_local_parameters = new Parameters (pars, null, lexer.Location);  
+               current_local_parameters = new Parameters (pars, null);  
                  
                if (RootContext.Documentation != null) {
                        tmpComment = Lexer.consume_doc_comment ();
@@ -1856,9 +1994,9 @@ conversion_operator_declarator
          {
                Parameter [] pars = new Parameter [1];
 
-               pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
+               pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null, lexer.Location);
 
-               current_local_parameters = new Parameters (pars, null, lexer.Location);  
+               current_local_parameters = new Parameters (pars, null);  
                  
                if (RootContext.Documentation != null) {
                        tmpComment = Lexer.consume_doc_comment ();
@@ -1962,11 +2100,11 @@ opt_constructor_initializer
 constructor_initializer
        : COLON BASE OPEN_PARENS opt_argument_list CLOSE_PARENS
          {
-               $$ = new ConstructorBaseInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
+               $$ = new ConstructorBaseInitializer ((ArrayList) $4, lexer.Location);
          }
        | COLON THIS OPEN_PARENS opt_argument_list CLOSE_PARENS
          {
-               $$ = new ConstructorThisInitializer ((ArrayList) $4, current_local_parameters, lexer.Location);
+               $$ = new ConstructorThisInitializer ((ArrayList) $4, lexer.Location);
          }
        | COLON error {
                Report.Error (1018, lexer.Location, "Keyword this or base expected");
@@ -1990,7 +2128,7 @@ destructor_declaration
          }
          IDENTIFIER OPEN_PARENS CLOSE_PARENS block
          {
-               if ((string) $5 != current_container.Basename){
+               if ((string) $5 != current_container.MemberName.Name){
                        Report.Error (574, lexer.Location, "Name of destructor must match name of class");
                } else if (current_container.Kind != Kind.Class){
                        Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
@@ -2013,7 +2151,7 @@ destructor_declaration
                         
                        Method d = new Destructor (
                                current_class, TypeManager.system_void_expr, m, "Finalize", 
-                               new Parameters (null, null, l), (Attributes) $1, l);
+                               new Parameters (null, null), (Attributes) $1, l);
                        if (RootContext.Documentation != null)
                                d.DocComment = ConsumeStoredComment ();
                  
@@ -2123,11 +2261,11 @@ add_accessor_declaration
                Parameter [] args = new Parameter [1];
                Parameter implicit_value_parameter = new Parameter (
                        implicit_value_parameter_type, "value", 
-                       Parameter.Modifier.NONE, null);
+                       Parameter.Modifier.NONE, null, lexer.Location);
 
                args [0] = implicit_value_parameter;
                
-               current_local_parameters = new Parameters (args, null, lexer.Location);  
+               current_local_parameters = new Parameters (args, null);  
                lexer.EventParsing = false;
          }
           block
@@ -2139,6 +2277,10 @@ add_accessor_declaration
                Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
                $$ = null;
          }
+       | opt_attributes modifiers ADD {
+               Report.Error (1609, lexer.Location, "Modifiers cannot be placed on event accessor declarations");
+               $$ = null;
+         }
        ;
 
 remove_accessor_declaration
@@ -2147,11 +2289,11 @@ remove_accessor_declaration
                Parameter [] args = new Parameter [1];
                Parameter implicit_value_parameter = new Parameter (
                        implicit_value_parameter_type, "value", 
-                       Parameter.Modifier.NONE, null);
+                       Parameter.Modifier.NONE, null, lexer.Location);
 
                args [0] = implicit_value_parameter;
                
-               current_local_parameters = new Parameters (args, null, lexer.Location);  
+               current_local_parameters = new Parameters (args, null);  
                lexer.EventParsing = false;
          }
           block
@@ -2163,6 +2305,10 @@ remove_accessor_declaration
                Report.Error (73, lexer.Location, "Add or remove accessor must have a body");
                $$ = null;
          }
+       | opt_attributes modifiers REMOVE {
+               Report.Error (1609, lexer.Location, "Modifiers cannot be placed on event accessor declarations");
+               $$ = null;
+         }
        ;
 
 indexer_declaration
@@ -2181,10 +2327,14 @@ indexer_declaration
           accessor_declarations 
          {
                  lexer.PropertyParsing = false;
+                 has_get = has_set = false;
                  parsing_indexer  = false;
          }
          CLOSE_BRACE
          { 
+               if ($7 == null)
+                       break;
+
                // The signature is computed from the signature of the indexer.  Look
                // at section 3.6 on the spec
                Location loc = (Location) $5;
@@ -2257,6 +2407,7 @@ indexer_declarator
 enum_declaration
        : opt_attributes
          opt_modifiers
+         opt_partial
          ENUM IDENTIFIER 
          opt_enum_base {
                if (RootContext.Documentation != null)
@@ -2264,26 +2415,33 @@ enum_declaration
          }
          enum_body
          opt_semicolon
-         { 
+         {
+               bool partial = (bool) $3;
+
+               if (partial) {
+                       Report.Error (267, lexer.Location, "The partial modifier can only appear before a 'class', 'struct', or 'interface'");
+                       break;  // assumes that the parser put us in a switch
+               }
+
                Location enum_location = lexer.Location;
 
-               MemberName full_name = MakeName (new MemberName ((string) $4));
-               Enum e = new Enum (current_namespace, current_container, (Expression) $5, (int) $2,
-                                  full_name, (Attributes) $1, enum_location);
+               MemberName name = MakeName (new MemberName ((string) $5));
+               Enum e = new Enum (current_namespace, current_class, (Expression) $6, (int) $2,
+                                  name, (Attributes) $1, enum_location);
                
                if (RootContext.Documentation != null)
                        e.DocComment = enumTypeComment;
 
-               foreach (VariableDeclaration ev in (ArrayList) $7) {
+               foreach (VariableDeclaration ev in (ArrayList) $8) {
                        e.AddEnumMember (ev.identifier, 
                                         (Expression) ev.expression_or_array_initializer,
                                         ev.Location, ev.OptAttributes,
                                         ev.DocComment);
                }
 
-               string name = full_name.GetName ();
                current_container.AddEnum (e);
                RootContext.Tree.RecordDecl (name, e);
+               $$ = e;
 
          }
        ;
@@ -2368,47 +2526,17 @@ enum_member_declaration
 delegate_declaration
        : opt_attributes
          opt_modifiers
-         DELEGATE type member_name
-         OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
+         DELEGATE
          {
-               Location l = lexer.Location;
-               MemberName name = MakeName ((MemberName) $5);
-               Delegate del = new Delegate (current_namespace, current_container, (Expression) $4,
-                                            (int) $2, name, (Parameters) $7, (Attributes) $1, l);
-
-               if (RootContext.Documentation != null) {
-                       del.DocComment = Lexer.consume_doc_comment ();
-                       Lexer.doc_state = XmlCommentState.Allowed;
-               }
-
-               current_container.AddDelegate (del);
-               RootContext.Tree.RecordDecl (name.GetName (true), del);
-
-               current_delegate = del;
-
                lexer.ConstraintsParsing = true;
          }
-         opt_type_parameter_constraints_clauses
-         {
-               lexer.ConstraintsParsing = false;
-         }
-         SEMICOLON
-         {
-               current_delegate.SetParameterInfo ((ArrayList) $9);
-
-               current_delegate = null;
-         }
-       | opt_attributes
-         opt_modifiers
-         DELEGATE VOID member_name
-         OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS 
+         type member_name
+         OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
          {
                Location l = lexer.Location;
-               MemberName name = MakeName ((MemberName) $5);
-               Delegate del = new Delegate (
-                       current_namespace, current_container,
-                       TypeManager.system_void_expr, (int) $2, name,
-                       (Parameters) $7, (Attributes) $1, l);
+               MemberName name = MakeName ((MemberName) $6);
+               Delegate del = new Delegate (current_namespace, current_class, (Expression) $5,
+                                            (int) $2, name, (Parameters) $8, (Attributes) $1, l);
 
                if (RootContext.Documentation != null) {
                        del.DocComment = Lexer.consume_doc_comment ();
@@ -2416,11 +2544,9 @@ delegate_declaration
                }
 
                current_container.AddDelegate (del);
-               RootContext.Tree.RecordDecl (name.GetName (true), del);
+               RootContext.Tree.RecordDecl (name, del);
 
                current_delegate = del;
-
-               lexer.ConstraintsParsing = true;
          }
          opt_type_parameter_constraints_clauses
          {
@@ -2428,7 +2554,8 @@ delegate_declaration
          }
          SEMICOLON
          {
-               current_delegate.SetParameterInfo ((ArrayList) $9);
+               current_delegate.SetParameterInfo ((ArrayList) $10);
+               $$ = current_delegate;
 
                current_delegate = null;
          }
@@ -3125,7 +3252,7 @@ anonymous_method_expression
                Location loc = (Location) $3;
                top_current_block = (Block) oob_stack.Pop ();
                current_block = (Block) oob_stack.Pop ();
-                       if (RootContext.Version == LanguageVersion.ISO_1){
+               if (RootContext.Version == LanguageVersion.ISO_1){
                                Report.FeatureIsNotStandardized (lexer.Location, "anonymous methods");
                                $$ = null;
                } else  {
@@ -3153,7 +3280,7 @@ anonymous_method_signature
                        ArrayList par_list = (ArrayList) $2;
                        Parameter [] pars = new Parameter [par_list.Count];
                        par_list.CopyTo (pars);
-                       $$ = new Parameters (pars, null, lexer.Location);
+                       $$ = new Parameters (pars, null);
                }
          }
        ;
@@ -3180,10 +3307,10 @@ anonymous_method_parameter_list
 
 anonymous_method_parameter
        : opt_parameter_modifier type IDENTIFIER {
-               $$ = new Parameter ((Expression) $2, (string) $3, (Parameter.Modifier) $1, null);
+               $$ = new Parameter ((Expression) $2, (string) $3, (Parameter.Modifier) $1, null, lexer.Location);
          }
        | PARAMS type IDENTIFIER {
-               Report.Error (-221, lexer.Location, "params modifier not allowed in anonymous method declaration");
+               Report.Error (1670, lexer.Location, "params modifier not allowed in anonymous method declaration");
                $$ = null;
          }
        ;
@@ -3326,16 +3453,23 @@ shift_expression
 
 opt_error
        : /* empty */
+         {
+               $$ = false;
+         }
        | error
          {
                lexer.PutbackNullable ();
+               $$ = true;
          }
        ;
 
 nullable_type_or_conditional
        : type opt_error
          {
-               $$ = $1;
+               if (((bool) $2) && ($1 is ComposedCast))
+                       $$ = ((ComposedCast) $1).RemoveNullable ();
+               else
+                       $$ = $1;
          }
        ;
 
@@ -3551,15 +3685,19 @@ class_declaration
        : opt_attributes
          opt_modifiers
          opt_partial
-         CLASS member_name
+         CLASS
          {
-               MemberName name = MakeName ((MemberName) $5);
+               lexer.ConstraintsParsing = true;
+         }
+         member_name
+         {
+               MemberName name = MakeName ((MemberName) $6);
                bool partial = (bool) $3;
                int mod_flags = (int) $2;
 
                if (partial) {
                        ClassPart part = PartialContainer.CreatePart (
-                               current_namespace, current_container, name, mod_flags,
+                               current_namespace, current_class, name, mod_flags,
                                (Attributes) $1, Kind.Class, lexer.Location);
 
                        current_container = part.PartialContainer;
@@ -3567,42 +3705,39 @@ class_declaration
                } else {
                        if ((mod_flags & Modifiers.STATIC) != 0) {
                                current_class = new StaticClass (
-                                       current_namespace, current_container, name,
+                                       current_namespace, current_class, name,
                                        mod_flags, (Attributes) $1, lexer.Location);
                        } else {
                                current_class = new Class (
-                                       current_namespace, current_container, name,
+                                       current_namespace, current_class, name,
                                        mod_flags, (Attributes) $1, lexer.Location);
                        }
 
+                       current_container.AddClassOrStruct (current_class);
                        current_container = current_class;
-                       RootContext.Tree.RecordDecl (name.GetName (true), current_class);
+                       RootContext.Tree.RecordDecl (name, current_class);
                }
-
-               lexer.ConstraintsParsing = true;
          }
          opt_class_base
          opt_type_parameter_constraints_clauses
          {
                lexer.ConstraintsParsing = false;
 
-               if ($7 != null) {
+               if ($8 != null) {
                        if (current_class.Name == "System.Object") {
                                Report.Error (537, current_class.Location,
                                              "The class System.Object cannot have a base " +
                                              "class or implement an interface.");
                        }
-                       current_class.Bases = (ArrayList) $7;
+                       current_class.Bases = (ArrayList) $8;
                }
 
-               current_class.SetParameterInfo ((ArrayList) $8);
+               current_class.SetParameterInfo ((ArrayList) $9);
 
                if (RootContext.Documentation != null) {
                        current_class.DocComment = Lexer.consume_doc_comment ();
                        Lexer.doc_state = XmlCommentState.Allowed;
                }
-
-               current_class.Register ();
          }
          class_body
          {
@@ -3611,10 +3746,7 @@ class_declaration
          }
          opt_semicolon 
          {
-               $$ = current_class;
-
-               current_container = current_container.Parent;
-               current_class = current_container;
+               $$ = pop_current_class ();
          }
        ;       
 
@@ -3744,8 +3876,7 @@ block
                        current_block = new ToplevelBlock ((ToplevelBlock) top_current_block, current_local_parameters, lexer.Location);
                        top_current_block = current_block;
                } else {
-                       current_block = new Block (current_block, current_local_parameters,
-                                                  lexer.Location, Location.Null);
+                       current_block = new Block (current_block, lexer.Location, Location.Null);
                }
          } 
          opt_statement_list CLOSE_BRACE 
@@ -4157,8 +4288,7 @@ for_statement
 
                                LocalInfo vi;
 
-                               vi = current_block.AddVariable (
-                                       type, decl.identifier, current_local_parameters, decl.Location);
+                               vi = current_block.AddVariable (type, decl.identifier, decl.Location);
                                if (vi == null)
                                        continue;
 
@@ -4268,9 +4398,9 @@ foreach_statement
                Location l = lexer.Location;
                LocalInfo vi;
 
-               vi = foreach_block.AddVariable ((Expression) $3, (string) $4, current_local_parameters, l);
+               vi = foreach_block.AddVariable ((Expression) $3, (string) $4, l);
                if (vi != null) {
-                       vi.ReadOnly = true;
+                       vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Foreach);
 
                        // Get a writable reference to this read-only variable.
                        //
@@ -4324,7 +4454,7 @@ continue_statement
 goto_statement
        : GOTO IDENTIFIER SEMICOLON 
          {
-               $$ = new Goto (current_block, (string) $2, lexer.Location);
+               $$ = new Goto ((string) $2, lexer.Location);
          }
        | GOTO CASE constant_expression SEMICOLON
          {
@@ -4370,6 +4500,11 @@ yield_statement
                        $$ = new Yield ((Expression) $3, lexer.Location); 
                }
          }
+       | IDENTIFIER RETURN SEMICOLON
+       {
+               Report.Error (1627, lexer.Location, "Expression expected after yield return");
+               $$ = null;
+       }
        | IDENTIFIER BREAK SEMICOLON
          {
                string s = (string) $1;
@@ -4541,7 +4676,7 @@ unsafe_statement
        {
                if (!RootContext.Unsafe){
                        Report.Error (227, lexer.Location, 
-                               "Unsafe code can only be used if --unsafe is used");
+                               "Unsafe code can only be used if -unsafe is used");
                }
        } block {
                $$ = new Unsafe ((Block) $3);
@@ -4565,11 +4700,11 @@ fixed_statement
                        Pair p = (Pair) list [i];
                        LocalInfo v;
 
-                       v = current_block.AddVariable (type, (string) p.First,current_local_parameters, l);
+                       v = current_block.AddVariable (type, (string) p.First, l);
                        if (v == null)
                                continue;
 
-                       v.ReadOnly = true;
+                       v.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Fixed);
                        v.Pinned = true;
                        p.First = v;
                        list [i] = p;
@@ -4650,12 +4785,10 @@ using_statement
 
                        foreach (VariableDeclaration decl in var_declarators){
 
-                               LocalInfo vi    = current_block.AddVariable (
-                                       type, decl.identifier, 
-                                       current_local_parameters, decl.Location);
+                               LocalInfo vi = current_block.AddVariable (type, decl.identifier, decl.Location);
                                if (vi == null)
                                        continue;
-                               vi.ReadOnly = true;
+                               vi.SetReadOnlyContext (LocalInfo.ReadOnlyContext.Using);
 
                                Expression expr;
                                if (decl.expression_or_array_initializer is Expression){
@@ -4829,6 +4962,23 @@ void Error_ExpectingTypeName (Location l, Expression expr)
        }
 }
 
+TypeContainer pop_current_class ()
+{
+       TypeContainer retval = current_class;
+
+       current_class = current_class.Parent;
+       current_container = current_container.Parent;
+       
+       if (current_class != current_container) {
+               if (!(current_class is ClassPart) ||
+                   ((ClassPart) current_class).PartialContainer != current_container)
+                       throw new InternalErrorException ();
+       } else if (current_container is ClassPart)
+               current_container = ((ClassPart) current_class).PartialContainer;
+
+       return retval;
+}
+
 // <summary>
 //   Given the @class_name name, it creates a fully qualified name
 //   based on the containing declaration space
@@ -4836,11 +4986,11 @@ void Error_ExpectingTypeName (Location l, Expression expr)
 MemberName
 MakeName (MemberName class_name)
 {
-       string ns = current_namespace.FullName;
+       Namespace ns = current_namespace.NS;
 
        if (current_container.Name == ""){
-               if (ns != "")
-                       return new MemberName (new MemberName (ns), class_name);
+               if (ns.Name != "")
+                       return new MemberName (ns.MemberName, class_name);
                else
                        return class_name;
        } else {
@@ -4875,7 +5025,7 @@ Block declare_local_variables (Expression type, ArrayList variable_declarators,
 
        foreach (VariableDeclaration decl in variable_declarators){
 
-               if (implicit_block.AddVariable (type, decl.identifier, current_local_parameters, decl.Location) != null) {
+               if (implicit_block.AddVariable (type, decl.identifier, decl.Location) != null) {
                        if (decl.expression_or_array_initializer != null){
                                if (inits == null)
                                        inits = new ArrayList (4);
@@ -4921,8 +5071,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,
-                                                 current_local_parameters, decl.Location);
+               implicit_block.AddConstant (type, decl.identifier, (Expression) decl.expression_or_array_initializer, decl.Location);
        }
        
        return implicit_block;
@@ -5001,11 +5150,6 @@ void syntax_error (Location l, string msg)
        Report.Error (1003, l, "Syntax error, " + msg);
 }
 
-void output (string s)
-{
-       Console.WriteLine (s);
-}
-
 void note (string s)
 {
        // Used to put annotations
@@ -5025,6 +5169,8 @@ public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList def
        this.name = file.Name;
        this.file = file;
        current_container = RootContext.Tree.Types;
+       // TODO: Make RootContext.Tree.Types a PartialContainer.
+       current_class = current_container;
        current_container.NamespaceEntry = current_namespace;
        oob_stack = new Stack ();
        switch_stack = new Stack ();
@@ -5034,14 +5180,13 @@ public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList def
 
 public void parse ()
 {
-       // try {
+       try {
                if (yacc_verbose_flag > 1)
                        yyparse (lexer, new yydebug.yyDebugSimple ());
                else
                        yyparse (lexer);
                Tokenizer tokenizer = lexer as Tokenizer;
                tokenizer.cleanup ();
-#if FIXME
        } catch (Exception e){
                //
                // Removed for production use, use parser verbose to get the output.
@@ -5051,7 +5196,8 @@ public void parse ()
                if (yacc_verbose_flag > 0)
                        Console.WriteLine (e);
        }
-#endif
+
+       RootContext.Tree.Types.NamespaceEntry = null;
 }
 
 void CheckToken (int error, int yyToken, string msg)