2005-01-21 Alp Toker <alp@atoker.com>
[mono.git] / mcs / gmcs / cs-parser.jay
old mode 100755 (executable)
new mode 100644 (file)
index 454e601..3e31f50
@@ -8,6 +8,7 @@
 // Licensed under the terms of the GNU GPL
 //
 // (C) 2001 Ximian, Inc (http://www.ximian.com)
+// (C) 2004 Novell, Inc
 //
 // TODO:
 //   (1) Figure out why error productions dont work.  `type-declaration' is a
@@ -40,14 +41,7 @@ namespace Mono.CSharp
                ///   Current block is used to add statements as we find
                ///   them.  
                /// </summary>
-
-               Block      current_block;
-
-               /// <summary>
-                ///   If true, creates a toplevel block in the block production
-                ///   This is flagged by the delegate creation
-                /// </summary>
-                bool       create_toplevel_block;
+               Block      current_block, top_current_block;
 
                Delegate   current_delegate;
 
@@ -81,7 +75,7 @@ namespace Mono.CSharp
                ///
                Stack switch_stack;
 
-               public bool yacc_verbose_flag;
+               static public int yacc_verbose_flag;
 
                // Name of the file we are parsing
                public string name;
@@ -90,6 +84,14 @@ namespace Mono.CSharp
                /// The current file.
                ///
                SourceFile file;
+
+               ///
+               /// Temporary Xml documentation cache.
+               /// For enum types, we need one more temporary store.
+               ///
+               string tmpComment;
+               string enumTypeComment;
+
                
                
                /// Current attribute target
@@ -297,7 +299,13 @@ compilation_unit
        
 opt_EOF
        : /* empty */
+       {
+               Lexer.check_incorrect_doc_comment ();
+       }
        | EOF
+       {
+               Lexer.check_incorrect_doc_comment ();
+       }
        ;
 
 outer_declarations
@@ -317,7 +325,15 @@ using_directives
 
 using_directive
        : using_alias_directive
+       {
+               if (RootContext.Documentation != null)
+                       Lexer.doc_state = XmlCommentState.Allowed;
+       }
        | using_namespace_directive
+       {
+               if (RootContext.Documentation != null)
+                       Lexer.doc_state = XmlCommentState.Allowed;
+       }
        ;
 
 using_alias_directive
@@ -344,20 +360,25 @@ using_namespace_directive
 // detach them
 // 
 namespace_declaration
-       : opt_attributes NAMESPACE namespace_name
+       : 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");
                }
 
-               if (current_namespace.Parent != null && $3 is MemberAccess) {
-                       // Cannot use qualified namespace names in nested namespace declarations
-                       Report.Error (134, lexer.Location, "Cannot use qualified namespace names in nested namespace declarations");
+               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, (string) $3, lexer.Location);
+                       current_namespace, file, name.GetName (), lexer.Location);
          } 
          namespace_body opt_semicolon
          { 
@@ -388,6 +409,10 @@ namespace_name
 
 namespace_body
        : OPEN_BRACE
+         {
+               if (RootContext.Documentation != null)
+                       Lexer.doc_state = XmlCommentState.Allowed;
+         }
          opt_using_directives
          opt_namespace_member_declarations
          CLOSE_BRACE
@@ -476,7 +501,7 @@ global_attributes
 }
 
 opt_attributes
-        : /* empty */
+       : /* empty */ 
          {
                global_attrs_enabled = false;
                $$ = null;
@@ -486,7 +511,7 @@ opt_attributes
                global_attrs_enabled = false;
                $$ = $1;
          }
-        ;
+    ;
  
 
 attribute_sections
@@ -497,16 +522,23 @@ attribute_sections
                if (global_attrs_enabled) {
                        if (current_attr_target == "module") {
                                CodeGen.Module.AddAttributes (sect);
-                       $$ = null;
+                               $$ = null;
                        } else if (current_attr_target == "assembly") {
                                CodeGen.Assembly.AddAttributes (sect);
-                       $$ = null;
+                               $$ = null;
                        } else {
                                $$ = new Attributes (sect);
-               }
+                       }
+                       if ($$ == null) {
+                               if (RootContext.Documentation != null) {
+                                       Lexer.check_incorrect_doc_comment ();
+                                       Lexer.doc_state =
+                                               XmlCommentState.Allowed;
+                               }
+                       }
                } else {
                        $$ = new Attributes (sect);
-          }
+               }               
                current_attr_target = null;
       }
        | attribute_sections attribute_section
@@ -526,13 +558,13 @@ attribute_sections
                                        attrs = new Attributes (sect);
                                else
                                        attrs.AddAttributes (sect);                     
-               }
+                       }
                } else {
                        if (attrs == null)
                                attrs = new Attributes (sect);
                        else
                                attrs.AddAttributes (sect);
-               }
+               }               
                $$ = attrs;
                current_attr_target = null;
          }
@@ -689,6 +721,11 @@ named_argument_list
 
                $$ = args;
          }
+         | named_argument_list COMMA expression
+           {
+                 Report.Error (1016, lexer.Location, "Named attribute argument expected");
+                 $$ = null;
+               }
         ;
 
 named_argument
@@ -764,12 +801,18 @@ struct_declaration
                if ($7 != null)
                        current_class.Bases = (ArrayList) $7;
 
-               CheckDef (current_class.SetParameterInfo ((ArrayList) $8), current_class.Name,
-                         current_class.Location);
+               current_class.SetParameterInfo ((ArrayList) $8);
+
+               if (RootContext.Documentation != null)
+                       current_class.DocComment = Lexer.consume_doc_comment ();
 
                current_class.Register ();
          }
          struct_body
+         {
+               if (RootContext.Documentation != null)
+                       Lexer.doc_state = XmlCommentState.Allowed;
+         }
          opt_semicolon
          {
                $$ = current_class;
@@ -783,7 +826,12 @@ struct_declaration
        ;
 
 struct_body
-       : OPEN_BRACE opt_struct_member_declarations CLOSE_BRACE
+       : OPEN_BRACE
+         {
+               if (RootContext.Documentation != null)
+                       Lexer.doc_state = XmlCommentState.Allowed;
+         }
+         opt_struct_member_declarations CLOSE_BRACE
        ;
 
 opt_struct_member_declarations
@@ -822,15 +870,24 @@ constant_declaration
          constant_declarators
          SEMICOLON
          {
+               int modflags = (int) $2;
                foreach (VariableDeclaration constant in (ArrayList) $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);
+                               continue;
+                       }
 
                        Const c = new Const (
                                current_class, (Expression) $4, (string) constant.identifier, 
-                               (Expression) constant.expression_or_array_initializer, (int) $2
+                               (Expression) constant.expression_or_array_initializer, modflags
                                (Attributes) $1, l);
 
-                       CheckDef (current_container.AddConstant (c), c.Name, l);
+                       if (RootContext.Documentation != null) {
+                               c.DocComment = Lexer.consume_doc_comment ();
+                               Lexer.doc_state = XmlCommentState.Allowed;
+                       }
+                       current_container.AddConstant (c);
                }
          }
        ;
