2008-06-25 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / cs-parser.jay
index defe946712475668d41ac2ac19c27a7c96c93b28..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");
@@ -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);
@@ -5189,15 +5202,11 @@ opt_catch_args
 catch_args 
        : OPEN_PARENS type opt_identifier CLOSE_PARENS 
          {
-               if ($2 is ATypeNameExpression || $2 == TypeManager.system_object_expr || $2 == TypeManager.system_string_expr) {
-                       $$ = new DictionaryEntry ($2, $3);
-               } else {
-                       Error_InvalidCatchType (GetLocation ($2));
-               }
+               $$ = new DictionaryEntry ($2, $3);
          }
        | OPEN_PARENS CLOSE_PARENS 
          {
-               Error_InvalidCatchType (GetLocation ($1));
+               Report.Error (1015, GetLocation ($1), "A type that derives from `System.Exception', `object', or `string' expected");
          }
        ;
 
@@ -5681,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;
        }
 
@@ -5693,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);
-               }
        }
 }
 
@@ -5737,11 +5733,6 @@ void Error_ExpectingTypeName (Expression expr)
        }
 }
 
-static void Error_InvalidCatchType (Location loc)
-{
-       Report.Error (1015, loc, "A type that derives from `System.Exception', `object', or `string' expected");
-}
-
 static void Error_ParameterModifierNotValid (string modifier, Location loc)
 {
        Report.Error (631, loc, "The parameter modifier `{0}' is not valid in this context",
@@ -5919,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);
@@ -6015,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;
@@ -6033,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;
 
@@ -6043,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;
        }