示例#1
0
        public static bool Compile(DMCompilerSettings settings)
        {
            ErrorCount   = 0;
            WarningCount = 0;
            Settings     = settings;
            if (Settings.Files == null)
            {
                return(false);
            }

            //TODO: Only use InvariantCulture where necessary instead of it being the default
            CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;

            _compileStartTime = DateTime.Now;

            if (settings.SuppressUnimplementedWarnings)
            {
                Warning(new CompilerWarning(Location.Internal, "Unimplemented proc & var warnings are currently suppressed"));
            }

            DMPreprocessor preprocessor      = Preprocess(settings.Files);
            bool           successfulCompile = preprocessor is not null && Compile(preprocessor);

            if (successfulCompile)
            {
                //Output file is the first file with the extension changed to .json
                string outputFile        = Path.ChangeExtension(settings.Files[0], "json");
                List <DreamMapJson> maps = ConvertMaps(preprocessor.IncludedMaps);

                if (ErrorCount > 0)
                {
                    successfulCompile = false;
                }
                else
                {
                    var output = SaveJson(maps, preprocessor.IncludedInterface, outputFile);
                    if (ErrorCount > 0)
                    {
                        successfulCompile = false;
                    }
                    else
                    {
                        Console.WriteLine($"Compilation succeeded with {WarningCount} warnings");
                        Console.WriteLine(output);
                    }
                }
            }
            if (!successfulCompile)
            {
                Console.WriteLine($"Compilation failed with {ErrorCount} errors and {WarningCount} warnings");
            }

            TimeSpan duration = DateTime.Now - _compileStartTime;

            Console.WriteLine($"Total time: {duration.ToString(@"mm\:ss")}");

            return(successfulCompile);
        }
示例#2
0
        public static bool Compile(DMCompilerSettings settings)
        {
            Settings = settings;
            if (Settings.Files == null)
            {
                return(false);
            }

            //TODO: Only use InvariantCulture where necessary instead of it being the default
            CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;

            _compileStartTime = DateTime.Now;

            if (settings.SuppressUnimplementedWarnings)
            {
                Warning(new CompilerWarning(Location.Unknown, "Unimplemented proc & var warnings are currently suppressed"));
            }

            DMPreprocessor preprocessor = Preprocess(settings.Files);

            if (settings.DumpPreprocessor)
            {
                StringBuilder result = new();
                foreach (Token t in preprocessor.GetResult())
                {
                    result.Append(t.Text);
                }

                string output = Path.Join(Path.GetDirectoryName(settings.Files?[0]) ?? AppDomain.CurrentDomain.BaseDirectory, "preprocessor_dump.dm");
                File.WriteAllText(output, result.ToString());
                Console.WriteLine($"Preprocessor output dumped to {output}");
            }

            bool successfulCompile = preprocessor is not null && Compile(preprocessor.GetResult());

            if (successfulCompile)
            {
                Console.WriteLine($"Compilation succeeded with {WarningCount} warnings");

                //Output file is the first file with the extension changed to .json
                string outputFile        = Path.ChangeExtension(settings.Files[0], "json");
                List <DreamMapJson> maps = ConvertMaps(preprocessor.IncludedMaps);

                SaveJson(maps, preprocessor.IncludedInterface, outputFile);
            }
            else
            {
                Console.WriteLine($"Compilation failed with {ErrorCount} errors and {WarningCount} warnings");
            }

            TimeSpan duration = DateTime.Now - _compileStartTime;

            Console.WriteLine($"Total time: {duration.ToString(@"mm\:ss")}");

            return(successfulCompile);
        }
示例#3
0
        private static bool TryParseArguments(string[] args, out DMCompilerSettings settings)
        {
            settings       = new();
            settings.Files = new List <string>();

            bool skipBad = args.Contains("--skip-bad-args");

            foreach (string arg in args)
            {
                switch (arg)
                {
                case "--suppress-unimplemented": settings.SuppressUnimplementedWarnings = true; break;

                case "--dump-preprocessor": settings.DumpPreprocessor = true; break;

                case "--no-standard": settings.NoStandard = true; break;

                case "--verbose": settings.Verbose = true; break;

                case "--skip-bad-args": break;

                default: {
                    string extension = Path.GetExtension(arg);

                    if (!String.IsNullOrEmpty(extension) && (extension == ".dme" || extension == ".dm"))
                    {
                        settings.Files.Add(arg);
                        Console.WriteLine($"Compiling {Path.GetFileName(arg)}");
                    }
                    else
                    {
                        if (skipBad)
                        {
                            DMCompiler.Warning(new CompilerWarning(Location.Internal, $"Invalid compiler arg '{arg}', skipping"));
                        }
                        else
                        {
                            Console.WriteLine($"Invalid arg '{arg}'");
                            return(false);
                        }
                    }

                    break;
                }
                }
            }

            if (settings.Files.Count == 0)
            {
                Console.WriteLine("At least one DME or DM file must be provided as an argument");
                return(false);
            }

            return(true);
        }