Esempio n. 1
0
        public static void GenerateCode()
        {
            var lexer = new Mq4Lexer();
            var resultTokens = lexer.BuildTextTokens(ScriptUtils.ComplexCode);

            var parser = new Mq4Parser();
            var astTree = parser.Parse(resultTokens);
            var semantic = new SemanticAnalysis(astTree);
            semantic.Perform();

            var codeGenerator = new CsCodeGenerator();
            codeGenerator.GenerateCodeForNode(astTree.Children[0]);
        }
Esempio n. 2
0
 public Mq4Translator()
 {
     _lexer = new Mq4Lexer();
     _parser = new Mq4Parser();
     _codeGenerator = new CsCodeGenerator();
 }
Esempio n. 3
0
    public static int Main(string[] args)
    {
        string outputPath = AppContext.BaseDirectory;

        if (args.Length > 0)
        {
            outputPath = args[0];
        }

        if (!Path.IsPathRooted(outputPath))
        {
            outputPath = Path.Combine(AppContext.BaseDirectory, outputPath);
        }

        if (!Directory.Exists(outputPath))
        {
            Directory.CreateDirectory(outputPath);
        }

        string?headerFile = Path.Combine(AppContext.BaseDirectory, "vulkan", "vulkan.h");
        var    options    = new CppParserOptions
        {
            ParseMacros = true,
            Defines     =
            {
                "VK_USE_PLATFORM_ANDROID_KHR",
                "VK_USE_PLATFORM_IOS_MVK",
                "VK_USE_PLATFORM_MACOS_MVK",
                "VK_USE_PLATFORM_METAL_EXT",
                "VK_USE_PLATFORM_VI_NN",
                //"VK_USE_PLATFORM_WAYLAND_KHR",
                //"VK_USE_PLATFORM_WIN32_KHR",
                //"VK_USE_PLATFORM_SCREEN_QNX",
                "VK_ENABLE_BETA_EXTENSIONS"
            }
        };

        var compilation = CppParser.ParseFile(headerFile, options);

        // Print diagnostic messages
        if (compilation.HasErrors)
        {
            foreach (var message in compilation.Diagnostics.Messages)
            {
                if (message.Type == CppLogMessageType.Error)
                {
                    var currentColor = Console.ForegroundColor;
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(message);
                    Console.ForegroundColor = currentColor;
                }
            }

            return(0);
        }

        bool generateFuncFile = false;

        if (generateFuncFile)
        {
            File.Delete("Vk.txt");
            foreach (var func in compilation.Functions)
            {
                var signature    = new System.Text.StringBuilder();
                var argSignature = CsCodeGenerator.GetParameterSignature(func, true);
                signature
                .Append(func.ReturnType.GetDisplayName())
                .Append(" ")
                .Append(func.Name)
                .Append("(")
                .Append(argSignature)
                .Append(")");
                File.AppendAllText("Vk.txt", signature.ToString() + Environment.NewLine);
            }
        }

        CsCodeGenerator.Generate(compilation, outputPath);
        return(0);
    }
Esempio n. 4
0
        void GenerateSource(IEnumerable<string> files, string nameSpace, string extension, out string[] sourceFiles)
        {
            List<string> sources = new List<string>();
            foreach (string inputXml in files)
            {
                NClassifyConfig config = NClassifyConfig.Read(inputXml, nameSpace);

                CsCodeGenerator gen = new CsCodeGenerator(config);
                string srcfile = Path.ChangeExtension(config.FilePath, extension ?? ".cs");
                using (TextWriter wtr = File.CreateText(srcfile))
                    gen.GenerateCode(wtr);

                sources.Add(srcfile);
            }
            sourceFiles = sources.ToArray();
        }