예제 #1
0
        /// <summary>
        /// Fetch a MethodRef descriptor for the method "retType name (pars)".
        /// If one exists, it is returned, else one is created.
        /// </summary>
        /// <param name="name">method name</param>
        /// <param name="retType">return type</param>
        /// <param name="pars">method parameter types</param>
        /// <returns>a descriptor for this method in anther module</returns>
        public MethodRef AddMethod(string name, Type retType, Type[] pars)
        {
            Contract.Requires(name != null);
            Contract.Requires(retType != null);
            Contract.Requires(pars != null);
            MethodRef meth = defaultClass.AddMethod(name, retType, pars);

            return(meth);
        }
예제 #2
0
        /// <summary>
        /// Make a method reference descriptor for this method to be used
        /// as a callsite signature for this vararg method
        /// </summary>
        /// <param name="optPars">the optional pars for the vararg method call</param>
        /// <returns></returns>
        public MethodRef MakeVarArgSignature(Type[] optPars)
        {
            Contract.Requires(optPars != null);
            MethSig mSig = new MethSig(name);

            mSig.parTypes = sig.parTypes;
            mSig.retType  = sig.retType;
            varArgSig     = new MethodRef(sig);
            varArgSig.MakeVarArgMethod(this, optPars);
            return(varArgSig);
        }
예제 #3
0
        internal void AddMethod(MethodRef meth)
        {
            Contract.Requires(meth != null);
            MethodRef m = (MethodRef)GetMethodDesc(meth.Name(), meth.GetParTypes());

            if (m == null)
            {
                methods.Add(meth);
                meth.SetParent(this);
            }
        }
예제 #4
0
        /*------------------------- public set and get methods --------------------------*/

        /// <summary>
        /// Add a method to this class
        /// </summary>
        /// <param name="name">method name</param>
        /// <param name="retType">return type</param>
        /// <param name="pars">parameter types</param>
        /// <returns>a descriptor for this method</returns>
        public MethodRef AddMethod(string name, Type retType, Type[] pars)
        {
            Contract.Requires(retType != null);
            MethodRef meth = (MethodRef)GetMethodDesc(name, pars);

            if (meth != null)
            {
                DescriptorError(meth);
            }
            meth = new MethodRef(this, name, retType, pars);
            methods.Add(meth);
            return(meth);
        }
예제 #5
0
        /// <summary>
        /// Add a method to this class
        /// </summary>
        /// <param name="name">method name</param>
        /// <param name="genPars">generic parameters</param>
        /// <param name="retType">return type</param>
        /// <param name="pars">parameter types</param>
        /// <returns>a descriptor for this method</returns>
        public MethodRef AddMethod(string name, GenericParam[] genPars, Type retType, Type[] pars)
        {
            MethodRef meth = AddMethod(name, retType, pars);

            if ((genPars != null) && (genPars.Length > 0))
            {
                for (int i = 0; i < genPars.Length; i++)
                {
                    genPars[i].SetMethParam(meth, i);
                }
                meth.SetGenericParams(genPars);
            }
            return(meth);
        }
예제 #6
0
        /// <summary>
        /// Makes the assembly debuggable by attaching the DebuggableAttribute
        /// to the Assembly. Call immediately before calling WritePEFile.
        /// </summary>
        /// <param name="allowDebug">set true to enable debugging, false otherwise</param>
        /// <param name="suppressOpt">set true to disable optimizations that affect debugging</param>
        public void MakeDebuggable(bool allowDebug, bool suppressOpt)
        {
            Type[]   twoBools = new Type[] { PrimitiveType.Boolean, PrimitiveType.Boolean };
            ClassRef debugRef = MSCorLib.mscorlib.GetClass("System.Diagnostics", "DebuggableAttribute");

            if (debugRef == null)
            {
                debugRef = MSCorLib.mscorlib.AddClass("System.Diagnostics", "DebuggableAttribute");
            }
            MethodRef dCtor = debugRef.GetMethod(".ctor", twoBools);

            if (dCtor == null)
            {
                dCtor = debugRef.AddMethod(".ctor", PrimitiveType.Void, twoBools);
                dCtor.AddCallConv(CallConv.Instance);
            }
            Constant[] dbgArgs = new Constant[] { new BoolConst(allowDebug), new BoolConst(suppressOpt) };
            thisAssembly.AddCustomAttribute(dCtor, dbgArgs);
        }
