Esempio n. 1
0
        public static int Main(string[] args)
		{
            DateTime ldt = DateTime.Now;
            PascalABCCompiler.StringResourcesLanguage.LoadDefaultConfig();

            Compiler = new PascalABCCompiler.Compiler(null, null);
            StringResourcesLanguage.CurrentLanguageName = StringResourcesLanguage.AccessibleLanguages[0];
            //Console.WriteLine("OK {0}ms", (DateTime.Now - ldt).TotalMilliseconds);
            ldt = DateTime.Now;
            
            //ShowConnectedParsers();

            if (args.Length == 0)
            {
                Console.WriteLine(StringResourcesGet("COMMANDLINEISABSENT"));
                return 2;
            }

            FileName = args[0];
            if (!File.Exists(FileName))
            {
                Console.WriteLine(StringResourcesGet("FILEISABSENT{0}"),FileName);
                return 3;
            }
            outputType = CompilerOptions.OutputType.ConsoleApplicaton;

            CompilerOptions co = new CompilerOptions(FileName, outputType);
            if (args.Length==1)
                co.OutputDirectory = "";
            else co.OutputDirectory = args[1];
            co.Rebuild = false;
            co.Debug = true;
            co.UseDllForSystemUnits = false;

            bool success = true;
            if (Compiler.Compile(co) != null)
                Console.WriteLine("OK");
            else
            {
                Console.WriteLine(StringResourcesGet("COMPILEERRORS"));
                success = false;
            }
            // Console.WriteLine("OK {0}ms", (DateTime.Now - ldt).TotalMilliseconds); /////

            for (int i = 0; i < Compiler.ErrorsList.Count; i++)
            {
                if (Compiler.ErrorsList[i] is LocatedError)
                {
                    SourceLocation sl;
                    if ((sl = (Compiler.ErrorsList[i] as LocatedError).SourceLocation) != null)
                        Console.WriteLine(string.Format("[{0},{1}] {2}: {3}", sl.BeginPosition.Line, sl.BeginPosition.Column, Path.GetFileName(sl.FileName), Compiler.ErrorsList[i].Message));
                    else
                        Console.WriteLine(Compiler.ErrorsList[i]);
                }
                break; // выйти после первой же ошибки
            }
            if (success)
                return 0;
            else return 1;
		}
        public static void Reset()
        {
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.WriteLine(StringResourcesGet("RESTARTING_COMPILER"));
            //StringResourcesLanguage.CurrentLanguageName = "–усский";
            DateTime ldt = DateTime.Now;

            Compiler = new PascalABCCompiler.Compiler(null, ChangeCompilerState);
            //GC.Collect();
            WriteColorText(Compiler.Banner + "\nCopyright (c) 2005-2018 by Ivan Bondarev, Stanislav Mihalkovich\n", ConsoleColor.Black, ConsoleColor.Green);
            Console.WriteLine("OK {0}ms", (DateTime.Now - ldt).TotalMilliseconds);
            if (Compiler.SupportedSourceFiles.Length == 0)
            {
                WriteColorText(StringResourcesGet("ERROR_PARSERS_NOT_FOUND") + Environment.NewLine, ConsoleColor.Black, ConsoleColor.Red);
            }
            Compiler.InternalDebug.SkipPCUErrors = false;
        }
Esempio n. 3
0
        private void CreateCompiler()
        {
            standartCompiler = new PascalABCCompiler.Compiler(SourceFilesProvider, OnChangeCompilerState);
            CodeCompletion.CodeCompletionController.comp = new PascalABCCompiler.Compiler((PascalABCCompiler.Compiler)standartCompiler, SourceFilesProvider, OnChangeCompilerState);
            CodeCompletion.CodeCompletionController.ParsersController   = standartCompiler.ParsersController;
            CodeCompletion.CodeCompletionController.StandartDirectories = StandartDirectories;

            this.CodeCompletionParserController.Init();
            if (defaultCompilerType == PascalABCCompiler.CompilerType.Remote && !Tools.IsUnix())
            {
                LoadRemoteCompiler();
            }
            else
            {
                defaultCompilerType = PascalABCCompiler.CompilerType.Standart;
            }
        }
