Beispiel #1
0
        /// <summary>
        /// Add a "global" method to this module
        /// </summary>
        /// <param name="mAtts">method attributes</param>
        /// <param name="iAtts">method implementation attributes</param>
        /// <param name="name">method name</param>
        /// <param name="genPars">generic parameters</param>
        /// <param name="retType">return type</param>
        /// <param name="pars">method parameters</param>
        /// <returns>a descriptor for this new "global" method</returns>
        public MethodDef AddMethod(MethAttr mAtts, ImplAttr iAtts, string name, GenericParam[] genPars, Type retType, Param[] pars)
        {
            //FIXME Contract.Requires(defaultClass != null);
            MethodDef newMeth = defaultClass.AddMethod(mAtts, iAtts, name, genPars, retType, pars);

            return(newMeth);
        }
Beispiel #2
0
        public MethodDef AddDefinition(MethAttr method_attr, ImplAttr impl_attr, CallConv call_conv,
                                       string name, TypeRef return_type, Param[] param_list,
                                       TypeRef[] param_type_list, Location location)
        {
            string signature = GetSignature(name, return_type, param_type_list);

            if (MethodDefinedEvent != null)
            {
                MethodDefinedEvent(this, new MethodDefinedEventArgs(signature, name,
                                                                    return_type, param_list, table.Contains(signature), method_attr,
                                                                    impl_attr, call_conv));
            }

            MethodTableItem item = (MethodTableItem)table[signature];

            if (item == null)
            {
                MethodDef method = parent_class.AddMethod(method_attr, impl_attr, name,
                                                          return_type.Type, param_list);
                method.AddCallConv(call_conv);
                AddDefined(signature, method, location);
                return(method);
            }

            item.Method.AddMethAttribute(method_attr);
            item.Method.AddImplAttribute(impl_attr);
            item.Method.AddCallConv(call_conv);
            item.Defined = true;

            return(item.Method);
        }
Beispiel #3
0
 public MethodDefinedEventArgs(string signature, string name,
                               TypeRef return_type, Param[] param_list, bool is_in_table, MethAttr method_attr,
                               ImplAttr impl_attr, CallConv call_conv) : base(signature, name,
                                                                              return_type, param_list, is_in_table)
 {
     MethodAttributes = method_attr;
     ImplAttributes   = impl_attr;
     CallConv         = call_conv;
 }
Beispiel #4
0
		public MethodDefinedEventArgs (string signature, string name, 
			TypeRef return_type, Param[] param_list, bool is_in_table, MethAttr method_attr, 
			ImplAttr impl_attr, CallConv call_conv) : base (signature, name, 
			return_type, param_list, is_in_table)
		{
			MethodAttributes = method_attr;
			ImplAttributes = impl_attr;
			CallConv = call_conv;
		}
Beispiel #5
0
        /// <summary>
        /// Define a new method to emit for the current class.
        /// </summary>
        public CILInstructions emitMethod(
            string name, string retType, string[] paramNames, string[] paramTypes,
            MethAttr attr, string[] localNames, string[] localTypes)
        {
            Param[] pars = new Param[paramNames.Length];
            for (int i = 0; i < pars.Length; i++)
            {
                pars[i] = new Param(ParamAttr.Default, paramNames[i], findType(paramTypes[i]));
            }

            // first check if this method was already stubbed out
            methodDef = (MethodDef)methods[getMethodKey(className, name, paramTypes)];
            if (methodDef == null)
            {
                // if not, we need to create it
                methodDef = classDef.AddMethod(attr, ImplAttr.IL, name, findType(retType), pars);
            }
            else
            {
                // if stubbed out, make sure we define the method correctly
                methodDef.SetMethAttributes(attr);
            }

            if ((attr & MethAttr.Static) != MethAttr.Static)
            {
                methodDef.AddCallConv(CallConv.Instance);
            }

            if (localNames.Length > 0)
            {
                Local[] locals = new Local[localNames.Length];
                for (int i = 0; i < locals.Length; i++)
                {
                    locals[i] = new Local(localNames[i], findType(localTypes[i]));
                }
                methodDef.AddLocals(locals, true);
            }

            // TODO - what the f**k should this be?
            methodDef.SetMaxStack(16 + pars.Length + localNames.Length);

            // add to lookup table
            addToMethodMap(className, name, paramTypes, methodDef);

            // don't create code buffer if abstract
            if ((attr & MethAttr.Abstract) == MethAttr.Abstract)
            {
                return(null);
            }

            return(methodDef.CreateCodeBuffer());
        }