@@ -840,15 +897,15 @@ constant_declarators
          {
                ArrayList constants = new ArrayList (4);
                if ($1 != null)
-               constants.Add ($1);
+                       constants.Add ($1);
                $$ = constants;
          }
        | constant_declarators COMMA constant_declarator
          {
                if ($3 != null) {
-               ArrayList constants = (ArrayList) $1;
-               constants.Add ($3);
-         }
+                       ArrayList constants = (ArrayList) $1;
+                       constants.Add ($3);
+               }
          }
        ;
 
@@ -882,7 +939,11 @@ field_declaration
                                                 var.expression_or_array_initializer, 
                                                 (Attributes) $1, l);
 
-                       CheckDef (current_container.AddField (field), field.Name, l);
+                       if (RootContext.Documentation != null) {
+                               field.DocComment = Lexer.consume_doc_comment ();
+                               Lexer.doc_state = XmlCommentState.Allowed;
+                       }
+                       current_container.AddField (field);
                }
          }
        | opt_attributes
@@ -933,11 +994,18 @@ variable_initializer
          {
                $$ = new StackAlloc ((Expression) $2, (Expression) $4, lexer.Location);
          }
+       | STACKALLOC type
+         {
+               Report.Error (1575, lexer.Location, "A stackalloc expression requires [] after type");
+                $$ = null;
+         }
        ;
 
 method_declaration
        : method_header {
                iterator_container = (IIteratorContainer) $1;
+               if (RootContext.Documentation != null)
+                       Lexer.doc_state = XmlCommentState.NotAllowed;
          }
          method_body
          {
@@ -959,11 +1027,14 @@ method_declaration
                        }
                }
 
-               method.Block = (Block) $3;
-               CheckDef (current_container.AddMethod (method), method.Name, method.Location);
+               method.Block = (ToplevelBlock) $3;
+               current_container.AddMethod (method);
 
                current_local_parameters = null;
                iterator_container = null;
+
+               if (RootContext.Documentation != null)
+                       Lexer.doc_state = XmlCommentState.Allowed;
          }
        ;
 
@@ -1011,7 +1082,7 @@ method_header
                        generic = new GenericMethod (current_namespace, current_class,
                                                     name, lexer.Location);
 
-                       CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
+                       generic.SetParameterInfo ((ArrayList) $9);
                }
 
                method = new Method (current_class, generic, (Expression) $3, (int) $2, false,
@@ -1019,6 +1090,9 @@ method_header
 
                current_local_parameters = (Parameters) $6;
 
+               if (RootContext.Documentation != null)
+                       method.DocComment = Lexer.consume_doc_comment ();
+
                $$ = method;
          }
        | opt_attributes
@@ -1044,8 +1118,7 @@ method_header
                        generic = new GenericMethod (current_namespace, current_class,
                                                     name, lexer.Location);
 
-
-                       CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
+                       generic.SetParameterInfo ((ArrayList) $9);
                }
 
                method = new Method (current_class, generic, TypeManager.system_void_expr,
@@ -1054,6 +1127,9 @@ method_header
 
                current_local_parameters = (Parameters) $6;
 
+               if (RootContext.Documentation != null)
+                       method.DocComment = Lexer.consume_doc_comment ();
+
                $$ = method;
          }
        | opt_attributes
@@ -1071,6 +1147,10 @@ method_header
                                            lexer.Location);
 
                current_local_parameters = (Parameters) $6;
+
+               if (RootContext.Documentation != null)
+                       method.DocComment = Lexer.consume_doc_comment ();
+
                $$ = method;
          }
        ;
@@ -1148,6 +1228,13 @@ fixed_parameter
          {
                $$ = new Parameter ((Expression) $3, (string) $4, (Parameter.Modifier) $2, (Attributes) $1);
          }
+       | opt_attributes
+         opt_parameter_modifier
+         type
+         {
+               Report.Error (1001, lexer.Location, "Identifier expected");
+               $$ = null;
+         }
        | opt_attributes
          opt_parameter_modifier
          type
@@ -1155,6 +1242,16 @@ fixed_parameter
                CheckIdentifierToken (yyToken);
                $$ = null;
          }
+       | opt_attributes
+         opt_parameter_modifier
+         type
+         IDENTIFIER
+         ASSIGN
+         constant_expression
+          {
+                Report.Error (241, lexer.Location, "Default parameter specifiers are not permitted");
+                $$ = null;
+          }
        ;
 
 opt_parameter_modifier
@@ -1173,6 +1270,11 @@ parameter_array
                $$ = new Parameter ((Expression) $3, (string) $4, Parameter.Modifier.PARAMS, (Attributes) $1);
                note ("type must be a single-dimension array type"); 
          }
