Beispiel #1
0
        public static void CreateConstCS()
        {
            StreamWriter sw = File.CreateText(VKxmlParser.GetDestination() + "VKConst.cs");

            sw.WriteLine("// Document Created with VulkanParser.");
            sw.WriteLine("//       " + DateTime.Now.ToString("HH:mm:ss dd/mm/yyyy"));
            sw.WriteLine("// by BROTHERHOOD OF THE BLACK SWORD.");
            sw.WriteLine();
            sw.WriteLine("using System;");
            sw.WriteLine();
            sw.WriteLine("namespace " + VKxmlParser.GetNamespace());
            sw.WriteLine("{");


            sw.WriteLine("\t" + "public static class VKConst");
            sw.WriteLine("\t" + "{");
            //for (int i=0;APIConstantsParser.ConstValues.Count;i++)
            foreach (string key in APIConstantsParser.ConstValues.Keys)
            {
                string dv    = APIConstantsParser.ConstValues[key];
                string tpv   = TypeValor(dv);
                string valor = TransValor(dv);

                sw.WriteLine("\t" + "\t" + "public const " + tpv + " " + key + " = " + valor + ";");//tab
            }

            sw.WriteLine("\t}");

            sw.WriteLine("}");
            sw.WriteLine();
            sw.Close();
        }
Beispiel #2
0
        public static void CreateIntPtrsCS()
        {
            StreamWriter sw = File.CreateText(VKxmlParser.GetDestination() + "VKIntPtrs.cs");

            sw.WriteLine("// Document Created with VulkanParser.");
            sw.WriteLine("//       " + DateTime.Now.ToString("HH:mm:ss dd/mm/yyyy"));
            sw.WriteLine("// by BROTHERHOOD OF THE BLACK SWORD.");
            sw.WriteLine();
            sw.WriteLine("using System;");
            sw.WriteLine();
            sw.WriteLine("namespace " + VKxmlParser.GetNamespace());
            sw.WriteLine("{");

            //MEOLLO
            for (int i = 0; i < IntPtrsParser.IntPtrs.Count; i++)       //IntPtrs
            {
                sw.WriteLine("\t" + "using " + IntPtrsParser.IntPtrs[i] + " = IntPtr;");
            }

            sw.WriteLine();
            for (int i = 0; i < HandleParser.handleTypes.Count; i++)       //handles
            {
                sw.WriteLine("\t" + "using " + HandleParser.handleTypes[i] + " = IntPtr;");
            }

            sw.WriteLine("}");
            sw.WriteLine();
            sw.Close();
        }
Beispiel #3
0
        public static void CreateMethodsDCS()
        {
            foreach (string key in VersionParser.d_commandsbyversion.Keys)             //por versiones
            {
                if (!Directory.Exists(VKxmlParser.GetDestination() + "/Internals"))
                {
                    Directory.CreateDirectory(VKxmlParser.GetDestination() + "/Internals");
                }
                StreamWriter sw = File.CreateText(VKxmlParser.GetDestination() + "/Internals/" + "Vulkan" + key.Replace(".", "") + "d.cs");
                sw.WriteLine("// Document Created with VulkanParser.");
                sw.WriteLine("//       " + DateTime.Now.ToString("HH:mm:ss dd/mm/yyyy"));
                sw.WriteLine("// by BROTHERHOOD OF THE BLACK SWORD.");
                sw.WriteLine();
                sw.WriteLine("namespace " + VKxmlParser.GetNamespace());
                sw.WriteLine("{");

                sw.WriteLine("\t" + "internal static class VK" + key.Replace(".", "") + "Delegates");           //Agrupar metodos en clase internal dentro de namespace de version
                sw.WriteLine("\t" + "{");

                foreach (string keygroups in VersionParser.d_commandsbyversion[key].grupocomandos.Keys)                //por grupos
                {
                    List <string> listametodos = VersionParser.d_commandsbyversion[key].grupocomandos[keygroups];

                    for (int i = 0; i < listametodos.Count; i++)
                    {
                        Metodo mtd     = CommandParser.Metodos[listametodos[i]];                            //Rescatar metodo del CommandParser
                        string smetodo = "internal delegate " + mtd.ValueReturned + " " + mtd.Nombre + "("; //confecionar string de metodo
                        foreach (string keyParams in mtd.Parametros.Keys)                                   //Añadir Parametyros del método
                        {
                            Parametro param = mtd.Parametros[keyParams];
                            if (param.constante)
                            {
                                smetodo += "const ";
                            }
                            string stipovalor = param.TipoValor;
                            if (param.puntero)
                            {
                                stipovalor += "*";
                            }
                            string svalorfinparam = Tools.VariableType(stipovalor);
                            smetodo += svalorfinparam + " " + param.Nombre + ", ";
                        }
                        smetodo = smetodo.Remove(smetodo.Length - 2, 2) + ");";  //quitar comay espacio tras último parametro y cerrar parentesis.
                        sw.WriteLine("\t" + "\t" + smetodo);                     //escribir enunciado de metodo.
                        sw.WriteLine();
                    }

                    //sw.WriteLine();
                }

                sw.WriteLine("\t" + "}");
                sw.WriteLine("}");
                sw.WriteLine();
                sw.Close();
            }
        }
