Преглед изворни кода

2002-09-19 Miguel de Icaza <[email protected]>

	* class.cs (TypeContainer.DefineType): We can not use the nice
	PackingSize with the size set to 1 DefineType method, because it
	will not allow us to define the interfaces that the struct
	implements.

	This completes the fixing of bug 27287

	* ecore.cs (Expresion.ImplicitReferenceConversion): `class-type S'
	means also structs.  This fixes part of the problem.
	(Expresion.ImplicitReferenceConversionExists): ditto.

svn path=/trunk/mcs/; revision=7633
Miguel de Icaza пре 23 година
родитељ
комит
6947f0572d
4 измењених фајлова са 36 додато и 44 уклоњено
  1. 11 0
      mcs/mcs/ChangeLog
  2. 16 37
      mcs/mcs/class.cs
  3. 8 7
      mcs/mcs/ecore.cs
  4. 1 0
      mcs/mcs/pending.cs

+ 11 - 0
mcs/mcs/ChangeLog

@@ -1,5 +1,16 @@
 2002-09-19  Miguel de Icaza  <[email protected]>
 
+	* class.cs (TypeContainer.DefineType): We can not use the nice
+	PackingSize with the size set to 1 DefineType method, because it
+	will not allow us to define the interfaces that the struct
+	implements.
+
+	This completes the fixing of bug 27287
+
+	* ecore.cs (Expresion.ImplicitReferenceConversion): `class-type S'
+	means also structs.  This fixes part of the problem. 
+	(Expresion.ImplicitReferenceConversionExists): ditto.
+
 	* decl.cs (DeclSparce.ResolveType): Only report the type-not-found
 	error if there were no errors reported during the type lookup
 	process, to avoid duplicates or redundant errors.  Without this

+ 16 - 37
mcs/mcs/class.cs

@@ -772,46 +772,25 @@ namespace Mono.CSharp {
 			// if (parent_builder is ModuleBuilder) {
 			if (IsTopLevel){
 				ModuleBuilder builder = CodeGen.ModuleBuilder;
+				TypeBuilder = builder.DefineType (
+					Name, type_attributes, parent, ifaces);
 				
-				//
-				// Structs with no fields need to have a ".size 1"
-				// appended
-				//
-
-				if (!is_class && !have_nonstatic_fields)
-					TypeBuilder = builder.DefineType (Name,
-									  type_attributes,
-									  parent, 
-									  PackingSize.Unspecified, 1);
-				else
-				//
-				// classes or structs with fields
-				//
-					TypeBuilder = builder.DefineType (Name,
-									  type_attributes,
-									  parent,
-									  ifaces);
 			} else {
 				TypeBuilder builder = Parent.TypeBuilder;
+				TypeBuilder = builder.DefineNestedType (
+					Basename, type_attributes, parent, ifaces);
+			}
 				
-				//
-				// Structs with no fields need to have a ".size 1"
-				// appended
-				//
-				if (!is_class && !have_nonstatic_fields)
-					TypeBuilder = builder.DefineNestedType (Basename,
-										type_attributes,
-										parent, 
-										PackingSize.Unspecified);
-				else {
-					//
-					// classes or structs with fields
-					//
-					TypeBuilder = builder.DefineNestedType (Basename,
-										type_attributes,
-										parent,
-										ifaces);
-				}
+			//
+			// Structs with no fields need to have at least one byte.
+			// The right thing would be to set the PackingSize in a DefineType
+			// but there are no functions that allow interfaces *and* the size to
+			// be specified.
+			//
+
+			if (!is_class && !have_nonstatic_fields){
+				TypeBuilder.DefineField ("$PRIVATE$", TypeManager.byte_type,
+							 FieldAttributes.Private);
 			}
 
 			// add interfaces that were not added at type creation (weird API issue)
@@ -2873,7 +2852,7 @@ namespace Mono.CSharp {
 			else
 				name = member.ShortName;
 			method_name = prefix + name;
-				
+
 			if (parent.Pending != null){
 				if (member is Indexer)
 					implementing = parent.Pending.IsInterfaceIndexer (

+ 8 - 7
mcs/mcs/ecore.cs

@@ -694,16 +694,17 @@ namespace Mono.CSharp {
 					return new EmptyCast (expr, target_type);
 
 				// from any class-type S to any interface-type T.
-				if (expr_type.IsClass && target_type.IsInterface) {
-					if (TypeManager.ImplementsInterface (expr_type, target_type))
-						return new EmptyCast (expr, target_type);
-					else
-						return null;
+				if (target_type.IsInterface) {
+					if (TypeManager.ImplementsInterface (expr_type, target_type)){
+						if (expr_type.IsClass)
+							return new EmptyCast (expr, target_type);
+						else if (expr_type.IsValueType)
+							return new BoxedCast (expr);
+					}
 				}
 
 				// from any interface type S to interface-type T.
 				if (expr_type.IsInterface && target_type.IsInterface) {
-
 					if (TypeManager.ImplementsInterface (expr_type, target_type))
 						return new EmptyCast (expr, target_type);
 					else
@@ -973,7 +974,7 @@ namespace Mono.CSharp {
 				// from ImplicitReferenceConversion so make sure code remains in sync
 				
 				// from any class-type S to any interface-type T.
-				if (expr_type.IsClass && target_type.IsInterface) {
+				if (target_type.IsInterface) {
 					if (TypeManager.ImplementsInterface (expr_type, target_type))
 						return true;
 				}

+ 1 - 0
mcs/mcs/pending.cs

@@ -206,6 +206,7 @@ namespace Mono.CSharp {
 			// TypeBuilder.
 			//
 			ifaces = type_builder.GetInterfaces ();
+
 #if DEBUG
 			{
 				Type x = type_builder;