예제 #1
0
        public static void CheckAllFilesForExceptions()
        {
            CompilationProject project = new CompilationProject("test",
                PlatformUtils.GetPathForProjectFile(@"Compiler\Scanner\Samples"), new string[] { "*.txt" },
                IBMCodePages.GetDotNetEncodingFromIBMCCSID(1147), EndOfLineDelimiter.FixedLengthLines, 80, ColumnsLayout.CobolReferenceFormat, new TypeCobolOptions());

            //int filesCount = 0;
            //int linesCount = 0;
            //Stopwatch chrono = new Stopwatch();
            foreach (string fileName in PlatformUtils.ListFilesInSubdirectory(@"Compiler\Scanner\Samples"))
            {
                string textName = Path.GetFileNameWithoutExtension(fileName);

                // Initialize a CompilationDocument
                FileCompiler compiler = new FileCompiler(null, textName, project.SourceFileProvider, project, ColumnsLayout.CobolReferenceFormat, new TypeCobolOptions(), null, true);

                // Start compilation
                try
                {
                    //chrono.Start();
                    compiler.CompileOnce();
                    //chrono.Stop();
                }
                catch(Exception e)
                {
                    throw new Exception("Error while scanning file " + fileName, e);
                }

                // Stats
                //filesCount++;
                //linesCount += compiler.CompilationResultsForCopy.TokensDocumentSnapshot.Lines.Count;
                //string result = compiler.CompilationResultsForCopy.TokensDocumentSnapshot.GetDebugString();
            }
            // throw new Exception("Test OK for " + filesCount + " files and " + linesCount + " lines : " + chrono.ElapsedMilliseconds + " ms");
        }
예제 #2
0
 public Workspace(string workspaceName, string rootDirectory, string[] fileExtensions, 
                  Encoding encoding, EndOfLineDelimiter endOfLineDelimiter, int fixedLineLength, ColumnsLayout columnsLayout, 
                  TypeCobolOptions compilationOptions)
 {
     compilationProject = new CompilationProject(workspaceName, rootDirectory, fileExtensions, encoding, endOfLineDelimiter, fixedLineLength, columnsLayout, compilationOptions);
     OpenedFileCompilers = new Dictionary<string, FileCompiler>(3);
 }
        public static void AttachIncrementalCompilerToTextEditorDocument(TypeCobolEditor textEditor, CompilationProject project, string textName, TypeCobolOptions compilerOptions, IObserver<IList<CompilationError>> errorObserver)
        {
            var serviceContainer = textEditor.TextArea.TextView.Services;
            if (serviceContainer.GetService(typeof(TypeCobolCompilerService)) != null)
            {
                serviceContainer.RemoveService(typeof(TypeCobolCompilerService));
            }

            TypeCobolCompilerService compilerService = new TypeCobolCompilerService(textEditor, project, textName, compilerOptions, errorObserver);
            serviceContainer.AddService(typeof(TypeCobolCompilerService), compilerService);
        }
예제 #4
0
        public void CheckPerformance()
        {
            // Sample program properties
            string folder = "Compiler" + Path.DirectorySeparatorChar + "Pipeline" + Path.DirectorySeparatorChar + "Samples";
            string textName = "BigBatch";
            DocumentFormat documentFormat = DocumentFormat.RDZReferenceFormat;

            // Create a FileCompiler for this program
            DirectoryInfo localDirectory = new DirectoryInfo(PlatformUtils.GetPathForProjectFile(folder));
            if (!localDirectory.Exists)
            {
                throw new Exception(String.Format("Directory : {0} does not exist", localDirectory.FullName));
            }
            CompilationProject project = new CompilationProject("test",
                localDirectory.FullName, new string[] { "*.cbl", "*.cpy" },
                documentFormat.Encoding, documentFormat.EndOfLineDelimiter, documentFormat.FixedLineLength, documentFormat.ColumnsLayout, new TypeCobolOptions());
            FileCompiler compiler = new FileCompiler(null, textName, project.SourceFileProvider, project, documentFormat.ColumnsLayout, new TypeCobolOptions(), null, false);

            // Execute a first (complete) compilation
            compiler.CompileOnce();

            // Append one line in the middle of the program
            ITextLine newLine = new TextLineSnapshot(9211, "094215D    DISPLAY '-ICLAUA      = ' ICLAUA.                            0000000", null);
            TextChangedEvent textChangedEvent = new TextChangedEvent();
            textChangedEvent.TextChanges.Add(new TextChange(TextChangeType.LineInserted, 9211, newLine));
            compiler.CompilationResultsForProgram.UpdateTextLines(textChangedEvent);

            // Execute a second (incremental) compilation
            compiler.CompileOnce();

            // Display a performance report
            StringBuilder report = new StringBuilder();
            report.AppendLine("Program properties :");
            report.AppendLine("- " + compiler.CompilationResultsForProgram.CobolTextLines.Count + " lines");
            report.AppendLine("- " + compiler.CompilationResultsForProgram.CodeElementsDocumentSnapshot.CodeElements.Count() + " code elements");
            report.AppendLine("First compilation performance");
            report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForText.FirstCompilationTime + " ms : text update");
            report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForScanner.FirstCompilationTime + " ms : scanner");
            report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForPreprocessor.FirstCompilationTime + " ms : preprocessor");
            report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForCodeElementsParser.FirstCompilationTime + " ms : code elements parser");
            report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForProgramClassParser.FirstCompilationTime + " ms : program class parser");
            report.AppendLine("Incremental compilation performance");
            report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForText.LastRefreshTime + " ms : text update");
            report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForScanner.LastRefreshTime + " ms : scanner");
            report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForPreprocessor.LastRefreshTime + " ms : preprocessor");
            report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForCodeElementsParser.LastRefreshTime + " ms : code elements parser");
            report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForProgramClassParser.LastRefreshTime + " ms : program class parser");

            Console.WriteLine(report.ToString());
        }
