2005-01-26 Rafael Teixeira <rafaelteixeirabr@hotmail.com>
[mono.git] / mcs / mbas / class.cs
index 8171bc6d1292672bacbea95579a8e0350b540cee..0c715930afd7b03620ce72473e3db3cd8784f785 100644 (file)
@@ -4,6 +4,7 @@
 //
 // Authors: Miguel de Icaza (miguel@gnu.org)
 //          Martin Baulig (martin@gnome.org)
+//                     Anirban Bhattacharjee (banirban@novell.com)
 //
 // Licensed under the terms of the GNU GPL
 //
@@ -37,7 +38,7 @@ using System.Reflection.Emit;
 using System.Runtime.CompilerServices;
 using System.Diagnostics.SymbolStore;
 
-namespace Mono.CSharp {
+namespace Mono.MonoBASIC {
 
        /// <summary>
        ///   This is the base class for structs and classes.  
@@ -82,15 +83,12 @@ namespace Mono.CSharp {
                // Holds the events
                ArrayList events;
 
-               // Holds the indexers
-               ArrayList indexers;
-
-               // Holds the operators
-               ArrayList operators;
+               // Holds AddHandlers stements for events
+               ArrayList handlers;
 
                // The emit context for toplevel objects.
                EmitContext ec;
-               
+
                //
                // Pointers to the default constructor and the default static constructor
                //
@@ -112,17 +110,23 @@ namespace Mono.CSharp {
                // from classes from the arraylist `type_bases' 
                //
                string     base_class_name;
-
+               public Type base_class_type;
+               
                ArrayList type_bases;
 
-               // Attributes for this type
-               protected Attributes attributes;
-
                // Information in the case we are an attribute type
 
-               public AttributeTargets Targets = AttributeTargets.All;
-               public bool AllowMultiple = false;
-               public bool Inherited;
+               AttributeUsageAttribute attribute_usage = new AttributeUsageAttribute (AttributeTargets.All);
+
+               public AttributeUsageAttribute AttributeUsage {
+                       get {
+                               return attribute_usage;
+                       }
+
+                       set {
+                               attribute_usage = value;
+                       }                               
+               }
 
                // The interfaces we implement.
                Type [] ifaces;
@@ -134,22 +138,23 @@ namespace Mono.CSharp {
                //
                // The indexer name for this class
                //
-               public string IndexerName;
+               public string DefaultPropName;
 
-               public TypeContainer (TypeContainer parent, string name, Location l)
-                       : base (parent, name, l)
+               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)
@@ -169,7 +174,7 @@ namespace Mono.CSharp {
                        return AdditionResult.Success;
                }
 
-               public AdditionResult AddEnum (Mono.CSharp.Enum e)
+               public AdditionResult AddEnum (Mono.MonoBASIC.Enum e)
                {
                        AdditionResult res;
 
@@ -188,13 +193,27 @@ namespace Mono.CSharp {
                public AdditionResult AddClass (Class c)
                {
                        AdditionResult res;
-
+                       
                        if ((res = IsValid (c.Basename)) != AdditionResult.Success)
                                return res;
-
+                               
+       
+                                       
                        DefineName (c.Name, c);
                        types.Add (c);
-
+                       
+                       // FIXME: Do we really need to explicitly add an empty default static constructor?
+                       // Apparently we don't
+/*                     if (c.default_static_constructor == null) 
+                       {
+                               bool isModule = c is Mono.MonoBASIC.Module;
+                               Constructor dc = new Constructor ("New", Parameters.EmptyReadOnlyParameters, null, c.Location);
+                               dc.ModFlags = isModule ? Modifiers.PUBLIC | Modifiers.STATIC : Modifiers.PUBLIC;                                
+                               c.AddConstructor (dc);          
+                       } 
+*/
+                       //--------------------------------------------------------------                                
+                               
                        return AdditionResult.Success;
                }
 
@@ -239,7 +258,7 @@ namespace Mono.CSharp {
 
                        if (basename == Basename)
                                return AdditionResult.EnclosingClash;
-
+                       
                        if (methods == null)
                                methods = new ArrayList ();
 
@@ -260,7 +279,7 @@ namespace Mono.CSharp {
                                return AdditionResult.NotAConstructor;
 
                        bool is_static = (c.ModFlags & Modifiers.STATIC) != 0;
-                       
+
                        if (is_static){
                                have_static_constructor = true;
                                if (default_static_constructor != null){
@@ -272,8 +291,8 @@ namespace Mono.CSharp {
                                default_static_constructor = c;
                        } else {
                                if (c.IsDefault ()){
-                                       if (default_constructor != null)
-                                               return AdditionResult.MethodExists;
+                                       /*if (default_constructor != null)
+                                               return AdditionResult.MethodExists;*/
                                        default_constructor = c;
                                }
                                
@@ -314,8 +333,8 @@ namespace Mono.CSharp {
                        
                        fields.Add (field);
                        
-                       if (field.HasInitializer){
-                               if ((field.ModFlags & Modifiers.STATIC) != 0){
+                       if (field.HasInitializer){      
+                               if ((field.ModFlags & Modifiers.STATIC) != 0) {
                                        if (initialized_static_fields == null)
                                                initialized_static_fields = new ArrayList ();
 
@@ -346,6 +365,13 @@ namespace Mono.CSharp {
                        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;
 
@@ -356,7 +382,9 @@ namespace Mono.CSharp {
                                properties.Insert (0, prop);
                        else
                                properties.Add (prop);
-                       DefineName (Name + "." + basename, prop);
+
+                       if (value == null)
+                               DefineName (Name + "." + basename, prop);
 
                        return AdditionResult.Success;
                }
@@ -378,26 +406,12 @@ namespace Mono.CSharp {
                        return AdditionResult.Success;
                }
 
-               public AdditionResult AddIndexer (Indexer i)
-               {
-                       if (indexers == null)
-                               indexers = new ArrayList ();
-
-                       if (i.InterfaceType != null)
-                               indexers.Insert (0, i);
-                       else
-                               indexers.Add (i);
-
-                       return AdditionResult.Success;
-               }
-
-               public AdditionResult AddOperator (Operator op)
+               public AdditionResult AddEventHandler (Statement stmt)
                {
-                       if (operators == null)
-                               operators = new ArrayList ();
-
-                       operators.Add (op);
+                       if (handlers == null)
+                               handlers = new ArrayList ();
 
+                       handlers.Add (stmt);
                        return AdditionResult.Success;
                }
 
@@ -408,7 +422,17 @@ namespace Mono.CSharp {
 
                        interface_order.Add (iface);
                }
-               
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+               {
+                       base.ApplyAttributeBuilder (a, cb);
+               } 
+
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               throw new NotSupportedException ();
+                       }
+               }
+
                public ArrayList Types {
                        get {
                                return types;
@@ -483,30 +507,12 @@ namespace Mono.CSharp {
                        }
                }
 
-               public ArrayList Indexers {
-                       get {
-                               return indexers;
-                       }
-               }
-
-               public ArrayList Operators {
-                       get {
-                               return operators;
-                       }
-               }
-
                public ArrayList Delegates {
                        get {
                                return delegates;
                        }
                }
                
-               public Attributes OptAttributes {
-                       get {
-                               return attributes;
-                       }
-               }
-               
                public bool HaveStaticConstructor {
                        get {
                                return have_static_constructor;
@@ -519,13 +525,19 @@ namespace Mono.CSharp {
                        }
                }
 
+               public ArrayList EventHandlers {
+                       get {
+                               return handlers;
+                       }
+               }
+
                //
                // Emits the instance field initializers
                //
                public bool EmitFieldInitializers (EmitContext ec)
                {
                        ArrayList fields;
-                       ILGenerator ig = ec.ig;
+                       //ILGenerator ig = ec.ig;
                        Expression instance_expr;
                        
                        if (ec.IsStatic){
@@ -571,16 +583,18 @@ namespace Mono.CSharp {
                        Constructor c;
                        int mods = 0;
 
-                       c = new Constructor (Basename, Parameters.EmptyReadOnlyParameters,
-                                            new ConstructorBaseInitializer (
-                                                    null, Parameters.EmptyReadOnlyParameters,
-                                                    Location.Null),
+                       c = new Constructor ("New", Parameters.EmptyReadOnlyParameters,
+                                            null,
                                             Location.Null);
                        
-                       if (is_static)
+                       if (is_static) {
                                mods = Modifiers.STATIC;
-
-                       c.ModFlags = mods;
+                               c.ModFlags = mods;
+                       }
+                       else 
+                               c.Initializer = new ConstructorBaseInitializer (
+                                       null, Parameters.EmptyReadOnlyParameters,
+                                       Location.Null);
 
                        AddConstructor (c);
                        
@@ -594,7 +608,7 @@ namespace Mono.CSharp {
                        
                        foreach (Field f in initialized_fields){
                                Report.Error (
-                                       573, Location,
+                                       31049, Location,
                                        "`" + n + "." + f.Name + "': can not have " +
                                        "instance field initializers in structs");
                        }
@@ -652,7 +666,7 @@ namespace Mono.CSharp {
                        //
                        count = bases.Count;
 
-                       if (is_class){
+                       if (is_class && (!(this is Interface))){
                                Expression name = (Expression) bases [0];
                                name = ResolveTypeExpr (name, false, Location);
 
@@ -671,10 +685,15 @@ namespace Mono.CSharp {
                                        start = 0;
                                }
 
+                               if (parent.IsSealed )
+                                       Report.Error (30299, Location,
+                                                               "Class " + Name + " cannot inherit " +
+                                                               "'NotInheritable' class " + TypeManager.MonoBASIC_Name (parent));
+                                       
                                if (!AsAccessible (parent, ModFlags))
-                                       Report.Error (60, Location,
+                                       Report.Error (30389, Location,
                                                      "Inconsistent accessibility: base class `" +
-                                                     TypeManager.CSharpName (parent) + "' is less " +
+                                                     TypeManager.MonoBASIC_Name (parent) + "' is less " +
                                                      "accessible than class `" +
                                                      Name + "'");
 
@@ -689,7 +708,6 @@ namespace Mono.CSharp {
                                Expression resolved = ResolveTypeExpr (name, false, Location);
                                bases [i] = resolved;
                                Type t = resolved.Type;
-
                                if (t == null){
                                        error = true;
                                        return null;
@@ -701,24 +719,23 @@ namespace Mono.CSharp {
                                        error = true;
                                        return null;
                                }
-                               
+                       
                                if (t.IsSealed) {
-                                       string detail = "";
-                                       
                                        if (t.IsValueType)
-                                               detail = " (a class can not inherit from a struct/enum)";
+                                               Report.Error (30258, "class `"+ Name +
+                                                       "': a class can not inherit from a struct/enum");
                                                        
-                                       Report.Error (509, "class `"+ Name +
+                                       /*Report.Error (509, "class `"+ Name +
                                                      "': Cannot inherit from sealed class `"+
-                                                     bases [i]+"'"+detail);
+                                                     bases [i]);*/
                                        error = true;
                                        return null;
                                }
 
                                if (t.IsClass) {
                                        if (parent != null){
-                                               Report.Error (527, "In Class `" + Name + "', type `"+
-                                                             name+"' is not an interface");
+                                               Report.Error (30121, Name + ": A class cannot inherit " +
+                                                       "more than one class");
                                                error = true;
                                                return null;
                                        }
@@ -735,7 +752,7 @@ namespace Mono.CSharp {
                                ifaces [j] = t;
                        }
 
-                       return TypeManager.ExpandInterfaces (ifaces);
+                       return ifaces;
                }
                
                //
@@ -743,7 +760,6 @@ namespace Mono.CSharp {
                //
                public override TypeBuilder DefineType ()
                {
-                       Type parent;
                        bool error;
                        bool is_class;
 
@@ -760,21 +776,29 @@ namespace Mono.CSharp {
                        else
                                is_class = false;
 
-                       ec = new EmitContext (this, Mono.CSharp.Location.Null, null, null, ModFlags);
+                       ec = new EmitContext (this, Mono.MonoBASIC.Location.Null, null, null, ModFlags);
 
-                       ifaces = GetClassBases (is_class, out parent, out error); 
+                       if (((ModFlags & Modifiers.ABSTRACT ) != 0) && 
+                                               ((ModFlags & Modifiers.SEALED) != 0)){
+                               Report.Error (31408, Location,
+                                       "Class declared as 'MustInherit' cannot be declared as 'NotInheritable'");
+                       }
                        
+                       ifaces = GetClassBases (is_class, out base_class_type, out error); 
                        if (error)
                                return null;
 
-                       if (is_class && parent != null){
-                               if (parent == TypeManager.enum_type ||
-                                   (parent == TypeManager.value_type && RootContext.StdLib) ||
-                                   parent == TypeManager.delegate_type ||
-                                   parent == TypeManager.array_type){
+                       if (this is Interface)
+                               base_class_type = null;
+
+                       if (is_class && base_class_type != null){
+                               if (base_class_type == TypeManager.enum_type ||
+                                   (base_class_type == TypeManager.value_type && RootContext.StdLib) ||
+                                   base_class_type == TypeManager.delegate_type ||
+                                   base_class_type == TypeManager.array_type){
                                        Report.Error (
                                                644, Location, "`" + Name + "' cannot inherit from " +
-                                               "special class `" + TypeManager.CSharpName (parent) + "'");
+                                               "special class `" + TypeManager.MonoBASIC_Name (base_class_type) + "'");
                                        return null;
                                }
                        }
@@ -782,37 +806,59 @@ namespace Mono.CSharp {
                        if (!is_class && TypeManager.value_type == null)
                                throw new Exception ();
 
+                       if (is_class  && Parent.Parent == null && (!(this is Interface))) 
+                       {
+                               if ((ModFlags & Modifiers.PRIVATE) != 0)
+                                       Report.Error (31089, Location,
+                                               "Only internal classes can be declared as 'Private'");
+
+                               if ((ModFlags & Modifiers.PROTECTED) != 0)
+                                       Report.Error (31047, Location,
+                                               "Only internal classes can be declared as 'Protected'");
+                       }
+
+                       if ((Parent is Module) && ((ModFlags & Modifiers.PROTECTED) != 0))
+                               Report.Error (30735, Location,
+                                       "'Type' inside a 'Module' can not be " +
+                                       "declared as 'Protected'");
+
+                       if ((Parent is Struct) && ((ModFlags & Modifiers.PROTECTED) != 0))
+                               Report.Error (31047, Location,
+                                       "'Type' inside a 'Structure' can not be " +
+                                       "declared as 'Protected'");
+                       
                        TypeAttributes type_attributes = TypeAttr;
 
-                       // if (parent_builder is ModuleBuilder) {
                        if (IsTopLevel){
                                ModuleBuilder builder = CodeGen.ModuleBuilder;
                                TypeBuilder = builder.DefineType (
-                                       Name, type_attributes, parent, ifaces);
+                                       Name, type_attributes, base_class_type, ifaces);
                                
                        } else {
                                TypeBuilder builder = Parent.TypeBuilder;
                                TypeBuilder = builder.DefineNestedType (
-                                       Basename, type_attributes, parent, ifaces);
+                                       Basename, type_attributes, base_class_type, ifaces);
                        }
                                
-                       //
-                       // Structs with no fields need to have at least one byte.
-                       // The right thing would be to set the PackingSize in a DefineType
-                       // but there are no functions that allow interfaces *and* the size to
-                       // be specified.
-                       //
+                       if (!is_class)
+                       {
+                               // structure must contain atleast one member variable
+                               if(!have_nonstatic_fields){
+                                       Report.Error (
+                                               30281, Location, "Structure `" + Name + "' do not " +
+                                               "contain any member Variable");
 
-                       if (!is_class && !have_nonstatic_fields){
-                               TypeBuilder.DefineField ("$PRIVATE$", TypeManager.byte_type,
-                                                        FieldAttributes.Private);
-                       }
+                                       /*TypeBuilder.DefineField ("$PRIVATE$", TypeManager.byte_type,
+                                                                FieldAttributes.Private);*/
+                               }
 
-                       // add interfaces that were not added at type creation (weird API issue)
-                       if (!is_class && !have_nonstatic_fields && (ifaces != null)) {
-                               foreach (Type i in ifaces)
-                                       TypeBuilder.AddInterfaceImplementation (i);
+                               // add interfaces that were not added at type creation (weird API issue)
+                               if (!have_nonstatic_fields && (ifaces != null)) {
+                                       foreach (Type i in ifaces)
+                                               TypeBuilder.AddInterfaceImplementation (i);
+                               }
                        }
+
                        
                        //
                        // Finish the setup for the EmitContext
@@ -821,11 +867,10 @@ namespace Mono.CSharp {
 
                        TypeManager.AddUserType (Name, TypeBuilder, this, ifaces);
 
-                       if ((parent != null) &&
-                           (parent == TypeManager.attribute_type ||
-                            parent.IsSubclassOf (TypeManager.attribute_type))) {
+                       if ((base_class_type != null) &&
+                           (base_class_type == TypeManager.attribute_type ||
+                            base_class_type.IsSubclassOf (TypeManager.attribute_type))) {
                                RootContext.RegisterAttribute (this);
-                               TypeManager.RegisterAttrType (TypeBuilder, this);
                        } else
                                RootContext.RegisterOrder (this); 
                                
@@ -864,7 +909,51 @@ namespace Mono.CSharp {
                void DefineMembers (ArrayList list, MemberInfo [] defined_names)
                {
                        int idx;
-                       
+
+                       // if one of the overloaded method is having
+                       // Shadows or Overloads modifier all other should 
+                       // have the same modifier
+                       Hashtable members = new Hashtable();
+                       int modval;
+                       foreach (MemberCore mc in list)
+                       {
+                               modval = 0;
+                               if(members[mc.Name] == null)
+                               {
+                                       foreach (MemberCore m in list)
+                                       {
+                                               if(m.Name == mc.Name) 
+                                               {
+                                                       if ((m.ModFlags & Modifiers.SHADOWS) != 0)
+                                                       {
+                                                               modval = Modifiers.SHADOWS;
+                                                               break;
+                                                       }
+                                                       else if((m.ModFlags & Modifiers.NEW) != 0)
+                                                       {
+                                                               modval = Modifiers.NEW;
+                                                       }
+                                               }
+                                       }
+                                       members.Add(mc.Name, modval);
+                               }
+                               
+                               modval = (int)members[mc.Name];
+                               if(modval != 0)
+                               {
+                                       if(((modval & Modifiers.SHADOWS) != 0) && ((mc.ModFlags & Modifiers.SHADOWS) == 0))
+                                               Report.Error (
+                                                       30695, mc.Location,
+                                                       "Function '" + mc.Name + "': must be declared 'Shadows' " +
+                                                       "because another '" + mc.Name + "' declared 'Shadows'");
+                                       else if(((modval & Modifiers.NEW) != 0) && ((mc.ModFlags & Modifiers.NEW) == 0))
+                                               Report.Error (
+                                                       31409, mc.Location,
+                                                       "Function '" + mc.Name + "': must be declared 'Overloads' " +
+                                                       "because another '" + mc.Name + "' declared 'Overloads'");
+                               }
+                       }
+                       members.Clear ();
                        remove_list.Clear ();
 
                        foreach (MemberCore mc in list){
@@ -881,6 +970,8 @@ namespace Mono.CSharp {
                                        if (RootContext.WarningLevel >= 4){
                                                if ((mc.ModFlags & Modifiers.NEW) != 0)
                                                        Warning_KewywordNewNotRequired (mc.Location, mc);
+                                               if ((mc.ModFlags & Modifiers.SHADOWS) != 0)
+                                                       Warning_KewywordShadowsNotRequired (mc.Location, mc);
                                        }
                                        continue;
                                }
@@ -896,8 +987,9 @@ namespace Mono.CSharp {
                                if (match is MethodBase && mc is MethodCore)
                                        continue; 
                                
-                               if ((mc.ModFlags & Modifiers.NEW) == 0)
-                                       Warning_KeywordNewRequired (mc.Location, defined_names [idx]);
+                               if (((mc.ModFlags & Modifiers.SHADOWS) == 0) && idx > 0)
+                                       Warning_KeywordShadowsRequired (mc.Location, defined_names [idx]);
+                               
                        }
                        
                        foreach (object o in remove_list)
@@ -906,46 +998,6 @@ namespace Mono.CSharp {
                        remove_list.Clear ();
                }
 
-               //
-               // Defines the indexers, and also verifies that the IndexerNameAttribute in the
-               // class is consisten.  Either it is `Item' or it is the name defined by all the
-               // indexers with the `IndexerName' attribute.
-               //
-               // Turns out that the IndexerNameAttribute is applied to each indexer,
-               // but it is never emitted, instead a DefaultName attribute is attached
-               // to the class.
-               //
-               void DefineIndexers ()
-               {
-                       string class_indexer_name = null;
-                       
-                       foreach (Indexer i in Indexers){
-                               string name;
-                               
-                               i.Define (this);
-
-                               name = i.IndexerName;
-
-                               if (i.InterfaceType != null)
-                                       continue;
-
-                               if (class_indexer_name == null){
-                                       class_indexer_name = name;
-                                       continue;
-                               }
-                               
-                               if (name == class_indexer_name)
-                                       continue;
-                               
-                               Report.Error (
-                                       668, "Two indexers have different names, " +
-                                       " you should use the same name for all your indexers");
-                       }
-                       if (class_indexer_name == null)
-                               class_indexer_name = "Item";
-                       IndexerName = class_indexer_name;
-               }
-
                static void Error_KeywordNotAllowed (Location loc)
                {
                        Report.Error (1530, loc, "Keyword new not allowed for namespace elements");
@@ -990,9 +1042,9 @@ namespace Mono.CSharp {
                        if (fields != null)
                                DefineMembers (fields, defined_names);
 
-                       if (this is Class){
+                       if (this is Class && (!(this is Interface))){
                                if (instance_constructors == null){
-                                       if (default_constructor == null)
+                                       if (default_constructor == null) 
                                                DefineDefaultConstructor (false);
                                }
 
@@ -1014,8 +1066,8 @@ namespace Mono.CSharp {
                                        ReportStructInitializedInstanceError ();
                        }
 
-                       Pending = PendingImplementation.GetPendingImplementations (this);
-                       
+                       if (!(this is Interface))
+                               Pending = PendingImplementation.GetPendingImplementations (this);
                        //
                        // Constructors are not in the defined_names array
                        //
@@ -1034,17 +1086,6 @@ namespace Mono.CSharp {
                        if (events != null)
                                DefineMembers (events, defined_names);
 
-                       if (indexers != null) {
-                               DefineIndexers ();
-                       } else
-                               IndexerName = "Item";
-
-                       if (operators != null){
-                               DefineMembers (operators, null);
-
-                               CheckPairedOperators ();
-                       }
-
                        if (enums != null)
                                DefineMembers (enums, defined_names);
                        
@@ -1193,19 +1234,6 @@ namespace Mono.CSharp {
                                        }
                                }
 
-                               if (operators != null){
-                                       foreach (Operator o in operators) {
-                                               if ((o.ModFlags & modflags) == 0)
-                                                       continue;
-                                               if ((o.ModFlags & static_mask) != static_flags)
-                                                       continue;
-                                               
-                                               MethodBuilder ob = o.OperatorMethodBuilder;
-                                               if (ob != null && filter (ob, criteria) == true)
-                                                       members.Add (ob);
-                                       }
-                               }
-
                                if (properties != null){
                                        foreach (Property p in properties){
                                                if ((p.ModFlags & modflags) == 0)
@@ -1224,25 +1252,6 @@ namespace Mono.CSharp {
                                                        members.Add (b);
                                        }
                                }
-
-                               if (indexers != null){
-                                       foreach (Indexer ix in indexers){
-                                               if ((ix.ModFlags & modflags) == 0)
-                                                       continue;
-                                               if ((ix.ModFlags & static_mask) != static_flags)
-                                                       continue;
-                                               
-                                               MethodBuilder b;
-
-                                               b = ix.GetBuilder;
-                                               if (b != null && filter (b, criteria) == true)
-                                                       members.Add (b);
-
-                                               b = ix.SetBuilder;
-                                               if (b != null && filter (b, criteria) == true)
-                                                       members.Add (b);
-                                       }
-                               }
                        }
 
                        if ((mt & MemberTypes.Event) != 0) {
@@ -1266,24 +1275,11 @@ namespace Mono.CSharp {
                                                        continue;
                                                if ((p.ModFlags & static_mask) != static_flags)
                                                        continue;
-
+                                               
                                                MemberInfo pb = p.PropertyBuilder;
-                                               if (pb != null && filter (pb, criteria) == true) {
-                                                       members.Add (p.PropertyBuilder);
-                                               }
-                                       }
-
-                               if (indexers != null)
-                                       foreach (Indexer ix in indexers) {
-                                               if ((ix.ModFlags & modflags) == 0)
-                                                       continue;
-                                               if ((ix.ModFlags & static_mask) != static_flags)
-                                                       continue;
 
-                                               MemberInfo ib = ix.PropertyBuilder;
-                                               if (ib != null && filter (ib, criteria) == true) {
-                                                       members.Add (ix.PropertyBuilder);
-                                               }
+                                               if (pb != null && filter (pb, criteria) == true)
+                                                       members.Add (p.PropertyBuilder);
                                        }
                        }
                        
@@ -1336,6 +1332,9 @@ namespace Mono.CSharp {
                        if ((mt & MemberTypes.Constructor) != 0){
                                if (((bf & BindingFlags.Instance) != 0) && (instance_constructors != null)){
                                        foreach (Constructor c in instance_constructors){
+                                               if ((c.ModFlags & modflags) == 0)
+                                                       continue;
+
                                                ConstructorBuilder cb = c.ConstructorBuilder;
                                                if (cb != null)
                                                        if (filter (cb, criteria) == true)
@@ -1343,13 +1342,14 @@ namespace Mono.CSharp {
                                        }
                                }
 
-                               if (((bf & BindingFlags.Static) != 0) && (default_static_constructor != null)){
+                               if (((bf & BindingFlags.Static) != 0) && (default_static_constructor != null) &&
+                                       ((default_static_constructor.ModFlags & modflags) != 0)){
                                        ConstructorBuilder cb =
                                                default_static_constructor.ConstructorBuilder;
                                        
                                        if (cb != null)
-                                       if (filter (cb, criteria) == true)
-                                               members.Add (cb);
+                                               if (filter (cb, criteria) == true)
+                                                       members.Add (cb);
                                }
                        }
 
@@ -1357,8 +1357,10 @@ namespace Mono.CSharp {
                        // Lookup members in parent if requested.
                        //
                        if (((bf & BindingFlags.DeclaredOnly) == 0) && (TypeBuilder.BaseType != null)) {
-                               MemberList list = FindMembers (TypeBuilder.BaseType, mt, bf, filter, criteria);
-                               members.AddRange (list);
+                               if ((mt & ~MemberTypes.Constructor) != 0) {
+                                       MemberList list = FindMembers (TypeBuilder.BaseType, mt & ~MemberTypes.Constructor, bf, filter, criteria);
+                                       members.AddRange (list);
+                               }
                        }
 
                        Timer.StopTimer (TimerType.TcFindMembers);
@@ -1421,20 +1423,12 @@ namespace Mono.CSharp {
                                foreach (Method m in methods)
                                        m.Emit (this);
 
-                       if (operators != null)
-                               foreach (Operator o in operators)
-                                       o.Emit (this);
-
                        if (properties != null)
                                foreach (Property p in properties)
                                        p.Emit (this);
 
-                       if (indexers != null){
-                               foreach (Indexer ix in indexers)
-                                       ix.Emit (this);
-                               
-                               CustomAttributeBuilder cb = Interface.EmitDefaultMemberAttr (
-                                       this, IndexerName, ModFlags, Location);
+                       if (this.DefaultPropName != null) {
+                               CustomAttributeBuilder cb = new CustomAttributeBuilder (TypeManager.default_member_ctor, new string [] { DefaultPropName });
                                TypeBuilder.SetCustomAttribute (cb);
                        }
                        
@@ -1450,9 +1444,10 @@ namespace Mono.CSharp {
                        if (Pending != null)
                                if (Pending.VerifyPendingMethods ())
                                        return;
-                       
-                       Attribute.ApplyAttributes (ec, TypeBuilder, this, OptAttributes, Location);
 
+                       if (OptAttributes != null)
+                               OptAttributes.Emit (ec, this);
+                       
                        //
                        // Check for internal or private fields that were never assigned
                        //
@@ -1488,7 +1483,7 @@ namespace Mono.CSharp {
 //                             foreach (TypeContainer tc in types)
 //                                     tc.Emit ();
                }
-               
+
                public override void CloseType ()
                {
                        try {
@@ -1536,14 +1531,21 @@ namespace Mono.CSharp {
                        return "`" + Name + "." + n + "'";
                }
 
-               public void Warning_KeywordNewRequired (Location l, MemberInfo mi)
+               public void Warning_KeywordShadowsRequired (Location l, MemberInfo mi)
                {
                        Report.Warning (
-                               108, l, "The keyword new is required on " + 
-                               MakeName (mi.Name) + " because it hides `" +
+                               108, l, "The keyword 'Shadows' is required on " + 
+                               MakeName (mi.Name) + " because it shadows `" +
                                mi.ReflectedType.Name + "." + mi.Name + "'");
                }
 
+               public void Warning_KewywordShadowsNotRequired (Location l, MemberCore mc)
+               {
+                       Report.Warning (
+                               109, l, "The member " + MakeName (mc.Name) + " does not hide an " +
+                               "inherited member, the keyword shadows is not required");
+               }
+
                public void Warning_KewywordNewNotRequired (Location l, MemberCore mc)
                {
                        Report.Warning (
@@ -1564,7 +1566,7 @@ namespace Mono.CSharp {
                {
                        const int vao = (Modifiers.VIRTUAL | Modifiers.ABSTRACT | Modifiers.OVERRIDE);
                        const int va = (Modifiers.VIRTUAL | Modifiers.ABSTRACT);
-                       const int nv = (Modifiers.NEW | Modifiers.VIRTUAL);
+                       //const int nv = (Modifiers.SHADOWS | Modifiers.VIRTUAL);
                        bool ok = true;
                        string name = MakeName (n);
                        
@@ -1574,8 +1576,8 @@ namespace Mono.CSharp {
                        if ((flags & Modifiers.STATIC) != 0){
                                if ((flags & vao) != 0){
                                        Report.Error (
-                                               112, loc, "static method " + name + "can not be marked " +
-                                               "as virtual, abstract or override");
+                                               30501, loc, "Shared method " + name + " can not be " +
+                                               "declared as Overridable");
                                        ok = false;
                                }
                        }
@@ -1587,10 +1589,18 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       if ((flags & Modifiers.OVERRIDE) != 0 && (flags & nv) != 0){
+                       if ((flags & Modifiers.OVERRIDE) != 0 && (flags & Modifiers.VIRTUAL) != 0)
+                       {
+                               Report.Error (
+                                       30730, loc, name +
+                                       ": Methods marked as Overrides cannot be made Overridable");
+                               ok = false;
+                       }
+
+                       if ((flags & Modifiers.OVERRIDE) != 0 && (flags & Modifiers.SHADOWS) != 0){
                                Report.Error (
-                                       113, loc, name +
-                                       " marked as override cannot be marked as new or virtual");
+                                       31408, loc, name +
+                                       ": Methods marked as Overrides cannot be marked as Shadows");
                                ok = false;
                        }
 
@@ -1611,10 +1621,18 @@ namespace Mono.CSharp {
                                        ok = false;
                                }
 
-                               if ((ModFlags & Modifiers.ABSTRACT) == 0){
+                               if((ModFlags & Modifiers.SEALED) != 0){
                                        Report.Error (
-                                               513, loc, name +
-                                               " is abstract but its container class is not");
+                                               30607, loc, 
+                                               "Class declared as 'NotInheritable' " +
+                                               "cannot have a 'MustOverride' member");
+                                       ok = false;
+                               }
+                               else if ((ModFlags & Modifiers.ABSTRACT) == 0){
+                                       Report.Error (
+                                               31411, loc, name +
+                                               " is declared as 'MustOverride', hence its container " +
+                                               "class should be declared as 'MustInherit'");
                                        ok = false;
 
                                }
@@ -1623,8 +1641,8 @@ namespace Mono.CSharp {
                        if ((flags & Modifiers.PRIVATE) != 0){
                                if ((flags & vao) != 0){
                                        Report.Error (
-                                               621, loc, name +
-                                               " virtual or abstract members can not be private");
+                                               30266, loc, name +
+                                               ": Members marked as Overridable or Overrides can not be Private");
                                        ok = false;
                                }
                        }
@@ -1633,7 +1651,15 @@ namespace Mono.CSharp {
                                if ((flags & Modifiers.OVERRIDE) == 0){
                                        Report.Error (
                                                238, loc, name +
-                                               " cannot be sealed because it is not an override");
+                                               ": cannot be sealed because it is not an override");
+                                       ok = false;
+                               }
+                       }
+                       if ((flags & Modifiers.NEW) != 0){
+                               if ((flags & Modifiers.SHADOWS) != 0){
+                                       Report.Error (
+                                               31408, loc, 
+                                               " 'Overloads' and 'Shadows' cannot be combined ");
                                        ok = false;
                                }
                        }
@@ -1654,7 +1680,7 @@ namespace Mono.CSharp {
                // 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) {
@@ -1775,9 +1801,9 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public static void Error_ExplicitInterfaceNotMemberInterface (Location loc, string name)
+               public static void Error_NotInterfaceMember (Location loc, string member_name, string iface_name)
                {
-                       Report.Error (539, loc, "Explicit implementation: `" + name + "' is not a member of the interface");
+                       Report.Error (30401, loc, "'" + member_name + "' is not a member of the interface '" + iface_name + "'");
                }
 
                //
@@ -1810,7 +1836,7 @@ namespace Mono.CSharp {
 
                bool IMemberContainer.IsInterface {
                        get {
-                               return false;
+                               return this is Interface;
                        }
                }
 
@@ -1819,130 +1845,6 @@ namespace Mono.CSharp {
                        return FindMembers (mt, bf | BindingFlags.DeclaredOnly, null, null);
                }
 
-               //
-               // Operator pair checking
-               //
-
-               class OperatorEntry {
-                       public int flags;
-                       public Type ret_type;
-                       public Type type1, type2;
-                       public Operator op;
-                       public Operator.OpType ot;
-                       
-                       public OperatorEntry (int f, Operator o)
-                       {
-                               flags = f;
-
-                               ret_type = o.OperatorMethod.GetReturnType ();
-                               Type [] pt = o.OperatorMethod.ParameterTypes;
-                               type1 = pt [0];
-                               type2 = pt [1];
-                               op = o;
-                               ot = o.OperatorType;
-                       }
-
-                       public override int GetHashCode ()
-                       {       
-                               return ret_type.GetHashCode ();
-                       }
-
-                       public override bool Equals (object o)
-                       {
-                               OperatorEntry other = (OperatorEntry) o;
-
-                               if (other.ret_type != ret_type)
-                                       return false;
-                               if (other.type1 != type1)
-                                       return false;
-                               if (other.type2 != type2)
-                                       return false;
-                               return true;
-                       }
-               }
-                               
-               //
-               // Checks that some operators come in pairs:
-               //  == and !=
-               // > and <
-               // >= and <=
-               //
-               // They are matched based on the return type and the argument types
-               //
-               void CheckPairedOperators ()
-               {
-                       Hashtable pairs = new Hashtable (null, null);
-
-                       // Register all the operators we care about.
-                       foreach (Operator op in operators){
-                               int reg = 0;
-                               
-                               switch (op.OperatorType){
-                               case Operator.OpType.Equality:
-                                       reg = 1; break;
-                               case Operator.OpType.Inequality:
-                                       reg = 2; break;
-                                       
-                               case Operator.OpType.GreaterThan:
-                                       reg = 1; break;
-                               case Operator.OpType.LessThan:
-                                       reg = 2; break;
-                                       
-                               case Operator.OpType.GreaterThanOrEqual:
-                                       reg = 1; break;
-                               case Operator.OpType.LessThanOrEqual:
-                                       reg = 2; break;
-                               }
-                               if (reg == 0)
-                                       continue;
-
-                               OperatorEntry oe = new OperatorEntry (reg, op);
-
-                               object o = pairs [oe];
-                               if (o == null)
-                                       pairs [oe] = oe;
-                               else {
-                                       oe = (OperatorEntry) o;
-                                       oe.flags |= reg;
-                               }
-                       }
-
-                       //
-                       // Look for the mistakes.
-                       //
-                       foreach (DictionaryEntry de in pairs){
-                               OperatorEntry oe = (OperatorEntry) de.Key;
-
-                               if (oe.flags == 3)
-                                       continue;
-
-                               string s = "";
-                               switch (oe.ot){
-                               case Operator.OpType.Equality:
-                                       s = "!=";
-                                       break;
-                               case Operator.OpType.Inequality: 
-                                       s = "==";
-                                       break;
-                               case Operator.OpType.GreaterThan: 
-                                       s = "<";
-                                       break;
-                               case Operator.OpType.LessThan:
-                                       s = ">";
-                                       break;
-                               case Operator.OpType.GreaterThanOrEqual:
-                                       s = "<=";
-                                       break;
-                               case Operator.OpType.LessThanOrEqual:
-                                       s = ">=";
-                                       break;
-                               }
-                               Report.Error (216, oe.op.Location,
-                                             "The operator `" + oe.op + "' requires a matching operator `" + s + "' to also be defined");
-                       }
-               }
-               
-               
        }
 
        public class Class : TypeContainer {
@@ -1956,21 +1858,37 @@ namespace Mono.CSharp {
                        Modifiers.INTERNAL |
                        Modifiers.PRIVATE |
                        Modifiers.ABSTRACT |
-                       Modifiers.SEALED |
-                       Modifiers.UNSAFE;
-
+                       Modifiers.SEALED ;
+               
                public Class (TypeContainer parent, string name, int mod, Attributes attrs, Location l)
-                       : base (parent, name, l)
+                       : base (parent, name, attrs, l)
                {
                        int accmods;
 
                        if (parent.Parent == null)
                                accmods = Modifiers.INTERNAL;
                        else
-                               accmods = Modifiers.PRIVATE;
+                               accmods = Modifiers.PUBLIC;
 
                        this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
-                       this.attributes = attrs;
+               }
+
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Class;
+                       }
+               }
+
+               public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
+               {
+                       if (a.UsageAttribute != null) {
+                               if (base_class_type != TypeManager.attribute_type && !base_class_type.IsSubclassOf (TypeManager.attribute_type) &&
+                                       TypeBuilder.FullName != "System.Attribute") {
+                                       Report.Error (641, a.Location, "Attribute '" + a.Name + "' is only valid on classes derived from System.Attribute");
+                               }
+                               AttributeUsage = a.UsageAttribute;
+                       } 
+                       base.ApplyAttributeBuilder (a, cb);
                }
 
                //
@@ -1997,20 +1915,24 @@ namespace Mono.CSharp {
                        Modifiers.PRIVATE;
 
                public Struct (TypeContainer parent, string name, int mod, Attributes attrs, Location l)
-                       : base (parent, name, l)
+                       : base (parent, name, attrs, l)
                {
                        int accmods;
                        
                        if (parent.Parent == null)
                                accmods = Modifiers.INTERNAL;
                        else
-                               accmods = Modifiers.PRIVATE;
+                               accmods = Modifiers.PUBLIC;
                        
                        this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
 
                        this.ModFlags |= Modifiers.SEALED;
-                       this.attributes = attrs;
-                       
+               }
+
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Struct;
+                       }
                }
 
                //
@@ -2037,6 +1959,9 @@ namespace Mono.CSharp {
                //
                protected InternalParameters parameter_info;
                protected Type [] parameter_types;
+       
+               // Whether this is an operator
+               public bool IsOperator;
 
                public MethodCore (Expression type, int mod, int allowed_mod, string name,
                                   Attributes attrs, Parameters parameters, Location loc)
@@ -2097,65 +2022,6 @@ namespace Mono.CSharp {
                        
                        return cc;
                }
-
-               public void LabelParameters (EmitContext ec, Type [] parameters, MethodBase builder)
-               {
-                       LabelParameters (ec, parameters, builder, null);
-               }
-
-               public void LabelParameters (EmitContext ec, Type [] parameters, MethodBase builder, Parameters p_params)
-               {
-                       //
-                       // Define each type attribute (in/out/ref) and
-                       // the argument names.
-                       //
-                       Parameter [] p = p_params == null ? Parameters.FixedParameters : p_params.FixedParameters;
-                       int i = 0;
-                       
-                       MethodBuilder mb = null;
-                       ConstructorBuilder cb = null;
-
-                       if (builder is MethodBuilder)
-                               mb = (MethodBuilder) builder;
-                       else
-                               cb = (ConstructorBuilder) builder;
-
-                       if (p != null){
-                               for (i = 0; i < p.Length; i++) {
-                                       ParameterBuilder pb;
-                                       
-                                       if (mb == null)
-                                               pb = cb.DefineParameter (
-                                                       i + 1, p [i].Attributes, p [i].Name);
-                                       else 
-                                               pb = mb.DefineParameter (
-                                                       i + 1, p [i].Attributes, p [i].Name);
-                                       
-                                       Attributes attr = p [i].OptAttributes;
-                                       if (attr != null)
-                                               Attribute.ApplyAttributes (ec, pb, pb, attr, Location);
-                               }
-                       }
-
-                       if (Parameters.ArrayParameter != null){
-                               ParameterBuilder pb;
-                               Parameter array_param = Parameters.ArrayParameter;
-                               
-                               if (mb == null)
-                                       pb = cb.DefineParameter (
-                                               i + 1, array_param.Attributes,
-                                               array_param.Name);
-                               else
-                                       pb = mb.DefineParameter (
-                                               i + 1, array_param.Attributes,
-                                               array_param.Name);
-                                       
-                               CustomAttributeBuilder a = new CustomAttributeBuilder (
-                                       TypeManager.cons_param_array_attribute, new object [0]);
-                               
-                               pb.SetCustomAttribute (a);
-                       }
-               }
        }
        
        public class Method : MethodCore {
@@ -2173,11 +2039,12 @@ namespace Mono.CSharp {
                        Modifiers.PRIVATE |
                        Modifiers.STATIC |
                        Modifiers.VIRTUAL |
-                       Modifiers.SEALED |
+                       Modifiers.NONVIRTUAL |
                        Modifiers.OVERRIDE |
                        Modifiers.ABSTRACT |
-                       Modifiers.UNSAFE |
-                       Modifiers.EXTERN;
+                       Modifiers.UNSAFE |
+                       Modifiers.EXTERN|
+                       Modifiers.SHADOWS;
 
                //
                // return_type can be "null" for VOID values.
@@ -2185,8 +2052,23 @@ namespace Mono.CSharp {
                public Method (Expression return_type, int mod, string name, Parameters parameters,
                               Attributes attrs, Location l)
                        : base (return_type, mod, AllowedModifiers, name, attrs, parameters, l)
-               { }
+               { 
+                       Implements = null;
+               }
 
+               public Method (Expression return_type, int mod, string name, Parameters parameters,
+                       Attributes attrs, ArrayList impl_what, Location l)
+                       : base (return_type, mod, AllowedModifiers, name, attrs, parameters, l)
+               { 
+                       Implements = impl_what;
+               }
+               
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Method;
+                       }
+               }
+               
                //
                // Returns the `System.Type' for the ReturnType of this
                // function.  Provides a nice cache.  (used between semantic analysis
@@ -2197,50 +2079,47 @@ namespace Mono.CSharp {
                        return MemberType;
                }
 
-               // Whether this is an operator method.
-               public bool IsOperator;
+               void DuplicateEntryPoint (MethodInfo b, Location location)
+               {
+                               Report.Error (
+                                               30738, location,
+                                               "Program `" + CodeGen.FileName +
+                                               "'  has more than one entry point defined: `" +
+                                               TypeManager.MonoBASIC_Signature(b) + "'");
+               }
 
-                void DuplicateEntryPoint (MethodInfo b, Location location)
-                {
-                        Report.Error (
-                                17, location,
-                                "Program `" + CodeGen.FileName +
-                                "'  has more than one entry point defined: `" +
-                                TypeManager.CSharpSignature(b) + "'");
-                }
-
-                void Report28 (MethodInfo b)
-                {
+               void Report28 (MethodInfo b)
+               {
                        if (RootContext.WarningLevel < 4) 
                                return;
                                
-                        Report.Warning (
-                                28, Location,
-                                "`" + TypeManager.CSharpSignature(b) +
-                                "' has the wrong signature to be an entry point");
-                }
-
-                public bool IsEntryPoint (MethodBuilder b, InternalParameters pinfo)
-                {
-                        if (b.ReturnType != TypeManager.void_type &&
-                            b.ReturnType != TypeManager.int32_type)
-                                return false;
-
-                        if (pinfo.Count == 0)
-                                return true;
-
-                        if (pinfo.Count > 1)
-                                return false;
-
-                        Type t = pinfo.ParameterType(0);
-                        if (t.IsArray &&
-                            (t.GetArrayRank() == 1) &&
-                            (t.GetElementType() == TypeManager.string_type) &&
-                            (pinfo.ParameterModifier(0) == Parameter.Modifier.NONE))
-                                return true;
-                        else
-                                return false;
-                }
+                       Report.Warning (
+                                       28, Location,
+                                       "`" + TypeManager.MonoBASIC_Signature(b) +
+                                       "' has the wrong signature to be an entry point");
+               }
+
+               public bool IsEntryPoint (MethodBuilder b, InternalParameters pinfo)
+               {
+                       if (b.ReturnType != TypeManager.void_type &&
+                               b.ReturnType != TypeManager.int32_type)
+                                       return false;
+
+                       if (pinfo.Count == 0)
+                                       return true;
+
+                       if (pinfo.Count > 1)
+                                       return false;
+
+                       Type t = pinfo.ParameterType(0);
+                       if (t.IsArray &&
+                               (t.GetArrayRank() == 1) &&
+                               (t.GetElementType() == TypeManager.string_type) &&
+                               (pinfo.ParameterModifier(0) == Parameter.Modifier.NONE))
+                                       return true;
+                       else
+                                       return false;
+               }
 
                //
                // Checks our base implementation if any
@@ -2319,17 +2198,35 @@ namespace Mono.CSharp {
                                                }
                                        }
                                } else {
-                                       if ((ModFlags & Modifiers.NEW) != 0)
-                                               WarningNotHiding (parent);
+                                       /*if ((ModFlags & Modifiers.NEW) != 0)
+                                               WarningNotHiding (parent);*/
 
                                        if ((ModFlags & Modifiers.OVERRIDE) != 0){
-                                               Report.Error (115, Location,
+                                               Report.Error (30284, Location,
                                                              parent.MakeName (Name) +
-                                                             " no suitable methods found to override");
+                                                             " : No suitable methods found to override");
                                        }
+                                       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 maked as Overrides");
+                                               }
+                                       }
+                                       // if a member of module is not inherited from Object class
+                                       // can not be declared protected
+                                       if ((parent is Module) && ((ModFlags & Modifiers.PROTECTED) != 0))
+                                               Report.Error (31066, Location,
+                                                               "'Sub' or 'Function' inside a 'Module' can not be declared as " +
+                                                               "'Protected' or 'Protected Friend'");
                                }
-                       } else if ((ModFlags & Modifiers.NEW) != 0)
+                       }
+                       /* else if ((ModFlags & Modifiers.NEW) != 0)
                                WarningNotHiding (parent);
+                       */
 
                        return true;
                }
@@ -2345,6 +2242,11 @@ namespace Mono.CSharp {
                        if (!CheckBase (parent))
                                return false;
 
+                       if ((parent is Struct) && ((ModFlags & Modifiers.PROTECTED) != 0))
+                               Report.Error (31067, Location,
+                                       "'Sub' or 'Function' inside a 'Structure' can not be declared as " +
+                                       "'Protected' or 'Protected Friend'");
+
                        CallingConventions cc = GetCallingConvention (parent is Class);
 
                        MethodData = new MethodData (this, null, MemberType, ParameterTypes,
@@ -2359,10 +2261,13 @@ namespace Mono.CSharp {
                        //
                        // This is used to track the Entry Point,
                        //
-                       if (Name == "Main" &&
+                       if (Name.ToUpper() == "MAIN" &&
                            ((ModFlags & Modifiers.STATIC) != 0) && 
                            (RootContext.MainClass == null ||
-                            RootContext.MainClass == parent.TypeBuilder.FullName)){
+                            RootContext.MainClass == parent.TypeBuilder.FullName ||
+                            (RootContext.RootNamespace != null &&
+                                 RootContext.RootNamespace.Length > 0 &&
+                                 (RootContext.RootNamespace + "." + RootContext.MainClass) == parent.TypeBuilder.FullName))) {
                                 if (IsEntryPoint (MethodBuilder, ParameterInfo)) {
                                         if (RootContext.EntryPoint == null) {
                                                 RootContext.EntryPoint = MethodBuilder;
@@ -2385,6 +2290,11 @@ namespace Mono.CSharp {
                {
                        MethodData.Emit (parent, Block, this);
                }
+
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+               {
+                       throw new Exception ("FIXME: I am just a placeholder implementation");
+               }
        }
 
        public abstract class ConstructorInitializer {
@@ -2392,6 +2302,7 @@ namespace Mono.CSharp {
                ConstructorInfo parent_constructor;
                Parameters parameters;
                Location loc;
+               public bool implicit_initialization;
                
                public ConstructorInitializer (ArrayList argument_list, Parameters parameters,
                                               Location loc)
@@ -2399,6 +2310,7 @@ namespace Mono.CSharp {
                        this.argument_list = argument_list;
                        this.parameters = parameters;
                        this.loc = loc;
+                       this.implicit_initialization = false;
                }
 
                public ArrayList Arguments {
@@ -2407,6 +2319,14 @@ namespace Mono.CSharp {
                        }
                }
 
+               public ConstructorInfo ParentConstructor
+               {
+                       get
+                       {
+                               return parent_constructor;
+                       }
+               }
+       
                public bool Resolve (EmitContext ec)
                {
                        Expression parent_constructor_group;
@@ -2428,14 +2348,15 @@ namespace Mono.CSharp {
                                        return true;
 
                                t = ec.ContainerType.BaseType;
-                               if (ec.ContainerType.IsValueType) {
+                               if (ec.ContainerType.IsValueType){
                                        Report.Error (522, loc,
                                                "structs cannot call base class constructors");
                                        return false;
                                }
-                       } else
+                       }
+                       else
                                t = ec.ContainerType;
-
+                       
                        parent_constructor_group = Expression.MemberLookup (
                                ec, t, t, ".ctor", 
                                MemberTypes.Constructor,
@@ -2443,20 +2364,24 @@ namespace Mono.CSharp {
                                loc);
                        
                        if (parent_constructor_group == null){
-                               Report.Error (1501, loc,
-                                      "Can not find a constructor for this argument list");
+                               Report.Error (30455, loc, "Class '" + t + "' can not find a constructor for this argument list" );
                                return false;
                        }
-                       
+
                        parent_constructor = (ConstructorInfo) Invocation.OverloadResolve (ec, 
                                (MethodGroupExpr) parent_constructor_group, argument_list, loc);
-                       
-                       if (parent_constructor == null){
-                               Report.Error (1501, loc,
-                                      "Can not find a constructor for this argument list");
+
+                       if (parent_constructor == null) {
+                               if (this.implicit_initialization)
+                                       Report.Error (30148, loc, "Must declare 'MyBase.New' in the constructor " +
+                                       "of the class '" + ec.TypeContainer.Name + "' with appropriate arguments, since the base class '" +
+                                               t.FullName + "' does not contain a definition of 'New' without any parameter");
+                               else
+                                       Report.Error (30455, loc, "Class '" + t + "' can not find a constructor for this argument list" );
+
                                return false;
                        }
-                       
+
                        return true;
                }
 
@@ -2469,6 +2394,8 @@ namespace Mono.CSharp {
                                        Invocation.EmitCall (ec, true, false, ec.This, parent_constructor, argument_list, loc);
                        }
                }
+
+
        }
 
        public class ConstructorBaseInitializer : ConstructorInitializer {
@@ -2488,7 +2415,6 @@ namespace Mono.CSharp {
        public class Constructor : MethodCore {
                public ConstructorBuilder ConstructorBuilder;
                public ConstructorInitializer Initializer;
-               new public Attributes OptAttributes;
 
                // <summary>
                //   Modifiers allowed for a constructor.
@@ -2512,6 +2438,23 @@ namespace Mono.CSharp {
                        Initializer = init;
                }
 
+               public Constructor (string name, int mod, Parameters args, ConstructorInitializer init, Location l)
+                       : base (null, mod, AllowedModifiers, name, null, args, l)
+               {
+                       Initializer = init;
+               }
+
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+               {
+                       ConstructorBuilder.SetCustomAttribute (cb);
+               }
+
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Constructor;
+                       }
+               }
+
                //
                // Returns true if this is a default constructor
                //
@@ -2536,16 +2479,41 @@ namespace Mono.CSharp {
                        MethodAttributes ca = (MethodAttributes.RTSpecialName |
                                               MethodAttributes.SpecialName);
 
+                       if (parent.EventHandlers != null) {
+                               ArrayList hdlrs = parent.EventHandlers;
+                               foreach(Statement stmt in hdlrs)
+                    this.Block.AddStatement (stmt);
+                       }
+
+
                        // Check if arguments were correct.
                        if (!DoDefineParameters (parent))
                                return false;
 
-                       if ((ModFlags & Modifiers.STATIC) != 0)
+                       if ((ModFlags & Modifiers.STATIC) != 0) {
                                ca |= MethodAttributes.Static;
+
+                               if (this.Parameters != Parameters.EmptyReadOnlyParameters)
+                                       Report.Error (
+                                               30479, Location, 
+                                               "Shared constructor can not have parameters");
+
+                               if ((ModFlags & Modifiers.Accessibility) != 0)
+                                       Report.Error (
+                                               30480, Location, 
+                                               "Shared constructor can not be declared " +
+                                               "explicitly as public, private, friend or protected");
+
+                               if (this.Initializer != null)
+                                       Report.Error (
+                                               30043, Location, 
+                                               "Keywords like MyBase, MyClass, Me are not " +
+                                               "valid inside a Shared Constructor");
+                       }
                        else {
-                               if (parent is Struct && ParameterTypes.Length == 0){
+                               if (parent is Struct && ParameterTypes.Length == 0)     {
                                        Report.Error (
-                                               568, Location, 
+                                               30629, Location, 
                                                "Structs can not contain explicit parameterless " +
                                                "constructors");
                                        return false;
@@ -2554,12 +2522,13 @@ namespace Mono.CSharp {
 
                                if ((ModFlags & Modifiers.PUBLIC) != 0)
                                        ca |= MethodAttributes.Public;
-                               else if ((ModFlags & Modifiers.PROTECTED) != 0){
+                               else if ((ModFlags & Modifiers.PROTECTED) != 0) {
                                        if ((ModFlags & Modifiers.INTERNAL) != 0)
                                                ca |= MethodAttributes.FamORAssem;
                                        else 
                                                ca |= MethodAttributes.Family;
-                               } else if ((ModFlags & Modifiers.INTERNAL) != 0)
+                               }
+                               else if ((ModFlags & Modifiers.INTERNAL) != 0)
                                        ca |= MethodAttributes.Assembly;
                                else if (IsDefault ())
                                        ca |= MethodAttributes.Public;
@@ -2594,10 +2563,11 @@ namespace Mono.CSharp {
                        EmitContext ec = new EmitContext (parent, Location, ig, null, ModFlags, true);
 
                        if ((ModFlags & Modifiers.STATIC) == 0){
-                               if (parent is Class && Initializer == null)
+                               if (parent is Class && Initializer == null) {
                                        Initializer = new ConstructorBaseInitializer (
                                                null, Parameters.EmptyReadOnlyParameters, parent.Location);
-
+                                       Initializer.implicit_initialization = true;
+                               }
 
                                //
                                // Spec mandates that Initializers will not have
@@ -2609,7 +2579,7 @@ namespace Mono.CSharp {
                                ec.IsStatic = false;
                        }
 
-                       LabelParameters (ec, ParameterTypes, ConstructorBuilder);
+                       Parameters.LabelParameters (ec, ConstructorBuilder, Location);
                        
                        //
                        // Classes can have base initializers and instance field initializers.
@@ -2618,13 +2588,21 @@ namespace Mono.CSharp {
                                if ((ModFlags & Modifiers.STATIC) == 0)
                                        parent.EmitFieldInitializers (ec);
                        }
-                       if (Initializer != null)
+
+                       if (Initializer != null) {
+                               if (this.ConstructorBuilder.Equals (Initializer.ParentConstructor))
+                                       Report.Error (
+                                               30297, Location,
+                                               "A constructor can not call itself" );
+
                                Initializer.Emit (ec);
+                       }
                        
                        if ((ModFlags & Modifiers.STATIC) != 0)
                                parent.EmitFieldInitializers (ec);
 
-                       Attribute.ApplyAttributes (ec, ConstructorBuilder, this, OptAttributes, Location);
+                       if (OptAttributes != null)
+                               OptAttributes.Emit (ec, this);
 
                        // If this is a non-static `struct' constructor and doesn't have any
                        // initializer, it must initialize all of the struct's fields.
@@ -2655,11 +2633,11 @@ namespace Mono.CSharp {
                //
                // Protected data.
                //
-               protected MemberBase member;
-               protected int modifiers;
-               protected MethodAttributes flags;
-               protected bool is_method;
-               protected string accessor_name;
+               readonly MemberBase member;
+               readonly int modifiers;
+               MethodAttributes flags;
+               readonly bool is_method;
+               readonly string accessor_name;
                ArrayList conditionals;
 
                MethodBuilder builder = null;
@@ -2697,32 +2675,27 @@ namespace Mono.CSharp {
 
                public virtual bool ApplyAttributes (Attributes opt_attrs, bool is_method)
                {
-                       if ((opt_attrs == null) || (opt_attrs.AttributeSections == null))
+                       if ((opt_attrs == null) || (opt_attrs.Attrs == null))
                                return true;
 
-                       foreach (AttributeSection asec in opt_attrs.AttributeSections) {
-                               if (asec.Attributes == null)
-                                       continue;
-                                       
-                               foreach (Attribute a in asec.Attributes) {
-                                       if (a.Name == "Conditional") {
-                                               if (!ApplyConditionalAttribute (a))
-                                                       return false;
-                                       } else if (a.Name == "Obsolete") {
-                                               if (!ApplyObsoleteAttribute (a))
-                                                       return false;
-                                       } else if (a.Name.IndexOf ("DllImport") != -1) {
-                                               if (!is_method) {
-                                                       a.Type = TypeManager.dllimport_type;
-                                                       Attribute.Error_AttributeNotValidForElement (a, Location);
-                                                       return false;
-                                               }
-                                               if (!ApplyDllImportAttribute (a))
-                                                       return false;
+                       foreach (Attribute a in opt_attrs.Attrs) {
+                               if (a.Name == "Conditional") {
+                                       if (!ApplyConditionalAttribute (a))
+                                               return false;
+                               } else if (a.Name == "Obsolete") {
+                                       if (!ApplyObsoleteAttribute (a))
+                                               return false;
+                               } else if (a.Name.IndexOf ("DllImport") != -1) {
+                                       if (!is_method) {
+                                               a.Type = TypeManager.dllimport_type;
+                                               Attribute.Error_AttributeNotValidForElement (a, Location);
+                                               return false;
                                        }
+                                       if (!ApplyDllImportAttribute (a))
+                                               return false;
                                }
                        }
-
+                       
                        return true;
                }
 
@@ -2855,47 +2828,110 @@ namespace Mono.CSharp {
 
                        return flags;
                }
+               
+               //
+               // Search all the interface bases recursively for unimplemented methods
+               //
+               bool SearchBasesForAbstractMethods (
+                       TypeContainer parent, Type iface_type, 
+                       string method_name, ref ArrayList implementing_list, 
+                       ref ArrayList implementing_iface)
+               {
+                       MethodInfo implementing = null;
+                       bool IsImplementing = false;
+                       Type current_iface_type = iface_type;
+
+                       implementing = parent.Pending.IsAbstractMethod (
+                       current_iface_type, method_name, ReturnType, ParameterTypes);
+
+                       if (implementing != null) {
+                               if (!implementing_list.Contains (implementing)) {
+                                       implementing_list.Add (implementing);
+                                       implementing_iface.Add(current_iface_type);
+                               }
+                               IsImplementing = true;
+                       } else {
+                               Type[] current_iface_types = current_iface_type.GetInterfaces();
+                               if (current_iface_types.Length == 0)
+                                       return false;
+
+                               foreach (Type curr_iface_type in current_iface_types) {
+                                       IsImplementing = SearchBasesForAbstractMethods (
+                                               parent, curr_iface_type, method_name, 
+                                               ref implementing_list, ref implementing_iface);
+
+                                       if (IsImplementing)
+                                               break;
+                               }
+                       }
+
+                       return IsImplementing;
+               }
 
                public virtual bool Define (TypeContainer parent)
                {
                        MethodInfo implementing = null;
-                       string method_name, name, prefix;
+                       ArrayList implementing_list = null;
+                       ArrayList implementing_iface = null;
+                       string method_name, name, prefix, impl_method_name;
+                       int pos = -1;
 
                        if (OptAttributes != null)
                                if (!ApplyAttributes (OptAttributes, is_method))
                                        return false;
 
-                       if (member.IsExplicitImpl)
-                               prefix = member.InterfaceType.FullName + ".";
-                       else
-                               prefix = "";
-
                        if (accessor_name != null)
                                name = accessor_name + "_" + member.ShortName;
                        else
                                name = member.ShortName;
-                       method_name = prefix + name;
 
-                       if (parent.Pending != null){
-                               if (member is Indexer)
-                                       implementing = parent.Pending.IsInterfaceIndexer (
-                                               member.InterfaceType, ReturnType, ParameterTypes);
+                       method_name = name;
+                       impl_method_name = name;
+
+                       if ((member.ModFlags & Modifiers.OVERRIDE) != 0) {
+                               if (parent.Pending == null)
+                                       implementing = null;
                                else
-                                       implementing = parent.Pending.IsInterfaceMethod (
-                                               member.InterfaceType, name, ReturnType, ParameterTypes);
+                                       implementing = parent.Pending.IsAbstractMethod (
+                                               (Type) parent.TypeBuilder.BaseType, name, 
+                                               ReturnType, ParameterTypes);
+                               
+                               if (implementing != null)
+                                       IsImplementing = true;
+                       }
 
-                               if (member.InterfaceType != null && implementing == null){
-                                       TypeContainer.Error_ExplicitInterfaceNotMemberInterface (
-                                               Location, name);
-                                       return false;
+                       if (member.Implements != null) {
+                               implementing_list = new ArrayList();
+                               implementing_iface = new ArrayList();
+
+                               foreach (Expression Impl in member.Implements) {
+                                       name = Impl.ToString();
+                                       prefix = name.Substring(0, name.LastIndexOf("."));
+                                       name = name.Substring(name.LastIndexOf(".") + 1);
+
+                                       if (accessor_name != null)
+                                               impl_method_name = accessor_name + "_" + name;
+                                       else
+                                               impl_method_name = name;
+
+                                       Type current_iface_type = (Type) member.InterfaceTypes[++pos];
+                                       IsImplementing = SearchBasesForAbstractMethods (
+                                               parent, current_iface_type, impl_method_name, 
+                                               ref implementing_list, ref implementing_iface);
+
+                                       if (IsImplementing == false) {
+                                               TypeContainer.Error_NotInterfaceMember (
+                                                       Location, name, prefix);
+                                               return false;
+                                       }
                                }
-                       }
+                       } 
 
                        //
                        // For implicit implementations, make sure we are public, for
                        // explicit implementations, make sure we are private.
                        //
-                       if (implementing != null){
+                       //if (IsImplementing){
                                //
                                // Setting null inside this block will trigger a more
                                // verbose error reporting for missing interface implementations
@@ -2903,7 +2939,7 @@ namespace Mono.CSharp {
                                // The "candidate" function has been flagged already
                                // but it wont get cleared
                                //
-                               if (!member.IsExplicitImpl){
+                       /*      if (!member.IsExplicitImpl){
                                        //
                                        // We already catch different accessibility settings
                                        // so we just need to check that we are not private
@@ -2921,30 +2957,22 @@ namespace Mono.CSharp {
                                                Modifiers.Error_InvalidModifier (Location, "public, virtual or abstract");
                                                implementing = null;
                                        }
-                               }
-                       }
+                               }*/
+                       //}
                        
                        //
                        // If implementing is still valid, set flags
                        //
-                       if (implementing != null){
+                       if (IsImplementing){
                                //
                                // When implementing interface methods, set NewSlot.
                                //
-                               if (implementing.DeclaringType.IsInterface)
-                                       flags |= MethodAttributes.NewSlot;
+                               if (implementing_list != null && implementing_list.Count != 0)
+                                               flags |= MethodAttributes.NewSlot;
 
                                flags |=
                                        MethodAttributes.Virtual |
                                        MethodAttributes.HideBySig;
-
-                               // Get the method name from the explicit interface.
-                               if (member.InterfaceType != null) {
-                                       name = implementing.Name;
-                                       method_name = prefix + name;
-                               }
-
-                               IsImplementing = true;
                        }
 
                        //
@@ -2974,20 +3002,48 @@ namespace Mono.CSharp {
 
                        if (IsImplementing) {
                                //
-                               // clear the pending implemntation flag
+                               // implement abstract methods from abstract classes
                                //
-                               if (member is Indexer) {
-                                       parent.Pending.ImplementIndexer (
-                                               member.InterfaceType, builder, ReturnType,
-                                               ParameterTypes, true);
-                               } else
-                                       parent.Pending.ImplementMethod (
-                                               member.InterfaceType, name, ReturnType,
-                                               ParameterTypes, member.IsExplicitImpl);
-
-                               if (member.IsExplicitImpl)
-                                       parent.TypeBuilder.DefineMethodOverride (
-                                               builder, implementing);
+                               if ((member.ModFlags & Modifiers.OVERRIDE) != 0) {
+                                       /*
+                                       if (member is Indexer)
+                                               parent.Pending.ImplementIndexer (
+                                                       (Type) parent.TypeBuilder.BaseType, 
+                                                       builder, ReturnType,
+                                                       ParameterTypes, true);
+                                       else
+                                       */
+                                               parent.Pending.ImplementMethod (
+                                                       (Type) parent.TypeBuilder.BaseType, 
+                                                       name, ReturnType,
+                                                       ParameterTypes, member.IsExplicitImpl);
+                               }
+                               
+                               //
+                               // implement abstract methods of interfaces
+                               //
+                               if (member.Implements != null)  {
+                                       pos = 0;
+                                       foreach (MethodInfo Impl in implementing_list)  {
+
+                                               /* 
+                                               if (member is Indexer)
+                                                       parent.Pending.ImplementIndexer (
+                                                               (Type) implementing_iface[pos++],
+                                                               builder, ReturnType,
+                                                               ParameterTypes, true);
+                                               else
+                                               */
+                                                       parent.Pending.ImplementMethod (
+                                                               (Type) implementing_iface[pos++],
+                                                               Impl.Name, ReturnType,
+                                                               ParameterTypes, member.IsExplicitImpl);
+
+                                               parent.TypeBuilder.DefineMethodOverride (
+                                                       builder, Impl);
+                                       }
+                               }
+                               
                        }
 
                        if (!TypeManager.RegisterMethod (builder, ParameterInfo, ParameterTypes)) {
@@ -3000,7 +3056,6 @@ namespace Mono.CSharp {
                        }
 
                        TypeManager.AddMethod (builder, this);
-
                        return true;
                }
 
@@ -3023,7 +3078,7 @@ namespace Mono.CSharp {
                                Attribute.ApplyAttributes (ec, builder, kind, OptAttributes, Location);
 
                        if (member is MethodCore)
-                               ((MethodCore) member).LabelParameters (ec, ParameterTypes, MethodBuilder);
+                               ((MethodCore) member).Parameters.LabelParameters (ec, MethodBuilder, ((MethodCore) member).Location);
 
                        //
                        // abstract or extern methods have no bodies
@@ -3038,13 +3093,13 @@ namespace Mono.CSharp {
                                if ((modifiers & Modifiers.ABSTRACT) != 0)
                                        Report.Error (
                                                500, Location, "Abstract method `" +
-                                               TypeManager.CSharpSignature (builder) +
+                                               TypeManager.MonoBASIC_Signature (builder) +
                                                "' can not have a body");
 
                                if ((modifiers & Modifiers.EXTERN) != 0)
                                        Report.Error (
                                                179, Location, "External method `" +
-                                               TypeManager.CSharpSignature (builder) +
+                                               TypeManager.MonoBASIC_Signature (builder) +
                                                "' can not have a body");
 
                                return;
@@ -3056,7 +3111,7 @@ namespace Mono.CSharp {
                        if (block == null) {
                                Report.Error (
                                        501, Location, "Method `" +
-                                       TypeManager.CSharpSignature (builder) +
+                                       TypeManager.MonoBASIC_Signature (builder) +
                                        "' must declare a body since it is not marked " +
                                        "abstract or extern");
                                return;
@@ -3135,7 +3190,7 @@ namespace Mono.CSharp {
 
        abstract public class MemberBase : MemberCore {
                public Expression Type;
-               public readonly Attributes OptAttributes;
+               public ArrayList Implements;
 
                protected MethodAttributes flags;
 
@@ -3164,6 +3219,7 @@ namespace Mono.CSharp {
                // If true, the interface type we are explicitly implementing
                //
                public Type InterfaceType = null;
+               public ArrayList InterfaceTypes = null;
 
                //
                // The method we're overriding if this is an override method.
@@ -3180,11 +3236,10 @@ namespace Mono.CSharp {
                //
                protected MemberBase (Expression type, int mod, int allowed_mod, string name,
                                      Attributes attrs, Location loc)
-                       : base (name, loc)
+                       : base (name, attrs, loc)
                {
                        Type = type;
-                       ModFlags = Modifiers.Check (allowed_mod, mod, Modifiers.PRIVATE, loc);
-                       OptAttributes = attrs;
+                       ModFlags = Modifiers.Check (allowed_mod, mod, Modifiers.PUBLIC, loc);
                }
 
                protected virtual bool CheckBase (TypeContainer parent)
@@ -3203,16 +3258,10 @@ namespace Mono.CSharp {
                                if (parent.AsAccessible (partype, ModFlags))
                                        continue;
 
-                               if (this is Indexer)
-                                       Report.Error (55, Location,
-                                                     "Inconsistent accessibility: parameter type `" +
-                                                     TypeManager.CSharpName (partype) + "' is less " +
-                                                     "accessible than indexer `" + Name + "'");
-                               else
-                                       Report.Error (51, Location,
-                                                     "Inconsistent accessibility: parameter type `" +
-                                                     TypeManager.CSharpName (partype) + "' is less " +
-                                                     "accessible than method `" + Name + "'");
+                               Report.Error (51, Location,
+                                                   "Inconsistent accessibility: parameter type `" +
+                                                   TypeManager.MonoBASIC_Name (partype) + "' is less " +
+                                                   "accessible than method `" + Name + "'");
                                error = true;
                        }
 
@@ -3234,27 +3283,62 @@ namespace Mono.CSharp {
                        if (MemberType == null)
                                return false;
 
+                       // check for whether the Interface is implemented by the class
+                       if (Implements != null) {
+                               InterfaceTypes = new ArrayList ();
+                               foreach (Expression Impls in Implements) {
+                                       string iname = Impls.ToString();
+                                       iname = iname.Substring(0, iname.LastIndexOf("."));
+                                       bool iface_found = false;
+
+                                       InterfaceType  = RootContext.LookupType (
+                                               parent, iname, false, Location);
+                                       if (InterfaceType == null)
+                                               return false;
+
+                                       InterfaceTypes.Add (InterfaceType);
+                                       Type[] tbases = parent.TypeBuilder.GetInterfaces();
+
+                                   if (tbases.Length != 0)     {
+                                               ArrayList bases = new ArrayList();
+                                               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)     {
+                                                               iface_found = true;
+                                                               break;
+                                                       }
+                                               }
+                                       }
+
+                                       if (!iface_found) {
+                                               Report.Error (31035, Location,
+                                                       "Class '" + parent.Name + "' doesn't implement interface '" + iname + "'");
+                                               return false;
+                                       }
+                               }
+                       }
+
                        // verify accessibility
                        if (!parent.AsAccessible (MemberType, ModFlags)) {
                                if (this is Property)
                                        Report.Error (53, Location,
                                                      "Inconsistent accessibility: property type `" +
-                                                     TypeManager.CSharpName (MemberType) + "' is less " +
+                                                     TypeManager.MonoBASIC_Name (MemberType) + "' is less " +
                                                      "accessible than property `" + Name + "'");
-                               else if (this is Indexer)
-                                       Report.Error (54, Location,
-                                                     "Inconsistent accessibility: indexer return type `" +
-                                                     TypeManager.CSharpName (MemberType) + "' is less " +
-                                                     "accessible than indexer `" + Name + "'");
                                else if (this is Method)
-                                       Report.Error (50, Location,
+                                       Report.Error (30508, Location,
                                                      "Inconsistent accessibility: return type `" +
-                                                     TypeManager.CSharpName (MemberType) + "' is less " +
+                                                     TypeManager.MonoBASIC_Name (MemberType) + "' is less " +
                                                      "accessible than method `" + Name + "'");
                                else
                                        Report.Error (52, Location,
                                                      "Inconsistent accessibility: field type `" +
-                                                     TypeManager.CSharpName (MemberType) + "' is less " +
+                                                     TypeManager.MonoBASIC_Name (MemberType) + "' is less " +
                                                      "accessible than field `" + Name + "'");
                                return false;
                        }
@@ -3265,7 +3349,7 @@ namespace Mono.CSharp {
                        //
                        // Check for explicit interface implementation
                        //
-                       if ((ExplicitInterfaceName == null) && (Name.IndexOf (".") != -1)){
+                       if ((ExplicitInterfaceName == null) && (Name.IndexOf (".") != -1)) {
                                int pos = Name.LastIndexOf (".");
 
                                ExplicitInterfaceName = Name.Substring (0, pos);
@@ -3273,22 +3357,6 @@ namespace Mono.CSharp {
                        } else
                                ShortName = Name;
 
-                       if (ExplicitInterfaceName != null) {
-                               InterfaceType  = RootContext.LookupType (
-                                       parent, ExplicitInterfaceName, false, Location);
-                               if (InterfaceType == null)
-                                       return false;
-
-                               // Compute the full name that we need to export.
-                               Name = InterfaceType.FullName + "." + ShortName;
-                               
-                               if (!parent.VerifyImplements (InterfaceType, ShortName, Name, Location))
-                                       return false;
-                               
-                               IsExplicitImpl = true;
-                       } else
-                               IsExplicitImpl = false;
-
                        return true;
                }
        }
@@ -3314,6 +3382,13 @@ namespace Mono.CSharp {
                        this.init = init;
                }
 
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Field;
+                       }
+               }
+
+
                //
                // Whether this field has an initializer.
                //
@@ -3351,6 +3426,7 @@ namespace Mono.CSharp {
 
                        return init_expr;
                }
+
        }
 
        //
@@ -3361,14 +3437,14 @@ namespace Mono.CSharp {
                //   Modifiers allowed in a class declaration
                // </summary>
                const int AllowedModifiers =
-                       Modifiers.NEW |
+                       Modifiers.SHADOWS |
                        Modifiers.PUBLIC |
                        Modifiers.PROTECTED |
                        Modifiers.INTERNAL |
                        Modifiers.PRIVATE |
                        Modifiers.STATIC |
-                       Modifiers.VOLATILE |
-                       Modifiers.UNSAFE |
+                  //     Modifiers.VOLATILE |
+                  //     Modifiers.UNSAFE |
                        Modifiers.READONLY;
 
                public Field (Expression type, int mod, string name, Object expr_or_array_init,
@@ -3377,6 +3453,12 @@ namespace Mono.CSharp {
                {
                }
 
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Field;
+                       }
+               }
+
                public override bool Define (TypeContainer parent)
                {
                        Type t = parent.ResolveType (Type, false, Location);
@@ -3387,7 +3469,7 @@ namespace Mono.CSharp {
                        if (!parent.AsAccessible (t, ModFlags)) {
                                Report.Error (52, Location,
                                              "Inconsistent accessibility: field type `" +
-                                             TypeManager.CSharpName (t) + "' is less " +
+                                             TypeManager.MonoBASIC_Name (t) + "' is less " +
                                              "accessible than field `" + Name + "'");
                                return false;
                        }
@@ -3395,18 +3477,41 @@ namespace Mono.CSharp {
                        if (t.IsPointer && !UnsafeOK (parent))
                                return false;
                                
-                       if (RootContext.WarningLevel > 1){
-                               Type ptype = parent.TypeBuilder.BaseType;
+                       Type ptype = parent.TypeBuilder.BaseType;
 
-                               // ptype is only null for System.Object while compiling corlib.
-                               if (ptype != null){
-                                       TypeContainer.FindMembers (
-                                               ptype, MemberTypes.Method,
-                                               BindingFlags.Public |
-                                               BindingFlags.Static | BindingFlags.Instance,
-                                               System.Type.FilterName, Name);
+                       // ptype is only null for System.Object while compiling corlib.
+                       if (ptype != null){
+                               MemberList list = TypeContainer.FindMembers (
+                                       ptype, MemberTypes.Field,
+                                       BindingFlags.Public |
+                                       BindingFlags.Static | BindingFlags.Instance,
+                                       System.Type.FilterName, Name);
+
+                               if (RootContext.WarningLevel > 1){      
+                                       if ((list.Count > 0) && ((ModFlags & Modifiers.SHADOWS) == 0)) 
+                                       {
+                                               Report.Warning (
+                                                       40004, 2, Location, 
+                                                       "Variable '" + Name + "' should be declared " +
+                                                       "Shadows since the base type '" + ptype.Name + 
+                                                       "' has a variable with same name");
+
+                                               ModFlags |= Modifiers.SHADOWS;
+                                       }
                                }
+                               if (list.Count == 0)
+                                       // if a member of module is not inherited from Object class
+                                       // can not be declared protected
+                                       if ((parent is Module) && ((ModFlags & Modifiers.PROTECTED) != 0))
+                                       Report.Error (30593, Location,
+                                               "'Variable' inside a 'Module' can not be " +
+                                               "declared as 'Protected'");
                        }
+                       
+                       if ((parent is Struct) && ((ModFlags & Modifiers.PROTECTED) != 0))
+                               Report.Error (31047, Location,
+                                       "'Variable' inside a 'Structure' can not be " +
+                                       "declared as 'Protected'");
 
                        if ((ModFlags & Modifiers.VOLATILE) != 0){
                                if (!t.IsClass){
@@ -3425,7 +3530,7 @@ namespace Mono.CSharp {
                                                Report.Error (
                                                        677, Location, parent.MakeName (Name) +
                                                        " A volatile field can not be of type `" +
-                                                       TypeManager.CSharpName (t) + "'");
+                                                       TypeManager.MonoBASIC_Name (t) + "'");
                                                return false;
                                        }
                                }
@@ -3453,8 +3558,15 @@ namespace Mono.CSharp {
                        EmitContext ec = new EmitContext (tc, Location, null,
                                                          FieldBuilder.FieldType, ModFlags);
 
-                       Attribute.ApplyAttributes (ec, FieldBuilder, this, OptAttributes, Location);
+                       if (OptAttributes != null)
+                               OptAttributes.Emit (ec, this);
                }
+               
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+               {
+                       FieldBuilder.SetCustomAttribute (cb);
+               }
+               
        }
 
        //
@@ -3474,168 +3586,340 @@ namespace Mono.CSharp {
                }
        }
 
-       //
-       // Properties and Indexers both generate PropertyBuilders, we use this to share 
-       // their common bits.
-       //
-       abstract public class PropertyBase : MethodCore {
-               public Accessor Get, Set;
-               public PropertyBuilder PropertyBuilder;
-               public MethodBuilder GetBuilder, SetBuilder;
-               public MethodData GetData, SetData;
+       public class GetMethod {
+               private Accessor Get;
+               public MethodData GetData;
+               public MethodBuilder GetBuilder;
 
-               protected EmitContext ec;
+               Property parent_property;
+               Location Location;
 
-               public PropertyBase (Expression type, string name, int mod_flags, int allowed_mod,
-                                    Parameters parameters, Accessor get_block, Accessor set_block,
-                                    Attributes attrs, Location loc)
-                       : base (type, mod_flags, allowed_mod, name, attrs, parameters, loc)
+               Parameters get_params;
+               
+               public GetMethod (Property parent_property, Accessor get_block, Attributes attrs, Parameters p_get, Location loc)
                {
+                       this.parent_property = parent_property;
                        Get = get_block;
-                       Set = set_block;
-               }
-
-               protected override bool DoDefine (TypeContainer parent)
+                       get_params = p_get;
+                       Location = loc;
+               }               
+               
+               public MethodBuilder Define (TypeContainer parent)
                {
-                       if (!base.DoDefine (parent))
-                               return false;
+                       Type [] g_parameters=null;
+                       Parameter [] g_parms;
+                       InternalParameters g_ip=null;
+
+                       if (get_params == Parameters.EmptyReadOnlyParameters) {
+                               g_parameters = TypeManager.NoTypes;
+                               g_ip = new InternalParameters (parent, Parameters.EmptyReadOnlyParameters);
+                       } else  {
+                               g_parameters = new Type [get_params.FixedParameters.Length];
+                               for (int i = 0; i < get_params.FixedParameters.Length; i ++) {
+                                       g_parameters[i] = get_params.FixedParameters[i].ParameterType;
+                               }
+                               g_parms = new Parameter [get_params.FixedParameters.Length];
+                               for (int i = 0; i < get_params.FixedParameters.Length; i ++) {
+                                       Parameter tp = get_params.FixedParameters[i];
+                                       g_parms[i] = new Parameter (tp.TypeName, tp.Name,
+                                               Parameter.Modifier.NONE, null);
+                               }
+                               g_ip = new InternalParameters (
+                                       parent, new Parameters (g_parms, null, Location));
+                       }
 
-                       ec = new EmitContext (parent, Location, null, MemberType, ModFlags);
+                       GetData = new MethodData (parent_property, "get", parent_property.MemberType,
+                                                 g_parameters, g_ip, CallingConventions.Standard,
+                                                 Get.OptAttributes, parent_property.ModFlags, parent_property.MethodAttributeFlags, false);
 
-                       return true;
+                       if (!GetData.Define (parent))
+                                       return null;
+
+                       GetBuilder = GetData.MethodBuilder;
+                       
+                       return GetBuilder;
                }
 
-               //
-               // Checks our base implementation if any
-               //
-               protected override bool CheckBase (TypeContainer parent)
-               {
-                       // Check whether arguments were correct.
-                       if (!DoDefineParameters (parent))
-                               return false;
+               public void Emit (TypeContainer tc)
+               {
+                       if (GetData != null) 
+                       {
+                               parent_property.Parameters = get_params;
+                               GetData.Emit (tc, Get.Block, Get);
+                       }
+               }
+       }
+
+       public class SetMethod {
+               Accessor Set;
+               MethodData SetData;
+               MethodBuilder SetBuilder;
+
+               Property parent_property;
+               Location Location;
+
+               string set_parameter_name;
+               Parameters set_params;
+               
+               public SetMethod (Property parent_property, Accessor set_block, string set_name, 
+                               Parameters p_set, Location loc)
+               {
+                       this.parent_property = parent_property;
+                       Set = set_block;
+                       set_params = p_set;
+                       set_parameter_name = set_name;
+                       this.Location = loc;
+               }               
+               
+               public MethodBuilder Define (TypeContainer parent)
+               {
+                       Type [] s_parameters=null;
+                       Parameter [] s_parms;
+                       InternalParameters s_ip=null;
+                       
+                       if (set_params == Parameters.EmptyReadOnlyParameters) 
+                       {
+                               s_parameters = new Type [1];
+                               s_parameters [0] = parent_property.MemberType;
+
+                               s_parms = new Parameter [1];
+                               s_parms [0] = new Parameter (parent_property.Type, set_parameter_name, 
+                                       Parameter.Modifier.NONE, null);
+                       } else {
+                               s_parameters = new Type [set_params.FixedParameters.Length];
+                               for (int i = 0; i < set_params.FixedParameters.Length; i ++) {
+                                       s_parameters[i] = set_params.FixedParameters[i].ParameterType;
+                               }
+
+                               s_parms = new Parameter [set_params.FixedParameters.Length];
+                               for (int i = 0; i < set_params.FixedParameters.Length; i ++) {
+                                       Parameter tp = set_params.FixedParameters[i];
+                                       s_parms[i] = new Parameter (tp.TypeName, tp.Name,
+                                               Parameter.Modifier.NONE, null);
+                               }
+                       }
+
+                       s_ip = new InternalParameters (
+                               parent, new Parameters (s_parms, null, Location));
+
+                       SetData = new MethodData (parent_property, "set", TypeManager.void_type,
+                               s_parameters, s_ip, CallingConventions.Standard,
+                               Set.OptAttributes, parent_property.ModFlags, parent_property.MethodAttributeFlags, false);
+
+                       if (!SetData.Define (parent))
+                               return null;
+
+                       SetBuilder = SetData.MethodBuilder;
+                       SetBuilder.DefineParameter (1, ParameterAttributes.None, 
+                               set_parameter_name); 
+
+                       return SetBuilder;
+               }
+
+               public void Emit (TypeContainer tc)
+               {
+                       if (SetData != null) 
+                       {
+                               parent_property.Parameters = set_params;
+                               SetData.Emit (tc, Set.Block, Set);
+                       }
+               }
+       }
+
+       public class Property : MethodCore {
+               GetMethod GetMethod;
+               SetMethod SetMethod;
+               
+               public Accessor Set;
+               public PropertyBuilder PropertyBuilder;
+               public MethodBuilder GetBuilder;
+               public MethodBuilder SetBuilder;
+               public MethodData SetData;
+
+               protected EmitContext ec;
+
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+               {
+                       PropertyBuilder.SetCustomAttribute (cb);
+               }
+
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Property;
+                       }
+               }
+
+               protected override bool DoDefine (TypeContainer parent)
+               {
+                       if (!base.DoDefine (parent))
+                               return false;
+
+                       ec = new EmitContext (parent, Location, null, MemberType, ModFlags);
+
+                       return true;
+               }
+
+               //
+               // Checks our base implementation if any
+               //
+               protected override bool CheckBase (TypeContainer container)
+               {
+                       base.CheckBase (container);
+                       
+                       // Check whether arguments were correct.
+                       if (!DoDefineParameters (container))
+                               return false;
 
                        if (IsExplicitImpl)
                                return true;
 
-                       string report_name;
-                       MethodSignature ms, base_ms;
+                       MethodSignature ms = new MethodSignature (Name, null, ParameterTypes);
+                       if (!IsOperator) 
+                       {
+                               MemberList mi_this;
+
+                               mi_this = TypeContainer.FindMembers (
+                                       container.TypeBuilder, MemberTypes.Property,
+                                       BindingFlags.NonPublic | BindingFlags.Public |
+                                       BindingFlags.Static | BindingFlags.Instance |
+                                       BindingFlags.DeclaredOnly,
+                                       MethodSignature.method_signature_filter, ms);
+
+                               if (mi_this.Count > 0) {
+                                       Report.Error (111, Location, "Class `" + container.Name + "' " +
+                                               "already defines a member called `" + Name + "' " +
+                                               "with the same parameter types");
+                                       return false;
+                               }
+                       }
+
+                       if (container is Interface)
+                               return true;
+
+                       Type retval = null;
+                       if ((ModFlags & Modifiers.READONLY) != 0)
+                               retval = MemberType;
+
+                       //string report_name;
+                       MethodSignature base_ms;
+                       
+                       /*
                        if (this is Indexer) {
                                string name, base_name;
 
                                report_name = "this";
-                               name = TypeManager.IndexerPropertyName (parent.TypeBuilder);
+                               name = TypeManager.IndexerPropertyName (container.TypeBuilder);
                                ms = new MethodSignature (name, null, ParameterTypes);
-                               base_name = TypeManager.IndexerPropertyName (parent.TypeBuilder.BaseType);
-                               base_ms = new MethodSignature (base_name, null, ParameterTypes);
-                       } else {
-                               report_name = Name;
-                               ms = base_ms = new MethodSignature (Name, null, ParameterTypes);
+                               base_name = TypeManager.IndexerPropertyName (container.TypeBuilder.BaseType);
+                               base_ms = new MethodSignature (base_name, retval, ParameterTypes);
+                       } else */ {
+                               //report_name = Name;
+                               ms = base_ms = new MethodSignature (Name, retval, ParameterTypes);
                        }
 
-                       MemberList props_this;
-
-                       props_this = TypeContainer.FindMembers (
-                               parent.TypeBuilder, MemberTypes.Property,
-                               BindingFlags.NonPublic | BindingFlags.Public |
-                               BindingFlags.Static | BindingFlags.Instance |
-                               BindingFlags.DeclaredOnly,
-                               MethodSignature.method_signature_filter, ms);
+                       //
+                       // Verify if the parent has a type with the same name, and then
+                       // check whether we have to create a new slot for it or not.
+                       //
+                       Type ptype = container.TypeBuilder.BaseType;
 
-                       if (props_this.Count > 0) {
-                               Report.Error (111, Location, "Class `" + parent.Name + "' " +
-                                             "already defines a member called `" + report_name + "' " +
-                                             "with the same parameter types");
-                               return false;
-                       }
+                       MemberInfo parent_member = null;
+                       MemberList mi, mi_static, mi_instance;
 
                        //
                        // Find properties with the same name on the base class
                        //
-                       MemberList props;
-                       MemberList props_static = TypeContainer.FindMembers (
-                               parent.TypeBuilder.BaseType, MemberTypes.Property,
+                       mi_static = TypeContainer.FindMembers (
+                               ptype, MemberTypes.Property,
                                BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static,
                                MethodSignature.inheritable_property_signature_filter, base_ms);
 
-                       MemberList props_instance = TypeContainer.FindMembers (
-                               parent.TypeBuilder.BaseType, MemberTypes.Property,
+                       mi_instance = TypeContainer.FindMembers (
+                               ptype, MemberTypes.Property,
                                BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance,
                                MethodSignature.inheritable_property_signature_filter,
                                base_ms);
 
-                       //
-                       // Find if we have anything
-                       //
-                       if (props_static.Count > 0)
-                               props = props_static;
-                       else if (props_instance.Count > 0)
-                               props = props_instance;
+                       if (mi_instance.Count > 0)
+                               mi = mi_instance;
+                       else if (mi_static.Count > 0)
+                               mi = mi_static;
                        else
-                               props = null;
+                               mi = null;
 
-                       //
-                       // If we have something on the base.
-                       if (props != null && props.Count > 0){
-                               PropertyInfo pi = (PropertyInfo) props [0];
+                       if (mi != null && mi.Count > 0) 
+                               parent_member = (PropertyInfo) mi [0];
 
-                               MethodInfo inherited_get = TypeManager.GetPropertyGetter (pi);
-                               MethodInfo inherited_set = TypeManager.GetPropertySetter (pi);
+                       if (parent_member is PropertyInfo) {
+                               PropertyInfo parent_property = (PropertyInfo)parent_member;
 
-                               MethodInfo reference = inherited_get == null ?
-                                       inherited_set : inherited_get;
-                               
-                               if (reference != null) {
-                                       string name = reference.DeclaringType.Name + "." + report_name;
+                               string name = parent_property.DeclaringType.Name + "." +
+                                       parent_property.Name;
 
-                                       if (!CheckMethodAgainstBase (parent, flags, reference, name))
-                                               return false;
-                               }
+                               MethodInfo get, set, parent_method;
+                               get = parent_property.GetGetMethod (true);
+                               set = parent_property.GetSetMethod (true);
 
-                               if (((ModFlags & Modifiers.NEW) == 0) && (pi.PropertyType != MemberType)) {
-                                       Report.Error (508, parent.MakeName (Name) + ": cannot " +
-                                                     "change return type when overriding inherited " +
-                                                     "member `" + pi.DeclaringType + "." + pi.Name + "'");
+                               if (get != null)
+                                       parent_method = get;
+                               else if (set != null)
+                                       parent_method = set;
+                               else
+                                       throw new Exception ("Internal error!");
+
+                               if (!CheckMethodAgainstBase (container, flags, parent_method, name))
                                        return false;
+
+                               if ((ModFlags & Modifiers.NEW) == 0) {
+                                       Type parent_type = TypeManager.TypeToCoreType (
+                                               parent_property.PropertyType);
+
+                                       if (parent_type != MemberType) {
+                                               Report.Error (
+                                                       508, Location, container.MakeName (Name) + ": cannot " +
+                                                       "change return type when overriding " +
+                                                       "inherited member " + name);
+                                               return false;
+                                       }
                                }
-                       } else {
-                               if ((ModFlags & Modifiers.NEW) != 0)
-                                       WarningNotHiding (parent);
-                               
-                               if ((ModFlags & Modifiers.OVERRIDE) != 0){
+                       } else if (parent_member == null) {
+                               /*if ((ModFlags & Modifiers.NEW) != 0)
+                                       WarningNotHiding (container);
+                               */
+                               if ((ModFlags & Modifiers.OVERRIDE) != 0) {
+
+                                       /*
                                        if (this is Indexer)
                                                Report.Error (115, Location,
-                                                             parent.MakeName (Name) +
-                                                             " no suitable indexers found to override");
+                                                       container.MakeName (Name) +
+                                                       " no suitable indexers found to override");
                                        else
+                                       */
                                                Report.Error (115, Location,
-                                                             parent.MakeName (Name) +
-                                                             " no suitable properties found to override");
+                                                       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)     {
+                                               Report.Error (31088, Location,
+                                                       container.MakeName (Name) + " : Cannot " +
+                                                       "be declared NotOverridable since this method is " +
+                                                       "not maked as Overrides");
+                                       }
+                               }
+                               // if a member of module is not inherited from Object class
+                               // can not be declared protected
+                               if ((container is Module) && ((ModFlags & Modifiers.PROTECTED) != 0))
+                                       Report.Error (31066, Location,
+                                               "'Property' inside a 'Module' can not be declared as " +
+                                               "'Protected' or 'Protected Friend'");
                        }
                        return true;
                }
 
-               public void Emit (TypeContainer tc)
-               {
-                       //
-                       // The PropertyBuilder can be null for explicit implementations, in that
-                       // case, we do not actually emit the ".property", so there is nowhere to
-                       // put the attribute
-                       //
-                       if (PropertyBuilder != null)
-                               Attribute.ApplyAttributes (ec, PropertyBuilder, this, OptAttributes, Location);
-/*
-                       if (GetData != null)
-                               GetData.Emit (tc, Get.Block, Get);
 
-                       if (SetData != null)
-                               SetData.Emit (tc, Set.Block, Set);
-*/                             
-               }
-       }
-                       
-       public class Property : PropertyBase {
                const int AllowedModifiers =
                        Modifiers.NEW |
                        Modifiers.PUBLIC |
@@ -3646,9 +3930,14 @@ namespace Mono.CSharp {
                        Modifiers.SEALED |
                        Modifiers.OVERRIDE |
                        Modifiers.ABSTRACT |
-                       Modifiers.UNSAFE |
+                       Modifiers.UNSAFE |
                        Modifiers.EXTERN |
-                       Modifiers.VIRTUAL;
+                       Modifiers.VIRTUAL |
+                       Modifiers.NONVIRTUAL |
+                       Modifiers.DEFAULT |
+                       Modifiers.READONLY |
+                       Modifiers.WRITEONLY |
+                       Modifiers.SHADOWS;
 
                string set_parameter_name;
                Parameters get_params;
@@ -3657,33 +3946,37 @@ namespace Mono.CSharp {
                public Property (Expression type, string name, int mod_flags,
                                Accessor get_block, Accessor set_block,
                                Attributes attrs, Location loc, string set_name, 
-                               Parameters p_get, Parameters p_set)
-                       : base (type, name, mod_flags, AllowedModifiers,
-                               p_set, // FIXME ???????????
-                               get_block, set_block, attrs, loc)
+                               Parameters p_get, Parameters p_set, ArrayList impl_what)
+                       : base (type, mod_flags, AllowedModifiers, name, attrs, p_set, loc)
+               
                {
-                       set_parameter_name = set_name;
-                       get_params = p_get;
-                       set_params = p_set;
-               }
+                       if (get_block != null)
+                               GetMethod = new GetMethod (this, get_block, attrs, p_get, loc);
 
+                       if (set_block != null)
+                               SetMethod = new SetMethod (this, set_block, set_name, p_set, loc);
+                       
+                       Implements = impl_what;
+               }               
+               
                public Property (Expression type, string name, int mod_flags,
                                 Accessor get_block, Accessor set_block,
                                 Attributes attrs, Location loc)
-                       : base (type, name, mod_flags, AllowedModifiers,
-                               Parameters.EmptyReadOnlyParameters,
-                               get_block, set_block, attrs, loc)
+                       : this (type, name, mod_flags, get_block, set_block, attrs, loc, 
+                                       "Value", Parameters.EmptyReadOnlyParameters, Parameters.EmptyReadOnlyParameters, null)
                {
-                       set_parameter_name = "Value";
-                       get_params = Parameters.EmptyReadOnlyParameters;
-                       set_params = Parameters.EmptyReadOnlyParameters;
                }
 
                public override bool Define (TypeContainer parent)
                {
-                       Type [] g_parameters=null, s_parameters=null;
-                       Parameter [] g_parms, s_parms;
-                       InternalParameters g_ip=null, s_ip=null;
+                       /*Type [] s_parameters=null;
+                       Parameter [] s_parms;
+                       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 (!DoDefine (parent))
                                return false;
@@ -3693,83 +3986,23 @@ namespace Mono.CSharp {
 
                        flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
 
-                       if (Get != null) {
-                               if (get_params == Parameters.EmptyReadOnlyParameters) 
-                               {
-                                       g_parameters = TypeManager.NoTypes;
-                                       g_ip = new InternalParameters (
-                                                       parent, Parameters.EmptyReadOnlyParameters);
-                               }
-                               else
-                               {
-                                       g_parameters = new Type [get_params.FixedParameters.Length];
-                                       for (int i = 0; i < get_params.FixedParameters.Length; i ++) 
-                                       {
-                                               g_parameters[i] = get_params.FixedParameters[i].ParameterType;
-                                       }
-                                       g_parms = new Parameter [get_params.FixedParameters.Length];
-                                       for (int i = 0; i < get_params.FixedParameters.Length; i ++) 
-                                       {
-                                               Parameter tp = get_params.FixedParameters[i];
-                                               g_parms[i] = new Parameter (tp.TypeName, tp.Name,
-                                                       Parameter.Modifier.NONE, null);
-                                       }
-                                       g_ip = new InternalParameters (
-                                               parent, new Parameters (g_parms, null, Location));
-                               }
-
-                               GetData = new MethodData (this, "get", MemberType,
-                                                         g_parameters, g_ip, CallingConventions.Standard,
-                                                         Get.OptAttributes, ModFlags, flags, false);
-
-                               if (!GetData.Define (parent))
-                                       return false;
-
-                               GetBuilder = GetData.MethodBuilder;
-                       }
-
-                       if (Set != null) {
-                               if (set_params == Parameters.EmptyReadOnlyParameters) 
-                               {
-                                       s_parameters = new Type [1];
-                                       s_parameters [0] = MemberType;
-
-                                       s_parms = new Parameter [1];
-                                       s_parms [0] = new Parameter (Type, /* was "value" */ set_parameter_name, 
-                                               Parameter.Modifier.NONE, null);
-                               }
-                               else
-                               {
-                                       s_parameters = new Type [set_params.FixedParameters.Length];
-                                       for (int i = 0; i < set_params.FixedParameters.Length; i ++) 
-                                       {
-                                               s_parameters[i] = set_params.FixedParameters[i].ParameterType;
-                                       }
-
-                                       s_parms = new Parameter [set_params.FixedParameters.Length];
-                                       for (int i = 0; i < set_params.FixedParameters.Length; i ++) 
-                                       {
-                                               Parameter tp = set_params.FixedParameters[i];
-                                               s_parms[i] = new Parameter (tp.TypeName, tp.Name,
-                                                                                                       Parameter.Modifier.NONE, null);
-                                       }
-                               }
-
-                               s_ip = new InternalParameters (
-                                       parent, new Parameters (s_parms, null, Location));
-
-                               
-                               SetData = new MethodData (this, "set", TypeManager.void_type,
-                                                         s_parameters, s_ip, CallingConventions.Standard,
-                                                         Set.OptAttributes, ModFlags, flags, false);
-
-                               if (!SetData.Define (parent))
-                                       return false;
+                       if (GetMethod == null) {
+                               if ((ModFlags & Modifiers.WRITEONLY) == 0)
+                                       Report.Error (
+                                               30124, Location,
+                                               "Property without 'Get' accessor must have a 'WriteOnly' modifier");
+                       } else
+                               GetBuilder = GetMethod.Define (parent);
 
-                               SetBuilder = SetData.MethodBuilder;
-                               SetBuilder.DefineParameter (1, ParameterAttributes.None, 
-                                                               /* was "value" */ set_parameter_name); 
+                       if (SetMethod== null) {
+                               if ((ModFlags & Modifiers.READONLY) == 0)
+                                       Report.Error (
+                                               30124, Location,
+                                               "Property without 'Set' accessor must have a 'ReadOnly' modifier");
+                                               
                        }
+                       else 
+                               SetBuilder = SetMethod.Define (parent);
 
                        // FIXME - PropertyAttributes.HasDefault ?
                        
@@ -3781,11 +4014,8 @@ namespace Mono.CSharp {
                                PropertyBuilder = parent.TypeBuilder.DefineProperty (
                                        Name, prop_attr, MemberType, null);
                                
-                               if (Get != null)
-                                       PropertyBuilder.SetGetMethod (GetBuilder);
-                               
-                               if (Set != null)
-                                       PropertyBuilder.SetSetMethod (SetBuilder);
+                               PropertyBuilder.SetGetMethod (GetBuilder);
+                               PropertyBuilder.SetSetMethod (SetBuilder);
 
                                //
                                // HACK for the reasons exposed above
@@ -3804,21 +4034,32 @@ namespace Mono.CSharp {
 
                public void Emit (TypeContainer tc)
                {
-                       base.Emit (tc);
+                       //
+                       // The PropertyBuilder can be null for explicit implementations, in that
+                       // case, we do not actually emit the ".property", so there is nowhere to
+                       // put the attribute
+                       //
                        
-                       if (GetData != null) \r
+                       if (PropertyBuilder != null && OptAttributes != null)
+                               OptAttributes.Emit (ec, this);
+                       
+                       if (GetMethod != null) 
                        {
-                               Parameters = get_params;
-                               GetData.Emit (tc, Get.Block, Get);
+                               GetMethod.Emit (tc);
                        }
 
-                       if (SetData != null) \r
+                       if (SetMethod != null) 
                        {
-                               Parameters = set_params;
-                               SetData.Emit (tc, Set.Block, Set);
+                               SetMethod.Emit (tc);
                        }
-                               
                }
+
+               public MethodAttributes MethodAttributeFlags {
+                       get {
+                               return flags;
+                       }
+               }
+
        }
 
        /// </summary>
@@ -3955,6 +4196,98 @@ namespace Mono.CSharp {
                        }
                }
        }
+
+       
+       public class AddDelegateMethod {
+               MethodBuilder AddBuilder;
+               MethodData AddData;
+               Event parent_event;
+               Location Location;
+               
+               public AddDelegateMethod (Event parent_event, Location loc)
+               {
+                       this.parent_event = parent_event;
+                       Location = loc;
+               }
+
+               public MethodBuilder Define (TypeContainer parent)
+               {
+                       Type [] parameter_types = new Type [1];
+                       parameter_types [0] = parent_event.MemberType;
+
+                       Parameter [] parms = new Parameter [1];
+                       parms [0] = new Parameter (parent_event.Type, /* was "value" */ parent_event.Name, Parameter.Modifier.NONE, null);
+                       InternalParameters ip = new InternalParameters (
+                               parent, new Parameters (parms, null, Location)); 
+
+                       AddData = new MethodData (parent_event, "add", TypeManager.void_type,
+                                                 parameter_types, ip, CallingConventions.Standard, null,
+                                                 parent_event.ModFlags, parent_event.MethodAttributeFlags, false);
+
+                       if (!AddData.Define (parent))
+                               return null;
+
+                       AddBuilder = AddData.MethodBuilder;
+                       AddBuilder.DefineParameter (1, ParameterAttributes.None, /* was "value" */ parent_event.Name);
+
+
+                       return AddBuilder;
+               }
+
+
+               public void Emit (TypeContainer tc)
+               {
+                       ILGenerator ig = AddData.MethodBuilder.GetILGenerator ();
+                       EmitContext ec = new EmitContext (tc, Location, ig, TypeManager.void_type, parent_event.ModFlags);
+                       parent_event.EmitDefaultMethod (ec, true);
+               }
+       }
+
+       public class RemoveDelegateMethod {
+               MethodBuilder RemoveBuilder;
+               MethodData RemoveData;
+               Event parent_event;
+               Location Location;
+               
+               public RemoveDelegateMethod (Event parent_event, Location loc)
+               {
+                       this.parent_event = parent_event;
+                       Location = loc;
+               }
+
+               public MethodBuilder Define (TypeContainer parent)
+               {
+                       //EventAttributes e_attr = EventAttributes.RTSpecialName | EventAttributes.SpecialName;
+
+                       Type [] parameter_types = new Type [1];
+                       parameter_types [0] = parent_event.MemberType;
+
+                       Parameter [] parms = new Parameter [1];
+                       parms [0] = new Parameter (parent_event.Type, /* was "value" */ parent_event.Name, Parameter.Modifier.NONE, null);
+                       InternalParameters ip = new InternalParameters (
+                               parent, new Parameters (parms, null, Location)); 
+
+
+                       RemoveData = new MethodData (parent_event, "remove", TypeManager.void_type,
+                                                    parameter_types, ip, CallingConventions.Standard, null,
+                                                    parent_event.ModFlags, parent_event.MethodAttributeFlags, false);
+
+                       if (!RemoveData.Define (parent))
+                               return null;
+
+                       RemoveBuilder = RemoveData.MethodBuilder;
+                       RemoveBuilder.DefineParameter (1, ParameterAttributes.None, /* was "value" */ parent_event.Name);
+
+                       return RemoveBuilder;
+               }
+
+               public void Emit (TypeContainer tc)
+               {
+                       ILGenerator ig = RemoveData.MethodBuilder.GetILGenerator ();
+                       EmitContext ec = new EmitContext (tc, Location, ig, TypeManager.void_type, parent_event.ModFlags);
+                       parent_event.EmitDefaultMethod (ec, false);
+               }
+       }
        
        public class Event : FieldBase {
                const int AllowedModifiers =
@@ -3970,21 +4303,41 @@ namespace Mono.CSharp {
                        Modifiers.UNSAFE |
                        Modifiers.ABSTRACT;
 
-               public readonly Accessor  Add;
-               public readonly Accessor  Remove;
+               public readonly AddDelegateMethod  Add;
+               public readonly RemoveDelegateMethod  Remove;
                public MyEventBuilder     EventBuilder;
 
                MethodBuilder AddBuilder, RemoveBuilder;
-               MethodData AddData, RemoveData;
                
-               public Event (Expression type, string name, Object init, int mod, Accessor add,
-                             Accessor remove, Attributes attrs, Location loc)
+               public Event (Expression type, string name, Object init, int mod, Attributes attrs, Location loc)
+                               : base (type, mod, AllowedModifiers, name, init, attrs, loc)
+               {
+                       Add = new AddDelegateMethod (this, loc);
+                       Remove = new RemoveDelegateMethod (this, loc);
+
+                       Implements = null;
+               }
+
+               public Event (Expression type, string name, Object init, int mod,  Attributes attrs, ArrayList impl_what, Location loc)
                        : base (type, mod, AllowedModifiers, name, init, attrs, loc)
                {
-                       Add = add;
-                       Remove = remove;
+                       Add = new AddDelegateMethod (this, loc);
+                       Remove = new RemoveDelegateMethod (this, loc);
+
+                       Implements = impl_what;
                }
 
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+               {
+                       EventBuilder.SetCustomAttribute (cb);
+               }
+
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Event;
+                       }
+               }
+               
                public override bool Define (TypeContainer parent)
                {
                        EventAttributes e_attr = EventAttributes.RTSpecialName | EventAttributes.SpecialName;
@@ -3993,7 +4346,7 @@ namespace Mono.CSharp {
                                return false;
 
                        if (!MemberType.IsSubclassOf (TypeManager.delegate_type)) {
-                               Report.Error (66, Location, "'" + parent.Name + "." + Name +
+                               Report.Error (31044, Location, "'" + parent.Name + "." + Name +
                                              "' : event must be of a delegate type");
                                return false;
                        }
@@ -4003,58 +4356,34 @@ namespace Mono.CSharp {
 
                        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;
 
-                       //
-                       // Now define the accessors
-                       //
-                       AddData = new MethodData (this, "add", TypeManager.void_type,
-                                                 parameter_types, ip, CallingConventions.Standard,
-                                                 (Add != null) ? Add.OptAttributes : null,
-                                                 ModFlags, flags, false);
-
-                       if (!AddData.Define (parent))
-                               return false;
-
-                       AddBuilder = AddData.MethodBuilder;
-                       AddBuilder.DefineParameter (1, ParameterAttributes.None, /* was "value" */ this.Name);
-
-                       RemoveData = new MethodData (this, "remove", TypeManager.void_type,
-                                                    parameter_types, ip, CallingConventions.Standard,
-                                                    (Remove != null) ? Remove.OptAttributes : null,
-                                                    ModFlags, flags, false);
-
-                       if (!RemoveData.Define (parent))
-                               return false;
-
-                       RemoveBuilder = RemoveData.MethodBuilder;
-                       RemoveBuilder.DefineParameter (1, ParameterAttributes.None, /* was "value" */ this.Name);
+                       AddBuilder = Add.Define (parent);
+                       RemoveBuilder = Remove.Define (parent);
+                       
 
                        if (!IsExplicitImpl){
                                EventBuilder = new MyEventBuilder (
                                        parent.TypeBuilder, Name, e_attr, MemberType);
                                        
-                               if (Add == null && Remove == null) {
-                                       FieldBuilder = parent.TypeBuilder.DefineField (
-                                               Name, MemberType,
+                               FieldBuilder = parent.TypeBuilder.DefineField (Name, MemberType,
                                                FieldAttributes.FamANDAssem | ((ModFlags & Modifiers.STATIC) != 0 ? FieldAttributes.Static : 0));
-                                       TypeManager.RegisterPrivateFieldOfEvent (
-                                               (EventInfo) EventBuilder, FieldBuilder);
-                                       TypeManager.RegisterFieldBase (FieldBuilder, this);
-                               }
+                               TypeManager.RegisterPrivateFieldOfEvent ((EventInfo) EventBuilder, FieldBuilder);
+                               TypeManager.RegisterFieldBase (FieldBuilder, this);
                        
                                EventBuilder.SetAddOnMethod (AddBuilder);
                                EventBuilder.SetRemoveOnMethod (RemoveBuilder);
 
                                if (!TypeManager.RegisterEvent (EventBuilder, AddBuilder, RemoveBuilder)) {
                                        Report.Error (111, Location,
-                                                     "Class `" + parent.Name +
-                                                     "' already contains a definition for the event `" +
-                                                     Name + "'");
+                                                   "Class `" + parent.Name +
+                                                "' already contains a definition for the event `" +
+                                                Name + "'");
                                        return false;
                                }
                        }
@@ -4062,7 +4391,7 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               void EmitDefaultMethod (EmitContext ec, bool is_add)
+               public void EmitDefaultMethod (EmitContext ec, bool is_add)
                {
                        ILGenerator ig = ec.ig;
                        MethodInfo method = null;
@@ -4095,529 +4424,22 @@ namespace Mono.CSharp {
                        EmitContext ec;
 
                        ec = new EmitContext (tc, Location, null, MemberType, ModFlags);
-                       Attribute.ApplyAttributes (ec, EventBuilder, this, OptAttributes, Location);
-
-                       if (Add != null)
-                               AddData.Emit (tc, Add.Block, Add);
-                       else {
-                               ILGenerator ig = AddData.MethodBuilder.GetILGenerator ();
-                               ec = new EmitContext (tc, Location, ig, TypeManager.void_type, ModFlags);
-                               EmitDefaultMethod (ec, true);
-                       }
-
-                       if (Remove != null)
-                               RemoveData.Emit (tc, Remove.Block, Remove);
-                       else {
-                               ILGenerator ig = RemoveData.MethodBuilder.GetILGenerator ();
-                               ec = new EmitContext (tc, Location, ig, TypeManager.void_type, ModFlags);
-                               EmitDefaultMethod (ec, false);
-                       }
-               }
-               
-       }
-
-       //
-       // FIXME: This does not handle:
-       //
-       //   int INTERFACENAME [ args ]
-       //   Does not 
-       //
-       // Only:
-       // 
-       // int this [ args ]
-       public class Indexer : PropertyBase {
-
-               const int AllowedModifiers =
-                       Modifiers.NEW |
-                       Modifiers.PUBLIC |
-                       Modifiers.PROTECTED |
-                       Modifiers.INTERNAL |
-                       Modifiers.PRIVATE |
-                       Modifiers.VIRTUAL |
-                       Modifiers.SEALED |
-                       Modifiers.OVERRIDE |
-                       Modifiers.UNSAFE |
-                       Modifiers.EXTERN |
-                       Modifiers.ABSTRACT;
-
-               public string IndexerName;
-               public string InterfaceIndexerName;
-
-               //
-               // Are we implementing an interface ?
-               //
-               bool IsImplementing = false;
-               
-               public Indexer (Expression type, string int_type, int flags, Parameters parameters,
-                               Accessor get_block, Accessor set_block, Attributes attrs, Location loc)
-                       : base (type, "", flags, AllowedModifiers, parameters, get_block, set_block,
-                               attrs, loc)
-               {
-                       ExplicitInterfaceName = int_type;
-               }
-
-               public override bool Define (TypeContainer parent)
-               {
-                       PropertyAttributes prop_attr =
-                               PropertyAttributes.RTSpecialName |
-                               PropertyAttributes.SpecialName;
-                       
-                       if (!DoDefine (parent))
-                               return false;
-
-                       IndexerName = Attribute.ScanForIndexerName (ec, OptAttributes);
-                       if (IndexerName == null)
-                               IndexerName = "Item";
-                       else if (IsExplicitImpl)
-                               Report.Error (592, Location,
-                                             "Attribute 'IndexerName' is not valid on this declaration " +
-                                             "type. It is valid on `property' declarations only.");
-
-                       ShortName = IndexerName;
-                       if (IsExplicitImpl) {
-                               InterfaceIndexerName = TypeManager.IndexerPropertyName (InterfaceType);
-                               Name = InterfaceType.FullName + "." + IndexerName;
-                       } else {
-                               InterfaceIndexerName = IndexerName;
-                               Name = ShortName;
-                       }
-
-                       if (!CheckBase (parent))
-                               return false;
-
-                       if (Get != null){
-                                InternalParameters ip = new InternalParameters (parent, Parameters);
-
-                               GetData = new MethodData (this, "get", MemberType,
-                                                         ParameterTypes, ip, CallingConventions.Standard,
-                                                         Get.OptAttributes, ModFlags, flags, false);
-
-                               if (!GetData.Define (parent))
-                                       return false;
-
-                               GetBuilder = GetData.MethodBuilder;
-                       }
-                       
-                       if (Set != null){
-                               int top = ParameterTypes.Length;
-                               Type [] set_pars = new Type [top + 1];
-                               ParameterTypes.CopyTo (set_pars, 0);
-                               set_pars [top] = MemberType;
-
-                               Parameter [] fixed_parms = Parameters.FixedParameters;
-
-                               if (fixed_parms == null){
-                                       throw new Exception ("We currently do not support only array arguments in an indexer");
-                                       // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
-                                       // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
-                                       //
-                                       // Here is the problem: the `value' parameter has
-                                       // to come *after* the array parameter in the declaration
-                                       // like this:
-                                       // X (object [] x, Type value)
-                                       // .param [0]
-                                       //
-                                       // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
-                                       // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
-                                       
-                               }
-                               
-                               Parameter [] tmp = new Parameter [fixed_parms.Length + 1];
-
-
-                               fixed_parms.CopyTo (tmp, 0);
-                               tmp [fixed_parms.Length] = new Parameter (
-                                       Type, /* was "value" */ this.Name, Parameter.Modifier.NONE, null);
-
-                               Parameters set_formal_params = new Parameters (tmp, null, Location);
-                               
-                               InternalParameters ip = new InternalParameters (parent, set_formal_params);
-
-                               SetData = new MethodData (this, "set", TypeManager.void_type,
-                                                         set_pars, ip, CallingConventions.Standard,
-                                                         Set.OptAttributes, ModFlags, flags, false);
-
-                               if (!SetData.Define (parent))
-                                       return false;
-
-                               SetBuilder = SetData.MethodBuilder;
-                       }
-
-                       //
-                       // Now name the parameters
-                       //
-                       Parameter [] p = Parameters.FixedParameters;
-                       if (p != null) {
-                               int i;
-                               
-                               for (i = 0; i < p.Length; ++i) {
-                                       if (Get != null)
-                                               GetBuilder.DefineParameter (
-                                                       i + 1, p [i].Attributes, p [i].Name);
-
-                                       if (Set != null)
-                                               SetBuilder.DefineParameter (
-                                                       i + 1, p [i].Attributes, p [i].Name);
-                               }
-                               
-
-                               if (Set != null)
-                                       SetBuilder.DefineParameter (
-                                               i + 1, ParameterAttributes.None, /* was "value" */ this.Name);
-                                       
-                               if (i != ParameterTypes.Length) {
-                                       Parameter array_param = Parameters.ArrayParameter;
-                                       SetBuilder.DefineParameter (
-                                               i + 1, array_param.Attributes, array_param.Name);
-                               }
-                       }
-
-                       if (GetData != null)
-                               IsImplementing = GetData.IsImplementing;
-                       else if (SetData != null)
-                               IsImplementing = SetData.IsImplementing;
-
-                       //
-                       // Define the PropertyBuilder if one of the following conditions are met:
-                       // a) we're not implementing an interface indexer.
-                       // b) the indexer has a different IndexerName and this is no
-                       //    explicit interface implementation.
-                       //
-                       if (!IsExplicitImpl) {
-                               PropertyBuilder = parent.TypeBuilder.DefineProperty (
-                                       IndexerName, prop_attr, MemberType, ParameterTypes);
-
-                               if (GetData != null)
-                                       PropertyBuilder.SetGetMethod (GetBuilder);
-
-                               if (SetData != null)
-                                       PropertyBuilder.SetSetMethod (SetBuilder);
-                               
-                               TypeManager.RegisterIndexer (PropertyBuilder, GetBuilder, SetBuilder,
-                                                            ParameterTypes);
-                       }
-
-                       return true;
-               }
-       }
-
-       public class Operator : MemberCore {
-
-               const int AllowedModifiers =
-                       Modifiers.PUBLIC |
-                       Modifiers.UNSAFE |
-                       Modifiers.EXTERN |
-                       Modifiers.STATIC;
 
-               const int RequiredModifiers =
-                       Modifiers.PUBLIC |
-                       Modifiers.STATIC;
-
-               public enum OpType : byte {
-
-                       // Unary operators
-                       LogicalNot,
-                       OnesComplement,
-                       Increment,
-                       Decrement,
-                       True,
-                       False,
-
-                       // Unary and Binary operators
-                       Addition,
-                       Subtraction,
-
-                       UnaryPlus,
-                       UnaryNegation,
-                       
-                       // Binary operators
-                       Multiply,
-                       Division,
-                       Modulus,
-                       BitwiseAnd,
-                       BitwiseOr,
-                       ExclusiveOr,
-                       LeftShift,
-                       RightShift,
-                       Equality,
-                       Inequality,
-                       GreaterThan,
-                       LessThan,
-                       GreaterThanOrEqual,
-                       LessThanOrEqual,
-
-                       // Implicit and Explicit
-                       Implicit,
-                       Explicit
-               };
-
-               public readonly OpType OperatorType;
-               public readonly Expression ReturnType;
-               public readonly Expression FirstArgType, SecondArgType;
-               public readonly string FirstArgName, SecondArgName;
-               public readonly Block  Block;
-               public Attributes      OptAttributes;
-               public MethodBuilder   OperatorMethodBuilder;
-               
-               public string MethodName;
-               public Method OperatorMethod;
-
-               public Operator (OpType type, Expression ret_type, int flags,
-                                Expression arg1type, string arg1name,
-                                Expression arg2type, string arg2name,
-                                Block block, Attributes attrs, Location loc)
-                       : base ("", loc)
-               {
-                       OperatorType = type;
-                       ReturnType = ret_type;
-                       ModFlags = Modifiers.Check (AllowedModifiers, flags, Modifiers.PUBLIC, loc);
-                       FirstArgType = arg1type;
-                       FirstArgName = arg1name;
-                       SecondArgType = arg2type;
-                       SecondArgName = arg2name;
-                       Block = block;
-                       OptAttributes = attrs;
-               }
-
-               string Prototype (TypeContainer parent)
-               {
-                       return parent.Name + ".operator " + OperatorType + " (" + FirstArgType + "," +
-                               SecondArgType + ")";
-               }
-               
-               public override bool Define (TypeContainer parent)
-               {
-                       int length = 1;
-                       MethodName = "op_" + OperatorType;
-                       
-                       if (SecondArgType != null)
-                               length = 2;
-                       
-                       Parameter [] param_list = new Parameter [length];
-
-                       if ((ModFlags & RequiredModifiers) != RequiredModifiers){
-                               Report.Error (
-                                       558, Location, 
-                                       "User defined operators `" +
-                                       Prototype (parent) +
-                                       "' must be declared static and public");
-                               return false;
-                       }
-
-                       param_list[0] = new Parameter (FirstArgType, FirstArgName,
-                                                      Parameter.Modifier.NONE, null);
-                       if (SecondArgType != null)
-                               param_list[1] = new Parameter (SecondArgType, SecondArgName,
-                                                              Parameter.Modifier.NONE, null);
-                       
-                       OperatorMethod = new Method (ReturnType, ModFlags, MethodName,
-                                                    new Parameters (param_list, null, Location),
-                                                    OptAttributes, Mono.CSharp.Location.Null);
-
-                       OperatorMethod.IsOperator = true;                       
-                       OperatorMethod.Define (parent);
-
-                       if (OperatorMethod.MethodBuilder == null)
-                               return false;
-                       
-                       OperatorMethodBuilder = OperatorMethod.MethodBuilder;
-
-                       Type [] param_types = OperatorMethod.ParameterTypes;
-                       Type declaring_type = OperatorMethodBuilder.DeclaringType;
-                       Type return_type = OperatorMethod.GetReturnType ();
-                       Type first_arg_type = param_types [0];
-
-                       // Rules for conversion operators
-                       
-                       if (OperatorType == OpType.Implicit || OperatorType == OpType.Explicit) {
-                               if (first_arg_type == return_type && first_arg_type == declaring_type){
-                                       Report.Error (
-                                               555, Location,
-                                               "User-defined conversion cannot take an object of the " +
-                                               "enclosing type and convert to an object of the enclosing" +
-                                               " type");
-                                       return false;
-                               }
-                               
-                               if (first_arg_type != declaring_type && return_type != declaring_type){
-                                       Report.Error (
-                                               556, Location, 
-                                               "User-defined conversion must convert to or from the " +
-                                               "enclosing type");
-                                       return false;
-                               }
-                               
-                               if (first_arg_type == TypeManager.object_type ||
-                                   return_type == TypeManager.object_type){
-                                       Report.Error (
-                                               -8, Location,
-                                               "User-defined conversion cannot convert to or from " +
-                                               "object type");
-                                       return false;
-                               }
-
-                               if (first_arg_type.IsInterface || return_type.IsInterface){
-                                       Report.Error (
-                                               552, Location,
-                                               "User-defined conversion cannot convert to or from an " +
-                                               "interface type");
-                                       return false;
-                               }
-                               
-                               if (first_arg_type.IsSubclassOf (return_type) ||
-                                   return_type.IsSubclassOf (first_arg_type)){
-                                       Report.Error (
-                                               -10, Location,
-                                               "User-defined conversion cannot convert between types " +
-                                               "that derive from each other");
-                                       return false;
-                               }
-                       } else if (SecondArgType == null) {
-                               // Checks for Unary operators
-                               
-                               if (first_arg_type != declaring_type){
-                                       Report.Error (
-                                               562, Location,
-                                               "The parameter of a unary operator must be the " +
-                                               "containing type");
-                                       return false;
-                               }
-                               
-                               if (OperatorType == OpType.Increment || OperatorType == OpType.Decrement) {
-                                       if (return_type != declaring_type){
-                                               Report.Error (
-                                                       559, Location,
-                                                       "The parameter and return type for ++ and -- " +
-                                                       "must be the containing type");
-                                               return false;
-                                       }
-                                       
-                               }
-                               
-                               if (OperatorType == OpType.True || OperatorType == OpType.False) {
-                                       if (return_type != TypeManager.bool_type){
-                                               Report.Error (
-                                                       215, Location,
-                                                       "The return type of operator True or False " +
-                                                       "must be bool");
-                                               return false;
-                                       }
-                               }
-                               
-                       } else {
-                               // Checks for Binary operators
-                               
-                               if (first_arg_type != declaring_type &&
-                                   param_types [1] != declaring_type){
-                                       Report.Error (
-                                               563, Location,
-                                               "One of the parameters of a binary operator must " +
-                                               "be the containing type");
-                                       return false;
-                               }
-                       }
+                       if (OptAttributes != null)
+                               OptAttributes.Emit (ec, this);
 
-                       return true;
+                       Add.Emit (tc);
+                       Remove.Emit (tc);
                }
-               
-               public void Emit (TypeContainer parent)
-               {
-                       EmitContext ec = new EmitContext (parent, Location, null, null, ModFlags);
-                       Attribute.ApplyAttributes (ec, OperatorMethodBuilder, this, OptAttributes, Location);
 
-                       //
-                       // abstract or extern methods have no bodies
-                       //
-                       if ((ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0)
-                               return;
-                       
-                       OperatorMethod.Block = Block;
-                       OperatorMethod.Emit (parent);
-               }
-
-               public static string GetName (OpType ot)
-               {
-                       switch (ot){
-                       case OpType.LogicalNot:
-                               return "!";
-                       case OpType.OnesComplement:
-                               return "~";
-                       case OpType.Increment:
-                               return "++";
-                       case OpType.Decrement:
-                               return "--";
-                       case OpType.True:
-                               return "true";
-                       case OpType.False:
-                               return "false";
-                       case OpType.Addition:
-                               return "+";
-                       case OpType.Subtraction:
-                               return "-";
-                       case OpType.UnaryPlus:
-                               return "+";
-                       case OpType.UnaryNegation:
-                               return "-";
-                       case OpType.Multiply:
-                               return "*";
-                       case OpType.Division:
-                               return "/";
-                       case OpType.Modulus:
-                               return "%";
-                       case OpType.BitwiseAnd:
-                               return "&";
-                       case OpType.BitwiseOr:
-                               return "|";
-                       case OpType.ExclusiveOr:
-                               return "^";
-                       case OpType.LeftShift:
-                               return "<<";
-                       case OpType.RightShift:
-                               return ">>";
-                       case OpType.Equality:
-                               return "==";
-                       case OpType.Inequality:
-                               return "!=";
-                       case OpType.GreaterThan:
-                               return ">";
-                       case OpType.LessThan:
-                               return "<";
-                       case OpType.GreaterThanOrEqual:
-                               return ">=";
-                       case OpType.LessThanOrEqual:
-                               return "<=";
-                       case OpType.Implicit:
-                               return "implicit";
-                       case OpType.Explicit:
-                               return "explicit";
-                       default: return "";
+               public MethodAttributes MethodAttributeFlags {
+                       get {
+                               return flags;
                        }
                }
                
-               public override string ToString ()
-               {
-                       Type return_type = OperatorMethod.GetReturnType();
-                       Type [] param_types = OperatorMethod.ParameterTypes;
-                       
-                       if (SecondArgType == null)
-                               return String.Format (
-                                       "{0} operator {1}({2})",
-                                       TypeManager.CSharpName (return_type),
-                                       GetName (OperatorType),
-                                       param_types [0]);
-                       else
-                               return String.Format (
-                                       "{0} operator {1}({2}, {3})",
-                                       TypeManager.CSharpName (return_type),
-                                       GetName (OperatorType),
-                                       param_types [0], param_types [1]);
-               }
        }
 
-       //
-       // This is used to compare method signatures
-       //
        struct MethodSignature {
                public string Name;
                public Type RetType;
@@ -4629,6 +4451,12 @@ namespace Mono.CSharp {
                /// </summary>
                public static MemberFilter method_signature_filter;
 
+               /// <summary>
+               ///    This delegate is used to extract methods which have the
+               ///    same signature as the argument except for the name
+               /// </summary>
+               public static MemberFilter method_signature_noname_filter;
+
                /// <summary>
                ///   This delegate is used to extract inheritable methods which
                ///   have the same signature as the argument.  By inheritable,
@@ -4648,6 +4476,7 @@ namespace Mono.CSharp {
                static MethodSignature ()
                {
                        method_signature_filter = new MemberFilter (MemberSignatureCompare);
+                       method_signature_noname_filter = new MemberFilter (MemberSignatureCompareNoName);
                        inheritable_method_signature_filter = new MemberFilter (
                                InheritableMemberSignatureCompare);
                        inheritable_property_signature_filter = new MemberFilter (
@@ -4700,11 +4529,21 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               static bool MemberSignatureCompareNoName (MemberInfo m, object filter_criteria)
+               {
+                       return MemberSignatureCompare (m, filter_criteria, false);
+               }
+
                static bool MemberSignatureCompare (MemberInfo m, object filter_criteria)
+               {
+                       return MemberSignatureCompare (m, filter_criteria, true);
+               }
+
+               static bool MemberSignatureCompare (MemberInfo m, object filter_criteria, bool use_name)
                {
                        MethodSignature sig = (MethodSignature) filter_criteria;
 
-                       if (m.Name != sig.Name)
+                       if (use_name && (m.Name != sig.Name))
                                return false;
 
                        Type ReturnType;
@@ -4717,7 +4556,7 @@ namespace Mono.CSharp {
                                ReturnType = pi.PropertyType;
                        else
                                return false;
-                       
+
                        //
                        // we use sig.RetType == null to mean `do not check the
                        // method return value.  
@@ -4731,6 +4570,7 @@ namespace Mono.CSharp {
                                args = TypeManager.GetArgumentTypes (mi);
                        else
                                args = TypeManager.GetArgumentTypes (pi);
+
                        Type [] sigp = sig.Parameters;
 
                        if (args.Length != sigp.Length)
@@ -4791,7 +4631,7 @@ namespace Mono.CSharp {
                // 
                static bool InheritablePropertySignatureCompare (MemberInfo m, object filter_criteria)
                {
-                       if (MemberSignatureCompare (m, filter_criteria)){
+               if (MemberSignatureCompare (m, filter_criteria)){
                                PropertyInfo pi = (PropertyInfo) m;
 
                                MethodInfo inherited_get = TypeManager.GetPropertyGetter (pi);