public TextReader CreateReader()
 {
     return(ReadOnlyTextDocument.CreateReader());
 }
 /// <summary>
 /// Gets a character at the specified position in the document.
 /// </summary>
 /// <paramref name="offset">The index of the character to get.</paramref>
 /// <exception cref="ArgumentOutOfRangeException">Offset is outside the valid range (0 to TextLength-1).</exception>
 /// <returns>The character at the specified position.</returns>
 /// <remarks>This is the same as Text[offset], but is more efficient because
 ///  it doesn't require creating a String object.</remarks>
 public char GetCharAt(int offset)
 {
     return(ReadOnlyTextDocument.GetCharAt(offset));
 }
 public string GetTextAt(int offset, int length)
 {
     return(ReadOnlyTextDocument.GetTextAt(offset, length));
 }
 public IDocumentLine GetLineByOffset(int offset)
 {
     return(ReadOnlyTextDocument.GetLineByOffset(offset));
 }
 public int OffsetToLineNumber(int offset)
 {
     return(ReadOnlyTextDocument.OffsetToLineNumber(offset));
 }
Esempio n. 6
0
        /// <summary>
        /// Start continuous background compilation on a newly opened file
        /// </summary>
        public void OpenSourceFile(Uri fileUri, string sourceText, LsrTestingOptions lsrOptions)
        {
            string        fileName = Path.GetFileName(fileUri.LocalPath);
            ITextDocument initialTextDocumentLines = new ReadOnlyTextDocument(fileName, TypeCobolConfiguration.Format.Encoding, TypeCobolConfiguration.Format.ColumnsLayout, sourceText);
            FileCompiler  fileCompiler             = null;

#if EUROINFO_RULES //Issue #583
            SymbolTable arrangedCustomSymbol = null;
            string      inputFileName        = string.Empty;

            using (var reader = new StringReader(sourceText))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (!line.StartsWith("       PROGRAM-ID.", StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }
                    inputFileName = line.Split('.')[1].Trim();
                    break;
                }
            }

            var matchingPgm =
                _customSymbols.Programs.Keys.FirstOrDefault(
                    k => k.Equals(inputFileName, StringComparison.InvariantCultureIgnoreCase));
            if (matchingPgm != null)
            {
                arrangedCustomSymbol = new SymbolTable(_customSymbols, SymbolTable.Scope.Namespace);
                var prog = _customSymbols.Programs.Values.SelectMany(p => p).Where(p => p.Name != matchingPgm);
                arrangedCustomSymbol.CopyAllPrograms(new List <List <Program> >()
                {
                    prog.ToList()
                });
                arrangedCustomSymbol.Programs.Remove(matchingPgm);
            }
            fileCompiler = new FileCompiler(initialTextDocumentLines, CompilationProject.SourceFileProvider,
                                            CompilationProject, CompilationProject.CompilationOptions, arrangedCustomSymbol ?? _customSymbols,
                                            false, CompilationProject);
#else
            fileCompiler = new FileCompiler(initialTextDocumentLines, CompilationProject.SourceFileProvider, CompilationProject, CompilationProject.CompilationOptions, _customSymbols, false, CompilationProject);
#endif


            fileCompiler.CompilationResultsForProgram.UpdateTokensLines();

            lock (OpenedFileCompiler)
            {
                if (OpenedFileCompiler.ContainsKey(fileUri))
                {
                    CloseSourceFile(fileUri); //Close and remove the previous opened file.
                }
                OpenedFileCompiler.Add(fileUri, fileCompiler);
                fileCompiler.CompilationResultsForProgram.ProgramClassChanged += ProgramClassChanged;
            }

            fileCompiler.CompilationResultsForProgram.SetOwnerThread(Thread.CurrentThread);

            if (lsrOptions != LsrTestingOptions.LsrSourceDocumentTesting)
            {
                fileCompiler.CompileOnce(lsrOptions.ExecutionStep(fileCompiler.CompilerOptions.ExecToStep.Value), fileCompiler.CompilerOptions.HaltOnMissingCopy, fileCompiler.CompilerOptions.UseAntlrProgramParsing); //Let's parse file for the first time after opening.
            }
        }
 public IDocumentLine GetLine(int lineNumber)
 {
     return(ReadOnlyTextDocument.GetLine(lineNumber));
 }
 public int LocationToOffset(int line, int column)
 {
     return(ReadOnlyTextDocument.LocationToOffset(new DocumentLocation(line, column)));
 }
 public int LocationToOffset(DocumentLocation location)
 {
     return(ReadOnlyTextDocument.LocationToOffset(location));
 }