예제 #5
0
        static PreprocessorUtils()
        {
            DirectivesProject = new CompilationProject("directives",
                PlatformUtils.GetPathForProjectFile(@"Compiler\Preprocessor\DirectiveTestFiles"), new string[] { ".cbl", ".cpy" },
                Encoding.Unicode, EndOfLineDelimiter.CrLfCharacters, 0, ColumnsLayout.CobolReferenceFormat, CompilerOptions);

            CopyProject = new CompilationProject("copy",
                PlatformUtils.GetPathForProjectFile(@"Compiler\Preprocessor\CopyTestFiles"), new string[] { ".cbl", ".cpy" },
                Encoding.Unicode, EndOfLineDelimiter.CrLfCharacters, 0, ColumnsLayout.CobolReferenceFormat, CompilerOptions);

            ReplaceProject = new CompilationProject("replace",
                PlatformUtils.GetPathForProjectFile(@"Compiler\Preprocessor\ReplaceTestFiles"), new string[] { ".cbl", ".cpy" },
                Encoding.Unicode, EndOfLineDelimiter.CrLfCharacters, 0, ColumnsLayout.CobolReferenceFormat, CompilerOptions);
        }
예제 #6
0
        //        public static void Main(string[] args)
        public static void main(string[] args)
        {
            // Directory where the source programs and COPY files are stored
            string sourcePath = @"D:\Users\Laurent\OneDrive\Dev\Visual Studio 2012\Projects\TypeCobol\TypeCobol.Test\Samples\EI Cobol samples\EI-Production";
            string[] programExtensions = { "*.PGM" };
            string[] copyExtensions = { "*.CPY" };

            // List of all sample programs used to compute the statistics
            IList<string> textNames = new List<string>();
            foreach (string programExtension in programExtensions)
            {
                foreach (string filePath in Directory.EnumerateFiles(sourcePath, programExtension))
                {
                    string textName = Path.GetFileNameWithoutExtension(filePath);
                    textNames.Add(textName);
                }
            }

            // Source file format for the samples
            DocumentFormat docFormat = new DocumentFormat(Encoding.GetEncoding("iso8859-1"), EndOfLineDelimiter.CrLfCharacters, 80, ColumnsLayout.CobolReferenceFormat);

            // Initialize a compilation project
            TypeCobolOptions compilerOptions = new TypeCobolOptions();
            CompilationProject project = new CompilationProject("samples", sourcePath, programExtensions.Concat(copyExtensions).ToArray(),
                docFormat.Encoding, docFormat.EndOfLineDelimiter, docFormat.FixedLineLength, docFormat.ColumnsLayout, compilerOptions);

            // Output files used to store the results
            string resultFilePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            string countersFile = Path.Combine(resultFilePath, "SyntaxCounters.txt");
            string languageModelForProgramFile = Path.Combine(resultFilePath, "LanguageModel.Program.txt");
            string languageModelForCopyFile = Path.Combine(resultFilePath, "LanguageModel.Copy.txt");

            // Compute statistics
            Stopwatch chrono = new Stopwatch();
            chrono.Start();
            StatsGenerator.GenerateStatisticsForPrograms(project, textNames, Console.Out, countersFile, languageModelForProgramFile, languageModelForCopyFile);
            chrono.Stop();
            Console.WriteLine("");
            Console.WriteLine("Programs analyzed in " + Math.Round(chrono.ElapsedMilliseconds / (double)1000, 3) + " sec");
        }
        private TypeCobolCompilerService(TypeCobolEditor textEditor, CompilationProject project, string textName, TypeCobolOptions compilerOptions, IObserver<IList<CompilationError>> errorObserver)
        {
            TextDocument = textEditor.TextDocument;

            // DEMO : TaskPoolScheduler can not be used yet because of Length property access on ITextDocument by CobolCharStream
            BackgroundCompilationScheduler = DispatcherScheduler.Current ;

            // Create a new file compiler for this document
            FileCompiler compiler = null;
            if (textName != null)
            {
                compiler = new FileCompiler(null, textName, project.SourceFileProvider, project, TextDocument, compilerOptions, false);
            }
            else
            {
                compiler = new FileCompiler(TextDocument, project.SourceFileProvider, project, compilerOptions, false);
            }
            CompilationUnit = compiler.CompilationResultsForProgram;

            // Compile in the background
            compiler.StartContinuousBackgroundCompilation(400, 400, 900, 2000);

            // Refresh the syntax coloring for rescanned lines
            IObservable<DocumentChangedEvent<ITokensLine>> tokensLinesObservable =
                Observable.FromEvent<EventHandler<DocumentChangedEvent<ITokensLine>>,DocumentChangedEvent<ITokensLine>>(
                    evtHandler => CompilationUnit.TokensLinesChanged += evtHandler,
                    evtHandler => CompilationUnit.TokensLinesChanged -= evtHandler);
            tokensLinesObservable.Subscribe(textEditor);

            // Listen to all compilation errors found by the incremental compiler => on the dispatcher thread to udpate the UI
            // --> TO DO : there is no way yet to observe compilation errors
            //compilationErrorsObservable.ObserveOn(DispatcherScheduler.Current).Subscribe(errorObserver);

            // Trigger initial notification after document load
            compiler.StartDocumentProcessing();
        }
