Example #1
0
        static void Main(string[] args)
        {
            var fs     = new FileSystem();
            var logger = new ConsoleLogger();

            if (args.Length == 0)
            {
                var xlator = new Translator("", "module_name", fs, logger);
                xlator.Translate("-", Console.In, Console.Out);
                Console.Out.Flush();
                return;
            }

            if (args[0].ToLower() == "-d")
            {
                //             org.yinwang.pysonar.demos.Demo.DemoMain(args);
                return;
            }

            if (args[0].ToLower() == "-r")
            {
#if !NOT_READY_FOR_TYPES
                var options      = new Dictionary <string, object>();
                var typeAnalysis = new AnalyzerImpl(fs, logger, options, DateTime.Now);
                typeAnalysis.Analyze(".");
                typeAnalysis.Finish();
                TranslateModules(typeAnalysis);
#else
                var startDir = args.Length == 2
                    ? args[1]
                    : Directory.GetCurrentDirectory();
                var walker = new DirectoryWalker(fs, startDir, "*.py");
                walker.Enumerate();
#endif
            }
            else
            {
                foreach (var fileName in args)
                {
                    var xlator = new Translator(
                        "",
                        fs.GetFileNameWithoutExtension(fileName),
                        fs,
                        new ConsoleLogger());
                    xlator.TranslateFile(fileName, fileName + ".cs");
                }
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            var fs = new FileSystem();
            var logger = new ConsoleLogger();
            if (args.Length == 0)
            {
                var xlator = new Translator("", "module_name", fs, logger);
                xlator.Translate("-", Console.In, Console.Out);
                Console.Out.Flush();
                return;
            }

            if (args[0].ToLower() == "-d")
            {
               //             org.yinwang.pysonar.demos.Demo.DemoMain(args);
                return;
            }

            if (args[0].ToLower() == "-r")
            {
            #if READY_FOR_TYPES
                var typeAnalysis = new Pytocs.TypeInference.AnalyzerImpl(fs, logger, new Dictionary<string, object>(), DateTime.Now);
                typeAnalysis.Analyze(".");
                TranslateModules(typeAnalysis);
            #else
                var walker = new DirectoryWalker("*.py");
                walker.Enumerate();
            #endif
            }
            else
            {
                foreach (var fileName in args)
                {
                    var xlator = new Translator(
                        "",
                        Path.GetFileNameWithoutExtension(fileName),
                        new FileSystem(),
                        new ConsoleLogger());
                    xlator.TranslateFile(fileName, fileName + ".cs");
                }
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            var fs     = new FileSystem();
            var logger = new ConsoleLogger();

            if (args.Length == 0)
            {
                var xlator = new Translator("", "module_name", fs, logger);
                xlator.Translate("-", Console.In, Console.Out);
                Console.Out.Flush();
                return;
            }

            if (args[0].ToLower() == "-r")
            {
                var startDir = args.Length == 2
                    ? args[1]
                    : Directory.GetCurrentDirectory();
                var options = new Dictionary <string, object>();
#if !NOT_READY_FOR_TYPES
                var typeAnalysis = new AnalyzerImpl(fs, logger, options, DateTime.Now);
                typeAnalysis.Analyze(startDir);
                typeAnalysis.Finish();
                var types = new TypeReferenceTranslator(
                    typeAnalysis.BuildTypeDictionary());
                //Console.WriteLine($"== Type dictionary: {types.Count}");
                //foreach (var de in types.OrderBy(d => d.Key.ToString()))
                //{
                //    Console.WriteLine("{0}: {1} {2}", de.Key, de.Key.Start, de.Value);
                //}

                var walker = new DirectoryWalker(fs, startDir, "*.py");
                walker.Enumerate(state =>
                {
                    foreach (var file in fs.GetFiles(state.DirectoryName, "*.py", SearchOption.TopDirectoryOnly))
                    {
                        var path   = fs.GetFullPath(file);
                        var xlator = new Translator(
                            state.Namespace,
                            fs.GetFileNameWithoutExtension(file),
                            fs,
                            logger);
                        var module = typeAnalysis.GetAstForFile(path);
                        xlator.TranslateModuleStatements(
                            module.body.stmts,
                            types,
                            Path.ChangeExtension(path, ".py.cs"));
                    }
                });
#else
                var walker = new DirectoryWalker(fs, startDir, "*.py");
                walker.Enumerate(walker.ProcessDirectoryFiles);
#endif
            }
            else
            {
                foreach (var fileName in args)
                {
                    var xlator = new Translator(
                        "",
                        fs.GetFileNameWithoutExtension(fileName),
                        fs,
                        new ConsoleLogger());
                    xlator.TranslateFile(fileName, fileName + ".cs");
                }
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            var fs     = new FileSystem();
            var logger = new ConsoleLogger();

            if (args.Length == 0)
            {
                var xlator = new Translator("", "module_name", fs, logger);
                xlator.Translate("-", Console.In, Console.Out);
                Console.Out.Flush();
                return;
            }

            if (args[0].ToLower() == "-r")
            {
#if NOT_READY_FOR_TYPES
                var options      = new Dictionary <string, object>();
                var typeAnalysis = new AnalyzerImpl(fs, logger, options, DateTime.Now);
                typeAnalysis.Analyze(".");
                typeAnalysis.Finish();

                var startDir = args.Length == 2
                    ? args[1]
                    : Directory.GetCurrentDirectory();
                var walker = new DirectoryWalker(fs, startDir, "*.py");
                walker.Enumerate(state =>
                {
                    foreach (var file in fs.GetFiles(state.DirectoryName, "*.py", SearchOption.TopDirectoryOnly))
                    {
                        var path   = fs.GetFullPath(file);
                        var xlator = new Translator(
                            state.Namespace,
                            fs.GetFileNameWithoutExtension(file),
                            fs,
                            new ConsoleLogger());
                        var module        = typeAnalysis.GetAstForFile(path);
                        var moduleBinding = typeAnalysis.ModuleTable.Values.SelectMany(s => s).FirstOrDefault(b => b.node == module);
                        xlator.TranslateModuleStatements(
                            module.body.stmts,
                            moduleBinding.type.Table,
                            Path.ChangeExtension(path, ".cs"));
                    }
                });
#else
                var startDir = args.Length == 2
                    ? args[1]
                    : Directory.GetCurrentDirectory();
                var walker = new DirectoryWalker(fs, startDir, "*.py");
                walker.Enumerate(walker.ProcessDirectoryFiles);
#endif
            }
            else
            {
                foreach (var fileName in args)
                {
                    var xlator = new Translator(
                        "",
                        fs.GetFileNameWithoutExtension(fileName),
                        fs,
                        new ConsoleLogger());
                    xlator.TranslateFile(fileName, fileName + ".cs");
                }
            }
        }