* XmlTypeAttribute.cs: added property AnonymousType for 2.0
[mono.git] / mcs / mcs / cs-parser.jay
index af0cc3f20b67af31ba781fb9fefddf466ce9f319..b93d179b6331a198ad7c4f014be78946c526c3f3 100644 (file)
@@ -33,7 +33,7 @@ namespace Mono.CSharp
        public class CSharpParser {
                NamespaceEntry  current_namespace;
                TypeContainer   current_container;
-               TypeContainer   current_class;
+               DeclSpace       current_class;
        
                IIteratorContainer iterator_container;
 
@@ -61,6 +61,7 @@ namespace Mono.CSharp
                ///   Hack to help create non-typed array initializer
                /// </summary>
                public static Expression current_array_type;
+               Expression pushed_current_array_type;
 
                /// <summary>
                ///   Used to determine if we are parsing the get/set pair
@@ -392,10 +393,14 @@ namespace_declaration
 
                current_namespace = new NamespaceEntry (
                        current_namespace, file, name.GetName ());
+               current_class = current_namespace.SlaveDeclSpace;
+               current_container = current_class.PartialContainer;
          } 
          namespace_body opt_semicolon
          { 
                current_namespace = current_namespace.Parent;
+               current_class = current_namespace.SlaveDeclSpace;
+               current_container = current_class.PartialContainer;
          }
        ;
 
@@ -758,21 +763,15 @@ struct_declaration
          STRUCT member_name
          { 
                MemberName name = MakeName ((MemberName) $5);
-               current_class = new Struct (
+               push_current_class (new Struct (
                        current_namespace, current_class, name, (int) $2,
-                       (Attributes) $1);
+                       (Attributes) $1), false, $3);
 
-               if ($3 != null) {
-                       current_container = current_container.AddPartial (current_class);
-               } else {
-                       current_container.AddClassOrStruct (current_class);
-                       current_container = current_class;
-               }
          }
          opt_class_base
          {
                if ($7 != null)
-                       current_class.Bases = (ArrayList) $7;
+                       current_container.AddBasesForPart (current_class, (ArrayList) $7);
 
                if (RootContext.Documentation != null)
                        current_container.DocComment = Lexer.consume_doc_comment ();
@@ -1174,11 +1173,22 @@ formal_parameter_list
                        Report.Error (231, ((Parameter) $1).Location, "A params parameter must be the last parameter in a formal parameter list");
                $$ = null;
          }
+       | fixed_parameters COMMA parameter_array COMMA error
+         {
+               if ($3 != null)
+                       Report.Error (231, ((Parameter) $3).Location, "A params parameter must be the last parameter in a formal parameter list");
+               $$ = null;
+         }
        | ARGLIST COMMA error
          {
                Report.Error (257, (Location) $1, "An __arglist parameter must be the last parameter in a formal parameter list");
                $$ = null;
          }
+       | fixed_parameters COMMA ARGLIST COMMA error 
+         {
+               Report.Error (257, (Location) $3, "An __arglist parameter must be the last parameter in a formal parameter list");
+               $$ = null;
+         }
        | parameter_array 
          {
                $$ = new Parameters (new Parameter[] { (Parameter) $1 } );
@@ -1456,20 +1466,13 @@ interface_declaration
          {
                MemberName name = MakeName ((MemberName) $5);
 
-               current_class = new Interface (
+               push_current_class (new Interface (
                        current_namespace, current_class, name, (int) $2,
-                       (Attributes) $1);
-
-               if ($3 != null) {
-                       current_container = current_container.AddPartial (current_class);
-               } else {
-                       current_container.AddInterface (current_class);
-                       current_container = current_class;
-               }
+                       (Attributes) $1), true, $3);
          }
          opt_class_base
          {
-               current_class.Bases = (ArrayList) $7;
+               current_container.AddBasesForPart (current_class, (ArrayList) $7);
 
                if (RootContext.Documentation != null) {
                        current_container.DocComment = Lexer.consume_doc_comment ();
@@ -2396,7 +2399,6 @@ enum_declaration
                }
 
                current_container.AddEnum (e);
-               RootContext.Tree.RecordDecl (current_namespace.NS, name, e);
                $$ = e;
 
          }
@@ -2503,7 +2505,6 @@ delegate_declaration
                }
 
                current_container.AddDelegate (del);
