예제 #1
0
    private void Serialize(Parser.CefApiData apiData)
    {
        var formatter = new BinaryFormatter();
        var stream    = new FileStream(serializedApi, FileMode.Create, FileAccess.Write, FileShare.None);

        formatter.Serialize(stream, apiData);
        stream.Close();
    }
예제 #2
0
    public CefApiDeclarations GetDeclarations()
    {
        apiData = Deserialize();
        string hash = Parser.ApiParser.ParseApiHash();

        if (apiData == null || !hash.Equals(apiData.ApiHashUniversal))
        {
            var parser = new Parser.ApiParser();
            apiData = parser.Parse();
            Serialize(apiData);
        }
        return(BuildTypes());
    }
예제 #3
0
        private CefApiData ParsePlatformApi(string filename)
        {
            var platformApi = new CefApiData();

            platformApi.CefEnums     = new List <EnumData>();
            platformApi.CefStructs   = new List <StructData>();
            platformApi.CefFunctions = new List <FunctionData>();
            codeFiles.Clear();
            AddFile(filename);

            ParseStructs(StripComments(codeFiles[filename]), platformApi.CefStructs);
            ParseFunctions(StripComments(codeFiles[filename]), platformApi.CefFunctions);
            ParseComments(platformApi);
            return(platformApi);
        }
예제 #4
0
        public CefApiData Parse()
        {
            ParseCppHeaders();

            AddFile(System.IO.Path.Combine("cef", "include", "cef_version.h"));

            AddFile(System.IO.Path.Combine("cef", "include", "internal", "cef_types.h"));
            AddFile(System.IO.Path.Combine("cef", "include", "internal", "cef_time.h"));

            var files = Directory.GetFiles(System.IO.Path.Combine("cef", "include", "capi"));

            foreach (var f in files)
            {
                AddFile(f);
            }

            var enums   = new List <EnumData>();
            var structs = new List <StructData>();
            var funcs   = new List <FunctionData>();

            ParseEnums(StripComments(codeFiles[System.IO.Path.Combine("cef", "include", "internal", "cef_types.h")]), enums);

            foreach (var cf in codeFiles)
            {
                var code = StripComments(cf.Value);
                ParseStructs(code, structs);
                if (cf.Key != System.IO.Path.Combine("cef", "include", "internal", "cef_time.h"))
                {
                    ParseFunctions(code, funcs);
                }
            }

            var api = new CefApiData();

            api.ApiHashUniversal = ParseApiHash();
            api.CefEnums         = enums;
            api.CefStructs       = structs;
            api.CefFunctions     = new List <FunctionData>();

            foreach (var f in funcs)
            {
                var cefStruct = MatchCefStructPrefix(f.Name, structs);
                if (cefStruct == null)
                {
                    api.CefFunctions.Add(f);
                }
                else
                {
                    cefStruct.CefFunctions.Add(f);
                }

                var token = ReduceToken(f.Name);
                if (booleanRetvals.Contains(token))
                {
                    f.Signature.ReturnType.Name = "bool";
                    //booleanRetvals.Remove(token)
                }
                foreach (var arg in f.Signature.Arguments)
                {
                    var t1 = token + ReduceToken(arg.Var);
                    if (booleanParameters.Contains(t1))
                    {
                        arg.ArgumentType.Name = "bool";
                        //booleanParameters.Remove(t1)
                    }
                }
            }

            foreach (var cefStruct in api.CefStructs)
            {
                var structToken = ReduceToken(cefStruct.Name.Substring(0, cefStruct.Name.Length - 2));
                if (cefConfigs.ContainsKey(structToken))
                {
                    cefStruct.CefConfig = cefConfigs[structToken];
                }

                foreach (var sm in cefStruct.StructMembers)
                {
                    if (sm.CallbackSignature != null)
                    {
                        var token = structToken + ReduceToken(sm.Name);

                        if (cefConfigs.ContainsKey(token))
                        {
                            sm.CefConfig = cefConfigs[token];
                            if (sm.CefConfig.CppApiName != null)
                            {
                                token = ReduceToken(cefStruct.Name.Substring(0, cefStruct.Name.Length - 2) + sm.CefConfig.CppApiName);
                            }
                        }

                        if (booleanRetvals.Contains(token))
                        {
                            sm.CallbackSignature.ReturnType.Name = "bool";
                            //booleanRetvals.Remove(token)
                        }
                        foreach (var arg in sm.CallbackSignature.Arguments)
                        {
                            var t1 = token + ReduceToken(arg.Var);
                            if (booleanParameters.Contains(t1))
                            {
                                arg.ArgumentType.Name = "bool";
                                //booleanParameters.Remove(t1)
                            }
                        }
                    }
                }
            }

            //If booleanRetvals.Count > 0 Then
            //    Stop
            //End If

            //If booleanParameters.Count > 0 Then
            //    Stop
            //End If

            var stringListCode     = File.ReadAllText(System.IO.Path.Combine("cef", "include", "internal", "cef_string_list.h"));
            var stringMapCode      = File.ReadAllText(System.IO.Path.Combine("cef", "include", "internal", "cef_string_map.h"));
            var stringMultiMapCode = File.ReadAllText(System.IO.Path.Combine("cef", "include", "internal", "cef_string_multimap.h"));

            funcs.Clear();
            ParseFunctions(stringListCode, funcs);
            ParseFunctions(stringMapCode, funcs);
            ParseFunctions(stringMultiMapCode, funcs);
            api.CefStringCollectionFunctions = funcs.ToArray();

            ParseComments(api);

            var pa = ParsePlatformApi(System.IO.Path.Combine("cef", "include", "internal", "cef_types_win.h"));

            api.CefFunctionsWindows = pa.CefFunctions;
            api.CefStructsWindows   = pa.CefStructs;

            pa = ParsePlatformApi(System.IO.Path.Combine("cef", "include", "internal", "cef_types_linux.h"));
            api.CefFunctionsLinux = pa.CefFunctions;
            api.CefStructsLinux   = pa.CefStructs;

            return(api);
        }