Beispiel #4
0
        public static void VKDelegatorMake()
        {
            StreamWriter sw = File.CreateText(VKxmlParser.GetDestination() + "VKDelegatesTools.cs"); // + key.Replace(".", "") + ".cs");

            sw.WriteLine("// Document Created with VulkanParser.");
            sw.WriteLine("//       " + DateTime.Now.ToString("HH:mm:ss dd/mm/yyyy"));
            sw.WriteLine("// by BROTHERHOOD OF THE BLACK SWORD.");
            sw.WriteLine();
            sw.WriteLine("using System;");
            sw.WriteLine("using System.Runtime.InteropServices;");
            sw.WriteLine("using " + VKxmlParser.GetNamespace() + ";");
            sw.WriteLine();
            sw.WriteLine("namespace " + VKxmlParser.GetNamespace());
            sw.WriteLine("{");

            sw.WriteLine("\t" + "internal static class VKDelegator");
            sw.WriteLine("\t" + "{");
            sw.WriteLine("\t" + "\t" + "internal static void InitDelegatesVK(VKDevice vkdevice)");
            sw.WriteLine("\t" + "\t" + "{");
            sw.WriteLine("\t" + "\t" + "\t" + "IntPtr ptr_mehod;");
            foreach (string key in VersionParser.d_commandsbyversion.Keys)                              //por versiones
            {
                foreach (string keygroups in VersionParser.d_commandsbyversion[key].grupocomandos.Keys) //por grupos
                {
                    string        s_grupo      = keygroups.Split(new string[] { " (" }, StringSplitOptions.RemoveEmptyEntries)[0].Replace(" ", "_");
                    string        sp_grupo     = char.ToUpper(s_grupo[0]) + s_grupo.Substring(1);
                    List <string> listametodos = VersionParser.d_commandsbyversion[key].grupocomandos[keygroups];
                    for (int i = 0; i < listametodos.Count; i++)             //Recorrer Metodos
                    {
                        Metodo mtd = CommandParser.Metodos[listametodos[i]]; //Rescatar metodo del CommandParser

                        sw.WriteLine("\t" + "\t" + "\t" + "ptr_mehod = GetVKMethodAdress(vkdevice, \"" + mtd.Nombre + "\");");
                        sw.WriteLine("\t" + "\t" + "\t" + "if (ptr_mehod != IntPtr.Zero)");
                        sw.WriteLine("\t" + "\t" + "\t" + "{");
                        string s_metodo = "";
                        s_metodo = "vkdevice.VK" + key.Replace(".", "") + "." + sp_grupo + ".p_" + mtd.Nombre + " = (" + VKxmlParser.GetNamespace() + ".VKDelegates.VK" + key.Replace(".", "") + "." + sp_grupo + "." + mtd.Nombre + ")";

                        s_metodo += "Marshal.GetDelegateForFunctionPointer<" + VKxmlParser.GetNamespace() + ".VKDelegates.VK" + key.Replace(".", "") + "." + sp_grupo + "." + mtd.Nombre + " >(ptr_mehod);";
                        sw.WriteLine("\t" + "\t" + "\t" + "\t" + s_metodo); //Escribir Fila De Declaracion de delegado.
                        sw.WriteLine("\t" + "\t" + "\t" + "}");
                    }
                }
                sw.WriteLine();
            }

            sw.WriteLine("\t" + "\t" + "}");

            GetAdress(sw); //Escribit metodo de obtención de direccion de metodo.

            sw.WriteLine("\t" + "}");
            sw.WriteLine("}");
            sw.WriteLine();
            sw.Close();
        }
Beispiel #5
0
 public static void GetAdress(StreamWriter sw)
 {
     sw.WriteLine("\t" + "\t" + "public static unsafe IntPtr GetVKMethodAdress(VKDevice vkdevice, string metodo)");
     sw.WriteLine("\t" + "\t" + "{");
     sw.WriteLine("\t" + "\t" + "\t" + "IntPtr p_ret = IntPtr.Zero;");
     sw.WriteLine("\t" + "\t" + "\t" + "p_ret = " + VKxmlParser.GetNamespace() + ".VK10.Device_initialization.vkGetDeviceProcAddr(vkdevice.Handle, metodo);");
     sw.WriteLine("#if DEBUG");
     sw.WriteLine("\t" + "\t" + "\t" + "if (p_ret != IntPtr.Zero){ Console.WriteLine(metodo);}");
     sw.WriteLine("#endif");
     sw.WriteLine("\t" + "\t" + "\t" + "return p_ret;");
     sw.WriteLine("\t" + "\t" + "}");
 }