Beispiel #6
0
 internal MethodDef(MetaData md, MethAttr mAttrSet, ImplAttr iAttrSet, string name, Type retType, Param[] pars) : base(name,retType) {
   metaData = md;
                     parList = pars;
                     if (parList != null) numPars = parList.Length;
   // Console.WriteLine("Creating method " + name + " with " + numPars + " parameters");
                     methFlags = (ushort)mAttrSet;
   implFlags = (ushort)iAttrSet;
   tabIx = MDTable.Method;
 }
		public MethodDef AddMethod(MethAttr mAtts, ImplAttr iAtts, string name, Type retType, Param[] pars) 
		{
			return AddMethod (mAtts, iAtts, name, new Param (ParamAttr.Default, "", retType), pars);
		}
Beispiel #8
0
 /// <summary>
 /// Add a method to this class
 /// </summary>
 /// <param name="mAtts">attributes for this method</param>
 /// <param name="iAtts">implementation attributes for this method</param>
 /// <param name="name">method name</param>
 /// <param name="genPars">generic parameters</param>
 /// <param name="retType">return type</param>
 /// <param name="pars">parameters</param>
 /// <returns>a descriptor for this new method</returns>
 public MethodDef AddMethod(MethAttr mAtts, ImplAttr iAtts, string name,
     GenericParam[] genPars, Type retType, Param[] pars)
 {
     Contract.Requires(name != null);
     Contract.Requires(genPars != null);
     Contract.Requires(retType != null);
     Contract.Requires(pars != null);
     MethodDef meth = AddMethod(name, genPars, retType, pars);
     meth.AddMethAttribute(mAtts);
     meth.AddImplAttribute(iAtts);
     return meth;
 }
Beispiel #9
0
 /// <summary>
 /// Add a "global" method to this module
 /// </summary>
 /// <param name="mAtts">method attributes</param>
 /// <param name="iAtts">method implementation attributes</param>
 /// <param name="name">method name</param>
 /// <param name="genPars">generic parameters</param>
 /// <param name="retType">return type</param>
 /// <param name="pars">method parameters</param>
 /// <returns>a descriptor for this new "global" method</returns>
 public MethodDef AddMethod(MethAttr mAtts, ImplAttr iAtts, string name, GenericParam[] genPars, Type retType, Param[] pars)
 {
     //FIXME Contract.Requires(defaultClass != null);
     MethodDef newMeth = defaultClass.AddMethod(mAtts, iAtts, name, genPars, retType, pars);
     return newMeth;
 }
Beispiel #10
0
 public void SetMethAttributes(MethAttr ma)
 {
     methFlags = (ushort)ma;
 }
Beispiel #11
0
 /// <summary>
 /// Add a method to this class
 /// </summary>
 /// <param name="mAtts">attributes for this method</param>
 /// <param name="iAtts">implementation attributes for this method</param>
 /// <param name="name">method name</param>
 /// <param name="genPars">generic parameters</param>
 /// <param name="retType">return type</param>
 /// <param name="pars">parameters</param>
 /// <returns>a descriptor for this new method</returns>
 public MethodDef AddMethod(MethAttr mAtts, ImplAttr iAtts, string name,
     GenericParam[] genPars, Type retType, Param[] pars)
 {
     MethodDef meth = AddMethod(name,genPars,retType,pars);
     meth.AddMethAttribute(mAtts);
     meth.AddImplAttribute(iAtts);
     return meth;
 }
Beispiel #12
0
 /// <summary>
 /// Add some attributes to this method descriptor
 /// </summary>
 /// <param name="ma">the attributes to be added</param>
 public void AddMethAttribute(MethAttr ma)
 {
     methFlags |= (ushort)ma;
 }
		internal MethodDef (MetaData md, MethAttr mAttrSet, ImplAttr iAttrSet, string name, 
				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;
		}
Beispiel #14
0
 /// <summary>
 /// Add a "global" method to this module
 /// </summary>
 /// <param name="mAtts">method attributes</param>
 /// <param name="iAtts">method implementation attributes</param>
 /// <param name="name">method name</param>
 /// <param name="retType">return type</param>
 /// <param name="pars">method parameters</param>
 /// <returns>a descriptor for this new "global" method</returns>
 public MethodDef AddMethod(MethAttr mAtts, ImplAttr iAtts, string name, Type retType, Param[] pars) {
   return moduleClass.AddMethod(mAtts,iAtts,name,retType,pars);
 }