Esempio n. 4
0
        public static void TestIntellisense(string dir)
        {
            //string dir = Path.Combine(@"c:\Work\Miks\_PABCNETGitHub\TestSuite", "intellisense_tests");
            var comp       = new PascalABCCompiler.Compiler();
            var controller = new CodeCompletion.CodeCompletionController();

            CodeCompletion.CodeCompletionController.comp = comp;
            CodeCompletion.CodeCompletionController.SetParser(".pas");
            CodeCompletion.CodeCompletionController.ParsersController = comp.ParsersController;
            var files  = Directory.GetFiles(dir, "*.pas");
            var parser = comp.ParsersController;

            for (int i = 0; i < files.Length; i++)
            {
                var FileName = files[i];
                var content  = File.ReadAllText(FileName);
                var dc       = controller.Compile(FileName, content);

                string expr_without_brackets = null;
                var    tmp = content;
                var    ind = -1;
                ind = tmp.IndexOf("{@");
                while (ind != -1)
                {
                    var lines       = tmp.Split(new string[] { System.Environment.NewLine }, System.StringSplitOptions.None);
                    var pos         = ind - 1;
                    var line        = GetLineByPos(lines, pos);
                    var col         = GetColByPos(lines, pos);
                    var desc        = CodeCompletion.CodeCompletionTester.GetDescription(pos, tmp, line, col, FileName, dc, comp.ParsersController);
                    var should_desc = tmp.Substring(ind + 2, tmp.IndexOf("@}") - ind - 2);
                    if (desc == null)
                    {
                        desc = "";
                    }
                    desc = desc.Split(new string[] { "\n" }, StringSplitOptions.None)[0].Trim();
                    assert(desc.Replace(", ", ",") == should_desc.Replace(", ", ","), FileName + ", should: " + should_desc + ", is: " + desc);
                    tmp = tmp.Remove(ind, tmp.IndexOf("@}") + 2 - ind);
                    ind = tmp.IndexOf("{@");
                }
            }
        }
        private void CreateCompiler()
        {
            standartCompiler = new PascalABCCompiler.Compiler(SourceFilesProvider, OnChangeCompilerState);
            CodeCompletion.CodeCompletionController.comp = new PascalABCCompiler.Compiler((PascalABCCompiler.Compiler)standartCompiler, SourceFilesProvider, OnChangeCompilerState);
            if (ProjectFactory.Instance.CurrentProject != null)
            {
                CodeCompletion.CodeCompletionController.comp.CompilerOptions.CurrentProject = ProjectFactory.Instance.CurrentProject;
                ProjectFactory.Instance.Dirty = true;
            }
            CodeCompletion.CodeCompletionController.ParsersController   = standartCompiler.ParsersController;
            CodeCompletion.CodeCompletionController.StandartDirectories = StandartDirectories;

            this.CodeCompletionParserController.Init();
            if (defaultCompilerType == PascalABCCompiler.CompilerType.Remote && !Tools.IsUnix())
            {
                LoadRemoteCompiler();
            }
            else
            {
                defaultCompilerType = PascalABCCompiler.CompilerType.Standart;
            }
        }
Esempio n. 6
0
        public static void TestIntellisense(string dir)
        {
            //string dir = Path.Combine(@"c:\Work\Miks\_PABCNETGitHub\TestSuite", "intellisense_tests");
            var comp = new PascalABCCompiler.Compiler();
            var controller = new CodeCompletion.CodeCompletionController();
            CodeCompletion.CodeCompletionController.comp = comp;
            CodeCompletion.CodeCompletionController.SetParser(".pas");
            CodeCompletion.CodeCompletionController.ParsersController = comp.ParsersController;
            var files = Directory.GetFiles(dir, "*.pas");
            var parser = comp.ParsersController;
            for (int i = 0; i < files.Length; i++)
            {
                var FileName = files[i];
                var content = File.ReadAllText(FileName);
                var dc = controller.Compile(FileName, content);
                
                string expr_without_brackets = null;
                var tmp = content;
                var ind = -1;
                ind = tmp.IndexOf("{@");
                while (ind != -1)
                {
                    var lines = tmp.Split(new string[] { System.Environment.NewLine }, System.StringSplitOptions.None);
                    var pos = ind-1;
                    var line = GetLineByPos(lines, pos);
                    var col = GetColByPos(lines, pos);
                    var desc = CodeCompletion.CodeCompletionTester.GetDescription(pos, tmp, line, col, FileName, dc, comp.ParsersController);
                    var should_desc = tmp.Substring(ind + 2, tmp.IndexOf("@}") - ind - 2);
                    if (desc == null)
                        desc = "";
                    desc = desc.Split(new string[] { "\n"},StringSplitOptions.None)[0].Trim();
                    assert(desc == should_desc, FileName+", should: "+should_desc+", is: "+desc);
                    tmp = tmp.Remove(ind, tmp.IndexOf("@}") + 2 - ind);
                    ind = tmp.IndexOf("{@");
                }

            }
        }
