2006-08-17 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / mbas / class.cs
index b4d265d810f536b5ab13f0cb6120f47b6be211fe..535d3d5ac6755228a083badbcba8f08eadfda0b5 100644 (file)
@@ -83,7 +83,7 @@ namespace Mono.MonoBASIC {
                // Holds the events
                ArrayList events;
 
-               // Holds AddHandlers stements for events
+               // Holds AddHandlers statements for events
                ArrayList handlers;
 
                // The emit context for toplevel objects.
@@ -138,22 +138,23 @@ namespace Mono.MonoBASIC {
                //
                // The indexer name for this class
                //
-               public string IndexerName;
+               public string DefaultPropName;
 
                public TypeContainer (TypeContainer parent, string name, Attributes attrs, Location l)
                        : base (parent, name, attrs, l)
                {
-                       string n;
                        types = new ArrayList ();
+                       
+                       base_class_name = null;
 
+                       /* string n;
+                         
                        if (parent == null)
                                n = "";
                        else
                                n = parent.Name;
 
-                       base_class_name = null;
-                       
-                       //Console.WriteLine ("New class " + name + " inside " + n);
+                       Console.WriteLine ("New class " + name + " inside " + n);*/
                }
 
                public AdditionResult AddConstant (Const constant)
@@ -255,9 +256,6 @@ namespace Mono.MonoBASIC {
                        if (value != null && (!(value is Method)))
                                return AdditionResult.NameExists;
 
-                       if (basename == Basename)
-                               return AdditionResult.EnclosingClash;
-                       
                        if (methods == null)
                                methods = new ArrayList ();
 
@@ -364,6 +362,13 @@ namespace Mono.MonoBASIC {
                        AdditionResult res;
                        string basename = prop.Name;
 
+                       string fullname = Name + "." + basename;
+
+                       Object value = defined_names [fullname];
+
+                       if (value != null && (!(value is Property)))
+                               return AdditionResult.NameExists;
+
                        if ((res = IsValid (basename)) != AdditionResult.Success)
                                return res;
 
@@ -374,7 +379,9 @@ namespace Mono.MonoBASIC {
                                properties.Insert (0, prop);
                        else
                                properties.Add (prop);
-                       DefineName (Name + "." + basename, prop);
+
+                       if (value == null)
+                               DefineName (Name + "." + basename, prop);
 
                        return AdditionResult.Success;
                }
@@ -527,7 +534,7 @@ namespace Mono.MonoBASIC {
                public bool EmitFieldInitializers (EmitContext ec)
                {
                        ArrayList fields;
-                       ILGenerator ig = ec.ig;
+                       //ILGenerator ig = ec.ig;
                        Expression instance_expr;
                        
                        if (ec.IsStatic){
@@ -681,7 +688,7 @@ namespace Mono.MonoBASIC {
                                                                "'NotInheritable' class " + TypeManager.MonoBASIC_Name (parent));
                                        
                                if (!AsAccessible (parent, ModFlags))
-                                       Report.Error (30389, Location,
+                                        Report.Error (30389, Location,
                                                      "Inconsistent accessibility: base class `" +
                                                      TypeManager.MonoBASIC_Name (parent) + "' is less " +
                                                      "accessible than class `" +
@@ -704,7 +711,7 @@ namespace Mono.MonoBASIC {
                                }
 
                                if (is_class == false && !t.IsInterface){
-                                       Report.Error (527, "In Struct `" + Name + "', type `"+
+                                       Report.Error (527, Location, "In Struct `" + Name + "', type `"+
                                                      name +"' is not an interface");
                                        error = true;
                                        return null;
@@ -712,10 +719,10 @@ namespace Mono.MonoBASIC {
                        
                                if (t.IsSealed) {
                                        if (t.IsValueType)
-                                               Report.Error (30258, "class `"+ Name +
+                                               Report.Error (30258, Location, "class `"+ Name +
                                                        "': a class can not inherit from a struct/enum");
                                                        
-                                       /*Report.Error (509, "class `"+ Name +
+                                       /*Report.Error (509, Location, "class `"+ Name +
                                                      "': Cannot inherit from sealed class `"+
                                                      bases [i]);*/
                                        error = true;
@@ -724,7 +731,7 @@ namespace Mono.MonoBASIC {
 
                                if (t.IsClass) {
                                        if (parent != null){
-                                               Report.Error (30121, Name + ": A class cannot inherit " +
+                                               Report.Error (30121, Location, Name + ": A class cannot inherit " +
                                                        "more than one class");
                                                error = true;
                                                return null;
@@ -733,7 +740,7 @@ namespace Mono.MonoBASIC {
 
                                for (int x = 0; x < j; x++) {
                                        if (t == ifaces [x]) {
-                                               Report.Error (528, "`" + name + "' is already listed in interface list");
+                                               Report.Error (528,Location, "`" + name + "' is already listed in interface list");
                                                error = true;
                                                return null;
                                        }
@@ -861,8 +868,14 @@ namespace Mono.MonoBASIC {
                            (base_class_type == TypeManager.attribute_type ||
                             base_class_type.IsSubclassOf (TypeManager.attribute_type))) {
                                RootContext.RegisterAttribute (this);
-                       } else
-                               RootContext.RegisterOrder (this); 
+                       }
+                       else
+                       {
+                               if ( this is Interface)
+                                       RootContext.RegisterOrder ((Interface) this); 
+                               else    
+                                       RootContext.RegisterOrder (this); 
+                       }
                                
                        if (Interfaces != null) {
                                foreach (Interface iface in Interfaces)
@@ -1265,7 +1278,7 @@ namespace Mono.MonoBASIC {
                                                        continue;
                                                if ((p.ModFlags & static_mask) != static_flags)
                                                        continue;
-
+                                               
                                                MemberInfo pb = p.PropertyBuilder;
 
                                                if (pb != null && filter (pb, criteria) == true)
@@ -1417,8 +1430,8 @@ namespace Mono.MonoBASIC {
                                foreach (Property p in properties)
                                        p.Emit (this);
 
-                       if (this.IndexerName != null) {
-                               CustomAttributeBuilder cb = new CustomAttributeBuilder (TypeManager.default_member_ctor, new string [] { IndexerName });
+                       if (this.DefaultPropName != null) {
+                               CustomAttributeBuilder cb = new CustomAttributeBuilder (TypeManager.default_member_ctor, new string [] { DefaultPropName });
                                TypeBuilder.SetCustomAttribute (cb);
                        }
                        
@@ -1445,6 +1458,9 @@ namespace Mono.MonoBASIC {
                                foreach (Field f in fields) {
                                        if ((f.ModFlags & Modifiers.PUBLIC) != 0)
                                                continue;
+                                               
+                                       if (f.Name.StartsWith(@"$STATIC$"))
+                                               continue;
 
                                        if (f.status == 0){
                                                Report.Warning (
@@ -1556,7 +1572,7 @@ namespace Mono.MonoBASIC {
                {
                        const int vao = (Modifiers.VIRTUAL | Modifiers.ABSTRACT | Modifiers.OVERRIDE);
                        const int va = (Modifiers.VIRTUAL | Modifiers.ABSTRACT);
-                       const int nv = (Modifiers.SHADOWS | Modifiers.VIRTUAL);
+                       //const int nv = (Modifiers.SHADOWS | Modifiers.VIRTUAL);
                        bool ok = true;
                        string name = MakeName (n);
                        
@@ -1631,7 +1647,7 @@ namespace Mono.MonoBASIC {
                        if ((flags & Modifiers.PRIVATE) != 0){
                                if ((flags & vao) != 0){
                                        Report.Error (
-                                               31408, loc, name +
+                                               30266, loc, name +
                                                ": Members marked as Overridable or Overrides can not be Private");
                                        ok = false;
                                }
@@ -1670,7 +1686,7 @@ namespace Mono.MonoBASIC {
                // and return the new level.
                static AccessLevel CheckAccessLevel (AccessLevel level, int flags)
                {
-                       AccessLevel old_level = level;
+                       //AccessLevel old_level = level;
 
                        if ((flags & Modifiers.INTERNAL) != 0) {
                                if ((flags & Modifiers.PROTECTED) != 0) {
@@ -2192,7 +2208,7 @@ namespace Mono.MonoBASIC {
                                                WarningNotHiding (parent);*/
 
                                        if ((ModFlags & Modifiers.OVERRIDE) != 0){
-                                               Report.Error (30284, Location,
+                                               Report.Error (30398, Location,
                                                              parent.MakeName (Name) +
                                                              " : No suitable methods found to override");
                                        }
@@ -3294,11 +3310,14 @@ namespace Mono.MonoBASIC {
                                                TypeManager.ExpandAllInterfaces (tbases, ref bases);
 
                                                foreach (Type tbase in bases) {
+                                                       /*
                                                        string bname = tbase.Name;
                                                        if (bname.LastIndexOf(".") != -1)
                                                                bname = bname.Substring(bname.LastIndexOf("."));
+                                                       */
 
-                                                       if (bname == iname)     {
+                                                       //if (bname == iname)   {
+                                                       if (tbase == InterfaceType) {
                                                                iface_found = true;
                                                                break;
                                                        }
@@ -3321,7 +3340,7 @@ namespace Mono.MonoBASIC {
                                                      TypeManager.MonoBASIC_Name (MemberType) + "' is less " +
                                                      "accessible than property `" + Name + "'");
                                else if (this is Method)
-                                       Report.Error (50, Location,
+                                       Report.Error (30508, Location,
                                                      "Inconsistent accessibility: return type `" +
                                                      TypeManager.MonoBASIC_Name (MemberType) + "' is less " +
                                                      "accessible than method `" + Name + "'");
@@ -3536,8 +3555,14 @@ namespace Mono.MonoBASIC {
                                              "' causes a cycle in the structure layout");
                                return false;
                        }
-                       FieldBuilder = parent.TypeBuilder.DefineField (
-                               Name, t, Modifiers.FieldAttr (ModFlags));
+                       
+                       //Local Static Variable
+                        if (Name.StartsWith(@"$STATIC$"))
+                                FieldBuilder = parent.TypeBuilder.DefineField (
+                                        Name, t, Modifiers.FieldAttr (ModFlags) | FieldAttributes.SpecialName);
+                        else
+                                FieldBuilder = parent.TypeBuilder.DefineField (
+                                        Name, t, Modifiers.FieldAttr (ModFlags));
 
                        TypeManager.RegisterFieldBase (FieldBuilder, this);
                        return true;
@@ -3790,7 +3815,7 @@ namespace Mono.MonoBASIC {
                        if ((ModFlags & Modifiers.READONLY) != 0)
                                retval = MemberType;
 
-                       string report_name;
+                       //string report_name;
                        MethodSignature base_ms;
                        
                        /*
@@ -3803,7 +3828,7 @@ namespace Mono.MonoBASIC {
                                base_name = TypeManager.IndexerPropertyName (container.TypeBuilder.BaseType);
                                base_ms = new MethodSignature (base_name, retval, ParameterTypes);
                        } else */ {
-                               report_name = Name;
+                               //report_name = Name;
                                ms = base_ms = new MethodSignature (Name, retval, ParameterTypes);
                        }
 
@@ -3830,7 +3855,6 @@ namespace Mono.MonoBASIC {
                                MethodSignature.inheritable_property_signature_filter,
                                base_ms);
 
-
                        if (mi_instance.Count > 0)
                                mi = mi_instance;
                        else if (mi_static.Count > 0)
@@ -3840,7 +3864,6 @@ namespace Mono.MonoBASIC {
 
                        if (mi != null && mi.Count > 0) 
                                parent_member = (PropertyInfo) mi [0];
-
                        if (parent_member is PropertyInfo) {
                                PropertyInfo parent_property = (PropertyInfo)parent_member;
 
@@ -3877,20 +3900,6 @@ namespace Mono.MonoBASIC {
                                /*if ((ModFlags & Modifiers.NEW) != 0)
                                        WarningNotHiding (container);
                                */
-                               if ((ModFlags & Modifiers.OVERRIDE) != 0) {
-
-                                       /*
-                                       if (this is Indexer)
-                                               Report.Error (115, Location,
-                                                       container.MakeName (Name) +
-                                                       " no suitable indexers found to override");
-                                       else
-                                       */
-                                               Report.Error (115, Location,
-                                                       container.MakeName (Name) +
-                                                       " no suitable properties found to override");
-                                       return false;
-                               }
 
                                if ((ModFlags & ( Modifiers.NEW | Modifiers.SHADOWS | Modifiers.OVERRIDE )) == 0) {
                                        if ((ModFlags & Modifiers.NONVIRTUAL) != 0)     {
@@ -3930,9 +3939,9 @@ namespace Mono.MonoBASIC {
                        Modifiers.WRITEONLY |
                        Modifiers.SHADOWS;
 
-               string set_parameter_name;
-               Parameters get_params;
-               Parameters set_params;
+               //string set_parameter_name;
+               //Parameters get_params;
+               //Parameters set_params;
                
                public Property (Expression type, string name, int mod_flags,
                                Accessor get_block, Accessor set_block,
@@ -3960,15 +3969,21 @@ namespace Mono.MonoBASIC {
 
                public override bool Define (TypeContainer parent)
                {
-                       Type [] s_parameters=null;
+                       /*Type [] s_parameters=null;
                        Parameter [] s_parms;
-                       InternalParameters s_ip=null;
+                       InternalParameters s_ip=null;*/
                        
                        if ((parent is Struct) && ((ModFlags & Modifiers.PROTECTED) != 0))
                                Report.Error (30435, Location,
                                        "'Property' inside a 'Structure' can not be declared as " +
                                        "'Protected' or 'Protected Friend'");
 
+                       if (((ModFlags & Modifiers.DEFAULT) != 0) && (Parameters == null || Parameters.CountStandardParams () == 0)) {
+                               Report.Error (31048, Location, "Properties with no required " +
+                                       "parameters cannot be declared 'Default'");
+                               return false;
+                       }
+
                        if (!DoDefine (parent))
                                return false;
 
@@ -4248,7 +4263,7 @@ namespace Mono.MonoBASIC {
 
                public MethodBuilder Define (TypeContainer parent)
                {
-                       EventAttributes e_attr = EventAttributes.RTSpecialName | EventAttributes.SpecialName;
+                       //EventAttributes e_attr = EventAttributes.RTSpecialName | EventAttributes.SpecialName;
 
                        Type [] parameter_types = new Type [1];
                        parameter_types [0] = parent_event.MemberType;
@@ -4347,8 +4362,9 @@ namespace Mono.MonoBASIC {
 
                        Parameter [] parms = new Parameter [1];
                        parms [0] = new Parameter (Type, /* was "value" */ this.Name, Parameter.Modifier.NONE, null);
-                       InternalParameters ip = new InternalParameters (
+                       /*InternalParameters ip = new InternalParameters (
                                parent, new Parameters (parms, null, Location)); 
+                       */
 
                        if (!CheckBase (parent))
                                return false;