Fix typos.
[mono.git] / mcs / mcs / cs-parser.jay
index 27470079b4db9e0665b1a911fbe54ce05e0cf571..23d58af14cb72a40ba42504cb661ebd739210d3e 100755 (executable)
@@ -8,6 +8,7 @@
 // cs-parser.jay: The Parser for the C# compiler
 //
 // Author: Miguel de Icaza (miguel@gnu.org)
+//         Ravi Pratap     (ravi@ximian.com)
 //
 // Licensed under the terms of the GNU GPL
 //
@@ -256,21 +257,29 @@ namespace Mono.CSharp
 %nonassoc HIGHPREC
 
 %start compilation_unit
-/*%start namespace_declaration */
 %%
 
 compilation_unit
-       : opt_using_directives opt_namespace_member_declarations opt_attributes opt_EOF
-         {
-               // Check that using comes only before namespace elements
-         }
-       ;
-
+        : outer_declarations opt_EOF
+        | outer_declarations attribute_sections opt_EOF
+        | attribute_sections opt_EOF
+        ;
+       
 opt_EOF
        : /* empty */
        | EOF
        ;
 
+outer_declarations
+        : outer_declaration
+        | outer_declarations outer_declaration
+        ;
+outer_declaration
+        : using_directive
+        | namespace_member_declaration
+        ;
+  
 using_directives
        : using_directive 
        | using_directives using_directive
@@ -296,15 +305,24 @@ using_namespace_directive
           }
        ;
 
-//  namespace_declarations
-//     : namespace_declaration
-//     | namespace_declarations namespace_declaration
-
+//
+// Strictly speaking, namespaces don't have attributes but
+// we parse global attributes along with namespace declarations and then
+// detach them
+// 
 namespace_declaration
-       : NAMESPACE qualified_identifier 
-         {
-               current_namespace = RootContext.Tree.RecordNamespace (current_namespace, name, (string) $2);
-         } 
+       : opt_attributes NAMESPACE qualified_identifier 
+       {
+               Attributes attrs = (Attributes) $1;
+
+               if (attrs != null) {
+                       foreach (AttributeSection asec in attrs.AttributeSections)
+                               if (asec.Target == "assembly")
+                                       RootContext.AddGlobalAttribute (asec, lexer.Location);
+               }
+
+               current_namespace = RootContext.Tree.RecordNamespace (current_namespace, name, (string) $3);
+       } 
          namespace_body opt_semicolon
          { 
                current_namespace = current_namespace.Parent;
@@ -400,26 +418,33 @@ type_declaration
 //
 // Attributes 17.2
 //
+
 opt_attributes
-       : /* empty */ { $$ = null; }
-       | attribute_section opt_attributes
+        : /* empty */
+       | attribute_sections { $$ = $1; }
+        ;
+attribute_sections
+       : attribute_section
+          {
+               AttributeSection sect = (AttributeSection) $1;
+
+               if (sect.Target == "assembly")
+                       RootContext.AddGlobalAttribute (sect, lexer.Location);
+                 
+               $$ = new Attributes ((AttributeSection) $1, lexer.Location);
+          }
+       | attribute_sections attribute_section
          {
                Attributes attrs = null;
-               AttributeSection sect = (AttributeSection) $1;
+               AttributeSection sect = (AttributeSection) $2;
 
-               if (sect.Target == "assembly"){
-                       RootContext.AddGlobalAttributes (sect, lexer.Location);
-                       sect = null;
-               }
+               if (sect.Target == "assembly")
+                       RootContext.AddGlobalAttribute (sect, lexer.Location);
 
-               if ($2 != null) {
-                       if (sect != null){
-                               attrs = (Attributes) $2;
-                               attrs.AddAttribute (sect);
-                       }
-               } else {
-                       if (sect != null)
-                               attrs = new Attributes (sect, lexer.Location);
+               if ($1 != null) {
+                       attrs = (Attributes) $1;
+                       attrs.AddAttribute (sect);
                }
                
                $$ = attrs;
@@ -621,7 +646,7 @@ struct_declaration
                                         (Attributes) $1, lexer.Location);
                current_container = new_struct;
                current_container.Namespace = current_namespace;
-               RootContext.Tree.RecordStruct (full_struct_name, new_struct);
+               RootContext.Tree.RecordDecl (full_struct_name, new_struct);
          }
          opt_struct_interfaces
          struct_body
@@ -1058,7 +1083,7 @@ set_accessor_declaration
 
 accessor_body
        : block 
-       | SEMICOLON             { $$ = new Block (null); }
+       | SEMICOLON             { $$ = null; }
        ;
 
 interface_declaration
@@ -1077,7 +1102,7 @@ interface_declaration
                }
                current_interface = new_interface;
                new_interface.Namespace = current_namespace;