예제 #7
0
        /// <summary>
        /// Get the MethodRef equivalent to this MethodDef.  If one
        /// does not exist, then create it.
        /// </summary>
        /// <returns>MethodRef for this MethodDef</returns>
        public MethodRef MakeRefOf()
        {
            if (refOf != null)
            {
                return(refOf);
            }
            ClassRef parRef = ((ClassDef)parent).MakeRefOf();

            refOf = parRef.GetMethod(name, sig.parTypes);
            if (refOf == null)
            {
                Type   rType  = sig.MakeRefRetType();
                Type[] pTypes = sig.MakeRefParTypes();
                refOf       = new MethodRef(parRef, name, rType, pTypes);
                refOf.defOf = this;
                refOf.AddCallConv(this.GetCallConv());
            }
            return(refOf);
        }
예제 #8
0
 internal static void GetMethodRefs(PEReader buff, uint num, ClassRef parent)
 {
     for (int i = 0; i < num; i++)
     {
         uint   rva       = buff.ReadUInt32();
         ushort implFlags = buff.ReadUInt16();
         ushort methFlags = buff.ReadUInt16();
         string name      = buff.GetString();
         uint   sigIx     = buff.GetBlobIx();
         uint   parIx     = buff.GetIndex(MDTable.Param);
         if (IsPublicOrProtected(methFlags))
         {
             MethodRef mRef = new MethodRef(parIx, name, sigIx);  // changed
             mRef.SetParent(parent);
             //Console.WriteLine(parent.NameString());
             MethSig mSig = buff.ReadMethSig(mRef, name, sigIx);
             //mSig.name = name;
             mRef.SetSig(mSig); // changed
             parent.AddToMethodList(mRef);
         }
     }
 }
예제 #9
0
 /// <summary>
 /// Get the MethodRef equivalent to this MethodDef.  If one
 /// does not exist, then create it.
 /// </summary>
 /// <returns>MethodRef for this MethodDef</returns>
 public MethodRef MakeRefOf()
 {
     if (refOf != null) return refOf;
     ClassRef parRef = ((ClassDef)parent).MakeRefOf();
     refOf = parRef.GetMethod(name, sig.parTypes);
     if (refOf == null)
     {
         Type rType = sig.MakeRefRetType();
         Type[] pTypes = sig.MakeRefParTypes();
         refOf = new MethodRef(parRef, name, rType, pTypes);
         refOf.defOf = this;
         refOf.AddCallConv(this.GetCallConv());
     }
     return refOf;
 }
예제 #10
0
 internal void AddToMethodList(MethodRef meth)
 {
     Contract.Requires(meth != null);
     defaultClass.AddToMethodList(meth);
 }
예제 #11
0
 /// <summary>
 /// Delete a method from this scope.
 /// </summary>
 /// <param name="meth">The method to be deleted.</param>
 public void RemoveMethod(MethodRef meth)
 {
     Contract.Requires(meth != null);
     defaultClass.RemoveMethod(meth);
 }
예제 #12
0
 /*------------------------- public set and get methods --------------------------*/
 /// <summary>
 /// Add a method to this class
 /// </summary>
 /// <param name="name">method name</param>
 /// <param name="retType">return type</param>
 /// <param name="pars">parameter types</param>
 /// <returns>a descriptor for this method</returns>
 public MethodRef AddMethod(string name, Type retType, Type[] pars)
 {
     Contract.Requires(retType != null);
     MethodRef meth = (MethodRef)GetMethodDesc(name, pars);
     if (meth != null) DescriptorError(meth);
     meth = new MethodRef(this, name, retType, pars);
     methods.Add(meth);
     return meth;
 }
