X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FPEAPI%2FMetadata.cs;h=d9b17da6a81524be9855bd2ec80234b626f3bc3e;hb=a713a14521da8ddf992c4a3e64855d56cb7897a3;hp=1e08ff38590bddf4950a8e3c9b03d0d8f2586051;hpb=ae3b35aa23f89afc78957b808ee8112b3670c8c7;p=mono.git diff --git a/mcs/class/PEAPI/Metadata.cs b/mcs/class/PEAPI/Metadata.cs index 1e08ff38590..d9b17da6a81 100644 --- a/mcs/class/PEAPI/Metadata.cs +++ b/mcs/class/PEAPI/Metadata.cs @@ -94,6 +94,11 @@ namespace PEAPI { ForwardRef = 0x10, PreserveSig = 0x0080, InternalCall = 0x1000, Synchronised = 0x0020, Synchronized = 0x0020, NoInLining = 0x0008, Optil = 0x0002} + /// + /// Storage location for initial field data + /// + public enum DataSegment { Data, TLS, CIL } + /// /// Modes for a parameter /// @@ -443,6 +448,60 @@ namespace PEAPI { type = constrType; cVal = val; tabIx = MDTable.CustomAttribute; + + byteVal = ConstantToByteArray (val); + } + + static byte[] ConstantToByteArray (Constant c) + { + var bac = c as ByteArrConst; + if (bac != null) + return bac.val; + + var ms = new MemoryStream (); + // Version info + ms.WriteByte (1); + ms.WriteByte (0); + + if (c == null) { + ms.WriteByte (0); + ms.WriteByte (0); + return ms.ToArray (); + } + + var sc = c as StringConst; + if (sc != null) { + string value = sc.val; + if (value == null) + throw new NotImplementedException (); + + var buf = Encoding.UTF8.GetBytes (value); + MetaData.CompressNum ((uint) buf.Length, ms); + var byteVal = ms.ToArray (); + System.Array.Resize (ref byteVal, (int) ms.Length + buf.Length + 2); + System.Array.Copy (buf, 0, byteVal, ms.Length, buf.Length); + return byteVal; + } + + var ac = c as ArrayConstant; + if (ac != null) { + var bw = new BinaryWriter (ms); + if (ac.ExplicitSize != null) + bw.Write (ac.ExplicitSize.Value); + ac.Write (bw); + bw.Write ((short)0); + return ms.ToArray (); + } + + var bc = c as DataConstant; + if (bc != null) { + var bw = new BinaryWriter (ms); + bc.Write (bw); + bw.Write ((short)0); + return ms.ToArray (); + } + + throw new NotImplementedException (c.GetType ().ToString ()); } internal CustomAttribute(MetaDataElement paren, Method constrType, @@ -2912,7 +2971,7 @@ namespace PEAPI { /// /// Boolean constant /// - public class BoolConst : Constant { + public class BoolConst : DataConstant { bool val; /// @@ -2945,7 +3004,7 @@ namespace PEAPI { } public class ByteArrConst : DataConstant { - byte[] val; + internal byte[] val; public ByteArrConst(byte[] val) { @@ -3110,7 +3169,7 @@ namespace PEAPI { } - public class UIntConst : Constant { + public class UIntConst : DataConstant { ulong val; public UIntConst(byte val) @@ -3165,7 +3224,7 @@ namespace PEAPI { } public class StringConst : DataConstant { - string val; + internal string val; public StringConst(string val) { @@ -3266,6 +3325,8 @@ namespace PEAPI { } } + public int? ExplicitSize { get; set; } + internal sealed override void Write(BinaryWriter bw) { for (int i=0; i < dataVals.Length; i++) { @@ -3310,6 +3371,7 @@ namespace PEAPI { Type type; Class cmodType; + PrimitiveTypeRef cmodPrimType; /// /// Create a new custom modifier for a type @@ -3324,10 +3386,23 @@ namespace PEAPI { this.cmodType = cmodType; } + public CustomModifiedType(Type type, CustomModifier cmod, PrimitiveTypeRef cmodType) + : base((byte)cmod) + { + this.type = type; + this.cmodPrimType = cmodType; + } + internal sealed override void TypeSig(MemoryStream str) { str.WriteByte(typeIndex); - MetaData.CompressNum(cmodType.TypeDefOrRefToken(),str); + + if (cmodType != null) { + MetaData.CompressNum(cmodType.TypeDefOrRefToken(),str); + } else { + MetaData.CompressNum(cmodPrimType.TypeDefOrRefToken(),str); + } + type.TypeSig(str); } @@ -4466,6 +4541,26 @@ namespace PEAPI { } + public class PrimitiveTypeRef : Type + { + PrimitiveType type; + MetaData metaData; + + internal PrimitiveTypeRef(PrimitiveType type, MetaData md) + : base (0) + { + this.type = type; + this.metaData = md; + } + + internal uint TypeDefOrRefToken() + { + uint cIx = type.GetTypeSpec (metaData).Row; + cIx = (cIx << 2) | 0x2; + return cIx; + } + } + /**************************************************************************/ /// /// Descriptor for an pointer (type * or type &) @@ -5256,12 +5351,20 @@ namespace PEAPI { MDTable tabIx = (MDTable)i; if (count > max5BitSmlIx) { + if (tabIx == MDTable.Method || tabIx == MDTable.Field || tabIx == MDTable.TypeRef || + tabIx == MDTable.TypeDef || tabIx == MDTable.Param || tabIx == MDTable.InterfaceImpl || + tabIx == MDTable.MemberRef || tabIx == MDTable.Module || tabIx == MDTable.DeclSecurity || + tabIx == MDTable.Property || tabIx == MDTable.Event || tabIx == MDTable.StandAloneSig || + tabIx == MDTable.ModuleRef || tabIx == MDTable.TypeSpec || tabIx == MDTable.Assembly || + tabIx == MDTable.AssemblyRef || tabIx == MDTable.File || tabIx == MDTable.ExportedType || + tabIx == MDTable.ManifestResource || tabIx == MDTable.GenericParam) lgeCIx[(int)CIx.HasCustomAttr] = true; } if (count > max3BitSmlIx) { - if ((tabIx == MDTable.TypeRef) || (tabIx == MDTable.ModuleRef) || (tabIx == MDTable.Method) || (tabIx == MDTable.TypeSpec) || (tabIx == MDTable.Field)) + if (tabIx == MDTable.Method || tabIx == MDTable.MemberRef) lgeCIx[(int)CIx.CustomAttributeType] = true; - if ((tabIx == MDTable.Method) || (tabIx == MDTable.MemberRef)) + if (tabIx == MDTable.TypeDef || tabIx == MDTable.TypeRef || tabIx == MDTable.ModuleRef || + tabIx == MDTable.Method || tabIx == MDTable.TypeSpec) lgeCIx[(int)CIx.MemberRefParent] = true; } if (count > max2BitSmlIx) {