Beispiel #6
0
        public static void CreateUnionCS()
        {
            StreamWriter sw = File.CreateText(VKxmlParser.GetDestination() + "VKUnions.cs");

            sw.WriteLine("// Document Created with VulkanParser.");
            sw.WriteLine("//       " + DateTime.Now.ToString("HH:mm:ss dd/mm/yyyy"));
            sw.WriteLine("// by BROTHERHOOD OF THE BLACK SWORD.");
            sw.WriteLine();
            sw.WriteLine("using System;");
            sw.WriteLine("using System.Runtime.InteropServices;");
            sw.WriteLine();
            sw.WriteLine("namespace " + VKxmlParser.GetNamespace());
            sw.WriteLine("{");

            foreach (string key in UnionParser.unions.Keys)             //ESTRUCTURAS
            {
                sw.WriteLine("\t" + "[StructLayout(LayoutKind.Explicit)]");
                sw.WriteLine("\t" + "public unsafe struct " + key);
                sw.WriteLine("\t" + "{");

                //bool first = true;
                //int cant = 0;
                foreach (string key2 in UnionParser.unions[key].members.Keys)                 //VALORES DE LA ESTRUCTURA
                {
                    sw.WriteLine("\t\t" + "[FieldOffset(0)]");
                    unionmembers unm0 = UnionParser.unions[key].members[key2];
                    if (unm0.cant.Length > 0)
                    {
                        sw.WriteLine("\t\t" + "public fixed " + Tools.VariableType(unm0.Type) + "\t" + unm0.name + "[" + unm0.cant + "];");
                    }
                    else
                    {
                        sw.WriteLine("\t\t" + "public " + Tools.VariableType(unm0.Type) + "\t" + unm0.name + ";");
                    }
                }

                sw.WriteLine("\t" + "}");
            }

            sw.WriteLine("}");
            sw.WriteLine();
            sw.Close();
        }
Beispiel #7
0
        public static void CreateMethodsICS()
        {
            foreach (string key in VersionParser.d_commandsbyversion.Keys)             //por versiones
            {
                if (!Directory.Exists(VKxmlParser.GetDestination() + "/Internals"))
                {
                    Directory.CreateDirectory(VKxmlParser.GetDestination() + "/Internals");
                }
                StreamWriter sw = File.CreateText(VKxmlParser.GetDestination() + "/Internals/" + "Vulkan" + key.Replace(".", "") + "i.cs");
                sw.WriteLine("// Document Created with VulkanParser.");
                sw.WriteLine("//       " + DateTime.Now.ToString("HH:mm:ss dd/mm/yyyy"));
                sw.WriteLine("// by BROTHERHOOD OF THE BLACK SWORD.");
                sw.WriteLine();
                sw.WriteLine("using System;");
                sw.WriteLine();
                sw.WriteLine("namespace " + VKxmlParser.GetNamespace());
                sw.WriteLine("{");

                sw.WriteLine("\t" + "internal static class VK" + key.Replace(".", "") + "Internals");           //Agrupar metodos en clase internal dentro de namespace de version
                sw.WriteLine("\t" + "{");

                foreach (string keygroups in VersionParser.d_commandsbyversion[key].grupocomandos.Keys)                //por grupos
                {
                    List <string> listametodos = VersionParser.d_commandsbyversion[key].grupocomandos[keygroups];

                    for (int i = 0; i < listametodos.Count; i++)
                    {
                        Metodo mtd     = CommandParser.Metodos[listametodos[i]];                                                           //Rescatar metodo del CommandParser
                        string smetodo = "internal static VK" + key.Replace(".", "") + "Delegates." + mtd.Nombre + " " + mtd.Nombre + ";"; //confecionar string de metodo
                        sw.WriteLine("\t" + "\t" + smetodo);                                                                               //escribir enunciado de metodo.
                        sw.WriteLine();
                    }

                    //sw.WriteLine();
                }

                sw.WriteLine("\t" + "}");
                sw.WriteLine("}");
                sw.WriteLine();
                sw.Close();
            }
        }
Beispiel #8
0
        public static void VKDeviceMake()
        {
            StreamWriter sw = File.CreateText(VKxmlParser.GetDestination() + "VKDevice.cs"); // + key.Replace(".", "") + ".cs");

            sw.WriteLine("// Document Created with VulkanParser.");
            sw.WriteLine("//       " + DateTime.Now.ToString("HH:mm:ss dd/mm/yyyy"));
            sw.WriteLine("// by BROTHERHOOD OF THE BLACK SWORD.");
            sw.WriteLine();
            sw.WriteLine("using System;");
            sw.WriteLine("using System.Runtime.InteropServices;");
            sw.WriteLine("using " + VKxmlParser.GetNamespace() + ";");
            sw.WriteLine();
            sw.WriteLine("namespace " + VKxmlParser.GetNamespace());
            sw.WriteLine("{");
            sw.WriteLine("\t" + "public class VKDevice");
            sw.WriteLine("\t" + "{");
            sw.WriteLine("\t" + "\t" + "private IntPtr ip_handle;");
            sw.WriteLine("\t" + "\t" + "public VKDevice(IntPtr handle)");
            sw.WriteLine("\t" + "\t" + "{");
            sw.WriteLine("\t" + "\t" + "\t" + "this.ip_handle = handle;");
            foreach (string key in VersionParser.d_commandsbyversion.Keys)             //por versiones
            {
                sw.WriteLine("\t" + "\t" + "\t" + "this.VK" + key.Replace(".", "") + " = new vk" + key.Replace(".", "") + "();");
            }
            sw.WriteLine("\t" + "\t" + "\t" + VKxmlParser.GetNamespace() + ".VKDelegator.InitDelegatesVK(this);");
            sw.WriteLine("\t" + "\t" + "}");
            sw.WriteLine();

            #region handle:
            sw.WriteLine("\t" + "\t" + "public IntPtr Handle");
            sw.WriteLine("\t" + "\t" + "{");
            sw.WriteLine("\t" + "\t" + "\t" + "get { return this.ip_handle; }");
            sw.WriteLine("\t" + "\t" + "}");
            sw.WriteLine();
            #endregion

            CreateBaseMethods(sw);

            sw.WriteLine("\t" + "}");
            sw.WriteLine("}");
            sw.Close();
        }
