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);
+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.
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;
}
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";}
}
}
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;}
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) {
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) {
}
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);
+ }
+
}
}
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) {
+ }
+ }
}
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 {
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;
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;
locals = new LocalBuilder [1];
locals [0] = res;
}
+ res.position = locals.Length - 1;
return res;
}
public virtual Label DefineLabel () {
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);
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);
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) {}
public sealed class LocalBuilder {
private Type type;
private string name;
+ internal int position;
internal LocalBuilder (Type t) {
type = t;
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;
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,
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);
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);
}
}
}
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;}}
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);
+ }
+
}
}
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 {
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 {
--- /dev/null
+
+//
+// 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";
+ }
+
+
+
+ }
+}
+
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;
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;}}
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;
}
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) {
method.fixup ();
}
}
+ if (ctors != null) {
+ foreach (ConstructorBuilder ctor in ctors) {
+ ctor.fixup ();
+ }
+ }
return null;
}
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);
+ }
+
}
}
\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
using System;
using System.Globalization;
+using System.Reflection.Emit;
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");
+ }
}
}