+       | opt_attributes PARAMS parameter_modifier type IDENTIFIER 
+         {
+               Report.Error (1611, lexer.Location, "The params parameter cannot be declared as ref or out");
+                $$ = null;
+         }
        | opt_attributes PARAMS type error {
                CheckIdentifierToken (yyToken);
                $$ = null;
@@ -1182,7 +1284,12 @@ parameter_array
 property_declaration
        : opt_attributes
          opt_modifiers
-         type namespace_or_type_name
+         type
+         namespace_or_type_name
+         {
+               if (RootContext.Documentation != null)
+                       tmpComment = Lexer.consume_doc_comment ();
+         }
          OPEN_BRACE 
          {
                implicit_value_parameter_type = (Expression) $3;
@@ -1200,23 +1307,28 @@ property_declaration
          CLOSE_BRACE
          { 
                Property prop;
-               Pair pair = (Pair) $7;
+               Pair pair = (Pair) $8;
                Accessor get_block = (Accessor) pair.First;
                Accessor set_block = (Accessor) pair.Second;
 
+               Location loc = (Location) $7;
                MemberName name = (MemberName) $4;
+
                if (name.TypeArguments != null)
                        syntax_error (lexer.Location, "a property can't have type arguments");
 
-               Location loc = (Location) $6;
                prop = new Property (current_container, (Expression) $3, (int) $2, false,
                                     name, (Attributes) $1, get_block, set_block, loc);
                if (SimpleIteratorContainer.Simple.Yields)
                        prop.SetYields ();
                
-               CheckDef (current_container.AddProperty (prop), prop.Name, loc);
+               current_container.AddProperty (prop);
                implicit_value_parameter_type = null;
                iterator_container = null;
+
+               if (RootContext.Documentation != null)
+                       prop.DocComment = ConsumeStoredComment ();
+
          }
        ;
 
@@ -1242,7 +1354,7 @@ opt_set_accessor_declaration
        ;
 
 get_accessor_declaration
-       : opt_attributes GET
+       : opt_attributes opt_modifiers GET
          {
                // If this is not the case, then current_local_parameters has already
                // been set in indexer_declaration
@@ -1254,14 +1366,18 @@ get_accessor_declaration
          }
           accessor_body
          {
-               $$ = new Accessor ((Block) $4, (Attributes) $1);
+               $$ = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, lexer.Location);
                current_local_parameters = null;
                lexer.PropertyParsing = true;
+
+               if (RootContext.Documentation != null)
+                       if (Lexer.doc_state == XmlCommentState.Error)
+                               Lexer.doc_state = XmlCommentState.NotAllowed;
          }
        ;
 
 set_accessor_declaration
-       : opt_attributes SET 
+       : opt_attributes opt_modifiers SET 
          {
                Parameter [] args;
                Parameter implicit_value_parameter = new Parameter (
@@ -1291,9 +1407,13 @@ set_accessor_declaration
          }
          accessor_body
          {
-               $$ = new Accessor ((Block) $4, (Attributes) $1);
+               $$ = new Accessor ((ToplevelBlock) $5, (int) $2, (Attributes) $1, lexer.Location);
                current_local_parameters = null;
                lexer.PropertyParsing = true;
+
+               if (RootContext.Documentation != null
+                       && Lexer.doc_state == XmlCommentState.Error)
+                       Lexer.doc_state = XmlCommentState.NotAllowed;
          }
        ;
 
@@ -1337,13 +1457,22 @@ interface_declaration
                if ($7 != null)
                        current_class.Bases = (ArrayList) $7;
 
-               CheckDef (current_class.SetParameterInfo ((ArrayList) $8),
-                         current_class.Name, current_class.Location);
+               current_class.SetParameterInfo ((ArrayList) $8);
+
+               if (RootContext.Documentation != null) {
+                       current_class.DocComment = Lexer.consume_doc_comment ();
+                       Lexer.doc_state = XmlCommentState.Allowed;
+               }
 
                current_class.Register ();
          }
-         interface_body opt_semicolon
+         interface_body
          { 
+               if (RootContext.Documentation != null)
+                       Lexer.doc_state = XmlCommentState.Allowed;
+         }
+         opt_semicolon 
+         {
                $$ = current_class;
 
                current_container = current_container.Parent;
@@ -1375,26 +1504,38 @@ interface_member_declaration
          { 
                Method m = (Method) $1;
 
-               CheckDef (current_container.AddMethod (m), m.Name, m.Location);
+               current_container.AddMethod (m);
+
+               if (RootContext.Documentation != null)
+                       Lexer.doc_state = XmlCommentState.Allowed;
          }
        | interface_property_declaration        
          { 
                Property p = (Property) $1;
 
-               CheckDef (current_container.AddProperty (p), p.Name, p.Location);
-          }
+               current_container.AddProperty (p);
+
+               if (RootContext.Documentation != null)
+                       Lexer.doc_state = XmlCommentState.Allowed;
+         }
        | interface_event_declaration 
           { 
                if ($1 != null){
                        Event e = (Event) $1;
-                       CheckDef (current_container.AddEvent (e), e.Name, lexer.Location);
+                       current_container.AddEvent (e);
                }
+
+               if (RootContext.Documentation != null)
+                       Lexer.doc_state = XmlCommentState.Allowed;
          }
        | interface_indexer_declaration
          { 
                Indexer i = (Indexer) $1;
 
                current_container.AddIndexer (i);
+
+               if (RootContext.Documentation != null)
+                       Lexer.doc_state = XmlCommentState.Allowed;
          }
        ;
 
@@ -1429,11 +1570,13 @@ interface_method_declaration
                        generic = new GenericMethod (current_namespace, current_class,
                                                     name, lexer.Location);
 
-                       CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
+                       generic.SetParameterInfo ((ArrayList) $9);
                }
 
                $$ = new Method (current_class, generic, (Expression) $3, (int) $2, true, name,
                                 (Parameters) $6, (Attributes) $1, lexer.Location);
+               if (RootContext.Documentation != null)
+                       ((Method) $$).DocComment = Lexer.consume_doc_comment ();
          }
        | opt_attributes opt_new VOID namespace_or_type_name
          OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
@@ -1456,11 +1599,13 @@ interface_method_declaration
                        generic = new GenericMethod (current_namespace, current_class,
                                                     name, lexer.Location);
 
-                       CheckDef (generic.SetParameterInfo ((ArrayList) $9), name.Name, lexer.Location);
+                       generic.SetParameterInfo ((ArrayList) $9);
                }
 
                $$ = new Method (current_class, generic, TypeManager.system_void_expr, (int) $2,
                                 true, name, (Parameters) $6, (Attributes) $1, lexer.Location);
+               if (RootContext.Documentation != null)
+                       ((Method) $$).DocComment = Lexer.consume_doc_comment ();
          }
        ;
 
@@ -1479,6 +1624,8 @@ interface_property_declaration
                $$ = new Property (current_class, (Expression) $3, (int) $2, true,
                                   new MemberName ((string) $4), (Attributes) $1,
                                   pinfo.Get, pinfo.Set, lexer.Location);
+               if (RootContext.Documentation != null)
+                       ((Property) $$).DocComment = Lexer.consume_doc_comment ();
          }
        | opt_attributes
          opt_new
@@ -1489,12 +1636,14 @@ interface_property_declaration
        ;
 
 interface_accessors
-       : opt_attributes GET SEMICOLON          { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null); }
-       | opt_attributes SET SEMICOLON          { $$ = new InterfaceAccessorInfo (false, true, null, (Attributes) $1); }
-       | opt_attributes GET SEMICOLON opt_attributes SET SEMICOLON 
-         { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $1, (Attributes) $3); }
-       | opt_attributes SET SEMICOLON opt_attributes GET SEMICOLON
-         { $$ = new InterfaceAccessorInfo (true, true, (Attributes) $3, (Attributes) $1); }
+       : opt_attributes opt_modifiers GET SEMICOLON    
+       { $$ = new InterfaceAccessorInfo (true, false, (Attributes) $1, null, (int) $2, 0, lexer.Location, lexer.Location); }
+       | 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); }
        ;
 
 interface_event_declaration
