In mcs:
authorRaja R Harinath <harinath@hurrynot.org>
Wed, 17 Jan 2007 15:45:46 +0000 (15:45 -0000)
committerRaja R Harinath <harinath@hurrynot.org>
Wed, 17 Jan 2007 15:45:46 +0000 (15:45 -0000)
2007-01-17  Bill Holmes  <bill.holmes@ansys.com>
    Raja R Harinath  <rharinath@novell.com>

Fix emit order of 'get' vs. 'set'.
* support.cs (Accessors): New.
* cs-parser.jay (accessor_declarations): Use it instead of 'Pair'.
Note the order in which accessors are declared in the source.
* class.cs (PropertyBase.DefineGet, PropertyBase.DefineSet): New.
Refactored from Property.Define and Indexer.Define.
(PropertyBase.DefineAccessors): New helper that calls the above in
appropriate order as noted by the parser.
(Property.Define, Indexer.Define): Update to changes.
(PropertyBase.SetMethod.PropertyInfo): Don't return a null.

In gmcs:
2007-01-17  Bill Holmes  <bill.holmes@ansys.com>
    Raja R Harinath  <rharinath@novell.com>

* cs-parser.jay (accessor_declarations): Use it instead of 'Pair'.
Note the order in which accessors are declared in the source.

svn path=/trunk/mcs/; revision=71201

mcs/gmcs/ChangeLog
mcs/gmcs/cs-parser.jay
mcs/mcs/ChangeLog
mcs/mcs/class.cs
mcs/mcs/cs-parser.jay
mcs/mcs/iterators.cs
mcs/mcs/support.cs

index 382d5471cb61b708edac46377dc68776f2a98154..9e4147f4a13be2c9faa5493d8a87ff94de5dd751 100644 (file)
@@ -1,3 +1,9 @@
+2007-01-17  Bill Holmes  <bill.holmes@ansys.com>
+           Raja R Harinath  <rharinath@novell.com>
+
+       * cs-parser.jay (accessor_declarations): Use it instead of 'Pair'.
+       Note the order in which accessors are declared in the source.
+
 2007-01-16  Sergey P. Kondratyev <se@unicom.tomica.ru>
 
        * generic.cs (TypeParameter.FindMembers): Use the generic
index 4ced6699acb52aa28d6b2e6e0d2b485f3d7e120d..09dbe6fa4dca37a50a3ec1f5263135ab1d844e56 100644 (file)
@@ -1417,9 +1417,9 @@ property_declaration
                        break;
 
                Property prop;
-               Pair pair = (Pair) $8;
-               Accessor get_block = (Accessor) pair.First;
-               Accessor set_block = (Accessor) pair.Second;
+               Accessors accessors = (Accessors) $8;
+               Accessor get_block = accessors.get_or_add;
+               Accessor set_block = accessors.set_or_remove;
 
                MemberName name = (MemberName) $4;
 
@@ -1427,7 +1427,7 @@ property_declaration
                        syntax_error (lexer.Location, "a property can't have type arguments");
 
                prop = new Property (current_class, (Expression) $3, (int) $2, false,
-                                    name, (Attributes) $1, get_block, set_block);
+                                    name, (Attributes) $1, get_block, set_block, accessors.declared_in_reverse);
                
                current_container.AddProperty (prop);
                implicit_value_parameter_type = null;
