private ModuleBuilder pmodule;
private int class_size;
private PackingSize packing_size;
+ private Type created;
- public const int UnspecifiedTypeSize = -1;
+ public const int UnspecifiedTypeSize = 0;
protected override TypeAttributes GetAttributeFlagsImpl () {
return attrs;
public override Assembly Assembly {
get {return pmodule.Assembly;}
}
- public override string AssemblyQualifiedName {get {return null;}}
+ public override string AssemblyQualifiedName {
+ get {
+ return FullName + ", " + Assembly.ToString();
+ }
+ }
public override Type BaseType {
get {
return parent;
}
}
- public override Type DeclaringType {get {return null;}}
+ public override Type DeclaringType {get {return nesting_type;}}
public override Type UnderlyingSystemType {
get {
if (fields != null) {
public PackingSize PackingSize {
get {return packing_size;}
}
- public override Type ReflectedType {get {return parent;}}
+ public override Type ReflectedType {get {return nesting_type;}}
public override MemberTypes MemberType {
get {return MemberTypes.TypeInfo;}
}
[MonoTODO]
public TypeBuilder DefineNestedType (string name) {
// FIXME: LAMESPEC: what other attributes should we use here as default?
- return DefineNestedType (name, TypeAttributes.Public, typeof(object), null);
+ return DefineNestedType (name, TypeAttributes.Public, pmodule.assemblyb.corlib_object_type, null);
}
public TypeBuilder DefineNestedType (string name, TypeAttributes attr) {
- return DefineNestedType (name, attr, typeof(object), null);
+ return DefineNestedType (name, attr, pmodule.assemblyb.corlib_object_type, null);
}
public TypeBuilder DefineNestedType (string name, TypeAttributes attr, Type parent) {
throw new NotImplementedException ();
}
+ [MethodImplAttribute(MethodImplOptions.InternalCall)]
+ private extern Type create_runtime_class (TypeBuilder tb);
+
public Type CreateType() {
+ /* handle nesting_type */
+ if (created != null)
+ throw new InvalidOperationException ("type already created");
if (methods != null) {
foreach (MethodBuilder method in methods) {
method.fixup ();
ctor.fixup ();
}
}
+ created = create_runtime_class (this);
return this;
}
}
protected override bool IsArrayImpl () {
- // FIXME
- return false;
+ return type_is_subtype_of (this, typeof (System.Array), false);
}
protected override bool IsByRefImpl () {
// FIXME
return false;
}
protected override bool IsValueTypeImpl () {
- // test this one
- return type_is_subtype_of (this, typeof (System.ValueType), false);
+ return ((type_is_subtype_of (this, pmodule.assemblyb.corlib_value_type, false) || type_is_subtype_of (this, typeof(System.ValueType), false)) &&
+ this != pmodule.assemblyb.corlib_value_type &&
+ this != pmodule.assemblyb.corlib_enum_type);
}
public override RuntimeTypeHandle TypeHandle { get { return _impl; } }
- private static int decode_len (byte[] data, int pos, out int rpos) {
- int len = 0;
- if ((data [pos] & 0x80) == 0) {
- len = (int)(data [pos++] & 0x7f);
- } else if ((data [pos] & 0x40) == 0) {
- len = ((data [pos] & 0x3f) << 8) + data [pos + 1];
- pos += 2;
- } else {
- len = ((data [pos] & 0x1f) << 24) + (data [pos + 1] << 16) + (data [pos + 2] << 8) + data [pos + 3];
- pos += 4;
- }
- rpos = pos;
- return len;
- }
-
- private static string string_from_bytes (byte[] data, int pos, int len) {
- char[] chars = new char [len];
- // FIXME: use a utf8 decoder here
- for (int i = 0; i < len; ++i)
- chars [i] = (char)data [pos + i];
- return new String (chars);
- }
-
public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
string attrname = customBuilder.Ctor.ReflectedType.FullName;
if (attrname == "System.Runtime.InteropServices.StructLayoutAttribute") {
int nnamed = (int)data [pos++];
nnamed |= ((int)data [pos++]) << 8;
for (int i = 0; i < nnamed; ++i) {
+ byte named_type = data [pos++];
byte type = data [pos++];
- int len = decode_len (data, pos, out pos);
- string named_name = string_from_bytes (data, pos, len);
+ int len = CustomAttributeBuilder.decode_len (data, pos, out pos);
+ string named_name = CustomAttributeBuilder.string_from_bytes (data, pos, len);
pos += len;
/* all the fields are integers in StructLayout */
int value = (int)data [pos++];
}
}
return;
+ } else if (attrname == "System.SerializableAttribute") {
+ attrs |= TypeAttributes.Serializable;
+ return;
}
if (cattrs != null) {
CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
public FieldBuilder DefineInitializedData( string name, byte[] data, FieldAttributes attributes) {
TypeBuilder datablobtype = pmodule.DefineType ("$ArrayType$"+InitializedDataCount.ToString(),
TypeAttributes.Public|TypeAttributes.ExplicitLayout|TypeAttributes.Sealed,
- typeof (System.ValueType), PackingSize.Size1, data.Length);
+ pmodule.assemblyb.corlib_value_type, PackingSize.Size1, data.Length);
datablobtype.packing_size = PackingSize.Size1;
datablobtype.class_size = data.Length;
datablobtype.CreateType ();