Beispiel #9
0
        public static void VKDelegatesMake()
        {
            StreamWriter sw = File.CreateText(VKxmlParser.GetDestination() + "VKDelegates.cs"); // + key.Replace(".", "") + ".cs");

            sw.WriteLine("// Document Created with VulkanParser.");
            sw.WriteLine("//       " + DateTime.Now.ToString("HH:mm:ss dd/mm/yyyy"));
            sw.WriteLine("// by BROTHERHOOD OF THE BLACK SWORD.");
            sw.WriteLine();
            sw.WriteLine("using System;");
            sw.WriteLine("using System.Runtime.InteropServices;");
            sw.WriteLine("using " + VKxmlParser.GetNamespace() + ";");
            sw.WriteLine();
            sw.WriteLine("namespace " + VKxmlParser.GetNamespace());
            sw.WriteLine("{");

            sw.WriteLine("\t" + "internal static class VKDelegates"); //ABRIR CLASE
            sw.WriteLine("\t" + "{");

            CreateBaseMethods(sw);

            sw.WriteLine("\t" + "}"); //CERRAR CLASE
            sw.WriteLine("}");
            sw.Close();
        }
Beispiel #10
0
        public static void CreateEnumCS()
        {
            StreamWriter sw = File.CreateText(VKxmlParser.GetDestination() + "VKEnums.cs");

            sw.WriteLine("// Document Created with VulkanParser.");
            sw.WriteLine("//       " + DateTime.Now.ToString("HH:mm:ss dd/mm/yyyy"));
            sw.WriteLine("// by BROTHERHOOD OF THE BLACK SWORD.");
            sw.WriteLine();
            sw.WriteLine("using System;");
            sw.WriteLine();
            sw.WriteLine("namespace " + VKxmlParser.GetNamespace());
            sw.WriteLine("{");

            foreach (string key in EnumParser.d_Enums.Keys)
            {
                bool tvneg    = false;
                bool tvmasint = false;
                //bool tvmaslong = false;
                foreach (string key2 in EnumParser.d_Enums[key].Keys)
                {
                    long tempval;
                    if (long.TryParse(EnumParser.d_Enums[key][key2], out tempval))
                    {
                        if (tempval < 0)
                        {
                            tvneg = true;
                            if ((tempval * -1) > int.MaxValue)
                            {
                                tvmasint = true;
                            }
                        }
                        else
                        {
                            if (tempval > int.MaxValue)
                            {
                                tvmasint = true;

                                /*if (tempval > int.MaxValue)
                                 * {
                                 *
                                 * }*/
                            }
                        }
                    }
                }

                string tvalor = "";

                if (tvneg)
                {
                    if (tvmasint)
                    {
                        tvalor = "long";
                    }
                    else
                    {
                        tvalor = "int";
                    }
                }
                else
                {
                    if (tvmasint)
                    {
                        tvalor = "ulong";
                    }
                    else
                    {
                        tvalor = "uint";
                    }
                }

                sw.WriteLine("\t" + "public enum " + key + " : " + tvalor);
                sw.WriteLine("\t" + "{");

                int maxkeys  = EnumParser.d_Enums[key].Keys.Count;
                int contador = 0;
                foreach (string key2 in EnumParser.d_Enums[key].Keys)
                {
                    if (EnumParser.d_EnumComments.ContainsKey(key2))
                    {
                        sw.WriteLine("\t" + "\t" + "/// <summary>" + EnumParser.d_EnumComments[key2] + "</summary>");
                    }
                    if (contador < maxkeys - 1)
                    {
                        sw.WriteLine("\t" + "\t" + key2 + " = " + EnumParser.d_Enums[key][key2] + ",");
                    }
                    else
                    {
                        sw.WriteLine("\t" + "\t" + key2 + " = " + EnumParser.d_Enums[key][key2]);
                    }
                    contador++;
                }

                sw.WriteLine("\t" + "}");
                sw.WriteLine();
            }

            sw.WriteLine("}");
            sw.WriteLine();
            sw.Close();
        }
