Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/ikvm-fork.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjfrijters <jfrijters>2011-03-14 08:03:30 +0300
committerjfrijters <jfrijters>2011-03-14 08:03:30 +0300
commit4300d8f5eaaedaf8edd363322706e428a1897363 (patch)
tree679fc97b9b2ab3f6c120abdd2b557d14b2db7d33 /reflect/Emit
parent2af3abfc91e7de453b6b8d826530b44094727376 (diff)
- Removed TypeBuilder.__SetStructLayoutAttribute().
- Added TypeBuilder.__SetLayout(). - Added Type.__GetLayout(). - Fixed Type.StructLayoutAttribute to be compatible with .NET.
Diffstat (limited to 'reflect/Emit')
-rw-r--r--reflect/Emit/ModuleBuilder.cs5
-rw-r--r--reflect/Emit/TypeBuilder.cs75
2 files changed, 45 insertions, 35 deletions
diff --git a/reflect/Emit/ModuleBuilder.cs b/reflect/Emit/ModuleBuilder.cs
index 3468e4b4..796a2b00 100644
--- a/reflect/Emit/ModuleBuilder.cs
+++ b/reflect/Emit/ModuleBuilder.cs
@@ -211,7 +211,10 @@ namespace IKVM.Reflection.Emit
TypeBuilder typeBuilder = __DefineType(ns, name);
typeBuilder.__SetAttributes(attr);
typeBuilder.SetParent(parent);
- typeBuilder.SetPackingSizeAndTypeSize(packingSize, typesize);
+ if (packingSize != PackingSize.Unspecified || typesize != 0)
+ {
+ typeBuilder.__SetLayout((int)packingSize, typesize);
+ }
return typeBuilder;
}
diff --git a/reflect/Emit/TypeBuilder.cs b/reflect/Emit/TypeBuilder.cs
index 87ef7d15..86134f3f 100644
--- a/reflect/Emit/TypeBuilder.cs
+++ b/reflect/Emit/TypeBuilder.cs
@@ -236,6 +236,7 @@ namespace IKVM.Reflection.Emit
private List<Type> interfaces;
private int size;
private short pack;
+ private bool hasLayout;
internal TypeBuilder(ITypeOwner owner, string ns, string name)
{
@@ -447,8 +448,10 @@ namespace IKVM.Reflection.Emit
TypeBuilder typeBuilder = __DefineNestedType(ns, name);
typeBuilder.__SetAttributes(attr);
typeBuilder.SetParent(parent);
- typeBuilder.pack = (short)packSize;
- typeBuilder.size = typeSize;
+ if (packSize != PackingSize.Unspecified || typeSize != 0)
+ {
+ typeBuilder.__SetLayout((int)packSize, typeSize);
+ }
return typeBuilder;
}
@@ -487,10 +490,38 @@ namespace IKVM.Reflection.Emit
get { return (PackingSize)pack; }
}
- public void __SetStructLayoutAttribute(StructLayoutAttribute attribute)
+ public override bool __GetLayout(out int packingSize, out int typeSize)
+ {
+ packingSize = this.pack;
+ typeSize = this.size;
+ return hasLayout;
+ }
+
+ public void __SetLayout(int packingSize, int typesize)
+ {
+ this.pack = (short)packingSize;
+ this.size = typesize;
+ this.hasLayout = true;
+ }
+
+ private void SetStructLayoutPseudoCustomAttribute(CustomAttributeBuilder customBuilder)
{
+ object val = customBuilder.GetConstructorArgument(0);
+ LayoutKind layout;
+ if (val is short)
+ {
+ layout = (LayoutKind)(short)val;
+ }
+ else
+ {
+ layout = (LayoutKind)val;
+ }
+ StructLayoutAttribute attr = new StructLayoutAttribute(layout);
+ attr.Pack = (int?)customBuilder.GetFieldValue("Pack") ?? 0;
+ attr.Size = (int?)customBuilder.GetFieldValue("Size") ?? 0;
+ attr.CharSet = customBuilder.GetFieldValue<CharSet>("CharSet") ?? CharSet.None;
attribs &= ~TypeAttributes.LayoutMask;
- switch (attribute.Value)
+ switch (attr.Value)
{
case LayoutKind.Auto:
attribs |= TypeAttributes.AutoLayout;
@@ -503,7 +534,7 @@ namespace IKVM.Reflection.Emit
break;
}
attribs &= ~TypeAttributes.StringFormatMask;
- switch (attribute.CharSet)
+ switch (attr.CharSet)
{
case CharSet.None:
case CharSet.Ansi:
@@ -516,33 +547,9 @@ namespace IKVM.Reflection.Emit
attribs |= TypeAttributes.UnicodeClass;
break;
}
- pack = (short)attribute.Pack;
- size = attribute.Size;
- }
-
- internal void SetPackingSizeAndTypeSize(PackingSize packingSize, int typesize)
- {
- this.pack = (short)packingSize;
- this.size = typesize;
- }
-
- private void SetStructLayoutPseudoCustomAttribute(CustomAttributeBuilder customBuilder)
- {
- object val = customBuilder.GetConstructorArgument(0);
- LayoutKind layout;
- if (val is short)
- {
- layout = (LayoutKind)(short)val;
- }
- else
- {
- layout = (LayoutKind)val;
- }
- StructLayoutAttribute attr = new StructLayoutAttribute(layout);
- attr.Pack = (int?)customBuilder.GetFieldValue("Pack") ?? 0;
- attr.Size = (int?)customBuilder.GetFieldValue("Size") ?? 0;
- attr.CharSet = customBuilder.GetFieldValue<CharSet>("CharSet") ?? CharSet.None;
- __SetStructLayoutAttribute(attr);
+ pack = (short)attr.Pack;
+ size = attr.Size;
+ hasLayout = pack != 0 || size != 0;
}
public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
@@ -645,10 +652,10 @@ namespace IKVM.Reflection.Emit
throw new NotImplementedException();
}
typeFlags |= TypeFlags.Baked;
- if (pack != 0 || size != 0)
+ if (hasLayout)
{
ClassLayoutTable.Record rec = new ClassLayoutTable.Record();
- rec.PackingSize = (short)pack;
+ rec.PackingSize = pack;
rec.ClassSize = size;
rec.Parent = token;
this.ModuleBuilder.ClassLayout.AddRecord(rec);