-               RootContext.Tree.RecordInterface (full_interface_name, new_interface);
+               RootContext.Tree.RecordDecl (full_interface_name, new_interface);
          }
          opt_interface_base
          interface_body opt_semicolon
@@ -1443,7 +1468,9 @@ destructor_declaration
                        Location l = lexer.Location;
 
                        Method d = new Method (
-                               "System.Void", 0, "Finalize", 
+                               "System.Void", 
+                               Modifiers.PROTECTED | Modifiers.OVERRIDE, 
+                               "Finalize", 
                                new Parameters (null, null, l), (Attributes) $1, l);
                  
                        d.Block = (Block) $6;
@@ -1649,7 +1676,7 @@ enum_declaration
                e.Namespace = current_namespace;
 
                CheckDef (current_container.AddEnum (e), full_name, enum_location);
-               RootContext.Tree.RecordEnum (full_name, e);
+               RootContext.Tree.RecordDecl (full_name, e);
 
          }
        ;
@@ -1718,7 +1745,7 @@ delegate_declaration
                                             MakeName ((string) $5), (Parameters) $7, 
                                             (Attributes) $1, l);
                  
-
+               del.Namespace = current_namespace;
                CheckDef (current_container.AddDelegate (del), del.Name, l);
          }     
        | opt_attributes
@@ -1735,6 +1762,7 @@ delegate_declaration
                        "System.Void", (int) $2, MakeName ((string) $5), (Parameters) $7, 
                        (Attributes) $1, l);
 
+               del.Namespace = current_namespace;
                CheckDef (current_container.AddDelegate (del), del.Name, l);
          }
        ;