Esempio n. 7
0
 public static void Reset()
 {
     Console.ForegroundColor = ConsoleColor.Gray;
     Console.WriteLine(StringResourcesGet("RESTARTING_COMPILER"));
     //StringResourcesLanguage.CurrentLanguageName = "–усский";
     DateTime ldt = DateTime.Now;
     Compiler = new PascalABCCompiler.Compiler(null,ChangeCompilerState);
     //GC.Collect();
     WriteColorText(Compiler.Banner + "\nCopyright © 2005-2016 by Ivan Bondarev, Stanislav Mihalkovich\n", ConsoleColor.Black, ConsoleColor.Green);
     Console.WriteLine("OK {0}ms", (DateTime.Now - ldt).TotalMilliseconds);
     if (Compiler.SupportedSourceFiles.Length == 0)
         WriteColorText(StringResourcesGet("ERROR_PARSERS_NOT_FOUND")+Environment.NewLine,ConsoleColor.Black,ConsoleColor.Red);
     Compiler.InternalDebug.SkipPCUErrors = false;
 }
        public static int Main(string[] args)
        {
            DateTime ldt = DateTime.Now;

            PascalABCCompiler.StringResourcesLanguage.LoadDefaultConfig();

            Compiler = new PascalABCCompiler.Compiler(null, null);
            StringResourcesLanguage.CurrentLanguageName = StringResourcesLanguage.AccessibleLanguages[0];
            //Console.WriteLine("OK {0}ms", (DateTime.Now - ldt).TotalMilliseconds);
            ldt = DateTime.Now;

            //ShowConnectedParsers();

            if (args.Length == 0)
            {
                Console.WriteLine(StringResourcesGet("COMMANDLINEISABSENT"));
                return(2);
            }

            FileName = args[0];
            if (!File.Exists(FileName))
            {
                Console.WriteLine(StringResourcesGet("FILEISABSENT{0}"), FileName);
                return(3);
            }
            outputType = CompilerOptions.OutputType.ConsoleApplicaton;

            CompilerOptions co = new CompilerOptions(FileName, outputType);

            if (FileName.ToLower().EndsWith(".pabcproj"))
            {
                co.ProjectCompiled = true;
            }
            if (args.Length == 1)
            {
                co.OutputDirectory = "";
            }
            else
            {
                co.OutputDirectory = args[1];
            }
            co.Rebuild = false;
            co.Debug   = true;
            co.UseDllForSystemUnits = false;

            bool success = true;

            if (Compiler.Compile(co) != null)
            {
                Console.WriteLine("OK");
            }
            else
            {
                Console.WriteLine(StringResourcesGet("COMPILEERRORS"));
                success = false;
            }
            // Console.WriteLine("OK {0}ms", (DateTime.Now - ldt).TotalMilliseconds); /////

            for (int i = 0; i < Compiler.ErrorsList.Count; i++)
            {
                if (Compiler.ErrorsList[i] is LocatedError)
                {
                    SourceLocation sl;
                    if ((sl = (Compiler.ErrorsList[i] as LocatedError).SourceLocation) != null)
                    {
                        Console.WriteLine(string.Format("[{0},{1}] {2}: {3}", sl.BeginPosition.Line, sl.BeginPosition.Column, Path.GetFileName(sl.FileName), Compiler.ErrorsList[i].Message));
                    }
                    else
                    {
                        Console.WriteLine(Compiler.ErrorsList[i]);
                    }
                }
                break; // выйти после первой же ошибки
            }
            if (success)
            {
                return(0);
            }
            else
            {
                return(1);
            }
        }
        private void OnChangeCompilerStateEx(PascalABCCompiler.ICompiler sender, PascalABCCompiler.CompilerState State, string FullFileName)
        {

            string RusName = null;
            string FileName = null;
            if (FullFileName != null)
                FileName = Path.GetFileName(FullFileName);
            switch (State)
            {
                case PascalABCCompiler.CompilerState.CompilationStarting:
                    RusName = VECStringResources.Get("STATE_START_COMPILING_ASSEMBLY{0}");
                    SetCompilingButtonsEnabled(false);
                    ParsedFiles.Clear();
                    break;
                case PascalABCCompiler.CompilerState.BeginCompileFile: RusName = VECStringResources.Get("STATE_BEGINCOMPILEFILE{0}"); break;
                case PascalABCCompiler.CompilerState.CompileInterface: RusName = VECStringResources.Get("STATE_COMPILEINTERFACE{0}"); break;
                case PascalABCCompiler.CompilerState.CompileImplementation: RusName = VECStringResources.Get("STATE_COMPILEIMPLEMENTATION{0}"); break;
                case PascalABCCompiler.CompilerState.EndCompileFile: RusName = VECStringResources.Get("STATE_ENDCOMPILEFILE{0}"); break;
                case PascalABCCompiler.CompilerState.CodeGeneration: RusName = VECStringResources.Get("STATE_CODEGENERATION{0}"); break;
                case PascalABCCompiler.CompilerState.ReadDLL: RusName = VECStringResources.Get("STATE_READDLL{0}"); break;
                case PascalABCCompiler.CompilerState.SavePCUFile: RusName = VECStringResources.Get("STATE_SAVEPCUFILE{0}"); break;
                case PascalABCCompiler.CompilerState.ReadPCUFile: RusName = VECStringResources.Get("STATE_READPCUFILE{0}"); break;
                case PascalABCCompiler.CompilerState.PCUReadingError: RusName = VECStringResources.Get("STATE_PCUREADINGERROR{0}"); break;
                case PascalABCCompiler.CompilerState.PCUWritingError: RusName = VECStringResources.Get("STATE_PCUWRITINGERROR{0}"); break;
                case PascalABCCompiler.CompilerState.SemanticTreeConversion: RusName = VECStringResources.Get("STATE_SEMANTICTREECONVERSION{0}"); break;
                case PascalABCCompiler.CompilerState.SemanticTreeConverterConnected: RusName = VECStringResources.Get("STATE_SEMANTICTREECONVERTERCONNECTED{0}"); break;
                case PascalABCCompiler.CompilerState.SyntaxTreeConversion: RusName = VECStringResources.Get("STATE_SYNTAXTREECONVERSION{0}"); break;
                case PascalABCCompiler.CompilerState.SyntaxTreeConverterConnected: RusName = VECStringResources.Get("STATE_SYNTAXTREECONVERTERCONNECTED{0}"); break;
                case PascalABCCompiler.CompilerState.ParserConnected:
                    FileName = Path.GetFileName(FileName);
                    if(sender.CompilerType== PascalABCCompiler.CompilerType.Standart)
                        RusName = string.Format(VECStringResources.Get("PARSER_CONNECTED{0}{1}"), sender.ParsersController.LastParser, FileName);
                    else
                        RusName = string.Format(VECStringResources.Get("PARSER_CONNECTED{0}"), FileName);
                    FileName = null;
                    break;
                case PascalABCCompiler.CompilerState.Ready:
                    RusName = VECStringResources.Get("STATE_READY");
                    if (!StartingCompleted)
                    {
                        switch (sender.CompilerType)
                        {
                            case PascalABCCompiler.CompilerType.Standart:
                                standartCompiler = (PascalABCCompiler.Compiler)sender;
                                break;
                            case PascalABCCompiler.CompilerType.Remote:
                                remoteCompiler = (PascalABCCompiler.RemoteCompiler)sender;
                                break;
                        }
                        if (!(defaultCompilerType == PascalABCCompiler.CompilerType.Remote) || (standartCompiler.State == PascalABCCompiler.CompilerState.Ready && (remoteCompiler != null && remoteCompiler.State == PascalABCCompiler.CompilerState.Ready)))
                            StartingCompleted = true;
                        AddCompilerTextToCompilerMessages(sender, VECStringResources.Get("SUPPORTED_LANGUAGES") + Environment.NewLine);
                        foreach (PascalABCCompiler.SupportedSourceFile ssf in standartCompiler.SupportedSourceFiles)
                            AddCompilerTextToCompilerMessages(sender, string.Format(VECStringResources.Get("CM_LANGUAGE_{0}"), ssf) + Environment.NewLine);
                        if (StartingCompleted)
                        {
                            ChangeVisualEnvironmentState(VisualEnvironmentState.FinishCompilerLoading, standartCompiler);
                            compilerLoaded = true;
            				VisualPABCSingleton.MainForm.StartTimer();
                            /*if (!ThreadPool.QueueUserWorkItem(new WaitCallback(CompileTestProgram)))
                                CompileTestProgram(null);*/
                            if (!ThreadPool.QueueUserWorkItem(new WaitCallback(LoadPlugins)))
                                LoadPlugins(null);
                            
                            SetCompilingButtonsEnabled(true);
                            SetDebugButtonsEnabled(true);
                        }
                    }
                    else
                    {
                        if (Compiler == sender)
                        {
                            SetCompilingButtonsEnabled(true);
                        }
                    }
                    break;
                case PascalABCCompiler.CompilerState.Reloading:
                    if (Compiler == sender)
                        SetCompilingButtonsEnabled(false);
                    RusName = VECStringResources.Get("STATE_RELOADING");
                    break;
                case PascalABCCompiler.CompilerState.CompilationFinished:
                    RusName = VECStringResources.Get("STATE_COMPILATIONFINISHED{0}");
                    if (Compiler.ErrorsList.Count == 0)
                    {
                        SaveSourceFilesIfCompilationOk();
                        AddTextToCompilerMessages(string.Format(VECStringResources.Get("CM_OK_{0}MS") + Environment.NewLine, (DateTime.Now - compilationStartTime).TotalMilliseconds) + Environment.NewLine);
                    }
                    else
                    {
                        List<PascalABCCompiler.Errors.Error> ErrorsList = ErrorsManager.CreateErrorsList(Compiler.ErrorsList);
                        AddTextToCompilerMessages(string.Format(VECStringResources.Get("CM_{0}_ERROS") + Environment.NewLine, ErrorsList.Count));
                        foreach (PascalABCCompiler.Errors.Error Err in ErrorsList)
                            AddTextToCompilerMessages(Err.ToString() + Environment.NewLine);
                    }

                    break;
                default: 
                    //RusName = State.ToString(); 
                    break;
            }
            if (RusName != null)
            {
                if (FileName != null)
                    RusName = string.Format(RusName, FileName);
                else RusName = string.Format(RusName, "");
                RusName += Environment.NewLine;
                AddCompilerTextToCompilerMessages(sender, RusName);
            }

            RusName = null;
            switch (State)
            {
                case PascalABCCompiler.CompilerState.BeginParsingFile:
                    ParsedFiles.Add(FullFileName);
                    break;
                case PascalABCCompiler.CompilerState.BeginCompileFile: RusName = VECStringResources.Get("STATETEXT_BEGINCOMPILEFILE{0}"); break;
                //case PascalABCCompiler.CompilerState.ReadPCUFile: RusName = "Чтение {0}..."; break;
                case PascalABCCompiler.CompilerState.CodeGeneration: RusName = VECStringResources.Get("STATETEXT_CODEGENERATION{0}"); break;
                //case PascalABCCompiler.CompilerState.ReadDLL: 
                //case PascalABCCompiler.CompilerState.ReadPCUFile: RusName = "Чтение {0}..."; break;
                case PascalABCCompiler.CompilerState.Ready:
                    if (Compiler != null)
                    {
                        List<PascalABCCompiler.Errors.Error> ErrorsList = ErrorsManager.CreateErrorsList(Compiler.ErrorsList);
                        if (ErrorsList.Count > 0)
                        {
                            RusName = string.Format(VECStringResources.Get("STATETEXT_{0}_ERROS"), ErrorsList.Count);
                        }
                        else
                            if (Compilation)
                            {
                                if (Compiler.Warnings.Count > 0)
                                    RusName = string.Format(VECStringResources.Get("STATETEXT_COMPILATION_SUCCESS_{0}LINES_{1}WARNINGS"), Compiler.LinesCompiled, Compiler.Warnings.Count);
                                else
                                    RusName = string.Format(VECStringResources.Get("STATETEXT_COMPILATION_SUCCESS_{0}LINES"), Compiler.LinesCompiled);
                            }
                            else
                                RusName = VECStringResources.Get("STATETEXT_READY");
                    }
                    else
                        RusName = VECStringResources.Get("STATETEXT_READY");
                    break;
                case PascalABCCompiler.CompilerState.Reloading: RusName = VECStringResources.Get("STATETEXT_RELOADING"); break;
            }
            if (RusName != null)
            {
                if (FileName != null)
                    RusName = string.Format(RusName, FileName);
                SetStateText(RusName);


            }
            if (!Compilation && State == PascalABCCompiler.CompilerState.CompilationStarting)
                Compilation = true;
            if (Compilation && State == PascalABCCompiler.CompilerState.Ready)
                Compilation = false;
        }
        private void CreateCompiler()
        {
            standartCompiler = new PascalABCCompiler.Compiler(SourceFilesProvider, OnChangeCompilerState);
            CodeCompletion.CodeCompletionController.comp = new PascalABCCompiler.Compiler((PascalABCCompiler.Compiler)standartCompiler, SourceFilesProvider, OnChangeCompilerState);
            CodeCompletion.CodeCompletionController.ParsersController = standartCompiler.ParsersController;
            CodeCompletion.CodeCompletionController.StandartDirectories = StandartDirectories;

            this.CodeCompletionParserController.Init();
            if (defaultCompilerType == PascalABCCompiler.CompilerType.Remote && !Tools.IsUnix())
                LoadRemoteCompiler();
            else
                defaultCompilerType = PascalABCCompiler.CompilerType.Standart;
        }