@@ -1503,6 +1652,8 @@ interface_event_declaration
                $$ = new EventField (current_class, (Expression) $4, (int) $2, true,
                                     new MemberName ((string) $5), null,
                                     (Attributes) $1, lexer.Location);
+               if (RootContext.Documentation != null)
+                       ((EventField) $$).DocComment = Lexer.consume_doc_comment ();
          }
        | opt_attributes opt_new EVENT type error {
                CheckIdentifierToken (yyToken);
@@ -1529,9 +1680,12 @@ interface_indexer_declaration
          {
                InterfaceAccessorInfo info = (InterfaceAccessorInfo) $10;
 
-               $$ = new Indexer (current_class, (Expression) $3, (int) $2, true,
-                                 MemberName.Null, (Parameters) $6, (Attributes) $1,
+               $$ = new Indexer (current_class, (Expression) $3,
+                                 new MemberName (TypeContainer.DefaultIndexerName),
+                                 (int) $2, true, (Parameters) $6, (Attributes) $1,
                                  info.Get, info.Set, lexer.Location);
+               if (RootContext.Documentation != null)
+                       ((Indexer) $$).DocComment = ConsumeStoredComment ();
          }
        ;
 
@@ -1544,10 +1698,19 @@ operator_declaration
          {
                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);
+               if (decl.arg2type != null)
+                       param_list[1] = new Parameter (decl.arg2type, decl.arg2name, Parameter.Modifier.NONE, null);
+
                Operator op = new Operator (
-                       current_class, decl.optype, decl.ret_type, (int) $2, decl.arg1type,
-                       decl.arg1name, decl.arg2type, decl.arg2name, (Block) $5,
-                       (Attributes) $1, decl.location);
+                       current_class, decl.optype, decl.ret_type, (int) $2, 
+                       new Parameters (param_list, null, decl.location),
+                       (ToplevelBlock) $5, (Attributes) $1, decl.location);
+
+               if (RootContext.Documentation != null)
+                       op.DocComment = ConsumeStoredComment ();
 
                if (SimpleIteratorContainer.Simple.Yields)
                        op.SetYields ();
@@ -1578,12 +1741,18 @@ operator_declarator
                        op = Operator.OpType.UnaryNegation;
 
                Parameter [] pars = new Parameter [1];
+               Expression type = (Expression) $5;
 
-               pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
+               pars [0] = new Parameter (type, (string) $6, Parameter.Modifier.NONE, null);
 
                current_local_parameters = new Parameters (pars, null, lexer.Location);
 
-               $$ = new OperatorDeclaration (op, (Expression) $1, (Expression) $5, (string) $6,
+               if (RootContext.Documentation != null) {
+                       tmpComment = Lexer.consume_doc_comment ();
+                       Lexer.doc_state = XmlCommentState.Allowed;
+               }
+
+               $$ = new OperatorDeclaration (op, (Expression) $1, type, (string) $6,
                                              null, null, lexer.Location);
        }
        | type OPERATOR overloadable_operator
@@ -1592,18 +1761,26 @@ operator_declarator
                type IDENTIFIER 
          CLOSE_PARENS
         {
-              CheckBinaryOperator ((Operator.OpType) $3);
+               CheckBinaryOperator ((Operator.OpType) $3);
+
+               Parameter [] pars = new Parameter [2];
 
-              Parameter [] pars = new Parameter [2];
+               Expression typeL = (Expression) $5;
+               Expression typeR = (Expression) $8;
 
-              pars [0] = new Parameter ((Expression) $5, (string) $6, Parameter.Modifier.NONE, null);
-              pars [1] = new Parameter ((Expression) $8, (string) $9, Parameter.Modifier.NONE, null);
+              pars [0] = new Parameter (typeL, (string) $6, Parameter.Modifier.NONE, null);
+              pars [1] = new Parameter (typeR, (string) $9, Parameter.Modifier.NONE, null);
 
               current_local_parameters = new Parameters (pars, null, lexer.Location);
+
+               if (RootContext.Documentation != null) {
+                       tmpComment = Lexer.consume_doc_comment ();
+                       Lexer.doc_state = XmlCommentState.Allowed;
+               }
               
               $$ = new OperatorDeclaration ((Operator.OpType) $3, (Expression) $1, 
-                                            (Expression) $5, (string) $6,
-                                            (Expression) $8, (string) $9, lexer.Location);
+                                            typeL, (string) $6,
+                                            typeR, (string) $9, lexer.Location);
         }
        | conversion_operator_declarator
        ;
