Beispiel #1
0
        public void convertFile(string inFile, string outFile)
        {
            nsList = new TNamespaceList(this);
            this.outFile = outFile;
            this.inFile = inFile;
            var localIdlFile = Program.idlOutTempDirectory + @"\" + Path.GetFileName(inFile);
            var localIdlFile2 = Program.idlOutTempDirectory + @"\" + Path.GetFileNameWithoutExtension(inFile) + ".i";
            var path = Path.GetDirectoryName(inFile).Replace(Program.idlInDirectory, "").Replace("\\", ".");

            if (File.Exists(localIdlFile)) File.Delete(localIdlFile);
            File.Copy(inFile, localIdlFile);

            Environment.CurrentDirectory = Path.GetDirectoryName(localIdlFile);
            if (Program.runPreprocessor)
            {
                Process.Start(new ProcessStartInfo(Program.preprocessorExe, localIdlFile + " /P /DLANGUAGE_JAVASCRIPT=1") { WindowStyle = ProcessWindowStyle.Hidden }).WaitForExit();
            }

            var lines = File.ReadAllLines(localIdlFile2);
            for (var i = 0; i < lines.Length; i++)
                if (lines[i].StartsWith("#")) lines[i] = "";

            TScriptTokenizer tokenizer = new TScriptTokenizer(string.Join("\r\n", lines));
            TCodeTokenFile tf = tokenizer.GetTokenFile();
            setTokens(tf.tokens);

            TNamespace ns = new TNamespace(this);
            nsList.Add(ns);

            path = path.Replace("Modules.", "");
            if (TransformationConfig.moveToRootNamespace.Contains(path.ToLower()))
            {
                ns.name = "SharpKit.Html";
            }
            else
            {
                ns.name = "SharpKit.Html." + path.ToLower();
                if (!Generator.namespaceNames.Contains(ns.name)) Generator.namespaceNames.Add(ns.name);
            }

            getNextToken();
            TAttributeList attributes = new TAttributeList();
            while (true)
            {
                //if (currentToken.token == ECodeToken.kwModule)
                //{
                //    getNextToken();
                //    var module = readDottedString();
                //    ns.name = "SharpKit.Html";

                //    //var seperateModules = new HashSet<string>(new string[]{
                //    //    "svg",
                //    //    "storage",
                //    //    "threads",
                //    //    "audio",
                //    //    "webaudio",
                //    //});

                //    if (TransformationConfig.createSubNamespaceForModule.Contains(module))
                //    {
                //        ns.name += "." + module;
                //        if (!Generator.namespaceNames.Contains(ns.name)) Generator.namespaceNames.Add(ns.name);
                //    }

                //}



                //if (CurrentToken.Token == ECodeToken.kwImport) {
                //  GetNextToken();
                //  string imp = readDottedString();
                //  if (!(imp.Contains("org.w3c.dom.html.Function"))) {
                //    ns.ImportList.Add(imp);
                //  }
                //}
                ns.importList.Clear();

                if (currentToken.token == ECodeToken.brSmallBraceBegin)
                {
                    attributes = readAttributes();
                }

                if (currentToken.token == ECodeToken.kwInterface) //new type
                {
                    TFileType t = readInterfaceType();
                    t.attributes = attributes;
                    foreach (var attr in t.attributes)
                        if (attr is TConstructorAttribute)
                            ((TConstructorAttribute)attr).constructor.parentType = t;
                    attributes = new TAttributeList(); //reset
                    t.ns = ns;
                    ns.types.Add(t);
                    t.checkProp();
                }
                getNextToken();
                if (_IsEndOfDocument)
                {
                    break;
                }
            }

        }
