+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.
// from classes from the arraylist `type_bases'
//
string base_class_name;
- public Type base_class_type;
+ TypeExpr parent_type;
ArrayList type_bases;
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;
Name);
}
- return TypeManager.ExpandInterfaces (ifaces);
+ return ifaces;
}
bool error = false;
//
public override TypeBuilder DefineType ()
{
- TypeExpr parent;
-
if (TypeBuilder != null)
return TypeBuilder;
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,
// 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;
}
}
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;
}
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 ();
return null;
TypeBuilder = builder.DefineNestedType (
- Basename, type_attributes, base_class_type, null);
+ Basename, type_attributes, ptype, null);
}
}
catch (ArgumentException) {
}
// 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);
}
//
//
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);
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);
}
}
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) {
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;
}
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);
}
}
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 ());
}
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);
}
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);
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);
}
}
- public virtual TypeExpr[] GetInterfaces ()
- {
- return TypeManager.GetInterfaces (Type);
- }
-
public abstract TypeExpr DoResolveAsTypeStep (EmitContext ec);
public virtual Type ResolveType (EmitContext ec)
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)
//
// 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;
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
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;
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);
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)
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);
/// 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;
}
/// 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;
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>
/// </remarks>
public static bool ImplementsInterface (Type t, Type iface)
{
- TypeExpr [] interfaces;
+ Type [] interfaces;
//
// FIXME OPTIMIZATION:
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;
}
}
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;
}