@@ -2467,91 +2495,111 @@ assignment_expression
          {
                Location l = lexer.Location;
 
-               $$ = new Assign ((Expression) $1,
-                                new Binary (Binary.Operator.Multiply, 
-                                            (Expression) $1,
-                                            (Expression) $3, l), l);
+               $$ = new CompoundAssign (
+                       (Expression) $1,
+                       new Binary (Binary.Operator.Multiply, 
+                                    (Expression) $1,
+                                    (Expression) $3, l), 
+                       (Expression) $3, l);
          }
        | prefixed_unary_expression OP_DIV_ASSIGN expression
          {
                Location l = lexer.Location;
 
-               $$ = new Assign ((Expression) $1,
-                                new Binary (Binary.Operator.Division, 
-                                            (Expression) $1,
-                                            (Expression) $3, l), l);
+               $$ = new CompoundAssign (
+                       (Expression) $1,
+                       new Binary (Binary.Operator.Division, 
+                                    (Expression) $1,
+                                    (Expression) $3, l),
+                       (Expression) $3, l);
          }
        | prefixed_unary_expression OP_MOD_ASSIGN expression
          {
                Location l = lexer.Location;
 
-               $$ = new Assign ((Expression) $1,
-                                new Binary (Binary.Operator.Modulus, 
-                                            (Expression) $1,
-                                            (Expression) $3, l), l);
+               $$ = new CompoundAssign (
+                       (Expression) $1,
+                       new Binary (Binary.Operator.Modulus, 
+                                    (Expression) $1,
+                                    (Expression) $3, l),
+                       (Expression) $3, l);
          }
        | prefixed_unary_expression OP_ADD_ASSIGN expression
          {
                Location l = lexer.Location;
 
-               $$ = new Assign ((Expression) $1,
-                                new Binary (Binary.Operator.Addition, 
-                                            (Expression) $1,
-                                            (Expression) $3, l), l);
+               $$ = new CompoundAssign (
+                       (Expression) $1,
+                       new Binary (Binary.Operator.Addition, 
+                                    (Expression) $1,
+                                    (Expression) $3, l),
+                       (Expression) $3, l);
          }
        | prefixed_unary_expression OP_SUB_ASSIGN expression
          {
                Location l = lexer.Location;
 
-               $$ = new Assign ((Expression) $1,
-                                new Binary (Binary.Operator.Subtraction, 
-                                            (Expression) $1,
-                                            (Expression) $3, l), l);
+               $$ = new CompoundAssign (
+                       (Expression) $1,
+                       new Binary (Binary.Operator.Subtraction, 
+                                    (Expression) $1,
+                                    (Expression) $3, l),
+                       (Expression) $3, l);
          }
        | prefixed_unary_expression OP_SHIFT_LEFT_ASSIGN expression
          {
                Location l = lexer.Location;
 
-               $$ = new Assign ((Expression) $1,
-                                new Binary (Binary.Operator.LeftShift, 
-                                            (Expression) $1,
-                                            (Expression) $3, l), l);
+               $$ = new CompoundAssign (
+                       (Expression) $1,
+                       new Binary (Binary.Operator.LeftShift, 
+                                    (Expression) $1,
+                                    (Expression) $3, l), 
+                       (Expression) $3, l);
          }
        | prefixed_unary_expression OP_SHIFT_RIGHT_ASSIGN expression
          {
                Location l = lexer.Location;
 
-               $$ = new Assign ((Expression) $1,
-                                new Binary (Binary.Operator.RightShift, 
-                                            (Expression) $1,
-                                            (Expression) $3, l), l);
+               $$ = new CompoundAssign (
+                       (Expression) $1,
+                       new Binary (Binary.Operator.RightShift, 
+                                    (Expression) $1,
+                                    (Expression) $3, l), 
+                       (Expression) $3, l);
          }
        | prefixed_unary_expression OP_AND_ASSIGN expression
          {
                Location l = lexer.Location;
 
-               $$ = new Assign ((Expression) $1,
-                                new Binary (Binary.Operator.BitwiseAnd, 
-                                            (Expression) $1,
-                                            (Expression) $3, l), l);
+               $$ = new CompoundAssign (
+                       (Expression) $1,
+                       new Binary (Binary.Operator.BitwiseAnd, 
+                                    (Expression) $1,
+                                    (Expression) $3, l),
+                       (Expression) $3, l);
          }
        | prefixed_unary_expression OP_OR_ASSIGN expression
          {
                Location l = lexer.Location;
 
-               $$ = new Assign ((Expression) $1,
-                                new Binary (Binary.Operator.BitwiseOr, 
-                                            (Expression) $1,
-                                            (Expression) $3, l), l);
+               $$ = new CompoundAssign (
+                       (Expression) $1,
+                       new Binary (Binary.Operator.BitwiseOr, 
+                                    (Expression) $1,
+                                    (Expression) $3, l),
+                       (Expression) $3, l);
          }
        | prefixed_unary_expression OP_XOR_ASSIGN expression
          {
                Location l = lexer.Location;
 
-               $$ = new Assign ((Expression) $1,
-                                new Binary (Binary.Operator.ExclusiveOr, 
-                                            (Expression) $1,
-                                            (Expression) $3, l), l);
+               $$ = new CompoundAssign (
+                       (Expression) $1,
+                       new Binary (Binary.Operator.ExclusiveOr, 
+                                    (Expression) $1,
+                                    (Expression) $3, l),
+                       (Expression) $3, l);
          }
        ;
 
@@ -2585,7 +2633,7 @@ class_declaration
                                       (Attributes) $1, lexer.Location);
                current_container = new_class;
                current_container.Namespace = current_namespace;
-               RootContext.Tree.RecordClass (name, new_class);
+               RootContext.Tree.RecordDecl (name, new_class);
          }
          opt_class_base
          class_body 
@@ -3691,13 +3739,6 @@ SimpleLookup (string name, Location loc)
        // as `expression' is allowed in argument_lists, which 
        // do not exist inside a block.  
        //
-#if BLAH
-       if (current_block != null){
-               if (current_block.IsVariableDefined (name)){
-                       return new LocalVariableReference (current_block, name, loc);
-               }
-       }
-#endif
 
        if (current_local_parameters != null){
                int idx;
@@ -3938,8 +3979,6 @@ public CSharpParser (string name, System.IO.Stream input, ArrayList defines)
 
 public override int parse ()
 {
-       StringBuilder value = new StringBuilder ();
-
        global_errors = 0;
        try {
                if (yacc_verbose_flag)