Esempio n. 11
0
        public static int Main(string[] args)
        {
            // SSM 18.03.19 Делаю параметры командной строки. Формат: pabcnetc.exe /Dir1=value1 /Dir2=value2 ... fname dir
            // dir - это пережиток старого - так можно было задавать каталог раньше. Пока - увы - пусть останется
            // Пока сделаю только директивы /Help /H /? и /Debug=0(1)
            // Имя директивы - это одно слово. Равенства может не быть - тогда value директивы равно null
            // Вычленяем первое равенство и делим директиву: до него - name, после него - value. Если name или value - пустые строки, то ошибка

            DateTime ldt = DateTime.Now;

            PascalABCCompiler.StringResourcesLanguage.LoadDefaultConfig();

            Compiler = new PascalABCCompiler.Compiler(null, null);
            StringResourcesLanguage.CurrentLanguageName = StringResourcesLanguage.AccessibleLanguages[0];
            //Console.WriteLine("OK {0}ms", (DateTime.Now - ldt).TotalMilliseconds);
            ldt = DateTime.Now;

            //ShowConnectedParsers();

            var n = args.Length;

            if (n == 0)
            {
                //Console.WriteLine(StringResourcesGet("COMMANDLINEISABSENT"));
                OutputHelp();
                return(2);
            }

            var n1 = args.TakeWhile(a => a[0] == '/').Count(); // количество директив

            if (n1 < n - 2)
            {
                Console.WriteLine("Error in argument {0}", args[n1 + 2]);
                Console.WriteLine("Command line cannot contain any arguments after filename '{0}' and outdirname '{1}'", args[n1], args[n1 + 1]);
                return(4);
            }

            if (n1 == n) // только директивы
            {
                string name, value;
                var    b = CheckAndSplitDirective(args[0], out name, out value);
                if (!b) // Сообщение уже будет выдано
                {
                    return(4);
                }
                switch (name)
                {
                case "help":
                case "h":
                case "?":
                    OutputHelp();
                    return(0);

                default:
                    Console.WriteLine("Filename is absent. Nothing to compile");
                    return(4);
                }
            }

            FileName = args[n1]; // следующий аргумент за директивами - имя файла
            if (!File.Exists(FileName))
            {
                Console.WriteLine(StringResourcesGet("FILEISABSENT{0}"), "'" + FileName + "'");
                return(3);
            }

            outputType = CompilerOptions.OutputType.ConsoleApplicaton;

            CompilerOptions co = new CompilerOptions(FileName, outputType);

            if (FileName.ToLower().EndsWith(".pabcproj"))
            {
                co.ProjectCompiled = true;
            }
            if (n1 == n - 1)
            {
                co.OutputDirectory = "";
            }
            else
            {
                co.OutputDirectory = args[n - 1];
            }
            co.Rebuild = false;
            co.Debug   = false;
            co.UseDllForSystemUnits = false;

            for (var i = 0; i < n1; i++)
            {
                var b = CheckAndApplyDirective(args[i], co);
                if (!b)
                {
                    return(4);
                }
            }


            bool success = true;

            if (Compiler.Compile(co) != null)
            {
                Console.WriteLine("OK");
            }
            else
            {
                Console.WriteLine(StringResourcesGet("COMPILEERRORS"));
                success = false;
            }
            // Console.WriteLine("OK {0}ms", (DateTime.Now - ldt).TotalMilliseconds); /////

            for (int i = 0; i < Compiler.ErrorsList.Count; i++)
            {
                if (Compiler.ErrorsList[i] is LocatedError)
                {
                    SourceLocation sl;
                    if ((sl = (Compiler.ErrorsList[i] as LocatedError).SourceLocation) != null)
                    {
                        Console.WriteLine(string.Format("[{0},{1}] {2}: {3}", sl.BeginPosition.Line, sl.BeginPosition.Column, Path.GetFileName(sl.FileName), Compiler.ErrorsList[i].Message));
                    }
                    else
                    {
                        Console.WriteLine(Compiler.ErrorsList[i]);
                    }
                }
                break; // выйти после первой же ошибки
            }
            if (success)
            {
                return(0);
            }
            else
            {
                return(1);
            }
        }
        private void OnChangeCompilerStateEx(PascalABCCompiler.ICompiler sender, PascalABCCompiler.CompilerState State, string FullFileName)
        {
            string RusName  = null;
            string FileName = null;

            if (FullFileName != null)
            {
                FileName = Path.GetFileName(FullFileName);
            }
            switch (State)
            {
            case PascalABCCompiler.CompilerState.CompilationStarting:
                RusName = VECStringResources.Get("STATE_START_COMPILING_ASSEMBLY{0}");
                SetCompilingButtonsEnabled(false);
                ParsedFiles.Clear();
                break;

            case PascalABCCompiler.CompilerState.BeginCompileFile: RusName = VECStringResources.Get("STATE_BEGINCOMPILEFILE{0}"); break;

            case PascalABCCompiler.CompilerState.CompileInterface: RusName = VECStringResources.Get("STATE_COMPILEINTERFACE{0}"); break;

            case PascalABCCompiler.CompilerState.CompileImplementation: RusName = VECStringResources.Get("STATE_COMPILEIMPLEMENTATION{0}"); break;

            case PascalABCCompiler.CompilerState.EndCompileFile: RusName = VECStringResources.Get("STATE_ENDCOMPILEFILE{0}"); break;

            case PascalABCCompiler.CompilerState.CodeGeneration: RusName = VECStringResources.Get("STATE_CODEGENERATION{0}"); break;

            case PascalABCCompiler.CompilerState.ReadDLL: RusName = VECStringResources.Get("STATE_READDLL{0}"); break;

            case PascalABCCompiler.CompilerState.SavePCUFile: RusName = VECStringResources.Get("STATE_SAVEPCUFILE{0}"); break;

            case PascalABCCompiler.CompilerState.ReadPCUFile: RusName = VECStringResources.Get("STATE_READPCUFILE{0}"); break;

            case PascalABCCompiler.CompilerState.PCUReadingError: RusName = VECStringResources.Get("STATE_PCUREADINGERROR{0}"); break;

            case PascalABCCompiler.CompilerState.PCUWritingError: RusName = VECStringResources.Get("STATE_PCUWRITINGERROR{0}"); break;

            case PascalABCCompiler.CompilerState.SemanticTreeConversion: RusName = VECStringResources.Get("STATE_SEMANTICTREECONVERSION{0}"); break;

            case PascalABCCompiler.CompilerState.SemanticTreeConverterConnected: RusName = VECStringResources.Get("STATE_SEMANTICTREECONVERTERCONNECTED{0}"); break;

            case PascalABCCompiler.CompilerState.SyntaxTreeConversion: RusName = VECStringResources.Get("STATE_SYNTAXTREECONVERSION{0}"); break;

            case PascalABCCompiler.CompilerState.SyntaxTreeConverterConnected: RusName = VECStringResources.Get("STATE_SYNTAXTREECONVERTERCONNECTED{0}"); break;

            case PascalABCCompiler.CompilerState.ParserConnected:
                FileName = Path.GetFileName(FileName);
                if (sender.CompilerType == PascalABCCompiler.CompilerType.Standart)
                {
                    RusName = string.Format(VECStringResources.Get("PARSER_CONNECTED{0}{1}"), sender.ParsersController.LastParser, FileName);
                }
                else
                {
                    RusName = string.Format(VECStringResources.Get("PARSER_CONNECTED{0}"), FileName);
                }
                FileName = null;
                break;

            case PascalABCCompiler.CompilerState.Ready:
                RusName = VECStringResources.Get("STATE_READY");
                if (!StartingCompleted)
                {
                    switch (sender.CompilerType)
                    {
                    case PascalABCCompiler.CompilerType.Standart:
                        standartCompiler = (PascalABCCompiler.Compiler)sender;
                        break;

                    case PascalABCCompiler.CompilerType.Remote:
                        remoteCompiler = (PascalABCCompiler.RemoteCompiler)sender;
                        break;
                    }
                    if (!(defaultCompilerType == PascalABCCompiler.CompilerType.Remote) || (standartCompiler.State == PascalABCCompiler.CompilerState.Ready && (remoteCompiler != null && remoteCompiler.State == PascalABCCompiler.CompilerState.Ready)))
                    {
                        StartingCompleted = true;
                    }
                    AddCompilerTextToCompilerMessages(sender, VECStringResources.Get("SUPPORTED_LANGUAGES") + Environment.NewLine);
                    foreach (PascalABCCompiler.SupportedSourceFile ssf in standartCompiler.SupportedSourceFiles)
                    {
                        AddCompilerTextToCompilerMessages(sender, string.Format(VECStringResources.Get("CM_LANGUAGE_{0}"), ssf) + Environment.NewLine);
                    }
                    if (StartingCompleted)
                    {
                        ChangeVisualEnvironmentState(VisualEnvironmentState.FinishCompilerLoading, standartCompiler);
                        compilerLoaded = true;
                        VisualPABCSingleton.MainForm.StartTimer();

                        /*if (!ThreadPool.QueueUserWorkItem(new WaitCallback(CompileTestProgram)))
                         *  CompileTestProgram(null);*/
                        if (!ThreadPool.QueueUserWorkItem(new WaitCallback(LoadPlugins)))
                        {
                            LoadPlugins(null);
                        }

                        SetCompilingButtonsEnabled(true);
                        SetDebugButtonsEnabled(true);
                    }
                }
                else
                {
                    if (Compiler == sender)
                    {
                        SetCompilingButtonsEnabled(true);
                    }
                }
                break;

            case PascalABCCompiler.CompilerState.Reloading:
                if (Compiler == sender)
                {
                    SetCompilingButtonsEnabled(false);
                }
                RusName = VECStringResources.Get("STATE_RELOADING");
                break;

            case PascalABCCompiler.CompilerState.CompilationFinished:
                RusName = VECStringResources.Get("STATE_COMPILATIONFINISHED{0}");
                if (Compiler.ErrorsList.Count == 0)
                {
                    SaveSourceFilesIfCompilationOk();
                    AddTextToCompilerMessages(string.Format(VECStringResources.Get("CM_OK_{0}MS") + Environment.NewLine, (DateTime.Now - compilationStartTime).TotalMilliseconds) + Environment.NewLine);
                }
                else
                {
                    List <PascalABCCompiler.Errors.Error> ErrorsList = ErrorsManager.CreateErrorsList(Compiler.ErrorsList);
                    AddTextToCompilerMessages(string.Format(VECStringResources.Get("CM_{0}_ERROS") + Environment.NewLine, ErrorsList.Count));
                    foreach (PascalABCCompiler.Errors.Error Err in ErrorsList)
                    {
                        AddTextToCompilerMessages(Err.ToString() + Environment.NewLine);
                    }
                }

                break;

            default:
                //RusName = State.ToString();
                break;
            }
            if (RusName != null)
            {
                if (FileName != null)
                {
                    RusName = string.Format(RusName, FileName);
                }
                else
                {
                    RusName = string.Format(RusName, "");
                }
                RusName += Environment.NewLine;
                AddCompilerTextToCompilerMessages(sender, RusName);
            }

            RusName = null;
            switch (State)
            {
            case PascalABCCompiler.CompilerState.BeginParsingFile:
                ParsedFiles.Add(FullFileName);
                break;

            case PascalABCCompiler.CompilerState.BeginCompileFile: RusName = VECStringResources.Get("STATETEXT_BEGINCOMPILEFILE{0}"); break;

            //case PascalABCCompiler.CompilerState.ReadPCUFile: RusName = "Чтение {0}..."; break;
            case PascalABCCompiler.CompilerState.CodeGeneration: RusName = VECStringResources.Get("STATETEXT_CODEGENERATION{0}"); break;

            //case PascalABCCompiler.CompilerState.ReadDLL:
            //case PascalABCCompiler.CompilerState.ReadPCUFile: RusName = "Чтение {0}..."; break;
            case PascalABCCompiler.CompilerState.Ready:
                if (Compiler != null)
                {
                    List <PascalABCCompiler.Errors.Error> ErrorsList = ErrorsManager.CreateErrorsList(Compiler.ErrorsList);
                    if (ErrorsList.Count > 0)
                    {
                        RusName = string.Format(VECStringResources.Get("STATETEXT_{0}_ERROS"), ErrorsList.Count);
                    }
                    else
                    if (Compilation)
                    {
                        if (Compiler.Warnings.Count > 0)
                        {
                            RusName = string.Format(VECStringResources.Get("STATETEXT_COMPILATION_SUCCESS_{0}LINES_{1}WARNINGS"), Compiler.LinesCompiled, Compiler.Warnings.Count);
                        }
                        else
                        {
                            RusName = string.Format(VECStringResources.Get("STATETEXT_COMPILATION_SUCCESS_{0}LINES"), Compiler.LinesCompiled);
                        }
                    }
                    else
                    {
                        RusName = VECStringResources.Get("STATETEXT_READY");
                    }
                }
                else
                {
                    RusName = VECStringResources.Get("STATETEXT_READY");
                }
                break;

            case PascalABCCompiler.CompilerState.Reloading: RusName = VECStringResources.Get("STATETEXT_RELOADING"); break;
            }
            if (RusName != null)
            {
                if (FileName != null)
                {
                    RusName = string.Format(RusName, FileName);
                }
                SetStateText(RusName);
            }
            if (!Compilation && State == PascalABCCompiler.CompilerState.CompilationStarting)
            {
                Compilation = true;
            }
            if (Compilation && State == PascalABCCompiler.CompilerState.Ready)
            {
                Compilation = false;
            }
        }