@@ -1676,10 +1853,13 @@ constructor_declaration
          constructor_body
          { 
                Constructor c = (Constructor) $3;
-               c.Block = (Block) $4;
+               c.Block = (ToplevelBlock) $4;
                c.OptAttributes = (Attributes) $1;
                c.ModFlags = (int) $2;
        
+               if (RootContext.Documentation != null)
+                       c.DocComment = ConsumeStoredComment ();
+
                if (c.Name == current_container.Basename){
                        if ((c.ModFlags & Modifiers.STATIC) != 0){
                                if ((c.ModFlags & Modifiers.Accessibility) != 0){
@@ -1707,28 +1887,36 @@ constructor_declaration
                        }
                } else {
                        // We let another layer check the validity of the constructor.
-                       Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
+                       //Console.WriteLine ("{0} and {1}", c.Name, current_container.Basename);
                }
 
-               CheckDef (current_container.AddConstructor (c), c.Name, c.Location);
+               current_container.AddConstructor (c);
 
                current_local_parameters = null;
+               if (RootContext.Documentation != null)
+                       Lexer.doc_state = XmlCommentState.Allowed;
          }
        ;
 
 constructor_declarator
-       : IDENTIFIER 
+       : IDENTIFIER
+         {
+               if (RootContext.Documentation != null) {
+                       tmpComment = Lexer.consume_doc_comment ();
+                       Lexer.doc_state = XmlCommentState.Allowed;
+               }
+         }
          OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS 
          {
                oob_stack.Push (lexer.Location);
 
-               current_local_parameters = (Parameters) $3;
+               current_local_parameters = (Parameters) $4;
          }
          opt_constructor_initializer
          {
                Location l = (Location) oob_stack.Pop ();
-               $$ = new Constructor (current_class, (string) $1, 0, (Parameters) $3,
-                                     (ConstructorInitializer) $6, l);
+               $$ = new Constructor (current_class, (string) $1, 0, (Parameters) $4,
+                                     (ConstructorInitializer) $7, l);
          }
        ;
 
@@ -1764,11 +1952,18 @@ opt_finalizer
         ;
         
 destructor_declaration
-       : opt_attributes opt_finalizer TILDE IDENTIFIER OPEN_PARENS CLOSE_PARENS block
+       : opt_attributes opt_finalizer TILDE 
+         {
+               if (RootContext.Documentation != null) {
+                       tmpComment = Lexer.consume_doc_comment ();
+                       Lexer.doc_state = XmlCommentState.NotAllowed;
+               }
+         }
+         IDENTIFIER OPEN_PARENS CLOSE_PARENS block
          {
-               if ((string) $4 != current_container.Basename){
+               if ((string) $5 != current_container.Basename){
                        Report.Error (574, lexer.Location, "Name of destructor must match name of class");
-               } else if (!(current_container is Class)){
+               } else if (current_container.Kind != Kind.Class){
                        Report.Error (575, lexer.Location, "Destructors are only allowed in class types");
                } else {
                        Location l = lexer.Location;
@@ -1790,19 +1985,13 @@ destructor_declaration
                        Method d = new Destructor (
                                current_class, TypeManager.system_void_expr, m, "Finalize", 
                                new Parameters (null, null, l), (Attributes) $1, l);
+                       if (RootContext.Documentation != null)
+                               d.DocComment = ConsumeStoredComment ();
                  
-                       d.Block = (Block) $7;
-                       CheckDef (current_container.AddMethod (d), d.Name, d.Location);
+                       d.Block = (ToplevelBlock) $8;
+                       current_container.AddMethod (d);
                }
          }
-       | opt_attributes opt_modifiers EVENT type member_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS block {
-               string mn = (string) $5;
-
-               if (mn.IndexOf ('.') != -1)
-                       Report.Error (71, lexer.Location, "Explicit implementation of events requires property syntax");
-               else 
-                       Report.Error (71, lexer.Location, "Event declaration should use property syntax");
-         }
        ;
 
 event_declaration
@@ -1814,13 +2003,17 @@ event_declaration
 
                        MemberName name = new MemberName (var.identifier);
 
-                       Event e = new EventField (current_class, (Expression) $4, (int) $2,
-                                                 false, name,
-                                                 var.expression_or_array_initializer,
-                                                 (Attributes) $1, lexer.Location);
+                       Event e = new EventField (
+                               current_class, (Expression) $4, (int) $2, false, name,
+                               var.expression_or_array_initializer, (Attributes) $1,
+                               lexer.Location);
+
+                       current_container.AddEvent (e);
 
-                       CheckDef (current_container.AddEvent (e), e.Name, e.Location);
-                                      
+                       if (RootContext.Documentation != null) {
+                               e.DocComment = Lexer.consume_doc_comment ();
+                               Lexer.doc_state = XmlCommentState.Allowed;
+                       }
                }
          }
        | opt_attributes
@@ -1844,20 +2037,36 @@ event_declaration
                        Report.Error (65, lexer.Location, "Event must have both add and remove accesors");
                        $$ = null;
                } else {
-               Pair pair = (Pair) $8;
-
-               MemberName name = (MemberName) $5;
-               if (name.TypeArguments != null)
-                       syntax_error (lexer.Location, "an event can't have type arguments");
+                       Pair pair = (Pair) $8;
+                       
+                       MemberName name = (MemberName) $5;
+
+                       if (name.TypeArguments != null)
+                               syntax_error (lexer.Location, "an event can't have type arguments");
+
+                       Event e = new EventProperty (
+                               current_class, (Expression) $4, (int) $2, false, name, null,
+                               (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second,
+                               loc);
+                       if (RootContext.Documentation != null) {
+                               e.DocComment = Lexer.consume_doc_comment ();
+                               Lexer.doc_state = XmlCommentState.Allowed;
+                       }
 
-               Event e = new EventProperty (current_class, (Expression) $4, (int) $2,
-                                            false, name, null, (Attributes) $1,
-                                            (Accessor) pair.First, (Accessor) pair.Second,
-                                            loc);
-               
-               CheckDef (current_container.AddEvent (e), e.Name, loc);
-               implicit_value_parameter_type = null;
+                       current_container.AddEvent (e);
+                       implicit_value_parameter_type = null;
+               }
          }
+       | opt_attributes opt_modifiers EVENT type namespace_or_type_name OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS block {
+               MemberName mn = (MemberName) $5;
+
+               if (mn.Left != null)
+                       Report.Error (71, lexer.Location, "Explicit implementation of events requires property syntax");
+               else 
+                       Report.Error (71, lexer.Location, "Event declaration should use property syntax");
+
+               if (RootContext.Documentation != null)
+                       Lexer.doc_state = XmlCommentState.Allowed;
          }
        ;
 
@@ -1872,6 +2081,12 @@ event_accessor_declarations
        }       
        | add_accessor_declaration  { $$ = null; } 
        | remove_accessor_declaration { $$ = null; } 
+       | error
+       { 
+               Report.Error (1055, lexer.Location, "An add or remove accessor expected");
+               $$ = null;
+       }
+       | { $$ = null; }
        ;
 
 add_accessor_declaration
@@ -1889,7 +2104,7 @@ add_accessor_declaration
          }
           block
          {
-               $$ = new Accessor ((Block) $4, (Attributes) $1);
+               $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, lexer.Location);
                lexer.EventParsing = true;
          }
        | opt_attributes ADD error {
@@ -1913,7 +2128,7 @@ remove_accessor_declaration
          }
           block
          {
-               $$ = new Accessor ((Block) $4, (Attributes) $1);
+               $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, lexer.Location);
                lexer.EventParsing = true;
          }
        | opt_attributes REMOVE error {
@@ -1954,17 +2169,17 @@ indexer_declaration
 
                MemberName name;
                if (decl.interface_type != null)
-                       name = new MemberName (decl.interface_type, "", null);
+                       name = new MemberName (decl.interface_type,
+                                              TypeContainer.DefaultIndexerName, null);
                else
-                       name = MemberName.Null;
+                       name = new MemberName (TypeContainer.DefaultIndexerName);
 
-               indexer = new Indexer (current_class, decl.type, (int) $2, false,
-                                      name, decl.param_list, (Attributes) $1,
+               indexer = new Indexer (current_class, decl.type, name,
+                                      (int) $2, false, decl.param_list, (Attributes) $1,
                                       get_block, set_block, loc);
+               if (RootContext.Documentation != null)
+                       indexer.DocComment = ConsumeStoredComment ();
 
-               // Note that there is no equivalent of CheckDef for this case
-               // We shall handle this in semantic analysis
-               
                current_container.AddIndexer (indexer);
                
                current_local_parameters = null;
@@ -1983,6 +2198,10 @@ indexer_declarator
                } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
                        Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
                }
