public static async Task ConvertFolderAsync(string sourcePath, string targetPath, ILogger logger) { try { var fs = new FileSystem(); var options = new Dictionary <string, object>(); var typeAnalysis = new AnalyzerImpl(fs, logger, options, DateTime.Now); typeAnalysis.Analyze(sourcePath); typeAnalysis.Finish(); var types = new TypeReferenceTranslator(typeAnalysis.BuildTypeDictionary()); var walker = new DirectoryWalker(fs, sourcePath, "*.py"); await walker.EnumerateAsync(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); var relativePath = MakeRelative(sourcePath, path); var targetFilePath = Path.ChangeExtension(MakeAbsolute(targetPath, relativePath), ".py.cs"); var targetFileDirectory = Path.GetDirectoryName(targetFilePath); if (!Directory.Exists(targetFileDirectory)) { Directory.CreateDirectory(targetFileDirectory); } xlator.TranslateModuleStatements( module.body.stmts, types, targetFilePath); } }); logger.Inform(Resources.Done); } catch (Exception ex) { logger.Error(Resources.ErrUnexpectedConversionError, ex.Message); logger.Inform(Resources.ConversionWasAborted); } }
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"); } } }
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"); } } }
public void TypeAn_Empty() { an.Analyze("\\foo"); }
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"); } } }