Beispiel #11
0
        public static void CreateMethodsCS()
        {
            foreach (string key in VersionParser.d_commandsbyversion.Keys) //por versiones
            {
                StreamWriter sw = File.CreateText(VKxmlParser.GetDestination() + "Vulkan" + key.Replace(".", "") + ".cs");
                sw.WriteLine("// Document Created with VulkanParser.");
                sw.WriteLine("//       " + DateTime.Now.ToString("HH:mm:ss dd/mm/yyyy"));
                sw.WriteLine("// by BROTHERHOOD OF THE BLACK SWORD.");
                sw.WriteLine();
                sw.WriteLine("using System;");
                sw.WriteLine("using System.Runtime.InteropServices;");
                sw.WriteLine("using " + VKxmlParser.GetNamespace() + ";");
                sw.WriteLine();
                sw.WriteLine("namespace " + VKxmlParser.GetNamespace() + ".VK" + key.Replace(".", ""));
                sw.WriteLine("{");

                foreach (string keygroups in VersionParser.d_commandsbyversion[key].grupocomandos.Keys)                                                               //por grupos
                {
                    sw.WriteLine("\t" + "public static class " + keygroups.Split(new string[] { " (" }, StringSplitOptions.RemoveEmptyEntries)[0].Replace(" ", "_")); //Agrupar metodos en clases como grupos
                    sw.WriteLine("\t" + "{");
                    List <string> listametodos = VersionParser.d_commandsbyversion[key].grupocomandos[keygroups];
                    sw.WriteLine("\t\t" + "const string VulkanLibrary = \"vulkan-1.dll\";");
                    sw.WriteLine();

                    for (int i = 0; i < listametodos.Count; i++)             //Recorrer Metodos
                    {
                        Metodo mtd = CommandParser.Metodos[listametodos[i]]; //Rescatar metodo del CommandParser
                        sw.WriteLine("\t\t" + "[DllImport (VulkanLibrary, EntryPoint =\"" + mtd.Nombre + "\", CallingConvention = CallingConvention.Winapi)]");
                        bool tienestructs = false;
                        bool tienearray   = false;
                        bool AllocCall    = false;

                        foreach (string keyParams in mtd.Parametros.Keys)  //Consultar Parametros del método
                        {
                            if (mtd.Parametros[keyParams].esarray)
                            {
                                if (mtd.Parametros[keyParams].TipoValor != "char")
                                {
                                    tienearray = true;
                                }
                            }
                            if (StructParser.estructuras.ContainsKey(keyParams))
                            {
                                tienestructs = true;
                            }
                            if (mtd.Parametros[keyParams].TipoValor == "VkAllocationCallbacks")
                            {
                                AllocCall = true;
                            }
                        }
                        string smetodo = "";

                        string valreturned = !mtd.ValueReturned.Contains("PFN_") ? mtd.ValueReturned : "IntPtr";

                        if (tienestructs | tienearray | AllocCall)
                        {
                            smetodo = "private static unsafe extern " + valreturned + " p_" + mtd.Nombre + "(";  //confecionar string de metodo
                        }
                        else
                        {
                            smetodo = "public static unsafe extern " + valreturned + " " + mtd.Nombre + "(";  //confecionar string de metodo
                        }

                        if (mtd.Nombre == "vkEnumerateInstanceExtensionProperties")
                        {
                            Console.WriteLine("Mierda");
                        }

                        foreach (string keyParams in mtd.Parametros.Keys)  //Añadir Parametros del método
                        {
                            Parametro param = mtd.Parametros[keyParams];

                            /*if (param.constante)
                             * {
                             *  smetodo += "const ";
                             * }*/
                            string stipovalor = param.TipoValor;
                            if (HandleParser.handleTypes.Contains(stipovalor))
                            {
                                stipovalor = "IntPtr";
                            }
                            if ((param.puntero) && (stipovalor != "char"))
                            {
                                stipovalor += "*";
                            }
                            string svalorfinparam = Tools.VariableType(stipovalor);
                            if (param.esarray)
                            {
                                if (stipovalor == "char")
                                {
                                    svalorfinparam = "char*";
                                }
                                if ((stipovalor != "char") && (!svalorfinparam.Contains("*")) && (!StructParser.estructuras.ContainsKey(param.TipoValor)))
                                {
                                    svalorfinparam += "*";
                                }
                            }
                            if (param.Nombre == "event")
                            {
                                param.Nombre = "@event";
                            }
                            if (param.puntero && StructParser.estructuras.ContainsKey(param.TipoValor) && !param.esarray)
                            {
                                smetodo += "ref ";
                            }
                            smetodo += svalorfinparam + " " + param.Nombre + ", ";
                        }
                        smetodo = smetodo.Remove(smetodo.Length - 2, 2) + ");"; //quitar coma y espacio tras último parametro y cerrar parentesis.
                        sw.WriteLine("\t" + "\t" + smetodo);                    //escribir enunciado de metodo.
                        //sw.WriteLine("\t"+"\t"+"{");
                        //sw.WriteLine("\t"+"\t"+"\t");
                        //sw.WriteLine("\t"+"\t"+"}");
                        sw.WriteLine();

                        if (tienestructs | tienearray | AllocCall)
                        {
                            CreatePublic(sw, mtd);
                            sw.WriteLine();
                        }
                    }
                    sw.WriteLine("\t" + "}");  //CERRAR CLASE
                    sw.WriteLine();
                }

                sw.WriteLine("}"); //CERRAR NAMESPACE
                sw.WriteLine();
                sw.Close();
            }
        }
