updated browser capabilities file
[mono.git] / mcs / gmcs / class.cs
index d20c50d489beb47d9ba414ddd980b57b0d27b466..d9826277297703ecb4952d2d738b80384f6464d8 100755 (executable)
@@ -113,9 +113,6 @@ namespace Mono.CSharp {
 
                ArrayList type_bases;
 
-               // Attributes for this type
-               protected Attributes attributes;
-
                // Information in the case we are an attribute type
 
                public AttributeTargets Targets = AttributeTargets.All;
@@ -134,20 +131,18 @@ namespace Mono.CSharp {
                //
                public string IndexerName;
 
-               public TypeContainer (NamespaceEntry ns, TypeContainer parent, string name, Location l)
-                       : base (ns, parent, name, l)
+               Type GenericType;
+
+               public TypeContainer ():
+                       this (null, null, "", null, new Location (-1)) {
+               }
+
+               public TypeContainer (NamespaceEntry ns, TypeContainer parent, string name, Attributes attrs, Location l)
+                       : base (ns, parent, name, attrs, l)
                {
-                       string n;
                        types = new ArrayList ();
 
-                       if (parent == null)
-                               n = "";
-                       else 
-                               n = parent.Name;
-
                        base_class_name = null;
-
-                       //Console.WriteLine ("New class " + name + " inside " + n);
                }
 
                public AdditionResult AddConstant (Const constant)
@@ -348,11 +343,19 @@ namespace Mono.CSharp {
                public AdditionResult AddProperty (Property prop)
                {
                        AdditionResult res;
-                       string basename = prop.Name;
-                       string fullname = Name + "." + basename;
 
-                       if ((res = IsValid (basename, fullname)) != AdditionResult.Success)
+                       if ((res = AddProperty (prop, prop.Name)) != AdditionResult.Success)
+                               return res;
+
+                       if (prop.Get != null) {
+                               if ((res = AddProperty (prop, "get_" + prop.Name)) != AdditionResult.Success)
+                                       return res;
+                       }
+
+                       if (prop.Set != null) {
+                               if ((res = AddProperty (prop, "set_" + prop.Name)) != AdditionResult.Success)
                                return res;
+                       }
 
                        if (properties == null)
                                properties = new ArrayList ();
@@ -361,6 +364,18 @@ namespace Mono.CSharp {
                                properties.Insert (0, prop);
                        else
                                properties.Add (prop);
+
+                       return AdditionResult.Success;
+               }
+
+               AdditionResult AddProperty (Property prop, string basename)
+               {
+                       AdditionResult res;
+                       string fullname = Name + "." + basename;
+
+                       if ((res = IsValid (basename, fullname)) != AdditionResult.Success)
+                               return res;
+
                        DefineName (fullname, prop);
 
                        return AdditionResult.Success;
@@ -384,7 +399,7 @@ namespace Mono.CSharp {
                        return AdditionResult.Success;
                }
 
-               public AdditionResult AddIndexer (Indexer i)
+               public void AddIndexer (Indexer i)
                {
                        if (indexers == null)
                                indexers = new ArrayList ();
@@ -393,8 +408,6 @@ namespace Mono.CSharp {
                                indexers.Insert (0, i);
                        else
                                indexers.Add (i);
-
-                       return AdditionResult.Success;
                }
 
                public AdditionResult AddOperator (Operator op)
@@ -404,6 +417,12 @@ namespace Mono.CSharp {
 
                        operators.Add (op);
 
+                       string basename = op.Name;
+                       string fullname = Name + "." + basename;
+                       if (!defined_names.Contains (fullname))
+                       {
+                               DefineName (fullname, op);
+                       }
                        return AdditionResult.Success;
                }
 
@@ -507,12 +526,6 @@ namespace Mono.CSharp {
                        }
                }
                
-               public Attributes OptAttributes {
-                       get {
-                               return attributes;
-                       }
-               }
-               
                public bool HaveStaticConstructor {
                        get {
                                return have_static_constructor;
@@ -531,7 +544,6 @@ namespace Mono.CSharp {
                public bool EmitFieldInitializers (EmitContext ec)
                {
                        ArrayList fields;
-                       ILGenerator ig = ec.ig;
                        Expression instance_expr;
                        
                        if (ec.IsStatic){
@@ -571,22 +583,26 @@ namespace Mono.CSharp {
                void DefineDefaultConstructor (bool is_static)
                {
                        Constructor c;
-                       int mods = 0;
 
-                       c = new Constructor (this, Basename, Parameters.EmptyReadOnlyParameters,
+                       // The default constructor is public
+                       // If the class is abstract, the default constructor is protected
+                       // The default static constructor is private
+
+                       int mods = Modifiers.PUBLIC;
+                       if (is_static)
+                               mods = Modifiers.STATIC | Modifiers.PRIVATE;
+                       else if ((ModFlags & Modifiers.ABSTRACT) != 0)
+                               mods = Modifiers.PROTECTED;
+
+                       c = new Constructor (this, Basename, mods, Parameters.EmptyReadOnlyParameters,
                                             new ConstructorBaseInitializer (
                                                     null, Parameters.EmptyReadOnlyParameters,
                                                     Location),
                                             Location);
                        
-                       if (is_static)
-                               mods = Modifiers.STATIC;
-
-                       c.ModFlags = mods;
-
                        AddConstructor (c);
                        
-                       c.Block = new Block (null);
+                       c.Block = new ToplevelBlock (null, Location);
                        
                }
 
@@ -818,7 +834,7 @@ namespace Mono.CSharp {
                                        return null;
                                }
 
-                               ModuleBuilder builder = CodeGen.ModuleBuilder;
+                               ModuleBuilder builder = CodeGen.Module.Builder;
                                TypeBuilder = builder.DefineType (
                                        Name, type_attributes, ptype, null);
                                
@@ -832,6 +848,9 @@ namespace Mono.CSharp {
                        }
 
                        if (IsGeneric) {
+                               CurrentType = new ConstructedType (
+                                       Name, CurrentTypeParameters, Location);
+
                                foreach (TypeParameter type_param in TypeParameters)
                                        type_param.Define (TypeBuilder);
                        }
@@ -1109,14 +1128,6 @@ namespace Mono.CSharp {
                        if (fields != null)
                                DefineMembers (fields, defined_names);
 
-                       if ((RootContext.WarningLevel >= 4) && (fields != null)) {
-                               foreach (Field f in fields) {
-                                       if (((f.ModFlags & Modifiers.READONLY) != 0) && !f.IsAssigned)
-                                               Report.Warning (649, "Field `" + MakeFQN (Name, f.Name) + "; is never " +
-                                                               "assigned and will ever have its default value");
-                               }
-                       }
-
                        if (this is Class){
                                if (instance_constructors == null){
                                        if (default_constructor == null)
@@ -1178,6 +1189,13 @@ namespace Mono.CSharp {
                        if (delegates != null)
                                DefineMembers (delegates, defined_names);
 
+                       if (CurrentType != null) {
+                               GenericType = CurrentType.ResolveType (ec);
+
+                               ec.ContainerType = GenericType;
+                       }
+
+
 #if CACHE
                        if (TypeBuilder.BaseType != null)
                                parent_container = TypeManager.LookupMemberContainer (TypeBuilder.BaseType);
@@ -1248,7 +1266,7 @@ namespace Mono.CSharp {
                public override MemberList FindMembers (MemberTypes mt, BindingFlags bf,
                                                        MemberFilter filter, object criteria)
                {
-                       ArrayList members = new ArrayList ();
+                       ArrayList members = null;
 
                        int modflags = 0;
                        if ((bf & BindingFlags.Public) != 0)
@@ -1280,35 +1298,52 @@ namespace Mono.CSharp {
 
                        if ((mt & MemberTypes.Field) != 0) {
                                if (fields != null) {
-                                       foreach (Field f in fields) {
+                                       int len = fields.Count;
+                                       for (int i = 0; i < len; i++) {
+                                               Field f = (Field) fields [i];
+                                               
                                                if ((f.ModFlags & modflags) == 0)
                                                        continue;
                                                if ((f.ModFlags & static_mask) != static_flags)
                                                        continue;
 
                                                FieldBuilder fb = f.FieldBuilder;
-                                               if (fb != null && filter (fb, criteria) == true)
+                                               if (fb != null && filter (fb, criteria) == true) {
+                                                       if (members == null)
+                                                               members = new ArrayList ();
+                                                       
                                                        members.Add (fb);
                                        }
                                }
+                               }
 
                                if (constants != null) {
-                                       foreach (Const con in constants) {
+                                       int len = constants.Count;
+                                       for (int i = 0; i < len; i++) {
+                                               Const con = (Const) constants [i];
+                                               
                                                if ((con.ModFlags & modflags) == 0)
                                                        continue;
                                                if ((con.ModFlags & static_mask) != static_flags)
                                                        continue;
 
                                                FieldBuilder fb = con.FieldBuilder;
-                                               if (fb != null && filter (fb, criteria) == true)
+                                               if (fb != null && filter (fb, criteria) == true) {
+                                                       if (members == null)
+                                                               members = new ArrayList ();
+                                                       
                                                        members.Add (fb);
                                        }
                                }
                        }
+                       }
 
                        if ((mt & MemberTypes.Method) != 0) {
                                if (methods != null) {
-                                       foreach (Method m in methods) {
+                                       int len = methods.Count;
+                                       for (int i = 0; i < len; i++) {
+                                               Method m = (Method) methods [i];
+                                               
                                                if ((m.ModFlags & modflags) == 0)
                                                        continue;
                                                if ((m.ModFlags & static_mask) != static_flags)
@@ -1316,26 +1351,40 @@ namespace Mono.CSharp {
                                                
                                                MethodBuilder mb = m.MethodBuilder;
 
-                                               if (mb != null && filter (mb, criteria) == true)
+                                               if (mb != null && filter (mb, criteria) == true) {
+                                                       if (members == null)
+                                                               members = new ArrayList ();
+                                                       
                                                        members.Add (mb);
                                        }
                                }
+                               }
+
+                               if (operators != null) {
+                                       int len = operators.Count;
+                                       for (int i = 0; i < len; i++) {
+                                               Operator o = (Operator) operators [i];
 
-                               if (operators != null){
-                                       foreach (Operator o in operators) {
                                                if ((o.ModFlags & modflags) == 0)
                                                        continue;
                                                if ((o.ModFlags & static_mask) != static_flags)
                                                        continue;
                                                
                                                MethodBuilder ob = o.OperatorMethodBuilder;
-                                               if (ob != null && filter (ob, criteria) == true)
+                                               if (ob != null && filter (ob, criteria) == true) {
+                                                       if (members == null)
+                                                               members = new ArrayList ();
+                                                       
                                                        members.Add (ob);
                                        }
                                }
+                               }
+
+                               if (properties != null) {
+                                       int len = properties.Count;
+                                       for (int i = 0; i < len; i++) {
+                                               Property p = (Property) properties [i];
 
-                               if (properties != null){
-                                       foreach (Property p in properties){
                                                if ((p.ModFlags & modflags) == 0)
                                                        continue;
                                                if ((p.ModFlags & static_mask) != static_flags)
@@ -1344,17 +1393,28 @@ namespace Mono.CSharp {
                                                MethodBuilder b;
 
                                                b = p.GetBuilder;
-                                               if (b != null && filter (b, criteria) == true)
+                                               if (b != null && filter (b, criteria) == true) {
+                                                       if (members == null)
+                                                               members = new ArrayList ();
+                                                       
                                                        members.Add (b);
+                                               }
 
                                                b = p.SetBuilder;
-                                               if (b != null && filter (b, criteria) == true)
+                                               if (b != null && filter (b, criteria) == true) {
+                                                       if (members == null)
+                                                               members = new ArrayList ();
+                                                       
                                                        members.Add (b);
                                        }
                                }
+                               }
+                               
+                               if (indexers != null) {
+                                       int len = indexers.Count;
+                                       for (int i = 0; i < len; i++) {
+                                               Indexer ix = (Indexer) indexers [i];
                                
-                               if (indexers != null){
-                                       foreach (Indexer ix in indexers){
                                                if ((ix.ModFlags & modflags) == 0)
                                                        continue;
                                                if ((ix.ModFlags & static_mask) != static_flags)
@@ -1363,33 +1423,52 @@ namespace Mono.CSharp {
                                                MethodBuilder b;
 
                                                b = ix.GetBuilder;
-                                               if (b != null && filter (b, criteria) == true)
+                                               if (b != null && filter (b, criteria) == true) {
+                                                       if (members == null)
+                                                               members = new ArrayList ();
+                                                       
                                                        members.Add (b);
+                                               }
 
                                                b = ix.SetBuilder;
-                                               if (b != null && filter (b, criteria) == true)
+                                               if (b != null && filter (b, criteria) == true) {
+                                                       if (members == null)
+                                                               members = new ArrayList ();
+                                                       
                                                        members.Add (b);
                                        }
                                }
                        }
+                       }
 
                        if ((mt & MemberTypes.Event) != 0) {
-                               if (events != null)
-                                       foreach (Event e in events) {
+                               if (events != null) {
+                                       int len = events.Count;
+                                       for (int i = 0; i < len; i++) {
+                                               Event e = (Event) events [i];
+                                               
                                                if ((e.ModFlags & modflags) == 0)
                                                        continue;
                                                if ((e.ModFlags & static_mask) != static_flags)
                                                        continue;
 
                                                MemberInfo eb = e.EventBuilder;
-                                               if (eb != null && filter (eb, criteria) == true)
+                                               if (eb != null && filter (eb, criteria) == true) {
+                                                       if (members == null)
+                                                               members = new ArrayList ();
+                                                       
                                                        members.Add (e.EventBuilder);
                                        }
                        }
+                               }
+                       }
                        
                        if ((mt & MemberTypes.Property) != 0){
-                               if (properties != null)
-                                       foreach (Property p in properties) {
+                               if (properties != null) {
+                                       int len = properties.Count;
+                                       for (int i = 0; i < len; i++) {
+                                               Property p = (Property) properties [i];
+                                               
                                                if ((p.ModFlags & modflags) == 0)
                                                        continue;
                                                if ((p.ModFlags & static_mask) != static_flags)
@@ -1397,12 +1476,19 @@ namespace Mono.CSharp {
 
                                                MemberInfo pb = p.PropertyBuilder;
                                                if (pb != null && filter (pb, criteria) == true) {
+                                                       if (members == null)
+                                                               members = new ArrayList ();
+                                                       
                                                        members.Add (p.PropertyBuilder);
                                                }
                                        }
+                               }
+
+                               if (indexers != null) {
+                                       int len = indexers.Count;
+                                       for (int i = 0; i < len; i++) {
+                                               Indexer ix = (Indexer) indexers [i];
 
-                               if (indexers != null)
-                                       foreach (Indexer ix in indexers) {
                                                if ((ix.ModFlags & modflags) == 0)
                                                        continue;
                                                if ((ix.ModFlags & static_mask) != static_flags)
@@ -1410,87 +1496,136 @@ namespace Mono.CSharp {
 
                                                MemberInfo ib = ix.PropertyBuilder;
                                                if (ib != null && filter (ib, criteria) == true) {
+                                                       if (members == null)
+                                                               members = new ArrayList ();
+                                                       
                                                        members.Add (ix.PropertyBuilder);
                                                }
                                        }
                        }
+                       }
                        
                        if ((mt & MemberTypes.NestedType) != 0) {
-                               if (types != null){
-                                       foreach (TypeContainer t in types) {
+                               if (types != null) {
+                                       int len = types.Count;
+                                       for (int i = 0; i < len; i++) {
+                                               TypeContainer t = (TypeContainer) types [i];
+                                               
                                                if ((t.ModFlags & modflags) == 0)
                                                        continue;
 
                                                TypeBuilder tb = t.TypeBuilder;
-                                               if (tb != null && (filter (tb, criteria) == true))
+                                               if (tb != null && (filter (tb, criteria) == true)) {
+                                                       if (members == null)
+                                                               members = new ArrayList ();
+                                                       
                                                                members.Add (tb);
                                        }
                                }
+                               }
+
+                               if (enums != null) {
+                                       int len = enums.Count;
+                                       for (int i = 0; i < len; i++) {
+                                               Enum en = (Enum) enums [i];
 
-                               if (enums != null){
-                                       foreach (Enum en in enums){
                                                if ((en.ModFlags & modflags) == 0)
                                                        continue;
 
                                                TypeBuilder tb = en.TypeBuilder;
-                                               if (tb != null && (filter (tb, criteria) == true))
+                                               if (tb != null && (filter (tb, criteria) == true)) {
+                                                       if (members == null)
+                                                               members = new ArrayList ();
+                                                       
                                                        members.Add (tb);
                                        }
                                }
+                               }
+                               
+                               if (delegates != null) {
+                                       int len = delegates.Count;
+                                       for (int i = 0; i < len; i++) {
+                                               Delegate d = (Delegate) delegates [i];
                                
-                               if (delegates != null){
-                                       foreach (Delegate d in delegates){
                                                if ((d.ModFlags & modflags) == 0)
                                                        continue;
 
                                                TypeBuilder tb = d.TypeBuilder;
-                                               if (tb != null && (filter (tb, criteria) == true))
+                                               if (tb != null && (filter (tb, criteria) == true)) {
+                                                       if (members == null)
+                                                               members = new ArrayList ();
+                                                       
                                                        members.Add (tb);
                                        }
                                }
+                               }
+
+                               if (interfaces != null) {
+                                       int len = interfaces.Count;
+                                       for (int i = 0; i < len; i++) {
+                                               Interface iface = (Interface) interfaces [i];
 
-                               if (interfaces != null){
-                                       foreach (Interface iface in interfaces){
                                                if ((iface.ModFlags & modflags) == 0)
                                                        continue;
 
                                                TypeBuilder tb = iface.TypeBuilder;
-                                               if (tb != null && (filter (tb, criteria) == true))
+                                               if (tb != null && (filter (tb, criteria) == true)) {
+                                                       if (members == null)
+                                                               members = new ArrayList ();
+                                                       
                                                        members.Add (tb);
                                        }
                                }
                        }
+                       }
 
                        if ((mt & MemberTypes.Constructor) != 0){
                                if (((bf & BindingFlags.Instance) != 0) && (instance_constructors != null)){
-                                       foreach (Constructor c in instance_constructors){
+                                       int len = instance_constructors.Count;
+                                       for (int i = 0; i < len; i++) {
+                                               Constructor c = (Constructor) instance_constructors [i];
+                                               
                                                ConstructorBuilder cb = c.ConstructorBuilder;
-                                               if (cb != null)
-                                                       if (filter (cb, criteria) == true)
+                                               if (cb != null && filter (cb, criteria) == true) {
+                                                       if (members == null)
+                                                               members = new ArrayList ();
+                                                       
                                                                members.Add (cb);
                                        }
                                }
+                               }
 
                                if (((bf & BindingFlags.Static) != 0) && (default_static_constructor != null)){
                                        ConstructorBuilder cb =
                                                default_static_constructor.ConstructorBuilder;
                                        
-                                       if (cb != null)
-                                       if (filter (cb, criteria) == true)
+                                       if (cb != null && filter (cb, criteria) == true) {
+                                               if (members == null)
+                                                       members = new ArrayList ();
+                                               
                                                members.Add (cb);
                                }
                        }
+                       }
 
                        //
                        // Lookup members in parent if requested.
                        //
                        if (((bf & BindingFlags.DeclaredOnly) == 0) && (TypeBuilder.BaseType != null)) {
                                MemberList list = FindMembers (TypeBuilder.BaseType, mt, bf, filter, criteria);
+                               if (list.Count > 0) {
+                                       if (members == null)
+                                               members = new ArrayList ();
+                                       
                                members.AddRange (list);
                        }
+                       }
 
                        Timer.StopTimer (TimerType.TcFindMembers);
 
+                       if (members == null)
+                               return MemberList.Empty;
+                       else
                        return new MemberList (members);
                }
 
@@ -1528,7 +1663,7 @@ namespace Mono.CSharp {
                {
                        if (constants != null)
                                foreach (Const con in constants)
-                                       con.EmitConstant (this);
+                                       con.Emit (this);
                        return;
                }
 
@@ -1587,10 +1722,10 @@ namespace Mono.CSharp {
                        if (RootContext.WarningLevel >= 3) {
                                if (fields != null){
                                        foreach (Field f in fields) {
-                                               if ((f.ModFlags & Modifiers.PUBLIC) != 0)
+                                               if ((f.ModFlags & Modifiers.Accessibility) != Modifiers.PRIVATE)
                                                        continue;
                                                
-                                               if (f.status == 0){
+                                               if ((f.status & Field.Status.USED) == 0){
                                                        Report.Warning (
                                                                169, f.Location, "Private field " +
                                                                MakeName (f.Name) + " is never used");
@@ -1628,11 +1763,12 @@ namespace Mono.CSharp {
                
                public override void CloseType ()
                {
+                       if (Created)
+                               return;
+                       
                        try {
-                               if (!Created){
                                        Created = true;
                                        TypeBuilder.CreateType ();
-                               }
                        } catch (TypeLoadException){
                                //
                                // This is fine, the code still created the type
@@ -1666,6 +1802,29 @@ namespace Mono.CSharp {
                        if (Delegates != null)
                                foreach (Delegate d in Delegates)
                                        d.CloseType ();
+                       
+                       types = null;
+                       properties = null;
+                       enums = null;
+                       delegates = null;
+                       fields = null;
+                       initialized_fields = null;
+                       initialized_static_fields = null;
+                       constants = null;
+                       interfaces = null;
+                       interface_order = null;
+                       methods = null;
+                       events = null;
+                       indexers = null;
+                       operators = null;
+                       ec = null;
+                       default_constructor = null;
+                       default_static_constructor = null;
+                       type_bases = null;
+                       OptAttributes = null;
+                       ifaces = null;
+                       parent_container = null;
+                       member_cache = null;
                }
 
                public string MakeName (string n)
@@ -1819,11 +1978,6 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public static void Error_ExplicitInterfaceNotMemberInterface (Location loc, string name)
-               {
-                       Report.Error (539, loc, "Explicit implementation: `" + name + "' is not a member of the interface");
-               }
-
                //
                // IMemberContainer
                //
@@ -1860,7 +2014,13 @@ namespace Mono.CSharp {
 
                MemberList IMemberContainer.GetMembers (MemberTypes mt, BindingFlags bf)
                {
-                       return FindMembers (mt, bf | BindingFlags.DeclaredOnly, null, null);
+                       BindingFlags new_bf = bf | BindingFlags.DeclaredOnly;
+
+                       if (GenericType != null)
+                               return TypeManager.FindMembers (GenericType, mt, new_bf,
+                                                               null, null);
+                       else
+                               return FindMembers (mt, new_bf, null, null);
                }
 
                //
@@ -2052,7 +2212,7 @@ namespace Mono.CSharp {
                        Modifiers.UNSAFE;
 
                public Class (NamespaceEntry ns, TypeContainer parent, string name, int mod, Attributes attrs, Location l)
-                       : base (ns, parent, name, l)
+                       : base (ns, parent, name, attrs, l)
                {
                        int accmods;
 
@@ -2062,7 +2222,6 @@ namespace Mono.CSharp {
                                accmods = Modifiers.PRIVATE;
 
                        this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
-                       this.attributes = attrs;
                }
 
                //
@@ -2089,7 +2248,7 @@ namespace Mono.CSharp {
                        Modifiers.PRIVATE;
 
                public Struct (NamespaceEntry ns, TypeContainer parent, string name, int mod, Attributes attrs, Location l)
-                       : base (ns, parent, name, l)
+                       : base (ns, parent, name, attrs, l)
                {
                        int accmods;
                        
@@ -2101,8 +2260,6 @@ namespace Mono.CSharp {
                        this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
 
                        this.ModFlags |= Modifiers.SEALED;
-                       this.attributes = attrs;
-                       
                }
 
                //
@@ -2329,6 +2486,7 @@ namespace Mono.CSharp {
                        Modifiers.OVERRIDE |
                        Modifiers.ABSTRACT |
                        Modifiers.UNSAFE |
+                       Modifiers.METHOD_YIELDS | 
                        Modifiers.EXTERN;
 
                //
@@ -2337,7 +2495,8 @@ namespace Mono.CSharp {
                public Method (DeclSpace ds, Expression return_type, int mod, string name,
                               Parameters parameters, Attributes attrs, Location l)
                        : base (ds, return_type, mod, AllowedModifiers, name, attrs, parameters, l)
-               { }
+               {
+               }
 
                public Method (GenericMethod generic, Expression return_type, int mod, string name,
                               Parameters parameters, Attributes attrs, Location l)
@@ -2501,15 +2660,18 @@ namespace Mono.CSharp {
                //
                public override bool Define (TypeContainer container)
                {
-                       if (!DoDefine (container))
-                               return false;
-
+                       DeclSpace decl;
                        MethodBuilder mb = null;
                        if (GenericMethod != null) {
                                mb = container.TypeBuilder.DefineGenericMethod (Name, flags);
                                if (!GenericMethod.Define (mb))
                                        return false;
-                       }
+                               decl = GenericMethod;
+                       } else
+                               decl = container;
+
+                       if (!DoDefine (decl, container))
+                               return false;
 
                        if (!CheckBase (container))
                                return false;
@@ -2544,7 +2706,7 @@ namespace Mono.CSharp {
                        // This is used to track the Entry Point,
                        //
                        if (Name == "Main" &&
-                           ((ModFlags & Modifiers.STATIC) != 0) && 
+                           ((ModFlags & Modifiers.STATIC) != 0) && RootContext.NeedsEntryPoint && 
                            (RootContext.MainClass == null ||
                             RootContext.MainClass == container.TypeBuilder.FullName)){
                                 if (IsEntryPoint (MethodBuilder, ParameterInfo)) {
@@ -2574,6 +2736,7 @@ namespace Mono.CSharp {
                {
                        MethodData.Emit (container, Block, this);
                        Block = null;
+                       MethodData = null;
                }
 
                void IIteratorContainer.SetYields ()
@@ -2607,7 +2770,7 @@ namespace Mono.CSharp {
                        Expression parent_constructor_group;
                        Type t;
 
-                       ec.CurrentBlock = new Block (null, Block.Flags.Implicit, parameters);
+                       ec.CurrentBlock = new ToplevelBlock (Block.Flags.Implicit, parameters, loc);
 
                        if (argument_list != null){
                                foreach (Argument a in argument_list){
@@ -2683,7 +2846,6 @@ namespace Mono.CSharp {
        public class Constructor : MethodCore {
                public ConstructorBuilder ConstructorBuilder;
                public ConstructorInitializer Initializer;
-               new public Attributes OptAttributes;
 
                // <summary>
                //   Modifiers allowed for a constructor.
@@ -2701,9 +2863,9 @@ namespace Mono.CSharp {
                // The spec claims that static is not permitted, but
                // my very own code has static constructors.
                //
-               public Constructor (DeclSpace ds, string name, Parameters args,
+               public Constructor (DeclSpace ds, string name, int mod, Parameters args,
                                    ConstructorInitializer init, Location l)
-                       : base (ds, null, 0, AllowedModifiers, name, null, args, l)
+                       : base (ds, null, mod, AllowedModifiers, name, null, args, l)
                {
                        Initializer = init;
                }
@@ -3162,8 +3324,7 @@ namespace Mono.CSharp {
                                                member.InterfaceType, name, ReturnType, ParameterTypes);
 
                                if (member.InterfaceType != null && implementing == null){
-                                       TypeContainer.Error_ExplicitInterfaceNotMemberInterface (
-                                               Location, name);
+                                       Report.Error (539, Location, "'{0}' in explicit interface declaration is not an interface", method_name);
                                        return false;
                                }
                        }
@@ -3263,7 +3424,9 @@ namespace Mono.CSharp {
                                        method_name, flags, CallingConventions,
                                        ReturnType, ParameterTypes);
                        else
-                               builder.SetGenericMethodSignature (ReturnType, ParameterTypes);
+                               builder.SetGenericMethodSignature (
+                                       flags, CallingConventions,
+                                       ReturnType, ParameterTypes);
 
                        if (builder == null)
                                return false;
@@ -3378,7 +3541,7 @@ namespace Mono.CSharp {
                        //
                        // FIXME: This code generates buggy code
                        //
-                       if (member.Name == "Finalize" && ReturnType == TypeManager.void_type)
+                       if (member is Destructor)
                                EmitDestructor (ec, block);
                        else {
                                SymbolWriter sw = CodeGen.SymbolWriter;
@@ -3400,18 +3563,15 @@ namespace Mono.CSharp {
                        ILGenerator ig = ec.ig;
                        
                        Label finish = ig.DefineLabel ();
-                       bool old_in_try = ec.InTry;
+
+                       block.SetDestructor ();
                        
                        ig.BeginExceptionBlock ();
-                       ec.InTry = true;
                        ec.ReturnLabel = finish;
                        ec.HasReturnLabel = true;
                        ec.EmitTopBlock (block, null, Location);
-                       ec.InTry = old_in_try;
                        
                        // ig.MarkLabel (finish);
-                       bool old_in_finally = ec.InFinally;
-                       ec.InFinally = true;
                        ig.BeginFinallyBlock ();
                        
                        if (ec.ContainerType.BaseType != null) {
@@ -3426,7 +3586,6 @@ namespace Mono.CSharp {
                                        ig.Emit (OpCodes.Call, (MethodInfo) parent_destructor.Methods [0]);
                                }
                        }
-                       ec.InFinally = old_in_finally;
                        
                        ig.EndExceptionBlock ();
                        //ig.MarkLabel (ec.ReturnLabel);
@@ -3434,12 +3593,22 @@ namespace Mono.CSharp {
                }
        }
 
+       public class Destructor : Method {
+
+               public Destructor (DeclSpace ds, Expression return_type, int mod, string name,
+                                  Parameters parameters, Attributes attrs, Location l)
+                       : base (ds, return_type, mod, name, parameters, attrs, l)
+               { }
+
+       }
+       
        abstract public class MemberBase : MemberCore {
                public Expression Type;
-               public readonly Attributes OptAttributes;
 
                protected MethodAttributes flags;
 
+               protected readonly int explicit_mod_flags;
+
                //
                // The "short" name of this property / indexer / event.  This is the
                // name without the explicit interface.
@@ -3481,11 +3650,11 @@ namespace Mono.CSharp {
                //
                protected MemberBase (Expression type, int mod, int allowed_mod, int def_mod, string name,
                                      Attributes attrs, Location loc)
-                       : base (name, loc)
+                       : base (name, attrs, loc)
                {
+                       explicit_mod_flags = mod;
                        Type = type;
                        ModFlags = Modifiers.Check (allowed_mod, mod, def_mod, loc);
-                       OptAttributes = attrs;
                }
 
                protected virtual bool CheckBase (TypeContainer container)
@@ -3685,7 +3854,7 @@ namespace Mono.CSharp {
                        return !error;
                }
 
-               protected virtual bool DoDefine (TypeContainer container)
+               protected virtual bool DoDefine (DeclSpace decl, TypeContainer container)
                {
                        if (Name == null)
                                Name = "this";
@@ -3696,7 +3865,7 @@ namespace Mono.CSharp {
                        flags = Modifiers.MethodAttr (ModFlags);
 
                        // Lookup Type, verify validity
-                       MemberType = container.ResolveType (Type, false, Location);
+                       MemberType = decl.ResolveType (Type, false, Location);
                        if (MemberType == null)
                                return false;
 
@@ -3758,12 +3927,19 @@ namespace Mono.CSharp {
                                if (InterfaceType == null)
                                        return false;
 
+                               if (InterfaceType.IsClass) {
+                                       Report.Error (538, Location, "'{0}' in explicit interface declaration is not an interface", ExplicitInterfaceName);
+                                       return false;
+                               }
+
                                // Compute the full name that we need to export.
                                Name = InterfaceType.FullName + "." + ShortName;
                                
                                if (!container.VerifyImplements (InterfaceType, ShortName, Name, Location))
                                        return false;
                                
+                               Modifiers.Check (Modifiers.AllowedExplicitImplFlags, explicit_mod_flags, 0, Location);
+                               
                                IsExplicitImpl = true;
                        } else
                                IsExplicitImpl = false;
@@ -3802,8 +3978,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               public bool IsAssigned;
-
                protected readonly Object init;
                // Private.
                Expression init_expr;
@@ -3832,6 +4006,11 @@ namespace Mono.CSharp {
 
                        return init_expr;
                }
+
+               public void SetAssigned ()
+               {
+                       status |= Status.ASSIGNED;
+               }
        }
 
        //
@@ -3934,10 +4113,17 @@ namespace Mono.CSharp {
                                return false;
                        }
 
+                       try {
                        FieldBuilder = container.TypeBuilder.DefineField (
                                Name, t, Modifiers.FieldAttr (ModFlags));
 
                        TypeManager.RegisterFieldBase (FieldBuilder, this);
+                       }
+                       catch (ArgumentException) {
+                               Report.Warning (-24, Location, "The Microsoft runtime is unable to use [void|void*] as a field type, try using the Mono runtime.");
+                               return false;
+                       }
+
                        return true;
                }
 
@@ -3989,9 +4175,9 @@ namespace Mono.CSharp {
                        Set = set_block;
                }
 
-               protected override bool DoDefine (TypeContainer container)
+               protected override bool DoDefine (DeclSpace decl, TypeContainer container)
                {
-                       if (!base.DoDefine (container))
+                       if (!base.DoDefine (decl, container))
                                return false;
 
                        ec = new EmitContext (container, Location, null, MemberType, ModFlags);
@@ -4138,7 +4324,7 @@ namespace Mono.CSharp {
                }
        }
                        
-       public class Property : PropertyBase {
+       public class Property : PropertyBase, IIteratorContainer {
                const int AllowedModifiers =
                        Modifiers.NEW |
                        Modifiers.PUBLIC |
@@ -4151,6 +4337,7 @@ namespace Mono.CSharp {
                        Modifiers.ABSTRACT |
                        Modifiers.UNSAFE |
                        Modifiers.EXTERN |
+                       Modifiers.METHOD_YIELDS |
                        Modifiers.VIRTUAL;
 
                public Property (DeclSpace ds, Expression type, string name, int mod_flags,
@@ -4164,7 +4351,7 @@ namespace Mono.CSharp {
 
                public override bool Define (TypeContainer container)
                {
-                       if (!DoDefine (container))
+                       if (!DoDefine (container, container))
                                return false;
 
                        if (!CheckBase (container))
@@ -4182,6 +4369,20 @@ namespace Mono.CSharp {
                                                          parameters, ip, CallingConventions.Standard,
                                                          Get.OptAttributes, ModFlags, flags, false);
 
+                               //
+                               // Setup iterator if we are one
+                               //
+                               if ((ModFlags & Modifiers.METHOD_YIELDS) != 0){
+                                       IteratorHandler ih = new  IteratorHandler (
+                                                                                  "get", container, MemberType,
+                                                                                  parameters, ip, ModFlags, Location);
+                                       
+                                       Block new_block = ih.Setup (block);
+                                       if (new_block == null)
+                                               return false;
+                                       block = new_block;
+                               }
+                               
                                if (!GetData.Define (container))
                                        return false;
 
@@ -4238,6 +4439,11 @@ namespace Mono.CSharp {
                        }
                        return true;
                }
+
+               public void SetYields ()
+               {
+                       ModFlags |= Modifiers.METHOD_YIELDS;
+               }
        }
 
        /// </summary>
@@ -4418,7 +4624,7 @@ namespace Mono.CSharp {
                        EventAttributes e_attr = EventAttributes.RTSpecialName | EventAttributes.SpecialName;
                        MethodAttributes m_attr = MethodAttributes.HideBySig | MethodAttributes.SpecialName
 ;
-                       if (!DoDefine (container))
+                       if (!DoDefine (container, container))
                                return false;
 
                        if (init != null && ((ModFlags & Modifiers.ABSTRACT) != 0)){
@@ -4584,8 +4790,6 @@ namespace Mono.CSharp {
                //
                // Are we implementing an interface ?
                //
-               bool IsImplementing = false;
-               
                public Indexer (DeclSpace ds, Expression type, string int_type, int flags,
                                Parameters parameters, Accessor get_block, Accessor set_block,
                                Attributes attrs, Location loc)
@@ -4601,7 +4805,7 @@ namespace Mono.CSharp {
                                PropertyAttributes.RTSpecialName |
                                PropertyAttributes.SpecialName;
                        
-                       if (!DoDefine (container))
+                       if (!DoDefine (container, container))
                                return false;
 
                        IndexerName = Attribute.ScanForIndexerName (ec, OptAttributes);
@@ -4621,6 +4825,9 @@ namespace Mono.CSharp {
                                Name = ShortName;
                        }
 
+                       if (!CheckNameCollision (container))
+                               return false;
+
                        if (!CheckBase (container))
                                return false;
 
@@ -4712,11 +4919,6 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       if (GetData != null)
-                               IsImplementing = GetData.IsImplementing;
-                       else if (SetData != null)
-                               IsImplementing = SetData.IsImplementing;
-
                        //
                        // Define the PropertyBuilder if one of the following conditions are met:
                        // a) we're not implementing an interface indexer.
@@ -4739,9 +4941,53 @@ namespace Mono.CSharp {
 
                        return true;
                }
+
+               bool CheckNameCollision (TypeContainer container) {
+                       switch (VerifyName (container)){
+                               case DeclSpace.AdditionResult.NameExists:
+                                       Report.Error (102, Location, "The container '{0}' already contains a definition for '{1}'", container.GetSignatureForError (), Name);
+                                       return false;
+
+                               case DeclSpace.AdditionResult.Success:
+                                       return true;
+                       }
+                       throw new NotImplementedException ();
+               }
+
+               DeclSpace.AdditionResult VerifyName (TypeContainer container) {
+                       if (!AddIndexer (container, container.Name + "." + Name))
+                               return DeclSpace.AdditionResult.NameExists;
+
+                       if (Get != null) {
+                               if (!AddIndexer (container, container.Name + ".get_" + Name))
+                                       return DeclSpace.AdditionResult.NameExists;
+                       }
+
+                       if (Set != null) {
+                               if (!AddIndexer (container, container.Name + ".set_" + Name))
+                                       return DeclSpace.AdditionResult.NameExists;
+                       }
+                       return DeclSpace.AdditionResult.Success;
+               }
+
+               bool AddIndexer (TypeContainer container, string fullname)
+               {
+                       object value = container.GetDefinition (fullname);
+
+                       if (value != null) {
+                               return value.GetType () != GetType () ? false : true;
+                       }
+
+                       container.DefineName (fullname, this);
+                       return true;
+               }
+
+               public override string GetSignatureForError () {
+                       return TypeManager.CSharpSignature (PropertyBuilder, true);
+               }
        }
 
-       public class Operator : MemberBase {
+       public class Operator : MemberBase, IIteratorContainer {
 
                const int AllowedModifiers =
                        Modifiers.PUBLIC |
@@ -4808,6 +5054,7 @@ namespace Mono.CSharp {
                        : base (ret_type, mod_flags, AllowedModifiers, Modifiers.PUBLIC, "", attrs, loc)
                {
                        OperatorType = type;
+                       Name = "op_" + OperatorType;
                        ReturnType = ret_type;
                        FirstArgType = arg1type;
                        FirstArgName = arg1name;
@@ -4851,6 +5098,7 @@ namespace Mono.CSharp {
                                                     new Parameters (param_list, null, Location),
                                                     OptAttributes, Location);
 
+                       OperatorMethod.Block = Block;
                        OperatorMethod.IsOperator = true;                       
                        OperatorMethod.Define (container);
 
@@ -4965,7 +5213,6 @@ namespace Mono.CSharp {
                        if ((ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0)
                                return;
                        
-                       OperatorMethod.Block = Block;
                        OperatorMethod.Emit (container);
                        Block = null;
                }
@@ -5047,6 +5294,11 @@ namespace Mono.CSharp {
                                        GetName (OperatorType),
                                        param_types [0], param_types [1]);
                }
+
+               public void SetYields ()
+               {
+                       ModFlags |= Modifiers.METHOD_YIELDS;
+               }
        }
 
        //
@@ -5222,10 +5474,7 @@ namespace Mono.CSharp {
                        // If only accessible to the defining assembly or 
                        if (prot == MethodAttributes.FamANDAssem ||
                            prot == MethodAttributes.Assembly){
-                               if (m.DeclaringType.Assembly == CodeGen.AssemblyBuilder)
-                                       return true;
-                               else
-                                       return false;
+                               return m.DeclaringType.Assembly == CodeGen.Assembly.Builder;
                        }
 
                        // Anything else (FamOrAssembly and Public) is fine