Author: miguel
Date: 2005-04-16 13:58:38 -0400 (Sat, 16 Apr 2005)
New Revision: 43100
Modified:
trunk/mcs/mcs/ChangeLog
trunk/mcs/mcs/class.cs
trunk/mcs/mcs/typemanager.cs
Log:
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.
Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog 2005-04-16 17:54:33 UTC (rev 43099)
+++ trunk/mcs/mcs/ChangeLog 2005-04-16 17:58:38 UTC (rev 43100)
@@ -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/mcs/class.cs
===================================================================
--- trunk/mcs/mcs/class.cs 2005-04-16 17:54:33 UTC (rev 43099)
+++ trunk/mcs/mcs/class.cs 2005-04-16 17:58:38 UTC (rev 43100)
@@ -1250,18 +1250,6 @@
ec.ContainerType = TypeBuilder;
}
- //
- // 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, ...).
@@ -2049,6 +2037,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) {
@@ -2630,7 +2639,7 @@
}
public abstract class ClassOrStruct : TypeContainer {
- bool hasExplicitLayout = false;
+ bool has_explicit_layout = false;
ListDictionary declarative_security;
public ClassOrStruct (NamespaceEntry ns, TypeContainer parent,
@@ -2647,7 +2656,7 @@
public override bool HasExplicitLayout {
get {
- return hasExplicitLayout;
+ return has_explicit_layout;
}
}
@@ -2673,9 +2682,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/mcs/typemanager.cs
===================================================================
--- trunk/mcs/mcs/typemanager.cs 2005-04-16 17:54:33 UTC (rev 43099)
+++ trunk/mcs/mcs/typemanager.cs 2005-04-16 17:58:38 UTC (rev 43100)
@@ -196,7 +196,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
///
@@ -1314,6 +1315,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