-               RootContext.Tree.RecordDecl (current_namespace.NS, name, del);
                $$ = del;
          }     
        ;
@@ -2757,7 +2758,8 @@ member_access
        | predefined_type DOT IDENTIFIER
          {
                LocatedToken lt = (LocatedToken) $3;
-               $$ = new MemberAccess ((Expression) $1, lt.Value);
+               // TODO: Location is wrong as some predefined types doesn't hold a location
+               $$ = new MemberAccess ((Expression) $1, lt.Value, lt.Location);
          }
        ;
 
@@ -3064,13 +3066,18 @@ variable_initializer_list
        ;
 
 typeof_expression
-       : TYPEOF OPEN_PARENS VOID CLOSE_PARENS
-         {
-               $$ = new TypeOfVoid ((Location) $1);
+       : TYPEOF
+      {
+               pushed_current_array_type = current_array_type;
          }
-       | TYPEOF OPEN_PARENS type CLOSE_PARENS
+         OPEN_PARENS type CLOSE_PARENS
          {
-               $$ = new TypeOf ((Expression) $3, (Location) $1);
+               Expression type = (Expression)$4;
+               if (type == TypeManager.system_void_expr)
+                       $$ = new TypeOfVoid ((Location) $1);
+               else
+                       $$ = new TypeOf (type, (Location) $1);
+               current_array_type = pushed_current_array_type;
          }
        ;
 
@@ -3499,16 +3506,9 @@ class_declaration
                MemberName name = MakeName ((MemberName) $5);
                int mod_flags = (int) $2;
 
-               current_class = new Class (
+               push_current_class (new Class (
                        current_namespace, current_class, name,
-                       mod_flags, (Attributes) $1);
-
-               if ($3 != null) {
-                       current_container = current_container.AddPartial (current_class);
-               } else {
-                       current_container.AddClassOrStruct (current_class);
-                       current_container = current_class;
-               }
+                       mod_flags, (Attributes) $1), false, $3);
          }
          opt_class_base
          {
@@ -3518,7 +3518,7 @@ class_declaration
                                              "The class System.Object cannot have a base " +
                                              "class or implement an interface.");
                        }
-                       current_class.Bases = (ArrayList) $7;
+                       current_container.AddBasesForPart (current_class, (ArrayList) $7);
                }
 
                if (RootContext.Documentation != null) {
@@ -3922,7 +3922,8 @@ switch_block
 opt_switch_sections
        : /* empty */           
           {
-               Report.Error (1522, lexer.Location, "Empty switch block"); 
+               Report.Warning (1522, 1, lexer.Location, "Empty switch block"); 
+               $$ = new ArrayList ();
          }
        | switch_sections
        ;
@@ -4664,11 +4665,20 @@ void Error_ExpectingTypeName (Expression expr)
        }
 }
 
-TypeContainer pop_current_class ()
+void push_current_class (TypeContainer tc, bool is_interface, object partial_token)
 {
-       TypeContainer retval = current_class;
+       if (partial_token != null)
+               current_container = current_container.AddPartial (tc, is_interface);
+       else
+               current_container = current_container.AddTypeContainer (tc, is_interface);
+       current_class = tc;
+}
+
+DeclSpace pop_current_class ()
+{
+       DeclSpace retval = current_class;
 
-       current_class = (TypeContainer) current_class.Parent;
+       current_class = current_class.Parent;
        current_container = current_class.PartialContainer;
 
        return retval;
@@ -4848,13 +4858,11 @@ public Tokenizer Lexer {
 
 public CSharpParser (SeekableStreamReader reader, SourceFile file, ArrayList defines)
 {
-       current_namespace = new NamespaceEntry (null, file, null);
        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;
+       current_namespace = new NamespaceEntry (null, file, null);
+       current_class = current_namespace.SlaveDeclSpace;
+       current_container = current_class.PartialContainer; // == RootContest.ToplevelTypes
 
        lexer = new Tokenizer (reader, file, defines);
 }
@@ -4880,7 +4888,8 @@ public void parse ()
                        Console.WriteLine (e);
        }
 
-       RootContext.Tree.Types.NamespaceEntry = null;
+       if (RootContext.ToplevelTypes.NamespaceEntry != null)
+               throw new InternalErrorException ("who set it?");
 }
 
 static void CheckToken (int error, int yyToken, string msg, Location loc)