+               if (RootContext.Documentation != null) {
+                       tmpComment = Lexer.consume_doc_comment ();
+                       Lexer.doc_state = XmlCommentState.Allowed;
+               }
 
                $$ = new IndexerDeclaration ((Expression) $1, null, pars);
          }
@@ -1996,11 +2215,17 @@ indexer_declarator
                } else if (pars.FixedParameters == null && pars.ArrayParameter == null){
                        Report.Error (1551, lexer.Location, "Indexers must have at least one parameter");
                }
+
                MemberName name = (MemberName) $2;
                if (name.TypeArguments != null)
                        syntax_error (lexer.Location, "an indexer can't have type arguments");
 
                $$ = new IndexerDeclaration ((Expression) $1, name, pars);
+
+               if (RootContext.Documentation != null) {
+                       tmpComment = Lexer.consume_doc_comment ();
+                       Lexer.doc_state = XmlCommentState.Allowed;
+               }
          }
        ;
 
@@ -2008,7 +2233,10 @@ enum_declaration
        : opt_attributes
          opt_modifiers
          ENUM IDENTIFIER 
-         opt_enum_base
+         opt_enum_base {
+               if (RootContext.Documentation != null)
+                       enumTypeComment = Lexer.consume_doc_comment ();
+         }
          enum_body
          opt_semicolon
          { 
@@ -2018,17 +2246,18 @@ enum_declaration
                Enum e = new Enum (current_namespace, current_container, (Expression) $5, (int) $2,
                                   full_name, (Attributes) $1, enum_location);
                
-               foreach (VariableDeclaration ev in (ArrayList) $6) {
-                       Location loc = (Location) ev.Location;
-
-                       CheckDef (e.AddEnumMember (ev.identifier, 
-                                                  (Expression) ev.expression_or_array_initializer,
-                                                  loc, ev.OptAttributes),
-                                 ev.identifier, loc);
+               if (RootContext.Documentation != null)
+                       e.DocComment = enumTypeComment;
+
+               foreach (VariableDeclaration ev in (ArrayList) $7) {
+                       e.AddEnumMember (ev.identifier, 
+                                        (Expression) ev.expression_or_array_initializer,
+                                        ev.Location, ev.OptAttributes,
+                                        ev.DocComment);
                }
 
-               string name = full_name.GetName (false);
-               CheckDef (current_container.AddEnum (e), name, enum_location);
+               string name = full_name.GetName ();
+               current_container.AddEnum (e);
                RootContext.Tree.RecordDecl (name, e);
 
          }
@@ -2040,9 +2269,20 @@ opt_enum_base
        ;
 
 enum_body
-       : OPEN_BRACE opt_enum_member_declarations CLOSE_BRACE
+       : OPEN_BRACE
          {
-               $$ = $2;
+               if (RootContext.Documentation != null)
+                       Lexer.doc_state = XmlCommentState.Allowed;
+         }
+         opt_enum_member_declarations
+         {
+               // here will be evaluated after CLOSE_BLACE is consumed.
+               if (RootContext.Documentation != null)
+                       Lexer.doc_state = XmlCommentState.Allowed;
+         }
+         CLOSE_BRACE
+         {
+               $$ = $3;
          }
        ;
 
@@ -2072,15 +2312,31 @@ enum_member_declarations
 enum_member_declaration
        : opt_attributes IDENTIFIER 
          {
-               $$ = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
+               VariableDeclaration vd = new VariableDeclaration ((string) $2, null, lexer.Location, (Attributes) $1);
+
+               if (RootContext.Documentation != null) {
+                       vd.DocComment = Lexer.consume_doc_comment ();
+                       Lexer.doc_state = XmlCommentState.Allowed;
+               }
+
+               $$ = vd;
          }
        | opt_attributes IDENTIFIER
          {
-                 $$ = lexer.Location;
+               $$ = lexer.Location;
+               if (RootContext.Documentation != null) {
+                       tmpComment = Lexer.consume_doc_comment ();
+                       Lexer.doc_state = XmlCommentState.NotAllowed;
+               }
          }
           ASSIGN expression
          { 
-               $$ = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
+               VariableDeclaration vd = new VariableDeclaration ((string) $2, $5, lexer.Location, (Attributes) $1);
+
+               if (RootContext.Documentation != null)
+                       vd.DocComment = ConsumeStoredComment ();
+
+               $$ = vd;
          }
        ;
 
@@ -2091,11 +2347,17 @@ delegate_declaration
          OPEN_PARENS opt_formal_parameter_list CLOSE_PARENS
          {
                Location l = lexer.Location;
-               Delegate del = new Delegate (
-                       current_namespace, current_container, (Expression) $4, (int) $2,
-                       MakeName ((MemberName) $5), (Parameters) $7, (Attributes) $1, l);
-                 
-               CheckDef (current_container.AddDelegate (del), del.Name, l);
+               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;
 
@@ -2107,7 +2369,7 @@ delegate_declaration
          }
          SEMICOLON
          {
-               CheckDef (current_delegate.SetParameterInfo ((ArrayList) $9), current_delegate.Name, current_delegate.Location);
+               current_delegate.SetParameterInfo ((ArrayList) $9);
 
                current_delegate = null;
          }
@@ -2117,12 +2379,19 @@ delegate_declaration
          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, MakeName ((MemberName) $5), 
+                       TypeManager.system_void_expr, (int) $2, name,
                        (Parameters) $7, (Attributes) $1, l);
 
-               CheckDef (current_container.AddDelegate (del), del.Name, 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;
 
@@ -2134,7 +2403,7 @@ delegate_declaration
          }
          SEMICOLON
          {
-               CheckDef (current_delegate.SetParameterInfo ((ArrayList) $9), current_delegate.Name, current_delegate.Location);
+               current_delegate.SetParameterInfo ((ArrayList) $9);
 
                current_delegate = null;
          }
@@ -2194,6 +2463,7 @@ type
        | pointer_type    
        ;
 
