Пример #1
0
        private List <INamedTypeSymbol> GetSymbolsForManagedApi()
        {
            CSharpCompilation compilation = NativeCefApiTypes.CompileNativeClasses(_basePath);

            compilation = CompileManagedClasses(compilation);
            GetAllSymbolsVisitor visitor = new GetAllSymbolsVisitor();

            visitor.Visit(compilation.Assembly.GlobalNamespace);
            return(visitor.GetSymbols());
        }
Пример #2
0
        private CSharpCompilation CompileManagedClasses(CSharpCompilation compilation)
        {
            var syntaxTrees = new List <SyntaxTree>();

            NativeCefApiTypes.AddFilesToSyntaxTrees(syntaxTrees, Path.Combine(_basePath, "Managed", "Types"));
            AddPrivateInterfaceFilesToSyntaxTrees(syntaxTrees, Path.Combine(_basePath, "Managed", "Internal"));
            syntaxTrees.Add(SyntaxFactory.ParseSyntaxTree(SourceText.From(File.ReadAllText(Path.Combine(_basePath, "..", "CefTypes", "CefBaseRefCounted.cs")))));
            syntaxTrees.Add(SyntaxFactory.ParseSyntaxTree(SourceText.From(File.ReadAllText(Path.Combine(_basePath, "..", "CefTypes", "CefBaseScoped.cs")))));
            syntaxTrees.Add(SyntaxFactory.ParseSyntaxTree(SourceText.From(File.ReadAllText(Path.Combine(_basePath, "..", "CefTypes", "CefColor.cs")))));
            syntaxTrees.Add(SyntaxFactory.ParseSyntaxTree(SourceText.From(File.ReadAllText(Path.Combine(_basePath, "..", "CefTypes", "CefStringList.cs")))));
            syntaxTrees.Add(SyntaxFactory.ParseSyntaxTree(SourceText.From(File.ReadAllText(Path.Combine(_basePath, "..", "CefTypes", "CefStringMap.cs")))));
            syntaxTrees.Add(SyntaxFactory.ParseSyntaxTree(SourceText.From(File.ReadAllText(Path.Combine(_basePath, "..", "CefString.cs")))));
            syntaxTrees.Add(SyntaxFactory.ParseSyntaxTree(SourceText.From(File.ReadAllText(Path.Combine(_basePath, "..", "CefStructure.cs")))));
            syntaxTrees.Add(SyntaxFactory.ParseSyntaxTree(SourceText.From(File.ReadAllText(Path.Combine(_basePath, "..", "CefTypes", "CApi", "cef_string_t.cs")))));
            syntaxTrees.Add(SyntaxFactory.ParseSyntaxTree(SourceText.From(File.ReadAllText(Path.Combine(_basePath, "..", "Unsafe", "RefCountedWrapperStruct.cs")))));
            syntaxTrees.Add(SyntaxFactory.ParseSyntaxTree(SourceText.From(File.ReadAllText(Path.Combine(_basePath, "..", "Unsafe", "CefWrapperType.cs")))));
            syntaxTrees.Add(SyntaxFactory.ParseSyntaxTree(SourceText.From("namespace System { static class Ext111 { public static void InitBlock(this IntPtr startAddress, byte value, int size) { } } }")));
            syntaxTrees.Add(SyntaxFactory.ParseSyntaxTree(SourceText.From("using CefNet.CApi; namespace CefNet { public unsafe class CefWindowInfo { public cef_window_info_t* GetNativeInstance() { return null; } public static CefWindowInfo Wrap(cef_window_info_t* p) { return null; } } }")));
            syntaxTrees.Add(SyntaxFactory.ParseSyntaxTree(SourceText.From("namespace CefNet { public class InvalidCefObjectException : System.Exception { } }")));
            syntaxTrees.Add(SyntaxFactory.ParseSyntaxTree(SourceText.From("namespace CefNet { public class CefApi { public static bool UseUnsafeImplementation; } }")));
            syntaxTrees.Add(SyntaxFactory.ParseSyntaxTree(SourceText.From("using CefNet.CApi; namespace CefNet { public class CefStringMultimap { cef_string_multimap_t a; public static implicit operator cef_string_multimap_t(CefStringMultimap a) { return a.a; } } }")));

            compilation = compilation.AddSyntaxTrees(syntaxTrees);

            using (var ms = new MemoryStream())
            {
                EmitResult emitResult = compilation.Emit(ms);
                if (!emitResult.Success)
                {
                    foreach (var diag in emitResult.Diagnostics)
                    {
                        Console.WriteLine(diag);
                    }
                    Debugger.Break();
                    Environment.Exit(-1);
                }
            }

            return(compilation);
        }
Пример #3
0
        static void Main(string[] args)
        {
            string cefPath     = null;
            string outDirPath  = null;
            string projectPath = GetProjectPath();

            bool onlyStdCall = false;

            foreach (string arg in args)
            {
                if (arg.StartsWith("--"))
                {
                    if (arg.StartsWith("--out="))
                    {
                        outDirPath = arg.Substring(6);
                    }
                    if (arg == "--stdcall")
                    {
                        onlyStdCall = true;
                    }
                    continue;
                }
                else if (cefPath == null)
                {
                    cefPath = arg;
                }
            }

            if (string.IsNullOrWhiteSpace(cefPath))
            {
                cefPath = Path.Combine(projectPath, "..", "cef");
            }
            else
            {
                cefPath = cefPath.Trim();
            }
            if (!Directory.Exists(cefPath))
            {
                Console.WriteLine("Could not find the CEF directory.");
                Environment.Exit(-1);
                return;
            }

            if (string.IsNullOrWhiteSpace(outDirPath))
            {
                outDirPath = Path.Combine(projectPath, "..", "CefNet", "Generated");
            }
            else
            {
                outDirPath = outDirPath.Trim();
            }
            if (!Directory.Exists(Path.GetDirectoryName(outDirPath)))
            {
                Console.WriteLine("Could not create the output directory.");
                Environment.Exit(-1);
                return;
            }

            Clean(outDirPath);

            Console.WriteLine("Generate unsafe types...");
            GenerateFromCHeaders(cefPath, outDirPath, onlyStdCall);

            Console.WriteLine("Compile unsafe types...");
            var nativeTypes = new NativeCefApiTypes(outDirPath);

            nativeTypes.Build();

            Console.WriteLine("Generate wrappers...");
            var managedApiBuilder = new ManagedCefApiBuilder(outDirPath);

            managedApiBuilder.Imports.Add("CefNet.CApi");
            managedApiBuilder.Imports.Add("CefNet.Internal");
            managedApiBuilder.EnableCallbackOverrideCheck = true;
            managedApiBuilder.GenerateFrom(nativeTypes);

            Console.WriteLine("Generate glue classes...");
            var cefnetGen = new CefNetCodeGen(outDirPath);

            cefnetGen.Generate();

            Console.WriteLine("Compile wrappers...");
            var managedTypes = new ManagedCefApiTypes(outDirPath);

            managedTypes.Build();

            Console.WriteLine("Generate MSIL for wrappers...");
            var msilGen = new ManagedCefApiMsilCodeGen(outDirPath);

            msilGen.GenerateFrom(managedTypes);

            Console.WriteLine("Complete.");
        }