2006-08-17 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / mbas / decl.cs
index 23449a4572e455f87e3b5fab6fada123d32554e5..4f17b3520e3d48ef8924f8b8a5c6a296e8fd08f8 100644 (file)
@@ -21,7 +21,8 @@ namespace Mono.MonoBASIC {
        ///   Base representation for members.  This is only used to keep track
        ///   of Name, Location and Modifier flags.
        /// </summary>
-       public abstract class MemberCore {
+       public abstract class MemberCore : Attributable
+       {
                /// <summary>
                ///   Public name
                /// </summary>
@@ -37,7 +38,8 @@ namespace Mono.MonoBASIC {
                /// </summary>
                public readonly Location Location;
 
-               public MemberCore (string name, Location loc)
+               public MemberCore (string name, Attributes attrs, Location loc)
+                       : base (attrs)
                {
                        Name = name;
                        Location = loc;
@@ -59,7 +61,7 @@ namespace Mono.MonoBASIC {
                        // FIXME: report the old/new permissions?
                        //
                        Report.Error (
-                               507, Location, parent.MakeName (Name) +
+                               31048, Location, parent.MakeName (Name) +
                                ": can't change the access modifiers when overriding inherited " +
                                "member `" + name + "'");
                }
@@ -75,26 +77,25 @@ namespace Mono.MonoBASIC {
                                                       MethodInfo mb, string name)
                {
                        bool ok = true;
-                       
+
                        if ((ModFlags & Modifiers.OVERRIDE) != 0){
-                               if (!(mb.IsAbstract || mb.IsVirtual)){
+                               // Now we check that the overriden method is not final
+                               if (mb.IsFinal) 
+                               {
+                                       Report.Error (30267, Location, parent.MakeName (Name) + " : cannot " +
+                                               "override inherited member `" + name +
+                                               "' because it is NotOverridable.");
+                                       ok = false;
+                               }
+                               else if (!(mb.IsAbstract || mb.IsVirtual)){
                                        Report.Error (
-                                               506, Location, parent.MakeName (Name) +
-                                               ": cannot override inherited member `" +
+                                               31086, Location, parent.MakeName (Name) +
+                                               ": Cannot override inherited member `" +
                                                name + "' because it is not " +
-                                               "virtual, abstract or override");
+                                               "declared as Overridable");
                                        ok = false;
                                }
                                
-                               // Now we check that the overriden method is not final
-                               
-                               if (mb.IsFinal) {
-                                       Report.Error (239, Location, parent.MakeName (Name) + " : cannot " +
-                                                     "override inherited member `" + name +
-                                                     "' because it is sealed.");
-                                       ok = false;
-                               }
-
                                //
                                // Check that the permissions are not being changed
                                //
@@ -107,7 +108,27 @@ namespace Mono.MonoBASIC {
                                }
                        }
 
-                       if (mb.IsVirtual || mb.IsAbstract){
+                       if ((ModFlags & ( Modifiers.NEW | Modifiers.SHADOWS | Modifiers.OVERRIDE )) == 0) {
+                               if ((ModFlags & Modifiers.NONVIRTUAL) != 0)     {
+                                       Report.Error (31088, Location,
+                                               parent.MakeName (Name) + " cannot " +
+                                               "be declared NotOverridable since this method is " +
+                                               "not marked as Overrides");
+                               }
+                       }
+
+                       if (mb.IsAbstract) {
+                               if ((ModFlags & (Modifiers.OVERRIDE)) == 0)     {
+                                       if (Name != "Finalize") {
+                                               Report.Error (
+                                                       31404, Location, 
+                                                       name + " cannot Shadows the method " +
+                                                       parent.MakeName (Name) + " since it is declared " +
+                                                       "'MustOverride' in base class");
+                                       }
+                               }
+                       }
+                       else if (mb.IsVirtual){
                                if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE | Modifiers.SHADOWS)) == 0){
                                        if (Name != "Finalize"){
                                                Report.Warning (
@@ -118,10 +139,10 @@ namespace Mono.MonoBASIC {
                                                ModFlags |= Modifiers.SHADOWS;
                                        }
                                }
-                       } else {
+                       } 
+                       else {
                                if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE | 
-                                       Modifiers.SHADOWS)) == 0)
-                               {
+                                       Modifiers.SHADOWS)) == 0){
                                        if (Name != "Finalize"){
                                                Report.Warning (
                                                        40004, 1, Location, "The keyword Shadows is required on " +
@@ -177,15 +198,6 @@ namespace Mono.MonoBASIC {
                        /// </summary>
                        NameExists,
 
-                       /// <summary>
-                       ///   Returned if the declation being added to the
-                       ///   name space clashes with its container name.
-                       ///
-                       ///   The only exceptions for this are constructors
-                       ///   and static constructors
-                       /// </summary>
-                       EnclosingClash,
-
                        /// <summary>
                        ///   Returned if a constructor was created (because syntactically
                        ///   it looked like a constructor) but was not (because the name
@@ -238,8 +250,8 @@ namespace Mono.MonoBASIC {
 
                TypeContainer parent;           
 
-               public DeclSpace (TypeContainer parent, string name, Location l)
-                       : base (name, l)
+               public DeclSpace (TypeContainer parent, string name, Attributes attrs, Location l)
+                       : base (name, attrs, l)
                {
                        Basename = name.Substring (1 + name.LastIndexOf ('.'));
                        defined_names = new Hashtable ();
@@ -252,9 +264,6 @@ namespace Mono.MonoBASIC {
                /// </summary>
                protected AdditionResult IsValid (string name)
                {
-                       if (name == Basename)
-                               return AdditionResult.EnclosingClash;
-
                        if (defined_names.Contains (name))
                                return AdditionResult.NameExists;
 
@@ -268,7 +277,15 @@ namespace Mono.MonoBASIC {
                /// </summary>
                protected void DefineName (string name, object o)
                {
-                       defined_names.Add (name, o);
+                       try {
+                               defined_names.Add (name, o);
+                       } 
+                       catch (ArgumentException exp) {
+                               Report.Error (30260, /*Location,*/
+                                       "More than one defination with same name '" + name + 
+                                       "' is found in the container '" + Name + "'");  
+                   }
+
                }
 
                /// <summary>
@@ -399,7 +416,7 @@ namespace Mono.MonoBASIC {
                        Expression d = e.Resolve (type_resolve_ec, ResolveFlags.Type);
                        if (d == null || d.eclass != ExprClass.Type){
                                if (!silent && errors == Report.Errors){
-                                       Report.Error (246, loc, "Cannot find type `"+ e.ToString () +"'");
+                                       Report.Error (30002, loc, "Cannot find type `"+ e.ToString () +"'");
                                }
                                return null;
                        }
@@ -419,7 +436,7 @@ namespace Mono.MonoBASIC {
                        Expression d = e.Resolve (type_resolve_ec, ResolveFlags.Type);
                        if (d == null || d.eclass != ExprClass.Type){
                                if (!silent){
-                                       Report.Error (246, loc, "Cannot find type `"+ e +"'");
+                                       Report.Error (30002, loc, "Cannot find type `"+ e +"'");
                                }
                                return null;
                        }
@@ -445,7 +462,7 @@ namespace Mono.MonoBASIC {
                        
                        t = parent.DefineType ();
                        if (t == null){
-                               Report.Error (146, Location, "Class definition is circular: `"+name+"'");
+                               Report.Error (30256, Location, "Class definition is circular: `"+name+"'");
                                error = true;
                                return null;
                        }
@@ -540,10 +557,10 @@ namespace Mono.MonoBASIC {
                                //
                                // Now check the using clause list
                                //
-                               ICollection imports_list = RootContext.SourceBeingCompiled.ImportsTable;\r
-\r
-                               if (imports_list == null)\r
-                                       continue;\r
+                               ICollection imports_list = RootContext.SourceBeingCompiled.ImportsTable;
+
+                               if (imports_list == null)
+                                       continue;
 
                                Type match = null;
                                foreach (SourceBeingCompiled.ImportsEntry ue in imports_list){
@@ -584,8 +601,24 @@ namespace Mono.MonoBASIC {
                public abstract MemberCache MemberCache {
                        get;
                }
+
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+               {
+                       try {
+                               TypeBuilder.SetCustomAttribute (cb);
+                       } catch (System.ArgumentException e) {
+                               Report.Warning (-21, a.Location,
+                                               "The CharSet named property on StructLayout\n"+
+                                               "\tdoes not work correctly on Microsoft.NET\n"+
+                                               "\tYou might want to remove the CharSet declaration\n"+
+                                               "\tor compile using the Mono runtime instead of the\n"+
+                                               "\tMicrosoft .NET runtime\n"+
+                                               "\tThe runtime gave the error: " + e);
+                       }
+               }
        }
 
+
        /// <summary>
        ///   This is a readonly list of MemberInfo's.      
        /// </summary>
@@ -858,7 +891,10 @@ namespace Mono.MonoBASIC {
 
                        IDictionaryEnumerator it = parent.member_hash.GetEnumerator ();
                        while (it.MoveNext ()) {
-                               hash [it.Key] = ((ArrayList) it.Value).Clone ();
+                               ArrayList al = (ArrayList) it.Value;
+                               // Constructors are never inherited and all have the same key
+                               if ((((CacheEntry)al [0]).EntryType & EntryType.Constructor) == 0)
+                                       hash [it.Key] = ((ArrayList) it.Value).Clone ();
                        }
 
                        return hash;
@@ -948,9 +984,9 @@ namespace Mono.MonoBASIC {
                void AddMembers (MemberTypes mt, BindingFlags bf, IMemberContainer container)
                {
                        MemberList members = container.GetMembers (mt, bf);
-                       BindingFlags new_bf = (container == Container) ?
+                       /*BindingFlags new_bf = (container == Container) ?
                                bf | BindingFlags.DeclaredOnly : bf;
-
+                       */
                        foreach (MemberInfo member in members) {
                                string name = member.Name;
 
@@ -1194,7 +1230,8 @@ bf |= BindingFlags.IgnoreCase;
                                // iteration of this loop if there are no members with the name we're
                                // looking for in the current class).
                                if (entry.Container != current) {
-                                       if (declared_only || DoneSearching (list))
+                                       //if (declared_only || DoneSearching (list))
+                                       if (declared_only)
                                                break;
 
                                        current = entry.Container;