Пример #1
0
        static void Main(string[] args)
        {
            // read all RhinoCommon classes into memory
            const string rhinocommonPath = @"C:\dev\github\mcneel\rhino\src4\DotNetSDK\rhinocommon\dotnet";

            Console.WriteLine("[Parse RhinoCommon source]");
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            RhinoCommonClass.BuildClassDictionary(rhinocommonPath);
            Console.ResetColor();

            Console.WriteLine("[Parse C++ Bindings]");
            Console.ForegroundColor = ConsoleColor.Green;
            const string bindingPath = @"../../../../src/bindings";

            BindingClass.BuildClassDictionary(bindingPath);
            Console.ResetColor();
            Console.WriteLine("[END PARSE]");


            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("Writing javascript");
            JavascriptClass.Write("rh3dm_temp.js");
            Console.WriteLine("Writing python");
            PythonClass.Write();
        }
Пример #2
0
        static void Main(string[] args)
        {
            // read all RhinoCommon classes into memory
            const string rhinocommonPath = @"../../dotnet";

            Console.WriteLine("[Parse RhinoCommon source]");
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            RhinoCommonClass.BuildClassDictionary(rhinocommonPath);
            Console.ResetColor();

            Console.WriteLine("[Parse C++ Bindings]");
            Console.ForegroundColor = ConsoleColor.Green;
            const string bindingPath = @"../../bindings";

            BindingClass.BuildDictionary(bindingPath);
            Console.ResetColor();
            Console.WriteLine("[END PARSE]");


            var outDir = new DirectoryInfo("../out");

            if (!outDir.Exists)
            {
                outDir.Create();
            }

            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("Writing javascript API help");
            JavascriptClass.GenerateApiHelp(Path.Combine(outDir.FullName, "js_apidocs"));
            Console.WriteLine("Writing javascript typescript definition file");
            JavascriptClass.GenerateTypescriptDefinition(Path.Combine(outDir.FullName, "js_tsdef"));

            Console.WriteLine("Writing python");
            PythonClass.Write(Path.Combine(outDir.FullName, "py_apidocs"));
        }
Пример #3
0
        public static void BuildDictionary(string sourcePath)
        {
            BindingClass activeClass = null;

            foreach (var file in AllSourceFiles(sourcePath))
            {
                string[] lines = System.IO.File.ReadAllLines(file);
                for (int i = 0; i < lines.Length; i++)
                {
                    string line = lines[i].Trim();
                    if (line.StartsWith("class_"))
                    {
                        string name = (line.Split(new char[] { '"' }))[1];
                        if (name.StartsWith("__"))
                        {
                            continue;
                        }
                        var activeJavascriptClass = new JavascriptClass(name);
                        int baseIndex             = line.IndexOf("base<BND_");
                        if (baseIndex > 0)
                        {
                            int baseEnd = line.IndexOf(">", baseIndex);
                            baseIndex += "base<BND_".Length;
                            string baseClass = line.Substring(baseIndex, baseEnd - baseIndex);
                            activeJavascriptClass.BaseClass = baseClass;
                        }
                        AllJavascriptClasses.Add(name.ToLowerInvariant(), activeJavascriptClass);
                        activeClass = activeJavascriptClass;
                        continue;
                    }

                    if (line.StartsWith("py::class_"))
                    {
                        string name = (line.Split(new char[] { '"' }))[1];
                        if (name.StartsWith("__"))
                        {
                            continue;
                        }
                        var activePythonClass = new PythonClass(name);
                        int baseIndex         = line.IndexOf(",");
                        if (baseIndex > 0)
                        {
                            baseIndex = line.IndexOf("BND_", baseIndex);
                        }
                        if (baseIndex > 0)
                        {
                            int baseEnd = line.IndexOf(">", baseIndex);
                            baseIndex += "BND_".Length;
                            if (baseEnd > baseIndex)
                            {
                                string baseClass = line.Substring(baseIndex, baseEnd - baseIndex);
                                activePythonClass.BaseClass = baseClass;
                            }
                        }
                        AllPythonClasses.Add(name.ToLowerInvariant(), activePythonClass);
                        activeClass = activePythonClass;
                        continue;
                    }

                    if (line.StartsWith("enum_"))
                    {
                        string name = (line.Split(new char[] { '"' }))[1];
                        if (name.StartsWith("__"))
                        {
                            continue;
                        }
                        var jsenum = new JavascriptEnum(name);
                        AllJavascriptEnums.Add(name.ToLowerInvariant(), jsenum);
                        activeClass = jsenum;
                        continue;
                    }

                    if (activeClass != null)
                    {
                        if (line.StartsWith(".constructor"))
                        {
                            int    startIndex = line.IndexOf("<");
                            int    endIndex   = line.IndexOf(">", startIndex);
                            string types      = line.Substring(startIndex + 1, endIndex - startIndex - 1);
                            activeClass.AddConstructor(types);
                            continue;
                        }
                        if (line.IndexOf("py::init<") > 0)
                        {
                            int    startIndex = line.IndexOf("py::init<") + "py::init<".Length;
                            int    endIndex   = line.IndexOf(">", startIndex);
                            string types      = line.Substring(startIndex, endIndex - startIndex);
                            activeClass.AddConstructor(types);
                            continue;
                        }

                        if (line.StartsWith(".property") ||
                            line.StartsWith(".def_property"))
                        {
                            string propName = (line.Split(new char[] { '"' }))[1];
                            activeClass.AddProperty(propName);
                            continue;
                        }

                        if (line.Contains("py::self"))
                        {
                            continue;
                        }

                        if (line.StartsWith(".function") || line.StartsWith(".def("))
                        {
                            string funcName = (line.Split(new char[] { '"' }))[1];
                            activeClass.AddMethod(funcName, false, GetArgList(line));
                        }

                        if (line.StartsWith(".class_function") ||
                            line.StartsWith(".def_static"))
                        {
                            string funcName = (line.Split(new char[] { '"' }))[1];
                            activeClass.AddMethod(funcName, true, GetArgList(line));
                        }
                        if (line.StartsWith(";"))
                        {
                            activeClass = null;
                        }
                        if (activeClass is JavascriptEnum && line.StartsWith(".value"))
                        {
                            string enumValue = (line.Split(new char[] { '"' }))[1];
                            (activeClass as JavascriptEnum).Elements.Add(enumValue);
                        }
                    }
                }
                Console.WriteLine($"parse: {file}");
            }
        }