Beispiel #1
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 #2
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 #3
0
        private static void CreateBaseMethods(StreamWriter sw)
        {
            #region VK METHODS

            foreach (string key in VersionParser.d_commandsbyversion.Keys) //por versiones
            {
                sw.WriteLine("\t" + "\t" + "internal static class VK" + key.Replace(".", ""));
                sw.WriteLine("\t" + "\t" + "{");
                foreach (string keygroups in VersionParser.d_commandsbyversion[key].grupocomandos.Keys) //por grupos
                {
                    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" + "internal static class " + sp_grupo);  //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 1: Valor Retornado y Apertura de Metodo
                        string valreturned = !mtd.ValueReturned.Contains("PFN_") ? mtd.ValueReturned : "IntPtr";

                        s_metodo = "internal unsafe delegate " + valreturned + " " + mtd.Nombre + "(";  //confecionar string de metodo

                        #endregion

                        #region PASO 2: Añadir Parametros al Metodo
                        List <string> referidos = new List <string>();    //controlar parametros referidos
                        foreach (string keyParams in mtd.Parametros.Keys) //Añadir Parametros del método
                        {
                            Parametro param      = mtd.Parametros[keyParams];
                            string    stipovalor = param.TipoValor;
                            if (stipovalor == "VkAllocationCallbacks")
                            {
                                s_metodo += "VkAllocationCallbacks* " + param.Nombre + ", ";
                            }
                            else
                            {
                                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 = "string";  //"char*";
                                    }
                                    if ((stipovalor != "char") && (!svalorfinparam.Contains("*")) && (!StructParser2.estructuras.ContainsKey(param.TipoValor)))
                                    {
                                        svalorfinparam += "*";
                                    }
                                }
                                if (param.Nombre == "event")
                                {
                                    param.Nombre = "@event";
                                }
                                if (param.puntero)
                                {
                                    if (StructParser2.estructuras.ContainsKey(param.TipoValor) || (stipovalor.Contains("IntPtr")))
                                    {
                                        if (!param.esarray)
                                        {
                                            s_metodo += "ref ";
                                            referidos.Add(keyParams);
                                            if (svalorfinparam.Contains("*"))
                                            {
                                                svalorfinparam = svalorfinparam.Replace("*", "");
                                            }
                                        }
                                    }
                                }
                                s_metodo += svalorfinparam + " " + param.Nombre + ", ";
                            }
                        }
                        #endregion
                        s_metodo = s_metodo.Remove(s_metodo.Length - 2, 2) + ");"; //quitar coma y espacio tras último parametro y cerrar parentesis.

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

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

            #endregion
        }