Beispiel #12
0
 private void InitParse()
 {
     VKxmlParser.Parse(this.openFileDialog1.FileName, this.textBox3.Text + ".Vulkan", this.folderBrowserDialog1.SelectedPath + "/");
 }
Beispiel #13
0
        private static void CreateBaseMethods(StreamWriter sw)
        {
            #region VK METHODS

            foreach (string key in VersionParser.d_commandsbyversion.Keys) //por versiones
            {
                sw.WriteLine("\t" + "\t" + "public vk" + key.Replace(".", "") + " VK" + key.Replace(".", "") + ";");
                sw.WriteLine();
                sw.WriteLine("\t" + "\t" + "public class vk" + key.Replace(".", ""));
                sw.WriteLine("\t" + "\t" + "{");
                sw.WriteLine("\t" + "\t" + "\t" + "public vk" + key.Replace(".", "") + "()");           //Constructor
                sw.WriteLine("\t" + "\t" + "\t" + "{ ");
                foreach (string keygroups in VersionParser.d_commandsbyversion[key].grupocomandos.Keys) //por grupos
                {
                    string s_grupo  = keygroups.Split(new string[] { " (" }, StringSplitOptions.RemoveEmptyEntries)[0].Replace(" ", "_");
                    string sp_grupo = char.ToUpper(s_grupo[0]) + s_grupo.Substring(1);
                    sw.WriteLine("\t" + "\t" + "\t" + "\t" + sp_grupo + " = new " + s_grupo.ToLower() + "();");
                }
                sw.WriteLine("\t" + "\t" + "\t" + "}");
                sw.WriteLine();
                sw.WriteLine("\t" + "\t" + "\t" + "#region Gruposaccesibles");
                foreach (string keygroups in VersionParser.d_commandsbyversion[key].grupocomandos.Keys) //Declaración de las clases de los grupos de métodos.
                {
                    string s_grupo  = keygroups.Split(new string[] { " (" }, StringSplitOptions.RemoveEmptyEntries)[0].Replace(" ", "_");
                    string sp_grupo = char.ToUpper(s_grupo[0]) + s_grupo.Substring(1);
                    sw.WriteLine("\t" + "\t" + "\t" + "public " + s_grupo.ToLower() + " " + sp_grupo + ";");
                }
                sw.WriteLine("\t" + "\t" + "\t" + "#endregion");
                sw.WriteLine();
                foreach (string keygroups in VersionParser.d_commandsbyversion[key].grupocomandos.Keys) //Definición de las clases de los grupos de metodos.
                {
                    List <string> listametodos = VersionParser.d_commandsbyversion[key].grupocomandos[keygroups];
                    string        s_grupo      = keygroups.Split(new string[] { " (" }, StringSplitOptions.RemoveEmptyEntries)[0].Replace(" ", "_");
                    string        sp_grupo     = char.ToUpper(s_grupo[0]) + s_grupo.Substring(1);
                    sw.WriteLine("\t" + "\t" + "\t" + "public class " + s_grupo.ToLower()); //Agrupar metodos en clases como grupos
                    sw.WriteLine("\t" + "\t" + "\t" + "{");
                    for (int i = 0; i < listametodos.Count; i++)                            //Recorrer Metodos del grupo
                    {
                        Metodo mtd      = CommandParser.Metodos[listametodos[i]];           //Rescatar metodo del CommandParser
                        string s_metodo = "";

                        #region PASO 0: tiene Array
                        bool tienearray = false;
                        foreach (string keyParams in mtd.Parametros.Keys)  //Consultar Parametros del método
                        {
                            if (mtd.Parametros[keyParams].esarray)
                            {
                                if (mtd.Parametros[keyParams].TipoValor != "char")
                                {
                                    tienearray = true; //Indica si el metodo va a tener fixeds.
                                }
                            }
                        }
                        #endregion

                        #region PASO 1: Valor Retornado y Apertura de Metodo
                        string valreturned = !mtd.ValueReturned.Contains("PFN_") ? mtd.ValueReturned : "IntPtr";

                        s_metodo = "internal unsafe " + VKxmlParser.GetNamespace() + ".VKDelegates.VK" + key.Replace(".", "") + "." + sp_grupo + "." + mtd.Nombre + " p_" + mtd.Nombre + ";";  //confecionar string de metodo

                        #endregion

                        sw.WriteLine("\t" + "\t" + "\t" + "\t" + s_metodo); //ESCRIBIR METODO

                        sw.WriteLine();

                        if (tienearray)
                        {
                            CreatePublicMethods(sw, mtd);
                            sw.WriteLine();
                        }
                        else
                        {
                            CreateNormalPublicMethods(sw, mtd);
                            sw.WriteLine();
                        }
                    }
                    sw.WriteLine("\t" + "\t" + "\t" + "}");
                    sw.WriteLine();
                }
                sw.WriteLine("\t" + "\t" + "}");
                sw.WriteLine();
            }

            #endregion
        }