예제 #5
0
        private void ParseComments(CefApiData api)
        {
            var enums   = new Dictionary <string, EnumData>();
            var structs = new Dictionary <string, StructData>();

            foreach (var e in api.CefEnums)
            {
                enums.Add(e.Name, e);
            }

            foreach (var s in api.CefStructs)
            {
                structs.Add(s.Name, s);
            }

            var comments = new Dictionary <string, CommentData>();

            var regex = new Regex(commentPattern + "\\s*CEF_EXPORT\\s+.*?\\b(\\w+)\\s*\\(", RegexOptions.Multiline);

            foreach (var cf in codeFiles)
            {
                var file = cf.Key;
                var code = cf.Value;
                ParseComments(file, code, regex, comments);
            }

            foreach (var f in api.CefFunctions)
            {
                f.Comments = comments[f.Name];
            }

            foreach (var s in api.CefStructs)
            {
                foreach (var f in s.CefFunctions)
                {
                    f.Comments = comments[f.Name];
                }
            }

            comments.Clear();

            regex = new Regex(commentPattern + "\\s*typedef\\s+enum\\s*{[^}]+}\\s*(\\w+)_t\\s*;", RegexOptions.Multiline);

            var enumFile = System.IO.Path.Combine("cef", "include", "internal", "cef_types.h");

            if (codeFiles.ContainsKey(enumFile))
            {
                var enumCode = codeFiles[enumFile];
                ParseComments(enumFile, enumCode, regex, comments);
                foreach (var e in api.CefEnums)
                {
                    comments.TryGetValue(e.Name, out e.Comments);
                }

                comments.Clear();

                var enumBodyEx         = new Regex("typedef\\s+enum\\s*({[^}]+})\\s*(\\w+)_t\\s*;", RegexOptions.Singleline);
                var enumFieldCommentEx = new Regex(commentPattern + "\\s*\\b(\\w+)(?:\\s*=\\s*\\w+)?\\s*[,}]", RegexOptions.Multiline);

                var mm = enumBodyEx.Matches(enumCode);
                foreach (Match m in mm)
                {
                    var body = m.Groups[1].Value;
                    var name = m.Groups[2].Value;
                    ParseComments(enumFile, body, enumFieldCommentEx, comments);
                    var e = enums[name];
                    foreach (var member in e.Members)
                    {
                        comments.TryGetValue(member.Name, out member.Comments);
                    }
                    comments.Clear();
                }
            }

            regex = new Regex(commentPattern + "\\s*typedef\\s+struct\\s+_(cef_\\w+)\\b", RegexOptions.Multiline);

            foreach (var cf in codeFiles)
            {
                var file = cf.Key;
                var code = cf.Value;
                ParseComments(file, code, regex, comments);
            }

            foreach (var s in api.CefStructs)
            {
                s.Comments = comments[s.Name];
            }

            comments.Clear();

            var structBodyEx       = new Regex("typedef\\s+struct\\s+_(\\w+)\\s*{(.*?)}\\s*\\1\\s*;", RegexOptions.Singleline);
            var callbackCommentsEx = new Regex(commentPattern + "[^;]*CEF_CALLBACK\\s*\\*\\s*(\\w+)", RegexOptions.Multiline | RegexOptions.Compiled);
            var valueCommentsEx    = new Regex(commentPattern + "[^;]*\\b(\\w+)\\s*;", RegexOptions.Multiline | RegexOptions.Compiled);

            foreach (var cf in codeFiles)
            {
                var file = cf.Key;
                var code = cf.Value;

                var mm = structBodyEx.Matches(code);
                foreach (Match m in mm)
                {
                    var name = m.Groups[1].Value;
                    var body = m.Groups[2].Value;
                    var t    = structs[name];

                    ParseComments(file, body, callbackCommentsEx, comments);
                    foreach (var sm in t.StructMembers)
                    {
                        comments.TryGetValue(sm.Name, out sm.Comments);
                    }
                    comments.Clear();

                    ParseComments(file, body, valueCommentsEx, comments);
                    foreach (var sm in t.StructMembers)
                    {
                        if (sm.Comments == null)
                        {
                            comments.TryGetValue(sm.Name, out sm.Comments);
                        }
                    }
                    comments.Clear();
                }
            }
        }