Example #1
0
        public TAttributeList readAttributes()
        {
            var attrList = new TAttributeList();

            getNextToken();
            if (currentToken.token == ECodeToken.brSmallBraceEnd)
            {
                getNextToken();
                return(attrList);
            }
            while (true)
            {
                var attr = readAttribute();
                if (attr != null)
                {
                    attrList.Add(attr);
                }
                if (currentToken.token == ECodeToken.syComma)
                {
                    getNextToken();
                }
                if (currentToken.token == ECodeToken.brSmallBraceEnd)
                {
                    getNextToken();
                    break;
                }
            }
            return(attrList);
        }
Example #2
0
 public TAttributeList readAttributes()
 {
     var attrList = new TAttributeList();
     getNextToken();
     if (currentToken.token == ECodeToken.brSmallBraceEnd)
     {
         getNextToken();
         return attrList;
     }
     while (true)
     {
         var attr = readAttribute();
         if (attr != null) attrList.Add(attr);
         if (currentToken.token == ECodeToken.syComma) getNextToken();
         if (currentToken.token == ECodeToken.brSmallBraceEnd)
         {
             getNextToken();
             break;
         }
     }
     return attrList;
 }
Example #3
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;
                }
            }

        }
Example #4
0
        private TMember readMember()
        {
            bool vStatic = false;
            bool vConst = false;
            bool vFinal = false;
            bool vReadonly = false;
            bool vAttribute = false;
            TType type = null;
            string name = "";
            TMember mem = null;
            var attrList = new TAttributeList();
            while (true)
            {
                switch (currentToken.token)
                {
                    case ECodeToken.brSmallBraceBegin:
                        attrList = readAttributes();
                        break;
                    case ECodeToken.kwStatic:
                        vStatic = true;
                        getNextToken();
                        break;
                    case ECodeToken.kwConst:
                        vConst = true;
                        getNextToken();
                        break;
                    case ECodeToken.kwAttribute:
                        vAttribute = true;
                        getNextToken();
                        break;
                    case ECodeToken.kwReadonly:
                        vReadonly = true;
                        getNextToken();
                        break;
                    //case ECodeToken.kwFinal:
                    //  vFinal = true;
                    //  break;
                    case ECodeToken.ltString:
                        type = readType();
                        name = currentToken.value;

                        getNextToken();
                        if (currentToken.token == ECodeToken.brBraceBegin)
                        {
                            mem = new TMethod(currentInterfaceType);
                            mem.name = name;
                            mem.resultType = type;
                            mem.attributes = attrList;
                            readParameters((TMethod)mem);
                            checkGotoEndOfStatement();
                        }
                        else
                        {
                            if (vAttribute)
                            {
                                mem = new TProperty(currentInterfaceType);
                                mem.name = name;
                                mem.resultType = type;
                                mem.attributes = attrList;
                                checkGotoEndOfStatement();
                                return mem;
                            }
                            else
                            {
                                mem = new TField(currentInterfaceType);
                                mem.name = name;
                                mem.resultType = type;
                                mem.attributes = attrList;
                                if (currentToken.token == ECodeToken.blEquals)
                                {
                                    getNextToken();
                                    string Value = currentToken.value;
                                    getNextToken();
                                    if (currentToken.token == ECodeToken.ltString)
                                    {
                                        Value += currentToken.value;
                                        if (Value.ToLower() == "0xffffffff")
                                        {
                                            Value = "0xFFFFFFF";
                                        }
                                    }
                                    ((TField)mem).value = Value;
                                }
                                return mem;
                            }
                        }
                        break;
                    default:
                        getNextToken();
                        break;
                }
                if (currentToken.token == ECodeToken.syEndOfCommand)
                {
                    break;
                }
            }
            return mem;
        }
Example #5
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;
                }
            }
        }
Example #6
0
        private TMember readMember()
        {
            bool    vStatic    = false;
            bool    vConst     = false;
            bool    vFinal     = false;
            bool    vReadonly  = false;
            bool    vAttribute = false;
            TType   type       = null;
            string  name       = "";
            TMember mem        = null;
            var     attrList   = new TAttributeList();

            while (true)
            {
                switch (currentToken.token)
                {
                case ECodeToken.brSmallBraceBegin:
                    attrList = readAttributes();
                    break;

                case ECodeToken.kwStatic:
                    vStatic = true;
                    getNextToken();
                    break;

                case ECodeToken.kwConst:
                    vConst = true;
                    getNextToken();
                    break;

                case ECodeToken.kwAttribute:
                    vAttribute = true;
                    getNextToken();
                    break;

                case ECodeToken.kwReadonly:
                    vReadonly = true;
                    getNextToken();
                    break;

                //case ECodeToken.kwFinal:
                //  vFinal = true;
                //  break;
                case ECodeToken.ltString:
                    type = readType();
                    name = currentToken.value;

                    getNextToken();
                    if (currentToken.token == ECodeToken.brBraceBegin)
                    {
                        mem            = new TMethod(currentInterfaceType);
                        mem.name       = name;
                        mem.resultType = type;
                        mem.attributes = attrList;
                        readParameters((TMethod)mem);
                        checkGotoEndOfStatement();
                    }
                    else
                    {
                        if (vAttribute)
                        {
                            mem            = new TProperty(currentInterfaceType);
                            mem.name       = name;
                            mem.resultType = type;
                            mem.attributes = attrList;
                            var prop = (TProperty)mem;
                            prop.canWrite = !vReadonly;
                            checkGotoEndOfStatement();
                            return(mem);
                        }
                        else
                        {
                            mem            = new TField(currentInterfaceType);
                            mem.name       = name;
                            mem.resultType = type;
                            mem.attributes = attrList;
                            if (currentToken.token == ECodeToken.blEquals)
                            {
                                getNextToken();
                                string Value = currentToken.value;
                                getNextToken();
                                if (currentToken.token == ECodeToken.ltString)
                                {
                                    Value += currentToken.value;
                                    if (Value.ToLower() == "0xffffffff")
                                    {
                                        Value = "0xFFFFFFF";
                                    }
                                }
                                ((TField)mem).value = Value;
                            }
                            return(mem);
                        }
                    }
                    break;

                default:
                    getNextToken();
                    break;
                }
                if ((currentToken == null) || (currentToken.token == ECodeToken.syEndOfCommand))
                {
                    break;
                }
            }
            return(mem);
        }