Beispiel #4
0
        private static void CreatePublic(StreamWriter sw, Metodo mtd)
        {
            string smetodo   = "public static unsafe " + mtd.ValueReturned + " " + mtd.Nombre + "("; //confecionar string de metodo
            int    paramcont = 0;

            if (mtd.Nombre == "vkCreateInstance")
            {
                Console.WriteLine("mierda");
            }
            foreach (string keyparam in mtd.Parametros.Keys) //recorrer parametros para enunciado.
            {
                Parametro param = mtd.Parametros[keyparam];
                if (param.Nombre == "event")
                {
                    param.Nombre = "@event";
                }
                paramcont++;
                //if (param.TipoValor != "VkAllocationCallbacks")
                //{
                if (param.puntero)
                {
                    smetodo += "ref ";
                    if (param.TipoValor == "void")
                    {
                        smetodo += "IntPtr";
                    }
                    else if (param.TipoValor == "char")
                    {
                        smetodo += "string";     // + "*");
                    }
                    else
                    {
                        smetodo += Tools.VariableType(param.TipoValor);     // + "*");
                    }
                }
                else
                {
                    smetodo += Tools.VariableType(param.TipoValor);
                }
                if ((param.esarray) && (param.TipoValor != "char"))
                {
                    smetodo += "[]";
                }
                smetodo += " " + param.Nombre + ", ";
                //}
            }

            if (smetodo.Substring(smetodo.Length - 2) == ", ")
            {
                smetodo = smetodo.Remove(smetodo.Length - 2);
            }


            smetodo += ")";                               //Cerrar enunciado de metodo.
            sw.WriteLine("\t" + "\t" + smetodo);          //escribir enunciado de metodo.
            sw.WriteLine("\t" + "\t" + "{");              //Abrir Metodo.
            List <string> l_params = new List <string>(); //Lista de metodos a incluir en llamada a extern
            int           ntabs    = 0;

            foreach (string keyparam in mtd.Parametros.Keys) //recorrer parametros.
            {
                Parametro param = mtd.Parametros[keyparam];

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

                if (param.Nombre == "event")
                {
                    param.Nombre = "@event";
                }
                //if (param.TipoValor == "VkAllocationCallbacks")
                //{
                //    l_params.Add("null");
                //}
                //else
                //{
                if (param.puntero)
                {
                    if (param.TipoValor != "char")
                    {
                        if (StructParser.estructuras.ContainsKey(param.TipoValor) && !param.esarray)
                        {
                            l_params.Add("ref " + param.Nombre);
                        }
                        else
                        {
                            string fixedtabs = "";
                            for (int t = 0; t < ntabs; t++)
                            {
                                fixedtabs += "\t";
                            }
                            string tempvalor = "";
                            if (param.TipoValor == "void")
                            {
                                tempvalor = "IntPtr";
                            }
                            else
                            {
                                tempvalor = Tools.VariableType(param.TipoValor);
                            }
                            if (param.esarray)
                            {
                                sw.WriteLine("\t" + "\t" + "\t" + fixedtabs + "fixed(" + /*param.TipoValor*/ tempvalor + "* p_" + param.Nombre + " = &" + param.Nombre + "[0])");
                            }
                            else
                            {
                                sw.WriteLine("\t" + "\t" + "\t" + fixedtabs + "fixed(" + /*param.TipoValor*/ tempvalor + "* p_" + param.Nombre + " = &" + param.Nombre + ")");
                            }
                            sw.WriteLine("\t" + "\t" + "\t" + fixedtabs + "{"); //abrir fixed;
                            l_params.Add("p_" + param.Nombre);
                            ntabs++;                                            //añadir numero de tabulaciones
                        }
                    }
                    else
                    {
                        string fixedtabs = "";
                        for (int t = 0; t < ntabs; t++)
                        {
                            fixedtabs += "\t";
                        }
                        if (param.esarray)
                        {
                            sw.WriteLine("\t" + "\t" + "\t" + fixedtabs + "fixed(" + /*param.TipoValor*/ "char* p_" + param.Nombre + " = &" + param.Nombre + ".ToCharArray()[0])");
                        }
                        //System.Runtime.InteropServices.Marshal.StringToHGlobalAuto(param.Nombre)
                        else
                        {
                            sw.WriteLine("\t" + "\t" + "\t" + fixedtabs + "fixed(" + /*param.TipoValor*/ "char* p_" + param.Nombre + " = &" + param.Nombre + ")");
                        }
                        sw.WriteLine("\t" + "\t" + "\t" + fixedtabs + "{"); //abrir fixed;
                        l_params.Add("p_" + param.Nombre);
                        ntabs++;                                            //añadir numero de tabulaciones
                    }
                }
                else
                {
                    l_params.Add(param.Nombre);
                }
                //}
            }

            #region Escribir llamada a metodo extern

            string sMethodCall = "";
            for (int i = 0; i < ntabs; i++) //Añadir Tabulaciones
            {
                sMethodCall += "\t";
            }
            if (mtd.ValueReturned != "void")
            {
                sMethodCall += "return ";
            }
            sMethodCall += "p_" + mtd.Nombre + "("; //Añadir nombre de metodo llamado
            for (int m = 0; m < l_params.Count; m++)
            {
                sMethodCall += l_params[m];
                if (m < l_params.Count - 1)
                {
                    sMethodCall += ", "; //añadir coma y espacio si no es el ultimo parametro
                }
            }
            sMethodCall += ");";
            sw.WriteLine("\t" + "\t" + "\t" + sMethodCall);

            #endregion

            #region Cerrar fixeds

            for (int i = 0; i < ntabs; i++) //Añadir Tabulaciones
            {
                string tabscierres = "";
                for (int e = 0; e < ntabs - i; e++)
                {
                    tabscierres += "\t";
                }
                sw.WriteLine("\t" + "\t" + tabscierres + "}");
            }

            #endregion

            sw.WriteLine("\t" + "\t" + "}"); //Cerrar Metodo.
        }