Beispiel #2
0
        public void convertFile(string inFile, string outFile)
        {
            nsList       = new TNamespaceList(this);
            this.outFile = outFile;
            this.inFile  = inFile;
            var localIdlFile  = Program.idlOutTempDirectory + @"\" + Path.GetFileName(inFile);
            var localIdlFile2 = Program.idlOutTempDirectory + @"\" + Path.GetFileNameWithoutExtension(inFile) + ".i";
            var path          = Path.GetDirectoryName(inFile).Replace(Program.idlInDirectory, "").Replace("\\", ".");

            if (File.Exists(localIdlFile))
            {
                File.Delete(localIdlFile);
            }
            File.Copy(inFile, localIdlFile);

            Environment.CurrentDirectory = Path.GetDirectoryName(localIdlFile);
            if (Program.runPreprocessor)
            {
                Process.Start(new ProcessStartInfo(Program.preprocessorExe, localIdlFile + " /P /DLANGUAGE_JAVASCRIPT=1")
                {
                    WindowStyle = ProcessWindowStyle.Hidden
                }).WaitForExit();
            }

            var lines = File.ReadAllLines(localIdlFile2);

            for (var i = 0; i < lines.Length; i++)
            {
                if (lines[i].StartsWith("#"))
                {
                    lines[i] = "";
                }
            }
            TScriptTokenizer tokenizer = new TScriptTokenizer(string.Join("\r\n", lines), localIdlFile2);
            TCodeTokenFile   tf        = tokenizer.GetTokenFile();

            setTokens(tf.tokens);

            TNamespace ns = new TNamespace(this);

            nsList.Add(ns);

            //path = path.Replace("modules.", "");
            if (TransformationConfig.moveToRootNamespace.Contains(path.ToLower()))
            {
                ns.name = "randori.webkit";
            }
            else
            {
                ns.name = "randori.webkit." + path.ToLower();
                if (!Generator.namespaceNames.Contains(ns.name))
                {
                    Generator.namespaceNames.Add(ns.name);
                }
            }

            getNextToken();
            TAttributeList attributes = new TAttributeList();

            while (true)
            {
                //if (currentToken.token == ECodeToken.kwModule)
                //{
                //    getNextToken();
                //    var module = readDottedString();
                //    ns.name = "SharpKit.Html";

                //    //var seperateModules = new HashSet<string>(new string[]{
                //    //    "svg",
                //    //    "storage",
                //    //    "threads",
                //    //    "audio",
                //    //    "webaudio",
                //    //});

                //    if (TransformationConfig.createSubNamespaceForModule.Contains(module))
                //    {
                //        ns.name += "." + module;
                //        if (!Generator.namespaceNames.Contains(ns.name)) Generator.namespaceNames.Add(ns.name);
                //    }

                //}



                //if (CurrentToken.Token == ECodeToken.kwImport) {
                //  GetNextToken();
                //  string imp = readDottedString();
                //  if (!(imp.Contains("org.w3c.dom.html.Function"))) {
                //    ns.ImportList.Add(imp);
                //  }
                //}
                ns.importList.Clear();

                if (currentToken.token == ECodeToken.brSmallBraceBegin)
                {
                    attributes = readAttributes();
                }

                if (currentToken.token == ECodeToken.kwInterface) //new type
                {
                    TFileType t = readInterfaceType();
                    t.attributes = attributes;
                    foreach (var attr in t.attributes)
                    {
                        if (attr is TConstructorAttribute)
                        {
                            ((TConstructorAttribute)attr).constructor.parentType = t;
                        }
                    }
                    attributes = new TAttributeList(); //reset
                    t.ns       = ns;
                    ns.types.Add(t);
                    t.checkProp();
                }
                getNextToken();
                if (_IsEndOfDocument)
                {
                    break;
                }
            }
        }
Beispiel #3
0
        public static void start()
        {
            if (!Directory.Exists(Program.idlOutTempDirectory))
            {
                Directory.CreateDirectory(Program.idlOutTempDirectory);
            }
            if (!Directory.Exists(Program.csOutDirectory))
            {
                Directory.CreateDirectory(Program.csOutDirectory);
            }

            TScriptTokenizer.SharedInit();

            //ConvertFile(@"D:\dotnet\webkit\Source\WebCore\Modules\intents\Intent.idl", csOutDirectory + @"test.cs");
            convertDirectory(Program.idlInDirectory, Program.csOutDirectory);

            foreach (var pFile in parsedFiles)
            {
                foreach (var ns in pFile.nsList)
                {
                    foreach (var t in ns.types)
                    {
                        foreach (var attr in t.attributes)
                        {
                            if (attr is TNameAttribute)
                            {
                                var nameAttr = attr as TNameAttribute;
                                if (nameAttr.name == "InterfaceName")
                                {
                                    t.rename(nameAttr.value);
                                    break;
                                }
                            }
                        }

                        if (t.name == "Event")
                        {
                            t.rename("DOMEvent");
                            t.aliasName = "Event";
                        }

                        string newName;
                        if (TransformationConfig.renameType.TryGetValue(t.name, out newName))
                        {
                            t.aliasName = t.name;
                            t.rename(newName);
                        }

                        //if (t.name.StartsWith("HTML"))
                        //{
                        //    t.aliasName = t.name;
                        //    t.rename(t.name.Replace("HTML", "Html"));
                        //}

                        //if (t.name.StartsWith("SVG"))
                        //{
                        //    t.aliasName = t.name;
                        //    t.rename(t.name.Replace("SVG", "Svg"));
                        //}

                        //if (t.name.StartsWith("CSS"))
                        //{
                        //    t.aliasName = t.name;
                        //    t.rename(t.name.Replace("CSS", "Css"));
                        //}

                        foreach (var entry in TransformationConfig.renameTypePrefix)
                        {
                            if (t.name.StartsWith(entry.Key))
                            {
                                t.aliasName = t.name;
                                t.rename(t.name.Replace(entry.Key, entry.Value));
                            }
                        }

                        foreach (var mem in t.members)
                        {
                            if (mem.name.StartsWith("on") && mem.resultType.name == "EventListener")
                            {
                                var eventName = mem.name.Substring(2) + "Event";
                                var eventType = findType(eventName, true);
                                if (eventType != null)
                                {
                                    mem.resultType.name        = "EventListener";
                                    mem.resultType.genericType = new TType()
                                    {
                                        name = eventType.name
                                    };
                                }
                            }
                        }
                    }
                }
            }

            foreach (var pFile in parsedFiles)
            {
                //pFile.removeUnknownTypes();
                foreach (var ns in pFile.nsList)
                {
                    foreach (var t in ns.types)
                    {
                        t.checkConvertToInterface();
                        t.generateConstructors();
                    }
                }
            }

            foreach (var pFile in parsedFiles)
            {
                foreach (var ns in pFile.nsList)
                {
                    foreach (var t in ns.types)
                    {
                        t.checkGenerateEnumerator();
                    }
                }
            }

            foreach (var pFile in parsedFiles)
            {
                pFile.saveFile();
            }

            Console.WriteLine("ready");
            Console.ReadKey();
        }
