2003-12-17 Zoltan Varga <vargaz@freemail.hu>
authorZoltan Varga <vargaz@gmail.com>
Wed, 17 Dec 2003 16:46:23 +0000 (16:46 -0000)
committerZoltan Varga <vargaz@gmail.com>
Wed, 17 Dec 2003 16:46:23 +0000 (16:46 -0000)
* AssemblyBuilder.cs (MonoResource): New 'offset' field used by the
runtime.

* ModuleBuilder: Implement DefineResource.

svn path=/trunk/mcs/; revision=21279

mcs/class/corlib/System.Reflection.Emit/AssemblyBuilder.cs
mcs/class/corlib/System.Reflection.Emit/ChangeLog
mcs/class/corlib/System.Reflection.Emit/ModuleBuilder.cs

index ce1fbd9762b69e40d5a55b6cd921cfde475ce9e4..f38b169ef1c96d7fc2326e1e4490af751b17aacc 100755 (executable)
@@ -40,9 +40,11 @@ namespace System.Reflection.Emit {
                public string name;
                public string filename;
                public ResourceAttributes attrs;
+               public int offset;
        }
 
        public sealed class AssemblyBuilder : Assembly {
+               #region Sync with reflection.h
                private IntPtr dynamic_assembly;
                private MethodInfo entry_point;
                private ModuleBuilder[] modules;
@@ -58,6 +60,7 @@ namespace System.Reflection.Emit {
                PEFileKinds pekind = PEFileKinds.Dll;
                bool delay_sign;
                uint access;
+               #endregion
                internal Type corlib_object_type = typeof (System.Object);
                internal Type corlib_value_type = typeof (System.ValueType);
                internal Type corlib_enum_type = typeof (System.Enum);
index 1cf009cd05a6c1605c5f087fbdcf2666b5646809..f0e5a979da5217670cd113e57175de12cb43cc2d 100644 (file)
@@ -1,3 +1,10 @@
+2003-12-17  Zoltan Varga  <vargaz@freemail.hu>
+
+       * AssemblyBuilder.cs (MonoResource): New 'offset' field used by the
+       runtime.
+
+       * ModuleBuilder: Implement DefineResource.
+
 2003-12-15  Zoltan Varga  <vargaz@freemail.hu>
 
        * AssemblyBuilder.cs (RefEmitPermissionSet): New helper structure.
index bf93fb61a9ad90752573960a006ec605be52043c..3fffd74803a350a74d36b8ecf985572839ee5c9a 100644 (file)
@@ -21,6 +21,7 @@ using System.Globalization;
 
 namespace System.Reflection.Emit {
        public class ModuleBuilder : Module {
+               #region Sync with reflection.h
                private IntPtr dynamic_image;
                private int num_types;
                private TypeBuilder[] types;
@@ -31,6 +32,8 @@ namespace System.Reflection.Emit {
                private MethodBuilder[] global_methods;
                private FieldBuilder[] global_fields;
                bool is_main;
+               private MonoResource[] resources;
+               #endregion
                private TypeBuilder global_type;
                private Type global_type_created;
                internal IMonoSymbolWriter symbol_writer;
@@ -39,6 +42,7 @@ namespace System.Reflection.Emit {
                private int[] table_indexes;
                bool transient;
                ModuleBuilderTokenGenerator token_gen;
+               ArrayList resource_writers = null;
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                private static extern void basic_init (ModuleBuilder ab);
@@ -411,7 +415,6 @@ namespace System.Reflection.Emit {
                        return copy;
                }
 
-               [MonoTODO]
                public IResourceWriter DefineResource (string name, string description, ResourceAttributes attribute)
                {
                        if (name == null)
@@ -422,7 +425,24 @@ namespace System.Reflection.Emit {
                                throw new InvalidOperationException ("The module is transient");
                        if (!assemblyb.IsSave)
                                throw new InvalidOperationException ("The assembly is transient");
-                       throw new NotImplementedException ();
+                       ResourceWriter writer = new ResourceWriter (new MemoryStream ());
+                       if (resource_writers == null)
+                               resource_writers = new ArrayList ();
+                       resource_writers.Add (writer);
+
+                       // The data is filled out later
+                       if (resources != null) {
+                               MonoResource[] new_r = new MonoResource [resources.Length + 1];
+                               System.Array.Copy(resources, new_r, resources.Length);
+                               resources = new_r;
+                       } else {
+                               resources = new MonoResource [1];
+                       }
+                       int p = resources.Length - 1;
+                       resources [p].name = name;
+                       resources [p].attrs = attribute;
+
+                       return writer;
                }
 
                public IResourceWriter DefineResource (string name, string description)
@@ -574,6 +594,17 @@ namespace System.Reflection.Emit {
                        if (transient)
                                return;
 
+                       if (resource_writers != null) {
+                               for (int i = 0; i < resource_writers.Count; ++i) {
+                                       ResourceWriter writer = (ResourceWriter)resource_writers [i];
+                                       writer.Generate ();
+                                       MemoryStream stream = (MemoryStream)writer.Stream;
+                                       resources [i].data = new byte [stream.Length];
+                                       stream.Seek (0, SeekOrigin.Begin);
+                                       stream.Read (resources [i].data, 0, (int)stream.Length);
+                               }                                       
+                       }
+
                        build_metadata (this);
 
                        if (symbol_writer != null) {