Ejemplo n.º 1
0
        public string Finish(string indent)
        {
            string ret = "";

            for (int i = 0; i < parms.Count; i++)
            {
                if ((bool)special[i] == false)
                {
                    continue;
                }

                Parameter    p    = parms [i] as Parameter;
                IGeneratable igen = p.Generatable;

                if (igen is CallbackGen)
                {
                    continue;
                }
                else if (igen is StructBase || igen is ByRefGen)
                {
                    ret += indent + String.Format("if ({0} != IntPtr.Zero) System.Runtime.InteropServices.Marshal.StructureToPtr (my{0}, {0}, false);\n", p.Name);
                }
                else
                {
                    ret += indent + p.Name + " = " + igen.ToNativeReturn("my" + p.Name) + ";\n";
                }
            }

            return(ret);
        }
Ejemplo n.º 2
0
        public string ToNativeReturn(string c_type, string val)
        {
            IGeneratable gen = this[c_type];

            if (gen == null)
            {
                return("");
            }
            return(gen.ToNativeReturn(val));
        }
        public string GenArgsInitialization(StreamWriter sw)
        {
            if (parms.Count > 1)
            {
                sw.WriteLine("\t\t\t\targs.Args = new object[" + (parms.Count - 1) + "];");
            }
            string finish = "";

            for (int idx = 1; idx < parms.Count; idx++)
            {
                Parameter    p    = parms [idx];
                IGeneratable igen = p.Generatable;
                if (p.PassAs != "out")
                {
                    if (igen is ManualGen)
                    {
                        sw.WriteLine("\t\t\t\tif (arg{0} == IntPtr.Zero)", idx);
                        sw.WriteLine("\t\t\t\t\targs.Args[{0}] = null;", idx - 1);
                        sw.WriteLine("\t\t\t\telse {");
                        sw.WriteLine("\t\t\t\t\targs.Args[" + (idx - 1) + "] = " + p.FromNative("arg" + idx) + ";");
                        sw.WriteLine("\t\t\t\t}");
                    }
                    else
                    {
                        sw.WriteLine("\t\t\t\targs.Args[" + (idx - 1) + "] = " + p.FromNative("arg" + idx) + ";");
                    }
                }
                if (igen is StructBase && p.PassAs == "ref")
                {
                    if (SymbolTable.Table.IsBlittable(SymbolTable.Table [igen.CName]))
                    {
                        finish += "\t\t\t\tunsafe { if (arg" + idx + " != IntPtr.Zero) " + string.Format("*({0}*){1} = my{1}", p.CSType, p.Name) + "; }\n";
                    }
                    else
                    {
                        finish += "\t\t\t\tif (arg" + idx + " != IntPtr.Zero) System.Runtime.InteropServices.Marshal.StructureToPtr (args.Args[" + (idx - 1) + "], arg" + idx + ", false);\n";
                    }
                }
                else if (p.PassAs != "")
                {
                    finish += "\t\t\t\targ" + idx + " = " + igen.ToNativeReturn("((" + p.CSType + ")args.Args[" + (idx - 1) + "])") + ";\n";
                }
            }
            return(finish);
        }