Mon Nov 19 13:58:01 CET 2001 Paolo Molaro <lupus@ximian.com>
authorPaolo Molaro <lupus@oddwiz.org>
Mon, 19 Nov 2001 09:09:26 +0000 (09:09 -0000)
committerPaolo Molaro <lupus@oddwiz.org>
Mon, 19 Nov 2001 09:09:26 +0000 (09:09 -0000)
* AssemblyBuilder.cs: add method to register a string in the "#US"
stream.
* EnumBuilder.cs, SignatureHelper.cs: added stubs.
* ILGenerator.cs: more stuff implemented.
* LocalBuilder.cs: keep track of local var index.

Mon Nov 19 13:56:55 CET 2001 Paolo Molaro <lupus@ximian.com>

* MethodBase.cs: add internal get_next_table_index() for use in
Reflection.Emit.

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

15 files changed:
mcs/class/corlib/System.Reflection.Emit/AssemblyBuilder.cs
mcs/class/corlib/System.Reflection.Emit/ChangeLog
mcs/class/corlib/System.Reflection.Emit/ConstructorBuilder.cs
mcs/class/corlib/System.Reflection.Emit/EnumBuilder.cs
mcs/class/corlib/System.Reflection.Emit/FieldBuilder.cs
mcs/class/corlib/System.Reflection.Emit/ILGenerator.cs
mcs/class/corlib/System.Reflection.Emit/LocalBuilder.cs
mcs/class/corlib/System.Reflection.Emit/MethodBuilder.cs
mcs/class/corlib/System.Reflection.Emit/ModuleBuilder.cs
mcs/class/corlib/System.Reflection.Emit/ParameterBuilder.cs
mcs/class/corlib/System.Reflection.Emit/PropertyBuilder.cs
mcs/class/corlib/System.Reflection.Emit/SignatureHelper.cs [new file with mode: 0755]
mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs
mcs/class/corlib/System.Reflection/ChangeLog
mcs/class/corlib/System.Reflection/MethodBase.cs

index d44529e847cb1a2ce72594d07e9552dd35efd029..2659d8146f52769bfed8f7f857eed0fa80991b10 100755 (executable)
@@ -162,6 +162,9 @@ namespace System.Reflection.Emit {
                        return null;
                }*/
 
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               private static extern int getUSIndex (AssemblyBuilder ab, string str);
+
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                private static extern int getDataChunk (AssemblyBuilder ab, int type, byte[] buf);
 
index 4c7bed1b3329be8f958c09d53d90b5cfe042f47a..b276b24a2a3a231be775773902addfff65744e31 100644 (file)
@@ -1,4 +1,21 @@
 
+Mon Nov 19 13:58:01 CET 2001 Paolo Molaro <lupus@ximian.com>
+
+       * AssemblyBuilder.cs: add method to register a string in the "#US"
+       stream.
+       * EnumBuilder.cs, SignatureHelper.cs: added stubs.
+       * ILGenerator.cs: more stuff implemented.
+       * LocalBuilder.cs: keep track of local var index.
+
+Thu Nov 15 18:11:23 CET 2001 Paolo Molaro <lupus@ximian.com>
+
+       * ConstructorBuilder.cs: implement the interesting methods.
+       * ILGenerator.cs: adapt for use with both a MethodBuilder and a
+       ConstructorBuilder.
+       * MethodBuilder.cs: add ImplAttributes.
+       * ParameterBuilder.cs: adapt for ConstructorBuilder.
+       * TypeBuilder.cs: add constructors handling.
+
 Wed Nov 14 17:01:45 CET 2001 Paolo Molaro <lupus@ximian.com>
 
        * ConstructorBuilder.cs: added missing stubs and some implementation.