Beispiel #14
0
        public static void CreateStructsCS()
        {
            StreamWriter sw = File.CreateText(VKxmlParser.GetDestination() + "VKStructs.cs");

            sw.WriteLine("// Document Created with VulkanParser.");
            sw.WriteLine("//       " + DateTime.Now.ToString("HH:mm:ss dd/mm/yyyy"));
            sw.WriteLine("// by BROTHERHOOD OF THE BLACK SWORD.");
            sw.WriteLine();
            sw.WriteLine("using System;");
            sw.WriteLine("using System.Runtime.InteropServices;");
            sw.WriteLine();
            sw.WriteLine("namespace " + VKxmlParser.GetNamespace());
            sw.WriteLine("{");

            //MEOLLO
            foreach (string key in StructParser2.estructuras.Keys)             //ESTRUCTURAS
            {
                sw.WriteLine("\t" + "[StructLayout(LayoutKind.Sequential)]");
                sw.WriteLine("\t" + "public unsafe struct " + key);
                sw.WriteLine("\t" + "{");
                //bool valorado = false;
                foreach (string key2 in StructParser2.estructuras[key].valores.Keys) //VALORES DE LA ESTRUCTURA
                {
                    Valor ValorTemp = StructParser2.estructuras[key].valores[key2];  //VALOR
                    if (ValorTemp.comentado)                                         //.comentario != "") //¿TIENE COMENTARIO?
                    {
                        sw.WriteLine("\t" + "\t" + "/// <summary>" + ValorTemp.comentario + "</summary>");
                    }
                    //Tipo de valor ¿puntero? ¿estructura? ¿valor?
                    string linea = "\t" + "\t" + "public ";
                    if (ValorTemp.constante | ValorTemp.tieneValor)
                    {
                        linea += "const ";
                    }

                    string tipovalor = Tools.VariableType(ValorTemp.typo);
                    if (ValorTemp.typo.Contains("PFN_"))
                    {
                        tipovalor = "IntPtr";
                    }
                    if (ValorTemp.typo == "char")
                    {
                        if (ValorTemp.puntero)
                        {
                            tipovalor = "char*";
                        }
                    }

                    if (ValorTemp.esArray)                                                                      //Arrays con: fixed tipovalor nombrevalor[dimension];
                    {
                        if ((StructParser2.estructuras.ContainsKey(ValorTemp.typo)) || (tipovalor == "IntPtr")) //Si es estructura o IntPtr se define la dimensión antes.
                        {
                            sw.WriteLine("\t" + "\t" + "[MarshalAs(UnmanagedType.ByValArray, SizeConst = " + ValorTemp.maxAray + ")]");
                        }
                        else
                        {
                            linea += "fixed ";
                        }
                    }

                    /*if (ValorTemp.esStruct)
                     *                  {
                     *                          string tipovalor = ValorTemp.typo;
                     *                          linea += tipovalor;
                     *                  }
                     *                  else
                     *                  {
                     *                          string tipovalor = Tools.VariableType(ValorTemp.typo);
                     *                          linea += tipovalor;
                     *                  }*/
                    /*if (HandleParser.handleTypes.Contains(ValorTemp.typo))
                     * {
                     *  string jamon = "";
                     * }*/

                    linea += tipovalor;
                    if (ValorTemp.esArray) //Si nes Array y estructura o IntPtr se marca como array tras el tipo []
                    {
                        if ((StructParser2.estructuras.ContainsKey(ValorTemp.typo)) || (tipovalor == "IntPtr"))
                        {
                            linea += "*";
                        }
                    }
                    if ((ValorTemp.puntero) && (!ValorTemp.typo.Contains("PFN_")))
                    {
                        linea += "*";
                    }
                    if (ValorTemp.nombre == "object")
                    {
                        ValorTemp.nombre = "@object";
                    }
                    linea += " " + ValorTemp.nombre;
                    if (ValorTemp.tieneValor)
                    {
                        //valorado = true;
                        linea += " = " + ValorTemp.svalor;
                    }

                    if (ValorTemp.esArray) //Arrays con: fixed tipovalor nombrevalor[dimension]
                    {
                        if (!StructParser2.estructuras.ContainsKey(ValorTemp.typo) && (tipovalor != "IntPtr"))
                        {
                            linea += "[" + ValorTemp.maxAray + "]";
                        }
                    }

                    /*
                     * if (ValorTemp.esArray) //Arrays con: fixed tipovalor nombrevalor[dimension]
                     * {
                     *  if (StructParser2.estructuras.ContainsKey(ValorTemp.typo) || tipovalor == "IntPtr")
                     *  {
                     *      for (int n=1;n<ValorTemp.maxAray;n++)
                     *      {
                     *          linea = "\t" + "\t" + "public " + tipovalor + " " + ValorTemp.nombre+n.ToString()+";";
                     *          sw.WriteLine(linea); //ESCRIBIR LINEA DE VALOR
                     *      }
                     *      linea = "\t" + "\t" + "public " + tipovalor + " " + ValorTemp.nombre + ValorTemp.maxAray;
                     *  }
                     * }*/
                    linea += ";";
                    sw.WriteLine(linea);                     //ESCRIBIR LINEA DE VALOR
                }

                /*if (valorado)
                 * {
                 *      sw.WriteLine();
                 *      sw.WriteLine("\t"+"\t"+"public "+key+"()");
                 *      sw.WriteLine("\t"+"\t"+"{");
                 *      foreach (string key3 in StructParser2.estructuras[key].valores.Keys)
                 *      {
                 *              Valor ValorTemp = StructParser2.estructuras[key].valores[key3]; //VALOR
                 *              if (ValorTemp.tieneValor)
                 *              {
                 *                      string s_lineavalora = "\t"+"\t"+"\t";
                 *                      s_lineavalora += (ValorTemp.nombre+" = "+ValorTemp.svalor+";");
                 *                      sw.WriteLine(s_lineavalora);
                 *              }
                 *      }
                 *      sw.WriteLine("\t"+"\t"+"}");
                 * }*/

                sw.WriteLine("\t" + "}");
                sw.WriteLine();
            }

            sw.WriteLine("}");
            sw.WriteLine();
            sw.Close();
        }
