Ejemplo n.º 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), 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;
                }
            }
        }