+
 pointer_type
        : type STAR
          {
@@ -2494,7 +2764,7 @@ element_access
                // Foo.Bar.Blah i;
                // SimpleName is when you have
                // Blah i;
-
+                 
                Expression expr = (Expression) $1;  
                if (expr is ComposedCast){
                        $$ = new ComposedCast (expr, (string) $2, lexer.Location);
@@ -2543,7 +2813,7 @@ base_access
                $$ = new BaseIndexerAccess ((ArrayList) $3, lexer.Location);
          }
        | BASE error {
-               Report.Error (175, "Use of keyword `base' is not valid in this context");
+               Report.Error (175, lexer.Location, "Use of keyword `base' is not valid in this context");
                $$ = null;
          }
        ;
@@ -2587,6 +2857,11 @@ array_creation_expression
          {
                $$ = new ArrayCreation ((Expression) $2, (string) $3, (ArrayList) $4, lexer.Location);
          }
+       | NEW error
+         {
+               Report.Error (1031, lexer.Location, "Type expected");
+                $$ = null;
+         }          
        | NEW type error 
          {
                Report.Error (1526, lexer.Location, "new expression requires () or [] after type");
@@ -2678,11 +2953,26 @@ variable_initializer_list
          }
        ;
 
+void_pointer_expression
+       : void_pointer_expression STAR
+         {
+               $$ = new ComposedCast ((Expression) $1, "*", lexer.Location);
+         }
+       | VOID STAR
+         {
+               $$ = new ComposedCast (TypeManager.system_void_expr, "*", lexer.Location);;
+         }
+       ;
+
 typeof_expression
        : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
          {
                $$ = new TypeOfVoid (lexer.Location);
          }
+       | TYPEOF OPEN_PARENS void_pointer_expression CLOSE_PARENS
+         {
+               $$ = new TypeOf ((Expression) $3, lexer.Location);
+         }
        | TYPEOF OPEN_PARENS
          {
                lexer.TypeOfParsing = true;
@@ -2728,25 +3018,32 @@ anonymous_method_expression
        : DELEGATE opt_anonymous_method_signature {
                oob_stack.Push (current_local_parameters);
                current_local_parameters = (Parameters)$2;
-               create_toplevel_block = true;
+
+               // Force the next block to be created as a ToplevelBlock
+               oob_stack.Push (current_block);
+               oob_stack.Push (top_current_block);
+               oob_stack.Push (lexer.Location);
+               current_block = null;
          } block {
-               if (true){
-                       Report.Error (-213, lexer.Location, "Anonymous methods are not supported in this branch");
-                       $$ = null;
-               } else {
-                       create_toplevel_block = false;
+               Location loc = (Location) oob_stack.Pop ();
+               top_current_block = (Block) oob_stack.Pop ();
+               current_block = (Block) oob_stack.Pop ();
                        if (RootContext.Version == LanguageVersion.ISO_1){
-                               Report.FeatureIsNotStandardized ("anonymous methods");
+                               Report.FeatureIsNotStandardized (lexer.Location, "anonymous methods");
                                $$ = null;
-                       } else 
-                               $$ = new AnonymousMethod ((Parameters) $2, (Block) $4, lexer.Location);
+               } else  {
+                       ToplevelBlock anon_block = (ToplevelBlock) $4;
+
+                       anon_block.Parent = current_block;
+                       $$ = new AnonymousMethod ((Parameters) $2, (ToplevelBlock) top_current_block, 
+                               anon_block, loc);
+               }
                        current_local_parameters = (Parameters) oob_stack.Pop ();
                }
-         }
        ;
 
 opt_anonymous_method_signature
-       : /* empty */                   { $$ = Parameters.EmptyReadOnlyParameters; }
+       : /* empty */                   { $$ = null; } 
        | anonymous_method_signature
        ;
 
@@ -2786,7 +3083,11 @@ anonymous_method_parameter_list
 
 anonymous_method_parameter
        : opt_parameter_modifier type IDENTIFIER {
-               $$ = new Parameter ((Expression) $2, (string) $2, (Parameter.Modifier) $1, null);
+               $$ = new Parameter ((Expression) $2, (string) $3, (Parameter.Modifier) $1, null);
+         }
+       | PARAMS type IDENTIFIER {
+               Report.Error (-221, lexer.Location, "params modifier not allowed in anonymous method declaration");
+               $$ = null;
          }
        ;
 
@@ -3166,12 +3467,20 @@ class_declaration
                        current_class.Bases = (ArrayList) $7;
                }
 
-               CheckDef (current_class.SetParameterInfo ((ArrayList) $8),
-                         current_class.Name, current_class.Location);
+               current_class.SetParameterInfo ((ArrayList) $8);
+
+               if (RootContext.Documentation != null) {
+                       current_class.DocComment = Lexer.consume_doc_comment ();
+                       Lexer.doc_state = XmlCommentState.Allowed;
+               }
 
                current_class.Register ();
          }
-         class_body 
+         class_body
+         {
+               if (RootContext.Documentation != null)
+                       Lexer.doc_state = XmlCommentState.Allowed;
+         }
          opt_semicolon 
          {
                $$ = current_class;
@@ -3303,8 +3612,9 @@ type_parameter_constraint
 block
        : OPEN_BRACE 
          {
-               if (current_block == null || create_toplevel_block){
-                       current_block = new ToplevelBlock (current_local_parameters, lexer.Location);
+               if (current_block == null){
+                       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);
@@ -3317,6 +3627,8 @@ block
                $$ = current_block;
                current_block.SetEndLocation (lexer.Location);
                current_block = current_block.Parent;
+               if (current_block == null)
+                       top_current_block = null;
          }
        ;
 
@@ -3937,7 +4249,7 @@ yield_statement
                        $$ = null;
                }
                if (RootContext.Version == LanguageVersion.ISO_1){
-                       Report.FeatureIsNotStandardized ("yield statement");
+                       Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
                        $$ = null;
                }
                if (iterator_container == null){
@@ -3956,7 +4268,7 @@ yield_statement
                        $$ = null;
                }
                if (RootContext.Version == LanguageVersion.ISO_1){
-                       Report.FeatureIsNotStandardized ("yield statement");
+                       Report.FeatureIsNotStandardized (lexer.Location, "yield statement");
                        $$ = null;
                }
                if (iterator_container == null){
@@ -3978,19 +4290,23 @@ try_statement
        : TRY block catch_clauses 
        {
                Catch g = null;
-               ArrayList s = new ArrayList (4);
                
-               foreach (Catch cc in (ArrayList) $3) {
-                       if (cc.IsGeneral)
+               ArrayList c = (ArrayList)$3;
+               for (int i = 0; i < c.Count; ++i) {
+                       Catch cc = (Catch) c [i];
+                       if (cc.IsGeneral) {
+                               if (i != c.Count - 1)
+                                       Report.Error (1017, cc.loc, "Empty catch block must be the last in a series of catch blocks");
                                g = cc;
-                       else
-                               s.Add (cc);
+                               c.RemoveAt (i);
+                               i--;
+                       }
                }
 
                // Now s contains the list of specific catch clauses
                // and g contains the general one.
                
-               $$ = new Try ((Block) $2, s, g, null, lexer.Location);
+               $$ = new Try ((Block) $2, c, g, null, ((Block) $2).loc);
        }
        | TRY block opt_catch_clauses FINALLY block
          {
@@ -4007,7 +4323,7 @@ try_statement
                        }
                }
 
-               $$ = new Try ((Block) $2, s, g, (Block) $5, lexer.Location);
+               $$ = new Try ((Block) $2, s, g, (Block) $5, ((Block) $2).loc);
          }
        | TRY block error 
          {
@@ -4084,7 +4400,7 @@ catch_clause
                }
 
 
-               $$ = new Catch (type, id , (Block) $4, lexer.Location);
+               $$ = new Catch (type, id , (Block) $4, ((Block) $4).loc);
        }
         ;
 
