Ooops.
[mono.git] / mcs / mbas / class.cs
index 90ebe3fe21ccbb654d34ce8c93d1dfaa54970213..ed4a5fe0b6d662c66a129726483c8bedd9dc6c2c 100644 (file)
@@ -83,9 +83,6 @@ namespace Mono.MonoBASIC {
                // Holds the events
                ArrayList events;
 
-               // Holds the indexers
-               ArrayList indexers;
-
                // Holds AddHandlers stements for events
                ArrayList handlers;
 
@@ -113,12 +110,10 @@ namespace Mono.MonoBASIC {
                // 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
 
                AttributeUsageAttribute attribute_usage = new AttributeUsageAttribute (AttributeTargets.All);
@@ -143,22 +138,23 @@ namespace Mono.MonoBASIC {
                //
                // 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)
@@ -369,6 +365,13 @@ namespace Mono.MonoBASIC {
                        AdditionResult res;
                        string basename = prop.Name;
 
+                       string fullname = Name + "." + basename;
+
+                       Object value = defined_names [fullname];
+
+                       if (value != null && (!(value is Property)))
+                               return AdditionResult.NameExists;
+
                        if ((res = IsValid (basename)) != AdditionResult.Success)
                                return res;
 
@@ -379,7 +382,9 @@ namespace Mono.MonoBASIC {
                                properties.Insert (0, prop);
                        else
                                properties.Add (prop);
-                       DefineName (Name + "." + basename, prop);
+
+                       if (value == null)
+                               DefineName (Name + "." + basename, prop);
 
                        return AdditionResult.Success;
                }
@@ -401,19 +406,6 @@ namespace Mono.MonoBASIC {
                        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 AddEventHandler (Statement stmt)
                {
                        if (handlers == null)
@@ -430,7 +422,17 @@ namespace Mono.MonoBASIC {
 
                        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;
@@ -505,24 +507,12 @@ namespace Mono.MonoBASIC {
                        }
                }
 
-               public ArrayList Indexers {
-                       get {
-                               return indexers;
-                       }
-               }
-
                public ArrayList Delegates {
                        get {
                                return delegates;
                        }
                }
                
-               public Attributes OptAttributes {
-                       get {
-                               return attributes;
-                       }
-               }
-               
                public bool HaveStaticConstructor {
                        get {
                                return have_static_constructor;
@@ -547,7 +537,7 @@ namespace Mono.MonoBASIC {
                public bool EmitFieldInitializers (EmitContext ec)
                {
                        ArrayList fields;
-                       ILGenerator ig = ec.ig;
+                       //ILGenerator ig = ec.ig;
                        Expression instance_expr;
                        
                        if (ec.IsStatic){
@@ -770,7 +760,6 @@ namespace Mono.MonoBASIC {
                //
                public override TypeBuilder DefineType ()
                {
-                       Type parent;
                        bool error;
                        bool is_class;
 
@@ -795,21 +784,21 @@ namespace Mono.MonoBASIC {
                                        "Class declared as 'MustInherit' cannot be declared as 'NotInheritable'");
                        }
                        
-                       ifaces = GetClassBases (is_class, out parent, out error); 
+                       ifaces = GetClassBases (is_class, out base_class_type, out error); 
                        if (error)
                                return null;
 
                        if (this is Interface)
-                               parent = null;
+                               base_class_type = 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 (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.MonoBASIC_Name (parent) + "'");
+                                               "special class `" + TypeManager.MonoBASIC_Name (base_class_type) + "'");
                                        return null;
                                }
                        }
@@ -840,16 +829,15 @@ namespace Mono.MonoBASIC {
                        
                        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);
                        }
                                
                        if (!is_class)
@@ -879,9 +867,9 @@ namespace Mono.MonoBASIC {
 
                        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);
                        } else
                                RootContext.RegisterOrder (this); 
@@ -1010,46 +998,6 @@ namespace Mono.MonoBASIC {
                        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");
@@ -1138,11 +1086,6 @@ namespace Mono.MonoBASIC {
                        if (events != null)
                                DefineMembers (events, defined_names);
 
-                       if (indexers != null) {
-                               DefineIndexers ();
-                       } else
-                               IndexerName = "Item";
-
                        if (enums != null)
                                DefineMembers (enums, defined_names);
                        
@@ -1309,25 +1252,6 @@ namespace Mono.MonoBASIC {
                                                        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) {
@@ -1351,25 +1275,12 @@ namespace Mono.MonoBASIC {
                                                        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 ((mt & MemberTypes.NestedType) != 0) {
@@ -1516,13 +1427,9 @@ namespace Mono.MonoBASIC {
                                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);
-                               TypeBuilder.SetCustomAttribute (cb);*/
+                       if (this.DefaultPropName != null) {
+                               CustomAttributeBuilder cb = new CustomAttributeBuilder (TypeManager.default_member_ctor, new string [] { DefaultPropName });
+                               TypeBuilder.SetCustomAttribute (cb);
                        }
                        
                        if (fields != null)
@@ -1537,9 +1444,10 @@ namespace Mono.MonoBASIC {
                        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
                        //
@@ -1575,7 +1483,7 @@ namespace Mono.MonoBASIC {
 //                             foreach (TypeContainer tc in types)
 //                                     tc.Emit ();
                }
-               
+
                public override void CloseType ()
                {
                        try {
@@ -1658,7 +1566,7 @@ namespace Mono.MonoBASIC {
                {
                        const int vao = (Modifiers.VIRTUAL | Modifiers.ABSTRACT | Modifiers.OVERRIDE);
                        const int va = (Modifiers.VIRTUAL | Modifiers.ABSTRACT);
-                       const int nv = (Modifiers.SHADOWS | Modifiers.VIRTUAL);
+                       //const int nv = (Modifiers.SHADOWS | Modifiers.VIRTUAL);
                        bool ok = true;
                        string name = MakeName (n);
                        
@@ -1733,7 +1641,7 @@ namespace Mono.MonoBASIC {
                        if ((flags & Modifiers.PRIVATE) != 0){
                                if ((flags & vao) != 0){
                                        Report.Error (
-                                               31408, loc, name +
+                                               30266, loc, name +
                                                ": Members marked as Overridable or Overrides can not be Private");
                                        ok = false;
                                }
@@ -1772,7 +1680,7 @@ namespace Mono.MonoBASIC {
                // and return the new level.
                static AccessLevel CheckAccessLevel (AccessLevel level, int flags)
                {
-                       AccessLevel old_level = level;
+                       //AccessLevel old_level = level;
 
                        if ((flags & Modifiers.INTERNAL) != 0) {
                                if ((flags & Modifiers.PROTECTED) != 0) {
@@ -1953,7 +1861,7 @@ namespace Mono.MonoBASIC {
                        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;
 
@@ -1963,7 +1871,24 @@ namespace Mono.MonoBASIC {
                                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);
                }
 
                //
@@ -1990,7 +1915,7 @@ namespace Mono.MonoBASIC {
                        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;
                        
@@ -2002,8 +1927,12 @@ namespace Mono.MonoBASIC {
                        this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
 
                        this.ModFlags |= Modifiers.SEALED;
-                       this.attributes = attrs;
-                       
+               }
+
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Struct;
+                       }
                }
 
                //
@@ -2093,80 +2022,6 @@ namespace Mono.MonoBASIC {
                        
                        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);
-
-                                       if (p [i].ParameterInitializer != null) {
-                                               if (p [i].ParameterInitializer is MemberAccess) {
-                                                       MemberAccess ma = p [i].ParameterInitializer as MemberAccess;
-
-                                                       Expression const_ex = ma.Resolve(ec);
-                                                       if (const_ex is EnumConstant)
-                                                               pb.SetConstant (((EnumConstant) const_ex).Child.GetValue());
-                                                       else
-                                                               Report.Error(-1,
-                                                                       "Internal error - Non supported argument type in optional parameter");
-                                               }
-                                               else
-                                                       pb.SetConstant (((Constant) p [i].ParameterInitializer).GetValue());
-                                       }
-
-                                       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 {
@@ -2207,7 +2062,13 @@ namespace Mono.MonoBASIC {
                { 
                        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
@@ -2341,7 +2202,7 @@ namespace Mono.MonoBASIC {
                                                WarningNotHiding (parent);*/
 
                                        if ((ModFlags & Modifiers.OVERRIDE) != 0){
-                                               Report.Error (30284, Location,
+                                               Report.Error (30398, Location,
                                                              parent.MakeName (Name) +
                                                              " : No suitable methods found to override");
                                        }
@@ -2429,6 +2290,11 @@ namespace Mono.MonoBASIC {
                {
                        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 {
@@ -2549,7 +2415,6 @@ namespace Mono.MonoBASIC {
        public class Constructor : MethodCore {
                public ConstructorBuilder ConstructorBuilder;
                public ConstructorInitializer Initializer;
-               new public Attributes OptAttributes;
 
                // <summary>
                //   Modifiers allowed for a constructor.
@@ -2579,6 +2444,17 @@ namespace Mono.MonoBASIC {
                        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
                //
@@ -2703,7 +2579,7 @@ namespace Mono.MonoBASIC {
                                ec.IsStatic = false;
                        }
 
-                       LabelParameters (ec, ParameterTypes, ConstructorBuilder);
+                       Parameters.LabelParameters (ec, ConstructorBuilder, Location);
                        
                        //
                        // Classes can have base initializers and instance field initializers.
@@ -2725,7 +2601,8 @@ namespace Mono.MonoBASIC {
                        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.
@@ -2756,11 +2633,11 @@ namespace Mono.MonoBASIC {
                //
                // 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;
@@ -2964,33 +2841,29 @@ namespace Mono.MonoBASIC {
                        bool IsImplementing = false;
                        Type current_iface_type = iface_type;
 
-                               if (member is Indexer)
-                                       implementing = parent.Pending.IsAbstractIndexer (
-                                       current_iface_type , ReturnType, ParameterTypes);
-                               else
-                                       implementing = parent.Pending.IsAbstractMethod (
-                                       current_iface_type, method_name, ReturnType, ParameterTypes);
+                       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;
+                       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);
+                               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;
-                                       }
+                                       if (IsImplementing)
+                                               break;
                                }
+                       }
 
                        return IsImplementing;
                }
@@ -3018,10 +2891,6 @@ namespace Mono.MonoBASIC {
                        if ((member.ModFlags & Modifiers.OVERRIDE) != 0) {
                                if (parent.Pending == null)
                                        implementing = null;
-                               else if (member is Indexer)
-                                       implementing = parent.Pending.IsAbstractIndexer (
-                                               (Type) parent.TypeBuilder.BaseType, 
-                                               ReturnType, ParameterTypes);
                                else
                                        implementing = parent.Pending.IsAbstractMethod (
                                                (Type) parent.TypeBuilder.BaseType, name, 
@@ -3136,12 +3005,14 @@ namespace Mono.MonoBASIC {
                                // implement abstract methods from abstract classes
                                //
                                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,
@@ -3154,12 +3025,15 @@ namespace Mono.MonoBASIC {
                                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,
@@ -3204,7 +3078,7 @@ namespace Mono.MonoBASIC {
                                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
@@ -3316,7 +3190,6 @@ namespace Mono.MonoBASIC {
 
        abstract public class MemberBase : MemberCore {
                public Expression Type;
-               public readonly Attributes OptAttributes;
                public ArrayList Implements;
 
                protected MethodAttributes flags;
@@ -3363,11 +3236,10 @@ namespace Mono.MonoBASIC {
                //
                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.PUBLIC, loc);
-                       OptAttributes = attrs;
                }
 
                protected virtual bool CheckBase (TypeContainer parent)
@@ -3386,16 +3258,10 @@ namespace Mono.MonoBASIC {
                                if (parent.AsAccessible (partype, ModFlags))
                                        continue;
 
-                               if (this is Indexer)
-                                       Report.Error (55, Location,
-                                                     "Inconsistent accessibility: parameter type `" +
-                                                     TypeManager.MonoBASIC_Name (partype) + "' is less " +
-                                                     "accessible than indexer `" + Name + "'");
-                               else
-                                       Report.Error (51, Location,
-                                                     "Inconsistent accessibility: parameter type `" +
-                                                     TypeManager.MonoBASIC_Name (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;
                        }
 
@@ -3464,13 +3330,8 @@ namespace Mono.MonoBASIC {
                                                      "Inconsistent accessibility: property type `" +
                                                      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.MonoBASIC_Name (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.MonoBASIC_Name (MemberType) + "' is less " +
                                                      "accessible than method `" + Name + "'");
@@ -3521,6 +3382,13 @@ namespace Mono.MonoBASIC {
                        this.init = init;
                }
 
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Field;
+                       }
+               }
+
+
                //
                // Whether this field has an initializer.
                //
@@ -3585,6 +3453,12 @@ namespace Mono.MonoBASIC {
                {
                }
 
+               public override AttributeTargets AttributeTargets {
+                       get {
+                               return AttributeTargets.Field;
+                       }
+               }
+
                public override bool Define (TypeContainer parent)
                {
                        Type t = parent.ResolveType (Type, false, Location);
@@ -3684,8 +3558,15 @@ namespace Mono.MonoBASIC {
                        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);
+               }
+               
        }
 
        //
@@ -3705,25 +3586,167 @@ namespace Mono.MonoBASIC {
                }
        }
 
-       //
-       // 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;
+                       get_params = p_get;
+                       Location = loc;
+               }               
+               
+               public MethodBuilder Define (TypeContainer parent)
+               {
+                       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));
+                       }
+
+                       GetData = new MethodData (parent_property, "get", parent_property.MemberType,
+                                                 g_parameters, g_ip, CallingConventions.Standard,
+                                                 Get.OptAttributes, parent_property.ModFlags, parent_property.MethodAttributeFlags, false);
+
+                       if (!GetData.Define (parent))
+                                       return null;
+
+                       GetBuilder = GetData.MethodBuilder;
+                       
+                       return GetBuilder;
+               }
+
+               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)
@@ -3777,8 +3800,10 @@ namespace Mono.MonoBASIC {
                        if ((ModFlags & Modifiers.READONLY) != 0)
                                retval = MemberType;
 
-                       string report_name;
+                       //string report_name;
                        MethodSignature base_ms;
+                       
+                       /*
                        if (this is Indexer) {
                                string name, base_name;
 
@@ -3787,8 +3812,8 @@ namespace Mono.MonoBASIC {
                                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;
+                       } else */ {
+                               //report_name = Name;
                                ms = base_ms = new MethodSignature (Name, retval, ParameterTypes);
                        }
 
@@ -3815,7 +3840,6 @@ namespace Mono.MonoBASIC {
                                MethodSignature.inheritable_property_signature_filter,
                                base_ms);
 
-
                        if (mi_instance.Count > 0)
                                mi = mi_instance;
                        else if (mi_static.Count > 0)
@@ -3863,11 +3887,14 @@ namespace Mono.MonoBASIC {
                                        WarningNotHiding (container);
                                */
                                if ((ModFlags & Modifiers.OVERRIDE) != 0) {
+
+                                       /*
                                        if (this is Indexer)
                                                Report.Error (115, Location,
                                                        container.MakeName (Name) +
                                                        " no suitable indexers found to override");
                                        else
+                                       */
                                                Report.Error (115, Location,
                                                        container.MakeName (Name) +
                                                        " no suitable properties found to override");
@@ -3892,26 +3919,7 @@ namespace Mono.MonoBASIC {
                        return true;
                }
 
-               public virtual 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 |
@@ -3922,7 +3930,7 @@ namespace Mono.MonoBASIC {
                        Modifiers.SEALED |
                        Modifiers.OVERRIDE |
                        Modifiers.ABSTRACT |
-                   Modifiers.UNSAFE |
+                       Modifiers.UNSAFE |
                        Modifiers.EXTERN |
                        Modifiers.VIRTUAL |
                        Modifiers.NONVIRTUAL |
@@ -3939,13 +3947,15 @@ namespace Mono.MonoBASIC {
                                Accessor get_block, Accessor set_block,
                                Attributes attrs, Location loc, string set_name, 
                                Parameters p_get, Parameters p_set, ArrayList impl_what)
-                       : base (type, name, mod_flags, AllowedModifiers,
-                               p_set,
-                               get_block, set_block, attrs, loc)
+                       : 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;
                }               
                
@@ -3959,10 +3969,10 @@ namespace Mono.MonoBASIC {
 
                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 " +
@@ -3976,43 +3986,15 @@ namespace Mono.MonoBASIC {
 
                        flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
 
-                       if (Get == null) {
+                       if (GetMethod == null) {
                                if ((ModFlags & Modifiers.WRITEONLY) == 0)
                                        Report.Error (
                                                30124, Location,
                                                "Property without 'Get' accessor must have a 'WriteOnly' modifier");
-                       }
-                       else {
-                               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;
-                       }
+                       } else
+                               GetBuilder = GetMethod.Define (parent);
 
-                       if (Set == null) {
+                       if (SetMethod== null) {
                                if ((ModFlags & Modifiers.READONLY) == 0)
                                        Report.Error (
                                                30124, Location,
@@ -4020,43 +4002,7 @@ namespace Mono.MonoBASIC {
                                                
                        }
                        else 
-                       {
-                               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, 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;
-
-                               SetBuilder = SetData.MethodBuilder;
-                               SetBuilder.DefineParameter (1, ParameterAttributes.None, 
-                                       set_parameter_name); 
-                       }
+                               SetBuilder = SetMethod.Define (parent);
 
                        // FIXME - PropertyAttributes.HasDefault ?
                        
@@ -4086,23 +4032,34 @@ namespace Mono.MonoBASIC {
                        return true;
                }
 
-               public override void Emit (TypeContainer tc)
+               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) 
+                       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) 
+                       if (SetMethod != null) 
                        {
-                               Parameters = set_params;
-                               SetData.Emit (tc, Set.Block, Set);
+                               SetMethod.Emit (tc);
                        }
-                               
                }
+
+               public MethodAttributes MethodAttributeFlags {
+                       get {
+                               return flags;
+                       }
+               }
+
        }
 
        /// </summary>
@@ -4239,6 +4196,98 @@ namespace Mono.MonoBASIC {
                        }
                }
        }
+
+       
+       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 =
@@ -4254,32 +4303,41 @@ namespace Mono.MonoBASIC {
                        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)
-                       : base (type, mod, AllowedModifiers, name, init, attrs, loc)
+               public Event (Expression type, string name, Object init, int mod, Attributes attrs, 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 = null;
                }
 
-               public Event (Expression type, string name, Object init, int mod, Accessor add,
-                       Accessor remove, Attributes attrs, ArrayList impl_what, Location loc)
+               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;
@@ -4298,58 +4356,34 @@ namespace Mono.MonoBASIC {
 
                        Parameter [] parms = new Parameter [1];
                        parms [0] = new Parameter (Type, /* was "value" */ this.Name, Parameter.Modifier.NONE, null);
-                       InternalParameters ip = new InternalParameters (
+                       /*InternalParameters ip = new InternalParameters (
                                parent, new Parameters (parms, null, Location)); 
+                       */
 
                        if (!CheckBase (parent))
                                return false;
 
-                       //
-                       // 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;
                                }
                        }
@@ -4357,7 +4391,7 @@ namespace Mono.MonoBASIC {
                        return true;
                }
 
-               void EmitDefaultMethod (EmitContext ec, bool is_add)
+               public void EmitDefaultMethod (EmitContext ec, bool is_add)
                {
                        ILGenerator ig = ec.ig;
                        MethodInfo method = null;
@@ -4390,211 +4424,20 @@ namespace Mono.MonoBASIC {
                        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 (OptAttributes != null)
+                               OptAttributes.Emit (ec, this);
 
-                       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);
-                       }
+                       Add.Emit (tc);
+                       Remove.Emit (tc);
                }
-               
-       }
-
-       //
-       // 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);
+               public MethodAttributes MethodAttributeFlags {
+                       get {
+                               return flags;
                        }
-
-                       return true;
                }
+               
        }
 
        struct MethodSignature {