From 5fb257ad8c863a5ce02acdefbc3dde66e6bf222c Mon Sep 17 00:00:00 2001 From: Paolo Molaro Date: Mon, 19 Nov 2001 09:09:26 +0000 Subject: [PATCH] Mon Nov 19 13:58:01 CET 2001 Paolo Molaro * 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 * MethodBase.cs: add internal get_next_table_index() for use in Reflection.Emit. svn path=/trunk/mcs/; revision=1384 --- .../System.Reflection.Emit/AssemblyBuilder.cs | 3 + .../corlib/System.Reflection.Emit/ChangeLog | 17 ++ .../ConstructorBuilder.cs | 51 ++++-- .../System.Reflection.Emit/EnumBuilder.cs | 153 +++++++++++++++++- .../System.Reflection.Emit/FieldBuilder.cs | 2 +- .../System.Reflection.Emit/ILGenerator.cs | 55 ++++++- .../System.Reflection.Emit/LocalBuilder.cs | 1 + .../System.Reflection.Emit/MethodBuilder.cs | 15 +- .../System.Reflection.Emit/ModuleBuilder.cs | 13 +- .../ParameterBuilder.cs | 6 +- .../System.Reflection.Emit/PropertyBuilder.cs | 2 +- .../System.Reflection.Emit/SignatureHelper.cs | 56 +++++++ .../System.Reflection.Emit/TypeBuilder.cs | 39 ++++- mcs/class/corlib/System.Reflection/ChangeLog | 5 + .../corlib/System.Reflection/MethodBase.cs | 13 ++ 15 files changed, 391 insertions(+), 40 deletions(-) create mode 100755 mcs/class/corlib/System.Reflection.Emit/SignatureHelper.cs diff --git a/mcs/class/corlib/System.Reflection.Emit/AssemblyBuilder.cs b/mcs/class/corlib/System.Reflection.Emit/AssemblyBuilder.cs index d44529e847c..2659d8146f5 100755 --- a/mcs/class/corlib/System.Reflection.Emit/AssemblyBuilder.cs +++ b/mcs/class/corlib/System.Reflection.Emit/AssemblyBuilder.cs @@ -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); diff --git a/mcs/class/corlib/System.Reflection.Emit/ChangeLog b/mcs/class/corlib/System.Reflection.Emit/ChangeLog index 4c7bed1b332..b276b24a2a3 100644 --- a/mcs/class/corlib/System.Reflection.Emit/ChangeLog +++ b/mcs/class/corlib/System.Reflection.Emit/ChangeLog @@ -1,4 +1,21 @@ +Mon Nov 19 13:58:01 CET 2001 Paolo Molaro + + * 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 + + * 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 * ConstructorBuilder.cs: added missing stubs and some implementation. diff --git a/mcs/class/corlib/System.Reflection.Emit/ConstructorBuilder.cs b/mcs/class/corlib/System.Reflection.Emit/ConstructorBuilder.cs index e3b293d9cb0..c5f17caec4d 100644 --- a/mcs/class/corlib/System.Reflection.Emit/ConstructorBuilder.cs +++ b/mcs/class/corlib/System.Reflection.Emit/ConstructorBuilder.cs @@ -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); + } + } } diff --git a/mcs/class/corlib/System.Reflection.Emit/EnumBuilder.cs b/mcs/class/corlib/System.Reflection.Emit/EnumBuilder.cs index c1ee333c3dc..d5fa777118a 100755 --- a/mcs/class/corlib/System.Reflection.Emit/EnumBuilder.cs +++ b/mcs/class/corlib/System.Reflection.Emit/EnumBuilder.cs @@ -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) { + } + } } diff --git a/mcs/class/corlib/System.Reflection.Emit/FieldBuilder.cs b/mcs/class/corlib/System.Reflection.Emit/FieldBuilder.cs index edc610cc946..9dd9cac2992 100755 --- a/mcs/class/corlib/System.Reflection.Emit/FieldBuilder.cs +++ b/mcs/class/corlib/System.Reflection.Emit/FieldBuilder.cs @@ -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 { diff --git a/mcs/class/corlib/System.Reflection.Emit/ILGenerator.cs b/mcs/class/corlib/System.Reflection.Emit/ILGenerator.cs index 2367141641f..895129a6e9f 100644 --- a/mcs/class/corlib/System.Reflection.Emit/ILGenerator.cs +++ b/mcs/class/corlib/System.Reflection.Emit/ILGenerator.cs @@ -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) {} diff --git a/mcs/class/corlib/System.Reflection.Emit/LocalBuilder.cs b/mcs/class/corlib/System.Reflection.Emit/LocalBuilder.cs index ff4cbe8c79d..38dcd20d2dd 100755 --- a/mcs/class/corlib/System.Reflection.Emit/LocalBuilder.cs +++ b/mcs/class/corlib/System.Reflection.Emit/LocalBuilder.cs @@ -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; diff --git a/mcs/class/corlib/System.Reflection.Emit/MethodBuilder.cs b/mcs/class/corlib/System.Reflection.Emit/MethodBuilder.cs index 8da0037a7ec..9265d314db4 100755 --- a/mcs/class/corlib/System.Reflection.Emit/MethodBuilder.cs +++ b/mcs/class/corlib/System.Reflection.Emit/MethodBuilder.cs @@ -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); } } } diff --git a/mcs/class/corlib/System.Reflection.Emit/ModuleBuilder.cs b/mcs/class/corlib/System.Reflection.Emit/ModuleBuilder.cs index 43605ce6839..54efb12ccf7 100644 --- a/mcs/class/corlib/System.Reflection.Emit/ModuleBuilder.cs +++ b/mcs/class/corlib/System.Reflection.Emit/ModuleBuilder.cs @@ -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); + } + } } diff --git a/mcs/class/corlib/System.Reflection.Emit/ParameterBuilder.cs b/mcs/class/corlib/System.Reflection.Emit/ParameterBuilder.cs index 1e24a75a810..28949d8d25e 100755 --- a/mcs/class/corlib/System.Reflection.Emit/ParameterBuilder.cs +++ b/mcs/class/corlib/System.Reflection.Emit/ParameterBuilder.cs @@ -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 { diff --git a/mcs/class/corlib/System.Reflection.Emit/PropertyBuilder.cs b/mcs/class/corlib/System.Reflection.Emit/PropertyBuilder.cs index db724cb74a7..b72596fbedc 100755 --- a/mcs/class/corlib/System.Reflection.Emit/PropertyBuilder.cs +++ b/mcs/class/corlib/System.Reflection.Emit/PropertyBuilder.cs @@ -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 index 00000000000..9838728d541 --- /dev/null +++ b/mcs/class/corlib/System.Reflection.Emit/SignatureHelper.cs @@ -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"; + } + + + + } +} + diff --git a/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs b/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs index e2d744fb914..42f44db53db 100644 --- a/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs +++ b/mcs/class/corlib/System.Reflection.Emit/TypeBuilder.cs @@ -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); + } + } } diff --git a/mcs/class/corlib/System.Reflection/ChangeLog b/mcs/class/corlib/System.Reflection/ChangeLog index 0537ecc6cea..8519090692c 100644 --- a/mcs/class/corlib/System.Reflection/ChangeLog +++ b/mcs/class/corlib/System.Reflection/ChangeLog @@ -1,4 +1,9 @@ +Mon Nov 19 13:56:55 CET 2001 Paolo Molaro + + * MethodBase.cs: add internal get_next_table_index() for use in + Reflection.Emit. + Wed Nov 14 16:53:28 CET 2001 Paolo Molaro * Assembly.cs: implement some of the Load() methods. diff --git a/mcs/class/corlib/System.Reflection/MethodBase.cs b/mcs/class/corlib/System.Reflection/MethodBase.cs index 6a08d609efc..54a1cb5be35 100644 --- a/mcs/class/corlib/System.Reflection/MethodBase.cs +++ b/mcs/class/corlib/System.Reflection/MethodBase.cs @@ -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"); + } } } -- 2.25.1