2004-11-16 Martin Baulig <martin@ximian.com>
authorMartin Baulig <martin@novell.com>
Tue, 16 Nov 2004 02:40:23 +0000 (02:40 -0000)
committerMartin Baulig <martin@novell.com>
Tue, 16 Nov 2004 02:40:23 +0000 (02:40 -0000)
Merged back from gmcs; these changes already went into gmcs a
couple of weeks ago.

* typemanager.cs
(TypeManager.AddUserType): Removed the `ifaces' argument.
(TypeManager.RegisterBuilder): Take a `Type []' instead of a
`TypeExpr []'.
(TypeManager.AddUserInterface): Removed.
(TypeManager.ExpandInterfaces): Return a `Type []' instead of a
`TypeExpr []'.
(TypeManager.GetInterfaces): Likewise.
(TypeManager.GetExplicitInterfaces): Likewise.

* ecore.cs (TypeExpr.GetInterfaces): Removed.

* class.cs (TypeContainer.base_class_type): Replaced with `ptype'.
(TypeContainer.base_inteface_types): Replaced with `ifaces'.

svn path=/trunk/mcs/; revision=36154

mcs/mcs/ChangeLog
mcs/mcs/class.cs
mcs/mcs/decl.cs
mcs/mcs/ecore.cs
mcs/mcs/expression.cs
mcs/mcs/pending.cs
mcs/mcs/typemanager.cs

index eea958cd2193a3b006785080284a8bc4402bbc12..721ec2bbe634da6fc1a2c5f4a27bc185dcc17c8c 100755 (executable)
@@ -1,3 +1,23 @@
+2004-11-16  Martin Baulig  <martin@ximian.com>
+
+       Merged back from gmcs; these changes already went into gmcs a
+       couple of weeks ago.
+
+       * typemanager.cs
+       (TypeManager.AddUserType): Removed the `ifaces' argument.
+       (TypeManager.RegisterBuilder): Take a `Type []' instead of a
+       `TypeExpr []'.
+       (TypeManager.AddUserInterface): Removed.
+       (TypeManager.ExpandInterfaces): Return a `Type []' instead of a
+       `TypeExpr []'.
+       (TypeManager.GetInterfaces): Likewise.
+       (TypeManager.GetExplicitInterfaces): Likewise.
+
+       * ecore.cs (TypeExpr.GetInterfaces): Removed.
+
+       * class.cs (TypeContainer.base_class_type): Replaced with `ptype'.
+       (TypeContainer.base_inteface_types): Replaced with `ifaces'.
+
 2004-11-14  Ben Maurer  <bmaurer@ximian.com>
 
        * statement.cs: Avoid adding bools to a hashtable.
index b03a9df1e48df2cfea288d556b6bc1bab3afe3a2..d10a844a03f033f97ee83f54c1ef0ab95df7aaa6 100755 (executable)
@@ -444,7 +444,7 @@ namespace Mono.CSharp {
                // from classes from the arraylist `type_bases' 
                //
                string     base_class_name;
-               public Type base_class_type;
+               TypeExpr parent_type;
 
                ArrayList type_bases;
 
@@ -452,8 +452,8 @@ namespace Mono.CSharp {
                bool members_defined_ok;
 
                // The interfaces we implement.
-               TypeExpr [] ifaces;
-               protected Type[] base_inteface_types;
+               protected Type [] ifaces;
+               protected Type ptype;
 
                // The parent member container and our member cache
                IMemberContainer parent_container;
@@ -1115,7 +1115,7 @@ namespace Mono.CSharp {
                                                      Name);
                        }
 
-                       return TypeManager.ExpandInterfaces (ifaces);
+                       return ifaces;
                }
 
                bool error = false;
