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

nazgul svnadmin at nemerle.org
Sun Jul 2 13:44:27 CEST 2006


Log:
Do not emit PLACE_HOLDER in empty structs. Modified patch by Snaury

Author: nazgul
Date: Sun Jul  2 13:44:07 2006
New Revision: 6416

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 13:44:07 2006
@@ -70,6 +70,8 @@
   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;
@@ -196,6 +198,8 @@
     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 13:44:07 2006
@@ -455,15 +455,29 @@
             | l => "`" + l.ToString ()
           }
 
+        def empty_struct = IsStruct && GetFields (BindingFlags.Instance %|
+                                                  BindingFlags.Public %|
+                                                  BindingFlags.NonPublic).IsEmpty;
+
         /* create the type builder for a top-level or nested class declaration */
         type_builder =
           if (!is_nested)
+            if(empty_struct)
+              TyManager._module_builder.DefineType (FullName + generic_mark_suffix, attrs, null, 1)
+            else
             TyManager._module_builder.DefineType (FullName + generic_mark_suffix, attrs)
           else {
             def containing_builder = (DeclaringType :> TypeBuilder).GetTypeBuilder ();
+            if(empty_struct)
+              containing_builder.DefineNestedType (Name + generic_mark_suffix, attrs, null, 1)
+            else
             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) {
@@ -482,17 +496,6 @@
         when (extension_patterns.Count > 0)
           TyManager.contains_nemerle_specifics = true;
 
-        // 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.
-        // maybe in 2.0 there is a better API
-        when (IsStruct && GetFields (BindingFlags.Instance %|
-                                     BindingFlags.Public %| 
-                                     BindingFlags.NonPublic).IsEmpty)
-          _ = type_builder.DefineField ("$PLACE_HOLDER$", SystemTypeCache.Byte,
-                                        FieldAttributes.Private %| FieldAttributes.SpecialName);
-        
         system_type = type_builder;
       }
     }



More information about the svn mailing list