[svn] r6419: nemerle/trunk/ncc: external/InternalTypes.n generation/HierarchyEmitter.n

nazgul svnadmin at nemerle.org
Sun Jul 2 16:31:27 CEST 2006


Log:
Better fix for sequential layout in empty structs. Mark type as beforefieldinit for types without static initializer

Author: nazgul
Date: Sun Jul  2 16:31:12 2006
New Revision: 6419

Modified:
   nemerle/trunk/ncc/external/InternalTypes.n
   nemerle/trunk/ncc/generation/HierarchyEmitter.n

Modified: nemerle/trunk/ncc/external/InternalTypes.n
==============================================================================
--- nemerle/trunk/ncc/external/InternalTypes.n	(original)
+++ nemerle/trunk/ncc/external/InternalTypes.n	Sun Jul  2 16:31:12 2006
@@ -70,8 +70,6 @@
   public mutable UInt64 : System.Type;
   public mutable Void : System.Type;
   public mutable ParamArrayAttribute : System.Type;
-  public mutable InteropServices_StructLayoutAttribute : System.Type;
-  public mutable InteropServices_LayoutKind : System.Type;
 
   // set in LibrariesLoader upon first possiblity
   public mutable ExtensionAttribute : System.Type;
@@ -198,8 +196,6 @@
     Void = Reflect ("System.Void");
     ParamArrayAttribute = Reflect ("System.ParamArrayAttribute");
     Reflection_DefaultMemberAttribute = Reflect ("System.Reflection.DefaultMemberAttribute");
-    InteropServices_StructLayoutAttribute = Reflect ("System.Runtime.InteropServices.StructLayoutAttribute");
-    InteropServices_LayoutKind = Reflect ("System.Runtime.InteropServices.LayoutKind");
 
     {
       Decimal_ctors = Hashtable ();

Modified: nemerle/trunk/ncc/generation/HierarchyEmitter.n
==============================================================================
--- nemerle/trunk/ncc/generation/HierarchyEmitter.n	(original)
+++ nemerle/trunk/ncc/generation/HierarchyEmitter.n	Sun Jul  2 16:31:12 2006
@@ -443,7 +443,7 @@
             | TypeDeclaration.Enum           => TypeAttributes.Sealed %| TypeAttributes.Class
           };
 
-        def attrs = make_type_attributes (Attributes, is_nested) %| type_kind_attrs;
+        mutable attrs = make_type_attributes (Attributes, is_nested, IsStruct) %| type_kind_attrs;
         mutable typarms_len = TyparmsCount;
 
         when (is_nested)
@@ -459,6 +459,13 @@
                                                   BindingFlags.Public %|
                                                   BindingFlags.NonPublic).IsEmpty;
 
+        def no_static_ctor = GetConstructors (BindingFlags.Static %|
+                                              BindingFlags.Public %|
+                                              BindingFlags.NonPublic).IsEmpty;
+
+        when (no_static_ctor)
+          attrs = attrs %| TypeAttributes.BeforeFieldInit; /* [DF] mimick mcs behaviour */
+
         /* create the type builder for a top-level or nested class declaration */
         type_builder =
           if (!is_nested)
@@ -474,10 +481,6 @@
               containing_builder.DefineNestedType (Name + generic_mark_suffix, attrs)
           };
 
-        when (empty_struct)
-          type_builder.SetCustomAttribute (Manager.AttributeCompiler.MakeEmittedAttribute (SystemTypeCache.InteropServices_StructLayoutAttribute, 
-            array [SystemTypeCache.InteropServices_LayoutKind], System.Runtime.InteropServices.LayoutKind.Sequential));
-          
         // creates and store generic parameters in our StaticTyVars
 
         unless (typarms.IsEmpty) {
@@ -534,9 +537,13 @@
     /**
      * Converts Nemerle modifiers to the Framework type attributes.
      */
-    private static make_type_attributes (attrs : NemerleAttributes, is_nested : bool) : TypeAttributes
+    private static make_type_attributes (attrs : NemerleAttributes, is_nested : bool, is_struct : bool = false) : TypeAttributes
     {
-      mutable result = TypeAttributes.AutoLayout;
+      mutable result =
+        if (is_struct)
+          TypeAttributes.SequentialLayout /* [DF] default struct layout is sequential */
+        else
+          TypeAttributes.AutoLayout;
       when (attrs %&& NemerleAttributes.Public)
         if (is_nested) result |= TypeAttributes.NestedPublic
         else result |= TypeAttributes.Public;



More information about the svn mailing list