Beispiel #15
0
        public static void CreateMethodsCS()
        {
            foreach (string key in VersionParser.d_commandsbyversion.Keys)             //por versiones
            {
                StreamWriter sw = File.CreateText(VKxmlParser.GetDestination() + "Vulkan" + key.Replace(".", "") + ".cs");
                sw.WriteLine("// Document Created with VulkanParser.");
                sw.WriteLine("//       " + DateTime.Now.ToString("HH:mm:ss dd/mm/yyyy"));
                sw.WriteLine("// by BROTHERHOOD OF THE BLACK SWORD.");
                sw.WriteLine();
                sw.WriteLine("using System;");
                sw.WriteLine("using System.Runtime.InteropServices;");
                sw.WriteLine("using " + VKxmlParser.GetNamespace() + ";");
                sw.WriteLine();
                sw.WriteLine("namespace " + VKxmlParser.GetNamespace() + ".VK" + key.Replace(".", ""));
                sw.WriteLine("{");

                foreach (string keygroups in VersionParser.d_commandsbyversion[key].grupocomandos.Keys)                                                               //por grupos
                {
                    sw.WriteLine("\t" + "public static class " + keygroups.Split(new string[] { " (" }, StringSplitOptions.RemoveEmptyEntries)[0].Replace(" ", "_")); //Agrupar metodos en clases como grupos
                    sw.WriteLine("\t" + "{");
                    List <string> listametodos = VersionParser.d_commandsbyversion[key].grupocomandos[keygroups];
                    sw.WriteLine("\t\t" + "const string VulkanLibrary = \"vulkan-1\";");
                    sw.WriteLine();

                    for (int i = 0; i < listametodos.Count; i++)                                                      //Recorrer Metodos
                    {
                        Metodo mtd = CommandParser.Metodos[listametodos[i]];                                          //Rescatar metodo del CommandParser
                        sw.WriteLine("\t\t" + "[DllImport (VulkanLibrary, CallingConvention = CallingConvention.Winapi)]");
                        string smetodo = "public static unsafe extern " + mtd.ValueReturned + " " + mtd.Nombre + "("; //confecionar string de metodo
                        foreach (string keyParams in mtd.Parametros.Keys)                                             //Añadir Parametros del método
                        {
                            Parametro param = mtd.Parametros[keyParams];

                            /*if (param.constante)
                             * {
                             *      smetodo += "const ";
                             * }*/
                            string stipovalor = param.TipoValor;
                            if (HandleParser.handleTypes.Contains(stipovalor))
                            {
                                stipovalor = "IntPtr";
                            }
                            if (param.puntero)
                            {
                                stipovalor += "*";
                            }
                            string svalorfinparam = Tools.VariableType(stipovalor);
                            if (param.Nombre == "event")
                            {
                                param.Nombre = "@event";
                            }
                            smetodo += svalorfinparam + " " + param.Nombre + ", ";
                        }
                        smetodo = smetodo.Remove(smetodo.Length - 2, 2) + ");";  //quitar comay espacio tras último parametro y cerrar parentesis.
                        sw.WriteLine("\t" + "\t" + smetodo);                     //escribir enunciado de metodo.
                        //sw.WriteLine("\t"+"\t"+"{");
                        //sw.WriteLine("\t"+"\t"+"\t");
                        //sw.WriteLine("\t"+"\t"+"}");
                        sw.WriteLine();
                    }
                    sw.WriteLine("\t" + "}");
                    sw.WriteLine();
                }

                sw.WriteLine("}");
                sw.WriteLine();
                sw.Close();
            }
        }