예제 #8
0
 public void Init(string[] extensions = null)
 {
     DirectoryInfo localDirectory = new DirectoryInfo(Path.GetDirectoryName( Comparator.paths.SamplePath));
     DocumentFormat format = Comparator.getSampleFormat();
     TypeCobolOptions options = new TypeCobolOptions();
     if (extensions == null) extensions = new[] { "*.cbl", "*.cpy" };
     //comparator.paths.sextension = extensions[0].Substring(1);
     CompilationProject project = new CompilationProject("TEST",
         localDirectory.FullName, extensions,
         format.Encoding, format.EndOfLineDelimiter, format.FixedLineLength, format.ColumnsLayout, options);
     string filename = Comparator.paths.SampleName;
     Compiler = new FileCompiler(null, filename, project.SourceFileProvider, project, format.ColumnsLayout, options, null, false);
 }
예제 #9
0
        public static void GenerateStatisticsForPrograms(CompilationProject project, IEnumerable<string> textNames, TextWriter console, string countersFile, string languageModelForProgramFile, string languageModelForCopyFile)
        {
            // Initialize statistics vars

            // 1. Program analysis after preprocessing

            // - total number of lines per program (including expanded COPY directives)
            long[] linesCountDistributionCategories = { 500, 1000, 1500, 2000, 3000, 5000, 7500, 10000, 15000, 20000, 30000, 50000, int.MaxValue };
            StatsCounter<CobolTextLineType> linesCounter = new StatsCounter<CobolTextLineType>(linesCountDistributionCategories);

            // - total number of tokens per program (after preprocessing)
            long[] tokensCountDistributionCategories = { 1500, 3000, 4500, 6000, 9000, 15000, 22500, 30000, 45000, 60000, 90000, 150000, int.MaxValue };
            StatsCounter<TokenType> tokensCounter = new StatsCounter<TokenType>(tokensCountDistributionCategories);

            // - number of copies per program
            long[] copiesCountDistributionCategories = { 0, 5, 10, 15, 20, 30, 50, int.MaxValue };
            StatsCounter<CopyDirectiveType> copiesCounter = new StatsCounter<CopyDirectiveType>(copiesCountDistributionCategories);

            // - number of replaced tokens per program
            long[] replacedTokensCountDistributionCategories = { 50, 100, 150, 200, 300, 500, 1000, 2000, 5000, 10000, 20000, int.MaxValue };
            StatsCounter<TokenType> replacedTokensCounter = new StatsCounter<TokenType>(tokensCountDistributionCategories);

            // - number of code elements per program
            long[] codeElementsCountDistributionCategories = { 100, 200, 300, 400, 500, 750, 1000, 1500, 2000, 5000, 10000, int.MaxValue };
            StatsCounter<CodeElementType> codeElementCounter = new StatsCounter<CodeElementType>(codeElementsCountDistributionCategories);

            // 2. Program files before preprocessing

            // - number of lines per program file (before preprocessing)
            long[] linesCountPerProgramFileDistributionCategories = { 25, 50, 100, 150, 200, 300, 500, 1000, 1500, 2000, 3000, int.MaxValue };
            StatsCounter<CobolTextLineType> linesPerProgramFileCounter = new StatsCounter<CobolTextLineType>(linesCountPerProgramFileDistributionCategories);

            // - number of tokens per program file (before preprocessing)
            long[] tokensCountPerProgramFileDistributionCategories = { 1500, 3000, 4500, 6000, 9000, 15000, 22500, 30000, 45000, 60000, 90000, 150000, int.MaxValue };
            StatsCounter<TokenType> tokensPerProgramFileCounter = new StatsCounter<TokenType>(tokensCountPerProgramFileDistributionCategories);

            // - number of compiler directives per program file
            long[] compilerDirectivesPerProgramFileCountDistributionCategories = { 0, 5, 10, 15, 20, 30, 50, 75, 100, 200, int.MaxValue };
            StatsCounter<CompilerDirectiveType> compilerDirectivesPerProgramFileCounter = new StatsCounter<CompilerDirectiveType>(compilerDirectivesPerProgramFileCountDistributionCategories);

            // 3. Copy files before preprocessing

            // - number of references to each copy file
            IDictionary<string, int> copyFileReferenceCount = new Dictionary<string, int>();

            // - number of lines per copy file (before preprocessing)
            long[] linesCountPerCopyFileDistributionCategories = { 25, 50, 100, 150, 200, 300, 500, 1000, 1500, 2000, 3000, int.MaxValue };
            StatsCounter<CobolTextLineType> linesPerCopyFileCounter = new StatsCounter<CobolTextLineType>(linesCountPerCopyFileDistributionCategories);

            // - number of tokens per copy file (before preprocessing)
            long[] tokensCountPerCopyFileDistributionCategories = { 1500, 3000, 4500, 6000, 9000, 15000, 22500, 30000, 45000, 60000, 90000, 150000, int.MaxValue };
            StatsCounter<TokenType> tokensPerCopyFileCounter = new StatsCounter<TokenType>(tokensCountPerCopyFileDistributionCategories);

            // - number of compiler directives per copy file
            long[] compilerDirectivesPerCopyFileCountDistributionCategories = { 0, 5, 10, 15, 20, 30, 50, 75, 100, 200, int.MaxValue };
            StatsCounter<CompilerDirectiveType> compilerDirectivesPerCopyFileCounter = new StatsCounter<CompilerDirectiveType>(compilerDirectivesPerCopyFileCountDistributionCategories);

            // 4. Language models

            // - language model to predict the next word in a program
            LanguageModelGenerator languageModelForProgram = new LanguageModelGenerator();

            // - language model to predict the next word in a copy
            LanguageModelGenerator languageModelForCopy = new LanguageModelGenerator();

            // -- Compile and compute stats --

            foreach(string textName in textNames)
            {
                    console.Write(textName + " : compilation ... ");

                    int programCopiesNotFound = 0;
                    try
                    {
                        // Compile program
                        FileCompiler fileCompiler = new FileCompiler(null, textName, project.SourceFileProvider, project, project.ColumnsLayout, project.CompilationOptions.Clone(), null, false);
                        fileCompiler.CompileOnce();
                        CompilationUnit compilationResult = fileCompiler.CompilationResultsForProgram;
                        programCopiesNotFound = 0;

                        // Compute stats
                        console.Write(" OK, compute stats ... ");

                        // STATS for PROGRAM

                        linesCounter.OnBeginProgram();
                        tokensCounter.OnBeginProgram();
                        copiesCounter.OnBeginProgram();
                        replacedTokensCounter.OnBeginProgram();
                        codeElementCounter.OnBeginProgram();
                        linesPerProgramFileCounter.OnBeginProgram();
                        tokensPerProgramFileCounter.OnBeginProgram();
                        compilerDirectivesPerProgramFileCounter.OnBeginProgram();
                        languageModelForProgram.OnBeginProgram();

                        // Iterate over program file lines
                        foreach (var line in compilationResult.CodeElementsDocumentSnapshot.Lines)
                        {
                            // + count lines
                            linesCounter.OnElement((int)line.Type);
                            linesPerProgramFileCounter.OnElement((int)line.Type);

                            // Use symbol information known at parsing time for the tokens to build a language model
                            if (line.CodeElements != null)
                            {
                                foreach (var codeElement in line.CodeElements)
                                {
                                    if (codeElement.SymbolInformationForTokens.Count > 0)
                                    {
                                        languageModelForProgram.AddSymbolInformationForTokens(codeElement.SymbolInformationForTokens);
                                    }
                                }
                            }
                            if (line.ImportedDocuments != null)
                            {
                                var symbolInformationForTokens = new Dictionary<Token, SymbolInformation>();
                                foreach (var copyDirective in line.ImportedDocuments.Keys)
                                {
                                    if (copyDirective.TextNameSymbol != null)
                                    {
                                        symbolInformationForTokens.Add(copyDirective.TextNameSymbol, new ExternalName(new AlphanumericValue(copyDirective.TextNameSymbol), SymbolType.TextName));
                                    }
                                    if (copyDirective.LibraryNameSymbol != null)
                                    {
                                        symbolInformationForTokens.Add(copyDirective.TextNameSymbol, new ExternalName(new AlphanumericValue(copyDirective.LibraryNameSymbol), SymbolType.LibraryName));
                                    }
                                }
                                languageModelForProgram.AddSymbolInformationForTokens(symbolInformationForTokens);
                            }

                            // Iterate over tokens on this line
                            foreach (var token in line.SourceTokens)
                            {
                                // + count tokens and build language model
                                tokensPerProgramFileCounter.OnElement((int)token.TokenType);
                                languageModelForProgram.OnToken(token);
                            }

                            // Iterate over compiler directives on this line
                            if (line.HasCompilerDirectives)
                            {
                                foreach (var token in line.TokensWithCompilerDirectives)
                                {
                                    CompilerDirectiveToken compilerDirectiveToken = token as CompilerDirectiveToken;
                                    if (compilerDirectiveToken != null)
                                    {
                                        compilerDirectivesPerProgramFileCounter.OnElement((int)compilerDirectiveToken.CompilerDirective.Type);
                                    }
                                }
                            }

                            // Iterate over COPY directives on this line
                            if (line.ImportedDocuments != null)
                            {
                                foreach (CopyDirective copyDirective in line.ImportedDocuments.Keys)
                                {
                                    // + count COPY directives
                                    CopyDirectiveType copyDirectiveType = CopyDirectiveType.Copy;
                                    if (copyDirective.InsertSuffixChar)
                                    {
                                        copyDirectiveType = CopyDirectiveType.CopyReplacingRemarks;
                                    }
                                    else if (copyDirective.RemoveFirst01Level)
                                    {
                                        copyDirectiveType = CopyDirectiveType.CopyRemarks;
                                    }
                                    else if (copyDirective.ReplaceOperations != null && copyDirective.ReplaceOperations.Count > 0)
                                    {
                                        copyDirectiveType = CopyDirectiveType.CopyReplacing;
                                    }
                                    copiesCounter.OnElement((int)copyDirectiveType);

                                    var importedDocument = line.ImportedDocuments[copyDirective];
                                    if (importedDocument == null)
                                    {
                                        // + count missing COPY files for this program
                                        programCopiesNotFound++;
                                    }
                                    else
                                    {
                                        // + count references to copy files
                                        // AND check if copy file has already been analyzed
                                        string copyFileReference = copyDirective.LibraryName + ":" + copyDirective.TextName;
                                        if (copyFileReferenceCount.ContainsKey(copyFileReference))
                                        {
                                            copyFileReferenceCount[copyFileReference] = copyFileReferenceCount[copyFileReference] + 1;

                                            // Iterate over copy file lines
                                            foreach (var copyLine in importedDocument.SourceDocument.Lines)
                                            {
                                                // + count lines inside COPY file
                                                linesCounter.OnElement((int)copyLine.Type);
                                                linesPerCopyFileCounter.OnElement((int)copyLine.Type);
                                            }
                                        }
                                        else
                                        {
                                            copyFileReferenceCount.Add(copyFileReference, 1);

                                            // STATS FOR COPY

                                            linesPerCopyFileCounter.OnBeginProgram();
                                            tokensPerCopyFileCounter.OnBeginProgram();
                                            compilerDirectivesPerCopyFileCounter.OnBeginProgram();
                                            languageModelForCopy.OnBeginProgram();

                                            // Iterate over copy file lines
                                            foreach (var copyLine in importedDocument.SourceDocument.Lines)
                                            {
                                                // + count lines inside COPY file
                                                linesCounter.OnElement((int)copyLine.Type);
                                                linesPerCopyFileCounter.OnElement((int)copyLine.Type);

                                                // Use symbol information known at parsing time for the tokens to build a language model
                                                if (copyLine.ImportedDocuments != null)
                                                {
                                                    var symbolInformationForTokens = new Dictionary<Token, SymbolInformation>();
                                                    foreach (var copyDirective2 in line.ImportedDocuments.Keys)
                                                    {
                                                        if (copyDirective2.TextNameSymbol != null)
                                                        {
                                                            symbolInformationForTokens.Add(copyDirective2.TextNameSymbol, new ExternalName(new AlphanumericValue(copyDirective2.TextNameSymbol), SymbolType.TextName));
                                                        }
                                                        if (copyDirective2.LibraryNameSymbol != null)
                                                        {
                                                            symbolInformationForTokens.Add(copyDirective2.TextNameSymbol, new ExternalName(new AlphanumericValue(copyDirective2.LibraryNameSymbol), SymbolType.LibraryName));
                                                        }
                                                    }
                                                    languageModelForCopy.AddSymbolInformationForTokens(symbolInformationForTokens);
                                                }

                                                // Iterate over tokens on this line
                                                foreach (var token in copyLine.SourceTokens)
                                                {
                                                    // + count tokens and build language model
                                                    tokensPerCopyFileCounter.OnElement((int)token.TokenType);
                                                    languageModelForCopy.OnToken(token);
                                                }

                                                // Iterate over compiler directives on this line
                                                if (copyLine.HasCompilerDirectives)
                                                {
                                                    foreach (var token in copyLine.TokensWithCompilerDirectives)
                                                    {
                                                        CompilerDirectiveToken compilerDirectiveToken = token as CompilerDirectiveToken;
                                                        if (compilerDirectiveToken != null)
                                                        {
                                                            compilerDirectivesPerCopyFileCounter.OnElement((int)compilerDirectiveToken.CompilerDirective.Type);
                                                        }
                                                    }
                                                }
                                            }

                                            linesPerCopyFileCounter.OnEndProgram();
                                            tokensPerCopyFileCounter.OnEndProgram();
                                            compilerDirectivesPerCopyFileCounter.OnEndProgram();
                                        }
                                    }
                                }
                            }

                            // Iterate over code elements on this line
                            if (line.CodeElements != null)
                            {
                                foreach (var codeElement in line.CodeElements)
                                {
                                    codeElementCounter.OnElement((int)codeElement.Type);
                                }
                            }
                        }

                        // Iterate over tokens AFTER preprocessing
                        ITokensLinesIterator processedTokensIterator = compilationResult.ProcessedTokensDocumentSnapshot.ProcessedTokens;
                        Token processedToken = null;
                        while ((processedToken = processedTokensIterator.NextToken()) != Token.END_OF_FILE)
                        {
                            tokensCounter.OnElement((int)processedToken.TokenType);
                            ReplacedToken replacedToken = processedToken as ReplacedToken;
                            if (replacedToken != null)
                            {
                                replacedTokensCounter.OnElement((int)replacedToken.OriginalToken.TokenType);
                            }
                            else if (processedToken is ReplacedTokenGroup)
                            {
                                replacedTokensCounter.OnElement((int)TokenType.ContinuationTokenGroup);
                            }
                        }

                        linesCounter.OnEndProgram();
                        tokensCounter.OnEndProgram();
                        copiesCounter.OnEndProgram();
                        replacedTokensCounter.OnEndProgram();
                        codeElementCounter.OnEndProgram();
                        linesPerProgramFileCounter.OnEndProgram();
                        tokensPerProgramFileCounter.OnEndProgram();
                        compilerDirectivesPerProgramFileCounter.OnEndProgram();
                    }
                    catch (Exception e)
                    {
                        console.WriteLine("ERROR :");
                        console.WriteLine(e.Message);
                    }
                    finally
                    {
                        console.Write("FINISHED");
                        if (programCopiesNotFound == 0)
                        {
                            console.WriteLine();
                        }
                        else
                        {
                            console.WriteLine(" (" + programCopiesNotFound + " missing COPY)");
                        }
                    }
                }

                // Compute language models
                languageModelForProgram.ComputeProbabilities();
                languageModelForCopy.ComputeProbabilities();

                // Write results files

            console.WriteLine("");

            console.WriteLine("Writing statistics results to " + countersFile);
            using (StreamWriter writer = new StreamWriter(countersFile))
            {
                writer.WriteLine("1. Program analysis after preprocessing");
                writer.WriteLine();
                WriteTitle(writer, "Total number of lines per program (including expanded COPY directives)");
                linesCounter.DisplayResults(writer);
                WriteTitle(writer, "Total number of tokens per program (after preprocessing)");
                tokensCounter.DisplayResults(writer);
                WriteTitle(writer, "Number of copies per program");
                copiesCounter.DisplayResults(writer);
                WriteTitle(writer, "Number of replaced tokens per program");
                replacedTokensCounter.DisplayResults(writer);
                WriteTitle(writer, "Number of code elements per program");
                codeElementCounter.DisplayResults(writer);

                writer.WriteLine("2. Program files before preprocessing");
                writer.WriteLine();
                WriteTitle(writer, "Number of lines per program file (before preprocessing)");
                linesPerProgramFileCounter.DisplayResults(writer);
                WriteTitle(writer, "Number of tokens per program file (before preprocessing)");
                tokensPerProgramFileCounter.DisplayResults(writer);
                WriteTitle(writer, "Number of compiler directives per program file");
                compilerDirectivesPerProgramFileCounter.DisplayResults(writer);

                writer.WriteLine("3. Copy files before preprocessing");
                writer.WriteLine();
                WriteTitle(writer, "Number of references to each copy file");
                // copyFileReferenceCount = new Dictionary<string, int>()
                WriteTitle(writer, "Number of lines per copy file (before preprocessing)");
                linesPerCopyFileCounter.DisplayResults(writer);
                WriteTitle(writer, "Number of tokens per copy file (before preprocessing)");
                tokensPerCopyFileCounter.DisplayResults(writer);
                WriteTitle(writer, "Number of compiler directives per copy file");
                compilerDirectivesPerCopyFileCounter.DisplayResults(writer);
            }
            console.WriteLine("Done");

            console.WriteLine("Writing language model for program to " + languageModelForProgramFile);
            using (StreamWriter writer = new StreamWriter(languageModelForProgramFile))
            {
                languageModelForProgram.WriteModelFile(writer, console);
            }

            console.WriteLine("Writing language model for copy to " + languageModelForCopyFile);
            using (StreamWriter writer = new StreamWriter(languageModelForCopyFile))
            {
                languageModelForCopy.WriteModelFile(writer, console);
            }
        }
