示例#1
0
文件: MethodDef.cs 项目: mdae/MonoRT
        private PEAPI.Param [] GenerateParams(CodeGen code_gen)
        {
            PEAPI.Param[] param_array;

            if (param_list != null && param_list.Count > 0)
            {
                int param_count = param_list.Count;

                // Remove the last param if its the sentinel, not sure what
                // should happen with more then one sentinel
                ParamDef last = (ParamDef)param_list [param_count - 1];
                if (last.IsSentinel())
                {
                    param_count--;
                }

                param_array = new PEAPI.Param [param_count];
                for (int i = 0; i < param_count; i++)
                {
                    ParamDef paramdef = (ParamDef)param_list [i];
                    paramdef.Define(code_gen);
                    param_array [i] = paramdef.PeapiParam;
                }
            }
            else
            {
                param_array = new PEAPI.Param [0];
            }

            return(param_array);
        }
        public override void Resolve(CodeGen code_gen)
        {
            if (is_resolved)
            {
                return;
            }

            PEAPI.Type [] arg_array;
            PEAPI.Type [] opt_array;
            bool          is_vararg = false;

            if (param_list != null)
            {
                ArrayList opt_list = new ArrayList();
                ArrayList arg_list = new ArrayList();
                bool      in_opt   = false;
                int       max      = param_list.Count;

                for (int i = 0; i < max; i++)
                {
                    ParamDef param = (ParamDef)param_list [i];

                    if (param.IsSentinel())
                    {
                        is_vararg = true;
                        in_opt    = true;
                        param.Type.Resolve(code_gen);
                    }
                    else if (in_opt)
                    {
                        param.Type.Resolve(code_gen);
                        opt_list.Add(param.Type.PeapiType);
                    }
                    else
                    {
                        param.Type.Resolve(code_gen);
                        arg_list.Add(param.Type.PeapiType);
                    }
                }

                arg_array = (PEAPI.Type [])arg_list.ToArray(typeof(PEAPI.Type));
                opt_array = (PEAPI.Type [])opt_list.ToArray(typeof(PEAPI.Type));
            }
            else
            {
                arg_array = new PEAPI.Type [0];
                opt_array = new PEAPI.Type [0];
            }

            ret.Resolve(code_gen);

            type = new PEAPI.MethPtrType(callconv, ret.PeapiType, arg_array, is_vararg, opt_array);
            type = Modify(code_gen, type);

            is_resolved = true;
        }
示例#3
0
文件: MethodDef.cs 项目: mdae/MonoRT
        static string CreateVarargSignature(BaseTypeRef RetType, string name, IList param_list)
        {
            StringBuilder builder = new StringBuilder();
            ParamDef      last    = null;

            builder.Append(RetType.FullName);
            builder.Append(" ");
            builder.Append(name);
            builder.Append('(');

            bool first = true;

            if (param_list != null)
            {
                foreach (ParamDef paramdef in param_list)
                {
                    if (!first)
                    {
                        builder.Append(',');
                    }
                    builder.Append(paramdef.TypeName);
                    first = false;
                }
                last = (ParamDef)param_list[param_list.Count - 1];
            }


            if (last == null || !last.IsSentinel())
            {
                if (!first)
                {
                    builder.Append(',');
                }
                builder.Append("...");
            }

            builder.Append(')');

            return(builder.ToString());
        }