**** Merged r36954 from MCS ****
[mono.git] / mcs / gmcs / class.cs
index 2fb89414dde196f1cf5fe1367bb19a53f3757255..4cb48f00c403065baad05528dc6af8250c7f74af 100755 (executable)
@@ -8,6 +8,7 @@
 // Licensed under the terms of the GNU GPL
 //
 // (C) 2001, 2002, 2003 Ximian, Inc (http://www.ximian.com)
+// (C) 2004 Novell, Inc
 //
 //
 //  2002-10-11  Miguel de Icaza  <miguel@ximian.com>
@@ -40,6 +41,7 @@ using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using System.Security;
 using System.Security.Permissions;
+using System.Xml;
 
 using Mono.CompilerServices.SymbolWriter;
 
@@ -1068,11 +1070,11 @@ namespace Mono.CSharp {
                                        return null;
                                }
 
-                               if (!parent.AsAccessible (this, ModFlags))
-                                       Report.Error (60, Location,
-                                                     "Inconsistent accessibility: base class `" +
-                                                     parent.Name + "' is less accessible than class `" +
-                                                     Name + "'");
+                               if (!parent.AsAccessible (this, ModFlags)) {
+                                       Report.SymbolRelatedToPreviousError (parent.Type);
+                                       Report.Error (60, Location, "Inconsistent accessibility: base class '{0}' is less accessible than class '{1}'", 
+                                               TypeManager.CSharpName (parent.Type), GetSignatureForError ());
+                               }
                        }
 
                        if (parent != null)
@@ -1098,13 +1100,11 @@ namespace Mono.CSharp {
                                }
 
                                if (iface.IsClass) {
-                                       if (parent != null){
-                                               Report.Error (527, Location,
-                                                             "In Class `{0}', `{1}' is not " +
-                                                             "an interface", Name, iface.Name);
-                                               error = true;
-                                               return null;
-                                       }
+                                       Report.Error (1722, Location,
+                                                     "In Class `{0}', `{1}' is not " +
+                                                     "an interface, a base class must be listed first", Name, iface.Name);
+                                       error = true;
+                                       return null;
                                }
   
                                for (int x = 0; x < i; x++) {
@@ -2397,6 +2397,10 @@ namespace Mono.CSharp {
                        }
                }
 