@@ -1441,23 +1441,24 @@ property_declaration
 accessor_declarations
        : get_accessor_declaration
         {
-               $$ = new Pair ($1, null);
+               $$ = new Accessors ((Accessor) $1, null);
         }
        | get_accessor_declaration accessor_declarations
         { 
-               Pair pair = (Pair) $2;
-               pair.First = $1;
-               $$ = pair;
+               Accessors accessors = (Accessors) $2;
+               accessors.get_or_add = (Accessor) $1;
+               $$ = accessors;
         }
        | set_accessor_declaration
         {
-               $$ = new Pair (null, $1);
+               $$ = new Accessors (null, (Accessor) $1);
         }
        | set_accessor_declaration accessor_declarations
         { 
-               Pair pair = (Pair) $2;
-               pair.Second = $1;
-               $$ = pair;
+               Accessors accessors = (Accessors) $2;
+               accessors.set_or_remove = (Accessor) $1;
+               accessors.declared_in_reverse = true;
+               $$ = accessors;
         }
        | error
          {
@@ -1841,24 +1842,24 @@ interface_property_declaration
                if ($7 == null) {
                        p = new Property (current_class, (Expression) $3, (int) $2, true,
                                   name, (Attributes) $1,
-                                  null, null);
+                                  null, null, false);
 
                        Report.Error (548, p.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ());
                        break;
                }
 
-               Pair pair = (Pair) $7;
+               Accessors accessor = (Accessors) $7;
                p = new Property (current_class, (Expression) $3, (int) $2, true,
                                   name, (Attributes) $1,
-                                  (Accessor)pair.First, (Accessor)pair.Second);
+                                  accessor.get_or_add, accessor.set_or_remove, accessor.declared_in_reverse);
 
-               if (pair.First != null && ((Accessor)(pair.First)).Block != null) {
+               if (accessor.get_or_add != null && accessor.get_or_add.Block != null) {
                        Report.Error (531, p.Location, "`{0}.get': interface members cannot have a definition", p.GetSignatureForError ());
                        $$ = null;
                        break;
                }
 
-               if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) {
+               if (accessor.set_or_remove != null && accessor.set_or_remove.Block != null) {
                        Report.Error (531, p.Location, "`{0}.set': interface members cannot have a definition", p.GetSignatureForError ());
                        $$ = null;
                        break;
@@ -1928,25 +1929,25 @@ interface_indexer_declaration
                        i = new Indexer (current_class, (Expression) $3,
                                  new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
                                  (int) $2, true, (Parameters) $6, (Attributes) $1,
-                                 null, null);
+                                 null, null, false);
 
                        Report.Error (548, i.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ());
                        break;
                }
 
-               Pair pair = (Pair) $10;
+               Accessors accessors = (Accessors) $10;
                i = new Indexer (current_class, (Expression) $3,
                                  new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
                                  (int) $2, true, (Parameters) $6, (Attributes) $1,
-                                  (Accessor)pair.First, (Accessor)pair.Second);
+                                  accessors.get_or_add, accessors.set_or_remove, accessors.declared_in_reverse);
 
