2008-06-25 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / cs-parser.jay
index aff28be985a23704322d55438e0e1f07c53ec86c..a48ed260b13b0aec6577dfa2c7418700c3d0eb02 100644 (file)
@@ -53,6 +53,9 @@ namespace Mono.CSharp
                ///   This is used by the unary_expression code to resolve
                ///   a name against a parameter.  
                /// </summary>
+               
+               // FIXME: This is very ugly and it's very hard to reset it correctly
+               // on all places, especially when some parameters are autogenerated.
                Parameters current_local_parameters;
 
                /// <summary>
@@ -92,7 +95,7 @@ namespace Mono.CSharp
                ///
                /// The current file.
                ///
-               SourceFile file;
+               CompilationUnit file;
 
                ///
                /// Temporary Xml documentation cache.
@@ -2613,10 +2616,11 @@ remove_accessor_declaration
                current_local_parameters = new Parameters (args);  
                lexer.EventParsing = false;
          }
-          block
+         block
          {
                $$ = new Accessor ((ToplevelBlock) $4, 0, (Attributes) $1, (Location) $2);
                lexer.EventParsing = true;
+               current_local_parameters = null;
          }
        | opt_attributes REMOVE error {
                Report.Error (73, (Location) $2, "An add or remove accessor must have a body");
@@ -3000,7 +3004,7 @@ type
                if ((bool) $2) {
                        $$ = new ComposedCast (name.GetTypeExpression (), "?", lexer.Location);
                } else {
-                       if (RootContext.Version > LanguageVersion.ISO_2 && name.Name == "var")
+                       if (RootContext.Version > LanguageVersion.ISO_2 && name.Left == null && name.Name == "var")
                                $$ = new VarExpr (name.Location);
                        else
                                $$ = name.GetTypeExpression ();
@@ -3558,7 +3562,7 @@ array_creation_expression
        ;
 
 anonymous_type_expression
-       : NEW OPEN_BRACE anonymous_type_parameters CLOSE_BRACE
+       : NEW OPEN_BRACE anonymous_type_parameters_opt_comma CLOSE_BRACE
          {
                if (RootContext.Version <= LanguageVersion.ISO_2)
                        Report.FeatureIsNotAvailable (GetLocation ($1), "anonymous types");
@@ -3567,9 +3571,18 @@ anonymous_type_expression
          }
        ;
 
-anonymous_type_parameters
+anonymous_type_parameters_opt_comma
+       : anonymous_type_parameters_opt
+       | anonymous_type_parameters COMMA
+       ;
+
+anonymous_type_parameters_opt
        : { $$ = null; }
-       | anonymous_type_parameter
+       | anonymous_type_parameters
+       ;
+
+anonymous_type_parameters
+       : anonymous_type_parameter
          {
                ArrayList a = new ArrayList (4);
                a.Add ($1);
@@ -4116,7 +4129,7 @@ conditional_expression
 assignment_expression
        : prefixed_unary_expression ASSIGN expression
          {
-               $$ = new Assign ((Expression) $1, (Expression) $3);
+               $$ = new SimpleAssign ((Expression) $1, (Expression) $3);
          }
        | prefixed_unary_expression OP_MULT_ASSIGN expression
          {
@@ -4883,7 +4896,7 @@ for_statement
                                var = new LocalVariableReference (assign_block, decl.identifier, l);
 
                                if (expr != null) {
-                                       Assign a = new Assign (var, expr, decl.Location);
+                                       Assign a = new SimpleAssign (var, expr, decl.Location);
                                        
                                        assign_block.AddStatement (new StatementExpression (a));
                                }
@@ -5183,16 +5196,19 @@ catch_clause
 
 opt_catch_args
        : /* empty */ { $$ = null; }
-        | catch_args
+       | catch_args
        ;         
 
 catch_args 
-        : open_parens type opt_identifier CLOSE_PARENS 
-          {
+       : OPEN_PARENS type opt_identifier CLOSE_PARENS 
+         {
                $$ = new DictionaryEntry ($2, $3);
          }
-        ;
-
+       | OPEN_PARENS CLOSE_PARENS 
+         {
+               Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected");
+         }
+       ;
 
 checked_statement
        : CHECKED block
@@ -5331,7 +5347,7 @@ using_statement
 
                        vars.Push (new DictionaryEntry (var, expr));
 
-                       // Assign a = new Assign (var, expr, decl.Location);
+                       // Assign a = new SimpleAssign (var, expr, decl.Location);
                        // assign_block.AddStatement (new StatementExpression (a));
                }
 
@@ -5674,11 +5690,9 @@ public class SimpleAnonymousHost : IAnonymousHost {
        public static readonly SimpleAnonymousHost Simple = new SimpleAnonymousHost ();
 
        bool yields;
-       ArrayList anonymous_methods;
 
        public static SimpleAnonymousHost GetSimple () {
                Simple.yields = false;
-               Simple.anonymous_methods = null;
                return Simple;
        }
 
@@ -5686,22 +5700,11 @@ public class SimpleAnonymousHost : IAnonymousHost {
        {
                yields = true;
        }
-
-       public void AddAnonymousMethod (AnonymousMethodExpression anonymous)
-       {
-               if (anonymous_methods == null)
-                       anonymous_methods = new ArrayList ();
-               anonymous_methods.Add (anonymous);
-       }
-
+       
        public void Propagate (IAnonymousHost real_host)
        {
                if (yields)
                        real_host.SetYields ();
-               if (anonymous_methods != null) {
-                       foreach (AnonymousMethodExpression ame in anonymous_methods)
-                               real_host.AddAnonymousMethod (ame);
-               }
        }
 }
 
@@ -5831,7 +5834,7 @@ Block declare_local_variables (Expression type, ArrayList variable_declarators,
                LocalVariableReference var;
                var = new LocalVariableReference (implicit_block, decl.identifier, loc);
 
-               assign = new Assign (var, expr, decl.Location);
+               assign = new SimpleAssign (var, expr, decl.Location);
 
                implicit_block.AddStatement (new StatementExpression (assign));
        }
@@ -5907,7 +5910,7 @@ static CSharpParser ()
        oob_stack = new Stack ();
 }
 
-public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
+public CSharpParser (SeekableStreamReader reader, CompilationUnit file, ArrayList defines)
 {
        this.file = file;
        current_namespace = new NamespaceEntry (null, file, null);
@@ -6003,15 +6006,9 @@ start_anonymous (bool lambda, Parameters parameters, Location loc)
 
        current_local_parameters = parameters;
 
-       ToplevelBlock top_current_block = current_block == null ? null : current_block.Toplevel;
-
        current_anonymous_method = lambda 
-               ? new LambdaExpression (
-                       current_anonymous_method, current_generic_method, current_container,
-                       parameters, top_current_block, loc) 
-               : new AnonymousMethodExpression (
-                       current_anonymous_method, current_generic_method, current_container,
-                       parameters, top_current_block, loc);
+               ? new LambdaExpression (current_container, parameters, loc) 
+               : new AnonymousMethodExpression (current_container, parameters, loc);
 
        // Force the next block to be created as a ToplevelBlock
        parsing_anonymous_method = true;
@@ -6021,8 +6018,7 @@ start_anonymous (bool lambda, Parameters parameters, Location loc)
  * Completes the anonymous method processing, if lambda_expr is null, this
  * means that we have a Statement instead of an Expression embedded 
  */
-AnonymousMethodExpression 
-end_anonymous (ToplevelBlock anon_block, Location loc)
+AnonymousMethodExpression end_anonymous (ToplevelBlock anon_block, Location loc)
 {
        AnonymousMethodExpression retval;
 
@@ -6031,9 +6027,6 @@ end_anonymous (ToplevelBlock anon_block, Location loc)
                retval = null;
        } else  {
                current_anonymous_method.Block = anon_block;
-               if ((anonymous_host != null) && (current_anonymous_method.Parent == null))
-                       anonymous_host.AddAnonymousMethod (current_anonymous_method);
-
                retval = current_anonymous_method;
        }