@@ -4131,12 +4447,14 @@ fixed_statement
          type fixed_pointer_declarators 
          CLOSE_PARENS 
          {
-               Block assign_block = new Block (current_block, Block.Flags.Implicit);
                ArrayList list = (ArrayList) $4;
                Expression type = (Expression) $3;
                Location l = lexer.Location;
                int top = list.Count;
 
+               Block assign_block = new Block (current_block);
+               current_block = assign_block;
+
                for (int i = 0; i < top; i++){
                        Pair p = (Pair) list [i];
                        LocalInfo v;
@@ -4150,32 +4468,40 @@ fixed_statement
                        p.First = v;
                        list [i] = p;
                }
-               current_block.AddStatement (assign_block);
-               current_block = assign_block;
-               oob_stack.Push (assign_block);
+
                oob_stack.Push (l);
          }
          embedded_statement 
          {
                Location l = (Location) oob_stack.Pop ();
-               oob_stack.Pop ();
 
-               $$ = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
+               Fixed f = new Fixed ((Expression) $3, (ArrayList) $4, (Statement) $7, l);
+
+               if (RootContext.WarningLevel >= 3){
+                       if ($7 == EmptyStatement.Value)
+                               Report.Warning (642, lexer.Location, "Possible mistaken empty statement");
+               }
+
+               current_block.AddStatement (f);
+               while (current_block.Implicit)
+                       current_block = current_block.Parent;
+               $$ = current_block;
+               current_block = current_block.Parent;
          }
        ;
 
 fixed_pointer_declarators
        : fixed_pointer_declarator      { 
-               ArrayList declarators = new ArrayList (4); 
+               ArrayList declarators = new ArrayList (4);
                if ($1 != null)
-               declarators.Add ($1);
+                       declarators.Add ($1);
                $$ = declarators;
          }
        | fixed_pointer_declarators COMMA fixed_pointer_declarator
          {
                ArrayList declarators = (ArrayList) $1;
                if ($3 != null)
-               declarators.Add ($3);
+                       declarators.Add ($3);
                $$ = declarators;
          }
        ;
@@ -4283,6 +4609,7 @@ public class VariableDeclaration {
        public object expression_or_array_initializer;
        public Location Location;
        public Attributes OptAttributes;
+       public string DocComment;
 
        public VariableDeclaration (string id, object eoai, Location l, Attributes opt_attrs)
        {
@@ -4305,13 +4632,19 @@ public class InterfaceAccessorInfo {
         public readonly Accessor Get, Set;
 
         public InterfaceAccessorInfo (bool has_get, bool has_set,
-                                      Attributes get_attrs, Attributes set_attrs)
+                                      Attributes get_attrs, Attributes set_attrs, int get_mod, int set_mod, Location get_loc, Location set_loc)
         {
+               if (get_mod != 0)
+                       Report.Error (275, get_loc, "Accessibility modifiers can not be used on accessors in interfaces");
+               if (set_mod != 0)
+                       Report.Error (275, set_loc, "Accessibility modifiers can not be used on accessors in interfaces");
+                       
                if (has_get)
-                       Get = new Accessor (null, get_attrs);
+                       Get = new Accessor (null, 0, get_attrs, get_loc);
                if (has_set)
-                       Set = new Accessor (null, set_attrs);
+                       Set = new Accessor (null, 0, set_attrs, set_loc);
         }
+
 }
 
 
@@ -4403,24 +4736,6 @@ MakeName (MemberName class_name)
        }
 }
 
-// <summary>
-//   Used to report back to the user the result of a declaration
-//   in the current declaration space
-// </summary>
-void 
-CheckDef (DeclSpace.AdditionResult result, string name, Location l)
-{
-       current_container.CheckDef (result, name, l);
-}
-
-void 
-CheckDef (bool result, string name, Location l)
-{
-       if (result)
-               return;
-       CheckDef (DeclSpace.AdditionResult.NameExists, name, l);
-}
-
 Block declare_local_variables (Expression type, ArrayList variable_declarators, Location loc)
 {
        Block implicit_block;
@@ -4608,19 +4923,19 @@ public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList def
 public void parse ()
 {
        try {
-               if (yacc_verbose_flag)
+               if (yacc_verbose_flag > 1)
                        yyparse (lexer, new yydebug.yyDebugSimple ());
                else
                        yyparse (lexer);
                Tokenizer tokenizer = lexer as Tokenizer;
                tokenizer.cleanup ();           
        } catch (Exception e){
-               // Please do not remove this, it is used during debugging
-               // of the grammar
                //
-               Console.WriteLine (e);
+               // Removed for production use, use parser verbose to get the output.
+               //
+               // Console.WriteLine (e);
                Report.Error (-25, lexer.Location, "Parsing error");
-               if (Driver.parser_verbose)
+               if (yacc_verbose_flag > 0)
                        Console.WriteLine (e);
        }
 }
@@ -4639,5 +4954,13 @@ void CheckIdentifierToken (int yyToken)
        CheckToken (1041, yyToken, "Identifier expected");
 }
 
+string ConsumeStoredComment ()
+{
+       string s = tmpComment;
+       tmpComment = null;
+       Lexer.doc_state = XmlCommentState.Allowed;
+       return s;
+}
+
 /* end end end */
 }