예제 #10
0
 /// <summary>
 /// Use a pre-existing text document, not yet associated with a Cobol file + Existing SymbolTable
 /// </summary>
 public FileCompiler(ITextDocument textDocument, SourceFileProvider sourceFileProvider, IProcessedTokensDocumentProvider documentProvider, TypeCobolOptions compilerOptions, SymbolTable customSymbols, bool isCopyFile, CompilationProject compilationProject) :
     this(null, null, null, sourceFileProvider, documentProvider, default(ColumnsLayout), textDocument, compilerOptions, customSymbols, isCopyFile, null, compilationProject, null)
 {
 }
예제 #11
0
 /// <summary>
 /// Load a Cobol source file in an pre-existing text document
 /// </summary>
 public FileCompiler(string libraryName, string fileName, SourceFileProvider sourceFileProvider, IProcessedTokensDocumentProvider documentProvider, ITextDocument textDocument, TypeCobolOptions compilerOptions, bool isCopyFile, CompilationProject compilationProject) :
     this(libraryName, fileName, null, sourceFileProvider, documentProvider, default(ColumnsLayout), textDocument, compilerOptions, null, isCopyFile, null, compilationProject, null)
 {
 }
예제 #12
0
 /// <summary>
 /// Load a Cobol source file in memory
 /// </summary>
 public FileCompiler(string libraryName, string fileName, SourceFileProvider sourceFileProvider, IProcessedTokensDocumentProvider documentProvider, ColumnsLayout columnsLayout, TypeCobolOptions compilerOptions, CodeModel.SymbolTable customSymbols, bool isCopyFile, CompilationProject compilationProject) :
     this(libraryName, fileName, null, sourceFileProvider, documentProvider, columnsLayout, null, compilerOptions, customSymbols, isCopyFile, null, compilationProject, null)
 {
 }