Beispiel #5
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 #6
0
        private static void CreateNormalPublicMethods(StreamWriter sw, Metodo mtd)
        {
            string s_ret = mtd.ValueReturned;

            if (s_ret.Contains("PFN"))
            {
                s_ret = "IntPtr";
            }
            string s_metodo = "public unsafe " + s_ret + " " + mtd.Nombre + "(";  //confecionar string de metodo

            #region PASO 2: Añadir Parametros al Metodo
            List <string> referidos = new List <string>();    //controlar parametros referidos
            foreach (string keyParams in mtd.Parametros.Keys) //Añadir Parametros del método
            {
                Parametro param      = mtd.Parametros[keyParams];
                string    stipovalor = param.TipoValor;
                if (stipovalor == "VkAllocationCallbacks")
                {
                    s_metodo += "VkAllocationCallbacks* " + param.Nombre + ", ";
                }
                else
                {
                    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 = "string";  //"char*";
                        }
                        if ((stipovalor != "char") && (!svalorfinparam.Contains("*")) && (!StructParser2.estructuras.ContainsKey(param.TipoValor)))
                        {
                            svalorfinparam += "*";
                        }
                    }
                    if (param.Nombre == "event")
                    {
                        param.Nombre = "@event";
                    }
                    if (param.puntero)
                    {
                        if (StructParser2.estructuras.ContainsKey(param.TipoValor) || (stipovalor.Contains("IntPtr")))
                        {
                            if (!param.esarray)
                            {
                                s_metodo += "ref ";
                                referidos.Add(keyParams);
                                if (svalorfinparam.Contains("*"))
                                {
                                    svalorfinparam = svalorfinparam.Replace("*", "");
                                }
                            }
                        }
                    }
                    s_metodo += svalorfinparam + " " + param.Nombre + ", ";
                }
            }
            s_metodo = s_metodo.Remove(s_metodo.Length - 2, 2) + ")"; //quitar coma y espacio tras último parametro y cerrar parentesis.
            #endregion

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

            #region PASO 3: Escribir contenido de metodo y llamada al metodo privado.
            sw.WriteLine("\t" + "\t" + "\t" + "\t" + "{");
            string s_internalMethod = mtd.ValueReturned != "void" ? "return " : ""; // ¿Retorna?
            s_internalMethod += "p_" + mtd.Nombre + "(";

            foreach (string kparam in mtd.Parametros.Keys)
            {
                if (referidos.Contains(kparam))
                {
                    s_internalMethod += "ref ";
                }
                s_internalMethod += mtd.Parametros[kparam].Nombre + ", ";
            }

            s_internalMethod = s_internalMethod.Remove(s_internalMethod.Length - 2, 2) + ");"; //Cerrar LLamada quitando ultimo coma y espacio.
            sw.WriteLine("\t" + "\t" + "\t" + "\t" + "\t" + s_internalMethod);                 // Escribir Llamada a Internal Method.

            sw.WriteLine("\t" + "\t" + "\t" + "\t" + "}");
            #endregion
        }
Beispiel #7
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 #8
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();
            }
        }