2009-01-29 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / class.cs
index f68cac5ad8bba0c03a223ae89a71f1343852a84d..d43800a097a2d65a99f2e371a5e6df7a2852a21a 100644 (file)
@@ -182,7 +182,7 @@ namespace Mono.CSharp {
                protected MemberCoreArrayList instance_constructors;
 
                // Holds the list of fields
-               MemberCoreArrayList fields;
+               protected MemberCoreArrayList fields;
 
                // Holds a list of fields that have initializers
                protected ArrayList initialized_fields;
@@ -246,6 +246,7 @@ namespace Mono.CSharp {
 
                private bool seen_normal_indexers = false;
                private string indexer_name = DefaultIndexerName;
+               protected bool requires_delayed_unmanagedtype_check;
 
                private CachedMethods cached_method;
 
@@ -405,7 +406,7 @@ namespace Mono.CSharp {
 
                }
                
-               public void AddMethod (Method method)
+               public void AddMethod (MethodOrOperator method)
                {
                        if (!AddToContainer (method, method.MemberName.Basename))
                                return;
@@ -1144,12 +1145,6 @@ namespace Mono.CSharp {
 
                protected virtual bool DoResolveType ()
                {
-                       if ((base_type != null) &&
-                           (base_type.ResolveAsTypeTerminal (this, false) == null)) {
-                               error = true;
-                               return false;
-                       }
-
                        if (!IsGeneric)
                                return true;
 
@@ -1331,6 +1326,14 @@ namespace Mono.CSharp {
 
                        if (Kind == Kind.Struct || Kind == Kind.Class) {
                                pending = PendingImplementation.GetPendingImplementations (this);
+
+                               if (requires_delayed_unmanagedtype_check) {
+                                       requires_delayed_unmanagedtype_check = false;
+                                       foreach (Field f in fields) {
+                                               if (f.MemberType != null && f.MemberType.IsPointer)
+                                                       TypeManager.VerifyUnManaged (f.MemberType, f.Location);
+                                       }
+                               }
                        }
                
                        //
@@ -1711,7 +1714,7 @@ namespace Mono.CSharp {
                                if (methods != null) {
                                        int len = methods.Count;
                                        for (int i = 0; i < len; i++) {
-                                               Method m = (Method) methods [i];
+                                               MethodOrOperator m = (MethodOrOperator) methods [i];
                                                
                                                if ((m.ModFlags & modflags) == 0)
                                                        continue;
@@ -1912,7 +1915,7 @@ namespace Mono.CSharp {
                                                if (cb != null && filter (cb, criteria) == true) {
                                                        if (members == null)
                                                                members = new ArrayList ();
-                                                       
+
                                                        members.Add (cb);
                                                }
                                        }
@@ -2133,7 +2136,7 @@ namespace Mono.CSharp {
 
                        if (methods != null) {
                                for (int i = 0; i < methods.Count; ++i)
-                                       ((Method) methods [i]).Emit ();
+                                       ((MethodOrOperator) methods [i]).Emit ();
                        }
                        
                        if (fields != null)
@@ -2576,12 +2579,12 @@ namespace Mono.CSharp {
                        }
 
                        Constructor c = new Constructor (this, MemberName.Name, mods,
-                               null, Parameters.EmptyReadOnlyParameters,
+                               null, ParametersCompiled.EmptyReadOnlyParameters,
                                new GeneratedBaseInitializer (Location),
                                Location);
                        
                        AddConstructor (c);
-                       c.Block = new ToplevelBlock (null, Location);
+                       c.Block = new ToplevelBlock (ParametersCompiled.EmptyReadOnlyParameters, Location);
                }
 
                public override bool Define ()
@@ -2807,7 +2810,7 @@ namespace Mono.CSharp {
                                                Report.Error (709, Location, "`{0}': Cannot derive from static class `{1}'",
                                                        GetSignatureForError (), TypeManager.CSharpName (base_class.Type));
                                        } else {
-                                               Report.Error (509, Location, "`{0}': cannot derive from sealed class `{1}'",
+                                               Report.Error (509, Location, "`{0}': cannot derive from sealed type `{1}'",
                                                        GetSignatureForError (), TypeManager.CSharpName (base_class.Type));
                                        }
                                        return ifaces;
@@ -2945,6 +2948,41 @@ namespace Mono.CSharp {
                        }
                }
 
+               public override bool IsUnmanagedType ()
+               {
+                       if (fields == null)
+                               return true;
+
+                       if (requires_delayed_unmanagedtype_check)
+                               return true;
+
+                       foreach (FieldBase f in fields) {
+                               if ((f.ModFlags & Modifiers.STATIC) != 0)
+                                       continue;
+
+                               // It can happen when recursive unmanaged types are defined
+                               // struct S { S* s; }
+                               Type mt = f.MemberType;
+                               if (mt == null) {
+                                       requires_delayed_unmanagedtype_check = true;
+                                       return true;
+                               }
+
+                               // TODO: Remove when pointer types are under mcs control
+                               while (mt.IsPointer)
+                                       mt = TypeManager.GetElementType (mt);
+                               if (TypeManager.IsEqual (mt, TypeBuilder))
+                                       continue;
+
+                               if (TypeManager.IsUnmanagedType (mt))
+                                       continue;
+
+                               return false;
+                       }
+
+                       return true;
+               }
+
                protected override TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
                {
                        TypeExpr[] ifaces = base.ResolveBaseTypes (out base_class);
@@ -3097,12 +3135,12 @@ namespace Mono.CSharp {
 
        public abstract class MethodCore : InterfaceMemberBase
        {
-               public readonly Parameters Parameters;
+               public readonly ParametersCompiled Parameters;
                protected ToplevelBlock block;
 
                public MethodCore (DeclSpace parent, GenericMethod generic,
                        FullNamedExpression type, int mod, int allowed_mod,
-                       MemberName name, Attributes attrs, Parameters parameters)
+                       MemberName name, Attributes attrs, ParametersCompiled parameters)
                        : base (parent, generic, type, mod, allowed_mod, name, attrs)
                {
                        Parameters = parameters;
@@ -3117,8 +3155,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               public Parameters ParameterInfo
-               {
+               public ParametersCompiled ParameterInfo {
                        get {
                                return Parameters;
                        }
@@ -3324,7 +3361,7 @@ namespace Mono.CSharp {
                protected virtual bool CheckForDuplications ()
                {
                        return Parent.MemberCache.CheckExistingMembersOverloads (
-                               this, GetFullName (MemberName), Parameters.EmptyReadOnlyParameters);
+                               this, GetFullName (MemberName), ParametersCompiled.EmptyReadOnlyParameters);
                }
 
                //
@@ -3340,6 +3377,7 @@ namespace Mono.CSharp {
 
                        if ((ModFlags & Modifiers.OVERRIDE) != 0){
                                if (!(base_method.IsAbstract || base_method.IsVirtual)){
+                                       Report.SymbolRelatedToPreviousError (base_method);
                                        Report.Error (506, Location,
                                                "`{0}': cannot override inherited member `{1}' because it is not marked virtual, abstract or override",
                                                 GetSignatureForError (), TypeManager.CSharpSignature (base_method));
@@ -3380,7 +3418,7 @@ namespace Mono.CSharp {
                        }
 
                        if ((ModFlags & Modifiers.NEW) == 0) {
-                               if ((ModFlags & Modifiers.OVERRIDE) == 0 && Name != "Finalize") {
+                               if ((ModFlags & Modifiers.OVERRIDE) == 0) {
                                        ModFlags |= Modifiers.NEW;
                                        Report.SymbolRelatedToPreviousError (base_method);
                                        if (!IsInterface && (base_method.IsVirtual || base_method.IsAbstract)) {
@@ -3437,39 +3475,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               protected bool DefineParameters (Parameters parameters)
-               {
-                       IResolveContext rc = GenericMethod == null ? this : (IResolveContext)ds;
-
-                       if (!parameters.Resolve (rc))
-                               return false;
-
-                       bool error = false;
-                       for (int i = 0; i < parameters.Count; ++i) {
-                               Parameter p = parameters [i];
-                               if (p.CheckAccessibility (this))
-                                       continue;
-
-                               Type t = parameters.Types [i];
-                               Report.SymbolRelatedToPreviousError (t);
-                               if (this is Indexer)
-                                       Report.Error (55, Location,
-                                                     "Inconsistent accessibility: parameter type `{0}' is less accessible than indexer `{1}'",
-                                                     TypeManager.CSharpName (t), GetSignatureForError ());
-                               else if (this is Operator)
-                                       Report.Error (57, Location,
-                                                     "Inconsistent accessibility: parameter type `{0}' is less accessible than operator `{1}'",
-                                                     TypeManager.CSharpName (t), GetSignatureForError ());
-                               else
-                                       Report.Error (51, Location,
-                                               "Inconsistent accessibility: parameter type `{0}' is less accessible than method `{1}'",
-                                               TypeManager.CSharpName (t), GetSignatureForError ());
-                               error = true;
-                       }
-                       return !error;
-               }
-
-               protected bool DoDefineBase ()
+               public override bool Define ()
                {
                        if (IsInterface) {
                                ModFlags = Modifiers.PUBLIC | Modifiers.ABSTRACT |
@@ -3481,8 +3487,7 @@ namespace Mono.CSharp {
                                        MethodAttributes.NewSlot |
                                        MethodAttributes.Virtual;
                        } else {
-                               if (!Parent.PartialContainer.MethodModifiersValid (this))
-                                       return false;
+                               Parent.PartialContainer.MethodModifiersValid (this);
 
                                flags = Modifiers.MethodAttr (ModFlags);
                        }
@@ -3506,11 +3511,43 @@ namespace Mono.CSharp {
                                } else {
                                        Parent.PartialContainer.VerifyImplements (this);
                                }
-                               
+
                                Modifiers.Check (Modifiers.AllowedExplicitImplFlags, explicit_mod_flags, 0, Location);
                        }
 
-                       return true;
+                       return base.Define ();
+               }
+
+               protected bool DefineParameters (ParametersCompiled parameters)
+               {
+                       IResolveContext rc = GenericMethod == null ? this : (IResolveContext)ds;
+
+                       if (!parameters.Resolve (rc))
+                               return false;
+
+                       bool error = false;
+                       for (int i = 0; i < parameters.Count; ++i) {
+                               Parameter p = parameters [i];
+                               if (p.CheckAccessibility (this))
+                                       continue;
+
+                               Type t = parameters.Types [i];
+                               Report.SymbolRelatedToPreviousError (t);
+                               if (this is Indexer)
+                                       Report.Error (55, Location,
+                                                     "Inconsistent accessibility: parameter type `{0}' is less accessible than indexer `{1}'",
+                                                     TypeManager.CSharpName (t), GetSignatureForError ());
+                               else if (this is Operator)
+                                       Report.Error (57, Location,
+                                                     "Inconsistent accessibility: parameter type `{0}' is less accessible than operator `{1}'",
+                                                     TypeManager.CSharpName (t), GetSignatureForError ());
+                               else
+                                       Report.Error (51, Location,
+                                               "Inconsistent accessibility: parameter type `{0}' is less accessible than method `{1}'",
+                                               TypeManager.CSharpName (t), GetSignatureForError ());
+                               error = true;
+                       }
+                       return !error;
                }
 
                public override void Emit()
@@ -3634,7 +3671,7 @@ namespace Mono.CSharp {
 
                protected MethodOrOperator (DeclSpace parent, GenericMethod generic, FullNamedExpression type, int mod,
                                int allowed_mod, MemberName name,
-                               Attributes attrs, Parameters parameters)
+                               Attributes attrs, ParametersCompiled parameters)
                        : base (parent, generic, type, mod, allowed_mod, name,
                                        attrs, parameters)
                {
@@ -3694,35 +3731,24 @@ namespace Mono.CSharp {
                                this, tc, this.ds, Location, ig, MemberType, ModFlags, false);
                }
 
-               public override bool Define ()
+               protected override bool ResolveMemberType ()
                {
-                       if (!DoDefineBase ())
-                               return false;
-
 #if GMCS_SOURCE
                        if (GenericMethod != null) {
                                MethodBuilder = Parent.TypeBuilder.DefineMethod (GetFullName (MemberName), flags);
-                               if (!GenericMethod.Define (MethodBuilder))
+                               if (!GenericMethod.Define (this))
                                        return false;
                        }
 #endif
 
-                       if (!DoDefine ())
-                               return false;
+                       return base.ResolveMemberType ();
+               }
 
-                       if (!CheckAbstractAndExtern (block != null))
+               public override bool Define ()
+               {
+                       if (!base.Define ())
                                return false;
 
-                       if ((ModFlags & Modifiers.PARTIAL) != 0) {
-                               for (int i = 0; i < Parameters.Count; ++i ) {
-                                       if (Parameters.FixedParameters [i].ModFlags == Parameter.Modifier.OUT) {
-                                               Report.Error (752, Location, "`{0}': A partial method parameters cannot use `out' modifier",
-                                                       GetSignatureForError ());
-                                               return false;
-                                       }
-                               }
-                       }
-
                        if (!CheckBase ())
                                return false;
 
@@ -3763,14 +3789,35 @@ namespace Mono.CSharp {
                        
                        Parent.MemberCache.AddMember (MethodBuilder, this);
 
+                       return true;
+               }
+
+               protected override void DoMemberTypeIndependentChecks ()
+               {
+                       base.DoMemberTypeIndependentChecks ();
+
+                       CheckAbstractAndExtern (block != null);
+
+                       if ((ModFlags & Modifiers.PARTIAL) != 0) {
+                               for (int i = 0; i < Parameters.Count; ++i) {
+                                       if (Parameters.FixedParameters[i].ModFlags == Parameter.Modifier.OUT) {
+                                               Report.Error (752, Location, "`{0}': A partial method parameters cannot use `out' modifier",
+                                                       GetSignatureForError ());
+                                               break;
+                                       }
+                               }
+                       }
+               }
+
+               protected override void DoMemberTypeDependentChecks ()
+               {
+                       base.DoMemberTypeDependentChecks ();
+
                        if (!TypeManager.IsGenericParameter (MemberType)) {
                                if (MemberType.IsAbstract && MemberType.IsSealed) {
                                        Report.Error (722, Location, Error722, TypeManager.CSharpName (MemberType));
-                                       return false;
                                }
                        }
-
-                       return true;
                }
 
                public override void Emit ()
@@ -3790,7 +3837,13 @@ namespace Mono.CSharp {
                                }
                        }
 
+                       if (MethodData != null)
+                               MethodData.Emit (Parent);
+
                        base.Emit ();
+
+                       Block = null;
+                       MethodData = null;
                }
 
                protected void Error_ConditionalAttributeIsNotValid ()
@@ -3845,21 +3898,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               protected override bool CheckBase ()
-               {
-                       if (!base.CheckBase ())
-                               return false;
-
-                       // TODO: Destructor should derive from MethodCore
-                       if (base_method != null && (ModFlags & Modifiers.OVERRIDE) != 0 && Name == "Finalize" &&
-                               base_method.DeclaringType == TypeManager.object_type && !(this is Destructor)) {
-                               Report.Error (249, Location, "Do not override object.Finalize. Instead, provide a destructor");
-                               return false;
-                       }
-
-                       return true;
-               }
-
                /// <summary>
                /// Returns true if method has conditional attribute and the conditions is not defined (method is excluded).
                /// </summary>
@@ -4004,7 +4042,7 @@ namespace Mono.CSharp {
 
                public Method (DeclSpace parent, GenericMethod generic,
                               FullNamedExpression return_type, int mod,
-                              MemberName name, Parameters parameters, Attributes attrs)
+                              MemberName name, ParametersCompiled parameters, Attributes attrs)
                        : base (parent, generic, return_type, mod,
                                parent.PartialContainer.Kind == Kind.Interface ? AllowedInterfaceModifiers : AllowedModifiers,
                                name, attrs, parameters)
@@ -4012,7 +4050,7 @@ namespace Mono.CSharp {
                }
 
                protected Method (DeclSpace parent, FullNamedExpression return_type, int mod, int amod,
-                                       MemberName name, Parameters parameters, Attributes attrs)
+                                       MemberName name, ParametersCompiled parameters, Attributes attrs)
                        : base (parent, null, return_type, mod, amod, name, attrs, parameters)
                {
                }
@@ -4022,11 +4060,11 @@ namespace Mono.CSharp {
                        return base.GetSignatureForError () + Parameters.GetSignatureForError ();
                }
 
-               void Error_DuplicateEntryPoint (MethodInfo b, Location location)
+               static void Error_DuplicateEntryPoint (Method b)
                {
-                       Report.Error (17, location,
+                       Report.Error (17, b.Location,
                                "Program `{0}' has more than one entry point defined: `{1}'",
-                               CodeGen.FileName, TypeManager.CSharpSignature(b));
+                               CodeGen.FileName, b.GetSignatureForError ());
                }
 
                bool IsEntryPoint ()
@@ -4119,11 +4157,28 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               protected override bool CheckBase ()
+               {
+                       if (!base.CheckBase ())
+                               return false;
+
+                       if (base_method != null && (ModFlags & Modifiers.OVERRIDE) != 0 && Name == Destructor.MetadataName) {
+                               Report.Error (249, Location, "Do not override `{0}'. Use destructor syntax instead",
+                                       TypeManager.CSharpSignature (base_method));
+                       }
+
+                       return true;
+               }
+
                //
                // Creates the type
                //
                public override bool Define ()
                {
+                       if (type_name == TypeManager.system_void_expr && Parameters.IsEmpty && Name == Destructor.MetadataName) {
+                               Report.Warning (465, 1, Location, "Introducing `Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor?");
+                       }
+
                        if (!base.Define ())
                                return false;
 
@@ -4132,11 +4187,6 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       if (ReturnType == TypeManager.void_type && Parameters.Count == 0 && 
-                               Name == "Finalize" && !(this is Destructor)) {
-                               Report.Warning (465, 1, Location, "Introducing a 'Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor?");
-                       }
-
                        if (base_method != null && (ModFlags & Modifiers.NEW) == 0) {
                                if (Parameters.Count == 1 && ParameterTypes [0] == TypeManager.object_type && Name == "Equals")
                                        Parent.PartialContainer.Mark_HasEquals ();
@@ -4188,15 +4238,12 @@ namespace Mono.CSharp {
                                                        Report.Warning (402, 4, Location, "`{0}': an entry point cannot be generic or in a generic type",
                                                                GetSignatureForError ());
                                                } else {
-                                                       IMethodData md = TypeManager.GetMethod (MethodBuilder);
-                                                       md.SetMemberIsUsed ();
-
-                                                       RootContext.EntryPoint = MethodBuilder;
-                                                       RootContext.EntryPointLocation = Location;
+                                                       SetMemberIsUsed ();
+                                                       RootContext.EntryPoint = this;
                                                }
                                        } else {
-                                               Error_DuplicateEntryPoint (RootContext.EntryPoint, RootContext.EntryPointLocation);
-                                               Error_DuplicateEntryPoint (MethodBuilder, Location);
+                                               Error_DuplicateEntryPoint (RootContext.EntryPoint);
+                                               Error_DuplicateEntryPoint (this);
                                        }
                                } else {
                                        Report.Warning (28, 4, Location, "`{0}' has the wrong signature to be an entry point",
@@ -4228,7 +4275,6 @@ namespace Mono.CSharp {
                                        Report.Error (759, Location, "A partial method `{0}' implementation is missing a partial method declaration",
                                                GetSignatureForError ());
 
-                               MethodData.Emit (Parent);
                                base.Emit ();
                                
 #if GMCS_SOURCE                                
@@ -4236,8 +4282,6 @@ namespace Mono.CSharp {
                                        MethodBuilder.SetCustomAttribute (TypeManager.extension_attribute_attr);
 #endif
 
-                               Block = null;
-                               MethodData = null;
                        } catch {
                                Console.WriteLine ("Internal compiler error at {0}: exception caught while emitting {1}",
                                                   Location, MethodBuilder);
@@ -4296,7 +4340,7 @@ namespace Mono.CSharp {
                        if (!base.VerifyClsCompliance ())
                                return false;
 
-                       if (ParameterInfo.Count > 0) {
+                       if (!Parameters.IsEmpty) {
                                ArrayList al = (ArrayList)Parent.PartialContainer.MemberCache.Members [Name];
                                if (al.Count > 1)
                                        MemberCache.VerifyClsParameterConflict (al, this, MethodBuilder);
@@ -4342,7 +4386,7 @@ namespace Mono.CSharp {
                                        return true;
 
                                type = ec.ContainerType.BaseType;
-                               if (ec.ContainerType.IsValueType) {
+                               if (TypeManager.IsStruct (ec.ContainerType)) {
                                        Report.Error (522, loc,
                                                "`{0}': Struct constructors cannot call base constructors", TypeManager.CSharpSignature (caller_builder));
                                        return false;
@@ -4354,7 +4398,7 @@ namespace Mono.CSharp {
                                //
                                // struct D { public D (int a) : this () {}
                                //
-                               if (ec.ContainerType.IsValueType && argument_list == null)
+                               if (TypeManager.IsStruct (ec.ContainerType) && argument_list == null)
                                        return true;
                                
                                type = ec.ContainerType;
@@ -4452,7 +4496,7 @@ namespace Mono.CSharp {
                // The spec claims that static is not permitted, but
                // my very own code has static constructors.
                //
-               public Constructor (DeclSpace parent, string name, int mod, Attributes attrs, Parameters args,
+               public Constructor (DeclSpace parent, string name, int mod, Attributes attrs, ParametersCompiled args,
                                    ConstructorInitializer init, Location loc)
                        : base (parent, null, null, mod, AllowedModifiers,
                                new MemberName (name, loc), attrs, args)
@@ -4576,7 +4620,6 @@ namespace Mono.CSharp {
                                if (!IsDefault ()) {
                                        Report.Error (669, Location, "`{0}': A class with the ComImport attribute cannot have a user-defined constructor",
                                                Parent.GetSignatureForError ());
-                                       return false;
                                }
                                ConstructorBuilder.SetImplementationFlags (MethodImplAttributes.InternalCall);
                        }
@@ -4625,7 +4668,7 @@ namespace Mono.CSharp {
                                        ((ModFlags & Modifiers.STATIC) == 0) && (Initializer == null))
                                        block.AddThisVariable (Parent, Location);
 
-                               if (!block.ResolveMeta (ec, ParameterInfo))
+                               if (!block.ResolveMeta (ec, Parameters))
                                        block = null;
 
                                if (block != null && (ModFlags & Modifiers.STATIC) == 0){
@@ -4654,7 +4697,7 @@ namespace Mono.CSharp {
 
                        bool unreachable = false;
                        if (block != null) {
-                               if (!ec.ResolveTopBlock (null, block, ParameterInfo, this, out unreachable))
+                               if (!ec.ResolveTopBlock (null, block, Parameters, this, out unreachable))
                                        return;
 
                                ec.EmitMeta (block);
@@ -4700,8 +4743,8 @@ namespace Mono.CSharp {
                                return false;
                        }
                        
-                       if (ParameterInfo.Count > 0) {
-                               ArrayList al = (ArrayList)Parent.MemberCache.Members [".ctor"];
+                       if (!Parameters.IsEmpty) {
+                               ArrayList al = (ArrayList)Parent.MemberCache.Members [ConstructorInfo.ConstructorName];
                                if (al.Count > 2)
                                        MemberCache.VerifyClsParameterConflict (al, this, ConstructorBuilder);
  
@@ -4780,7 +4823,7 @@ namespace Mono.CSharp {
                MemberName MethodName { get; }
                Type ReturnType { get; }
                GenericMethod GenericMethod { get; }
-               Parameters ParameterInfo { get; }
+               ParametersCompiled ParameterInfo { get; }
 
                Attributes OptAttributes { get; }
                ToplevelBlock Block { get; set; }
@@ -4993,7 +5036,7 @@ namespace Mono.CSharp {
                                declaring_type = container.TypeBuilder;
 
                        if (implementing != null && member.IsExplicitImpl) {
-                               container.TypeBuilder.DefineMethodOverride (builder, implementing);
+                                       container.TypeBuilder.DefineMethodOverride (builder, implementing);
                        }
 
                        TypeManager.AddMethod (builder, method);
@@ -5017,7 +5060,7 @@ namespace Mono.CSharp {
                /// <summary>
                /// Create the MethodBuilder for the method 
                /// </summary>
-               void DefineMethodBuilder (TypeContainer container, string method_name, Parameters param)
+               void DefineMethodBuilder (TypeContainer container, string method_name, ParametersCompiled param)
                {
                        if (builder == null) {
                                builder = container.TypeBuilder.DefineMethod (
@@ -5075,77 +5118,31 @@ namespace Mono.CSharp {
 
                        SourceMethod source = SourceMethod.Create (parent, MethodBuilder, method.Block);
 
-                       //
-                       // Handle destructors specially
-                       //
-                       // FIXME: This code generates buggy code
-                       //
-                       if (member is Destructor)
-                               EmitDestructor (ec, block);
-                       else
-                               ec.EmitTopBlock (method, block);
+                       ec.EmitTopBlock (method, block);
 
                        if (source != null) {
                                method.EmitExtraSymbolInfo (source);
                                source.CloseMethod ();
                        }
                }
-
-               void EmitDestructor (EmitContext ec, ToplevelBlock block)
-               {
-                       ILGenerator ig = ec.ig;
-                       
-                       Label finish = ig.DefineLabel ();
-
-                       block.SetDestructor ();
-                       
-                       ig.BeginExceptionBlock ();
-                       ec.ReturnLabel = finish;
-                       ec.HasReturnLabel = true;
-                       ec.EmitTopBlock (method, block);
-                       
-                       // ig.MarkLabel (finish);
-                       ig.BeginFinallyBlock ();
-                       
-                       if (ec.ContainerType.BaseType != null) {
-                               Expression member_lookup = Expression.MemberLookup (
-                                       ec.ContainerType.BaseType, null, ec.ContainerType.BaseType,
-                                       "Finalize", MemberTypes.Method, Expression.AllBindingFlags, method.Location);
-
-                               if (member_lookup != null){
-                                       MethodGroupExpr base_destructor = ((MethodGroupExpr) member_lookup);
-                               
-                                       ig.Emit (OpCodes.Ldarg_0);
-                                       ig.Emit (OpCodes.Call, (MethodInfo) base_destructor.Methods [0]);
-                               }
-                       }
-                       
-                       ig.EndExceptionBlock ();
-                       //ig.MarkLabel (ec.ReturnLabel);
-                       ig.Emit (OpCodes.Ret);
-               }
        }
 
-       // TODO: Should derive from MethodCore
-       public class Destructor : Method
+       public class Destructor : MethodOrOperator
        {
                const int AllowedModifiers =
                        Modifiers.UNSAFE |
                        Modifiers.EXTERN;
 
-               static string[] attribute_targets = new string [] { "method" };
+               static readonly string[] attribute_targets = new string [] { "method" };
+
+               public static readonly string MetadataName = "Finalize";
 
-               public Destructor (DeclSpace parent, FullNamedExpression return_type, int mod,
-                                  string name, Parameters parameters, Attributes attrs,
-                                  Location l)
-                       : base (parent, return_type, mod, AllowedModifiers, new MemberName (name, l),
-                               parameters, attrs)
+               public Destructor (DeclSpace parent, int mod, ParametersCompiled parameters, Attributes attrs, Location l)
+                       : base (parent, null, TypeManager.system_void_expr, mod, AllowedModifiers,
+                               new MemberName (MetadataName, l), attrs, parameters)
                {
                        ModFlags &= ~Modifiers.PRIVATE;
-                       if (!RootContext.StdLib && parent.Name == "System.Object")
-                               ModFlags |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
-                       else
-                               ModFlags |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
+                       ModFlags |= Modifiers.PROTECTED;
                }
 
                public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
@@ -5158,11 +5155,55 @@ namespace Mono.CSharp {
                        base.ApplyAttributeBuilder (a, cb);
                }
 
+               protected override bool CheckBase ()
+               {
+                       flags |= MethodAttributes.Virtual;
+
+                       if (!base.CheckBase ())
+                               return false;
+
+                       if (Parent.PartialContainer.BaseCache == null)
+                               return true;
+
+                       Type base_type = Parent.PartialContainer.BaseCache.Container.Type;
+                       if (base_type != null && Block != null) {
+                               MethodGroupExpr method_expr = Expression.MethodLookup (Parent.TypeBuilder, base_type, MetadataName, Location);
+                               if (method_expr == null)
+                                       throw new NotImplementedException ();
+
+                               method_expr.IsBase = true;
+                               method_expr.InstanceExpression = new CompilerGeneratedThis (Parent.TypeBuilder, Location);
+
+                               ToplevelBlock new_block = new ToplevelBlock (Block.StartLocation);
+                               new_block.EndLocation = Block.EndLocation;
+
+                               Block finaly_block = new ExplicitBlock (new_block, Location, Location);
+                               Block try_block = new Block (new_block, block);
+
+                               //
+                               // 0-size arguments to avoid CS0250 error
+                               // TODO: Should use AddScopeStatement or something else which emits correct
+                               // debugger scope
+                               //
+                               finaly_block.AddStatement (new StatementExpression (new Invocation (method_expr, new ArrayList (0))));
+                               new_block.AddStatement (new TryFinally (try_block, finaly_block, Location));
+
+                               block = new_block;
+                       }
+
+                       return true;
+               }
+
                public override string GetSignatureForError ()
                {
                        return Parent.GetSignatureForError () + ".~" + Parent.MemberName.Name + "()";
                }
 
+               protected override MethodInfo FindOutBaseMethod (ref Type base_ret_type)
+               {
+                       return null;
+               }
+
                public override string[] ValidAttributeTargets {
                        get {
                                return attribute_targets;
@@ -5170,32 +5211,14 @@ namespace Mono.CSharp {
                }
        }
        
-       abstract public class MemberBase : MemberCore {
+       public abstract class MemberBase : MemberCore
+       {
                protected FullNamedExpression type_name;
+               protected Type member_type;
+
                public readonly DeclSpace ds;
                public readonly GenericMethod GenericMethod;
 
-               //
-               // The type of this property / indexer / event
-               //
-               protected Type member_type;
-               public Type MemberType {
-                       get {
-                               // TODO: Who wrote this, ResolveAsTypeTerminal can have side effects
-                               if (member_type == null && type_name != null) {
-                                       IResolveContext rc = GenericMethod == null ? this : (IResolveContext)ds;
-                                       type_name = type_name.ResolveAsTypeTerminal (rc, false);
-                                       if (type_name != null) {
-                                               member_type = type_name.Type;
-                                       }
-                               }
-                               return member_type;
-                       }
-               }
-
-               //
-               // The constructor is only exposed to our children
-               //
                protected MemberBase (DeclSpace parent, GenericMethod generic,
                                      FullNamedExpression type, int mod, int allowed_mod, int def_mod,
                                      MemberName name, Attributes attrs)
@@ -5209,25 +5232,40 @@ namespace Mono.CSharp {
                                GenericMethod.ModFlags = ModFlags;
                }
 
-               protected virtual bool CheckBase ()
+               //
+               // Main member define entry
+               //
+               public override bool Define ()
                {
-                       CheckProtectedModifier ();
+                       DoMemberTypeIndependentChecks ();
 
+                       //
+                       // Returns false only when type resolution failed
+                       //
+                       if (!ResolveMemberType ())
+                               return false;
+
+                       DoMemberTypeDependentChecks ();
                        return true;
                }
 
-               protected virtual bool DoDefine ()
+               //
+               // Any type_name independent checks
+               //
+               protected virtual void DoMemberTypeIndependentChecks ()
                {
-                       if (MemberType == null)
-                               return false;
-
-                       if ((Parent.ModFlags & Modifiers.SEALED) != 0 && 
-                               (ModFlags & (Modifiers.VIRTUAL|Modifiers.ABSTRACT)) != 0) {
-                                       Report.Error (549, Location, "New virtual member `{0}' is declared in a sealed class `{1}'",
-                                               GetSignatureForError (), Parent.GetSignatureForError ());
-                                       return false;
+                       if ((Parent.ModFlags & Modifiers.SEALED) != 0 &&
+                               (ModFlags & (Modifiers.VIRTUAL | Modifiers.ABSTRACT)) != 0) {
+                               Report.Error (549, Location, "New virtual member `{0}' is declared in a sealed class `{1}'",
+                                       GetSignatureForError (), Parent.GetSignatureForError ());
                        }
-                       
+               }
+
+               //
+               // Any type_name dependent checks
+               //
+               protected virtual void DoMemberTypeDependentChecks ()
+               {
                        // verify accessibility
                        if (!IsAccessibleAs (MemberType)) {
                                Report.SymbolRelatedToPreviousError (MemberType);
@@ -5258,10 +5296,7 @@ namespace Mono.CSharp {
                                                      TypeManager.CSharpName (MemberType) + "' is less " +
                                                      "accessible than field `" + GetSignatureForError () + "'");
                                }
-                               return false;
                        }
-
-                       return true;
                }
 
                protected bool IsTypePermitted ()
@@ -5272,6 +5307,36 @@ namespace Mono.CSharp {
                        }
                        return true;
                }
+
+               protected virtual bool CheckBase ()
+               {
+                       CheckProtectedModifier ();
+
+                       return true;
+               }
+
+               public Type MemberType {
+                       get { return member_type; }
+               }
+
+               protected virtual bool ResolveMemberType ()
+               {
+                       if (member_type != null)
+                               throw new InternalErrorException ("Multi-resolve");
+
+                       IResolveContext rc = GenericMethod == null ? this : (IResolveContext) ds;
+                       TypeExpr te = type_name.ResolveAsTypeTerminal (rc, false);
+                       if (te == null)
+                               return false;
+
+                       //
+                       // Replace original type name, error reporting can use fully resolved name
+                       //
+                       type_name = te;
+
+                       member_type = te.Type;
+                       return true;
+               }
        }
 
        //
@@ -5366,29 +5431,19 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public override bool Define()
+               protected override void DoMemberTypeDependentChecks ()
                {
-                       if (MemberType == null || member_type == null)
-                               return false;
+                       base.DoMemberTypeDependentChecks ();
 
                        if (TypeManager.IsGenericParameter (MemberType))
-                               return true;
+                               return;
 
                        if (MemberType.IsSealed && MemberType.IsAbstract) {
                                Error_VariableOfStaticClass (Location, GetSignatureForError (), MemberType);
-                               return false;
                        }
 
-                       if (!CheckBase ())
-                               return false;
-
-                       if (!DoDefine ())
-                               return false;
-
-                       if (!IsTypePermitted ())
-                               return false;
-
-                       return true;
+                       CheckBase ();
+                       IsTypePermitted ();
                }
 
                //
@@ -5530,9 +5585,6 @@ namespace Mono.CSharp {
 
                public override bool Define()
                {
-                       if (!Parent.IsInUnsafeScope)
-                               Expression.UnsafeError (Location);
-
                        if (!base.Define ())
                                return false;
 
@@ -5556,13 +5608,21 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public override void Emit()
+               protected override void DoMemberTypeIndependentChecks ()
                {
+                       base.DoMemberTypeIndependentChecks ();
+
+                       if (!Parent.IsInUnsafeScope)
+                               Expression.UnsafeError (Location);
+
                        if (Parent.PartialContainer.Kind != Kind.Struct) {
                                Report.Error (1642, Location, "`{0}': Fixed size buffer fields may only be members of structs",
                                        GetSignatureForError ());
                        }
+               }
 
+               public override void Emit()
+               {
                        EmitContext ec = new EmitContext (this, Parent, Location, null, TypeManager.void_type, ModFlags);
                        Constant c = size_expr.ResolveAsConstant (ec, this);
                        if (c == null)
@@ -5739,9 +5799,6 @@ namespace Mono.CSharp {
                        if (TypeManager.IsReferenceType (MemberType))
                                return true;
 
-                       if (MemberType.IsEnum)
-                               return true;
-
                        if (MemberType == TypeManager.bool_type || MemberType == TypeManager.char_type ||
                                MemberType == TypeManager.sbyte_type || MemberType == TypeManager.byte_type ||
                                MemberType == TypeManager.short_type || MemberType == TypeManager.ushort_type ||
@@ -5749,6 +5806,9 @@ namespace Mono.CSharp {
                                MemberType == TypeManager.float_type)
                                return true;
 
+                       if (TypeManager.IsEnumType (MemberType))
+                               return true;
+
                        return false;
                }
 
@@ -5784,18 +5844,6 @@ namespace Mono.CSharp {
                        if (!base.Define ())
                                return false;
 
-                       if ((ModFlags & Modifiers.VOLATILE) != 0){
-                               if (!CanBeVolatile ()) {
-                                       Report.Error (677, Location, "`{0}': A volatile field cannot be of the type `{1}'",
-                                               GetSignatureForError (), TypeManager.CSharpName (MemberType));
-                               }
-
-                               if ((ModFlags & Modifiers.READONLY) != 0){
-                                       Report.Error (678, Location, "`{0}': A field cannot be both volatile and readonly",
-                                               GetSignatureForError ());
-                               }
-                       }
-
                        try {
 #if GMCS_SOURCE
                                Type[] required_modifier = null;
@@ -5833,6 +5881,23 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               protected override void DoMemberTypeDependentChecks ()
+               {
+                       base.DoMemberTypeDependentChecks ();
+
+                       if ((ModFlags & Modifiers.VOLATILE) != 0) {
+                               if (!CanBeVolatile ()) {
+                                       Report.Error (677, Location, "`{0}': A volatile field cannot be of the type `{1}'",
+                                               GetSignatureForError (), TypeManager.CSharpName (MemberType));
+                               }
+
+                               if ((ModFlags & Modifiers.READONLY) != 0) {
+                                       Report.Error (678, Location, "`{0}': A field cannot be both volatile and readonly",
+                                               GetSignatureForError ());
+                               }
+                       }
+               }
+
                public override string GetSignatureForError ()
                {
                        string s = base.GetSignatureForError ();
@@ -5874,9 +5939,9 @@ namespace Mono.CSharp {
                public Attributes Attributes;
                public Location Location;
                public int ModFlags;
-               public Parameters Parameters;
+               public ParametersCompiled Parameters;
                
-               public Accessor (ToplevelBlock b, int mod, Attributes attrs, Parameters p, Location loc)
+               public Accessor (ToplevelBlock b, int mod, Attributes attrs, ParametersCompiled p, Location loc)
                {
                        Block = b;
                        Attributes = attrs;
@@ -5969,7 +6034,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               public abstract Parameters ParameterInfo { get ; }
+               public abstract ParametersCompiled ParameterInfo { get ; }
                public abstract Type ReturnType { get; }
                public abstract EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig);
 
@@ -6147,9 +6212,9 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       public override Parameters ParameterInfo {
+                       public override ParametersCompiled ParameterInfo {
                                get {
-                                       return Parameters.EmptyReadOnlyParameters;
+                                       return ParametersCompiled.EmptyReadOnlyParameters;
                                }
                        }
 
@@ -6164,12 +6229,12 @@ namespace Mono.CSharp {
 
                        static string[] attribute_targets = new string [] { "method", "param", "return" };
                        ImplicitParameter param_attr;
-                       protected Parameters parameters;
+                       protected ParametersCompiled parameters;
 
                        public SetMethod (PropertyBase method) :
                                base (method, "set_")
                        {
-                               parameters = new Parameters (
+                               parameters = new ParametersCompiled (
                                        new Parameter (method.type_name, "value", Parameter.Modifier.NONE, null, Location));
                        }
 
@@ -6192,7 +6257,7 @@ namespace Mono.CSharp {
                                base.ApplyAttributeBuilder (a, cb);
                        }
 
-                       public override Parameters ParameterInfo {
+                       public override ParametersCompiled ParameterInfo {
                            get {
                                return parameters;
                            }
@@ -6322,13 +6387,18 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       public bool HasCustomAccessModifier
-                       {
+                       public bool HasCustomAccessModifier {
                                get {
                                        return (ModFlags & Modifiers.PROPERTY_CUSTOM) != 0;
                                }
                        }
 
+                       public PropertyBase Property {
+                               get {
+                                       return method;
+                               }
+                       }
+
                        public override EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig)
                        {
                                return new EmitContext (this,
@@ -6410,21 +6480,24 @@ namespace Mono.CSharp {
                        }
                }
 
-               public override bool Define ()
+               protected override void DoMemberTypeDependentChecks ()
                {
-                       if (!DoDefine ())
-                               return false;
+                       base.DoMemberTypeDependentChecks ();
 
-                       if (!IsTypePermitted ())
-                               return false;
+                       IsTypePermitted ();
+#if MS_COMPATIBLE
+                       if (MemberType.IsGenericParameter)
+                               return;
+#endif
 
-                       return true;
+                       if ((MemberType.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute) {
+                               Report.Error (722, Location, Error722, TypeManager.CSharpName (MemberType));
+                       }
                }
 
-               protected override bool DoDefine ()
+               protected override void DoMemberTypeIndependentChecks ()
                {
-                       if (!base.DoDefine ())
-                               return false;
+                       base.DoMemberTypeIndependentChecks ();
 
                        //
                        // Accessors modifiers check
@@ -6433,7 +6506,6 @@ namespace Mono.CSharp {
                                (Set.ModFlags & Modifiers.Accessibility) != 0) {
                                Report.Error (274, Location, "`{0}': Cannot specify accessibility modifiers for both accessors of the property or indexer",
                                                GetSignatureForError ());
-                               return false;
                        }
 
                        if ((ModFlags & Modifiers.OVERRIDE) == 0 && 
@@ -6442,20 +6514,7 @@ namespace Mono.CSharp {
                                Report.Error (276, Location, 
                                              "`{0}': accessibility modifiers on accessors may only be used if the property or indexer has both a get and a set accessor",
                                              GetSignatureForError ());
-                               return false;
                        }
-
-#if MS_COMPATIBLE
-                       if (MemberType.IsGenericParameter)
-                               return true;
-#endif
-
-                       if ((MemberType.Attributes & Class.StaticClassAttribute) == Class.StaticClassAttribute) {
-                               Report.Error (722, Location, Error722, TypeManager.CSharpName (MemberType));
-                               return false;
-                       }
-
-                       return true;
                }
 
                bool DefineGet ()
@@ -6617,28 +6676,6 @@ namespace Mono.CSharp {
                const int AllowedInterfaceModifiers =
                        Modifiers.NEW;
 
-               void CreateAutomaticProperty (Block block, Accessor get_block, Accessor set_block)
-               {
-                       // Make the field
-                       Field field = new Field (
-                               Parent, type_name,
-                               Modifiers.BACKING_FIELD | Modifiers.PRIVATE | (ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE)),
-                           new MemberName ("<" + Name + ">k__BackingField", Location), null);
-                       ((TypeContainer)Parent).PartialContainer.AddField (field);
-
-                       // Make get block
-                       get_block.Block = new ToplevelBlock (block, null, Location);
-                       Return r = new Return (new SimpleName(field.Name, Location), Location);
-                       get_block.Block.AddStatement (r);
-                       get_block.ModFlags |= Modifiers.COMPILER_GENERATED;
-
-                       // Make set block
-                       set_block.Block = new ToplevelBlock (block, set_block.Parameters, Location);
-                       Assign a = new SimpleAssign (new SimpleName (field.Name, Location), new SimpleName ("value", Location));
-                       set_block.Block.AddStatement (new StatementExpression(a));
-                       set_block.ModFlags |= Modifiers.COMPILER_GENERATED;
-               }
-
                public Property (DeclSpace parent, FullNamedExpression type, int mod,
                                 MemberName name, Attributes attrs, Accessor get_block,
                                 Accessor set_block, bool define_set_first)
@@ -6654,15 +6691,6 @@ namespace Mono.CSharp {
                                parent.PartialContainer.Kind == Kind.Interface ? AllowedInterfaceModifiers : AllowedModifiers,
                                name, attrs, define_set_first)
                {
-                       if (!IsInterface && (mod & (Modifiers.ABSTRACT | Modifiers.EXTERN)) == 0 &&
-                               get_block != null && get_block.Block == null &&
-                               set_block != null && set_block.Block == null) {
-                               if (RootContext.Version <= LanguageVersion.ISO_2)
-                                       Report.FeatureIsNotAvailable (Location, "automatically implemented properties");
-                               
-                               CreateAutomaticProperty (current_block, get_block, set_block);
-                       }
-
                        if (get_block == null)
                                Get = new GetMethod (this);
                        else
@@ -6672,18 +6700,51 @@ namespace Mono.CSharp {
                                Set = new SetMethod (this);
                        else
                                Set = new SetMethod (this, set_block);
+
+                       if (!IsInterface && (mod & (Modifiers.ABSTRACT | Modifiers.EXTERN)) == 0 &&
+                               get_block != null && get_block.Block == null &&
+                               set_block != null && set_block.Block == null) {
+                               if (RootContext.Version <= LanguageVersion.ISO_2)
+                                       Report.FeatureIsNotAvailable (Location, "automatically implemented properties");
+
+                               Get.ModFlags |= Modifiers.COMPILER_GENERATED;
+                               Set.ModFlags |= Modifiers.COMPILER_GENERATED;
+                       }
                }
 
-               public override bool Define ()
+               void CreateAutomaticProperty ()
                {
-                       if (!DoDefineBase ())
-                               return false;
+                       // Create backing field
+                       Field field = new Field (
+                               Parent, type_name,
+                               Modifiers.BACKING_FIELD | Modifiers.PRIVATE | (ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE)),
+                               new MemberName ("<" + GetFullName (MemberName) + ">k__BackingField", Location), null);
+                       if (!field.Define ())
+                               return;
+
+                       Parent.PartialContainer.AddField (field);
+
+                       // Create get block
+                       Get.Block = new ToplevelBlock (ParametersCompiled.EmptyReadOnlyParameters, Location);
+                       Return r = new Return (new SimpleName (field.Name, Location), Location);
+                       Get.Block.AddStatement (r);
 
+                       // Create set block
+                       Set.Block = new ToplevelBlock (Set.ParameterInfo, Location);
+                       Assign a = new SimpleAssign (new SimpleName (field.Name, Location), new SimpleName ("value", Location));
+                       Set.Block.AddStatement (new StatementExpression (a));
+               }
+
+               public override bool Define ()
+               {
                        if (!base.Define ())
                                return false;
 
                        flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
 
+                       if ((Get.ModFlags & Modifiers.COMPILER_GENERATED) != 0)
+                               CreateAutomaticProperty ();
+
                        if (!DefineAccessors ())
                                return false;
 
@@ -6724,7 +6785,7 @@ namespace Mono.CSharp {
                protected override PropertyInfo ResolveBaseProperty ()
                {
                        return Parent.PartialContainer.BaseCache.FindMemberToOverride (
-                               Parent.TypeBuilder, Name, Parameters.EmptyReadOnlyParameters, null, true) as PropertyInfo;
+                               Parent.TypeBuilder, Name, ParametersCompiled.EmptyReadOnlyParameters, null, true) as PropertyInfo;
                }
        }
 
@@ -7204,7 +7265,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       public override Parameters ParameterInfo {
+                       public override ParametersCompiled ParameterInfo {
                                get {
                                        return method.parameters;
                                }
@@ -7233,7 +7294,7 @@ namespace Mono.CSharp {
                public MyEventBuilder     EventBuilder;
                public MethodBuilder AddBuilder, RemoveBuilder;
 
-               Parameters parameters;
+               ParametersCompiled parameters;
 
                protected Event (DeclSpace parent, FullNamedExpression type, int mod_flags, MemberName name, Attributes attrs)
                        : base (parent, null, type, mod_flags,
@@ -7265,18 +7326,14 @@ namespace Mono.CSharp {
 
                public override bool Define ()
                {
-                       if (!DoDefineBase ())
-                               return false;
-
-                       if (!DoDefine ())
+                       if (!base.Define ())
                                return false;
 
                        if (!TypeManager.IsDelegateType (MemberType)) {
                                Report.Error (66, Location, "`{0}': event must be of a delegate type", GetSignatureForError ());
-                               return false;
                        }
 
-                       parameters = Parameters.CreateFullyResolved (
+                       parameters = ParametersCompiled.CreateFullyResolved (
                                new Parameter (null, "value", Parameter.Modifier.NONE, null, Location), MemberType);
 
                        if (!CheckBase ())
@@ -7354,7 +7411,7 @@ namespace Mono.CSharp {
        {
                public class GetIndexerMethod : GetMethod
                {
-                       Parameters parameters;
+                       ParametersCompiled parameters;
 
                        public GetIndexerMethod (Indexer method):
                                base (method)
@@ -7384,7 +7441,7 @@ namespace Mono.CSharp {
                                return false;
                        }                       
 
-                       public override Parameters ParameterInfo {
+                       public override ParametersCompiled ParameterInfo {
                                get {
                                        return parameters;
                                }
@@ -7396,7 +7453,7 @@ namespace Mono.CSharp {
                        public SetIndexerMethod (Indexer method):
                                base (method)
                        {
-                               parameters = Parameters.MergeGenerated (method.parameters, false, parameters [0], null);
+                               parameters = ParametersCompiled.MergeGenerated (method.parameters, false, parameters [0], null);
                        }
 
                        public SetIndexerMethod (PropertyBase method, Accessor accessor):
@@ -7432,10 +7489,10 @@ namespace Mono.CSharp {
                const int AllowedInterfaceModifiers =
                        Modifiers.NEW;
 
-               public readonly Parameters parameters;
+               public readonly ParametersCompiled parameters;
 
                public Indexer (DeclSpace parent, FullNamedExpression type, MemberName name, int mod,
-                               Parameters parameters, Attributes attrs,
+                               ParametersCompiled parameters, Attributes attrs,
                                Accessor get_block, Accessor set_block, bool define_set_first)
                        : base (parent, type, mod,
                                parent.PartialContainer.Kind == Kind.Interface ? AllowedInterfaceModifiers : AllowedModifiers,
@@ -7461,9 +7518,6 @@ namespace Mono.CSharp {
                
                public override bool Define ()
                {
-                       if (!DoDefineBase ())
-                               return false;
-
                        if (!base.Define ())
                                return false;
 
@@ -7665,7 +7719,7 @@ namespace Mono.CSharp {
                }
                
                public Operator (DeclSpace parent, OpType type, FullNamedExpression ret_type,
-                                int mod_flags, Parameters parameters,
+                                int mod_flags, ParametersCompiled parameters,
                                 ToplevelBlock block, Attributes attrs, Location loc)
                        : base (parent, null, ret_type, mod_flags, AllowedModifiers,
                                new MemberName (GetMetadataName (type), loc), attrs, parameters)
@@ -7689,7 +7743,6 @@ namespace Mono.CSharp {
                        const int RequiredModifiers = Modifiers.PUBLIC | Modifiers.STATIC;
                        if ((ModFlags & RequiredModifiers) != RequiredModifiers){
                                Report.Error (558, Location, "User-defined operator `{0}' must be declared static and public", GetSignatureForError ());
-                               return false;
                        }
 
                        if (!base.Define ())
@@ -7811,41 +7864,14 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               protected override bool DoDefine ()
+               protected override bool ResolveMemberType ()
                {
-                       if (!base.DoDefine ())
+                       if (!base.ResolveMemberType ())
                                return false;
 
                        flags |= MethodAttributes.SpecialName | MethodAttributes.HideBySig;
                        return true;
                }
-               
-               public override void Emit ()
-               {
-                       base.Emit ();
-
-                       Parameters.ApplyAttributes (MethodBuilder);
-
-                       //
-                       // abstract or extern methods have no bodies
-                       //
-                       if ((ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0)
-                               return;
-                       
-                       EmitContext ec;
-                       if ((flags & MethodAttributes.PinvokeImpl) == 0)
-                               ec = CreateEmitContext (Parent, MethodBuilder.GetILGenerator ());
-                       else
-                               ec = CreateEmitContext (Parent, null);
-                       
-                       SourceMethod source = SourceMethod.Create (Parent, MethodBuilder, Block);
-                       ec.EmitTopBlock (this, Block);
-
-                       if (source != null)
-                               source.CloseMethod ();
-
-                       Block = null;
-               }
 
                // Operator cannot be override
                protected override MethodInfo FindOutBaseMethod (ref Type base_ret_type)