Esempio n. 10
0
        public static void Check_ASCIICobolFile_FreeTextFormat()
        {
            DocumentFormat docFormat = DocumentFormat.FreeTextFormat;

            SourceFileProvider fileProvider = new SourceFileProvider();

            fileProvider.AddLocalDirectoryLibrary(
                PlatformUtils.GetPathForProjectFile(SampleFolder),
                false, new string[] { ".cpy" },
                docFormat.Encoding, docFormat.EndOfLineDelimiter, docFormat.FixedLineLength);

            DummyTextSourceListener textSourceListener = new DummyTextSourceListener();

            CobolFile cobolFile;

            if (fileProvider.TryGetFile("AsciiFreeFormat", out cobolFile))
            {
                // Load the CobolFile in a TextDocument
                ReadOnlyTextDocument textDocument = new ReadOnlyTextDocument("AsciiFreeFormat.cpy", docFormat.Encoding, docFormat.ColumnsLayout, cobolFile.ReadChars());
                // Send all text lines in one batch to the test observer
                textDocument.TextChanged += textSourceListener.OnTextChanged;
                textDocument.StartSendingChangeEvents();
            }

            TextChangeMap tce1 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges.First <TextChange>(), docFormat.ColumnsLayout);

            if (tce1.LineIndex != 0 || tce1.Type != TextChangeType.LineInserted ||
                tce1.NewLineMap.SequenceNumberText != null || tce1.NewLineMap.IndicatorChar != '/' ||
                tce1.NewLineMap.SourceText != "----------------------------------------------------------------" || tce1.NewLineMap.CommentText != null)
            {
                throw new Exception("Error reading line 1 of the ASCII text source (free text format)");
            }

            TextChangeMap tce2 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges[4], docFormat.ColumnsLayout);

            if (tce2.LineIndex != 4 || tce2.Type != TextChangeType.LineInserted ||
                tce2.NewLineMap.SequenceNumberText != null || tce2.NewLineMap.IndicatorChar != '*' ||
                tce2.NewLineMap.SourceText != " Comportant TAGs (ou BALISEs) standards/normalisés apposées via  commentaires standards à respecter                             " || tce2.NewLineMap.CommentText != null)
            {
                throw new Exception("Error reading line 5 of the ASCII text source (free text format)");
            }

            TextChangeMap tce3 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges[7], docFormat.ColumnsLayout);

            if (tce3.LineIndex != 7 || tce3.Type != TextChangeType.LineInserted ||
                tce3.NewLineMap.SequenceNumberText != null || tce3.NewLineMap.IndicatorChar != ' ' ||
                tce3.NewLineMap.SourceText != "      10                          PIC X(008) VALUE " || tce3.NewLineMap.CommentText != null)
            {
                throw new Exception("Error reading line 8 of the ASCII text source (free text format)");
            }

            TextChangeMap tce4 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges[8], docFormat.ColumnsLayout);

            if (tce4.LineIndex != 8 || tce4.Type != TextChangeType.LineInserted ||
                tce4.NewLineMap.SequenceNumberText != null || tce4.NewLineMap.IndicatorChar != ' ' ||
                tce4.NewLineMap.SourceText != " 'MSVCINP '.   " || tce4.NewLineMap.CommentText != null)
            {
                throw new Exception("Error reading line 9 of the ASCII text source (free text format)");
            }

            TextChangeMap tce5 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges[13], docFormat.ColumnsLayout);

            if (tce5.LineIndex != 13 || tce5.Type != TextChangeType.LineInserted ||
                tce5.NewLineMap.SequenceNumberText != null || tce5.NewLineMap.IndicatorChar != 'D' ||
                tce5.NewLineMap.SourceText != "       15  :MSVCINP:-AppSessnId           PIC X(064).           " || tce5.NewLineMap.CommentText != null)
            {
                throw new Exception("Error reading line 14 of the ASCII text source (free text format)");
            }

            TextChangeMap tce6 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges[18], docFormat.ColumnsLayout);

            if (tce6.LineIndex != 18 || tce6.Type != TextChangeType.LineInserted ||
                tce6.NewLineMap.SequenceNumberText != null || tce6.NewLineMap.IndicatorChar != ' ' ||
                tce6.NewLineMap.SourceText != "    05  FILLER                             PIC X(499).           " || tce6.NewLineMap.CommentText != null)
            {
                throw new Exception("Error reading line 19 of the ASCII text source (free text format)");
            }

            TextChangeMap tce7 = new TextChangeMap(textSourceListener.LastTextChangedEvent.TextChanges.Last <TextChange>(), docFormat.ColumnsLayout);

            if (tce7.LineIndex != 27 || tce7.Type != TextChangeType.LineInserted ||
                tce7.NewLineMap.SequenceNumberText != null || tce7.NewLineMap.IndicatorChar != 'd' ||
                tce7.NewLineMap.SourceText != "   05                            PIC X(008) VALUE '/MSVCINP'.   " || tce7.NewLineMap.CommentText != null)
            {
                throw new Exception("Error reading line 28 of the ASCII text source (free text format)");
            }
        }