index e3b293d9cb0ef4987ec8583d28c3880b018de28a..c5f17caec4d9f1df8b7bdcdbc16da087e33b5784 100644 (file)
@@ -17,9 +17,26 @@ using System.Security.Permissions;
 namespace System.Reflection.Emit {
        public sealed class ConstructorBuilder : ConstructorInfo {
                private ILGenerator ilgen;
+               private Type[] parameters;
+               private MethodAttributes attrs;
+               private MethodImplAttributes iattrs;
+               private int table_idx;
+               private CallingConventions call_conv;
+               private TypeBuilder type;
 
+               internal ConstructorBuilder (TypeBuilder tb, MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes) {
+                       attrs = attributes;
+                       call_conv = callingConvention;
+                       if (parameterTypes != null) {
+                               this.parameters = new Type [parameterTypes.Length];
+                               System.Array.Copy (parameterTypes, this.parameters, parameterTypes.Length);
+                       }
+                       type = tb;
+                       table_idx = get_next_table_index (0x06, true);
+               }
+               
                public override MethodImplAttributes GetMethodImplementationFlags() {
-                       return (MethodImplAttributes)0;
+                       return iattrs;
                }
                public override ParameterInfo[] GetParameters() {
                        return null;
@@ -32,11 +49,15 @@ namespace System.Reflection.Emit {
                }
 
                public override RuntimeMethodHandle MethodHandle { get {return new RuntimeMethodHandle ();} }
-               public override MethodAttributes Attributes { get {return (MethodAttributes)0;} }
-               public override Type ReflectedType { get {return null;}}
-               public override Type DeclaringType { get {return null;}}
+               public override MethodAttributes Attributes { 
+                       get {return attrs;} 
+               }
+               public override Type ReflectedType { get {return type;}}
+               public override Type DeclaringType { get {return type;}}
                public Type ReturnType { get {return null;}}
-               public override string Name { get {return ".ctor";}}
+               public override string Name { 
+                       get {return (attrs & MethodAttributes.Static) != 0 ? ".cctor" : ".ctor";}
+               }
                public string Signature {
                        get {return "constructor signature";}
                }
@@ -50,9 +71,10 @@ namespace System.Reflection.Emit {
                }
 
                public ParameterBuilder DefineParameter(int iSequence, ParameterAttributes attributes, string strParamName) {
-                       return null;
+                       ParameterBuilder pb = new ParameterBuilder (this, iSequence, attributes, strParamName);
+                       /* FIXME: add it to pinfo */
+                       return pb;
                }
-               
 
                public override bool IsDefined (Type attribute_type, bool inherit) {return false;}
 
@@ -64,8 +86,8 @@ namespace System.Reflection.Emit {
                        return GetILGenerator (256);
                }
                public ILGenerator GetILGenerator (int size) {
-                       //ilgen = new ILGenerator (this, size);
-                       return null;
+                       ilgen = new ILGenerator (this, size);
+                       return ilgen;
                }
 
                public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
@@ -73,12 +95,13 @@ namespace System.Reflection.Emit {
                public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
                }
                public void SetImplementationFlags( MethodImplAttributes attributes) {
+                       iattrs = attributes;
                }
                public Module GetModule() {
                        return null;
                }
                public MethodToken GetToken() {
-                       return new MethodToken();
+                       return new MethodToken (0x06000000 | table_idx);
                }
                public void SetSymCustomAttribute( string name, byte[] data) {
                }
@@ -86,5 +109,13 @@ namespace System.Reflection.Emit {
                        return "constructor";
                }
 
+               internal void fixup () {
+                       if (ilgen != null)
+                               ilgen.label_fixup ();
+               }
+               internal override int get_next_table_index (int table, bool inc) {
+                       return type.get_next_table_index (table, inc);
+               }
+
        }
 }
index c1ee333c3dc0619bd49df1af79840efc89bdc8de..d5fa777118aef073d307ca947340163e9b894527 100755 (executable)
@@ -15,6 +15,155 @@ using System.Globalization;
 using System.Runtime.CompilerServices;
 
 namespace System.Reflection.Emit {
-       /*public sealed class EnumBuilder : Type {
-       }*/
+       public sealed class EnumBuilder : Type {
+               public override Assembly Assembly {
+                       get {return null;}
+               }
+               public override string AssemblyQualifiedName {
+                       get {return null;}
+               }
+               public override Type BaseType {
+                       get {return null;}
+               }
+               public override Type DeclaringType {
+                       get {return null;}
+               }
+               public override string FullName {
+                       get {return null;}
+               }
+               /*public override Guid GUID {
+                       get {return null;}
+               }*/
+               public override Module Module {
+                       get {return null;}
+               }
+               public override string Name {
+                       get {return null;}
+               }
+               public override string Namespace {
+                       get {return null;}
+               }
+               public override Type ReflectedType {
+                       get {return null;}
+               }
+               public override RuntimeTypeHandle TypeHandle {
+                       get {return new RuntimeTypeHandle ();}
+               }
+               public TypeToken TypeToken {
+                       get {return new TypeToken ();}
+               }
+               public FieldBuilder UnderlyingField {
+                       get {return null;}
+               }
+               /*public override Type UnderlyingSystemType {
+                       get {return null;}
+               }*/
+               public override MemberTypes MemberType {
+                       get {return MemberTypes.TypeInfo;}
+               }
+
+               internal EnumBuilder (ModuleBuilder mb, string name, TypeAttributes visibility, Type underlyingType) {
+               }
+               public Type CreateType() {
+                       return null;
+               }
+               public FieldBuilder DefineLiteral( string literalName, object literalValue) {
+                       return null;
+               }
+               /*protected override TypeAttributes GetAttributeFlagsImpl() {
+                       return (TypeAttributes)0;
+               }
+               protected override ConstructorInfo GetConstructorImpl( BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers) {
+                       return null;
+               }
+               public override ConstructorInfo[] GetConstructors( BindingFlags bindingAttr) {
+                       return null;
+               }*/
+               public override object[] GetCustomAttributes(bool inherit) {
+                       return null;
+               }
+               public override object[] GetCustomAttributes(Type attributeType, bool inherit) {
+                       return null;
+               }
+               public override Type GetElementType() {
+                       throw new NotSupportedException ();
+               }
+               /*public override EventInfo GetEvent( string name, BindingFlags bindingAttr) {
+                       return null;
+               }
+               public override EventInfo[] GetEvents() {
+                       return null;
+               }
+               public override EventInfo[] GetEvents( BindingFlags bindingAttr) {
+                       return null;
+               }
+               public override FieldInfo GetField( string name, BindingFlags bindingAttr) {
+                       return null;
+               }
+               public override FieldInfo[] GetFields( BindingFlags bindingAttr) {
+                       return null;
+               }
+               public override Type GetInterface( string name, bool ignoreCase) {
+                       return null;
+               }
+               public override InterfaceMapping GetInterfaceMap( Type interfaceType) {
+                       return null;
+               }*/
+               public override Type[] GetInterfaces() {
+                       return null;
+               }
+               /*public override MemberInfo[] GetMember( string name, MemberTypes type, BindingFlags bindingAttr) {
+                       return null;
+               }
+               public override MemberInfo[] GetMembers( BindingFlags bindingAttr) {
+                       return null;
+               }
+               public override MethodInfo[] GetMethods( BindingFlags bindingAttr) {
+                       return null;
+               }
+               public override Type GetNestedType( string name, BindingFlags bindingAttr) {
+                       return null;
+               }
+               public override Type[] GetNestedTypes( BindingFlags bindingAttr) {
+                       return null;
+               }
+               public override PropertyInfo[] GetProperties( BindingFlags bindingAttr) {
+                       return null;
+               }
+               protected override PropertyInfo GetPropertyImpl( string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers) {
+                       return null;
+               }
+               protected override bool HasElementTypeImpl() {
+                       throw new NotSupportedException ();
+               }
+               public override object InvokeMember( string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters)  {
+                       return null;
+               }
+               protected override bool IsArrayImpl() {
+                       return false;
+               }
+               protected override bool IsByRefImpl() {
+                       return false;
+               }
+               protected override bool IsCOMObjectImpl() {
+                       return false;
+               }*/
+               public override bool IsDefined( Type attributeType, bool inherit) {
+                       return false;
+               }
+               /*protected override bool IsPointerImpl() {
+                       return false;
+               }
+               protected override bool IsPrimitiveImpl() {
+                       return false;
+               }
+               protected override bool IsValueTypeImpl() {
+                       return true;
+               }*/
+               
+               public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
+               }
+               public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
+               }
+       }
 }