예제 #13
0
        /// <summary>
        /// Common internal implementation for all 4 constructors above
        /// </summary>
        private FileCompiler(string libraryName, string fileName, CobolFile loadedCobolFile, SourceFileProvider sourceFileProvider, IProcessedTokensDocumentProvider documentProvider, ColumnsLayout columnsLayout, ITextDocument textDocument, TypeCobolOptions compilerOptions, SymbolTable customSymbols, bool isCopyFile,
                             [CanBeNull] MultilineScanState scanState, CompilationProject compilationProject, List <RemarksDirective.TextNameVariation> copyTextNameVariations)
        {
            // 1.a Find the Cobol source file
            CobolFile sourceFile = null;

            CompilationProject = compilationProject;

            if (fileName != null)
            {
                if (sourceFileProvider.TryGetFile(libraryName, fileName, out sourceFile))
                {
                    CobolFile = sourceFile;
                }
                else
                {
                    if (isCopyFile)
                    {
                        compilationProject.MissingCopys.Add(fileName);
                    }

                    throw new Exception(string.Format("Could not find a Cobol source file named {0} in {1}", fileName, libraryName));
                }
            }
            // 1.b Register a Cobol source file which was already loaded
            else if (loadedCobolFile != null)
            {
                CobolFile = loadedCobolFile;
            }

            // 2.a Load it in a new text document in memory
            if (textDocument == null)
            {
                TextDocument = new ReadOnlyTextDocument(sourceFile.Name, sourceFile.Encoding, columnsLayout, sourceFile.ReadChars());
            }
            // 2.b Load it in an existing text document in memory
            else if (sourceFile != null)
            {
                TextDocument = textDocument;
                textDocument.LoadChars(sourceFile.ReadChars());
            }
            // 2.c Use a pre-existing text document
            //     - not yet associated with a Cobol source file
            //     - with a Cobol source file already loaded
            else if (sourceFile == null || loadedCobolFile != null)
            {
                TextDocument = textDocument;
            }

            // 3. Prepare the data structures used by the different steps of the compiler
            if (isCopyFile)
            {
                CompilationResultsForCopy = new CompilationDocument(TextDocument.Source, TextDocument.Lines, compilerOptions, documentProvider, scanState, copyTextNameVariations);
                CompilationResultsForCopy.CustomSymbols = customSymbols;
            }
            else
            {
                CompilationResultsForProgram = new CompilationUnit(TextDocument.Source, TextDocument.Lines, compilerOptions, documentProvider, copyTextNameVariations);
                CompilationResultsForProgram.CustomSymbols = customSymbols;
            }
            CompilerOptions = compilerOptions;
        }