Esempio n. 11
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)
        {
            var chrono = new Stopwatch();

            chrono.Start();

            // 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
                {
                    var message = string.IsNullOrEmpty(libraryName) ? string.Format("Cobol source file not found: {0}", fileName)
                                                                    : string.Format("Cobol source file not found: {0} in {1}", fileName, libraryName);
                    throw new Exception(message);
                }
            }
            // 1.b Register a Cobol source file which was already loaded
            else if (loadedCobolFile != null)
            {
                CobolFile = loadedCobolFile;
            }

            chrono.Stop();
            SourceFileSearchTime = (int)chrono.ElapsedMilliseconds;
            chrono.Reset();

            // 2.a Load it in a new text document in memory
            chrono.Start();
            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;
            }

            if (TextDocument != null && TextDocument.LineCount == 0)
            {
                throw new Exception(string.Format("Source file {0} is empty", fileName));
            }

            chrono.Stop();
            SourceFileLoadTime = (int)chrono.ElapsedMilliseconds;
            chrono.Reset();

            // 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;
        }
        public static void Check_EmptyDocument()
        {
            ReadOnlyTextDocument textDocument = new ReadOnlyTextDocument("empty", Encoding.Default, ColumnsLayout.CobolReferenceFormat, String.Empty);

            Exception resultException = null;

            try
            {
                textDocument.CharAt(-1);
            }
            catch (Exception e)
            {
                resultException = e;
            }
            if (resultException == null || !(resultException is InvalidOperationException))
            {
                throw new Exception("Any attempt to get char at -1 invalid offset should result in an InvalidOperationException");
            }
            resultException = null;
            try
            {
                textDocument.CharAt(0);
            }
            catch (Exception e)
            {
                resultException = e;
            }
            if (resultException == null || !(resultException is InvalidOperationException))
            {
                throw new Exception("Any attempt to get char at 0 invalid offset should result in an InvalidOperationException");
            }

            if (textDocument.Chars.Any())
            {
                throw new Exception("An empty document should have 0 chars");
            }

            if (textDocument.Source.Name != "empty")
            {
                throw new Exception("File name should be \"empty\"");
            }

            resultException = null;
            try
            {
                textDocument.GetLineByIndex(-1);
            }
            catch (Exception e)
            {
                resultException = e;
            }
            if (resultException == null || !(resultException is InvalidOperationException))
            {
                throw new Exception("Any attempt to get line at -1 invalid index should result in an InvalidOperationException");
            }
            resultException = null;
            try
            {
                textDocument.GetLineByIndex(0);
            }
            catch (Exception e)
            {
                resultException = e;
            }
            if (resultException == null || !(resultException is InvalidOperationException))
            {
                throw new Exception("Any attempt to get line at 0 invalid index should result in an InvalidOperationException");
            }

            resultException = null;
            int indexOfCharInLine;

            try
            {
                textDocument.GetLineByOffset(-1, out indexOfCharInLine);
            }
            catch (Exception e)
            {
                resultException = e;
            }
            if (resultException == null || !(resultException is InvalidOperationException))
            {
                throw new Exception("Any attempt to get line at -1 invalid index should result in an InvalidOperationException");
            }
            resultException = null;
            try
            {
                textDocument.GetLineByOffset(0, out indexOfCharInLine);
            }
            catch (Exception e)
            {
                resultException = e;
            }
            if (resultException == null || !(resultException is InvalidOperationException))
            {
                throw new Exception("Any attempt to get line at 0 invalid index should result in an InvalidOperationException");
            }

            if (textDocument.Length != 0)
            {
                throw new Exception("An empty document should have length 0");
            }

            if (textDocument.LineCount != 0)
            {
                throw new Exception("An empty document should have 0 line count");
            }

            if (textDocument.Lines.Any())
            {
                throw new Exception("An empty document should have 0 lines");
            }
        }
        public static void Check_FreeFormatDocument()
        {
            DocumentFormat docFormat = DocumentFormat.FreeTextFormat;

            SourceFileProvider fileProvider = new SourceFileProvider();

            fileProvider.AddLocalDirectoryLibrary(
                PlatformUtils.GetPathForProjectFile(@"Compiler\Text\Samples"),
                false, new string[] { ".cpy" },
                docFormat.Encoding, docFormat.EndOfLineDelimiter, docFormat.FixedLineLength);

            CobolFile cobolFile;

            if (!fileProvider.TryGetFile("MSVCINP free format", out cobolFile))
            {
                throw new Exception("File MSVCINP free format.cpy not found");
            }

            // Load the CobolFile in a TextDocument
            ReadOnlyTextDocument textDocument = new ReadOnlyTextDocument("MSVCINP free format.cpy", docFormat.Encoding, docFormat.ColumnsLayout, cobolFile.ReadChars());

            if (textDocument.CharAt(0) != '/')
            {
                throw new Exception("Character at position 0 should be 0");
            }
            if (textDocument.CharAt(92) != 'a')
            {
                throw new Exception("Character at position 92 should be a");
            }
            if (textDocument.CharAt(2582) != '/')
            {
                throw new Exception("Character at position 2582 should be /");
            }
            if (textDocument.CharAt(2522) != ' ')
            {
                throw new Exception("Character at position 2522 should be space");
            }

            if (textDocument.Chars.Skip(90).First() != 'a')
            {
                throw new Exception("Character enumerator after 90 iterations should return a");
            }

            ReadOnlyTextLine line = (ReadOnlyTextLine)textDocument.GetLineByIndex(0);

            if (line.Length != 65 || line.LineIndex != 0 || line.StartOffset != 0 ||
                line.Text != "/----------------------------------------------------------------")
            {
                throw new Exception("Incorrect line at index 0");
            }
            line = (ReadOnlyTextLine)textDocument.GetLineByIndex(1);
            if (line.Length != 96 || line.LineIndex != 1 || line.StartOffset != 67 ||
                line.Text != "* MSVCINP               partie ALLER FIXE des MESSAGES échangés avec tout SERVICE APPLICATIF C14")
            {
                throw new Exception("Incorrect line at index 1");
            }
            line = (ReadOnlyTextLine)textDocument.GetLineByIndex(36);
            if (line.Length != 66 || line.LineIndex != 36 || line.StartOffset != 2529 ||
                line.Text != "d    05                            PIC X(008) VALUE '/MSVCINP'.   ")
            {
                throw new Exception("Incorrect line at index 36");
            }

            int indexOfCharInLine = -1;

            line = (ReadOnlyTextLine)textDocument.GetLineByOffset(12, out indexOfCharInLine);
            if (line.LineIndex != 0 || indexOfCharInLine != 12)
            {
                throw new Exception("Incorrect line at offset 12");
            }
            line = (ReadOnlyTextLine)textDocument.GetLineByOffset(881, out indexOfCharInLine);
            if (line.LineIndex != 11 || indexOfCharInLine != 48)
            {
                throw new Exception("Incorrect line at offset 881");
            }
            line = (ReadOnlyTextLine)textDocument.GetLineByOffset(2509, out indexOfCharInLine);
            if (line.LineIndex != 35 || indexOfCharInLine != 48)
            {
                throw new Exception("Incorrect line at offset 2509");
            }

            if (textDocument.Length != 2595)
            {
                throw new Exception("Document should have length 2595");
            }

            if (textDocument.LineCount != 37)
            {
                throw new Exception("Document should have 37 line count");
            }

            if (textDocument.Lines.Count() != 37)
            {
                throw new Exception("Document should have 37 lines");
            }
        }
        public static void Check_ReferenceFormatDocument()
        {
            DocumentFormat docFormat = DocumentFormat.RDZReferenceFormat;

            SourceFileProvider fileProvider = new SourceFileProvider();

            fileProvider.AddLocalDirectoryLibrary(
                PlatformUtils.GetPathForProjectFile(@"Compiler\Text\Samples"),
                false, new string[] { ".cpy" },
                docFormat.Encoding, docFormat.EndOfLineDelimiter, docFormat.FixedLineLength);

            CobolFile cobolFile;

            if (!fileProvider.TryGetFile("MSVCOUT", out cobolFile))
            {
                throw new Exception("File MSVCOUT.cpy not found");
            }

            // Load the CobolFile in a TextDocument
            ReadOnlyTextDocument textDocument = new ReadOnlyTextDocument("MSVCOUT.cpy", docFormat.Encoding, docFormat.ColumnsLayout, cobolFile.ReadChars());

            if (textDocument.CharAt(0) != '0')
            {
                throw new Exception("Character at position 0 should be 0");
            }
            if (textDocument.CharAt(90) != 'M')
            {
                throw new Exception("Character at position 90 should be M");
            }
            if (textDocument.CharAt(18345) != '/')
            {
                throw new Exception("Character at position 18345 should be /");
            }
            if (textDocument.CharAt(18365) != '1')
            {
                throw new Exception("Character at position 18365 should be 1");
            }

            if (textDocument.Chars.Skip(88).First() != 'M')
            {
                throw new Exception("Character enumerator after 88 iterations should return M");
            }

            ReadOnlyTextLine line = (ReadOnlyTextLine)textDocument.GetLineByIndex(0);

            if (line.Length != 80 || line.LineIndex != 0 || line.StartOffset != 0 ||
                line.Text != "000010*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-  00001001")
            {
                throw new Exception("Incorrect line at index 0");
            }
            line = (ReadOnlyTextLine)textDocument.GetLineByIndex(1);
            if (line.Length != 80 || line.LineIndex != 1 || line.StartOffset != 82 ||
                line.Text != "000020*-Maintenance frame - Created on 14 Oct 2013 at 17:27:08          00002001")
            {
                throw new Exception("Incorrect line at index 1");
            }
            line = (ReadOnlyTextLine)textDocument.GetLineByIndex(223);
            if (line.Length != 80 || line.LineIndex != 223 || line.StartOffset != 18286 ||
                line.Text != "002240     05                             PIC X(08) VALUE '/MSVCOUT'.   02010001")
            {
                throw new Exception("Incorrect line at index 223");
            }

            int indexOfCharInLine = -1;

            line = (ReadOnlyTextLine)textDocument.GetLineByOffset(12, out indexOfCharInLine);
            if (line.LineIndex != 0 || indexOfCharInLine != 12)
            {
                throw new Exception("Incorrect line at offset 12");
            }
            line = (ReadOnlyTextLine)textDocument.GetLineByOffset(159, out indexOfCharInLine);
            if (line.LineIndex != 1 || indexOfCharInLine != 77)
            {
                throw new Exception("Incorrect line at offset 159");
            }
            line = (ReadOnlyTextLine)textDocument.GetLineByOffset(17899, out indexOfCharInLine);
            if (line.LineIndex != 218 || indexOfCharInLine != 23)
            {
                throw new Exception("Incorrect line at offset 17899");
            }

            if (textDocument.Length != 18366)
            {
                throw new Exception("Document should have length 18366");
            }

            if (textDocument.LineCount != 224)
            {
                throw new Exception("Document should have 224 line count");
            }

            if (textDocument.Lines.Count() != 224)
            {
                throw new Exception("Document should have 224 lines");
            }
        }
 public TextReader CreateReader(int offset, int length)
 {
     return(ReadOnlyTextDocument.CreateReader(offset, length));
 }
 public DocumentLocation OffsetToLocation(int offset)
 {
     return(ReadOnlyTextDocument.OffsetToLocation(offset));
 }
 public ITextSource CreateSnapshot()
 {
     return(ReadOnlyTextDocument.CreateSnapshot());
 }
Esempio n. 18
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;
        }