-               if (pair.First != null && ((Accessor)(pair.First)).Block != null) {
+               if (accessors.get_or_add != null && accessors.get_or_add.Block != null) {
                        Report.Error (531, i.Location, "`{0}.get': interface members cannot have a definition", i.GetSignatureForError ());
                        $$ = null;
                        break;
                }
 
-               if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) {
+               if (accessors.set_or_remove != null && accessors.set_or_remove.Block != null) {
                        Report.Error (531, i.Location, "`{0}.set': interface members cannot have a definition", i.GetSignatureForError ());
                        $$ = null;
                        break;
@@ -2349,18 +2350,18 @@ event_declaration
                                current_container.Name, name.ToString ());
                        $$ = null;
                } else {
-                       Pair pair = (Pair) $8;
+                       Accessors accessors = (Accessors) $8;
                        
                        if (name.TypeArguments != null)
                                syntax_error (lexer.Location, "an event can't have type arguments");
 
-                       if (pair.First == null || pair.Second == null)
+                       if (accessors.get_or_add == null || accessors.set_or_remove == null)
                                // CS0073 is already reported, so no CS0065 here.
                                $$ = null;
                        else {
                                Event e = new EventProperty (
                                        current_class, (Expression) $4, (int) $2, false, name,
-                                       (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second);
+                                       (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
                                if (RootContext.Documentation != null) {
                                        e.DocComment = Lexer.consume_doc_comment ();
                                        Lexer.doc_state = XmlCommentState.Allowed;
@@ -2387,11 +2388,13 @@ event_declaration
 event_accessor_declarations
        : add_accessor_declaration remove_accessor_declaration
          {
-               $$ = new Pair ($1, $2);
+               $$ = new Accessors ((Accessor) $1, (Accessor) $2);
          }
        | remove_accessor_declaration add_accessor_declaration
          {
-               $$ = new Pair ($2, $1);
+               Accessors accessors = new Accessors ((Accessor) $2, (Accessor) $1);
+               accessors.declared_in_reverse = true;
+               $$ = accessors;
          }     
        | add_accessor_declaration  { $$ = null; } 
        | remove_accessor_declaration { $$ = null; } 
@@ -2488,9 +2491,9 @@ indexer_declaration
                // at section 3.6 on the spec
                Indexer indexer;
                IndexerDeclaration decl = (IndexerDeclaration) $3;
-               Pair pair = (Pair) $6;
-               Accessor get_block = (Accessor) pair.First;
-               Accessor set_block = (Accessor) pair.Second;
+               Accessors accessors = (Accessors) $6;
+               Accessor get_block = accessors.get_or_add;
+               Accessor set_block = accessors.set_or_remove;
 
                MemberName name;
                if (decl.interface_type != null)
@@ -2501,7 +2504,7 @@ indexer_declaration
 
                indexer = new Indexer (current_class, decl.type, name,
                                       (int) $2, false, decl.param_list, (Attributes) $1,
-                                      get_block, set_block);
+                                      get_block, set_block, accessors.declared_in_reverse);
 
                if (RootContext.Documentation != null)
                        indexer.DocComment = ConsumeStoredComment ();
index 0fa6e89674ce4443d79b3150bac821e2cd20d4fb..d296de9ceae95db77ea23d93fa076a6f2f2bfb34 100644 (file)
@@ -1,3 +1,17 @@
+2007-01-17  Bill Holmes  <bill.holmes@ansys.com>
+           Raja R Harinath  <rharinath@novell.com>
+
+       Fix emit order of 'get' vs. 'set'.
+       * support.cs (Accessors): New.
+       * cs-parser.jay (accessor_declarations): Use it instead of 'Pair'.
+       Note the order in which accessors are declared in the source.
+       * class.cs (PropertyBase.DefineGet, PropertyBase.DefineSet): New.
+       Refactored from Property.Define and Indexer.Define.
+       (PropertyBase.DefineAccessors): New helper that calls the above in
+       appropriate order as noted by the parser.
+       (Property.Define, Indexer.Define): Update to changes.
+       (PropertyBase.SetMethod.PropertyInfo): Don't return a null.
+
 2007-01-17  Raja R Harinath  <rharinath@novell.com>
 
        Fix cs0029-6.cs and gcs0029-2.cs (regression)
index dc2a17ca317563402222a11f5957974104288651..c8d5aff7382e7431b7627eccbd66ec7736df8960 100644 (file)
@@ -6391,6 +6391,8 @@ namespace Mono.CSharp {
 
                        public override Parameters ParameterInfo {
                                get {
+                                       if (parameters == null)
+                                               DefineParameters ();
                                        return parameters;
                                }
                        }
@@ -6404,7 +6406,6 @@ namespace Mono.CSharp {
 
                        public override MethodBuilder Define (DeclSpace parent)
                        {
-                               DefineParameters ();
                                if (IsDummy)
                                        return null;
 
@@ -6585,11 +6586,14 @@ namespace Mono.CSharp {
                public PropertyBuilder PropertyBuilder;
                public MethodBuilder GetBuilder, SetBuilder;
 
+               protected bool define_set_first = false;
+
                public PropertyBase (DeclSpace parent, Expression type, int mod_flags,
                                     int allowed_mod, bool is_iface, MemberName name,
-                                    Attributes attrs)
+                                    Attributes attrs, bool define_set_first)
                        : base (parent, null, type, mod_flags, allowed_mod, is_iface, name,     attrs)
                {
+                        this.define_set_first = define_set_first;
                }
 
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
@@ -6649,6 +6653,31 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               bool DefineGet ()
+               {
+                       if (Get.IsDummy)
+                               return true;
+
+                       GetBuilder = Get.Define (Parent);
+                       return GetBuilder != null;
+               }
+
+               bool DefineSet (bool define)
+               {
+                       if (!define || Set.IsDummy)
+                               return true;
+
+                       SetBuilder = Set.Define (Parent);
+                       return SetBuilder != null;
+               }
+
+               protected bool DefineAccessors ()
+               {
+                       return DefineSet (define_set_first) &&
+                               DefineGet () &&
+                               DefineSet (!define_set_first);
+               }
+
                protected abstract PropertyInfo ResolveBaseProperty ();
 
                // TODO: rename to Resolve......
@@ -6785,10 +6814,10 @@ namespace Mono.CSharp {
 
                public Property (DeclSpace parent, Expression type, int mod, bool is_iface,
                                 MemberName name, Attributes attrs, Accessor get_block,
-                                Accessor set_block)
+                                Accessor set_block, bool define_set_first)
                        : base (parent, type, mod,
                                is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
-                               is_iface, name, attrs)
+                               is_iface, name, attrs, define_set_first)
                {
                        if (get_block == null)
                                Get = new GetMethod (this);
@@ -6814,17 +6843,8 @@ namespace Mono.CSharp {
 
                        flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
 
-                       if (!Get.IsDummy) {
-                               GetBuilder = Get.Define (Parent);
-                               if (GetBuilder == null)
-                                       return false;
-                       }
-
-                       SetBuilder = Set.Define (Parent);
-                       if (!Set.IsDummy) {
-                               if (SetBuilder == null)
-                                       return false;
-                       }
+                       if (!DefineAccessors ())
+                               return false;
 
                        // FIXME - PropertyAttributes.HasDefault ?
 
@@ -7493,10 +7513,10 @@ namespace Mono.CSharp {
 
                public Indexer (DeclSpace parent, Expression type, MemberName name, int mod,
                                bool is_iface, Parameters parameters, Attributes attrs,
-                               Accessor get_block, Accessor set_block)
+                               Accessor get_block, Accessor set_block, bool define_set_first)
                        : base (parent, type, mod,
                                is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
-                               is_iface, name, attrs)
+                               is_iface, name, attrs, define_set_first)
                {
                        this.parameters = parameters;
 
@@ -7614,26 +7634,18 @@ namespace Mono.CSharp {
                                return false;
 
                        flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
-                       if (!Get.IsDummy){
-                               GetBuilder = Get.Define (Parent);
-                               if (GetBuilder == null)
-                                       return false;
+                       
+                       if (!DefineAccessors ())
+                               return false;
 
-                               //
+                       if (!Get.IsDummy) {
                                // Setup iterator if we are one
-                               //
                                if ((ModFlags & Modifiers.METHOD_YIELDS) != 0){
                                        Iterator iterator = Iterator.CreateIterator (Get, Parent, null, ModFlags);
                                        if (iterator == null)
                                                return false;
                                }
                        }
-                       
-                       SetBuilder = Set.Define (Parent);
-                       if (!Set.IsDummy){
-                               if (SetBuilder == null)
-                                       return false;
-                       }
 
                        //
                        // Now name the parameters
index b3bea2da1486ad3d6428016a05ccbf3d14da5c4a..519a57e737d64319f267ef3737e80da3055c2828 100644 (file)
@@ -1346,14 +1346,14 @@ property_declaration
                        break;
 
                Property prop;
-               Pair pair = (Pair) $8;
-               Accessor get_block = (Accessor) pair.First;
-               Accessor set_block = (Accessor) pair.Second;
+               Accessors accessors = (Accessors) $8;
+               Accessor get_block = accessors.get_or_add;
+               Accessor set_block = accessors.set_or_remove;
 
                MemberName name = (MemberName) $4;
 
                prop = new Property (current_class, (Expression) $3, (int) $2,
-                       false, name, (Attributes) $1, get_block, set_block);
+                       false, name, (Attributes) $1, get_block, set_block, accessors.declared_in_reverse);
                
                current_container.AddProperty (prop);
                implicit_value_parameter_type = null;
@@ -1367,23 +1367,24 @@ property_declaration
 accessor_declarations
        : get_accessor_declaration
         {
-               $$ = new Pair ($1, null);
+               $$ = new Accessors ((Accessor) $1, null);
         }
        | get_accessor_declaration accessor_declarations
         { 
-               Pair pair = (Pair) $2;
-               pair.First = $1;
-               $$ = pair;
+               Accessors accessors = (Accessors) $2;
+               accessors.get_or_add = (Accessor) $1;
+               $$ = accessors;
         }
        | set_accessor_declaration
         {
-               $$ = new Pair (null, $1);
+               $$ = new Accessors (null, (Accessor) $1);
         }
        | set_accessor_declaration accessor_declarations
         { 
-               Pair pair = (Pair) $2;
-               pair.Second = $1;
-               $$ = pair;
+               Accessors accessors = (Accessors) $2;
+               accessors.set_or_remove = (Accessor) $1;
+               accessors.declared_in_reverse = true;
+               $$ = accessors;
         }
        | error
          {
@@ -1697,24 +1698,24 @@ interface_property_declaration
                if ($7 == null) {
                        p = new Property (current_class, (Expression) $3, (int) $2, true,
                                   name, (Attributes) $1,
-                                  null, null);
+                                  null, null, false);
 
                        Report.Error (548, p.Location, "`{0}': property or indexer must have at least one accessor", p.GetSignatureForError ());
                        break;
                }
 
-               Pair pair = (Pair) $7;
+               Accessors accessor = (Accessors) $7;
                p = new Property (current_class, (Expression) $3, (int) $2, true,
                                   name, (Attributes) $1,
-                                  (Accessor)pair.First, (Accessor)pair.Second);
+                                  accessor.get_or_add, accessor.set_or_remove, accessor.declared_in_reverse);
 
-               if (pair.First != null && ((Accessor)(pair.First)).Block != null) {
+               if (accessor.get_or_add != null && accessor.get_or_add.Block != null) {
                        Report.Error (531, p.Location, "`{0}.get': interface members cannot have a definition", p.GetSignatureForError ());
                        $$ = null;
                        break;
                }
 
-               if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) {
+               if (accessor.set_or_remove != null && accessor.set_or_remove.Block != null) {
                        Report.Error (531, p.Location, "`{0}.set': interface members cannot have a definition", p.GetSignatureForError ());
                        $$ = null;
                        break;
@@ -1784,25 +1785,25 @@ interface_indexer_declaration
                        i = new Indexer (current_class, (Expression) $3,
                                  new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
                                  (int) $2, true, (Parameters) $6, (Attributes) $1,
-                                 null, null);
+                                 null, null, false);
 
                        Report.Error (548, i.Location, "`{0}': property or indexer must have at least one accessor", i.GetSignatureForError ());
                        break;
                }
 
-               Pair pair = (Pair) $10;
+               Accessors accessors = (Accessors) $10;
                i = new Indexer (current_class, (Expression) $3,
                                  new MemberName (TypeContainer.DefaultIndexerName, (Location) $4),
                                  (int) $2, true, (Parameters) $6, (Attributes) $1,
-                                  (Accessor)pair.First, (Accessor)pair.Second);
+                                  accessors.get_or_add, accessors.set_or_remove, accessors.declared_in_reverse);
 
-               if (pair.First != null && ((Accessor)(pair.First)).Block != null) {
+               if (accessors.get_or_add != null && accessors.get_or_add.Block != null) {
                        Report.Error (531, i.Location, "`{0}.get': interface members cannot have a definition", i.GetSignatureForError ());
                        $$ = null;
                        break;
                }
 
-               if (pair.Second != null && ((Accessor)(pair.Second)).Block != null) {
+               if (accessors.set_or_remove != null && accessors.set_or_remove.Block != null) {
                        Report.Error (531, i.Location, "`{0}.set': interface members cannot have a definition", i.GetSignatureForError ());
                        $$ = null;
                        break;
@@ -2205,14 +2206,14 @@ event_declaration
                                current_container.Name, name.ToString ());
                        $$ = null;
                } else {
-                       Pair pair = (Pair) $8;
-                       if (pair.First == null || pair.Second == null)
+                       Accessors accessors = (Accessors) $8;
+                       if (accessors.get_or_add == null || accessors.set_or_remove == null)
                                // CS0073 is already reported, so no CS0065 here.
                                $$ = null;
                        else {
                                Event e = new EventProperty (
                                        current_class, (Expression) $4, (int) $2, false, name,
-                                       (Attributes) $1, (Accessor) pair.First, (Accessor) pair.Second);
+                                       (Attributes) $1, accessors.get_or_add, accessors.set_or_remove);
                                if (RootContext.Documentation != null) {
                                        e.DocComment = Lexer.consume_doc_comment ();
                                        Lexer.doc_state = XmlCommentState.Allowed;
@@ -2239,11 +2240,13 @@ event_declaration
 event_accessor_declarations
        : add_accessor_declaration remove_accessor_declaration
          {
-               $$ = new Pair ($1, $2);
+               $$ = new Accessors ((Accessor) $1, (Accessor) $2);
          }
        | remove_accessor_declaration add_accessor_declaration
          {
-               $$ = new Pair ($2, $1);
+               Accessors accessors = new Accessors ((Accessor) $2, (Accessor) $1);
+               accessors.declared_in_reverse = true;
+               $$ = accessors;
          }     
        | add_accessor_declaration  { $$ = null; } 
        | remove_accessor_declaration { $$ = null; } 
@@ -2341,9 +2344,9 @@ indexer_declaration
                Indexer indexer;
                IndexerDeclaration decl = (IndexerDeclaration) $3;
                Location loc = decl.location;
-               Pair pair = (Pair) $6;
-               Accessor get_block = (Accessor) pair.First;
-               Accessor set_block = (Accessor) pair.Second;
+               Accessors accessors = (Accessors) $6;
+               Accessor get_block = accessors.get_or_add;
+               Accessor set_block = accessors.set_or_remove;
 
                MemberName name;
                if (decl.interface_type != null)
@@ -2353,7 +2356,7 @@ indexer_declaration
 
                indexer = new Indexer (current_class, decl.type, name,
                                       (int) $2, false, decl.param_list, (Attributes) $1,
-                                      get_block, set_block);
+                                      get_block, set_block, accessors.declared_in_reverse);
 
                if (RootContext.Documentation != null)
                        indexer.DocComment = ConsumeStoredComment ();
index 8720298fca897c6039fcf59d0f5efe8f9fc2ec46..c259e530e6aaf5f9d540b6d0f8d371e80fa9e8a2 100644 (file)
@@ -306,7 +306,7 @@ namespace Mono.CSharp {
                        Accessor getter = new Accessor (get_block, 0, null, Location);
 
                        Property current = new Property (
-                               this, type, 0, false, name, null, getter, null);
+                               this, type, 0, false, name, null, getter, null, false);
                        AddProperty (current);
                }
 
index b0bb63d99cb7940748a222c5e59697abdf113528..45acc20962f963a1d9536a01c64144bc47869904 100644 (file)
@@ -341,6 +341,20 @@ namespace Mono.CSharp {
                }
        }
 
+       public class Accessors {
+               public Accessor get_or_add;
+               public Accessor set_or_remove;
+
+               // was 'set' declared before 'get'?  was 'remove' declared before 'add'?
+               public bool declared_in_reverse;
+
+               public Accessors (Accessor get_or_add, Accessor set_or_remove)
+               {
+                       this.get_or_add = get_or_add;
+                       this.set_or_remove = set_or_remove;
+               }
+       }
+
        /// <summary>
        ///   This is a wrapper around StreamReader which is seekable backwards
        ///   within a window of around 2048 chars.