예제 #14
0
 /// <summary>
 /// Use a pre-existing text document, already initialized from a Cobol file
 /// </summary>
 public FileCompiler(string libraryName, string fileName, SourceFileProvider sourceFileProvider, IProcessedTokensDocumentProvider documentProvider, ColumnsLayout columnsLayout, TypeCobolOptions compilerOptions, CodeModel.SymbolTable customSymbols, bool isCopyFile, MultilineScanState scanState, CompilationProject compilationProject, List <RemarksDirective.TextNameVariation> copyTextNameVariations) :
     this(libraryName, fileName, null, sourceFileProvider, documentProvider, columnsLayout, null, compilerOptions, customSymbols, isCopyFile, scanState, compilationProject, copyTextNameVariations)
 {
 }
예제 #15
0
        public static void Main(string[] args)
        {
            // Basic test program, useful to debug : compiles all sample programs located under TypeCobol.Test\Samples\EI Cobol samples\EI-Production"

            string currentDirectory = Directory.GetCurrentDirectory();
            string projectRootPath = currentDirectory.Substring(0, currentDirectory.IndexOf(@"\TypeCobol\") + 11);

            string sourcePath = projectRootPath + @"TypeCobol.Test\Samples\EI Cobol samples\EI-Production";
            string[] programExtensions = { "*.PGM" };
            string[] copyExtensions = { "*.CPY" };

            DocumentFormat docFormat = new DocumentFormat(Encoding.GetEncoding("iso8859-1"), EndOfLineDelimiter.CrLfCharacters, 80, ColumnsLayout.CobolReferenceFormat);

            TypeCobolOptions compilerOptions = new TypeCobolOptions();
            CompilationProject project = new CompilationProject("samples", sourcePath, programExtensions.Concat(copyExtensions).ToArray(),
                docFormat.Encoding, docFormat.EndOfLineDelimiter, docFormat.FixedLineLength, docFormat.ColumnsLayout, compilerOptions);

            // Iterate over all programs in the source directory
            foreach (string programExtension in programExtensions)
            {
                foreach (string filePath in Directory.EnumerateFiles(sourcePath, programExtension))
                {
                    // Compile program
                    string textName = Path.GetFileNameWithoutExtension(filePath);
                    Console.Write(textName + " ... ");
                    try
                    {
                        FileCompiler fileCompiler = new FileCompiler(null, textName, project.SourceFileProvider, project, ColumnsLayout.CobolReferenceFormat, compilerOptions.Clone(), null, false);
                        fileCompiler.CompileOnce();
                        Console.WriteLine(" OK");
                    }
                    catch(Exception e)
                    {
                        Console.WriteLine("error :");
                        Console.WriteLine(e.Message);
                    }
                }
            }

            /*
            // TO DO : read compiler options on the command line
            // Start with the default compiler options
            TypeCobolOptions compilerOptions = new TypeCobolOptions();

            // Simple test version
            // - all referenced files should be located under the current directory

            CompilationProject project = new CompilationProject("project", ".", new string[] { "*.cbl", "*.cpy" },
                IBMCodePages.GetDotNetEncodingFromIBMCCSID(1147), EndOfLineDelimiter.FixedLengthLines, 80, ColumnsLayout.CobolReferenceFormat, compilerOptions);

            // - gets one file name as argument and compiles it
            if (args.Length == 1)
            {
                string textName = args[0];

                FileCompiler fileCompiler = new FileCompiler(null, textName, project.SourceFileProvider, project, ColumnsLayout.CobolReferenceFormat, compilerOptions.Clone(), false);
                fileCompiler.CompileOnce();
            }
            // - gets an optional "-continuous" flag as the first argument to activate source file monitoring and automatic recompilation
            else if (args.Length == 2)
            {
                if (String.Equals(args[0], "-continuous", StringComparison.InvariantCultureIgnoreCase))
                {
                    string textName = args[1];

                    FileCompiler fileCompiler = new FileCompiler(null, textName, project.SourceFileProvider, project, ColumnsLayout.CobolReferenceFormat, compilerOptions.Clone(), false);
                    fileCompiler.StartContinuousBackgroundCompilation(400, 400, 900, 2000);

                    Console.WriteLine("Processing, press enter to stop ...");
                    fileCompiler.StartContinuousFileProcessing();

                    Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("ERROR : Invalid option");
                }
            }
            else
            {
                Console.WriteLine("ERROR : Invalid number of arguments");
            }
            */
        }