예제 #13
0
 internal void AddVarArgSig(MethodRef meth)
 {
     varArgSig = meth;
     //meth.MakeVarArgMethod(this,null);
 }
예제 #14
0
 /// <summary>
 /// Delete a method from this scope.
 /// </summary>
 /// <param name="meth">The method to be deleted.</param>
 public void RemoveMethod(MethodRef meth)
 {
     Contract.Requires(meth != null);
     defaultClass.RemoveMethod(meth);
 }
예제 #15
0
 internal void AddVarArgSig(MethodRef meth)
 {
     varArgSig = meth;
     //meth.MakeVarArgMethod(this,null);
 }
예제 #16
0
 /// <summary>
 /// Make a method reference descriptor for this method to be used 
 /// as a callsite signature for this vararg method
 /// </summary>
 /// <param name="optPars">the optional pars for the vararg method call</param>
 /// <returns></returns>
 public MethodRef MakeVarArgSignature(Type[] optPars)
 {
     Contract.Requires(optPars != null);
     MethSig mSig = new MethSig(name);
     mSig.parTypes = sig.parTypes;
     mSig.retType = sig.retType;
     varArgSig = new MethodRef(sig);
     varArgSig.MakeVarArgMethod(this, optPars);
     return varArgSig;
 }
예제 #17
0
 internal static void GetMethodRefs(PEReader buff, uint num, ClassRef parent)
 {
     for (int i = 0; i < num; i++)
     {
         uint rva = buff.ReadUInt32();
         ushort implFlags = buff.ReadUInt16();
         ushort methFlags = buff.ReadUInt16();
         string name = buff.GetString();
         uint sigIx = buff.GetBlobIx();
         uint parIx = buff.GetIndex(MDTable.Param);
         if (IsPublicOrProtected(methFlags))
         {
             MethodRef mRef = new MethodRef(parIx, name, sigIx);  // changed
             mRef.SetParent(parent);
             //Console.WriteLine(parent.NameString());
             MethSig mSig = buff.ReadMethSig(mRef, name, sigIx);
             //mSig.name = name;
             mRef.SetSig(mSig); // changed
             parent.AddToMethodList(mRef);
         }
     }
 }
예제 #18
0
 internal void AddToMethodList(MethodRef meth)
 {
     Contract.Requires(meth != null);
     defaultClass.AddToMethodList(meth);
 }
예제 #19
0
 /*-------------------- Constructors ---------------------------------*/
 internal ClassSpec(Class clType, Type[] gPars)
 {
     Contract.Requires(clType != null);
     Contract.Requires(gPars != null);
     this.typeIndex = GENERICINST;
     genClass = clType;
     genericParams = new ArrayList(gPars);
     tabIx = MDTable.TypeSpec;
     typeIndex = GENERICINST;
     ArrayList classMethods = clType.GetMethodList();
     ArrayList classFields = clType.GetFieldList();
     for (int i = 0; i < classMethods.Count; i++)
     {
         MethSig mSig = ((Method)classMethods[i]).GetSig(); //.InstantiateGenTypes(this,gPars);
         if (mSig != null)
         {
             MethodRef newMeth = new MethodRef(mSig);
             newMeth.SetParent(this);
             newMeth.GenericParams = ((Method)classMethods[i]).GenericParams;
             methods.Add(newMeth);
         }
     }
     for (int i = 0; i < classFields.Count; i++)
     {
         Type fType = ((Field)classFields[i]).GetFieldType();
         fields.Add(new FieldRef(this, ((Field)classFields[i]).Name(), fType));
     }
 }
예제 #20
0
 internal void AddMethod(MethodRef meth)
 {
     Contract.Requires(meth != null);
     MethodRef m = (MethodRef)GetMethodDesc(meth.Name(), meth.GetParTypes());
     if (m == null)
     {
         methods.Add(meth);
         meth.SetParent(this);
     }
 }