Beispiel #15
0
		public MethodDef AddDefinition (MethAttr method_attr, ImplAttr impl_attr, CallConv call_conv, 
			string name, TypeRef return_type, Param[] param_list, 
			TypeRef[] param_type_list, Location location) 
		{
			string signature = GetSignature (name, return_type, param_type_list);

			if (MethodDefinedEvent != null)
				MethodDefinedEvent (this, new MethodDefinedEventArgs (signature, name,
					return_type, param_list, table.Contains (signature), method_attr, 
					impl_attr, call_conv));

			MethodTableItem item = (MethodTableItem) table[signature];
			
			if (item == null) {
				MethodDef method = parent_class.AddMethod (method_attr, impl_attr, name, 
					return_type.Type, param_list);
				method.AddCallConv (call_conv);
				AddDefined (signature, method, location);
				return method;
			}
			
			item.Method.AddMethAttribute (method_attr);
			item.Method.AddImplAttribute (impl_attr);
			item.Method.AddCallConv (call_conv);
			item.Defined = true;
		
			return item.Method;
		}
Beispiel #16
0
 public void SetMethAttributes(MethAttr ma)
 {
     methFlags = (ushort)ma;
 }
Beispiel #17
0
        /// <summary>
        /// Define a new method to emit for the current class.
        /// </summary>
        public CILInstructions emitMethod(
      string name, string retType, string[] paramNames, string[] paramTypes,
      MethAttr attr, string[] localNames, string[] localTypes)
        {
            Param[] pars = new Param[paramNames.Length];
              for (int i=0; i<pars.Length; i++)
            pars[i] = new Param(ParamAttr.Default, paramNames[i], findType(paramTypes[i]));

              // first check if this method was already stubbed out
              methodDef = (MethodDef)methods[getMethodKey(className, name, paramTypes)];
              if (methodDef == null)
              {
            // if not, we need to create it
            methodDef = classDef.AddMethod(attr, ImplAttr.IL, name, findType(retType), pars);
              }
              else
              {
            // if stubbed out, make sure we define the method correctly
            methodDef.SetMethAttributes(attr);
              }

              if ((attr & MethAttr.Static) != MethAttr.Static)
            methodDef.AddCallConv(CallConv.Instance);

              if (localNames.Length > 0)
              {
            Local[] locals = new Local[localNames.Length];
            for (int i=0; i<locals.Length; i++)
              locals[i] = new Local(localNames[i], findType(localTypes[i]));
            methodDef.AddLocals(locals, true);
              }

              // TODO - what the f**k should this be?
              methodDef.SetMaxStack(16 + pars.Length + localNames.Length);

              // add to lookup table
              addToMethodMap(className, name, paramTypes, methodDef);

              // don't create code buffer if abstract
              if ((attr & MethAttr.Abstract) == MethAttr.Abstract)
            return null;

              return methodDef.CreateCodeBuffer();
        }
		/// <summary>
		/// Add a method to this class
		/// </summary>
		/// <param name="mAtts">attributes for this method</param>
		/// <param name="iAtts">implementation attributes for this method</param>
		/// <param name="name">method name</param>
		/// <param name="retType">return type</param>
		/// <param name="pars">parameters</param>
		/// <returns>a descriptor for this new method</returns>
		public MethodDef AddMethod(MethAttr mAtts, ImplAttr iAtts, string name, 
				Param ret_param, Param [] pars) {
			// Console.WriteLine("Adding method " + name + " to class " + this.name);
			MethodDef meth = new MethodDef (metaData, mAtts, iAtts, name, ret_param, pars);
			methods.Add(meth);
			return meth;
		}
Beispiel #19
0
 /// <summary>
 /// Add a "global" method to this module
 /// </summary>
 /// <param name="mAtts">method attributes</param>
 /// <param name="iAtts">method implementation attributes</param>
 /// <param name="name">method name</param>
 /// <param name="genPars">generic parameters</param>
 /// <param name="retType">return type</param>
 /// <param name="pars">method parameters</param>
 /// <returns>a descriptor for this new "global" method</returns>
 public MethodDef AddMethod(MethAttr mAtts, ImplAttr iAtts, string name, GenericParam[] genPars, Type retType, Param[] pars)
 {
     MethodDef newMeth = defaultClass.AddMethod(mAtts,iAtts,name,genPars,retType,pars);
     return newMeth;
 }
		/// <summary>
		/// Add some attributes to this method descriptor
		/// </summary>
		/// <param name="ma">the attributes to be added</param>
		public void AddMethAttribute(MethAttr ma) 
		{
			methFlags |= (ushort)ma;
		}
        internal CodeGenContext CreateMethod(ClassDef ParentClass, MethAttr attr, string name, PERWAPI.Type return_type, params Param[] parameters) {
            CodeGenContext newContext = new CodeGenContext(this);

            newContext.Method = ParentClass.AddMethod(attr, ImplAttr.IL, name, return_type, parameters);

            if ((attr & MethAttr.Static) == 0)
                newContext.Method.AddCallConv(CallConv.Instance);

            newContext.CLRLocals = new List<Local>();

            newContext.Method.CreateCodeBuffer();

            newContext.buffer.OpenScope();

            return newContext;
        }