Beispiel #4
0
        public static void start()
        {
            if (Program.runW3CXMLPreProcess)
            {
                PreprocessW3CXML();
            }

            if (!Directory.Exists(Program.idlOutTempDirectory))
            {
                Directory.CreateDirectory(Program.idlOutTempDirectory);
            }
            if (!Directory.Exists(Program.csOutDirectory))
            {
                Directory.CreateDirectory(Program.csOutDirectory);
            }

            TScriptTokenizer.SharedInit();

            convertDirectory(Program.idlInDirectory, Program.csOutDirectory);

            foreach (var pFile in parsedFiles)
            {
                foreach (var ns in pFile.nsList)
                {
                    foreach (var t in ns.types)
                    {
                        foreach (var attr in t.attributes)
                        {
                            if (attr is TNameAttribute)
                            {
                                var nameAttr = attr as TNameAttribute;
                                if (nameAttr.name == "InterfaceName")
                                {
                                    t.rename(nameAttr.value);
                                    break;
                                }
                            }
                        }

                        var extraMethods = TransformationConfig.addMethodToType.ContainsKey(t.name) ? TransformationConfig.addMethodToType[t.name] : null;
                        if (extraMethods != null)
                        {
                            foreach (var extraMethod in extraMethods)
                            {
                                extraMethod.parentType = t;
                                t.members.Add(extraMethod);
                            }
                        }

                        /*if (t.name == "Event")
                         * {
                         *  t.rename("DOMEvent");
                         *  t.aliasName = "Event";
                         * }*/

                        string newName;
                        if (TransformationConfig.renameType.TryGetValue(t.name, out newName))
                        {
                            t.aliasName = t.name;
                            t.rename(newName);
                        }

                        foreach (var entry in TransformationConfig.renameTypePrefix)
                        {
                            if (t.name.StartsWith(entry.Key))
                            {
                                t.aliasName = t.name;
                                t.rename(t.name.Replace(entry.Key, entry.Value));
                            }
                        }

                        foreach (var mem in t.members)
                        {
                            if (mem.name.StartsWith("on") && mem.resultType.name == "Function")
                            {
                                var eventName = mem.name.Substring(2) + "Event";
                                var eventType = findFileType(eventName, true);
                                eventName = char.ToUpper(eventName[0]) + eventName.Substring(1);
                                mem.comments.Add("Function that accepts an event of type <code>" + eventName + "</code>.");
                                if (eventType != null)
                                {
                                    mem.comments.Add("@see " + eventType.ns.name + "." + eventType.name);
                                    mem.resultType.name = "Function";
                                    //mem.resultType.genericType = new TType() { name = eventType.name };
                                }
                            }
                        }
                    }
                }
            }

            foreach (var pFile in parsedFiles)
            {
                //pFile.removeUnknownTypes();
                foreach (var ns in pFile.nsList)
                {
                    foreach (var t in ns.types)
                    {
                        t.checkConvertToInterface();
                        if (t.name == "SVGLocatable")
                        {
                            t.convertToInterface();
                        }
                        t.generateConstructors();
                        t.disambiguateMethodNames();
                        t.generateComments();
                        t.generateMemberComments();
                        t.mergeConstructors();
                    }
                }
            }

            foreach (var pFile in parsedFiles)
            {
                foreach (var ns in pFile.nsList)
                {
                    foreach (var t in ns.types)
                    {
                        t.checkGenerateEnumerator();
                        if (t.name == "Window")
                        {
                            t.jsAttributes.Add(new TJsAttribute()
                            {
                                name = "mode", value = "\"global\""
                            });
                            foreach (var m in t.members)
                            {
                                m.isStatic = true;
                            }
                        }
                    }
                }
            }

            foreach (var pFile in parsedFiles)
            {
                foreach (var ns in pFile.nsList)
                {
                    foreach (var t in ns.types)
                    {
                        if (!hasConstructor(t))
                        {
                            t.createSubConstructors();
                        }
                        t.removeMembersAlreadyPresentInBaseTypes();
                    }
                }
            }

            foreach (var pFile in parsedFiles)
            {
                pFile.saveFile();
            }

            Console.WriteLine("ready");
            Console.ReadKey();
        }