Author: martin
Date: 2005-04-20 04:54:17 -0400 (Wed, 20 Apr 2005)
New Revision: 43319

Modified:
   trunk/mcs/gmcs/ChangeLog
   trunk/mcs/gmcs/class.cs
   trunk/mcs/gmcs/typemanager.cs
Log:
**** Merged r43100 from MCS ****


Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog    2005-04-20 08:53:46 UTC (rev 43318)
+++ trunk/mcs/gmcs/ChangeLog    2005-04-20 08:54:17 UTC (rev 43319)
@@ -1,3 +1,14 @@
+2005-04-16  Miguel de Icaza  <[EMAIL PROTECTED]>
+
+       * class.cs (TypeContainer.EmitType): Moved the definition of the
+       special $PRIVATE$ field from the resolve phase to the Emit phase.
+       During resolve we do not know if we are a struct with
+       HasExplicitLayout, we know this only after the attributes for the
+       type are emitted.
+
+       Set the FieldOffset to zero on the dummy field that we create for
+       the class.   Fixes 74590.
+
 2005-04-16  Raja R Harinath  <[EMAIL PROTECTED]>
 
        Fix #73834.

Modified: trunk/mcs/gmcs/class.cs
===================================================================
--- trunk/mcs/gmcs/class.cs     2005-04-20 08:53:46 UTC (rev 43318)
+++ trunk/mcs/gmcs/class.cs     2005-04-20 08:54:17 UTC (rev 43319)
@@ -1351,18 +1351,6 @@
                        if (ptype != null)
                                TypeBuilder.SetParent (ptype);
 
-                       //
-                       // Structs with no fields need to have at least one 
byte.
-                       // The right thing would be to set the PackingSize in a 
DefineType
-                       // but there are no functions that allow interfaces 
*and* the size to
-                       // be specified.
-                       //
-
-                       if ((Kind == Kind.Struct) && !have_nonstatic_fields){
-                               TypeBuilder.DefineField ("$PRIVATE$", 
TypeManager.byte_type,
-                                                        
FieldAttributes.Private);
-                       }
-
                        // add interfaces that were not added at type creation
                        if (iface_exprs != null) {
                                // FIXME: I think this should be 
...ExpandInterfaces (Parent.EmitContext, ...).
@@ -2197,6 +2185,27 @@
                        if (OptAttributes != null)
                                OptAttributes.Emit (ec, this);
 
+                       //
+                       // Structs with no fields need to have at least one 
byte.
+                       // The right thing would be to set the PackingSize in a 
DefineType
+                       // but there are no functions that allow interfaces 
*and* the size to
+                       // be specified.
+                       //
+
+                       if ((Kind == Kind.Struct) && !have_nonstatic_fields){
+                               FieldBuilder fb = TypeBuilder.DefineField 
("$PRIVATE$", TypeManager.byte_type,
+                                                                          
FieldAttributes.Private);
+
+                               if (HasExplicitLayout){
+                                       object [] ctor_args = new object [1];
+                                       ctor_args [0] = 0;
+                               
+                                       CustomAttributeBuilder cba = new 
CustomAttributeBuilder (
+                                               
TypeManager.field_offset_attribute_ctor, ctor_args);
+                                       fb.SetCustomAttribute (cba);
+                               }
+                       }
+
                        Emit ();
 
                        if (instance_constructors != null) {
@@ -2870,7 +2879,7 @@
        }
 
        public abstract class ClassOrStruct : TypeContainer {
-               bool hasExplicitLayout = false;
+               bool has_explicit_layout = false;
                ListDictionary declarative_security;
 
                public ClassOrStruct (NamespaceEntry ns, TypeContainer parent,
@@ -2887,7 +2896,7 @@
 
                public override bool HasExplicitLayout {
                        get {
-                               return hasExplicitLayout;
+                               return has_explicit_layout;
                                }
                        }
 
@@ -2913,9 +2922,8 @@
                                return;
                        }
 
-                       if (a.Type == TypeManager.struct_layout_attribute_type 
&&
-                           a.GetLayoutKindValue () == LayoutKind.Explicit)
-                               hasExplicitLayout = true;
+                       if (a.Type == TypeManager.struct_layout_attribute_type 
&& a.GetLayoutKindValue () == LayoutKind.Explicit)
+                               has_explicit_layout = true;
 
                        base.ApplyAttributeBuilder (a, cb);
                }

Modified: trunk/mcs/gmcs/typemanager.cs
===================================================================
--- trunk/mcs/gmcs/typemanager.cs       2005-04-20 08:53:46 UTC (rev 43318)
+++ trunk/mcs/gmcs/typemanager.cs       2005-04-20 08:54:17 UTC (rev 43319)
@@ -194,7 +194,8 @@
        static public ConstructorInfo default_member_ctor;
        static public ConstructorInfo decimal_constant_attribute_ctor;
        static internal ConstructorInfo struct_layout_attribute_ctor;
-
+       static public ConstructorInfo field_offset_attribute_ctor;
+       
        ///
        /// A new in C# 2.0
        /// 
@@ -1412,6 +1413,8 @@
                decimal_constant_attribute_ctor = GetConstructor 
(decimal_constant_attribute_type, new Type []
                        { byte_type, byte_type, uint32_type, uint32_type, 
uint32_type } );
 
+               field_offset_attribute_ctor = GetConstructor 
(field_offset_attribute_type, new Type []
+                       { int32_type });
 
                //
                // .NET 2.0 types

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to