Thu Mar 7 17:10:42 CET 2002 Paolo Molaro <lupus@ximian.com>
authorPaolo Molaro <lupus@oddwiz.org>
Thu, 7 Mar 2002 12:41:37 +0000 (12:41 -0000)
committerPaolo Molaro <lupus@oddwiz.org>
Thu, 7 Mar 2002 12:41:37 +0000 (12:41 -0000)
* AssemblyBuilder.cs: allow saving bigger assemblies.
* ILGenerator.cs: add fixup table for fields and methods, since
at the end of the compile they may end up with a different table
index.
* ModuleBuilder.cs: add cache for type names to speed up the type
lookups from the compiler.
* TypeBuilder.cs: GetInterfaces () returns only interfaces in the
current type, not in parents (the docs are wrong).

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

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

index f938ac3232b8d0e8715e5539fa6f8e253ecad7c1..5239d6f40e8eb6bb5e840b6634da789a775e6edf 100755 (executable)
@@ -189,7 +189,7 @@ namespace System.Reflection.Emit {
 
                public void Save (string assemblyFileName)
                {
-                       byte[] buf = new byte [65536];
+                       byte[] buf = new byte [1024000];
                        FileStream file;
                        int count;
 
@@ -198,8 +198,11 @@ namespace System.Reflection.Emit {
                        count = getDataChunk (this, 0, buf);
                        if (count != 0) {
                                file.Write (buf, 0, count);
-                               count = getDataChunk (this, 1, buf); /* may be a too small buffer */
-                               file.Write (buf, 0, count);
+                               int offset = 1;
+                               while ((count = getDataChunk (this, offset, buf)) != 0) {
+                                       file.Write (buf, 0, count);
+                                       offset += count;
+                               }
                        }
 
                        file.Close ();
index 8803a0a6a52c256b3d77623aacaba04cc3bfefe1..35a818cd0d1df2d60dc9a03aa9fc46c49a15d275 100644 (file)
@@ -1,4 +1,15 @@
 
+Thu Mar 7 17:10:42 CET 2002 Paolo Molaro <lupus@ximian.com>
+
+       * AssemblyBuilder.cs: allow saving bigger assemblies.
+       * ILGenerator.cs: add fixup table for fields and methods, since
+       at the end of the compile they may end up with a different table
+       index.
+       * ModuleBuilder.cs: add cache for type names to speed up the type
+       lookups from the compiler.
+       * TypeBuilder.cs: GetInterfaces () returns only interfaces in the
+       current type, not in parents (the docs are wrong).
+
 Tue Mar 5 18:09:34 CET 2002 Paolo Molaro <lupus@ximian.com>
 
        * EventBuilder.cs: implemented.
index 526f689d21ea22e7f11d14616a853fc8dbd40155..b8f73a67a04f2b8da3a48642cfe404b832889ced 100644 (file)
@@ -96,6 +96,11 @@ namespace System.Reflection.Emit {
                }
        }
        
+       internal struct ILTokenInfo {
+               public MemberInfo member;
+               public int code_pos;
+       }
+
        public class ILGenerator: Object {
                private struct LabelFixup {
                        public int size;
@@ -109,6 +114,8 @@ namespace System.Reflection.Emit {
                private int cur_stack;
                private LocalBuilder[] locals;
                private ILExceptionInfo[] ex_handlers;
+               private int num_token_fixups;
+               private ILTokenInfo[] token_fixups;
                private int[] label_to_addr;
                private int num_labels;
                private LabelFixup[] fixups;
@@ -127,6 +134,8 @@ namespace System.Reflection.Emit {
                        num_fixups = num_labels = 0;
                        label_to_addr = new int [16];
                        fixups = new LabelFixup [16];
+                       token_fixups = new ILTokenInfo [16];
+                       num_token_fixups = 0;
                        if (mb is MethodBuilder) {
                                abuilder = (AssemblyBuilder)((MethodBuilder)mb).TypeBuilder.Module.Assembly;
                        } else if (mb is ConstructorBuilder) {
@@ -134,6 +143,16 @@ namespace System.Reflection.Emit {
                        }
                }
 
+               private void add_token_fixup (MemberInfo mi) {
+                       if (num_token_fixups == token_fixups.Length) {
+                               ILTokenInfo[] ntf = new ILTokenInfo [num_token_fixups * 2];
+                               token_fixups.CopyTo (ntf, 0);
+                               token_fixups = ntf;
+                       }
+                       token_fixups [num_token_fixups].member = mi;
+                       token_fixups [num_token_fixups++].code_pos = code_len;
+               }
+
                private void make_room (int nbytes) {
                        if (code_len + nbytes < code.Length)
                                return;
@@ -311,6 +330,8 @@ namespace System.Reflection.Emit {
                        int token = abuilder.GetToken (constructor);
                        make_room (6);
                        ll_emit (opcode);
+                       if (constructor is ConstructorBuilder)
+                               add_token_fixup (constructor);
                        emit_int (token);
                }
                public virtual void Emit (OpCode opcode, Double val) {
@@ -324,6 +345,8 @@ namespace System.Reflection.Emit {
                        int token = abuilder.GetToken (field);
                        make_room (6);
                        ll_emit (opcode);
+                       if (field is FieldBuilder)
+                               add_token_fixup (field);
                        emit_int (token);
                }
                public virtual void Emit (OpCode opcode, Int16 val) {
@@ -396,6 +419,8 @@ namespace System.Reflection.Emit {
                        int token = abuilder.GetToken (method);
                        make_room (6);
                        ll_emit (opcode);
+                       if (method is MethodBuilder)
+                               add_token_fixup (method);
                        emit_int (token);
                }
                [CLSCompliant(false)]
index cd4c43d740611fb97f23c7476d22a19b6799d245..538d155a5909c93fc9b39ae36a7be2bc8f33feed 100644 (file)
@@ -10,6 +10,7 @@
 
 using System;
 using System.Reflection;
+using System.Collections;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 
@@ -19,12 +20,14 @@ namespace System.Reflection.Emit {
                private CustomAttributeBuilder[] cattrs;
                private int table_idx;
                private AssemblyBuilder assemblyb;
+               Hashtable name_cache;
 
                internal ModuleBuilder (AssemblyBuilder assb, string name, string fullyqname) {
                        this.name = this.scopename = name;
                        this.fqname = fullyqname;
                        this.assembly = this.assemblyb = assb;
                        table_idx = get_next_table_index (0x00, true);
+                       name_cache = new Hashtable ();
                }
        
                public override string FullyQualifiedName {get { return fqname;}}
@@ -54,6 +57,7 @@ namespace System.Reflection.Emit {
                                types = new TypeBuilder [1];
                                types [0] = res;
                        }
+                       name_cache.Add (name, res);
                        return res;
                }
 
@@ -88,6 +92,8 @@ namespace System.Reflection.Emit {
 
                private TypeBuilder search_in_array (TypeBuilder[] arr, string className, bool ignoreCase) {
                        int i;
+                       if (arr == types && !ignoreCase)
+                               return (TypeBuilder)name_cache [className];
                        for (i = 0; i < arr.Length; ++i) {
                                if (String.Compare (className, arr [i].FullName, ignoreCase) == 0) {
                                        return arr [i];
index ba30dd24a2143a47609078fd6e162a6741bac707..721a64b0036b863c1cbd2886c9794321a5b151f4 100644 (file)
@@ -380,20 +380,11 @@ namespace System.Reflection.Emit {
                
                public override Type[] GetInterfaces () {
                        if (interfaces != null) {
-                               Type [] pi;
-                               if (parent != null)
-                                       pi = parent.GetInterfaces ();
-                               else
-                                       pi = Type.EmptyTypes;
-                               Type[] ret = new Type [interfaces.Length + pi.Length];
+                               Type[] ret = new Type [interfaces.Length];
                                interfaces.CopyTo (ret, 0);
-                               pi.CopyTo (ret, interfaces.Length);
                                return ret;
                        } else {
-                               if (parent != null)
-                                       return parent.GetInterfaces ();
-                               else
-                                       return Type.EmptyTypes;
+                               return Type.EmptyTypes;
                        }
                }