[xbuild]: Support <PropertyGroup/ItemGroup> inside <Target>.
[mono.git] / mcs / class / PEAPI / Metadata.cs
index cd580be3d590ce8b98cbe1c2c8761c087a75c8f3..b2bc01dbd606b888ae23d0e394284717b93d2193 100644 (file)
@@ -29,7 +29,7 @@ namespace PEAPI {
        /// <summary>
        /// Attributes for this assembly
        /// </summary>
-       public enum AssemAttr { EnableJITCompileTracking = 0x8000, 
+       public enum AssemAttr { Retargetable = 0x100, EnableJITCompileTracking = 0x8000, 
                DisableJITCompileOptimizer = 0x4000}
 
        /// <summary>
@@ -55,6 +55,7 @@ namespace PEAPI {
                PublicSealed = 0x101, SpecialName = 0x400, RTSpecialName = 0x800, 
                Import = 0x1000, Serializable = 0x2000, UnicodeClass = 0x10000,
                AutoClass = 0x20000, HasSecurity = 0x40000, BeforeFieldInit = 0x100000,
+               Forwarder = 0x200000,
                VisibilityMask = 0x07 }
 
        /// <summary>
@@ -72,7 +73,7 @@ namespace PEAPI {
                Family, FamOrAssem, Public, Static = 0x0010, PublicStatic = 0x16, 
                Final = 0x0020, PublicStaticFinal = 0x36, Virtual = 0x0040, 
                PrivateVirtual, PublicVirtual = 0x0046, HideBySig = 0x0080, 
-               NewSlot = 0x0100, Abstract = 0x0400, SpecialName = 0x0800,
+               NewSlot = 0x0100, Strict = 0x200, Abstract = 0x0400, SpecialName = 0x0800,
                RTSpecialName = 0x1000, SpecialRTSpecialName = 0x1800, 
                HasSecurity = 0x4000, RequireSecObject = 0x8000}
 
@@ -242,6 +243,8 @@ namespace PEAPI {
                protected bool done = false;
                protected MDTable tabIx;
                protected bool sortTable = false;
+               //Temporary hack.. 
+               private bool has_custom_attrs = false;
 
                internal MetaDataElement() { }
 
@@ -254,6 +257,11 @@ namespace PEAPI {
                        }
                }
 
+               public bool HasCustomAttr {
+                       get { return has_custom_attrs; }
+                       set { has_custom_attrs = value; }
+               }
+
                internal virtual uint GetCodedIx(CIx code) { return 0; }
 
                /// <summary>
@@ -421,7 +429,6 @@ namespace PEAPI {
 
        public class CustomAttribute : MetaDataElement {
 
-               private static readonly ushort prolog = 0x0001;
                MetaDataElement parent;
                Method type;
                uint valIx;
@@ -464,9 +471,14 @@ namespace PEAPI {
 
                internal sealed override void BuildTables(MetaData md) 
                {
+                       md.AddToTable(MDTable.CustomAttribute, this);
+                       if (byteVal == null) {
+                               valIx = 0;
+                               return;
+                       }
+
                        BinaryWriter bw = new BinaryWriter(new MemoryStream());
                        bw.Write(byteVal);
-                       md.AddToTable(MDTable.CustomAttribute, this);
                        MemoryStream str = (MemoryStream)bw.BaseStream;
                        valIx = md.AddToBlobHeap(str.ToArray());
                }
@@ -660,7 +672,6 @@ namespace PEAPI {
        {
                PEAPI.SecurityAction sec_action;
                ArrayList permissions;
-               PEAPI.PermissionSet ps;
 
                public PermissionSet (PEAPI.SecurityAction sec_action)
                {
@@ -1328,6 +1339,10 @@ namespace PEAPI {
                        tabIx = MDTable.Param;
                }
 
+               public bool HasMarshalInfo {
+                       get { return marshalInfo != null; }
+               }
+
                /// <summary>
                /// Add a default value to this parameter
                /// </summary>
@@ -1564,8 +1579,6 @@ namespace PEAPI {
        /// 
        public class ClassDef : Class {
 
-               private static readonly byte ElementType_Class = 0x12;
-
                Class superType;
                ArrayList fields = new ArrayList();
                ArrayList methods = new ArrayList();
@@ -1573,7 +1586,6 @@ namespace PEAPI {
                ArrayList properties;
                bool typeIndexChecked = true;
                uint fieldIx = 0, methodIx = 0;
-               byte[] securityActions;
                uint flags;
                ClassLayout layout;
                ClassDef parentClass;
@@ -1688,9 +1700,14 @@ namespace PEAPI {
                /// <param name="pars">parameters</param>
                /// <returns>a descriptor for this new method</returns>
                public MethodDef AddMethod(string name, Type retType, Param[] pars) 
+               {
+                       return AddMethod (name, new Param (ParamAttr.Default, "", retType), pars);
+               }
+
+               public MethodDef AddMethod (string name, Param ret_param, Param [] pars) 
                {
                        // Console.WriteLine("Adding method " + name + " to class " + this.name);
-                       MethodDef meth = new MethodDef(metaData,name,retType, pars);
+                       MethodDef meth = new MethodDef(metaData,name, ret_param, pars);
                        methods.Add(meth);
                        return meth;
                }
@@ -1705,9 +1722,9 @@ namespace PEAPI {
                /// <param name="pars">parameters</param>
                /// <returns>a descriptor for this new method</returns>
                public MethodDef AddMethod(MethAttr mAtts, ImplAttr iAtts, string name, 
-                               Type retType, Param[] pars) {
+                               Param ret_param, Param [] pars) {
                        // Console.WriteLine("Adding method " + name + " to class " + this.name);
-                       MethodDef meth = new MethodDef(metaData,mAtts,iAtts,name,retType,pars);
+                       MethodDef meth = new MethodDef (metaData, mAtts, iAtts, name, ret_param, pars);
                        methods.Add(meth);
                        return meth;
                }
@@ -1938,7 +1955,6 @@ namespace PEAPI {
        public class ClassRef : Class, IExternRef, IResolutionScope {
 
                protected IResolutionScope parent;
-               ExternClass externClass;
                protected MetaData metaData;
 
                internal ClassRef(string nsName, string name, MetaData md) : base(nsName, name, md) 
@@ -2075,9 +2091,9 @@ namespace PEAPI {
                ExternClass externClass;
 
                internal ExternClassRef(TypeAttr attrs, string nsName, string name,
-                               FileRef declFile, MetaData md) : base(nsName,name,md) 
+                               MetaDataElement declRef, MetaData md) : base(nsName,name,md) 
                {
-                       externClass = new ExternClass(attrs,nameSpaceIx,nameIx,declFile);
+                       externClass = new ExternClass(attrs,nameSpaceIx,nameIx,declRef);
                        metaData.AddToTable(MDTable.ExportedType,externClass);
                }
 
@@ -3800,12 +3816,10 @@ namespace PEAPI {
                // private static readonly byte LocalSigByte = 0x7;
                uint parIx = 0, textOffset = 0;
                private CallConv callConv = CallConv.Default;
-               private Type retType;
                private int gen_param_count;
 
                MetaData metaData;
                CILInstructions code;
-               ArrayList securityActions = new ArrayList();
                Param[] parList;
                Local[] locals;
                bool initLocals;
@@ -3817,21 +3831,23 @@ namespace PEAPI {
                ImplMap pinvokeImpl;
                Param ret_param;
 
-
-               internal MethodDef(MetaData md, string name, Type retType, Param[] pars) : base (name)
+               internal MethodDef (MetaData md, string name, Param ret_param, Param [] pars)
+                       : this (md, 0, 0, name, ret_param, pars)
                {
-                       this.retType = retType;
-                       metaData = md;
-                       parList = pars;
-                       if (parList != null) numPars = parList.Length;
-                       tabIx = MDTable.Method;
                }
 
                internal MethodDef (MetaData md, MethAttr mAttrSet, ImplAttr iAttrSet, string name, 
-                               Type retType, Param [] pars) : this (md, name, retType, pars)
+                               Param ret_param, Param [] pars) 
+                       : base (name)
                {
                        methFlags = (ushort)mAttrSet;
                        implFlags = (ushort)iAttrSet;
+                       this.ret_param = ret_param;
+                       metaData = md;
+                       parList = pars;
+                       if (parList != null) 
+                               numPars = parList.Length;
+                       tabIx = MDTable.Method;
                }
 
                internal Param[] GetPars() 
@@ -3917,7 +3933,6 @@ namespace PEAPI {
                /* Add Marshal info for return type */
                public void AddRetTypeMarshallInfo (NativeType marshallType) 
                {
-                       ret_param = new Param (ParamAttr.HasFieldMarshal, "", retType);
                        ret_param.AddMarshallInfo (marshallType);
                }
 
@@ -3952,7 +3967,7 @@ namespace PEAPI {
                        for (int i=0; i < numPars; i++) {
                                pars[i] = parList[i].GetParType();
                        }
-                       varArgSig = new MethodRef(this,name,retType,pars,true,optPars, 0);
+                       varArgSig = new MethodRef (this, name, ret_param.GetParType (), pars, true, optPars, 0);
 
                        if (varArgSigList == null)
                                varArgSigList = new ArrayList ();
@@ -3966,9 +3981,9 @@ namespace PEAPI {
                        if ((callConv & CallConv.Generic) == CallConv.Generic)
                                MetaData.CompressNum ((uint) gen_param_count, sig);
                        MetaData.CompressNum((uint)numPars,sig);
-                       if (ret_param != null)
-                               ret_param.seqNo = 0;
-                       retType.TypeSig(sig);
+
+                       ret_param.seqNo = 0;
+                       ret_param.TypeSig (sig);
                        for (ushort i=0; i < numPars; i++) {
                                parList[i].seqNo = (ushort)(i+1);
                                parList[i].TypeSig(sig);
@@ -3997,7 +4012,7 @@ namespace PEAPI {
                        nameIx = md.AddToStringsHeap(name);
                        sigIx = GetSigIx(md);
                        parIx = md.TableIndex(MDTable.Param);
-                       if (ret_param != null) {
+                       if (ret_param.HasMarshalInfo || ret_param.HasCustomAttr) {
                                md.AddToTable(MDTable.Param, ret_param);
                                ret_param.BuildTables(md);
                        }
@@ -4311,7 +4326,6 @@ namespace PEAPI {
 
        public class FixedArray : NativeType  {
 
-               NativeType elemType;
                uint numElem;
 
                //public FixedArray(NativeType elemType, int numElems) : base(0x1E) {
@@ -4524,6 +4538,11 @@ namespace PEAPI {
                        tabIx = MDTable.AssemblyRef;
                }
 
+               public void AddAssemblyAttr (AssemAttr aa)
+               {
+                       flags |= (uint)aa;
+               }
+
                /// <summary>
                /// Add version information about this external assembly
                /// </summary>
@@ -4697,7 +4716,7 @@ namespace PEAPI {
                private readonly string systemName = "System";
                private Class[] systemClasses = new Class[valueTypeIx+2];
                private PrimitiveType[] systemTypes = new PrimitiveType[valueTypeIx];
-               private TypeSpec[] specialTypeSpecs = new TypeSpec[valueTypeIx];
+
                private static int[] specialNames = {
                        PrimitiveType.Void.GetName().GetHashCode(),
                        PrimitiveType.Boolean.GetName().GetHashCode(),
@@ -4908,7 +4927,9 @@ namespace PEAPI {
                private static readonly uint max3BitSmlIx = 0x1FFF;
                private static readonly uint max5BitSmlIx = 0x7FF;
                // NOTE: version and stream name strings MUST always be quad padded
-#if NET_2_0 || BOOTSTRAP_NET_2_0
+#if NET_4_0
+               private static readonly string version = "v4.0.30319\0\0";
+#elif NET_2_0
                private static readonly string version = "v2.0.50727\0\0";
 #else
                private static readonly string version = "v1.1.4322\0\0\0";
@@ -4922,7 +4943,6 @@ namespace PEAPI {
                private static readonly uint TildeHeaderSize = 24;
                private static readonly uint StreamHeaderSize = 8;
                private static readonly uint numMetaDataTables = (int)MDTable.GenericParamConstraint + 1;
-               private static readonly uint tildeHeaderSize = 8 + (uint)tildeName.Length;
 
                MetaDataStream strings, us, guid, blob;
 
@@ -5315,9 +5335,9 @@ namespace PEAPI {
 
                internal void WriteTildeStream(FileImage output) 
                {
-                       long startTilde = output.Seek(0,SeekOrigin.Current);
+                       output.Seek(0,SeekOrigin.Current);
                        output.Write((uint)0); // Reserved
-#if NET_2_0 || BOOTSTRAP_NET_2_0
+#if NET_2_0
                        output.Write((byte)2); // MajorVersion
                        output.Write((byte)0); // MinorVersion
 #else
@@ -5328,13 +5348,15 @@ namespace PEAPI {
                        output.Write((byte)1); // Reserved
                        output.Write(valid);
                        output.Write(sorted);
+                       
                        for (int i=0; i < numMetaDataTables; i++) {
                                if (metaDataTables[i] != null) {
                                        uint count = (uint)metaDataTables[i].Count;
                                        output.Write(count);
                                }
                        }
-                       long tabStart = output.Seek(0,SeekOrigin.Current);
+                       
+                       output.Seek(0,SeekOrigin.Current);
                        // Console.WriteLine("Starting metaData tables at " + tabStart);
                        for (int i=0; i < numMetaDataTables; i++) {
                                if (metaDataTables[i] != null) {
@@ -5372,7 +5394,7 @@ namespace PEAPI {
                        BuildTable(metaDataTables[(int)MDTable.TypeDef]);
                        BuildTable(metaDataTables[(int)MDTable.TypeSpec]);
                        BuildTable(metaDataTables[(int)MDTable.MemberRef]);
-#if NET_2_0 || BOOTSTRAP_NET_2_0
+#if NET_2_0
                        BuildTable(metaDataTables[(int)MDTable.GenericParam]);
                        BuildTable(metaDataTables[(int)MDTable.MethodSpec]);
                        BuildTable(metaDataTables[(int)MDTable.GenericParamConstraint]);
@@ -5421,7 +5443,7 @@ namespace PEAPI {
                        SortTable(metaDataTables[(int)MDTable.DeclSecurity]);
                        SortTable(metaDataTables[(int)MDTable.MethodSemantics]);
                        SortTable(metaDataTables[(int)MDTable.ImplMap]);
-#if NET_2_0 || BOOTSTRAP_NET_2_0
+#if NET_2_0
                        if (metaDataTables[(int)MDTable.GenericParam] != null) {
                                SortTable(metaDataTables[(int)MDTable.GenericParam]);
                                // Now add GenericParamConstraints