/// <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); }
/// <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); }
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); } }
/*------------------------- 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); }
/// <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); }
/// <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); }
/// <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); }
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); } } }
/// <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; }
internal void AddToMethodList(MethodRef meth) { Contract.Requires(meth != null); defaultClass.AddToMethodList(meth); }
/// <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); }
/*------------------------- 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; }
internal void AddVarArgSig(MethodRef meth) { varArgSig = meth; //meth.MakeVarArgMethod(this,null); }
/// <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; }
/*-------------------- 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)); } }