index edc610cc946c993dfaf5f7d0e099fbcd235304f4..9dd9cac29922b093d5a7aadbac0dd1163cbf5574 100755 (executable)
@@ -31,7 +31,7 @@ namespace System.Reflection.Emit {
                        this.type = type;
                        offset = -1;
                        typeb = tb;
-                       table_idx = tb.pmodule.assemblyb.get_next_table_index (0x04, true);
+                       table_idx = tb.get_next_table_index (0x04, true);
                }
 
                public override FieldAttributes Attributes {
index 2367141641f58a4f033d4b95a8db8922c71e6f84..895129a6e9ff3eeac39aefd6dc853200e35fc161 100644 (file)
@@ -19,7 +19,7 @@ namespace System.Reflection.Emit {
                        public int label_idx;
                };
                private byte[] code;
-               private MethodBuilder mbuilder;
+               private MethodBase mbuilder; /* a MethodBuilder or ConstructorBuilder */
                private int code_len;
                private int max_stack;
                private int cur_stack;
@@ -29,7 +29,7 @@ namespace System.Reflection.Emit {
                private LabelFixup[] fixups;
                private int num_fixups;
 
-               internal ILGenerator (MethodBuilder mb, int size) {
+               internal ILGenerator (MethodBase mb, int size) {
                        if (size < 0)
                                size = 256;
                        code_len = 0;
@@ -141,6 +141,7 @@ namespace System.Reflection.Emit {
                                locals = new LocalBuilder [1];
                                locals [0] = res;
                        }
+                       res.position = locals.Length - 1;
                        return res;
                }
                public virtual Label DefineLabel () {
@@ -169,7 +170,12 @@ namespace System.Reflection.Emit {
                        ll_emit (opcode);
                        emit_int (token);
                }
-               public virtual void Emit (OpCode opcode, Int16 val) {}
+               public virtual void Emit (OpCode opcode, Int16 val) {
+                       make_room (4);
+                       ll_emit (opcode);
+                       code [code_len++] = (byte) (val & 0xFF);
+                       code [code_len++] = (byte) ((val >> 8) & 0xFF);
+               }
                public virtual void Emit (OpCode opcode, Int32 val) {
                        make_room (6);
                        ll_emit (opcode);
@@ -192,8 +198,33 @@ namespace System.Reflection.Emit {
                        code_len += tlen;
 
                }
-               public virtual void Emit (OpCode opcode, Label[] labels) {}
-               public virtual void Emit (OpCode opcode, LocalBuilder lbuilder) {}
+               public virtual void Emit (OpCode opcode, Label[] labels) {
+                       /* opcode needs to be switch. */
+                       int count = labels.Length;
+                       make_room (6 + count * 4);
+                       ll_emit (opcode);
+                       emit_int (count);
+                       if (num_fixups + count >= fixups.Length) {
+                               LabelFixup[] newf = new LabelFixup [fixups.Length + count + 16];
+                               System.Array.Copy (fixups, newf, fixups.Length);
+                               fixups = newf;
+                       }
+                       for (int i = 0; i < count; ++i) {
+                               fixups [num_fixups].size = 4;
+                               fixups [num_fixups].pos = code_len;
+                               fixups [num_fixups].label_idx = labels [i].label;
+                               num_fixups++;
+                               code_len += 4;
+                       }
+               }
+               public virtual void Emit (OpCode opcode, LocalBuilder lbuilder) {
+                       make_room (6);
+                       ll_emit (opcode);
+                       code [code_len++] = (byte) (lbuilder.position & 0xFF);
+                       if (opcode.operandType == OperandType.InlineVar) {
+                               code [code_len++] = (byte) ((lbuilder.position >> 8) & 0xFF);
+                       }
+               }
                public virtual void Emit (OpCode opcode, MethodInfo method) {
                        int token = 0; // FIXME: request a token from the modulebuilder
                        make_room (6);
@@ -206,9 +237,19 @@ namespace System.Reflection.Emit {
                        ll_emit (opcode);
                        code [code_len++] = (byte)val;
                }
-               public virtual void Emit (OpCode opcode, SignatureHelper shelper) {}
+               public virtual void Emit (OpCode opcode, SignatureHelper shelper) {
+                       int token = 0; // FIXME: request a token from the modulebuilder
+                       make_room (6);
+                       ll_emit (opcode);
+                       emit_int (token);
+               }
                public virtual void Emit (OpCode opcode, float val) {}
-               public virtual void Emit (OpCode opcode, string val) {}
+               public virtual void Emit (OpCode opcode, string val) {
+                       int token = 0; /* FIXME: request the token from the assembly */
+                       make_room (3);
+                       ll_emit (opcode);
+                       emit_int (token);
+               }
                public virtual void Emit (OpCode opcode, Type type) {}
 
                public void EmitCall (OpCode opcode, MethodInfo methodinfo, Type[] optionalParamTypes) {}
index ff4cbe8c79df391c47b1b55ed9ab22b262ba5e43..38dcd20d2dddc82efb18bab01a738a6ac073461b 100755 (executable)
@@ -18,6 +18,7 @@ namespace System.Reflection.Emit {
        public sealed class LocalBuilder {
                private Type type;
                private string name;
+               internal int position;
 
                internal LocalBuilder (Type t) {
                        type = t;
index 8da0037a7ecde01021cb9a4e1be81b3b8dee6f32..9265d314db4e7bfcbf7acc31571fe4809171cd97 100755 (executable)
@@ -21,11 +21,12 @@ namespace System.Reflection.Emit {
                private Type rtype;
                private Type[] parameters;
                private MethodAttributes attrs;
+               private MethodImplAttributes iattrs;
                private string name;
                private int table_idx;
                private byte[] code;
                private ILGenerator ilgen;
-               internal TypeBuilder type;
+               private TypeBuilder type;
                private ParameterBuilder[] pinfo;
                private string pi_dll;
                private string pi_entry;
@@ -43,7 +44,7 @@ namespace System.Reflection.Emit {
                                System.Array.Copy (parameterTypes, this.parameters, parameterTypes.Length);
                        }
                        type = tb;
-                       table_idx = tb.pmodule.assemblyb.get_next_table_index (0x06, true);
+                       table_idx = get_next_table_index (0x06, true);
                }
 
                internal MethodBuilder (TypeBuilder tb, string name, MethodAttributes attributes, 
@@ -73,16 +74,12 @@ namespace System.Reflection.Emit {
                        return null;
                }
                public override MethodImplAttributes GetMethodImplementationFlags() {
-                       return (MethodImplAttributes)0;
+                       return iattrs;
                }
                public override ParameterInfo[] GetParameters() {
                        return null;
                }
                
-               /*
-                * FIXME: this method signature needs to be expanded to handle also
-                * a ILGenerator.
-                */
                public void CreateMethodBody( byte[] il, int count) {
                        code = new byte [count];
                        System.Array.Copy(il, code, count);
@@ -123,6 +120,10 @@ namespace System.Reflection.Emit {
                public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
                }
                public void SetImplementationFlags( MethodImplAttributes attributes) {
+                       iattrs = attributes;
+               }
+               internal override int get_next_table_index (int table, bool inc) {
+                       return type.get_next_table_index (table, inc);
                }
        }
 }
index 43605ce6839d1d0dcc82fa38560384953ffb2344..54efb12ccf72aa47303704bea05359a2b326eb61 100644 (file)
@@ -16,13 +16,13 @@ namespace System.Reflection.Emit {
        public class ModuleBuilder : Module {
                private TypeBuilder[] types;
                private int table_idx;
-               internal AssemblyBuilder assemblyb;
+               private AssemblyBuilder assemblyb;
 
                internal ModuleBuilder (AssemblyBuilder assb, string name, string fullyqname) {
                        this.name = this.scopename = name;
                        this.fqname = fullyqname;
                        this.assemblyb = assb;
-                       table_idx = assb.get_next_table_index (0x00, true);
+                       table_idx = get_next_table_index (0x00, true);
                }
        
                public override string FullyQualifiedName {get { return fqname;}}
@@ -70,5 +70,14 @@ namespace System.Reflection.Emit {
                        return null;
                }
 
+               public EnumBuilder DefineEnum( string name, TypeAttributes visibility, Type underlyingType) {
+                       EnumBuilder eb = new EnumBuilder (this, name, visibility, underlyingType);
+                       return eb;
+               }
+
+               internal int get_next_table_index (int table, bool inc) {
+                       return assemblyb.get_next_table_index (table, inc);
+               }
+
        }
 }
index 1e24a75a810adb17c77e259972c23d9695dd3311..28949d8d25ed8281a6b651db14dabc0a57124378 100755 (executable)
@@ -17,18 +17,18 @@ using System.Runtime.CompilerServices;
 
 namespace System.Reflection.Emit {
        public class ParameterBuilder {
-               private MethodBuilder methodb;
+               private MethodBase methodb; /* MethodBuilder or ConstructorBuilder */
                private string name;
                private ParameterAttributes attrs;
                private int position;
                private int table_idx;
                
-               internal ParameterBuilder (MethodBuilder mb, int pos, ParameterAttributes attributes, string strParamName) {
+               internal ParameterBuilder (MethodBase mb, int pos, ParameterAttributes attributes, string strParamName) {
                        name = strParamName;
                        position = pos;
                        attrs = attributes;
                        methodb = mb;
-                       table_idx = mb.type.pmodule.assemblyb.get_next_table_index (0x08, true);
+                       table_idx = mb.get_next_table_index (0x08, true);
                }
 
                public virtual int Attributes {
index db724cb74a74762ce7a399c8432e2550f01f400a..b72596fbedc8abfd51331a6dd741088d852c4548 100755 (executable)
@@ -35,7 +35,7 @@ namespace System.Reflection.Emit {
                                System.Array.Copy (parameterTypes, this.parameters, this.parameters.Length);
                        }
                        typeb = tb;
-                       table_idx = tb.pmodule.assemblyb.get_next_table_index (0x17, true);
+                       table_idx = tb.get_next_table_index (0x17, true);
                }
 
                public override PropertyAttributes Attributes {
diff --git a/mcs/class/corlib/System.Reflection.Emit/SignatureHelper.cs b/mcs/class/corlib/System.Reflection.Emit/SignatureHelper.cs
new file mode 100755 (executable)
index 0000000..9838728
--- /dev/null
@@ -0,0 +1,56 @@
+
+//
+// System.Reflection.Emit/SignatureHelper.cs
+//
+// Author:
+//   Paolo Molaro (lupus@ximian.com)
+//
+// (C) 2001 Ximian, Inc.  http://www.ximian.com
+//
+
+using System;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Globalization;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+namespace System.Reflection.Emit {
+       public sealed class SignatureHelper {
+               public static SignatureHelper GetFieldSigHelper (Module mod) {
+                       return null;
+               }
+               public static SignatureHelper GetLocalVarSigHelper( Module mod) {
+                       return null;
+               }
+               public static SignatureHelper GetMethodSigHelper( Module mod, CallingConventions callingConvention, Type returnType) {
+                       return null;
+               }
+               public static SignatureHelper GetMethodSigHelper( Module mod, Type returnType, Type[] parameterTypes) {
+                       return null;
+               }
+               public static SignatureHelper GetPropertySigHelper( Module mod, Type returnType, Type[] parameterTypes) {
+                       return null;
+               }
+               public void AddArgument( Type clsArgument) {
+               }
+               public void AddSentinel() {
+               }
+               public override bool Equals( object obj) {
+                       return false;
+               }
+               public override int GetHashCode() {
+                       return 0;
+               }
+               public byte[] GetSignature() {
+                       return null;
+               }
+               public override string ToString() {
+                       return "SignatureHelper";
+               }
+
+
+
+       }
+}
+
index e2d744fb91437a629b72e9f6a21b38b451d6ac5b..42f44db53dbff059c5f4820d52fc303d9d707678 100644 (file)
@@ -20,16 +20,17 @@ namespace System.Reflection.Emit {
        private Type parent;
        private Type[] interfaces;
        private MethodBuilder[] methods;
+       private ConstructorBuilder[] ctors;
        private PropertyBuilder[] properties;
        private FieldBuilder[] fields;
        private TypeAttributes attrs;
        private int table_idx;
-       internal ModuleBuilder pmodule;
+       private ModuleBuilder pmodule;
        private PackingSize packing_size;
 
        public const int UnspecifiedTypeSize = -1;
 
-       internal TypeBuilder (ModuleBuilder mb, string name, TypeAttributes attr, Type parent, Type[] interfaces) {
+               internal TypeBuilder (ModuleBuilder mb, string name, TypeAttributes attr, Type parent, Type[] interfaces) {
                        int sep_index;
                        this.parent = parent;
                        this.attrs = attr;
@@ -47,8 +48,8 @@ namespace System.Reflection.Emit {
                                System.Array.Copy (interfaces, this.interfaces, interfaces.Length);
                        }
                        pmodule = mb;
-                       table_idx = mb.assemblyb.get_next_table_index (0x02, true);
-       }
+                       table_idx = mb.get_next_table_index (0x02, true);
+               }
 
                public override Assembly Assembly {get {return null;}}
                public override string AssemblyQualifiedName {get {return null;}}
@@ -75,7 +76,9 @@ namespace System.Reflection.Emit {
                        get {return packing_size;}
                }
                public override Type ReflectedType {get {return null;}}
-               public override MemberTypes MemberType { get {return (MemberTypes)0;}}
+               public override MemberTypes MemberType { 
+                       get {return MemberTypes.TypeInfo;}
+               }
 
                public override bool IsDefined( Type attributeType, bool inherit) {
                        return false;
@@ -127,11 +130,21 @@ namespace System.Reflection.Emit {
                }
 
                public ConstructorBuilder DefineConstructor( MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes) {
-                       return null;
+                       ConstructorBuilder cb = new ConstructorBuilder (this, attributes, callingConvention, parameterTypes);
+                       if (ctors != null) {
+                               ConstructorBuilder[] new_ctors = new ConstructorBuilder [ctors.Length+1];
+                               System.Array.Copy (ctors, new_ctors, ctors.Length);
+                               new_ctors [ctors.Length] = cb;
+                               ctors = new_ctors;
+                       } else {
+                               ctors = new ConstructorBuilder [1];
+                               ctors [0] = cb;
+                       }
+                       return cb;
                }
 
                public ConstructorBuilder DefineDefaultConstructor( MethodAttributes attributes) {
-                       return null;
+                       return DefineConstructor (attributes, CallingConventions.Standard, null);
                }
 
                public MethodBuilder DefineMethod( string name, MethodAttributes attributes, Type returnType, Type[] parameterTypes) {
@@ -203,6 +216,11 @@ namespace System.Reflection.Emit {
                                        method.fixup ();
                                }
                        }
+                       if (ctors != null) {
+                               foreach (ConstructorBuilder ctor in ctors) {
+                                       ctor.fixup ();
+                               }
+                       }
                        return null;
                }
 
@@ -229,5 +247,12 @@ namespace System.Reflection.Emit {
                        return null;
                }
 
+               public void SetParent (Type parentType) {
+                       parent = parentType;
+               }
+               internal int get_next_table_index (int table, bool inc) {
+                       return pmodule.get_next_table_index (table, inc);
+               }
+
        }
 }
index 0537ecc6ceafb060d20c901975723ef4920cfac9..8519090692c5c037e3b4215af696a736de6349c5 100644 (file)
@@ -1,4 +1,9 @@
 \r
+Mon Nov 19 13:56:55 CET 2001 Paolo Molaro <lupus@ximian.com>\r
+\r
+       * MethodBase.cs: add internal get_next_table_index() for use in\r
+       Reflection.Emit.\r
+\r
 Wed Nov 14 16:53:28 CET 2001 Paolo Molaro <lupus@ximian.com>\r
 \r
        * Assembly.cs: implement some of the Load() methods.\r
index 6a08d609efc684c8be280c4b99e8053a39e5d660..54a1cb5be35adfd05f5bdb0e7393ed7234d6883d 100644 (file)
@@ -9,6 +9,7 @@
 
 using System;
 using System.Globalization;
+using System.Reflection.Emit;
 
 namespace System.Reflection {
 
@@ -120,5 +121,17 @@ namespace System.Reflection {
                                        && (Name == ".ctor"));
                        }
                }
+
+               internal virtual int get_next_table_index (int table, bool inc) {
+                       if (this is MethodBuilder) {
+                               MethodBuilder mb = (MethodBuilder)this;
+                               return mb.get_next_table_index (table, inc);
+                       }
+                       if (this is ConstructorBuilder) {
+                               ConstructorBuilder mb = (ConstructorBuilder)this;
+                               return mb.get_next_table_index (table, inc);
+                       }
+                       throw new Exception ("Method is not a builder method");
+               }
        }
 }