private Dictionary <Uri, ParseResult> ParseSrcInternal(string srcPath, int maxConcurrency = 1) { var parseResults = new Dictionary <Uri, ParseResult>(); foreach (var kvp in externals) { parseResults[kvp.Key] = kvp.Value; } var absoluteSrcFilePath = Path.GetFullPath(srcPath); if (maxConcurrency <= 1) { foreach (var f in SrcFileHelper.LoadScriptsFilePaths(absoluteSrcFilePath)) { if (!File.Exists(f)) { continue; } //var fileUri = new Uri(Uri.EscapeDataString(f)); var result = LoadFile(f, false, parseResults.Values); var fileUriWithColonEncoded = new Uri(f).AbsoluteUri.Replace(":", "%3A").Replace("file%3A///", "file:///"); parseResults.Add(new Uri(fileUriWithColonEncoded), result); } } return(parseResults); }
public Compiler(CompilationOptions options) { _scriptPaths = new List <string>(); string absoluteSrcFilePath = Path.GetFullPath(options.SrcFilePath); _runtimePath = options.RuntimePath; if (_runtimePath == String.Empty) { string srcFileNameLowerWithoutExtension = Path.GetFileNameWithoutExtension(absoluteSrcFilePath).ToLower(); _runtimePath = Path.Combine(GetBuiltinsPath(), srcFileNameLowerWithoutExtension + ".d"); } if (File.Exists(_runtimePath)) { _scriptPaths.Add(_runtimePath); } else { if (_verbose && options.RuntimePath != String.Empty) { Console.WriteLine($"Specified runtime {_runtimePath} doesn't exist."); } _runtimePath = null; } _scriptPaths.AddRange(SrcFileHelper.LoadScriptsFilePaths(absoluteSrcFilePath)); _outputPathDat = options.OutputPathDat; _generateOutputUnits = options.GenerateOutputUnits; _outputPathOuDir = options.OutputPathOuDir; _zenPaths = options.ZenPaths; _strictSyntax = options.StrictSyntax; _globallySuppressedCodes = options.GloballySuppressedCodes; _verbose = options.Verbose; if (_generateOutputUnits) { _ouBuilder = new OutputUnitsBuilder(_verbose); } DatFile = null; _errorLogger = new StdErrorLogger(); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); }
public bool CompileFromSrc( string srcFilePath, bool compileToAssembly, bool verbose = true, bool generateOutputUnits = true ) { var absoluteSrcFilePath = Path.GetFullPath(srcFilePath); try { string[] paths = SrcFileHelper.LoadScriptsFilePaths(absoluteSrcFilePath).ToArray(); string srcFileName = Path.GetFileNameWithoutExtension(absoluteSrcFilePath).ToLower(); string runtimePath = Path.Combine(GetBuiltinsPath(), srcFileName + ".d"); if (File.Exists(runtimePath)) { _assemblyBuilder.IsCurrentlyParsingExternals = true; if (verbose) { Console.WriteLine($"[0/{paths.Length}]Compiling runtime: {runtimePath}"); } DaedalusParser parser = GetParserForScriptsFile(runtimePath); ParseTreeWalker.Default.Walk(new DaedalusListener(_assemblyBuilder, 0), parser.daedalusFile()); _assemblyBuilder.IsCurrentlyParsingExternals = false; } for (int i = 0; i < paths.Length; i++) { if (verbose) { Console.WriteLine($"[{i + 1}/{paths.Length}]Compiling: {paths[i]}"); } string fileContent = GetFileContent(paths[i]); DaedalusParser parser = GetParserForText(fileContent); _assemblyBuilder.ErrorContext.FileContentLines = fileContent.Split(Environment.NewLine); _assemblyBuilder.ErrorContext.FilePath = paths[i]; _assemblyBuilder.ErrorContext.FileIndex = i; ParseTreeWalker.Default.Walk(new DaedalusListener(_assemblyBuilder, i), parser.daedalusFile()); if (generateOutputUnits) { _ouBuilder.ParseText(fileContent); } } if (!compileToAssembly) { Directory.CreateDirectory(_outputDirPath); } if (generateOutputUnits) { _ouBuilder.SaveOutputUnits(_outputDirPath); } _assemblyBuilder.Finish(); if (_assemblyBuilder.Errors.Any()) { _assemblyBuilder.Errors.Sort((x, y) => x.CompareTo(y)); string lastErrorFilePath = ""; string lastErrorBlockName = null; var logger = new StdErrorLogger(); foreach (CompilationMessage error in _assemblyBuilder.Errors) { if (lastErrorFilePath != error.FilePath) { lastErrorFilePath = error.FilePath; Console.WriteLine(error.FilePath); } if (lastErrorBlockName != error.ExecBlockName) { lastErrorBlockName = error.ExecBlockName; if (error.ExecBlockName == null) { Console.WriteLine($"{error.FileName}: In global scope:"); } else { Console.WriteLine($"{error.FileName}: In {error.ExecBlockType} ‘{error.ExecBlockName}’:"); } } error.Print(logger); } return(false); } if (compileToAssembly) { Console.WriteLine(_assemblyBuilder.GetAssembler()); } else { Directory.CreateDirectory(_outputDirPath); string datPath = Path.Combine(_outputDirPath, srcFileName + ".dat"); _assemblyBuilder.SaveToDat(datPath); } return(true); } catch (Exception exc) { Console.WriteLine("SRC compilation failed"); Console.WriteLine($"{exc}"); return(false); } }