2008-10-04 Ivan N. Zlatev <contact@i-nz.net>
[mono.git] / mcs / mcs / class.cs
index 49c1f26ebfdd2b7b27c9da950588d11853a6d1a5..a0b46cd70a9e4eda4dbffcf0c768684bd0732f58 100644 (file)
@@ -5,10 +5,10 @@
 //          Martin Baulig (martin@ximian.com)
 //          Marek Safar (marek.safar@seznam.cz)
 //
-// Licensed under the terms of the GNU GPL
+// Dual licensed under the terms of the MIT X11 or GNU GPL
 //
-// (C) 2001, 2002, 2003 Ximian, Inc (http://www.ximian.com)
-// (C) 2004 Novell, Inc
+// Copyright 2001, 2002, 2003 Ximian, Inc (http://www.ximian.com)
+// Copyright 2004-2008 Novell, Inc
 //
 //
 //  2002-10-11  Miguel de Icaza  <miguel@ximian.com>
@@ -249,11 +249,9 @@ namespace Mono.CSharp {
                TypeExpr[] iface_exprs;
                Type GenericType;
 
-               ArrayList type_bases;
+               protected ArrayList type_bases;
 
-               bool members_resolved;
-               bool members_resolved_ok;
-               bool members_defined;
+               protected bool members_defined;
                bool members_defined_ok;
 
                // The interfaces we implement.
@@ -270,10 +268,6 @@ namespace Mono.CSharp {
 
                private CachedMethods cached_method;
 
-#if GMCS_SOURCE
-               GenericTypeParameterBuilder[] gen_params;
-#endif
-
                ArrayList partial_parts;
 
                /// <remarks>
@@ -295,7 +289,7 @@ namespace Mono.CSharp {
 
                public bool AddMember (MemberCore symbol)
                {
-                       return AddToContainer (symbol, symbol.MemberName.MethodName);
+                       return AddToContainer (symbol, symbol.MemberName.Basename);
                }
 
                protected virtual bool AddMemberType (DeclSpace ds)
@@ -303,6 +297,11 @@ namespace Mono.CSharp {
                        return AddToContainer (ds, ds.Basename);
                }
 
+               protected virtual void RemoveMemberType (DeclSpace ds)
+               {
+                       RemoveFromContainer (ds.Basename);
+               }
+
                public void AddConstant (Const constant)
                {
                        if (!AddMember (constant))
@@ -340,8 +339,8 @@ namespace Mono.CSharp {
                                return AddTypeContainer (next_part);
 
                        if ((tc.ModFlags & Modifiers.PARTIAL) == 0) {
-                               Report.SymbolRelatedToPreviousError (tc);
-                               Error_MissingPartialModifier (next_part);
+                               Report.SymbolRelatedToPreviousError (next_part);
+                               Error_MissingPartialModifier (tc);
                        }
 
                        if (tc.Kind != next_part.Kind) {
@@ -360,20 +359,6 @@ namespace Mono.CSharp {
                                        next_part.GetSignatureForError ());
                        }
 
-                       if (tc.MemberName.IsGeneric) {
-                               TypeParameter[] tc_names = tc.TypeParameters;
-                               TypeParameterName[] part_names = next_part.MemberName.TypeArguments.GetDeclarations ();
-
-                               for (int i = 0; i < tc_names.Length; ++i) {
-                                       if (tc_names[i].Name == part_names[i].Name)
-                                               continue;
-
-                                       Report.SymbolRelatedToPreviousError (part_names[i].Location, "");
-                                       Report.Error (264, tc.Location, "Partial declarations of `{0}' must have the same type parameter names in the same order",
-                                               tc.GetSignatureForError ());
-                               }
-                       }
-
                        if (tc.partial_parts == null)
                                tc.partial_parts = new ArrayList (1);
 
@@ -398,6 +383,13 @@ namespace Mono.CSharp {
                        return tc;
                }
 
+               public virtual void RemoveTypeContainer (TypeContainer next_part)
+               {
+                       if (types != null)
+                               types.Remove (next_part);
+                       RemoveMemberType (next_part);
+               }
+               
                public void AddDelegate (Delegate d)
                {
                        if (!AddMemberType (d))
@@ -416,11 +408,16 @@ namespace Mono.CSharp {
                                ordered_member_list = new MemberCoreArrayList ();
                        }
 
-                       if(isexplicit) {
+                       if (isexplicit) {
+                               if (Kind == Kind.Interface) {
+                                       Report.Error (541, mc.Location,
+                                               "`{0}': explicit interface declaration can only be declared in a class or struct",
+                                               mc.GetSignatureForError ());
+                               }
+
                                ordered_explicit_member_list.Add (mc);
                                alist.Insert (0, mc);
-                       } 
-                       else {
+                       } else {
                                ordered_member_list.Add (mc);
                                alist.Add (mc);
                        }
@@ -429,8 +426,7 @@ namespace Mono.CSharp {
                
                public void AddMethod (Method method)
                {
-                       MemberName mn = method.MemberName;
-                       if (!AddToContainer (method, mn.IsGeneric ? mn.Basename : mn.MethodName))
+                       if (!AddToContainer (method, method.MemberName.Basename))
                                return;
                        
                        if (methods == null)
@@ -442,34 +438,14 @@ namespace Mono.CSharp {
                                AddMemberToList (method, methods, false);
                }
 
-               //
-               // Do not use this method: use AddMethod.
-               //
-               // This is only used by iterators.
-               //
-               public void AppendMethod (Method method)
-               {
-                       if (!AddMember (method))
-                               return;
-
-                       if (methods == null)
-                               methods = new MemberCoreArrayList ();
-
-                       AddMemberToList (method, methods, false);
-               }
-
                public void AddConstructor (Constructor c)
                {
-                       if (c.Name != MemberName.Name) {
-                               Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
-                       }
-
                        bool is_static = (c.ModFlags & Modifiers.STATIC) != 0;
                        if (!AddToContainer (c, is_static ?
                                ConstructorBuilder.ConstructorName : ConstructorBuilder.TypeConstructorName))
                                return;
                        
-                       if (is_static && c.Parameters.Empty){
+                       if (is_static && c.Parameters.IsEmpty){
                                if (default_static_constructor != null) {
                                    Report.SymbolRelatedToPreviousError (default_static_constructor);
                                        Report.Error (111, c.Location,
@@ -480,7 +456,7 @@ namespace Mono.CSharp {
 
                                default_static_constructor = c;
                        } else {
-                               if (c.Parameters.Empty)
+                               if (c.Parameters.IsEmpty)
                                        default_constructor = c;
                                
                                if (instance_constructors == null)
@@ -622,27 +598,11 @@ namespace Mono.CSharp {
                        }
                }
 
-               public ArrayList CompilerGenerated {
-                       get {
-                               return compiler_generated;
-                       }
-               }
-
                protected Type BaseType {
                        get {
                                return TypeBuilder.BaseType;
                        }
                }
-               
-               public ArrayList Bases {
-                       get {
-                               return type_bases;
-                       }
-
-                       set {
-                               type_bases = value;
-                       }
-               }
 
                public ArrayList Fields {
                        get {
@@ -726,19 +686,12 @@ namespace Mono.CSharp {
 
                public void ResolveFieldInitializers (EmitContext ec)
                {
-                       // Field initializers are tricky for partial classes. They have to
-                       // share same costructor (block) but they have they own resolve scope.
-                       DeclSpace orig = ec.DeclContainer;
-
                        if (partial_parts != null) {
                                foreach (TypeContainer part in partial_parts) {
-                                       ec.DeclContainer = part;
                                        part.DoResolveFieldInitializers (ec);
                                }
                        }
-                       ec.DeclContainer = PartialContainer;
                        DoResolveFieldInitializers (ec);
-                       ec.DeclContainer = orig; 
                }
 
                void DoResolveFieldInitializers (EmitContext ec)
@@ -747,28 +700,32 @@ namespace Mono.CSharp {
                                if (initialized_static_fields == null)
                                        return;
 
-                               bool has_complex_initializer = false;
-                               using (ec.Set (EmitContext.Flags.InFieldInitializer)) {
-                                       foreach (FieldInitializer fi in initialized_static_fields) {
-                                               fi.ResolveStatement (ec);
-                                               if (!fi.IsComplexInitializer)
-                                                       continue;
-
-                                               has_complex_initializer = true;
+                               bool has_complex_initializer = !RootContext.Optimize;
+                               int i;
+                               ExpressionStatement [] init = new ExpressionStatement [initialized_static_fields.Count];
+                               for (i = 0; i < initialized_static_fields.Count; ++i) {
+                                       FieldInitializer fi = (FieldInitializer) initialized_static_fields [i];
+                                       ExpressionStatement s = fi.ResolveStatement (ec);
+                                       if (s == null) {
+                                               s = EmptyExpressionStatement.Instance;
+                                       } else if (fi.IsComplexInitializer) {
+                                               has_complex_initializer |= true;
                                        }
 
+                                       init [i] = s;
+                               }
+
+                               for (i = 0; i < initialized_static_fields.Count; ++i) {
+                                       FieldInitializer fi = (FieldInitializer) initialized_static_fields [i];
+                                       //
                                        // Need special check to not optimize code like this
                                        // static int a = b = 5;
                                        // static int b = 0;
-                                       if (!has_complex_initializer && RootContext.Optimize) {
-                                               for (int i = 0; i < initialized_static_fields.Count; ++i) {
-                                                       FieldInitializer fi = (FieldInitializer) initialized_static_fields [i];
-                                                       if (fi.IsDefaultInitializer) {
-                                                               initialized_static_fields.RemoveAt (i);
-                                                               --i;
-                                                       }
-                                               }
-                                       }
+                                       //
+                                       if (!has_complex_initializer && fi.IsDefaultInitializer)
+                                               continue;
+
+                                       ec.CurrentBlock.AddScopeStatement (new StatementExpression (init [i]));
                                }
 
                                return;
@@ -777,16 +734,19 @@ namespace Mono.CSharp {
                        if (initialized_fields == null)
                                return;
 
-                       using (ec.Set (EmitContext.Flags.InFieldInitializer)) {
-                               for (int i = 0; i < initialized_fields.Count; ++i) {
-                                       FieldInitializer fi = (FieldInitializer) initialized_fields [i];
-                                       fi.ResolveStatement (ec);
-                                       if (fi.IsDefaultInitializer && RootContext.Optimize) {
-                                               // Field is re-initialized to its default value => removed
-                                               initialized_fields.RemoveAt (i);
-                                               --i;
-                                       }
-                               }
+                       for (int i = 0; i < initialized_fields.Count; ++i) {
+                               FieldInitializer fi = (FieldInitializer) initialized_fields [i];
+                               ExpressionStatement s = fi.ResolveStatement (ec);
+                               if (s == null)
+                                       continue;
+
+                               //
+                               // Field is re-initialized to its default value => removed
+                               //
+                               if (fi.IsDefaultInitializer && RootContext.Optimize)
+                                       continue;
+
+                               ec.CurrentBlock.AddScopeStatement (new StatementExpression (s));
                        }
                }
 
@@ -845,48 +805,80 @@ namespace Mono.CSharp {
                {
                        // FIXME: get rid of partial_parts and store lists of bases of each part here
                        // assumed, not verified: 'part' is in 'partial_parts' 
-                       ((TypeContainer) part).Bases = bases;
+                       ((TypeContainer) part).type_bases = bases;
                }
 
-               TypeExpr[] GetNormalBases (out TypeExpr base_class)
+               /// <summary>
+               ///   This function computes the Base class and also the
+               ///   list of interfaces that the class or struct @c implements.
+               ///   
+               ///   The return value is an array (might be null) of
+               ///   interfaces implemented (as Types).
+               ///   
+               ///   The @base_class argument is set to the base object or null
+               ///   if this is `System.Object'. 
+               /// </summary>
+               protected virtual TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
                {
                        base_class = null;
-                       if (Bases == null)
+                       if (type_bases == null)
                                return null;
 
-                       int count = Bases.Count;
-                       int start = 0, i, j;
+                       int count = type_bases.Count;
+                       TypeExpr [] ifaces = null;
+                       for (int i = 0, j = 0; i < count; i++){
+                               FullNamedExpression fne = (FullNamedExpression) type_bases [i];
 
-                       if (Kind == Kind.Class){
-                               TypeExpr name = ((Expression) Bases [0]).ResolveAsBaseTerminal (this, false);
+                               //
+                               // Standard ResolveAsTypeTerminal cannot be used in this case because
+                               // it does ObsoleteAttribute and constraint checks which require
+                               // base type to be set
+                               //
+                               TypeExpr fne_resolved = fne.ResolveAsBaseTerminal (this, false);
+                               if (fne_resolved == null)
+                                       continue;
 
-                               if (name == null){
-                                       return null;
+                               if (i == 0 && Kind == Kind.Class && !fne_resolved.Type.IsInterface) {
+                                       base_class = fne_resolved;
+                                       continue;
                                }
 
-                               if (!name.IsInterface) {
-                                       // base_class could be a class, struct, enum, delegate.
-                                       // This is validated in GetClassBases.
-                                       base_class = name;
-                                       start = 1;
-                               }
-                       }
+                               if (ifaces == null)
+                                       ifaces = new TypeExpr [count - i];
+
+                               if (fne_resolved.Type.IsInterface) {
+                                       for (int ii = 0; ii < j; ++ii) {
+                                               if (TypeManager.IsEqual (fne_resolved.Type, ifaces [ii].Type)) {
+                                                       Report.Error (528, Location, "`{0}' is already listed in interface list",
+                                                               fne_resolved.GetSignatureForError ());
+                                                       break;
+                                               }
+                                       }
 
-                       TypeExpr [] ifaces = new TypeExpr [count-start];
-                       
-                       for (i = start, j = 0; i < count; i++, j++){
-                               TypeExpr resolved = ((Expression) Bases [i]).ResolveAsBaseTerminal (this, false);
-                               if (resolved == null) {
-                                       return null;
+                                       if (Kind == Kind.Interface && !fne_resolved.AsAccessible (this)) {
+                                               Report.Error (61, fne.Location,
+                                                       "Inconsistent accessibility: base interface `{0}' is less accessible than interface `{1}'",
+                                                       fne_resolved.GetSignatureForError (), GetSignatureForError ());
+                                       }
+                               } else {
+                                       Report.SymbolRelatedToPreviousError (fne_resolved.Type);
+                                       if (Kind != Kind.Class) {
+                                               Report.Error (527, fne.Location, "Type `{0}' in interface list is not an interface", fne_resolved.GetSignatureForError ());
+                                       } else if (base_class != null)
+                                               Report.Error (1721, fne.Location, "`{0}': Classes cannot have multiple base classes (`{1}' and `{2}')",
+                                                       GetSignatureForError (), base_class.GetSignatureForError (), fne_resolved.GetSignatureForError ());
+                                       else {
+                                               Report.Error (1722, fne.Location, "`{0}': Base class `{1}' must be specified as first",
+                                                       GetSignatureForError (), fne_resolved.GetSignatureForError ());
+                                       }
                                }
-                               
-                               ifaces [j] = resolved;
+
+                               ifaces [j++] = fne_resolved;
                        }
 
-                       return ifaces.Length == 0 ? null : ifaces;
+                       return ifaces;
                }
 
-
                TypeExpr[] GetNormalPartialBases (ref TypeExpr base_class)
                {
                        ArrayList ifaces = new ArrayList (0);
@@ -895,7 +887,7 @@ namespace Mono.CSharp {
 
                        foreach (TypeContainer part in partial_parts) {
                                TypeExpr new_base_class;
-                               TypeExpr[] new_ifaces = part.GetClassBases (out new_base_class);
+                               TypeExpr[] new_ifaces = part.ResolveBaseTypes (out new_base_class);
                                if (new_base_class != TypeManager.system_object_expr) {
                                        if (base_class == TypeManager.system_object_expr)
                                                base_class = new_base_class;
@@ -928,65 +920,6 @@ namespace Mono.CSharp {
                        return (TypeExpr[])ifaces.ToArray (typeof (TypeExpr));
                }
 
-               /// <summary>
-               ///   This function computes the Base class and also the
-               ///   list of interfaces that the class or struct @c implements.
-               ///   
-               ///   The return value is an array (might be null) of
-               ///   interfaces implemented (as Types).
-               ///   
-               ///   The @base_class argument is set to the base object or null
-               ///   if this is `System.Object'. 
-               /// </summary>
-               public virtual TypeExpr [] GetClassBases (out TypeExpr base_class)
-               {
-                       TypeExpr[] ifaces = GetNormalBases (out base_class);
-
-                       if (ifaces == null)
-                               return null;
-
-                       int count = ifaces.Length;
-
-                       for (int i = 0; i < count; i++) {
-                               TypeExpr iface = (TypeExpr) ifaces [i];
-
-                               if (!iface.IsInterface) {
-                                       if (Kind != Kind.Class) {
-                                               // TODO: location of symbol related ....
-                                               Error_TypeInListIsNotInterface (Location, iface.GetSignatureForError ());
-                                       }
-                                       else if (base_class != null)
-                                               Report.Error (1721, Location, "`{0}': Classes cannot have multiple base classes (`{1}' and `{2}')",
-                                                       GetSignatureForError (), base_class.GetSignatureForError (), iface.GetSignatureForError ());
-                                       else {
-                                               Report.Error (1722, Location, "`{0}': Base class `{1}' must be specified as first",
-                                                       GetSignatureForError (), iface.GetSignatureForError ());
-                                       }
-                                       return null;
-                               }
-
-                               for (int x = 0; x < i; x++) {
-                                       if (iface.Equals (ifaces [x])) {
-                                               Report.Error (528, Location,
-                                                             "`{0}' is already listed in " +
-                                                             "interface list", iface.GetSignatureForError ());
-                                               return null;
-                                       }
-                               }
-
-                               if ((Kind == Kind.Interface) &&
-                                   !iface.AsAccessible (this)) {
-                                       Report.Error (61, Location,
-                                                     "Inconsistent accessibility: base " +
-                                                     "interface `{0}' is less accessible " +
-                                                     "than interface `{1}'", iface.GetSignatureForError (),
-                                                     Name);
-                                       return null;
-                               }
-                       }
-                       return ifaces;
-               }
-
                bool CheckGenericInterfaces (Type[] ifaces)
                {
 #if GMCS_SOURCE
@@ -1019,11 +952,6 @@ namespace Mono.CSharp {
 
                bool error = false;
                
-               protected void Error_TypeInListIsNotInterface (Location loc, string type)
-               {
-                       Report.Error (527, loc, "Type `{0}' in interface list is not an interface", type);
-               }
-
                bool CreateTypeBuilder ()
                {
                        try {
@@ -1033,6 +961,11 @@ namespace Mono.CSharp {
                                else if (Kind == Kind.Enum)
                                        default_parent = TypeManager.enum_type;
 
+                               //
+                               // Sets .size to 1 for structs with no instance fields
+                               //
+                               int type_size = Kind == Kind.Struct && first_nonstatic_field == null ? 1 : 0;
+
                                if (IsTopLevel){
                                        if (TypeManager.NamespaceClash (Name, Location)) {
                                                return false;
@@ -1040,12 +973,12 @@ namespace Mono.CSharp {
 
                                        ModuleBuilder builder = CodeGen.Module.Builder;
                                        TypeBuilder = builder.DefineType (
-                                               Name, TypeAttr, default_parent, null);
+                                               Name, TypeAttr, default_parent, type_size);
                                } else {
                                        TypeBuilder builder = Parent.TypeBuilder;
 
                                        TypeBuilder = builder.DefineNestedType (
-                                               Basename, TypeAttr, default_parent, null);
+                                               Basename, TypeAttr, default_parent, type_size);
                                }
                        } catch (ArgumentException) {
                                Report.RuntimeMissingSupport (Location, "static classes");
@@ -1060,7 +993,7 @@ namespace Mono.CSharp {
                                for (int i = 0; i < TypeParameters.Length; i++)
                                        param_names [i] = TypeParameters [i].Name;
 
-                               gen_params = TypeBuilder.DefineGenericParameters (param_names);
+                               GenericTypeParameterBuilder[] gen_params = TypeBuilder.DefineGenericParameters (param_names);
 
                                int offset = CountTypeParameters - CurrentTypeParameters.Length;
                                for (int i = offset; i < gen_params.Length; i++)
@@ -1073,7 +1006,7 @@ namespace Mono.CSharp {
 
                bool DefineBaseTypes ()
                {
-                       iface_exprs = GetClassBases (out base_type);
+                       iface_exprs = ResolveBaseTypes (out base_type);
                        if (partial_parts != null) {
                                iface_exprs = GetNormalPartialBases (ref base_type);
                        }
@@ -1091,22 +1024,11 @@ namespace Mono.CSharp {
                        if (!(this is CompilerGeneratedClass))
                                RootContext.RegisterOrder (this); 
 
-                       if (IsGeneric && base_type != null && TypeManager.IsAttributeType (base_type.Type)) {
-                               Report.Error (698, base_type.Location,
-                                             "A generic type cannot derive from `{0}' because it is an attribute class",
-                                             base_type.Name);
-                               return false;
-                       }
-
                        if (!CheckRecursiveDefinition (this))
                                return false;
 
                        if (base_type != null && base_type.Type != null) {
                                TypeBuilder.SetParent (base_type.Type);
-
-                               ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (base_type.Type);
-                               if (obsolete_attr != null && !IsInObsoleteScope)
-                                       AttributeTester.Report_ObsoleteMessage (obsolete_attr, base_type.GetSignatureForError (), Location);
                        }
 
                        // add interfaces that were not added at type creation
@@ -1118,13 +1040,6 @@ namespace Mono.CSharp {
                                foreach (Type itype in ifaces)
                                        TypeBuilder.AddInterfaceImplementation (itype);
 
-                               foreach (TypeExpr ie in iface_exprs) {
-                                       ObsoleteAttribute oa = AttributeTester.GetObsoleteAttribute (ie.Type);
-                                       if ((oa != null) && !IsInObsoleteScope)
-                                               AttributeTester.Report_ObsoleteMessage (
-                                                       oa, ie.GetSignatureForError (), Location);
-                               }
-
                                if (!CheckGenericInterfaces (ifaces))
                                        return false;
 
@@ -1188,13 +1103,6 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       if (!(this is CompilerGeneratedClass)) {
-                               if (!ResolveMembers ()) {
-                                       error = true;
-                                       return null;
-                               }
-                       }
-
                        if (!DefineNestedTypes ()) {
                                error = true;
                                return null;
@@ -1203,123 +1111,40 @@ namespace Mono.CSharp {
                        return TypeBuilder;
                }
 
-               public bool ResolveMembers ()
-               {
-                       if (members_resolved)
-                               return members_resolved_ok;
-
-                       members_resolved_ok = DoResolveMembers ();
-                       members_resolved = true;
-
-                       return members_resolved_ok;
-               }
-
-               protected virtual bool DoResolveMembers ()
-               {
-                       if (methods != null) {
-                               foreach (Method method in methods) {
-                                       if (!method.ResolveMembers ())
-                                               return false;
-                               }
-                       }
-
-                       if (instance_constructors != null) {
-                               foreach (Constructor c in instance_constructors) {
-                                       if (!c.ResolveMembers ())
-                                               return false;
-                               }
-                       }
-
-                       if (default_static_constructor != null) {
-                               if (!default_static_constructor.ResolveMembers ())
-                                       return false;
-                       }
-
-                       if (operators != null) {
-                               foreach (Operator o in operators) {
-                                       if (!o.ResolveMembers ())
-                                               return false;
-                               }
-                       }
-
-                       if (properties != null) {
-                               foreach (PropertyBase p in properties) {
-                                       if (!p.Get.IsDummy && !p.Get.ResolveMembers ())
-                                               return false;
-                                       if (!p.Set.IsDummy && !p.Set.ResolveMembers ())
-                                               return false;
-                               }
-                       }
-
-                       if (indexers != null) {
-                               foreach (PropertyBase p in indexers) {
-                                       if (!p.Get.IsDummy && !p.Get.ResolveMembers ())
-                                               return false;
-                                       if (!p.Set.IsDummy && !p.Set.ResolveMembers ())
-                                               return false;
-                               }
-                       }
-
-                       if (events != null) {
-                               foreach (Event e in events) {
-                                       if (!e.Add.ResolveMembers ())
-                                               return false;
-                                       if (!e.Remove.ResolveMembers ())
-                                               return false;
-                               }
-                       }
-
-                       if (compiler_generated != null) {
-                               foreach (CompilerGeneratedClass c in compiler_generated) {
-                                       if (c.DefineType () == null)
-                                               return false;
-                               }
-                       }
-
-                       return true;
-               }
-
-               Constraints [] constraints;
                public override void SetParameterInfo (ArrayList constraints_list)
                {
-                       if (PartialContainer == this) {
-                               base.SetParameterInfo (constraints_list);
-                               return;
-                       }
+                       base.SetParameterInfo (constraints_list);
 
-                       if (constraints_list == null)
+                       if (!is_generic || PartialContainer == this)
                                return;
 
-                       constraints = new Constraints [PartialContainer.CountCurrentTypeParameters];
-
-                       TypeParameter[] current_params = PartialContainer.CurrentTypeParameters;
-                       for (int i = 0; i < constraints.Length; i++) {
-                               foreach (Constraints constraint in constraints_list) {
-                                       if (constraint.TypeParameter == current_params [i].Name) {
-                                               constraints [i] = constraint;
-                                               break;
-                                       }
+                       TypeParameter[] tc_names = PartialContainer.TypeParameters;
+                       for (int i = 0; i < tc_names.Length; ++i) {
+                               if (tc_names [i].Name != type_params [i].Name) {
+                                       Report.SymbolRelatedToPreviousError (PartialContainer.Location, "");
+                                       Report.Error (264, Location, "Partial declarations of `{0}' must have the same type parameter names in the same order",
+                                               GetSignatureForError ());
+                                       break;
                                }
                        }
                }
 
-               bool UpdateTypeParameterConstraints ()
+               void UpdateTypeParameterConstraints (TypeContainer part)
                {
-                       if (constraints == null)
-                               return true;
-
-                       TypeParameter[] current_params = PartialContainer.CurrentTypeParameters;
+                       TypeParameter[] current_params = CurrentTypeParameters;
                        for (int i = 0; i < current_params.Length; i++) {
-                               if (!current_params [i].UpdateConstraints (this, constraints [i])) {
-                                       Report.SymbolRelatedToPreviousError (Location, "");
-                                       Report.Error (265, PartialContainer.Location,
-                                               "Partial declarations of `{0}' have inconsistent constraints for type parameter `{1}'",
-                                               PartialContainer.GetSignatureForError (), current_params [i].Name);
-                                       return false;
-                               }
-                       }
+                               Constraints c = part.CurrentTypeParameters [i].Constraints;
+                               if (c == null)
+                                       continue;
 
-                       return true;
+                               if (current_params [i].UpdateConstraints (part, c))
+                                       continue;
+
+                               Report.SymbolRelatedToPreviousError (Location, "");
+                               Report.Error (265, part.Location,
+                                       "Partial declarations of `{0}' have inconsistent constraints for type parameter `{1}'",
+                                       GetSignatureForError (), current_params [i].GetSignatureForError ());
+                       }
                }
 
                public bool ResolveType ()
@@ -1359,13 +1184,9 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       if (partial_parts != null) {
-                               foreach (TypeContainer part in partial_parts) {
-                                       if (!part.UpdateTypeParameterConstraints ()) {
-                                               error = true;
-                                               return false;
-                                       }
-                               }
+                       if (partial_parts != null && is_generic) {
+                               foreach (TypeContainer part in partial_parts)
+                                       UpdateTypeParameterConstraints (part);
                        }
 
                        foreach (TypeParameter type_param in TypeParameters) {
@@ -1376,23 +1197,13 @@ namespace Mono.CSharp {
                        }
 
                        current_type = new ConstructedType (TypeBuilder, TypeParameters, Location);
-
-                       foreach (TypeParameter type_param in TypeParameters)
-                               if (!type_param.CheckDependencies ()) {
-                                       error = true;
-                                       return false;
-                               }
-
-                       if (current_type != null) {
-                               current_type = current_type.ResolveAsTypeTerminal (this, false);
-                               if (current_type == null) {
-                                       error = true;
-                                       return false;
-                               }
-
-                               CurrentType = current_type.Type;
+                       current_type = current_type.ResolveAsTypeTerminal (this, false);
+                       if (current_type == null) {
+                               error = true;
+                               return false;
                        }
 
+                       CurrentType = current_type.Type;
                        return true;
                }
 
@@ -1457,22 +1268,14 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public static void Error_KeywordNotAllowed (Location loc)
-               {
-                       Report.Error (1530, loc, "Keyword `new' is not allowed on namespace elements");
-               }
-
                /// <summary>
                ///   Populates our TypeBuilder with fields and methods
                /// </summary>
-               public override bool DefineMembers ()
+               public override bool Define ()
                {
                        if (members_defined)
                                return members_defined_ok;
 
-                       if (!base.DefineMembers ())
-                               return false;
-
                        members_defined_ok = DoDefineMembers ();
                        members_defined = true;
 
@@ -1483,6 +1286,11 @@ namespace Mono.CSharp {
                {
                        if (iface_exprs != null) {
                                foreach (TypeExpr iface in iface_exprs) {
+                                       ObsoleteAttribute oa = AttributeTester.GetObsoleteAttribute (iface.Type);
+                                       if ((oa != null) && !IsInObsoleteScope)
+                                               AttributeTester.Report_ObsoleteMessage (
+                                                       oa, iface.GetSignatureForError (), Location);
+
                                        ConstructedType ct = iface as ConstructedType;
                                        if ((ct != null) && !ct.CheckConstraints (this))
                                                return false;
@@ -1490,6 +1298,10 @@ namespace Mono.CSharp {
                        }
 
                        if (base_type != null) {
+                               ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (base_type.Type);
+                               if (obsolete_attr != null && !IsInObsoleteScope)
+                                       AttributeTester.Report_ObsoleteMessage (obsolete_attr, base_type.GetSignatureForError (), Location);
+
                                ConstructedType ct = base_type as ConstructedType;
                                if ((ct != null) && !ct.CheckConstraints (this))
                                        return false;
@@ -1647,20 +1459,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               public override bool Define ()
-               {
-                       CheckProtectedModifier ();
-
-                       if (compiler_generated != null) {
-                               foreach (CompilerGeneratedClass c in compiler_generated) {
-                                       if (!c.Define ())
-                                               return false;
-                               }
-                       }
-
-                       return true;
-               }
-
                public MemberInfo FindBaseMemberWithSameName (string name, bool ignore_methods)
                {
                        return BaseCache == null ? null : BaseCache.FindMemberWithSameName (name, ignore_methods, null);
@@ -1690,7 +1488,7 @@ namespace Mono.CSharp {
                {
                        ArrayList members = new ArrayList ();
 
-                       DefineMembers ();
+                       Define ();
 
                        if (methods != null) {
                                int len = methods.Count;
@@ -1757,6 +1555,11 @@ namespace Mono.CSharp {
                        set { caching_flags |= Flags.HasExplicitLayout; }
                }
 
+               public bool HasStructLayout {
+                       get { return (caching_flags & Flags.HasStructLayout) != 0; }
+                       set { caching_flags |= Flags.HasStructLayout; }
+               }
+
                //
                // Return the nested type with name @name.  Ensures that the nested type
                // is defined if necessary.  Do _not_ use this when you have a MemberCache handy.
@@ -2254,8 +2057,14 @@ namespace Mono.CSharp {
                                                
                                                if ((f.caching_flags & Flags.IsAssigned) != 0)
                                                        continue;
+
+                                               //
+                                               // Don't be pendatic over serializable attributes
+                                               //
+                                               if (f.OptAttributes != null || PartialContainer.HasStructLayout)
+                                                       continue;
                                                
-                                               Constant c = New.Constantify (f.Type.Type);
+                                               Constant c = New.Constantify (f.MemberType);
                                                Report.Warning (649, 4, f.Location, "Field `{0}' is never assigned to, and will always have its default value `{1}'",
                                                        f.GetSignatureForError (), c == null ? "null" : c.AsString ());
                                        }
@@ -2286,7 +2095,7 @@ namespace Mono.CSharp {
                                        has_compliant_args = c.HasCompliantArgs;
                                }
                                if (!has_compliant_args)
-                                       Report.Error (3015, Location, "`{0}' has no accessible constructors which use only CLS-compliant types", GetSignatureForError ());
+                                       Report.Warning (3015, 1, Location, "`{0}' has no accessible constructors which use only CLS-compliant types", GetSignatureForError ());
                        } else {
                                foreach (Constructor c in instance_constructors) {
                                        try {
@@ -2308,45 +2117,6 @@ namespace Mono.CSharp {
                        if (OptAttributes != null)
                                OptAttributes.Emit ();
 
-#if GMCS_SOURCE
-                       if (IsGeneric) {
-                               int offset = CountTypeParameters - CurrentTypeParameters.Length;
-                               for (int i = offset; i < gen_params.Length; i++)
-                                       CurrentTypeParameters [i - offset].Emit ();
-                       }
-#endif
-
-                       //
-                       // Structs with no fields need to have at least one byte.
-                       // The right thing would be to set the PackingSize in a DefineType
-                       // but there are no functions that allow interfaces *and* the size to
-                       // be specified.
-                       //
-
-                       if (Kind == Kind.Struct && first_nonstatic_field == null){
-                               FieldBuilder fb = TypeBuilder.DefineField ("$PRIVATE$", TypeManager.byte_type,
-                                                                          FieldAttributes.Private);
-
-                               if (HasExplicitLayout){
-                                       object [] ctor_args = new object [] { 0 };
-
-                                       if (TypeManager.field_offset_attribute_ctor == null) {
-                                               // Type is optional
-                                               if (TypeManager.field_offset_attribute_type == null) {
-                                                       TypeManager.field_offset_attribute_type = TypeManager.CoreLookupType (
-                                                               "System.Runtime.InteropServices", "FieldOffsetAttribute", Kind.Class, true);
-                                               }
-
-                                               TypeManager.field_offset_attribute_ctor = TypeManager.GetPredefinedConstructor (
-                                                       TypeManager.field_offset_attribute_type, Location, TypeManager.int32_type);
-                                       }
-                               
-                                       CustomAttributeBuilder cba = new CustomAttributeBuilder (
-                                               TypeManager.field_offset_attribute_ctor, ctor_args);
-                                       fb.SetCustomAttribute (cba);
-                               }
-                       }
-
                        Emit ();
 
                        EmitConstructors ();
@@ -2359,11 +2129,6 @@ namespace Mono.CSharp {
                        if (default_static_constructor != null)
                                default_static_constructor.Emit ();
                        
-                       if (methods != null){
-                               for (int i = 0; i < methods.Count; ++i)
-                                       ((Method)methods[i]).Emit ();
-                       }
-
                        if (operators != null)
                                foreach (Operator o in operators)
                                        o.Emit ();
@@ -2377,16 +2142,21 @@ namespace Mono.CSharp {
                                        indx.Emit ();
                                EmitIndexerName ();
                        }
-                       
-                       if (fields != null)
-                               foreach (FieldBase f in fields)
-                                       f.Emit ();
 
                        if (events != null){
                                foreach (Event e in Events)
                                        e.Emit ();
                        }
 
+                       if (methods != null) {
+                               for (int i = 0; i < methods.Count; ++i)
+                                       ((Method) methods [i]).Emit ();
+                       }
+                       
+                       if (fields != null)
+                               foreach (FieldBase f in fields)
+                                       f.Emit ();
+
                        if (delegates != null) {
                                foreach (Delegate d in Delegates) {
                                        d.Emit ();
@@ -2394,19 +2164,14 @@ namespace Mono.CSharp {
                        }
 
                        if (pending != null)
-                               if (pending.VerifyPendingMethods ())
-                                       return;
+                               pending.VerifyPendingMethods ();
 
                        if (Report.Errors > 0)
                                return;
 
                        if (compiler_generated != null) {
-                               foreach (CompilerGeneratedClass c in compiler_generated) {
-                                       if (!c.DefineMembers ())
-                                               throw new InternalErrorException ();
-                               }
-                               foreach (CompilerGeneratedClass c in compiler_generated)
-                                       c.EmitType ();
+                               for (int i = 0; i < compiler_generated.Count; ++i)
+                                       ((CompilerGeneratedClass) compiler_generated [i]).EmitType ();
                        }
                }
                
@@ -2442,8 +2207,8 @@ namespace Mono.CSharp {
                                foreach (Delegate d in Delegates)
                                        d.CloseType ();
 
-                       if (CompilerGenerated != null)
-                               foreach (CompilerGeneratedClass c in CompilerGenerated)
+                       if (compiler_generated != null)
+                               foreach (CompilerGeneratedClass c in compiler_generated)
                                        c.CloseType ();
                        
                        types = null;
@@ -2564,7 +2329,7 @@ namespace Mono.CSharp {
 
                        Type base_type = TypeBuilder.BaseType;
                        if (base_type != null && !AttributeTester.IsClsCompliant (base_type)) {
-                               Report.Error (3009, Location, "`{0}': base type `{1}' is not CLS-compliant", GetSignatureForError (), TypeManager.CSharpName (base_type));
+                               Report.Warning (3009, 1, Location, "`{0}': base type `{1}' is not CLS-compliant", GetSignatureForError (), TypeManager.CSharpName (base_type));
                        }
                        return true;
                }
@@ -2608,11 +2373,8 @@ namespace Mono.CSharp {
                                } else {
                                        Report.SymbolRelatedToPreviousError ((MemberCore) found);
                                }
-#if GMCS_SOURCE
+
                                Report.Warning (3005, 1, mc.Location, "Identifier `{0}' differing only in case is not CLS-compliant", mc.GetSignatureForError ());
-#else
-                               Report.Error (3005, mc.Location, "Identifier `{0}' differing only in case is not CLS-compliant", mc.GetSignatureForError ());
-#endif
                        }
                }
 
@@ -2763,11 +2525,11 @@ namespace Mono.CSharp {
 
                protected override bool AddToContainer (MemberCore symbol, string name)
                {
-                       if (name == MemberName.Name) {
+                       if (name == MemberName.Name && symbol.MemberName.Left == null) {
                                if (symbol is TypeParameter) {
                                        Report.Error (694, symbol.Location,
-                                                     "Type parameter `{0}' has same name as " +
-                                                     "containing type, or method", name);
+                                               "Type parameter `{0}' has same name as containing type, or method",
+                                               symbol.GetSignatureForError ());
                                        return false;
                                }
 
@@ -2804,8 +2566,11 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       if (a.Type == TypeManager.struct_layout_attribute_type && a.GetLayoutKindValue () == LayoutKind.Explicit) {
-                               HasExplicitLayout = true;
+                       if (a.Type == TypeManager.struct_layout_attribute_type) {
+                               PartialContainer.HasStructLayout = true;
+
+                               if (a.GetLayoutKindValue () == LayoutKind.Explicit)
+                                       PartialContainer.HasExplicitLayout = true;
                        }
 
                        base.ApplyAttributeBuilder (a, cb);
@@ -2828,7 +2593,7 @@ namespace Mono.CSharp {
                        }
 
                        Constructor c = new Constructor (this, MemberName.Name, mods,
-                               Parameters.EmptyReadOnlyParameters,
+                               null, Parameters.EmptyReadOnlyParameters,
                                new GeneratedBaseInitializer (Location),
                                Location);
                        
@@ -2838,17 +2603,23 @@ namespace Mono.CSharp {
 
                public override bool Define ()
                {
-                       if (default_static_constructor == null && PartialContainer.HasStaticFieldInitializer)
-                               DefineDefaultConstructor (true);
+                       CheckProtectedModifier ();
+
+                       base.Define ();
 
                        if (default_static_constructor != null)
                                default_static_constructor.Define ();
 
-                       return base.Define ();
+                       return true;
                }
 
                public override void Emit ()
                {
+                       if (default_static_constructor == null && PartialContainer.HasStaticFieldInitializer) {
+                               DefineDefaultConstructor (true);
+                               default_static_constructor.Define ();
+                       }
+
                        base.Emit ();
 
                        if (declarative_security != null) {
@@ -2934,7 +2705,7 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       if (AttributeTester.IsAttributeExcluded (a.Type))
+                       if (AttributeTester.IsAttributeExcluded (a.Type, Location))
                                return;
 
                        base.ApplyAttributeBuilder (a, cb);
@@ -2967,11 +2738,6 @@ namespace Mono.CSharp {
                                        continue;
                                }
 
-                               if ((m.ModFlags & Modifiers.PROTECTED) != 0) {
-                                       m.CheckProtectedModifier ();
-                                       continue;
-                               }
-
                                if (m is Indexer) {
                                        Report.Error (720, m.Location, "`{0}': cannot declare indexers in a static class", m.GetSignatureForError ());
                                        continue;
@@ -2997,19 +2763,17 @@ namespace Mono.CSharp {
                        base.DefineContainerMembers (list);
                }
 
-               public override TypeBuilder DefineType ()
+               public override bool Define ()
                {
                        if ((ModFlags & Modifiers.ABSTRACT) == Modifiers.ABSTRACT && (ModFlags & (Modifiers.SEALED | Modifiers.STATIC)) != 0) {
                                Report.Error (418, Location, "`{0}': an abstract class cannot be sealed or static", GetSignatureForError ());
-                               return null;
                        }
 
                        if ((ModFlags & (Modifiers.SEALED | Modifiers.STATIC)) == (Modifiers.SEALED | Modifiers.STATIC)) {
                                Report.Error (441, Location, "`{0}': a class cannot be both static and sealed", GetSignatureForError ());
-                               return null;
                        }
 
-                       return base.DefineType ();
+                       return base.Define ();
                }
 
                protected override bool DoDefineMembers ()
@@ -3030,9 +2794,9 @@ namespace Mono.CSharp {
 #endif                 
                }
 
-               public override TypeExpr[] GetClassBases (out TypeExpr base_class)
+               protected override TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
                {
-                       TypeExpr[] ifaces = base.GetClassBases (out base_class);
+                       TypeExpr[] ifaces = base.ResolveBaseTypes (out base_class);
 
                        if (base_class == null) {
                                if (RootContext.StdLib)
@@ -3048,9 +2812,10 @@ namespace Mono.CSharp {
                                        return ifaces;
                                }
 
-                               if (base_class.Type.IsArray || base_class.Type.IsPointer) {
-                                       Report.Error (1521, base_class.Location, "Invalid base type");
-                                       return ifaces;
+                               if (IsGeneric && TypeManager.IsAttributeType (base_class.Type)) {
+                                       Report.Error (698, base_class.Location,
+                                               "A generic type cannot derive from `{0}' because it is an attribute class",
+                                               base_class.GetSignatureForError ());
                                }
 
                                if (base_class.IsSealed){
@@ -3117,7 +2882,7 @@ namespace Mono.CSharp {
 
                        foreach (Attribute a in attrs) {
                                string condition = a.GetConditionalAttributeValue ();
-                               if (RootContext.AllDefines.Contains (condition))
+                               if (Location.CompilationUnit.IsConditionalDefined (condition))
                                        return false;
                        }
 
@@ -3173,21 +2938,33 @@ namespace Mono.CSharp {
                        this.ModFlags |= Modifiers.SEALED;
                }
 
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+               {
+                       base.ApplyAttributeBuilder (a, cb);
+
+                       //
+                       // When struct constains fixed fixed and struct layout has explicitly
+                       // set CharSet, its value has to be propagated to compiler generated
+                       // fixed field types
+                       //
+                       if (a.Type == TypeManager.struct_layout_attribute_type && Fields != null && a.HasField ("CharSet")) {
+                               for (int i = 0; i < Fields.Count; ++i) {
+                                       FixedField ff = Fields [i] as FixedField;
+                                       if (ff != null)
+                                               ff.SetCharSet (TypeBuilder.Attributes);
+                               }
+                       }
+               }
+
                public override AttributeTargets AttributeTargets {
                        get {
                                return AttributeTargets.Struct;
                        }
                }
 
-               const TypeAttributes DefaultTypeAttributes =
-                       TypeAttributes.SequentialLayout |
-                       TypeAttributes.Sealed |
-                       TypeAttributes.BeforeFieldInit;
-
-
-               public override TypeExpr[] GetClassBases (out TypeExpr base_class)
+               protected override TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
                {
-                       TypeExpr[] ifaces = base.GetClassBases (out base_class);
+                       TypeExpr[] ifaces = base.ResolveBaseTypes (out base_class);
                        //
                        // If we are compiling our runtime,
                        // and we are defining ValueType, then our
@@ -3210,6 +2987,11 @@ namespace Mono.CSharp {
                //
                protected override TypeAttributes TypeAttr {
                        get {
+                               const TypeAttributes DefaultTypeAttributes =
+                                       TypeAttributes.SequentialLayout |
+                                       TypeAttributes.Sealed |
+                                       TypeAttributes.BeforeFieldInit;
+
                                return base.TypeAttr | DefaultTypeAttributes;
                        }
                }
@@ -3273,13 +3055,13 @@ namespace Mono.CSharp {
                        }
                }
 
-               const TypeAttributes DefaultTypeAttributes =
-                       TypeAttributes.AutoLayout |
-                       TypeAttributes.Abstract |
-                       TypeAttributes.Interface;
-
                protected override TypeAttributes TypeAttr {
                        get {
+                               const TypeAttributes DefaultTypeAttributes =
+                                       TypeAttributes.AutoLayout |
+                                       TypeAttributes.Abstract |
+                                       TypeAttributes.Interface;
+
                                return base.TypeAttr | DefaultTypeAttributes;
                        }
                }
@@ -3309,9 +3091,9 @@ namespace Mono.CSharp {
        public abstract class PropertyBasedMember : InterfaceMemberBase
        {
                public PropertyBasedMember (DeclSpace parent, GenericMethod generic,
-                       Expression type, int mod, int allowed_mod, bool is_iface,
+                       FullNamedExpression type, int mod, int allowed_mod,
                        MemberName name, Attributes attrs)
-                       : base (parent, generic, type, mod, allowed_mod, is_iface, name, attrs)
+                       : base (parent, generic, type, mod, allowed_mod, name, attrs)
                {
                }
 
@@ -3321,7 +3103,7 @@ namespace Mono.CSharp {
                                return false;
 
                        if (!AttributeTester.IsClsCompliant (MemberType)) {
-                               Report.Error (3003, Location, "Type of `{0}' is not CLS-compliant",
+                               Report.Warning (3003, 1, Location, "Type of `{0}' is not CLS-compliant",
                                        GetSignatureForError ());
                        }
                        return true;
@@ -3336,9 +3118,9 @@ namespace Mono.CSharp {
                protected ToplevelBlock block;
 
                public MethodCore (DeclSpace parent, GenericMethod generic,
-                       Expression type, int mod, int allowed_mod, bool is_iface,
+                       FullNamedExpression type, int mod, int allowed_mod,
                        MemberName name, Attributes attrs, Parameters parameters)
-                       : base (parent, generic, type, mod, allowed_mod, is_iface, name, attrs)
+                       : base (parent, generic, type, mod, allowed_mod, name, attrs)
                {
                        Parameters = parameters;
                }
@@ -3375,23 +3157,7 @@ namespace Mono.CSharp {
                        if (!DefineParameters (Parameters))
                                return false;
 
-                       if ((caching_flags & Flags.MethodOverloadsExist) != 0) {
-                               if (!Parent.MemberCache.CheckExistingMembersOverloads (this,
-                                       MemberName.IsGeneric ? MemberName.Basename : MemberName.MethodName, Parameters))
-                                       return false;
-
-                               // TODO: Find a better way how to check reserved accessors collision
-                               Method m = this as Method;
-                               if (m != null) {
-                                       if (!m.CheckForDuplications ())
-                                               return false;
-                               }
-                       }
-
-                       if (!base.CheckBase ())
-                               return false;
-
-                       return true;
+                       return base.CheckBase ();
                }
 
                //
@@ -3430,12 +3196,7 @@ namespace Mono.CSharp {
                                return true;
                        }
 
-                       return false;
-               }
-
-               public virtual void SetYields ()
-               {
-                       ModFlags |= Modifiers.METHOD_YIELDS;
+                       return base.EnableOverloadChecks (overload);
                }
 
                protected override bool VerifyClsCompliance ()
@@ -3444,11 +3205,11 @@ namespace Mono.CSharp {
                                return false;
 
                        if (Parameters.HasArglist) {
-                               Report.Error (3000, Location, "Methods with variable arguments are not CLS-compliant");
+                               Report.Warning (3000, 1, Location, "Methods with variable arguments are not CLS-compliant");
                        }
 
                        if (!AttributeTester.IsClsCompliant (MemberType)) {
-                               Report.Error (3002, Location, "Return type of `{0}' is not CLS-compliant",
+                               Report.Warning (3002, 1, Location, "Return type of `{0}' is not CLS-compliant",
                                        GetSignatureForError ());
                        }
 
@@ -3485,12 +3246,12 @@ namespace Mono.CSharp {
                public MethodAttributes flags;
 
                public InterfaceMemberBase (DeclSpace parent, GenericMethod generic,
-                                  Expression type, int mod, int allowed_mod, bool is_iface,
+                                  FullNamedExpression type, int mod, int allowed_mod,
                                   MemberName name, Attributes attrs)
                        : base (parent, generic, type, mod, allowed_mod, Modifiers.PRIVATE,
                                name, attrs)
                {
-                       IsInterface = is_iface;
+                       IsInterface = parent.PartialContainer.Kind == Kind.Interface;
                        IsExplicitImpl = (MemberName.Left != null);
                        explicit_mod_flags = mod;
                }
@@ -3499,6 +3260,9 @@ namespace Mono.CSharp {
                {
                        if (!base.CheckBase ())
                                return false;
+
+                       if ((caching_flags & Flags.MethodOverloadsExist) != 0)
+                               CheckForDuplications ();
                        
                        if (IsExplicitImpl)
                                return true;
@@ -3563,7 +3327,7 @@ namespace Mono.CSharp {
                        }
 
                        if ((ModFlags & Modifiers.NEW) == 0) {
-                               if (this is Method && conflict_symbol is MethodBase)
+                               if (this is MethodOrOperator && conflict_symbol.MemberType == MemberTypes.Method)
                                        return true;
 
                                Report.SymbolRelatedToPreviousError (conflict_symbol);
@@ -3574,6 +3338,12 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               protected virtual bool CheckForDuplications ()
+               {
+                       return Parent.MemberCache.CheckExistingMembersOverloads (
+                               this, GetFullName (MemberName), Parameters.EmptyReadOnlyParameters);
+               }
+
                //
                // Performs various checks on the MethodInfo `mb' regarding the modifier flags
                // that have been defined.
@@ -3608,7 +3378,7 @@ namespace Mono.CSharp {
                                MethodAttributes base_classp = base_method.Attributes & MethodAttributes.MemberAccessMask;
 
                                if (!CheckAccessModifiers (thisp, base_classp, base_method)) {
-                                       Error_CannotChangeAccessModifiers (base_method, base_classp, null);
+                                       Error_CannotChangeAccessModifiers (Location, base_method, base_classp, null);
                                        ok = false;
                                }
 
@@ -3692,64 +3462,35 @@ namespace Mono.CSharp {
                                return false;
 
                        bool error = false;
-                       foreach (Parameter p in parameters.FixedParameters) {
+                       for (int i = 0; i < parameters.Count; ++i) {
+                               Parameter p = parameters [i];
                                if (p.CheckAccessibility (this))
                                        continue;
 
-                               Report.SymbolRelatedToPreviousError (p.ParameterType);
+                               Type t = parameters.Types [i];
+                               Report.SymbolRelatedToPreviousError (t);
                                if (this is Indexer)
                                        Report.Error (55, Location,
-                                               "Inconsistent accessibility: parameter type `" +
-                                               TypeManager.CSharpName (p.ParameterType) + "' is less " +
-                                               "accessible than indexer `" + GetSignatureForError () + "'");
+                                                     "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 `" +
-                                               TypeManager.CSharpName (p.ParameterType) + "' is less " +
-                                               "accessible than operator `" + GetSignatureForError () + "'");
+                                                     "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 (p.ParameterType), GetSignatureForError ());
+                                               TypeManager.CSharpName (t), GetSignatureForError ());
                                error = true;
                        }
                        return !error;
                }
 
-               protected override bool DoDefine()
-               {
-                       if (!base.DoDefine ())
-                               return false;
-
-                       if (IsExplicitImpl) {
-                               Expression expr = MemberName.Left.GetTypeExpression ();
-                               TypeExpr texpr = expr.ResolveAsTypeTerminal (this, false);
-                               if (texpr == null)
-                                       return false;
-
-                               InterfaceType = texpr.Type;
-
-                               if (!InterfaceType.IsInterface) {
-                                       Report.Error (538, Location, "`{0}' in explicit interface declaration is not an interface", TypeManager.CSharpName (InterfaceType));
-                                       return false;
-                               }
-                               
-                               if (!Parent.PartialContainer.VerifyImplements (this))
-                                       return false;
-                               
-                       }
-                       return true;
-               }
-
-               protected virtual bool DoDefineBase ()
+               protected bool DoDefineBase ()
                {
-                       if (Name == null)
-                               throw new InternalErrorException ();
-
                        if (IsInterface) {
-                               ModFlags = Modifiers.PUBLIC |
-                                       Modifiers.ABSTRACT |
-                                       Modifiers.VIRTUAL | (ModFlags & Modifiers.UNSAFE) | (ModFlags & Modifiers.NEW);
+                               ModFlags = Modifiers.PUBLIC | Modifiers.ABSTRACT |
+                                       Modifiers.VIRTUAL | (ModFlags & (Modifiers.UNSAFE | Modifiers.NEW));
 
                                flags = MethodAttributes.Public |
                                        MethodAttributes.Abstract |
@@ -3764,26 +3505,24 @@ namespace Mono.CSharp {
                        }
 
                        if (IsExplicitImpl) {
-                               Expression expr = MemberName.Left.GetTypeExpression ();
-                               TypeExpr iface_texpr = expr.ResolveAsTypeTerminal (this, false);
+                               TypeExpr iface_texpr = MemberName.Left.GetTypeExpression ().ResolveAsTypeTerminal (this, false);
                                if (iface_texpr == null)
                                        return false;
 
                                if ((ModFlags & Modifiers.PARTIAL) != 0) {
                                        Report.Error (754, Location, "A partial method `{0}' cannot explicitly implement an interface",
                                                GetSignatureForError ());
-                                       return false;
                                }
 
                                InterfaceType = iface_texpr.Type;
 
                                if (!InterfaceType.IsInterface) {
-                                       Report.Error (538, Location, "'{0}' in explicit interface declaration is not an interface", TypeManager.CSharpName (InterfaceType));
-                                       return false;
+                                       Report.SymbolRelatedToPreviousError (InterfaceType);
+                                       Report.Error (538, Location, "The type `{0}' in explicit interface declaration is not an interface",
+                                               TypeManager.CSharpName (InterfaceType));
+                               } else {
+                                       Parent.PartialContainer.VerifyImplements (this);
                                }
-
-                               if (!Parent.PartialContainer.VerifyImplements (this))
-                                       return false;
                                
                                Modifiers.Check (Modifiers.AllowedExplicitImplFlags, explicit_mod_flags, 0, Location);
                        }
@@ -3804,7 +3543,24 @@ namespace Mono.CSharp {
                        base.Emit ();
                }
 
-               protected void Error_CannotChangeAccessModifiers (MemberInfo base_method, MethodAttributes ma, string suffix)
+               public override bool EnableOverloadChecks (MemberCore overload)
+               {
+                       //
+                       // Two members can differ in their explicit interface
+                       // type parameter only
+                       //
+                       InterfaceMemberBase imb = overload as InterfaceMemberBase;
+                       if (imb != null && imb.IsExplicitImpl) {
+                               if (IsExplicitImpl) {
+                                       caching_flags |= Flags.MethodOverloadsExist;
+                               }
+                               return true;
+                       }
+
+                       return IsExplicitImpl;
+               }
+
+               protected void Error_CannotChangeAccessModifiers (Location loc, MemberInfo base_method, MethodAttributes ma, string suffix)
                {
                        Report.SymbolRelatedToPreviousError (base_method);
                        string base_name = TypeManager.GetFullNameSignature (base_method);
@@ -3814,7 +3570,7 @@ namespace Mono.CSharp {
                                this_name += suffix;
                        }
 
-                       Report.Error (507, Location, "`{0}': cannot change access modifiers when overriding `{1}' inherited member `{2}'",
+                       Report.Error (507, loc, "`{0}': cannot change access modifiers when overriding `{1}' inherited member `{2}'",
                                this_name, Modifiers.GetDescription (ma), base_name);
                }
 
@@ -3839,23 +3595,34 @@ namespace Mono.CSharp {
                        set { SetMemberName (new MemberName (MemberName.Left, value, Location)); }
                }
                
+               //
+               // Returns full metadata method name
+               //
                public string GetFullName (MemberName name)
                {
                        if (!IsExplicitImpl)
                                return name.Name;
 
-                       return InterfaceType.FullName.Replace ('+', '.') + "." + name.Name;
+                       //
+                       // When dealing with explicit members a full interface type
+                       // name is added to member name to avoid possible name conflicts
+                       //
+                       // We use CSharpName which gets us full name with benefit of
+                       // replacing predefined names which saves some space and name
+                       // is still unique
+                       //
+                       return TypeManager.CSharpName (InterfaceType) + "." + name.Name;
                }
 
                protected override bool VerifyClsCompliance ()
                {
                        if (!base.VerifyClsCompliance ()) {
                                if (IsInterface && HasClsCompliantAttribute && Parent.IsClsComplianceRequired ()) {
-                                       Report.Error (3010, Location, "`{0}': CLS-compliant interfaces must have only CLS-compliant members", GetSignatureForError ());
+                                       Report.Warning (3010, 1, Location, "`{0}': CLS-compliant interfaces must have only CLS-compliant members", GetSignatureForError ());
                                }
 
                                if ((ModFlags & Modifiers.ABSTRACT) != 0 && Parent.TypeBuilder.IsClass && IsExposedFromAssembly () && Parent.IsClsComplianceRequired ()) {
-                                       Report.Error (3011, Location, "`{0}': only CLS-compliant members can be abstract", GetSignatureForError ());
+                                       Report.Warning (3011, 1, Location, "`{0}': only CLS-compliant members can be abstract", GetSignatureForError ());
                                }
                                return false;
                        }
@@ -3880,15 +3647,12 @@ namespace Mono.CSharp {
                ListDictionary declarative_security;
                protected MethodData MethodData;
 
-               Iterator iterator;
-               ArrayList anonymous_methods;
-
                static string[] attribute_targets = new string [] { "method", "return" };
 
-               protected MethodOrOperator (DeclSpace parent, GenericMethod generic, Expression type, int mod,
-                               int allowed_mod, bool is_interface, MemberName name,
+               protected MethodOrOperator (DeclSpace parent, GenericMethod generic, FullNamedExpression type, int mod,
+                               int allowed_mod, MemberName name,
                                Attributes attrs, Parameters parameters)
-                       : base (parent, generic, type, mod, allowed_mod, is_interface, name,
+                       : base (parent, generic, type, mod, allowed_mod, name,
                                        attrs, parameters)
                {
                }
@@ -3932,64 +3696,34 @@ namespace Mono.CSharp {
                        }
                }
 
-               public virtual EmitContext CreateEmitContext (DeclSpace tc, ILGenerator ig)
+               protected override bool CheckForDuplications ()
                {
-                       return new EmitContext (
-                               this, tc, this.ds, Location, ig, MemberType, ModFlags, false);
+                       string name = GetFullName (MemberName);
+                       if (MemberName.IsGeneric)
+                               name = MemberName.MakeName (name, MemberName.TypeArguments);
+
+                       return Parent.MemberCache.CheckExistingMembersOverloads (this, name, Parameters);
                }
 
-               public void AddAnonymousMethod (AnonymousMethodExpression anonymous)
+               public virtual EmitContext CreateEmitContext (DeclSpace tc, ILGenerator ig)
                {
-                       if (anonymous_methods == null)
-                               anonymous_methods = new ArrayList ();
-                       anonymous_methods.Add (anonymous);
+                       return new EmitContext (
+                               this, tc, this.ds, Location, ig, MemberType, ModFlags, false);
                }
 
-               protected bool DefineGenericMethod ()
+               public override bool Define ()
                {
                        if (!DoDefineBase ())
                                return false;
 
 #if GMCS_SOURCE
                        if (GenericMethod != null) {
-
-#if MS_COMPATIBLE
-                               MethodBuilder = Parent.TypeBuilder.DefineMethod (GetFullName (MemberName), flags); //, ReturnType, null);
-#else
                                MethodBuilder = Parent.TypeBuilder.DefineMethod (GetFullName (MemberName), flags);
-#endif
-
-                               if (!GenericMethod.Define (MethodBuilder, block))
+                               if (!GenericMethod.Define (MethodBuilder))
                                        return false;
                        }
 #endif
 
-                       return true;
-               }
-
-               public bool ResolveMembers ()
-               {
-                       if (!DefineGenericMethod ())
-                               return false;
-
-                       if ((ModFlags & Modifiers.METHOD_YIELDS) != 0) {
-                               iterator = Iterator.CreateIterator (this, Parent, GenericMethod, ModFlags);
-                               if (iterator == null)
-                                       return false;
-                       }
-
-                       if (anonymous_methods != null) {
-                               foreach (AnonymousMethodExpression ame in anonymous_methods) {
-                                       if (!ame.CreateAnonymousHelpers ())
-                                               return false;
-                               }
-                       }
-
-                       return true;
-               }
-
-               public override bool Define ()
-               {
                        if (!DoDefine ())
                                return false;
 
@@ -3998,7 +3732,7 @@ namespace Mono.CSharp {
 
                        if ((ModFlags & Modifiers.PARTIAL) != 0) {
                                for (int i = 0; i < Parameters.Count; ++i ) {
-                                       if (Parameters.ParameterModifier (i) == Parameter.Modifier.OUT) {
+                                       if (Parameters.FixedParameters [i].ModFlags == Parameter.Modifier.OUT) {
                                                Report.Error (752, Location, "`{0}': A partial method parameters cannot use `out' modifier",
                                                        GetSignatureForError ());
                                                return false;
@@ -4008,7 +3742,16 @@ namespace Mono.CSharp {
 
                        if (!CheckBase ())
                                return false;
-                       
+
+                       if (block != null && block.IsIterator && !(Parent is IteratorStorey)) {
+                               //
+                               // Current method is turned into automatically generated
+                               // wrapper which creates an instance of iterator
+                               //
+                               Iterator.CreateIterator (this, Parent.PartialContainer, ModFlags);
+                               ModFlags |= Modifiers.DEBUGGER_HIDDEN;
+                       }
+
                        if (IsPartialDefinition) {
                                caching_flags &= ~Flags.Excluded_Undetected;
                                caching_flags |= Flags.Excluded;
@@ -4050,8 +3793,10 @@ namespace Mono.CSharp {
                public override void Emit ()
                {
 #if GMCS_SOURCE                        
-                       if ((ModFlags & Modifiers.COMPILER_GENERATED) != 0)
+                       if ((ModFlags & Modifiers.COMPILER_GENERATED) != 0 && !Parent.IsCompilerGenerated)
                                MethodBuilder.SetCustomAttribute (TypeManager.GetCompilerGeneratedAttribute (Location));
+                       if ((ModFlags & Modifiers.DEBUGGER_HIDDEN) != 0)
+                               MethodBuilder.SetCustomAttribute (TypeManager.GetDebuggerHiddenAttribute (Location));
 #endif
                        if (OptAttributes != null)
                                OptAttributes.Emit ();
@@ -4095,9 +3840,6 @@ namespace Mono.CSharp {
                public CallingConventions CallingConventions {
                        get {
                                CallingConventions cc = Parameters.CallingConvention;
-                               if (Parameters.HasArglist && block != null)
-                                       block.HasVarargs = true;
-
                                if (!IsInterface)
                                        if ((ModFlags & Modifiers.STATIC) == 0)
                                                cc |= CallingConventions.HasThis;
@@ -4120,16 +3862,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               public Iterator Iterator {
-                       get { return iterator; }
-               }
-
-               public new Location Location {
-                       get {
-                               return base.Location;
-                       }
-               }
-
                protected override bool CheckBase ()
                {
                        if (!base.CheckBase ())
@@ -4171,7 +3903,7 @@ namespace Mono.CSharp {
                                        if (condition == null)
                                                return false;
 
-                                       if (RootContext.AllDefines.Contains (condition))
+                                       if (Location.CompilationUnit.IsConditionalDefined (condition))
                                                return false;
                                }
 
@@ -4181,7 +3913,7 @@ namespace Mono.CSharp {
 
                        IMethodData md = TypeManager.GetMethod (TypeManager.DropGenericMethodArguments (base_method));
                        if (md == null) {
-                               if (AttributeTester.IsConditionalMethodExcluded (base_method)) {
+                               if (AttributeTester.IsConditionalMethodExcluded (base_method, Location)) {
                                        caching_flags |= Flags.Excluded;
                                        return true;
                                }
@@ -4201,41 +3933,35 @@ namespace Mono.CSharp {
                        }
                }
 
-               public virtual void EmitExtraSymbolInfo ()
+               public virtual void EmitExtraSymbolInfo (SourceMethod source)
                { }
 
                #endregion
 
        }
 
-       public class SourceMethod : ISourceMethod
+       public class SourceMethod : IMethodDef
        {
-               DeclSpace parent;
-               MethodBase builder;
+               MethodBase method;
+               SourceMethodBuilder builder;
 
-               protected SourceMethod (DeclSpace parent, MethodBase builder,
-                                       ISourceFile file, Location start, Location end)
+               protected SourceMethod (DeclSpace parent, MethodBase method, ICompileUnit file)
                {
-                       this.parent = parent;
-                       this.builder = builder;
+                       this.method = method;
                        
-                       SymbolWriter.OpenMethod (file, this, start.Row, start.Column, end.Row, start.Column);
+                       builder = SymbolWriter.OpenMethod (file, parent.NamespaceEntry.SymbolFileID, this);
                }
 
                public string Name {
-                       get { return builder.Name; }
-               }
-
-               public int NamespaceID {
-                       get { return parent.NamespaceEntry.SymbolFileID; }
+                       get { return method.Name; }
                }
 
                public int Token {
                        get {
-                               if (builder is MethodBuilder)
-                                       return ((MethodBuilder) builder).GetToken ().Token;
-                               else if (builder is ConstructorBuilder)
-                                       return ((ConstructorBuilder) builder).GetToken ().Token;
+                               if (method is MethodBuilder)
+                                       return ((MethodBuilder) method).GetToken ().Token;
+                               else if (method is ConstructorBuilder)
+                                       return ((ConstructorBuilder) method).GetToken ().Token;
                                else
                                        throw new NotSupportedException ();
                        }
@@ -4246,7 +3972,13 @@ namespace Mono.CSharp {
                        SymbolWriter.CloseMethod ();
                }
 
-               public static SourceMethod Create (DeclSpace parent, MethodBase builder, Block block)
+               public void SetRealMethodName (string name)
+               {
+                       if (builder != null)
+                               builder.SetRealMethodName (name);
+               }
+
+               public static SourceMethod Create (DeclSpace parent, MethodBase method, Block block)
                {
                        if (!SymbolWriter.HasSymbolWriter)
                                return null;
@@ -4257,20 +3989,15 @@ namespace Mono.CSharp {
                        if (start_loc.IsNull)
                                return null;
 
-                       Location end_loc = block.EndLocation;
-                       if (end_loc.IsNull)
+                       ICompileUnit compile_unit = start_loc.CompilationUnit;
+                       if (compile_unit == null)
                                return null;
 
-                       ISourceFile file = start_loc.SourceFile;
-                       if (file == null)
-                               return null;
-
-                       return new SourceMethod (
-                               parent, builder, file, start_loc, end_loc);
+                       return new SourceMethod (parent, method, compile_unit);
                }
        }
 
-       public class Method : MethodOrOperator, IAnonymousHost {
+       public class Method : MethodOrOperator {
 
                /// <summary>
                ///   Modifiers allowed in a class declaration
@@ -4286,22 +4013,24 @@ namespace Mono.CSharp {
                        Modifiers.SEALED |
                        Modifiers.OVERRIDE |
                        Modifiers.ABSTRACT |
-                       Modifiers.UNSAFE |
-                       Modifiers.METHOD_YIELDS | 
+                       Modifiers.UNSAFE |
                        Modifiers.EXTERN;
 
                const int AllowedInterfaceModifiers =
                        Modifiers.NEW | Modifiers.UNSAFE;
 
-               //
-               // return_type can be "null" for VOID values.
-               //
                public Method (DeclSpace parent, GenericMethod generic,
-                              Expression return_type, int mod, bool is_iface,
+                              FullNamedExpression return_type, int mod,
                               MemberName name, Parameters parameters, Attributes attrs)
                        : base (parent, generic, return_type, mod,
-                               is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
-                               is_iface, name, attrs, parameters)
+                               parent.PartialContainer.Kind == Kind.Interface ? AllowedInterfaceModifiers : AllowedModifiers,
+                               name, attrs, parameters)
+               {
+               }
+
+               protected Method (DeclSpace parent, FullNamedExpression return_type, int mod, int amod,
+                                       MemberName name, Parameters parameters, Attributes attrs)
+                       : base (parent, null, return_type, mod, amod, name, attrs, parameters)
                {
                }
                
@@ -4329,7 +4058,7 @@ namespace Mono.CSharp {
                        if (Parameters.Count > 1)
                                return false;
 
-                       Type t = Parameters.ParameterType (0);
+                       Type t = Parameters.Types [0];
                        return t.IsArray && t.GetArrayRank () == 1 &&
                                        TypeManager.GetElementType (t) == TypeManager.string_type &&
                                        (Parameters[0].ModFlags & ~Parameter.Modifier.PARAMS) == Parameter.Modifier.NONE;
@@ -4366,7 +4095,7 @@ namespace Mono.CSharp {
                                }
 
                                for (int i = 0; i < Parameters.Count; ++i) {
-                                       if ((Parameters.ParameterModifier (i) & Parameter.Modifier.OUTMASK) != 0) {
+                                       if (Parameters.FixedParameters [i].ModFlags == Parameter.Modifier.OUT) {
                                                Report.Error (685, Location, "Conditional method `{0}' cannot have an out parameter", GetSignatureForError ());
                                                return;
                                        }
@@ -4381,8 +4110,11 @@ namespace Mono.CSharp {
                        base.ApplyAttributeBuilder (a, cb);
                }
 
-               public bool CheckForDuplications ()
+               protected override bool CheckForDuplications ()
                {
+                       if (!base.CheckForDuplications ())
+                               return false;
+
                        ArrayList ar = Parent.PartialContainer.Properties;
                        if (ar != null) {
                                for (int i = 0; i < ar.Count; ++i) {
@@ -4412,12 +4144,12 @@ namespace Mono.CSharp {
                        if (!base.Define ())
                                return false;
 
-                       if (RootContext.StdLib && (ReturnType == TypeManager.arg_iterator_type || ReturnType == TypeManager.typed_reference_type)) {
+                       if (RootContext.StdLib && TypeManager.IsSpecialType (ReturnType)) {
                                Error1599 (Location, ReturnType);
                                return false;
                        }
 
-                       if (ReturnType == TypeManager.void_type && ParameterTypes.Length == 0 && 
+                       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?");
                        }
@@ -4425,7 +4157,7 @@ namespace Mono.CSharp {
                        if (base_method != null && (ModFlags & Modifiers.NEW) == 0) {
                                if (Parameters.Count == 1 && ParameterTypes [0] == TypeManager.object_type && Name == "Equals")
                                        Parent.PartialContainer.Mark_HasEquals ();
-                               else if (Parameters.Empty && Name == "GetHashCode")
+                               else if (Parameters.IsEmpty && Name == "GetHashCode")
                                        Parent.PartialContainer.Mark_HasGetHashCode ();
                        }
 
@@ -4550,7 +4282,7 @@ namespace Mono.CSharp {
                protected override MethodInfo FindOutBaseMethod (ref Type base_ret_type)
                {
                        MethodInfo mi = (MethodInfo) Parent.PartialContainer.BaseCache.FindMemberToOverride (
-                               Parent.TypeBuilder, Name, ParameterTypes, GenericMethod, false);
+                               Parent.TypeBuilder, Name, Parameters, GenericMethod, false);
 
                        if (mi == null)
                                return null;
@@ -4591,7 +4323,7 @@ namespace Mono.CSharp {
                }
        }
 
-       public abstract class ConstructorInitializer : Expression
+       public abstract class ConstructorInitializer : ExpressionStatement
        {
                ArrayList argument_list;
                MethodGroupExpr base_constructor_group;
@@ -4608,6 +4340,11 @@ namespace Mono.CSharp {
                        }
                }
 
+               public override Expression CreateExpressionTree (EmitContext ec)
+               {
+                       throw new NotSupportedException ("ET");
+               }
+
                public bool Resolve (ConstructorBuilder caller_builder, EmitContext ec)
                {
                        if (argument_list != null){
@@ -4674,12 +4411,17 @@ namespace Mono.CSharp {
                        if (base_constructor_group == null)
                                return;
                        
-                       ec.Mark (loc, false);
+                       ec.Mark (loc);
                        if (!ec.IsStatic)
                                base_constructor_group.InstanceExpression = ec.GetThis (loc);
                        
                        base_constructor_group.EmitCall (ec, argument_list);
                }
+
+               public override void EmitStatement (EmitContext ec)
+               {
+                       Emit (ec);
+               }
        }
 
        public class ConstructorBaseInitializer : ConstructorInitializer {
@@ -4703,11 +4445,10 @@ namespace Mono.CSharp {
                }
        }
        
-       public class Constructor : MethodCore, IMethodData, IAnonymousHost {
+       public class Constructor : MethodCore, IMethodData {
                public ConstructorBuilder ConstructorBuilder;
                public ConstructorInitializer Initializer;
                ListDictionary declarative_security;
-               ArrayList anonymous_methods;
                bool has_compliant_args;
 
                // <summary>
@@ -4728,10 +4469,10 @@ 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, Parameters args,
+               public Constructor (DeclSpace parent, string name, int mod, Attributes attrs, Parameters args,
                                    ConstructorInitializer init, Location loc)
-                       : base (parent, null, null, mod, AllowedModifiers, false,
-                               new MemberName (name, loc), null, args)
+                       : base (parent, null, null, mod, AllowedModifiers,
+                               new MemberName (name, loc), attrs, args)
                {
                        Initializer = init;
                }
@@ -4744,19 +4485,15 @@ namespace Mono.CSharp {
                        get { return AttributeTargets.Constructor; }
                }
 
-               public Iterator Iterator {
-                       get { return null; }
-               }
-
                //
                // Returns true if this is a default constructor
                //
                public bool IsDefault ()
                {
                        if ((ModFlags & Modifiers.STATIC) != 0)
-                               return Parameters.Empty;
+                               return Parameters.IsEmpty;
                        
-                       return Parameters.Empty &&
+                       return Parameters.IsEmpty &&
                                        (Initializer is ConstructorBaseInitializer) &&
                                        (Initializer.Arguments == null);
                }
@@ -4778,29 +4515,10 @@ namespace Mono.CSharp {
                        ConstructorBuilder.SetCustomAttribute (cb);
                }
 
-               public void AddAnonymousMethod (AnonymousMethodExpression anonymous)
-               {
-                       if (anonymous_methods == null)
-                               anonymous_methods = new ArrayList ();
-                       anonymous_methods.Add (anonymous);
-               }
-
-               public bool ResolveMembers ()
-               {
-                       if (anonymous_methods != null) {
-                               foreach (AnonymousMethodExpression ame in anonymous_methods) {
-                                       if (!ame.CreateAnonymousHelpers ())
-                                               return false;
-                               }
-                       }
-
-                       return true;
-               }
-
                protected override bool CheckBase ()
                {
                        if ((ModFlags & Modifiers.STATIC) != 0) {
-                               if (!Parameters.Empty) {
+                               if (!Parameters.IsEmpty) {
                                        Report.Error (132, Location, "`{0}': The static constructor must be parameterless",
                                                GetSignatureForError ());
                                        return false;
@@ -4815,11 +4533,11 @@ namespace Mono.CSharp {
                                return false;
 
                        if ((caching_flags & Flags.MethodOverloadsExist) != 0)
-                               Parent.MemberCache.CheckExistingMembersOverloads (this, ConstructorBuilder.ConstructorName,
+                               Parent.MemberCache.CheckExistingMembersOverloads (this, ConstructorInfo.ConstructorName,
                                        Parameters);
 
                        if (Parent.PartialContainer.Kind == Kind.Struct) {
-                               if (ParameterTypes.Length == 0) {
+                               if (Parameters.Count == 0) {
                                        Report.Error (568, Location, 
                                                "Structs cannot contain explicit parameterless constructors");
                                        return false;
@@ -4869,10 +4587,7 @@ namespace Mono.CSharp {
 
                        ConstructorBuilder = Parent.TypeBuilder.DefineConstructor (
                                ca, CallingConventions,
-                               ParameterTypes);
-
-                       if ((ModFlags & Modifiers.UNSAFE) != 0)
-                               ConstructorBuilder.InitLocals = false;
+                               Parameters.GetEmitTypes ());
 
                        if (Parent.PartialContainer.IsComImport) {
                                if (!IsDefault ()) {
@@ -4887,9 +4602,9 @@ namespace Mono.CSharp {
                        TypeManager.AddMethod (ConstructorBuilder, this);
                        
                        // It's here only to report an error
-                       if ((ModFlags & Modifiers.METHOD_YIELDS) != 0) {
+                       if (block != null && block.IsIterator) {
                                member_type = TypeManager.void_type;
-                               Iterator.CreateIterator (this, Parent, null, ModFlags);
+                               Iterator.CreateIterator (this, Parent.PartialContainer, ModFlags);
                        }
 
                        return true;
@@ -4900,6 +4615,9 @@ namespace Mono.CSharp {
                //
                public override void Emit ()
                {
+                       if ((ModFlags & Modifiers.DEBUGGER_HIDDEN) != 0)
+                               ConstructorBuilder.SetCustomAttribute (TypeManager.GetDebuggerHiddenAttribute (Location));
+
                        if (OptAttributes != null)
                                OptAttributes.Emit ();
 
@@ -4926,27 +4644,30 @@ namespace Mono.CSharp {
 
                                if (!block.ResolveMeta (ec, ParameterInfo))
                                        block = null;
-                       }
-
-                       if ((ModFlags & Modifiers.STATIC) == 0){
-                               if (Parent.PartialContainer.Kind == Kind.Class && Initializer == null)
-                                       Initializer = new GeneratedBaseInitializer (Location);
-
-                               //
-                               // Spec mandates that Initializers will not have
-                               // `this' access
-                               //
-                               ec.IsStatic = true;
-                               if ((Initializer != null) &&
-                                   !Initializer.Resolve (ConstructorBuilder, ec))
-                                       return;
-                               ec.IsStatic = false;
+
+                               if (block != null && (ModFlags & Modifiers.STATIC) == 0){
+                                       if (Parent.PartialContainer.Kind == Kind.Class && Initializer == null)
+                                               Initializer = new GeneratedBaseInitializer (Location);
+
+                                       //
+                                       // Spec mandates that Initializers will not have `this' access
+                                       //
+                                       if (Initializer != null) {
+                                               ec.IsStatic = true;
+                                               Initializer.Resolve (ConstructorBuilder, ec);
+                                               ec.IsStatic = false;
+                                               block.AddScopeStatement (new StatementExpression (Initializer));
+                                       }
+                               }
                        }
 
                        Parameters.ApplyAttributes (ConstructorBuilder);
                        
-                       SourceMethod source = SourceMethod.Create (
-                               Parent, ConstructorBuilder, block);
+                       SourceMethod source = null;
+                       if (block == null)
+                               ec.OmitDebuggingInfo = true;
+                       else
+                               source = SourceMethod.Create (Parent, ConstructorBuilder, block);
 
                        bool unreachable = false;
                        if (block != null) {
@@ -4958,17 +4679,6 @@ namespace Mono.CSharp {
                                if (Report.Errors > 0)
                                        return;
 
-                               if (emit_field_initializers)
-                                       Parent.PartialContainer.EmitFieldInitializers (ec);
-
-                               if (block.ScopeInfo != null) {
-                                       ExpressionStatement init = block.ScopeInfo.GetScopeInitializer (ec);
-                                       init.EmitStatement (ec);
-                               }
-
-                               if (Initializer != null)
-                                       Initializer.Emit (ec);
-                       
                                ec.EmitResolvedTopBlock (block, unreachable);
                        }
 
@@ -5013,7 +4723,7 @@ namespace Mono.CSharp {
                                        MemberCache.VerifyClsParameterConflict (al, this, ConstructorBuilder);
  
                                if (TypeManager.IsSubclassOf (Parent.TypeBuilder, TypeManager.attribute_type)) {
-                                       foreach (Type param in ParameterTypes) {
+                                       foreach (Type param in Parameters.Types) {
                                                if (param.IsArray) {
                                                        return true;
                                                }
@@ -5040,12 +4750,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               public new Location Location {
-                       get {
-                               return base.Location;
-                       }
-               }
-
                public MemberName MethodName {
                        get {
                                return MemberName;
@@ -5077,7 +4781,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               void IMethodData.EmitExtraSymbolInfo ()
+               void IMethodData.EmitExtraSymbolInfo (SourceMethod source)
                { }
 
                #endregion
@@ -5095,8 +4799,6 @@ namespace Mono.CSharp {
                GenericMethod GenericMethod { get; }
                Parameters ParameterInfo { get; }
 
-               Iterator Iterator { get; }
-
                Attributes OptAttributes { get; }
                ToplevelBlock Block { get; set; }
 
@@ -5106,15 +4808,17 @@ namespace Mono.CSharp {
                bool IsExcluded ();
                bool IsClsComplianceRequired ();
                void SetMemberIsUsed ();
-               void EmitExtraSymbolInfo ();
+               void EmitExtraSymbolInfo (SourceMethod source);
        }
 
        //
        // Encapsulates most of the Method's state
        //
        public class MethodData {
-
-               readonly IMethodData method;
+#if GMCS_SOURCE
+               static FieldInfo methodbuilder_attrs_field;
+#endif
+               public readonly IMethodData method;
 
                public readonly GenericMethod GenericMethod;
 
@@ -5174,12 +4878,7 @@ namespace Mono.CSharp {
 
                        PendingImplementation pending = container.PendingImplementations;
                        if (pending != null){
-                               if (member is Indexer) // TODO: test it, but it should work without this IF
-                                       implementing = pending.IsInterfaceIndexer (
-                                               member.InterfaceType, method.ReturnType, method.ParameterInfo);
-                               else
-                                       implementing = pending.IsInterfaceMethod (
-                                               member.InterfaceType, name, method.ReturnType, method.ParameterInfo);
+                               implementing = pending.IsInterfaceMethod (name, member.InterfaceType, this);
 
                                if (member.InterfaceType != null){
                                        if (implementing == null){
@@ -5300,7 +4999,7 @@ namespace Mono.CSharp {
                                        flags |= MethodAttributes.Final;
                        }
 
-                       DefineMethodBuilder (container, method_full_name, method.ParameterInfo.Types);
+                       DefineMethodBuilder (container, method_full_name, method.ParameterInfo);
 
                        if (builder == null)
                                return false;
@@ -5310,26 +5009,8 @@ namespace Mono.CSharp {
                        else
                                declaring_type = container.TypeBuilder;
 
-                       if ((modifiers & Modifiers.UNSAFE) != 0)
-                               builder.InitLocals = false;
-
-
-                       if (implementing != null){
-                               //
-                               // clear the pending implemntation flag
-                               //
-                               if (member is Indexer) {
-                                       pending.ImplementIndexer (
-                                               member.InterfaceType, builder, method.ReturnType,
-                                               method.ParameterInfo, member.IsExplicitImpl);
-                               } else
-                                       pending.ImplementMethod (
-                                               member.InterfaceType, name, method.ReturnType,
-                                               method.ParameterInfo, member.IsExplicitImpl);
-
-                               if (member.IsExplicitImpl)
-                                       container.TypeBuilder.DefineMethodOverride (
-                                               builder, implementing);
+                       if (implementing != null && member.IsExplicitImpl) {
+                               container.TypeBuilder.DefineMethodOverride (builder, implementing);
                        }
 
                        TypeManager.AddMethod (builder, method);
@@ -5353,19 +5034,34 @@ namespace Mono.CSharp {
                /// <summary>
                /// Create the MethodBuilder for the method 
                /// </summary>
-               void DefineMethodBuilder (TypeContainer container, string method_name, Type[] ParameterTypes)
+               void DefineMethodBuilder (TypeContainer container, string method_name, Parameters param)
                {
                        if (builder == null) {
                                builder = container.TypeBuilder.DefineMethod (
                                        method_name, flags, method.CallingConventions,
-                                       method.ReturnType, ParameterTypes);
+                                       method.ReturnType, param.GetEmitTypes ());
                                return;
                        }
 
-#if GMCS_SOURCE && !MS_COMPATIBLE
-                       builder.SetGenericMethodSignature (
-                               flags, method.CallingConventions,
-                               method.ReturnType, ParameterTypes);
+#if GMCS_SOURCE
+                       //
+                       // Generic method has been already defined to resolve method parameters
+                       // correctly when they use type parameters
+                       //
+                       builder.SetParameters (param.GetEmitTypes ());
+                       builder.SetReturnType (method.ReturnType);
+
+                       if (builder.Attributes != flags) {
+                               try {
+                                       if (methodbuilder_attrs_field == null)
+                                               methodbuilder_attrs_field = typeof (MethodBuilder).GetField ("attrs", BindingFlags.NonPublic | BindingFlags.Instance);
+                                       methodbuilder_attrs_field.SetValue (builder, flags);
+                               } catch {
+                                       Report.RuntimeMissingSupport (method.Location, "Generic method MethodAttributes");
+                               }
+                       }
+#else
+                       throw new InternalErrorException ();
 #endif
                }
 
@@ -5387,6 +5083,13 @@ namespace Mono.CSharp {
                        if (GenericMethod != null)
                                GenericMethod.EmitAttributes ();
 
+                       //
+                       // clear the pending implementation flag
+                       //
+                       if (implementing != null)
+                               parent.PartialContainer.PendingImplementations.ImplementMethod (method.MethodName.Basename,
+                                       member.InterfaceType, this, member.IsExplicitImpl);
+
                        SourceMethod source = SourceMethod.Create (parent, MethodBuilder, method.Block);
 
                        //
@@ -5400,7 +5103,7 @@ namespace Mono.CSharp {
                                ec.EmitTopBlock (method, block);
 
                        if (source != null) {
-                               method.EmitExtraSymbolInfo ();
+                               method.EmitExtraSymbolInfo (source);
                                source.CloseMethod ();
                        }
                }
@@ -5441,16 +5144,26 @@ namespace Mono.CSharp {
        }
 
        // TODO: Should derive from MethodCore
-       public class Destructor : Method {
+       public class Destructor : Method
+       {
+               const int AllowedModifiers =
+                       Modifiers.UNSAFE |
+                       Modifiers.EXTERN;
 
                static string[] attribute_targets = new string [] { "method" };
 
-               public Destructor (DeclSpace parent, Expression return_type, int mod,
+               public Destructor (DeclSpace parent, FullNamedExpression return_type, int mod,
                                   string name, Parameters parameters, Attributes attrs,
                                   Location l)
-                       : base (parent, null, return_type, mod, false, new MemberName (name, l),
+                       : base (parent, return_type, mod, AllowedModifiers, new MemberName (name, l),
                                parameters, attrs)
-               { }
+               {
+                       ModFlags &= ~Modifiers.PRIVATE;
+                       if (!RootContext.StdLib && parent.Name == "System.Object")
+                               ModFlags |= Modifiers.PROTECTED | Modifiers.VIRTUAL;
+                       else
+                               ModFlags |= Modifiers.PROTECTED | Modifiers.OVERRIDE;
+               }
 
                public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
                {
@@ -5475,7 +5188,7 @@ namespace Mono.CSharp {
        }
        
        abstract public class MemberBase : MemberCore {
-               public Expression Type;
+               protected FullNamedExpression type_name;
                public readonly DeclSpace ds;
                public readonly GenericMethod GenericMethod;
 
@@ -5485,11 +5198,12 @@ namespace Mono.CSharp {
                protected Type member_type;
                public Type MemberType {
                        get {
-                               if (member_type == null && Type != null) {
+                               // TODO: Who wrote this, ResolveAsTypeTerminal can have side effects
+                               if (member_type == null && type_name != null) {
                                        IResolveContext rc = GenericMethod == null ? this : (IResolveContext)ds;
-                                       Type = Type.ResolveAsTypeTerminal (rc, false);
-                                       if (Type != null) {
-                                               member_type = Type.Type;
+                                       type_name = type_name.ResolveAsTypeTerminal (rc, false);
+                                       if (type_name != null) {
+                                               member_type = type_name.Type;
                                        }
                                }
                                return member_type;
@@ -5500,12 +5214,12 @@ namespace Mono.CSharp {
                // The constructor is only exposed to our children
                //
                protected MemberBase (DeclSpace parent, GenericMethod generic,
-                                     Expression type, int mod, int allowed_mod, int def_mod,
+                                     FullNamedExpression type, int mod, int allowed_mod, int def_mod,
                                      MemberName name, Attributes attrs)
                        : base (parent, name, attrs)
                {
                        this.ds = generic != null ? generic : (DeclSpace) parent;
-                       Type = type;
+                       this.type_name = type;
                        ModFlags = Modifiers.Check (allowed_mod, mod, def_mod, Location);
                        GenericMethod = generic;
                        if (GenericMethod != null)
@@ -5569,7 +5283,7 @@ namespace Mono.CSharp {
 
                protected bool IsTypePermitted ()
                {
-                       if (MemberType == TypeManager.arg_iterator_type || MemberType == TypeManager.typed_reference_type) {
+                       if (TypeManager.IsSpecialType (MemberType)) {
                                Report.Error (610, Location, "Field or property cannot be of type `{0}'", TypeManager.CSharpName (MemberType));
                                return false;
                        }
@@ -5592,7 +5306,7 @@ namespace Mono.CSharp {
 
                static readonly string[] attribute_targets = new string [] { "field" };
 
-               protected FieldBase (DeclSpace parent, Expression type, int mod,
+               protected FieldBase (DeclSpace parent, FullNamedExpression type, int mod,
                                     int allowed_mod, MemberName name, Attributes attrs)
                        : base (parent, null, type, mod, allowed_mod | Modifiers.ABSTRACT, Modifiers.PRIVATE,
                                name, attrs)
@@ -5630,6 +5344,7 @@ namespace Mono.CSharp {
                        }
 #endif
 
+#if !NET_2_0
                        if (a.Type == TypeManager.marshal_as_attr_type) {
                                UnmanagedMarshal marshal = a.GetMarshal (this);
                                if (marshal != null) {
@@ -5637,7 +5352,7 @@ namespace Mono.CSharp {
                                }
                                return;
                        }
-
+#endif
                        if ((a.HasSecurityAttribute)) {
                                a.Error_InvalidSecurityParent ();
                                return;
@@ -5670,18 +5385,12 @@ namespace Mono.CSharp {
 
                public override bool Define()
                {
-                       if (MemberType == null || Type == null)
+                       if (MemberType == null || member_type == null)
                                return false;
 
                        if (TypeManager.IsGenericParameter (MemberType))
                                return true;
 
-                       if (MemberType == TypeManager.void_type) {
-                               // TODO: wrong location
-                               Expression.Error_VoidInvalidInTheContext (Location);
-                               return false;
-                       }
-
                        if (MemberType.IsSealed && MemberType.IsAbstract) {
                                Error_VariableOfStaticClass (Location, GetSignatureForError (), MemberType);
                                return false;
@@ -5709,17 +5418,16 @@ namespace Mono.CSharp {
                public override void Emit ()
                {
 #if GMCS_SOURCE
-                       if ((ModFlags & Modifiers.COMPILER_GENERATED) != 0) {
+                       if ((ModFlags & Modifiers.COMPILER_GENERATED) != 0 && !Parent.IsCompilerGenerated)
                                FieldBuilder.SetCustomAttribute (TypeManager.GetCompilerGeneratedAttribute (Location));
-                       }
 #endif
 
                        if (OptAttributes != null) {
                                OptAttributes.Emit ();
                        }
 
-                       if (((status & Status.HAS_OFFSET) == 0) && (ModFlags & Modifiers.STATIC) == 0 && Parent.PartialContainer.HasExplicitLayout) {
-                               Report.Error (625, Location, "`{0}': Instance field types marked with StructLayout(LayoutKind.Explicit) must have a FieldOffset attribute.", GetSignatureForError ());
+                       if (((status & Status.HAS_OFFSET) == 0) && (ModFlags & (Modifiers.STATIC | Modifiers.BACKING_FIELD)) == 0 && Parent.PartialContainer.HasExplicitLayout) {
+                               Report.Error (625, Location, "`{0}': Instance field types marked with StructLayout(LayoutKind.Explicit) must have a FieldOffset attribute", GetSignatureForError ());
                        }
 
                        base.Emit ();
@@ -5762,7 +5470,8 @@ namespace Mono.CSharp {
                                return false;
 
                        if (!IsFieldClsCompliant) {
-                               Report.Error (3003, Location, "Type of `{0}' is not CLS-compliant", GetSignatureForError ());
+                               Report.Warning (3003, 1, Location, "Type of `{0}' is not CLS-compliant",
+                                       GetSignatureForError ());
                        }
                        return true;
                }
@@ -5826,11 +5535,11 @@ namespace Mono.CSharp {
                        Modifiers.INTERNAL |
                        Modifiers.PRIVATE;
 
-               public FixedField (DeclSpace parent, Expression type, int mod, string name,
+               public FixedField (DeclSpace parent, FullNamedExpression type, int mod, string name,
                        Expression size_expr, Attributes attrs, Location loc):
                        base (parent, type, mod, AllowedModifiers, new MemberName (name, loc), attrs)
                {
-                       if (RootContext.Version == LanguageVersion.ISO_1)
+                       if (RootContext.Version < LanguageVersion.ISO_2)
                                Report.FeatureIsNotAvailable (loc, "fixed size buffers");
 
                        this.size_expr = size_expr;
@@ -5851,7 +5560,7 @@ namespace Mono.CSharp {
                        
                        // Create nested fixed buffer container
                        string name = String.Format ("<{0}>__FixedBuffer{1}", Name, GlobalCounter++);
-                       fixed_buffer_type = Parent.TypeBuilder.DefineNestedType (name,
+                       fixed_buffer_type = Parent.TypeBuilder.DefineNestedType (name, CodeGen.Module.DefaultCharSetType |
                                TypeAttributes.NestedPublic | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit, TypeManager.value_type);
                        
                        element = fixed_buffer_type.DefineField (FixedElementName, MemberType, FieldAttributes.Public);
@@ -5875,8 +5584,8 @@ namespace Mono.CSharp {
                        Constant c = size_expr.ResolveAsConstant (ec, this);
                        if (c == null)
                                return;
-
-                       IntConstant buffer_size_const = c.ImplicitConversionRequired (TypeManager.int32_type, Location) as IntConstant;
+                       
+                       IntConstant buffer_size_const = c.ImplicitConversionRequired (ec, TypeManager.int32_type, Location) as IntConstant;
                        if (buffer_size_const == null)
                                return;
 
@@ -5897,6 +5606,28 @@ namespace Mono.CSharp {
 
                        buffer_size *= type_size;
                        EmitFieldSize (buffer_size);
+
+#if GMCS_SOURCE
+                       //
+                       // Emit compiler generated fixed buffer type attribute
+                       //
+                       CustomAttributeBuilder cab = TypeManager.unsafe_value_type_attr;
+                       if (cab == null) {
+                               Type attr_type = TypeManager.CoreLookupType (
+                                       "System.Runtime.CompilerServices", "UnsafeValueTypeAttribute", Kind.Class, true);
+
+                               if (attr_type != null) {
+                                       ConstructorInfo ci = TypeManager.GetPredefinedConstructor (attr_type, Location);
+                                       if (ci != null) {
+                                               cab = new CustomAttributeBuilder (ci, new object [0]);
+                                               TypeManager.unsafe_value_type_attr = cab;
+                                       }
+                               }
+                       }
+
+                       if (cab != null)
+                               fixed_buffer_type.SetCustomAttribute (cab);
+#endif
                        base.Emit ();
                }
 
@@ -5958,6 +5689,27 @@ namespace Mono.CSharp {
                        }
                }
 
+               public void SetCharSet (TypeAttributes ta)
+               {
+                       TypeAttributes cta = fixed_buffer_type.Attributes;
+                       if ((cta & TypeAttributes.UnicodeClass) != (ta & TypeAttributes.UnicodeClass))
+                               SetTypeBuilderCharSet ((cta & ~TypeAttributes.AutoClass) | TypeAttributes.UnicodeClass);
+                       else if ((cta & TypeAttributes.AutoClass) != (ta & TypeAttributes.AutoClass))
+                               SetTypeBuilderCharSet ((cta & ~TypeAttributes.UnicodeClass) | TypeAttributes.AutoClass);
+                       else if (cta == 0 && ta != 0)
+                               SetTypeBuilderCharSet (cta & ~(TypeAttributes.UnicodeClass | TypeAttributes.AutoClass));
+               }
+
+               void SetTypeBuilderCharSet (TypeAttributes ta)
+               {
+                       MethodInfo mi = typeof (TypeBuilder).GetMethod ("SetCharSet", BindingFlags.Instance | BindingFlags.NonPublic);
+                       if (mi == null) {
+                               Report.RuntimeMissingSupport (Location, "TypeBuilder::SetCharSet");
+                       } else {
+                               mi.Invoke (fixed_buffer_type, new object [] { ta });
+                       }
+               }
+
                #region IFixedField Members
 
                public FieldInfo Element {
@@ -5993,7 +5745,7 @@ namespace Mono.CSharp {
                        Modifiers.UNSAFE |
                        Modifiers.READONLY;
 
-               public Field (DeclSpace parent, Expression type, int mod, string name,
+               public Field (DeclSpace parent, FullNamedExpression type, int mod, string name,
                              Attributes attrs, Location loc)
                        : base (parent, type, mod, AllowedModifiers, new MemberName (name, loc),
                                attrs)
@@ -6018,6 +5770,33 @@ namespace Mono.CSharp {
                        return false;
                }
 
+               bool CheckStructLayout (Type type, bool isStatic)
+               {
+                       if (TypeManager.IsBuiltinType (type))
+                               return true;
+
+                       if (isStatic) {
+                               if (!TypeManager.IsValueType (type) || TypeManager.IsEqual (type, Parent.TypeBuilder))
+                                       return true;
+                       }
+
+                       if (!TypeManager.IsEqual (TypeManager.DropGenericTypeArguments (type), Parent.TypeBuilder)) {
+                               if (!TypeManager.IsGenericType (type))
+                                       return true;
+
+                               foreach (Type t in TypeManager.GetTypeArguments (type)) {
+                                       if (!CheckStructLayout (t, false))
+                                               return false;
+                               }
+                               return true;
+                       }
+                       
+                       Report.Error (523, Location,
+                               "Struct member `{0}' of type `{1}' causes a cycle in the struct layout",
+                               GetSignatureForError (), TypeManager.CSharpName (MemberType));
+                       return false;
+               }
+
                public override bool Define ()
                {
                        if (!base.Define ())
@@ -6035,8 +5814,6 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       FieldAttributes fa = Modifiers.FieldAttr (ModFlags);
-
                        try {
 #if GMCS_SOURCE
                                Type[] required_modifier = null;
@@ -6059,24 +5836,32 @@ namespace Mono.CSharp {
                                TypeManager.RegisterFieldBase (FieldBuilder, this);
                        }
                        catch (ArgumentException) {
-                               Report.Warning (-24, 1, Location, "The Microsoft runtime is unable to use [void|void*] as a field type, try using the Mono runtime.");
+                               Report.RuntimeMissingSupport (Location, "`void' or `void*' field type");
                                return false;
                        }
 
-                       if (initializer != null)
+                       if (initializer != null) {
                                ((TypeContainer) Parent).RegisterFieldForInitialization (this,
-                                       new FieldInitializer (FieldBuilder, initializer));
-
-                       if (Parent.PartialContainer.Kind == Kind.Struct && (fa & FieldAttributes.Static) == 0 &&
-                               MemberType == Parent.TypeBuilder && !TypeManager.IsBuiltinType (MemberType) && initializer == null) {
-                               Report.Error (523, Location, "Struct member `{0}' causes a cycle in the structure layout",
-                                       GetSignatureForError ());
-                               return false;
+                                       new FieldInitializer (FieldBuilder, initializer, this));
+                       } else {
+                               if (Parent.PartialContainer.Kind == Kind.Struct)
+                                       CheckStructLayout (member_type, (ModFlags & Modifiers.STATIC) != 0);
                        }
 
                        return true;
                }
 
+               public override string GetSignatureForError ()
+               {
+                       string s = base.GetSignatureForError ();
+                       if ((ModFlags & Modifiers.BACKING_FIELD) == 0)
+                               return s;
+
+                       // Undecorate name mangling
+                       int l = s.LastIndexOf ('>');
+                       return s.Substring (0, l).Remove (s.LastIndexOf ('<'), 1);
+               }
+
                protected override bool VerifyClsCompliance ()
                {
                        if (!base.VerifyClsCompliance ())
@@ -6093,7 +5878,7 @@ namespace Mono.CSharp {
        //
        // `set' and `get' accessors are represented with an Accessor.
        // 
-       public class Accessor : IAnonymousHost {
+       public class Accessor {
                //
                // Null if the accessor is empty, or a Block if not
                //
@@ -6107,28 +5892,16 @@ namespace Mono.CSharp {
                public Attributes Attributes;
                public Location Location;
                public int ModFlags;
-               public bool Yields;
-               public ArrayList AnonymousMethods;
+               public Parameters Parameters;
                
-               public Accessor (ToplevelBlock b, int mod, Attributes attrs, Location loc)
+               public Accessor (ToplevelBlock b, int mod, Attributes attrs, Parameters p, Location loc)
                {
                        Block = b;
                        Attributes = attrs;
                        Location = loc;
+                       Parameters = p;
                        ModFlags = Modifiers.Check (AllowedModifiers, mod, 0, loc);
                }
-
-               public void SetYields ()
-               {
-                       Yields = true;
-               }
-
-               public void AddAnonymousMethod (AnonymousMethodExpression ame)
-               {
-                       if (AnonymousMethods == null)
-                               AnonymousMethods = new ArrayList ();
-                       AnonymousMethods.Add (ame);
-               }
        }
 
        // Ooouh Martin, templates are missing here.
@@ -6175,10 +5948,6 @@ namespace Mono.CSharp {
 
                #region IMethodData Members
 
-               public abstract Iterator Iterator {
-                       get;
-               }
-
                public ToplevelBlock Block {
                        get {
                                return block;
@@ -6273,8 +6042,10 @@ namespace Mono.CSharp {
                        EmitMethod (parent);
 
 #if GMCS_SOURCE                        
-                       if ((ModFlags & Modifiers.COMPILER_GENERATED) != 0)
+                       if ((ModFlags & Modifiers.COMPILER_GENERATED) != 0 && !Parent.IsCompilerGenerated)
                                method_data.MethodBuilder.SetCustomAttribute (TypeManager.GetCompilerGeneratedAttribute (Location));
+                       if (((ModFlags & Modifiers.DEBUGGER_HIDDEN) != 0))
+                               method_data.MethodBuilder.SetCustomAttribute (TypeManager.GetDebuggerHiddenAttribute (Location));
 #endif                 
                        if (OptAttributes != null)
                                OptAttributes.Emit ();
@@ -6342,17 +6113,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               public new Location Location { 
-                       get {
-                               return base.Location;
-                       }
-               }
-
-               public virtual bool ResolveMembers ()
-               {
-                       return true;
-               }
-
                //
                //   Represents header string for documentation comment.
                //
@@ -6360,7 +6120,7 @@ namespace Mono.CSharp {
                        get { throw new InvalidOperationException ("Unexpected attempt to get doc comment from " + this.GetType () + "."); }
                }
 
-               void IMethodData.EmitExtraSymbolInfo ()
+               void IMethodData.EmitExtraSymbolInfo (SourceMethod source)
                { }
        }
 
@@ -6386,14 +6146,11 @@ namespace Mono.CSharp {
 
                        public override MethodBuilder Define (DeclSpace parent)
                        {
-                               if (!CheckForDuplications ())
-                                       return null;
+                               base.Define (parent);
 
                                if (IsDummy)
                                        return null;
                                
-                               base.Define (parent);
-                               
                                method_data = new MethodData (method, ModFlags, flags, this);
 
                                if (!method_data.Define (parent, method.GetFullName (MemberName)))
@@ -6427,14 +6184,17 @@ namespace Mono.CSharp {
                        ImplicitParameter param_attr;
                        protected Parameters parameters;
 
-                       public SetMethod (PropertyBase method):
+                       public SetMethod (PropertyBase method) :
                                base (method, "set_")
                        {
+                               parameters = new Parameters (
+                                       new Parameter (method.type_name, "value", Parameter.Modifier.NONE, null, Location));
                        }
 
                        public SetMethod (PropertyBase method, Accessor accessor):
                                base (method, accessor, "set_")
                        {
+                               this.parameters = accessor.Parameters;
                        }
 
                        protected override void ApplyToExtraTarget(Attribute a, CustomAttributeBuilder cb)
@@ -6451,29 +6211,19 @@ namespace Mono.CSharp {
                        }
 
                        public override Parameters ParameterInfo {
-                               get {
-                                       if (parameters == null)
-                                               DefineParameters ();
-                                       return parameters;
-                               }
-                       }
-
-                       protected virtual void DefineParameters ()
-                       {
-                               parameters = Parameters.CreateFullyResolved (
-                                       new Parameter (method.MemberType, "value", Parameter.Modifier.NONE, null, Location));
+                           get {
+                               return parameters;
+                           }
                        }
 
                        public override MethodBuilder Define (DeclSpace parent)
                        {
-                               if (!CheckForDuplications ())
-                                       return null;
-                               
+                               parameters.Resolve (ResolveContext);
+                               base.Define (parent);
+
                                if (IsDummy)
                                        return null;
 
-                               base.Define (parent);
-
                                method_data = new MethodData (method, ModFlags, flags, this);
 
                                if (!method_data.Define (parent, method.GetFullName (MemberName)))
@@ -6501,14 +6251,12 @@ namespace Mono.CSharp {
                {
                        protected readonly PropertyBase method;
                        protected MethodAttributes flags;
-                       Iterator iterator;
-                       ArrayList anonymous_methods;
-                       bool yields;
 
                        public PropertyMethod (PropertyBase method, string prefix)
                                : base (method, prefix)
                        {
                                this.method = method;
+                               this.ModFlags = method.ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE);                                
                        }
 
                        public PropertyMethod (PropertyBase method, Accessor accessor,
@@ -6516,19 +6264,13 @@ namespace Mono.CSharp {
                                : base (method, accessor, prefix)
                        {
                                this.method = method;
-                               this.ModFlags = accessor.ModFlags;
-                               yields = accessor.Yields;
-                               anonymous_methods = accessor.AnonymousMethods;
+                               this.ModFlags = accessor.ModFlags | (method.ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE));
 
                                if (accessor.ModFlags != 0 && RootContext.Version == LanguageVersion.ISO_1) {
                                        Report.FeatureIsNotAvailable (Location, "access modifiers on properties");
                                }
                        }
 
-                       public override Iterator Iterator {
-                               get { return iterator; }
-                       }
-
                        public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
                        {
                                if (a.IsInternalMethodImplAttribute) {
@@ -6549,26 +6291,23 @@ namespace Mono.CSharp {
                                return method.IsClsComplianceRequired ();
                        }
 
-                       public override bool ResolveMembers ()
+                       public virtual MethodBuilder Define (DeclSpace parent)
                        {
-                               if (yields) {
-                                       iterator = Iterator.CreateIterator (this, Parent, null, ModFlags);
-                                       if (iterator == null)
-                                               return false;
-                               }
-
-                               if (anonymous_methods != null) {
-                                       foreach (AnonymousMethodExpression ame in anonymous_methods) {
-                                               if (!ame.CreateAnonymousHelpers ())
-                                                       return false;
+                               CheckForDuplications ();
+
+                               if (IsDummy) {
+                                       if (method.InterfaceType != null && parent.PartialContainer.PendingImplementations != null) {
+                                               MethodInfo mi = parent.PartialContainer.PendingImplementations.IsInterfaceMethod (
+                                                       MethodName.Name, method.InterfaceType, new MethodData (method, ModFlags, flags, this));
+                                               if (mi != null) {
+                                                       Report.SymbolRelatedToPreviousError (mi);
+                                                       Report.Error (551, Location, "Explicit interface implementation `{0}' is missing accessor `{1}'",
+                                                               method.GetSignatureForError (), TypeManager.CSharpSignature (mi, true));
+                                               }
                                        }
+                                       return null;
                                }
 
-                               return true;
-                       }
-
-                       public virtual MethodBuilder Define (DeclSpace parent)
-                       {
                                TypeContainer container = parent.PartialContainer;
 
                                //
@@ -6594,6 +6333,10 @@ namespace Mono.CSharp {
                                }
 
                                CheckAbstractAndExtern (block != null);
+
+                               if (block != null && block.IsIterator)
+                                       Iterator.CreateIterator (this, Parent.PartialContainer, ModFlags);
+
                                return null;
                        }
 
@@ -6606,7 +6349,7 @@ namespace Mono.CSharp {
 
                        public override EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig)
                        {
-                               return new EmitContext (method,
+                               return new EmitContext (this,
                                        ds, method.ds, method.Location, ig, ReturnType,
                                        method.ModFlags, false);
                        }
@@ -6646,7 +6389,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       protected bool CheckForDuplications () 
+                       protected bool CheckForDuplications ()
                        {
                                if ((caching_flags & Flags.MethodOverloadsExist) == 0)
                                        return true;
@@ -6661,10 +6404,10 @@ namespace Mono.CSharp {
 
                protected bool define_set_first = false;
 
-               public PropertyBase (DeclSpace parent, Expression type, int mod_flags,
-                                    int allowed_mod, bool is_iface, MemberName name,
+               public PropertyBase (DeclSpace parent, FullNamedExpression type, int mod_flags,
+                                    int allowed_mod, MemberName name,
                                     Attributes attrs, bool define_set_first)
-                       : base (parent, null, type, mod_flags, allowed_mod, is_iface, name,     attrs)
+                       : base (parent, null, type, mod_flags, allowed_mod, name, attrs)
                {
                         this.define_set_first = define_set_first;
                }
@@ -6711,11 +6454,12 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       if ((Get.IsDummy || Set.IsDummy)
-                                       && (Get.ModFlags != 0 || Set.ModFlags != 0) && (ModFlags & Modifiers.OVERRIDE) == 0) {
+                       if ((ModFlags & Modifiers.OVERRIDE) == 0 && 
+                               (Get.IsDummy && (Set.ModFlags & Modifiers.Accessibility) != 0) ||
+                               (Set.IsDummy && (Get.ModFlags & Modifiers.Accessibility) != 0)) {
                                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 ());
+                                             "`{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;
                        }
 
@@ -6762,45 +6506,44 @@ namespace Mono.CSharp {
                        PropertyInfo base_property = ResolveBaseProperty ();
                        if (base_property == null)
                                return null;
-  
+
                        base_ret_type = base_property.PropertyType;
                        MethodInfo get_accessor = base_property.GetGetMethod (true);
                        MethodInfo set_accessor = base_property.GetSetMethod (true);
                        MethodAttributes get_accessor_access = 0, set_accessor_access = 0;
 
-                       if ((ModFlags & Modifiers.OVERRIDE) != 0) {
-                               if (Get != null && !Get.IsDummy && get_accessor == null) {
-                                       Report.SymbolRelatedToPreviousError (base_property);
-                                       Report.Error (545, Location, "`{0}.get': cannot override because `{1}' does not have an overridable get accessor", GetSignatureForError (), TypeManager.GetFullNameSignature (base_property));
-                               }
+                       //
+                       // Check base property accessors conflict
+                       //
+                       if ((ModFlags & (Modifiers.OVERRIDE | Modifiers.NEW)) == Modifiers.OVERRIDE) {
+                               if (get_accessor == null) {
+                                       if (Get != null && !Get.IsDummy) {
+                                               Report.SymbolRelatedToPreviousError (base_property);
+                                               Report.Error (545, Location,
+                                                       "`{0}.get': cannot override because `{1}' does not have an overridable get accessor",
+                                                       GetSignatureForError (), TypeManager.GetFullNameSignature (base_property));
+                                       }
+                               } else {
+                                       get_accessor_access = get_accessor.Attributes & MethodAttributes.MemberAccessMask;
 
-                               if (Set != null && !Set.IsDummy && set_accessor == null) {
-                                       Report.SymbolRelatedToPreviousError (base_property);
-                                       Report.Error (546, Location, "`{0}.set': cannot override because `{1}' does not have an overridable set accessor", GetSignatureForError (), TypeManager.GetFullNameSignature (base_property));
+                                       if (!Get.IsDummy && !CheckAccessModifiers (
+                                               Modifiers.MethodAttr (Get.ModFlags) & MethodAttributes.MemberAccessMask, get_accessor_access, get_accessor))
+                                               Error_CannotChangeAccessModifiers (Get.Location, get_accessor, get_accessor_access, ".get");
                                }
 
-                               //
-                               // Check base class accessors access
-                               //
-
-                               // TODO: rewrite to reuse Get|Set.CheckAccessModifiers and share code there
-                               get_accessor_access = set_accessor_access = 0;
-                               if ((ModFlags & Modifiers.NEW) == 0) {
-                                       if (get_accessor != null) {
-                                               MethodAttributes get_flags = Modifiers.MethodAttr (Get.ModFlags != 0 ? Get.ModFlags : ModFlags);
-                                               get_accessor_access = (get_accessor.Attributes & MethodAttributes.MemberAccessMask);
-
-                                               if (!Get.IsDummy && !CheckAccessModifiers (get_flags & MethodAttributes.MemberAccessMask, get_accessor_access, get_accessor))
-                                                       Error_CannotChangeAccessModifiers (get_accessor, get_accessor_access, ".get");
+                               if (set_accessor == null) {
+                                       if (Set != null && !Set.IsDummy) {
+                                               Report.SymbolRelatedToPreviousError (base_property);
+                                               Report.Error (546, Location,
+                                                       "`{0}.set': cannot override because `{1}' does not have an overridable set accessor",
+                                                       GetSignatureForError (), TypeManager.GetFullNameSignature (base_property));
                                        }
+                               } else {
+                                       set_accessor_access = set_accessor.Attributes & MethodAttributes.MemberAccessMask;
 
-                                       if (set_accessor != null) {
-                                               MethodAttributes set_flags = Modifiers.MethodAttr (Set.ModFlags != 0 ? Set.ModFlags : ModFlags);
-                                               set_accessor_access = (set_accessor.Attributes & MethodAttributes.MemberAccessMask);
-
-                                               if (!Set.IsDummy && !CheckAccessModifiers (set_flags & MethodAttributes.MemberAccessMask, set_accessor_access, set_accessor))
-                                                       Error_CannotChangeAccessModifiers (set_accessor, set_accessor_access, ".set");
-                                       }
+                                       if (!Set.IsDummy && !CheckAccessModifiers (
+                                               Modifiers.MethodAttr (Set.ModFlags) & MethodAttributes.MemberAccessMask, set_accessor_access, set_accessor))
+                                               Error_CannotChangeAccessModifiers (Set.Location, set_accessor, set_accessor_access, ".set");
                                }
                        }
 
@@ -6887,7 +6630,6 @@ namespace Mono.CSharp {
                        Modifiers.ABSTRACT |
                        Modifiers.UNSAFE |
                        Modifiers.EXTERN |
-                       Modifiers.METHOD_YIELDS |
                        Modifiers.VIRTUAL;
 
                const int AllowedInterfaceModifiers =
@@ -6897,10 +6639,10 @@ namespace Mono.CSharp {
                {
                        // Make the field
                        Field field = new Field (
-                               Parent, Type,
-                               Modifiers.COMPILER_GENERATED | Modifiers.PRIVATE | (ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE)),
+                               Parent, type_name,
+                               Modifiers.BACKING_FIELD | Modifiers.PRIVATE | (ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE)),
                            "<" + Name + ">k__BackingField", null, Location);
-                       ((TypeContainer)Parent).AddField (field);
+                       ((TypeContainer)Parent).PartialContainer.AddField (field);
 
                        // Make get block
                        get_block.Block = new ToplevelBlock (block, null, Location);
@@ -6909,29 +6651,28 @@ namespace Mono.CSharp {
                        get_block.ModFlags |= Modifiers.COMPILER_GENERATED;
 
                        // Make set block
-                       Parameters parameters = new Parameters (new Parameter (Type, "value", Parameter.Modifier.NONE, null, Location));
-                       set_block.Block = new ToplevelBlock (block, parameters, Location);
-                       Assign a = new Assign (new SimpleName(field.Name, Location), new SimpleName ("value", Location));
+                       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, Expression type, int mod, bool is_iface,
+               public Property (DeclSpace parent, FullNamedExpression type, int mod,
                                 MemberName name, Attributes attrs, Accessor get_block,
                                 Accessor set_block, bool define_set_first)
-                       : this (parent, type, mod, is_iface, name, attrs, get_block, set_block,
+                       : this (parent, type, mod, name, attrs, get_block, set_block,
                                define_set_first, null)
                {
                }
                
-               public Property (DeclSpace parent, Expression type, int mod, bool is_iface,
+               public Property (DeclSpace parent, FullNamedExpression type, int mod,
                                 MemberName name, Attributes attrs, Accessor get_block,
                                 Accessor set_block, bool define_set_first, Block current_block)
                        : base (parent, type, mod,
-                               is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
-                               is_iface, name, attrs, define_set_first)
+                               parent.PartialContainer.Kind == Kind.Interface ? AllowedInterfaceModifiers : AllowedModifiers,
+                               name, attrs, define_set_first)
                {
-                       if (!is_iface && (mod & (Modifiers.ABSTRACT | Modifiers.EXTERN)) == 0 &&
+                       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)
@@ -6959,14 +6700,14 @@ namespace Mono.CSharp {
                        if (!base.Define ())
                                return false;
 
-                       if (!CheckBase ())
-                               return false;
-
                        flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
 
                        if (!DefineAccessors ())
                                return false;
 
+                       if (!CheckBase ())
+                               return false;
+
                        // FIXME - PropertyAttributes.HasDefault ?
 
                        PropertyBuilder = Parent.TypeBuilder.DefineProperty (
@@ -6987,10 +6728,21 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               public override void Emit ()
+               {
+                       if (((Set.ModFlags | Get.ModFlags) & (Modifiers.STATIC | Modifiers.COMPILER_GENERATED)) == Modifiers.COMPILER_GENERATED && Parent.PartialContainer.HasExplicitLayout) {
+                               Report.Error (842, Location,
+                                       "Automatically implemented property `{0}' cannot be used inside a type with an explicit StructLayout attribute",
+                                       GetSignatureForError ());
+                       }
+
+                       base.Emit ();
+               }
+
                protected override PropertyInfo ResolveBaseProperty ()
                {
                        return Parent.PartialContainer.BaseCache.FindMemberToOverride (
-                               Parent.TypeBuilder, Name, Parameters.EmptyReadOnlyParameters.Types, null, true) as PropertyInfo;
+                               Parent.TypeBuilder, Name, Parameters.EmptyReadOnlyParameters, null, true) as PropertyInfo;
                }
        }
 
@@ -7146,12 +6898,9 @@ namespace Mono.CSharp {
        public class EventProperty: Event {
                abstract class AEventPropertyAccessor : AEventAccessor
                {
-                       readonly ArrayList anonymous_methods;
-
-                       public AEventPropertyAccessor (Event method, Accessor accessor, string prefix):
+                       protected AEventPropertyAccessor (Event method, Accessor accessor, string prefix):
                                base (method, accessor, prefix)
                        {
-                               this.anonymous_methods = accessor.AnonymousMethods;
                        }
 
                        public override MethodBuilder Define (DeclSpace ds)
@@ -7164,20 +6913,6 @@ namespace Mono.CSharp {
                        {
                                return method.GetSignatureForError () + "." + prefix.Substring (0, prefix.Length - 1);
                        }
-
-                       public override bool ResolveMembers ()
-                       {
-                               if (anonymous_methods == null)
-                                       return true;
-
-                               foreach (AnonymousMethodExpression ame in anonymous_methods) {
-                                       if (!ame.CreateAnonymousHelpers ())
-                                               return false;
-                               }
-
-                               return true;
-                       }
-
                }
 
                sealed class AddDelegateMethod: AEventPropertyAccessor
@@ -7211,10 +6946,10 @@ namespace Mono.CSharp {
 
                static readonly string[] attribute_targets = new string [] { "event" }; // "property" target was disabled for 2.0 version
 
-               public EventProperty (DeclSpace parent, Expression type, int mod_flags,
-                                     bool is_iface, MemberName name,
+               public EventProperty (DeclSpace parent, FullNamedExpression type, int mod_flags,
+                                     MemberName name,
                                      Attributes attrs, Accessor add, Accessor remove)
-                       : base (parent, type, mod_flags, is_iface, name, attrs)
+                       : base (parent, type, mod_flags, name, attrs)
                {
                        Add = new AddDelegateMethod (this, add);
                        Remove = new RemoveDelegateMethod (this, remove);
@@ -7249,6 +6984,10 @@ namespace Mono.CSharp {
 
                        protected override void EmitMethod(DeclSpace parent)
                        {
+                               if (method_data.implementing != null)
+                                       parent.PartialContainer.PendingImplementations.ImplementMethod (
+                                               Name, method.InterfaceType, method_data, method.IsExplicitImpl);
+                               
                                if ((method.ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0)
                                        return;
 
@@ -7316,10 +7055,8 @@ namespace Mono.CSharp {
                public FieldBuilder FieldBuilder;
                public Expression Initializer;
 
-               public EventField (DeclSpace parent, Expression type, int mod_flags,
-                                  bool is_iface, MemberName name,
-                                  Attributes attrs)
-                       : base (parent, type, mod_flags, is_iface, name, attrs)
+               public EventField (DeclSpace parent, FullNamedExpression type, int mod_flags, MemberName name, Attributes attrs)
+                       : base (parent, type, mod_flags, name, attrs)
                {
                        Add = new AddDelegateMethod (this);
                        Remove = new RemoveDelegateMethod (this);
@@ -7373,7 +7110,7 @@ namespace Mono.CSharp {
                                }
 
                                ((TypeContainer) Parent).RegisterFieldForInitialization (this,
-                                       new FieldInitializer (FieldBuilder, Initializer));
+                                       new FieldInitializer (FieldBuilder, Initializer, this));
                        }
 
                        return true;
@@ -7409,10 +7146,6 @@ namespace Mono.CSharp {
                                this.ModFlags = method.ModFlags;
                        }
 
-                       public override Iterator Iterator {
-                               get { return null; }
-                       }
-
                        public bool IsInterfaceImplementation {
                                get { return method_data.implementing != null; }
                        }
@@ -7474,7 +7207,7 @@ namespace Mono.CSharp {
                        public override EmitContext CreateEmitContext (DeclSpace ds, ILGenerator ig)
                        {
                                return new EmitContext (
-                                       ds, method.Parent, Location, ig, ReturnType,
+                                       this, method.Parent, Location, ig, ReturnType,
                                        method.ModFlags, false);
                        }
 
@@ -7520,10 +7253,9 @@ namespace Mono.CSharp {
 
                Parameters parameters;
 
-               protected Event (DeclSpace parent, Expression type, int mod_flags,
-                             bool is_iface, MemberName name, Attributes attrs)
+               protected Event (DeclSpace parent, FullNamedExpression type, int mod_flags, MemberName name, Attributes attrs)
                        : base (parent, null, type, mod_flags,
-                               is_iface ? AllowedInterfaceModifiers : AllowedModifiers, is_iface,
+                               parent.PartialContainer.Kind == Kind.Interface ? AllowedInterfaceModifiers : AllowedModifiers,
                                name, attrs)
                {
                }
@@ -7563,7 +7295,7 @@ namespace Mono.CSharp {
                        }
 
                        parameters = Parameters.CreateFullyResolved (
-                               new Parameter (MemberType, "value", Parameter.Modifier.NONE, null, Location));
+                               new Parameter (null, "value", Parameter.Modifier.NONE, null, Location), MemberType);
 
                        if (!CheckBase ())
                                return false;
@@ -7622,8 +7354,8 @@ namespace Mono.CSharp {
                        if (mi == null)
                                return null;
 
-                       ParameterData pd = TypeManager.GetParameterData (mi);
-                       base_ret_type = pd.ParameterType (0);
+                       AParametersCollection pd = TypeManager.GetParameterData (mi);
+                       base_ret_type = pd.Types [0];
                        return mi;
                }
 
@@ -7638,16 +7370,26 @@ namespace Mono.CSharp {
  
        public class Indexer : PropertyBase
        {
-               class GetIndexerMethod : GetMethod
+               public class GetIndexerMethod : GetMethod
                {
-                       public GetIndexerMethod (PropertyBase method):
+                       Parameters parameters;
+
+                       public GetIndexerMethod (Indexer method):
                                base (method)
                        {
+                               this.parameters = method.parameters;
                        }
 
                        public GetIndexerMethod (PropertyBase method, Accessor accessor):
                                base (method, accessor)
                        {
+                               parameters = accessor.Parameters;
+                       }
+
+                       public override MethodBuilder Define (DeclSpace parent)
+                       {
+                               parameters.Resolve (ResolveContext);
+                               return base.Define (parent);
                        }
                        
                        public override bool EnableOverloadChecks (MemberCore overload)
@@ -7662,29 +7404,25 @@ namespace Mono.CSharp {
 
                        public override Parameters ParameterInfo {
                                get {
-                                       return ((Indexer)method).parameters;
+                                       return parameters;
                                }
                        }
                }
 
-               class SetIndexerMethod: SetMethod
+               public class SetIndexerMethod: SetMethod
                {
-                       public SetIndexerMethod (PropertyBase method):
+                       public SetIndexerMethod (Indexer method):
                                base (method)
                        {
+                               parameters = Parameters.MergeGenerated (method.parameters, false, parameters [0], null);
                        }
 
                        public SetIndexerMethod (PropertyBase method, Accessor accessor):
                                base (method, accessor)
                        {
+                               parameters = method.Get.IsDummy ? accessor.Parameters : accessor.Parameters.Clone ();                   
                        }
 
-                       protected override void DefineParameters ()
-                       {
-                               parameters = Parameters.MergeGenerated (((Indexer)method).parameters,
-                                       new Parameter (method.MemberType, "value", Parameter.Modifier.NONE, null, method.Location));
-                       }
-                       
                        public override bool EnableOverloadChecks (MemberCore overload)
                        {
                                if (base.EnableOverloadChecks (overload)) {
@@ -7693,7 +7431,7 @@ namespace Mono.CSharp {
                                }
 
                                return false;
-                       }                       
+                       }
                }
 
                const int AllowedModifiers =
@@ -7714,16 +7452,13 @@ namespace Mono.CSharp {
 
                public readonly Parameters parameters;
 
-               public Indexer (DeclSpace parent, Expression type, MemberName name, int mod,
-                               bool is_iface, Parameters parameters, Attributes attrs,
+               public Indexer (DeclSpace parent, FullNamedExpression type, MemberName name, int mod,
+                               Parameters parameters, Attributes attrs,
                                Accessor get_block, Accessor set_block, bool define_set_first)
                        : base (parent, type, mod,
-                               is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
-                               is_iface, name, attrs, define_set_first)
+                               parent.PartialContainer.Kind == Kind.Interface ? AllowedInterfaceModifiers : AllowedModifiers,
+                               name, attrs, define_set_first)
                {
-                       if (type == TypeManager.system_void_expr)
-                               Report.Error (620, name.Location, "An indexer return type cannot be `void'");
-                       
                        this.parameters = parameters;
 
                        if (get_block == null)
@@ -7736,6 +7471,11 @@ namespace Mono.CSharp {
                        else
                                Set = new SetIndexerMethod (this, set_block);
                }
+
+               protected override bool CheckForDuplications ()
+               {
+                       return Parent.MemberCache.CheckExistingMembersOverloads (this, GetFullName (MemberName), parameters);
+               }
                
                public override bool Define ()
                {
@@ -7785,34 +7525,19 @@ namespace Mono.CSharp {
                                !Parent.PartialContainer.AddMember (Get) || !Parent.PartialContainer.AddMember (Set))
                                return false;
 
-                       if (!CheckBase ())
-                               return false;
-
-
-                       if ((caching_flags & Flags.MethodOverloadsExist) != 0) {
-                               if (!Parent.MemberCache.CheckExistingMembersOverloads (this, Name, parameters))
-                                       return false;
-                       }
-
                        flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
                        
                        if (!DefineAccessors ())
                                return false;
 
-                       if (!Get.IsDummy) {
-                               // Setup iterator if we are one
-                               if ((ModFlags & Modifiers.METHOD_YIELDS) != 0){
-                                       Iterator iterator = Iterator.CreateIterator (Get, Parent, null, ModFlags);
-                                       if (iterator == null)
-                                               return false;
-                               }
-                       }
+                       if (!CheckBase ())
+                               return false;
 
                        //
                        // Now name the parameters
                        //
                        PropertyBuilder = Parent.TypeBuilder.DefineProperty (
-                               GetFullName (MemberName), PropertyAttributes.None, MemberType, parameters.Types);
+                               GetFullName (MemberName), PropertyAttributes.None, MemberType, parameters.GetEmitTypes ());
 
                        if (!Get.IsDummy) {
                                PropertyBuilder.SetGetMethod (GetBuilder);
@@ -7824,7 +7549,7 @@ namespace Mono.CSharp {
                                Parent.MemberCache.AddMember (SetBuilder, Set);
                        }
                                
-                       TypeManager.RegisterIndexer (PropertyBuilder, GetBuilder, SetBuilder, parameters.Types);
+                       TypeManager.RegisterIndexer (PropertyBuilder, parameters);
                        Parent.MemberCache.AddMember (PropertyBuilder, this);
                        return true;
                }
@@ -7836,7 +7561,7 @@ namespace Mono.CSharp {
                                return true;
                        }
 
-                       return false;
+                       return base.EnableOverloadChecks (overload);
                }
 
                public override string GetDocCommentName (DeclSpace ds)
@@ -7860,7 +7585,7 @@ namespace Mono.CSharp {
                protected override PropertyInfo ResolveBaseProperty ()
                {
                        return Parent.PartialContainer.BaseCache.FindMemberToOverride (
-                               Parent.TypeBuilder, Name, parameters.Types, null, true) as PropertyInfo;
+                               Parent.TypeBuilder, Name, parameters, null, true) as PropertyInfo;
                }
 
                protected override bool VerifyClsCompliance ()
@@ -7873,7 +7598,7 @@ namespace Mono.CSharp {
                }
        }
 
-       public class Operator : MethodOrOperator, IAnonymousHost {
+       public class Operator : MethodOrOperator {
 
                const int AllowedModifiers =
                        Modifiers.PUBLIC |
@@ -7923,12 +7648,45 @@ namespace Mono.CSharp {
                };
 
                public readonly OpType OperatorType;
+
+               static readonly string [] [] names;
+
+               static Operator ()
+               {
+                       names = new string[(int)OpType.TOP][];
+                       names [(int) OpType.LogicalNot] = new string [] { "!", "op_LogicalNot" };
+                       names [(int) OpType.OnesComplement] = new string [] { "~", "op_OnesComplement" };
+                       names [(int) OpType.Increment] = new string [] { "++", "op_Increment" };
+                       names [(int) OpType.Decrement] = new string [] { "--", "op_Decrement" };
+                       names [(int) OpType.True] = new string [] { "true", "op_True" };
+                       names [(int) OpType.False] = new string [] { "false", "op_False" };
+                       names [(int) OpType.Addition] = new string [] { "+", "op_Addition" };
+                       names [(int) OpType.Subtraction] = new string [] { "-", "op_Subtraction" };
+                       names [(int) OpType.UnaryPlus] = new string [] { "+", "op_UnaryPlus" };
+                       names [(int) OpType.UnaryNegation] = new string [] { "-", "op_UnaryNegation" };
+                       names [(int) OpType.Multiply] = new string [] { "*", "op_Multiply" };
+                       names [(int) OpType.Division] = new string [] { "/", "op_Division" };
+                       names [(int) OpType.Modulus] = new string [] { "%", "op_Modulus" };
+                       names [(int) OpType.BitwiseAnd] = new string [] { "&", "op_BitwiseAnd" };
+                       names [(int) OpType.BitwiseOr] = new string [] { "|", "op_BitwiseOr" };
+                       names [(int) OpType.ExclusiveOr] = new string [] { "^", "op_ExclusiveOr" };
+                       names [(int) OpType.LeftShift] = new string [] { "<<", "op_LeftShift" };
+                       names [(int) OpType.RightShift] = new string [] { ">>", "op_RightShift" };
+                       names [(int) OpType.Equality] = new string [] { "==", "op_Equality" };
+                       names [(int) OpType.Inequality] = new string [] { "!=", "op_Inequality" };
+                       names [(int) OpType.GreaterThan] = new string [] { ">", "op_GreaterThan" };
+                       names [(int) OpType.LessThan] = new string [] { "<", "op_LessThan" };
+                       names [(int) OpType.GreaterThanOrEqual] = new string [] { ">=", "op_GreaterThanOrEqual" };
+                       names [(int) OpType.LessThanOrEqual] = new string [] { "<=", "op_LessThanOrEqual" };
+                       names [(int) OpType.Implicit] = new string [] { "implicit", "op_Implicit" };
+                       names [(int) OpType.Explicit] = new string [] { "explicit", "op_Explicit" };
+               }
                
-               public Operator (DeclSpace parent, OpType type, Expression ret_type,
+               public Operator (DeclSpace parent, OpType type, FullNamedExpression ret_type,
                                 int mod_flags, Parameters parameters,
                                 ToplevelBlock block, Attributes attrs, Location loc)
-                       : base (parent, null, ret_type, mod_flags, AllowedModifiers, false,
-                               new MemberName ("op_" + type.ToString(), loc), attrs, parameters)
+                       : base (parent, null, ret_type, mod_flags, AllowedModifiers,
+                               new MemberName (GetMetadataName (type), loc), attrs, parameters)
                {
                        OperatorType = type;
                        Block = block;
@@ -7957,14 +7715,9 @@ namespace Mono.CSharp {
 
                        // imlicit and explicit operator of same types are not allowed
                        if (OperatorType == OpType.Explicit)
-                               Parent.MemberCache.CheckExistingMembersOverloads (this, "op_Implicit", Parameters);
+                               Parent.MemberCache.CheckExistingMembersOverloads (this, GetMetadataName (OpType.Implicit), Parameters);
                        else if (OperatorType == OpType.Implicit)
-                               Parent.MemberCache.CheckExistingMembersOverloads (this, "op_Explicit", Parameters);
-
-                       if (MemberType == TypeManager.void_type) {
-                               Report.Error (590, Location, "User-defined operators cannot return void");
-                               return false;
-                       }
+                               Parent.MemberCache.CheckExistingMembersOverloads (this, GetMetadataName (OpType.Explicit), Parameters);
 
                        Type declaring_type = MethodData.DeclaringType;
                        Type return_type = MemberType;
@@ -8024,7 +7777,7 @@ namespace Mono.CSharp {
                                        }
                                }
                        } else if (OperatorType == OpType.LeftShift || OperatorType == OpType.RightShift) {
-                               if (first_arg_type != declaring_type || ParameterTypes [1] != TypeManager.int32_type) {
+                               if (first_arg_type != declaring_type || Parameters.Types [1] != TypeManager.int32_type) {
                                        Report.Error (564, Location, "Overloaded shift operator must have the type of the first operand be the containing type, and the type of the second operand must be int");
                                        return false;
                                }
@@ -8044,11 +7797,9 @@ namespace Mono.CSharp {
                                        }
                                }
                                
-                               if (first_arg_type != declaring_type){
-                                       Report.Error (
-                                               562, Location,
-                                               "The parameter of a unary operator must be the " +
-                                               "containing type");
+                               if (!TypeManager.IsEqual (first_arg_type_unwrap, declaring_type)){
+                                       Report.Error (562, Location,
+                                               "The parameter type of a unary operator must be the containing type");
                                        return false;
                                }
                                
@@ -8066,7 +7817,7 @@ namespace Mono.CSharp {
                                // Checks for Binary operators
                                
                                if (first_arg_type != declaring_type &&
-                                   ParameterTypes [1] != declaring_type){
+                                   Parameters.Types [1] != declaring_type){
                                        Report.Error (
                                                563, Location,
                                                "One of the parameters of a binary operator must " +
@@ -8122,108 +7873,62 @@ namespace Mono.CSharp {
 
                public static string GetName (OpType ot)
                {
-                       switch (ot){
-                       case OpType.LogicalNot:
-                               return "!";
-                       case OpType.OnesComplement:
-                               return "~";
-                       case OpType.Increment:
-                               return "++";
-                       case OpType.Decrement:
-                               return "--";
-                       case OpType.True:
-                               return "true";
-                       case OpType.False:
-                               return "false";
-                       case OpType.Addition:
-                               return "+";
-                       case OpType.Subtraction:
-                               return "-";
-                       case OpType.UnaryPlus:
-                               return "+";
-                       case OpType.UnaryNegation:
-                               return "-";
-                       case OpType.Multiply:
-                               return "*";
-                       case OpType.Division:
-                               return "/";
-                       case OpType.Modulus:
-                               return "%";
-                       case OpType.BitwiseAnd:
-                               return "&";
-                       case OpType.BitwiseOr:
-                               return "|";
-                       case OpType.ExclusiveOr:
-                               return "^";
-                       case OpType.LeftShift:
-                               return "<<";
-                       case OpType.RightShift:
-                               return ">>";
-                       case OpType.Equality:
-                               return "==";
-                       case OpType.Inequality:
-                               return "!=";
-                       case OpType.GreaterThan:
-                               return ">";
-                       case OpType.LessThan:
-                               return "<";
-                       case OpType.GreaterThanOrEqual:
-                               return ">=";
-                       case OpType.LessThanOrEqual:
-                               return "<=";
-                       case OpType.Implicit:
-                               return "implicit";
-                       case OpType.Explicit:
-                               return "explicit";
-                       default: return "";
-                       }
+                       return names [(int) ot] [0];
                }
 
-               public OpType GetMatchingOperator ()
+               public static string GetName (string metadata_name)
                {
-                       switch (OperatorType) {
-                               case OpType.Equality:
-                                       return OpType.Inequality;
-                               case OpType.Inequality:
-                                       return OpType.Equality;
-                               case OpType.True:
-                                       return OpType.False;
-                               case OpType.False:
-                                       return OpType.True;
-                               case OpType.GreaterThan:
-                                       return OpType.LessThan;
-                               case OpType.LessThan:
-                                       return OpType.GreaterThan;
-                               case OpType.GreaterThanOrEqual:
-                                       return OpType.LessThanOrEqual;
-                               case OpType.LessThanOrEqual:
-                                       return OpType.GreaterThanOrEqual;
-                               default:
-                                       return OpType.TOP;
+                       for (int i = 0; i < names.Length; ++i) {
+                               if (names [i] [1] == metadata_name)
+                                       return names [i] [0];
                        }
+                       return null;
                }
 
-               public static OpType GetOperatorType (string name)
+               public static string GetMetadataName (OpType ot)
                {
-                       if (name.StartsWith ("op_")){
-                               for (int i = 0; i < Unary.oper_names.Length; ++i) {
-                                       if (Unary.oper_names [i] == name)
-                                               return (OpType)i;
-                               }
+                       return names [(int) ot] [1];
+               }
 
-                               for (int i = 0; i < Binary.oper_names.Length; ++i) {
-                                       if (Binary.oper_names [i] == name)
-                                               return (OpType)i;
-                               }
+               public static string GetMetadataName (string name)
+               {
+                       for (int i = 0; i < names.Length; ++i) {
+                               if (names [i] [0] == name)
+                                       return names [i] [1];
+                       }
+                       return null;
+               }
+
+               public OpType GetMatchingOperator ()
+               {
+                       switch (OperatorType) {
+                       case OpType.Equality:
+                               return OpType.Inequality;
+                       case OpType.Inequality:
+                               return OpType.Equality;
+                       case OpType.True:
+                               return OpType.False;
+                       case OpType.False:
+                               return OpType.True;
+                       case OpType.GreaterThan:
+                               return OpType.LessThan;
+                       case OpType.LessThan:
+                               return OpType.GreaterThan;
+                       case OpType.GreaterThanOrEqual:
+                               return OpType.LessThanOrEqual;
+                       case OpType.LessThanOrEqual:
+                               return OpType.GreaterThanOrEqual;
+                       default:
+                               return OpType.TOP;
                        }
-                       return OpType.TOP;
                }
 
                public override string GetSignatureForError ()
                {
                        StringBuilder sb = new StringBuilder ();
                        if (OperatorType == OpType.Implicit || OperatorType == OpType.Explicit) {
-                               sb.AppendFormat ("{0}.{1} operator {2}", Parent.GetSignatureForError (), GetName (OperatorType), Type.Type == null ? Type.ToString () : TypeManager.CSharpName (Type.Type));
+                               sb.AppendFormat ("{0}.{1} operator {2}",
+                                       Parent.GetSignatureForError (), GetName (OperatorType), type_name.GetSignatureForError ());
                        }
                        else {
                                sb.AppendFormat ("{0}.operator {1}", Parent.GetSignatureForError (), GetName (OperatorType));
@@ -8341,7 +8046,7 @@ namespace Mono.CSharp {
                        if (mi != null)
                                args = TypeManager.GetParameterData (mi).Types;
                        else
-                               args = TypeManager.GetArgumentTypes (pi);
+                               args = TypeManager.GetParameterData (pi).Types;
                        Type [] sigp = sig.Parameters;
 
                        if (args.Length != sigp.Length)