+               public Constructor DefaultStaticConstructor {
+                       get { return default_static_constructor; }
+               }
+
                protected override bool VerifyClsCompliance (DeclSpace ds)
                {
                        if (!base.VerifyClsCompliance (ds))
@@ -2533,6 +2537,19 @@ namespace Mono.CSharp {
                                return FindMembers (mt, new_bf, null, null);
                }
 
+               //
+               // Generates xml doc comments (if any), and if required,
+               // handle warning report.
+               //
+               internal override void GenerateDocComment (DeclSpace ds)
+               {
+                       DocUtil.GenerateTypeDocComment (this, ds);
+               }
+
+               public override string DocCommentHeader {
+                       get { return "T:"; }
+               }
+
                public virtual MemberCache ParentCache {
                        get {
                                return parent_cache;
@@ -2549,11 +2566,11 @@ namespace Mono.CSharp {
                public readonly TypeAttributes DefaultTypeAttributes;
 
                static PartialContainer Create (NamespaceEntry ns, TypeContainer parent,
-                                               MemberName name, int mod_flags, Kind kind,
+                                               MemberName member_name, int mod_flags, Kind kind,
                                                Location loc)
                {
                        PartialContainer pc;
-                       string full_name = name.GetName (true);
+                       string full_name = member_name.GetName (true);
                        DeclSpace ds = (DeclSpace) RootContext.Tree.Decls [full_name];
                        if (ds != null) {
                                pc = ds as PartialContainer;
@@ -2563,7 +2580,7 @@ namespace Mono.CSharp {
                                                260, ds.Location, "Missing partial modifier " +
                                                "on declaration of type `{0}'; another " +
                                                "partial implementation of this type exists",
-                                               name);
+                                               member_name.GetPartialName());
 
                                        Report.LocationOfPreviousError (loc);
                                        return null;
@@ -2573,7 +2590,7 @@ namespace Mono.CSharp {
                                        Report.Error (
                                                261, loc, "Partial declarations of `{0}' " +
                                                "must be all classes, all structs or " +
-                                               "all interfaces", name);
+                                               "all interfaces", member_name.GetPartialName ());
                                        return null;
                                }
 
@@ -2581,14 +2598,14 @@ namespace Mono.CSharp {
                                        Report.Error (
                                                262, loc, "Partial declarations of `{0}' " +
                                                "have conflicting accessibility modifiers",
-                                               name);
+                                               member_name.GetPartialName ());
                                        return null;
                                }
 
                                return pc;
                        }
 
-                       pc = new PartialContainer (ns, parent, name, mod_flags, kind, loc);
+                       pc = new PartialContainer (ns, parent, member_name, mod_flags, kind, loc);
                        RootContext.Tree.RecordDecl (full_name, pc);
                        parent.AddType (pc);
                        pc.Register ();
@@ -3557,6 +3574,34 @@ namespace Mono.CSharp {
                        return false;
                }
 
+               //
+               // Returns a string that represents the signature for this 
+               // member which should be used in XML documentation.
+               //
+               public override string GetDocCommentName (DeclSpace ds)
+               {
+                       return DocUtil.GetMethodDocCommentName (this, ds);
+               }
+
+               //
+               // Raised (and passed an XmlElement that contains the comment)
+               // when GenerateDocComment is writing documentation expectedly.
+               //
+               // FIXME: with a few effort, it could be done with XmlReader,
+               // that means removal of DOM use.
+               //
+               internal override void OnGenerateDocComment (DeclSpace ds, XmlElement el)
+               {
+                       DocUtil.OnMethodGenerateDocComment (this, ds, el);
+               }
+
+               //
+               //   Represents header string for documentation comment.
+               //
+               public override string DocCommentHeader {
+                       get { return "M:"; }
+               }
+
                protected override void VerifyObsoleteAttribute()
                {
                        base.VerifyObsoleteAttribute ();
@@ -5262,8 +5307,8 @@ namespace Mono.CSharp {
                                                      "Inconsistent accessibility: indexer return type `" +
                                                      TypeManager.CSharpName (MemberType) + "' is less " +
                                                      "accessible than indexer `" + Name + "'");
-                               else if (this is Method) {
-                                       if (((Method) this).IsOperator)
+                               else if (this is MethodCore) {
+                                       if (this is Operator)
                                                Report.Error (56, Location,
                                                              "Inconsistent accessibility: return type `" +
                                                              TypeManager.CSharpName (MemberType) + "' is less " +
@@ -5273,11 +5318,12 @@ namespace Mono.CSharp {
                                                              "Inconsistent accessibility: return type `" +
                                                              TypeManager.CSharpName (MemberType) + "' is less " +
                                                              "accessible than method `" + Name + "'");
-                               } else
+                               } else {
                                        Report.Error (52, Location,
                                                      "Inconsistent accessibility: field type `" +
                                                      TypeManager.CSharpName (MemberType) + "' is less " +
                                                      "accessible than field `" + Name + "'");
+                               }
                                return false;
                        }
 
@@ -5292,8 +5338,8 @@ namespace Mono.CSharp {
 
                                InterfaceType = iface_texpr.Type;
 
-                               if (InterfaceType.IsClass) {
-                                       Report.Error (538, Location, "'{0}' in explicit interface declaration is not an interface", ExplicitInterfaceName);
+                               if (!InterfaceType.IsInterface) {
+                                       Report.Error (538, Location, "'{0}' in explicit interface declaration is not an interface", TypeManager.CSharpName (InterfaceType));
                                        return false;
                                }
 
@@ -5357,7 +5403,8 @@ namespace Mono.CSharp {
                [Flags]
                public enum Status : byte {
                        ASSIGNED = 1,
-                       USED = 2
+                       USED = 2,
+                       HAS_OFFSET = 4          // Used by FieldMember.
                }
 
                static string[] attribute_targets = new string [] { "field" };
@@ -5522,7 +5569,7 @@ namespace Mono.CSharp {
 
        public abstract class FieldMember: FieldBase
        {
-               bool has_field_offset = false;
+               
 
                protected FieldMember (TypeContainer parent, Expression type, int mod,
                        int allowed_mod, MemberName name, object init, Attributes attrs, Location loc)
@@ -5534,7 +5581,7 @@ namespace Mono.CSharp {
                {
                        if (a.Type == TypeManager.field_offset_attribute_type)
                        {
-                               has_field_offset = true;
+                               status |= Status.HAS_OFFSET;
 
                                if (!Parent.HasExplicitLayout) {
                                        Report.Error (636, Location, "The FieldOffset attribute can only be placed on members of types marked with the StructLayout(LayoutKind.Explicit)");
@@ -5587,12 +5634,19 @@ namespace Mono.CSharp {
 
                public override void Emit ()
                {
-                       if (Parent.HasExplicitLayout && !has_field_offset && (ModFlags & Modifiers.STATIC) == 0) {
+                       if (Parent.HasExplicitLayout && ((status & Status.HAS_OFFSET) == 0) && (ModFlags & Modifiers.STATIC) == 0) {
                                Report.Error (625, Location, "'{0}': Instance field types marked with StructLayout(LayoutKind.Explicit) must have a FieldOffset attribute.", GetSignatureForError ());
                        }
 
                        base.Emit ();
                }
+
+               //
+               //   Represents header string for documentation comment.
+               //
+               public override string DocCommentHeader {
+                       get { return "F:"; }
+               }
        }
 
        //
@@ -5827,7 +5881,7 @@ namespace Mono.CSharp {
                {
                        if (a.Type == TypeManager.cls_compliant_attribute_type || a.Type == TypeManager.obsolete_attribute_type ||
                                        a.Type == TypeManager.conditional_attribute_type) {
-                               Report.Error (1667, a.Location, "'{0}' is not valid on property or event accessors. It is valid on '{1}' declarations only", TypeManager.CSharpName (a.Type), a.GetValidTargets ());
+                               Report.Error (1667, a.Location, "'{0}' is not valid on property or event accessors. It is valid on {1} declarations only", TypeManager.CSharpName (a.Type), a.GetValidTargets ());
                                return;
                        }
 
@@ -5861,7 +5915,7 @@ namespace Mono.CSharp {
 
                public override bool Define()
                {
-                       return false;
+                       throw new NotSupportedException ();
                }
 
                public virtual void Emit (TypeContainer container)
@@ -5908,6 +5962,13 @@ namespace Mono.CSharp {
                        }
                }
 
+               //
+               //   Represents header string for documentation comment.
+               //
+               public override string DocCommentHeader {
+                       get { throw new InvalidOperationException ("Unexpected attempt to get doc comment from " + this.GetType () + "."); }
+               }
+
                protected override void VerifyObsoleteAttribute()
                {
                }
@@ -6354,6 +6415,13 @@ namespace Mono.CSharp {
                                return attribute_targets;
                        }
                }
+
+               //
+               //   Represents header string for documentation comment.
+               //
+               public override string DocCommentHeader {
+                       get { return "P:"; }
+               }
        }
                        
        public class Property : PropertyBase, IIteratorContainer {
@@ -6621,6 +6689,10 @@ namespace Mono.CSharp {
                {
                        Add = new AddDelegateMethod (this, add);
                        Remove = new RemoveDelegateMethod (this, remove);
+
+                       // For this event syntax we don't report error CS0067
+                       // because it is hard to do it.
+                       SetAssigned ();
                }
 
                public override string[] ValidAttributeTargets {
@@ -6636,6 +6708,7 @@ namespace Mono.CSharp {
        public class EventField: Event {
 
                static string[] attribute_targets = new string [] { "event", "field", "method" };
+               static string[] attribute_targets_interface = new string[] { "event", "method" };
 
                public EventField (TypeContainer parent, Expression type, int mod_flags,
                                   bool is_iface, MemberName name, Object init,
@@ -6654,8 +6727,8 @@ namespace Mono.CSharp {
                        }
 
                        if (a.Target == AttributeTargets.Method) {
-                               AddBuilder.SetCustomAttribute (cb);
-                               RemoveBuilder.SetCustomAttribute (cb);
+                               Add.ApplyAttributeBuilder (a, cb);
+                               Remove.ApplyAttributeBuilder (a, cb);
                                return;
                        }
 
@@ -6664,7 +6737,7 @@ namespace Mono.CSharp {
 
                public override string[] ValidAttributeTargets {
                        get {
-                               return attribute_targets;
+                               return IsInterface ? attribute_targets_interface : attribute_targets;
                        }
                }
        }
@@ -7001,6 +7074,13 @@ namespace Mono.CSharp {
 
                        return TypeManager.GetFullNameSignature (EventBuilder);
                }
+
+               //
+               //   Represents header string for documentation comment.
+               //
+               public override string DocCommentHeader {
+                       get { return "E:"; }
+               }
        }
 
  
@@ -7133,8 +7213,11 @@ namespace Mono.CSharp {
                                return false;
 
                        if (OptAttributes != null) {
-                               Attribute indexer_attr = OptAttributes.GetIndexerNameAttribute (ec);
+                               Attribute indexer_attr = OptAttributes.Search (TypeManager.indexer_name_type, ec);
                                if (indexer_attr != null) {
+                                       // Remove the attribute from the list because it is not emitted
+                                       OptAttributes.Attrs.Remove (indexer_attr);
+
                                        ShortName = indexer_attr.GetIndexerAttributeValue (ec);
 
                                        if (IsExplicitImpl) {