@@ -1125,8 +1125,6 @@ namespace Mono.CSharp {
                //
                public override TypeBuilder DefineType ()
                {
-                       TypeExpr parent;
-
                        if (TypeBuilder != null)
                                return TypeBuilder;
 
@@ -1143,16 +1141,16 @@ namespace Mono.CSharp {
 
                        ec = new EmitContext (this, Mono.CSharp.Location.Null, null, null, ModFlags);
 
-                       ifaces = GetClassBases (out parent, out error); 
+                       TypeExpr[] iface_exprs = GetClassBases (out parent_type, out error);
                        if (error)
                                return null;
 
-                       if (parent == null) {
+                       if (parent_type == null) {
                                if (Kind == Kind.Class){
                                        if (RootContext.StdLib)
-                                               parent = TypeManager.system_object_expr;
+                                               parent_type = TypeManager.system_object_expr;
                                        else if (Name != "System.Object")
-                                               parent = TypeManager.system_object_expr;
+                                               parent_type = TypeManager.system_object_expr;
                                } else if (Kind == Kind.Struct) {
                                        //
                                        // If we are compiling our runtime,
@@ -1160,9 +1158,9 @@ namespace Mono.CSharp {
                                        // parent is `System.Object'.
                                        //
                                        if (!RootContext.StdLib && Name == "System.ValueType")
-                                               parent = TypeManager.system_object_expr;
+                                               parent_type = TypeManager.system_object_expr;
                                        else
-                                               parent = TypeManager.system_valuetype_expr;
+                                               parent_type = TypeManager.system_valuetype_expr;
                                }
                        }
 
@@ -1171,9 +1169,9 @@ namespace Mono.CSharp {
 
                        TypeAttributes type_attributes = TypeAttr;
 
-                       if (parent != null) {
-                               base_class_type = parent.ResolveType (ec);
-                               if (base_class_type == null) {
+                       if (parent_type != null) {
+                               ptype = parent_type.ResolveType (ec);
+                               if (ptype == null) {
                                        error = true;
                                        return null;
                                }
@@ -1188,7 +1186,7 @@ namespace Mono.CSharp {
                                
                                        ModuleBuilder builder = CodeGen.Module.Builder;
                                        TypeBuilder = builder.DefineType (
-                                               Name, type_attributes, base_class_type, null);
+                                               Name, type_attributes, ptype, null);
                                
                                } else {
                                        TypeBuilder builder = Parent.DefineType ();
@@ -1196,7 +1194,7 @@ namespace Mono.CSharp {
                                                return null;
                                
                                        TypeBuilder = builder.DefineNestedType (
-                                               Basename, type_attributes, base_class_type, null);
+                                               Basename, type_attributes, ptype, null);
                                }
                        }
                        catch (ArgumentException) {
@@ -1217,20 +1215,17 @@ namespace Mono.CSharp {
                        }
 
                        // add interfaces that were not added at type creation
-                       if (ifaces != null) {
-                               base_inteface_types = new Type[ifaces.Length];
-                               for (int i = 0; i < ifaces.Length; ++i) {
-                                       Type itype = ifaces [i].ResolveType (ec);
-                                       if (itype == null) {
-                                               error = true;
-                                               continue;
-                                       }
-                                       TypeBuilder.AddInterfaceImplementation (itype);
-                                       base_inteface_types [i] = itype;
+                       if (iface_exprs != null) {
+                               ifaces = TypeManager.ExpandInterfaces (ec, iface_exprs);
+                               if (ifaces == null) {
+                                       error = true;
+                                       return null;
                                }
 
-                               if (error)
-                                       return null;
+                               foreach (Type itype in ifaces)
+                                       TypeBuilder.AddInterfaceImplementation (itype);
+
+                               TypeManager.RegisterBuilder (TypeBuilder, ifaces);
                        }
 
                        //
@@ -1238,9 +1233,9 @@ namespace Mono.CSharp {
                        //
                        ec.ContainerType = TypeBuilder;
 
-                       TypeManager.AddUserType (Name, TypeBuilder, this, ifaces);
+                       TypeManager.AddUserType (Name, TypeBuilder, this);
 
-                       if ((parent != null) && parent.IsAttribute) {
+                       if ((parent_type != null) && parent_type.IsAttribute) {
                                RootContext.RegisterAttribute (this);
                        } else if (!(this is Iterator))
                                RootContext.RegisterOrder (this); 
@@ -1283,7 +1278,7 @@ namespace Mono.CSharp {
                        if (Parts != null) {
                                foreach (ClassPart part in Parts) {
                                        part.TypeBuilder = TypeBuilder;
-                                       part.base_class_type = base_class_type;
+                                       part.ptype = ptype;
                                        part.ec = new EmitContext (part, Mono.CSharp.Location.Null, null, null, ModFlags);
                                }
                        }
@@ -1929,8 +1924,8 @@ namespace Mono.CSharp {
                                                members.AddRange (list);
                                        }
                                }
-                               if (base_inteface_types != null) {
-                                       foreach (Type base_type in base_inteface_types) {
+                               if (ifaces != null) {
+                                       foreach (Type base_type in ifaces) {
                                                MemberList list = TypeContainer.FindMembers (base_type, mt, bf, filter, criteria);
 
                                                if (list.Count > 0) {
@@ -2343,8 +2338,8 @@ namespace Mono.CSharp {
                        bool found = false;
 
                        if (ifaces != null){
-                               foreach (TypeExpr t in ifaces){
-                                       if (t.Type == interface_type){
+                               foreach (Type t in ifaces){
+                                       if (t == interface_type){
                                                found = true;
                                                break;
                                        }
@@ -2361,13 +2356,13 @@ namespace Mono.CSharp {
 
                protected override void VerifyObsoleteAttribute()
                {
-                       CheckUsageOfObsoleteAttribute (base_class_type);
+                       CheckUsageOfObsoleteAttribute (ptype);
 
                        if (ifaces == null)
                                return;
 
-                       foreach (TypeExpr expr in ifaces) {
-                               CheckUsageOfObsoleteAttribute (expr.Type);
+                       foreach (Type iface in ifaces) {
+                               CheckUsageOfObsoleteAttribute (iface);
                        }
                }
 
@@ -2710,13 +2705,13 @@ namespace Mono.CSharp {
                        if (tb == null)
                                return null;
 
-                       if (base_class_type != TypeManager.object_type) {
-                               Report.Error (713, Location, "Static class '{0}' cannot derive from type '{1}'. Static classes must derive from object", GetSignatureForError (), TypeManager.CSharpName (base_class_type));
+                       if (ptype != TypeManager.object_type) {
+                               Report.Error (713, Location, "Static class '{0}' cannot derive from type '{1}'. Static classes must derive from object", GetSignatureForError (), TypeManager.CSharpName (ptype));
                                return null;
                        }
 
-                       if (base_inteface_types != null) {
-                               foreach (Type t in base_inteface_types)
+                       if (ifaces != null) {
+                               foreach (Type t in ifaces)
                                        Report.SymbolRelatedToPreviousError (t);
                                Report.Error (714, Location, "'{0}': static classes cannot implement interfaces", GetSignatureForError ());
                        }
@@ -2775,7 +2770,7 @@ namespace Mono.CSharp {
                public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
                {
                        if (a.UsageAttribute != null) {
-                               if (base_class_type != TypeManager.attribute_type && !base_class_type.IsSubclassOf (TypeManager.attribute_type) &&
+                               if (ptype != TypeManager.attribute_type && !ptype.IsSubclassOf (TypeManager.attribute_type) &&
                                        TypeBuilder.FullName != "System.Attribute") {
                                        Report.Error (641, a.Location, "Attribute '{0}' is only valid on classes derived from System.Attribute", a.Name);
                                }
@@ -3984,7 +3979,7 @@ namespace Mono.CSharp {
                        if (parent_constructor == null)
                                return;
 
-                       TypeContainer type_ds = TypeManager.LookupTypeContainer (tc.base_class_type);
+                       TypeContainer type_ds = TypeManager.LookupTypeContainer (tc.TypeBuilder.BaseType);
                        if (type_ds == null) {
                                ObsoleteAttribute oa = AttributeTester.GetMemberObsoleteAttribute (parent_constructor);
 
index 96cce02378a429b79650b71ecc5513ff0c83874a..e614c8ccc625ffe339a806c1093d07cac393eaed 100755 (executable)
@@ -1350,11 +1350,9 @@ namespace Mono.CSharp {
                Hashtable SetupCacheForInterface (MemberCache parent)
                {
                        Hashtable hash = SetupCache (parent);
-                       TypeExpr [] ifaces = TypeManager.GetInterfaces (Container.Type);
-
-                       foreach (TypeExpr iface in ifaces) {
-                               Type itype = iface.Type;
+                       Type [] ifaces = TypeManager.GetInterfaces (Container.Type);
 
+                       foreach (Type itype in ifaces) {
                                IMemberContainer iface_container =
                                        TypeManager.LookupMemberContainer (itype);
 
index e77457aef8ee75a926eb42810fdf6661dd876660..975124739f72703274e44c77cd7994c0ca5d8be5 100755 (executable)
@@ -2292,11 +2292,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               public virtual TypeExpr[] GetInterfaces ()
-               {
-                       return TypeManager.GetInterfaces (Type);
-               }
-
                public abstract TypeExpr DoResolveAsTypeStep (EmitContext ec);
 
                public virtual Type ResolveType (EmitContext ec)
index c04d1e34e1bb7705840864a5807d1f59bec565fe..7799ab93e41b36e1d6db51aceb537c80070df5f9 100755 (executable)
@@ -8030,10 +8030,9 @@ namespace Mono.CSharp {
                        if (!lookup_type.IsInterface)
                                return ix;
 
-                       TypeExpr [] ifaces = TypeManager.GetInterfaces (lookup_type);
+                       Type [] ifaces = TypeManager.GetInterfaces (lookup_type);
                        if (ifaces != null) {
-                               foreach (TypeExpr iface in ifaces) {
-                                       Type itype = iface.Type;
+                               foreach (Type itype in ifaces) {
                                        MemberInfo [] mi = GetIndexersForTypeOrInterface (caller_type, itype);
                                        if (mi != null){
                                                if (ix == null)
index 5c3394f02fe86ffe18100275bb7b0152ad143a2d..4d9283f31a2d62f5f97a6b3bd78704e941adf48b 100755 (executable)
@@ -229,7 +229,7 @@ namespace Mono.CSharp {
                        //
                        // Completely broken.  So we do it ourselves!
                        //
-                       TypeExpr [] impl = TypeManager.GetExplicitInterfaces (type_builder);
+                       Type [] impl = TypeManager.GetExplicitInterfaces (type_builder);
 
                        if (impl == null || impl.Length == 0)
                                return EmptyMissingInterfacesInfo;
@@ -237,7 +237,7 @@ namespace Mono.CSharp {
                        MissingInterfacesInfo [] ret = new MissingInterfacesInfo [impl.Length];
 
                        for (int i = 0; i < impl.Length; i++)
-                               ret [i] = new MissingInterfacesInfo (impl [i].Type);
+                               ret [i] = new MissingInterfacesInfo (impl [i]);
                        
                        // we really should not get here because Object doesnt implement any
                        // interfaces. But it could implement something internal, so we have
@@ -245,11 +245,9 @@ namespace Mono.CSharp {
                        if (type_builder.BaseType == null)
                                return ret;
                        
-                       TypeExpr [] parent_impls = TypeManager.GetInterfaces (type_builder.BaseType);
+                       Type [] parent_impls = TypeManager.GetInterfaces (type_builder.BaseType);
                        
-                       foreach (TypeExpr te in parent_impls) {
-                               Type t = te.Type;
-                               
+                       foreach (Type t in parent_impls) {
                                for (int i = 0; i < ret.Length; i ++) {
                                        if (t == ret [i].Type) {
                                                ret [i].Optional = true;
index 34e32a4a87a7919a2c56f79b53ec6b4c92833338..3416dcce27d9bf4dc0ca9aa449215a377add5227 100755 (executable)
@@ -407,7 +407,7 @@ public class TypeManager {
                types.Add (name, t);
        }
        
-       public static void AddUserType (string name, TypeBuilder t, TypeExpr[] ifaces)
+       public static void AddUserType (string name, TypeBuilder t)
        {
                try {
                        types.Add (name, t);
@@ -415,25 +415,22 @@ public class TypeManager {
                        HandleDuplicate (name, t); 
                }
                user_types.Add (t);
-                       
-               if (ifaces != null)
-                       builder_to_ifaces [t] = ifaces;
        }
 
        //
        // This entry point is used by types that we define under the covers
        // 
-       public static void RegisterBuilder (TypeBuilder tb, TypeExpr [] ifaces)
+       public static void RegisterBuilder (Type tb, Type [] ifaces)
        {
                if (ifaces != null)
                        builder_to_ifaces [tb] = ifaces;
        }
        
-       public static void AddUserType (string name, TypeBuilder t, TypeContainer tc, TypeExpr [] ifaces)
+       public static void AddUserType (string name, TypeBuilder t, TypeContainer tc)
        {
                builder_to_declspace.Add (t, tc);
                typecontainers.Add (name, tc);
-               AddUserType (name, t, ifaces);
+               AddUserType (name, t);
        }
 
        public static void AddDelegateType (string name, TypeBuilder t, Delegate del)
@@ -457,13 +454,6 @@ public class TypeManager {
                builder_to_declspace.Add (t, en);
        }
 
-       public static void AddUserInterface (string name, TypeBuilder t, Interface i, TypeExpr [] ifaces)
-       {
-               AddUserType (name, t, ifaces);
-               builder_to_declspace.Add (t, i);
-       }
-
-
        public static void AddMethod (MethodBase builder, IMethodData method)
        {
                builder_to_method.Add (builder, method);
@@ -1947,22 +1937,26 @@ public class TypeManager {
        ///   This expands in context like: IA; IB : IA; IC : IA, IB; the interface "IC" to
        ///   be IA, IB, IC.
        /// </remarks>
-       public static TypeExpr[] ExpandInterfaces (TypeExpr [] base_interfaces)
+       public static Type[] ExpandInterfaces (EmitContext ec, TypeExpr [] base_interfaces)
        {
                ArrayList new_ifaces = new ArrayList ();
                
                foreach (TypeExpr iface in base_interfaces){
-                       if (!new_ifaces.Contains (iface))
-                               new_ifaces.Add (iface);
+                       Type itype = iface.ResolveType (ec);
+                       if (itype == null)
+                               return null;
+
+                       if (!new_ifaces.Contains (itype))
+                               new_ifaces.Add (itype);
                        
-                       TypeExpr [] implementing = iface.GetInterfaces ();
+                       Type [] implementing = itype.GetInterfaces ();
                        
-                       foreach (TypeExpr imp in implementing){
+                       foreach (Type imp in implementing){
                                if (!new_ifaces.Contains (imp))
                                        new_ifaces.Add (imp);
                        }
                }
-               TypeExpr [] ret = new TypeExpr [new_ifaces.Count];
+               Type [] ret = new Type [new_ifaces.Count];
                new_ifaces.CopyTo (ret, 0);
                return ret;
        }
@@ -1973,10 +1967,10 @@ public class TypeManager {
        ///   This function returns the interfaces in the type `t'.  Works with
        ///   both types and TypeBuilders.
        /// </summary>
-       public static TypeExpr [] GetInterfaces (Type t)
+       public static Type [] GetInterfaces (Type t)
        {
                
-               TypeExpr [] cached = iface_cache [t] as TypeExpr [];
+               Type [] cached = iface_cache [t] as Type [];
                if (cached != null)
                        return cached;
                
@@ -1994,43 +1988,36 @@ public class TypeManager {
                        t = TypeManager.array_type;
                
                if (t is TypeBuilder){
-                       TypeExpr [] parent_ifaces;
+                       Type [] parent_ifaces;
                        
                        if (t.BaseType == null)
-                               parent_ifaces = NoTypeExprs;
+                               parent_ifaces = NoTypes;
                        else
                                parent_ifaces = GetInterfaces (t.BaseType);
-                       TypeExpr [] type_ifaces = (TypeExpr []) builder_to_ifaces [t];
+                       Type [] type_ifaces = (Type []) builder_to_ifaces [t];
                        if (type_ifaces == null)
-                               type_ifaces = NoTypeExprs;
+                               type_ifaces = NoTypes;
 
                        int parent_count = parent_ifaces.Length;
-                       TypeExpr [] result = new TypeExpr [parent_count + type_ifaces.Length];
+                       Type [] result = new Type [parent_count + type_ifaces.Length];
                        parent_ifaces.CopyTo (result, 0);
                        type_ifaces.CopyTo (result, parent_count);
 
                        iface_cache [t] = result;
                        return result;
                } else {
-                       Type [] ifaces = t.GetInterfaces ();
-                       if (ifaces.Length == 0)
-                               return NoTypeExprs;
-
-                       TypeExpr [] result = new TypeExpr [ifaces.Length];
-                       for (int i = 0; i < ifaces.Length; i++)
-                               result [i] = new TypeExpression (ifaces [i], Location.Null);
-                       
-                       iface_cache [t] = result;
-                       return result;
+                       Type[] ifaces = t.GetInterfaces ();
+                       iface_cache [t] = ifaces;
+                       return ifaces;
                }
        }
        
        //
        // gets the interfaces that are declared explicitly on t
        //
-       public static TypeExpr [] GetExplicitInterfaces (TypeBuilder t)
+       public static Type [] GetExplicitInterfaces (TypeBuilder t)
        {
-               return (TypeExpr []) builder_to_ifaces [t];
+               return (Type []) builder_to_ifaces [t];
        }
        
        /// <remarks>
@@ -2039,7 +2026,7 @@ public class TypeManager {
        /// </remarks>
        public static bool ImplementsInterface (Type t, Type iface)
        {
-               TypeExpr [] interfaces;
+               Type [] interfaces;
 
                //
                // FIXME OPTIMIZATION:
@@ -2052,8 +2039,8 @@ public class TypeManager {
                        interfaces = GetInterfaces (t);
 
                        if (interfaces != null){
-                               foreach (TypeExpr i in interfaces){
-                                       if (i.Type == iface)
+                               foreach (Type i in interfaces){
+                                       if (i == iface)
                                                return true;
                                }
                        }
@@ -2732,14 +2719,14 @@ public class TypeManager {
                if (queried_type.IsArray)
                        queried_type = TypeManager.array_type;
                
-               TypeExpr [] ifaces = GetInterfaces (queried_type);
+               Type [] ifaces = GetInterfaces (queried_type);
                if (ifaces == null)
                        return null;
                
-               foreach (TypeExpr itype in ifaces){
+               foreach (Type itype in ifaces){
                        MemberInfo [] x;
 
-                       x = MemberLookup (null, null, itype.Type, mt, bf, name, null);
+                       x = MemberLookup (null, null, itype, mt, bf, name, null);
                        if (x != null)
                                return x;
                }