public TreeToCode(IEnumerable<ICobolTextLine> source = null, ColumnsLayout layout = ColumnsLayout.FreeTextFormat) { if (source == null) Input = new List<ICobolTextLine>(); else Input = new List<ICobolTextLine>(source); Output = new System.IO.StringWriter(); this.Layout = layout; }
public CobolTextLine(ITextLine textLine, ColumnsLayout columnsLayout) { // Reuse the external text line object this.textLine = textLine; LineIndex = textLine.LineIndex; ColumnsLayout = columnsLayout; // Scan the line to find the indexes of the different areas // - 72 columns reference format if (columnsLayout == ColumnsLayout.CobolReferenceFormat) { MapVariableLengthLineWithReferenceFormat(); } // - free format and unlimited line length else { MapVariableLengthLineWithFreeFormat(); } // Study the indicator char to determine the type of the line ComputeLineTypeFromIndicator(); // First text analysis phase of the incremental compilation process CompilationStep = CompilationStep.Text; }
public void Generate(CompilationUnit compilationUnit, ColumnsLayout columns = ColumnsLayout.FreeTextFormat) { Destination.Append(""); //Add version to output file if (!string.IsNullOrEmpty(TypeCobolVersion)) { Destination.AppendLine(" *TypeCobol_Version:" + TypeCobolVersion); } var sourceFile = compilationUnit.ProgramClassDocumentSnapshot.Root; sourceFile.AcceptASTVisitor(new ExportToDependency()); var lines = sourceFile.SelfAndChildrenLines; foreach (var textLine in lines) { if (textLine is TextLineSnapshot) { var test = CobolTextLine.Create(textLine.Text, ColumnsLayout.CobolReferenceFormat); Destination.AppendLine(test.First().Text); } else { Destination.AppendLine(textLine.Text); } } }
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); }
/// <summary> /// Generate Code /// </summary> /// <param name="compilationUnit"> Compilation Unit resulting from TypeCobol Parsing</param> /// <param name="columns">Columns layout</param> public void Generate(CompilationUnit compilationUnit, ColumnsLayout columns = ColumnsLayout.FreeTextFormat) { //Check if there is any error in diags if (compilationUnit.AllDiagnostics().Any(d => d.Info.Severity == Compiler.Diagnostics.Severity.Error)) { AnalyticsWrapper.Telemetry.TrackEvent("[Generation] Diagnostics Detected", EventType.Genration); throw new GenerationException("Unable to generate because of error diagnostics", null, null, false, false); } AnalyticsWrapper.Telemetry.TrackEvent("[Generation] Started", EventType.Genration); // STEP 0: Initialize the global values. RootNode = compilationUnit.ProgramClassDocumentSnapshot.Root; SymTable = compilationUnit.ProgramClassDocumentSnapshot.Root.SymbolTable; Layout = columns; //Create the Initial target document. CreateTargetDocument(); // STEP 1: modify tree to adapt it to destination language // 1.1 Run the Qualifier action on this node Qualifier qualifier = new Qualifier(this, RootNode); qualifier.Execute(); // 1.2 Perform other actions Actions.Perform(RootNode); // STEP 2: convert tree to destination language code TreeToCode(); AnalyticsWrapper.Telemetry.TrackEvent("[Generation] Ended", EventType.Genration); }
public static ICollection <ITextLine> CreateCobolLines(ColumnsLayout layout, int index, char indicator, string indent, string text, int pmax, int pmin, bool bConvertFirstLine) { var result = new List <ITextLine>(); int max = pmax; int min = pmax; int nLine = (text.Length / max) + ((text.Length % max) != 0 ? 1 : 0); if (nLine == 1) { result.Add(new TextLineSnapshot(index, bConvertFirstLine ? Convert(layout, text, indicator, indent, pmax) : text, null)); return(result); } if (indicator == ' ') { max = pmax; min = pmin; indicator = '-'; } IList <Tuple <string, bool> > lines = lines = Split(text, max, min); for (int i = 0; i < lines.Count; i++) { if (index > -1) { index++; } result.Add(new TextLineSnapshot(index, !((i == 0 && bConvertFirstLine) || i > 0) ? lines[i].Item1 : Convert(layout, lines[i].Item1, indicator != '-' ? indicator : ((lines[i].Item2 && i != 0) ? indicator : (i == 0 ? NoIndicator : NoOneIndicator)), indent, pmax), null)); } return(result); }
private static string Convert(ColumnsLayout layout, string text, int indicator, string indent, int pmax) { string result = ""; if (layout == ColumnsLayout.FreeTextFormat) { result = (indicator == '*' ? "*" : "") + indent + text; } else { var end = text.Length < pmax ? new string(' ', pmax - text.Length) : ""; if (indicator != '-') { if (indicator == NoIndicator) { result = NoContinuationLinePrefix + indent + text + end + " "; } else if (indicator == NoOneIndicator) { result = NoOneContinuationLinePrefix + indent + text + end + " "; } else { result = " " + (char)indicator + indent + text + end + " "; } } else { result = ContinuationLinePrefix + indent + text + end + " "; } } return(result); }
/// <summary> /// Initialize a cobol document from any source of characters /// </summary> /// <param name="fileName">Name of the file the document is stored in</param> /// <param name="textSource">Sequence of unicode characters with line delimiters (Cr? Lf)</param> public ReadOnlyTextDocument(string fileName, Encoding encodingForAlphanumericLiterals, ColumnsLayout columnsLayout, IEnumerable<char> textSource) { // Document source name and text format Source = new TextSourceInfo(fileName, encodingForAlphanumericLiterals, columnsLayout); // Initialize document text lines LoadChars(textSource); }
public AvalonEditTextDocument(ICSharpCode.AvalonEdit.Document.TextDocument avalonEditTextDocument, Encoding encodingForAlphanumericLiterals, ColumnsLayout columnsLayout) { // Document source name and text format Source = new TextSourceInfo(_avalonEditTextDocument.FileName, encodingForAlphanumericLiterals, columnsLayout); _avalonEditTextDocument = avalonEditTextDocument; // Listen to all line changes in the editor _avalonEditTextDocument.VerifyAccess(); _weakLineTracker = WeakLineTracker.Register(_avalonEditTextDocument, this); }
public override void Generate(CompilationUnit compilationUnit, ColumnsLayout columns = ColumnsLayout.FreeTextFormat) { _usedGenerator.Generate(compilationUnit, columns); //After generation get the generated cobol code and mix it with TypeCobol source using Transform project var mixedContent = new StringBuilder(); Transform.Decoder.Encode(compilationUnit.CobolTextLines.Select(l => l.Text).ToArray(), Destination.ToString().Split(new string[] { Environment.NewLine }, StringSplitOptions.None), mixedContent); this.Destination.Clear(); this.Destination.Append(mixedContent); }
/// <summary> /// Common internal implementation for all 4 constructors above /// </summary> private FileCompiler(string libraryName, string textName, CobolFile loadedCobolFile, SourceFileProvider sourceFileProvider, IProcessedTokensDocumentProvider documentProvider, ColumnsLayout columnsLayout, ITextDocument textDocument, TypeCobolOptions compilerOptions, SymbolTable customSymbols, bool isCopyFile, [CanBeNull] MultilineScanState scanState) { // 1.a Find the Cobol source file CobolFile sourceFile = null; if (textName != null) { if (sourceFileProvider.TryGetFile(libraryName, textName, out sourceFile)) { CobolFile = sourceFile; } else { throw new Exception(String.Format("Could not find a Cobol source file named {0} in {1}", textName, 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); CompilationResultsForCopy.CustomSymbols = customSymbols; } else { CompilationResultsForProgram = new CompilationUnit(TextDocument.Source, TextDocument.Lines, compilerOptions, documentProvider); CompilationResultsForProgram.CustomSymbols = customSymbols; } CompilerOptions = compilerOptions; }
/// <summary> /// Document line factory for the compiler processing steps : create new line from text /// </summary> protected CodeElementsLine CreateNewDocumentLine(ITextLine textLine, ColumnsLayout columnsLayout) { // Ensure all document lines are read-only snapshots ITextLine textLineSnapshot; if (!textLine.IsReadOnly) { textLineSnapshot = new TextLineSnapshot(textLine); } else { textLineSnapshot = textLine; } return(new CodeElementsLine(textLineSnapshot, columnsLayout)); }
/// <summary> /// Create a new Cobol compilation project in a local directory /// </summary> public CompilationProject(string projectName, string rootDirectory, string[] fileExtensions, Encoding encoding, EndOfLineDelimiter endOfLineDelimiter, int fixedLineLength, ColumnsLayout columnsLayout, TypeCobolOptions compilationOptions) { Name = projectName; RootDirectory = rootDirectory; SourceFileProvider = new SourceFileProvider(); rootDirectoryLibrary = SourceFileProvider.AddLocalDirectoryLibrary(rootDirectory, false, fileExtensions, encoding, endOfLineDelimiter, fixedLineLength); Encoding = encoding; EndOfLineDelimiter = endOfLineDelimiter; FixedLineLength = fixedLineLength; ColumnsLayout = columnsLayout; CompilationOptions = compilationOptions; CobolFiles = new Dictionary <string, CobolFile>(); CobolTextReferences = new Dictionary <string, CobolFile>(); CobolProgramCalls = new Dictionary <string, CobolFile>(); }
void AddToColumnsLayout(PivotMemberItem member) { if (member != null) { // Для данного элемента пытаемся получить по координатам LayoutCellWrapper LayoutCellWrapper itemWrapper = ColumnsLayout[member.ColumnIndex, member.RowIndex]; if (itemWrapper == null) { itemWrapper = new LayoutCellWrapper(); ColumnsLayout.Add(itemWrapper, member.ColumnIndex, member.RowIndex); } // Создаем описатель для данного элемента и добавляем его в коллекцию объектов ячейки сетки MemberLayoutItem item = new MemberLayoutItem(member); itemWrapper.Items.Add(item); item.RowSpan = member.RowSpan; item.ColumnSpan = member.ColumnSpan; // Если элемент в ширину больше чем 1, то добавляем фиктивные элементы на сетку for (int i = 1; i < member.ColumnSpan; i++) { LayoutCellWrapper ext_itemWrapper = ColumnsLayout[member.ColumnIndex + i, member.RowIndex]; if (ext_itemWrapper == null) { ext_itemWrapper = new LayoutCellWrapper(); ColumnsLayout.Add(ext_itemWrapper, member.ColumnIndex + i, member.RowIndex); } // Создаем описатель для фиктивного элемента MemberLayoutItem ext_item = new MemberLayoutItem(member); ext_item.IsExtension = true; ext_itemWrapper.Items.Add(ext_item); ext_item.ColumnSpan = member.ColumnSpan - i; ext_item.RowSpan = member.RowSpan; } foreach (PivotMemberItem dd_item in member.DrillDownChildren) { AddToColumnsLayout(dd_item); } foreach (PivotMemberItem child_item in member.Children) { AddToColumnsLayout(child_item); } } }
// -- Project creation and persistence -- /// <summary> /// Create a new Cobol compilation project in a local directory /// </summary> public CompilationProject(string projectName, string rootDirectory, string[] fileExtensions, Encoding encoding, EndOfLineDelimiter endOfLineDelimiter, int fixedLineLength, ColumnsLayout columnsLayout, TypeCobolOptions compilationOptions) { Name = projectName; RootDirectory = rootDirectory; SourceFileProvider = new SourceFileProvider(); rootDirectoryLibrary = SourceFileProvider.AddLocalDirectoryLibrary(rootDirectory, true, fileExtensions, encoding, endOfLineDelimiter, fixedLineLength); Encoding = encoding; EndOfLineDelimiter = endOfLineDelimiter; FixedLineLength = fixedLineLength; ColumnsLayout = columnsLayout; CompilationOptions = compilationOptions; CobolFiles = new Dictionary<string, CobolFile>(); CobolTextReferences = new Dictionary<string, CobolFile>(); CobolProgramCalls = new Dictionary<string, CobolFile>(); }
public DocumentFormat(Encoding encoding, EndOfLineDelimiter endOfLineDelimiter, int fixedLineLength, ColumnsLayout columnsLayout) { Encoding = encoding; EndOfLineDelimiter = endOfLineDelimiter; if (endOfLineDelimiter == EndOfLineDelimiter.FixedLengthLines) { if (columnsLayout == ColumnsLayout.FreeTextFormat) { throw new ArgumentException("With free text format, fixed length lines are not allowed"); } else if (columnsLayout == ColumnsLayout.CobolReferenceFormat && fixedLineLength < 72) { throw new ArgumentException("With Cobol reference format, fixed length lines must be at least 72 characters long"); } FixedLineLength = fixedLineLength; } ColumnsLayout = columnsLayout; }
private static string Convert(ColumnsLayout layout, string text, char indicator, string indent) { string result = ""; if (layout == ColumnsLayout.FreeTextFormat) { result = (indicator == '*' ? "*" : "") + indent + text; } else { string end = ""; for (int c = text.Length; c < 65; c++) { end += " "; } result = " " + indicator + indent + text + end + " ";//+"000000"; } return(result); }
private static ICollection <ITextLine> CreateCobolLines(ColumnsLayout layout, int index, char indicator, string indent, string text) { var result = new List <ITextLine>(); var lines = Split(text, 65); result.Add(new TextLineSnapshot(index, Convert(layout, lines[0], indicator, indent), null)); if (indicator == ' ') { indicator = '-'; } for (int i = 1; i < lines.Count; i++) { if (index > -1) { index++; } result.Add(new TextLineSnapshot(index, Convert(layout, lines[i], indicator, indent), null)); } return(result); }
public void Generate(CompilationUnit compilationUnit, ColumnsLayout columns = ColumnsLayout.FreeTextFormat) { Destination.Write(""); //Add version to output file if (!string.IsNullOrEmpty(TypeCobolVersion)) { Destination.WriteLine(" *TypeCobol_Version:" + TypeCobolVersion); } var sourceFile = compilationUnit.ProgramClassDocumentSnapshot.Root; sourceFile.AcceptASTVisitor(new ExportToDependency()); var lines = sourceFile.SelfAndChildrenLines; foreach (var textLine in lines) { Destination.WriteLine(textLine.Text); } Destination.Flush(); Destination.Close(); }
/// <summary> /// Generate /// </summary> /// <param name="compilationUnit"></param> /// <param name="columns"></param> public void Generate(CompilationUnit compilationUnit, ColumnsLayout columns = ColumnsLayout.FreeTextFormat) { this.Layout = columns; Compiler.Preprocessor.ProcessedTokensDocument processedTokensDocument = compilationUnit.ProcessedTokensDocumentSnapshot; // Create a token iterator on top of pre-processed tokens lines Compiler.Scanner.ITokensLinesIterator tokensIterator = Compiler.Preprocessor.ProcessedTokensDocument.GetProcessedTokensIterator( compilationUnit.TextSourceInfo, processedTokensDocument.Lines, compilationUnit.CompilerOptions); //var date1 = DateTime.Now; TypeCobol.Compiler.Scanner.Token curToken = null; while ((curToken = (curToken == null ? tokensIterator.NextToken() : curToken)) != null) { var token = curToken; curToken = null; if (token.TokenType == Compiler.Scanner.TokenType.EndOfFile) { break; } else if (token is TypeCobol.Compiler.Preprocessor.ImportedToken) { InsertImportedTokensAction(token, tokensIterator); curToken = tokensIterator.CurrentToken; } else if (token is TypeCobol.Compiler.Preprocessor.ReplacedPartialCobolWord) { ReplaceAction(token as TypeCobol.Compiler.Preprocessor.ReplacedPartialCobolWord); } } //Now Run Actions PerformActions(); TargetDocument.Write(Destination); //var date2 = DateTime.Now; //var date_diff = date2 - date1; //System.Console.Out.WriteLine(date_diff); }
public CobolTextLine(ITextLine textLine, ColumnsLayout columnsLayout) { // Reuse the external text line object this.textLine = textLine; ColumnsLayout = columnsLayout; // Scan the line to find the indexes of the different areas // - 72 columns reference format if (columnsLayout == ColumnsLayout.CobolReferenceFormat) { MapVariableLengthLineWithReferenceFormat(); } // - free format and unlimited line length else { MapVariableLengthLineWithFreeFormat(); } // Study the indicator char to determine the type of the line ComputeLineTypeFromIndicator(); // First text analysis phase of the incremental compilation process CompilationStep = CompilationStep.Text; }
public static ICollection <ITextLine> Create(string text, ColumnsLayout layout, int index = -1) { if (layout == ColumnsLayout.FreeTextFormat) { var result = new List <ITextLine>(); result.Add(new TextLineSnapshot(index, text, null)); return(result); } if (layout == ColumnsLayout.CobolReferenceFormat) { char indicator = ' '; string indent = ""; bool wasComment = text.Trim().StartsWith("*"); if (wasComment) { indicator = '*'; int i = text.IndexOf('*'); indent = text.Substring(0, i); text = text.Substring(i + 1); } return(CreateCobolLines(layout, index, indicator, indent, text)); } throw new System.NotImplementedException("Unsuported ITextLine type: " + layout); }
/// <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) { }
/// <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) { }
public TokensLine(ITextLine textLine, ColumnsLayout columnsLayout) : base(textLine, columnsLayout) { lastSourceIndex = Source.EndIndex; SourceTokens = new List <Token>(); _ScannerDiagnostics = new List <Diagnostic>(); }
/// <summary> /// Initialize a cobol document from any source of characters /// </summary> /// <param name="fileName">Name of the file the document is stored in</param> /// <param name="textSource">Sequence of unicode characters with line delimiters (Cr? Lf)</param> public ReadOnlyTextDocument(string fileName, Encoding encodingForAlphanumericLiterals, ColumnsLayout columnsLayout, IEnumerable <char> textSource) { // Document source name and text format Source = new TextSourceInfo(fileName, encodingForAlphanumericLiterals, columnsLayout); // Initialize document text lines LoadChars(textSource); }
public static ICollection<ITextLine> Create(string text, ColumnsLayout layout, int index = -1) { if (layout == ColumnsLayout.FreeTextFormat) { var result = new List<ITextLine>(); result.Add(new TextLineSnapshot(index, text, null)); return result; } if (layout == ColumnsLayout.CobolReferenceFormat) { char indicator = ' '; string indent = ""; bool wasComment = text.Trim().StartsWith("*"); if (wasComment) { indicator = '*'; int i = text.IndexOf('*'); indent = text.Substring(0, i); text = text.Substring(i + 1); } return CreateCobolLines(layout, index, indicator, indent, text); } throw new System.NotImplementedException("Unsuported ITextLine type: " + layout); }
public CodeElementsLine(ITextLine textLine, ColumnsLayout columnsLayout) : base(textLine, columnsLayout) { }
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); }
internal ProcessedTokensLine(ITextLine textLine, ColumnsLayout columnsLayout) : base(textLine, columnsLayout) { PreprocessingState = PreprocessorState.NeedsCompilerDirectiveParsing; }
/// <summary> /// Constructor /// </summary> /// <param name="buildEngine"></param> /// <param name="projectName"></param> /// <param name="rootDirectory"></param> /// <param name="fileExtensions"></param> /// <param name="encoding"></param> /// <param name="endOfLineDelimiter"></param> /// <param name="fixedLineLength"></param> /// <param name="columnsLayout"></param> /// <param name="compilationOptions"></param> public BuildProject(BuildEngine buildEngine, string projectName, string rootDirectory, string[] fileExtensions, Encoding encoding, EndOfLineDelimiter endOfLineDelimiter, int fixedLineLength, ColumnsLayout columnsLayout, TypeCobolOptions compilationOptions) : base(projectName, rootDirectory, fileExtensions, encoding, endOfLineDelimiter, fixedLineLength, columnsLayout, compilationOptions) { BuilderEngine = buildEngine; }
/// <summary>Generates code</summary> /// <param name="tree">Root of a syntax tree</param> /// <param name="table">Table of symbols</param> /// <param name="columns">Columns layout</param> public void Generate(Root tree, SymbolTable table, ColumnsLayout columns = ColumnsLayout.FreeTextFormat) { Actions = new List<Action>(); // STEP 1: modify tree to adapt it to destination language tree.Accept(this); var groups = new List<string>(); foreach (var action in Actions) { if (action.Group != null && groups.Contains(action.Group)) continue; action.Execute(); if (action.Group != null) groups.Add(action.Group); } // Console.WriteLine(tree.Root.ToString()); // STEP 2: convert tree to destination language code var converter = new TreeToCode(Input, columns); tree.Accept(converter); converter.WriteInputLinesUntilEnd(); Writer.Write(converter.Output.ToString()); Writer.Flush(); // Console.WriteLine(converter.Output.ToString()); }
/// <summary> /// Load a Cobol source file in memory /// </summary> public FileCompiler(string libraryName, string textName, SourceFileProvider sourceFileProvider, IProcessedTokensDocumentProvider documentProvider, ColumnsLayout columnsLayout, TypeCobolOptions compilerOptions, CodeModel.SymbolTable customSymbols, bool isCopyFile) : this(libraryName, textName, null, sourceFileProvider, documentProvider, columnsLayout, null, compilerOptions, customSymbols, isCopyFile) { }
/// <summary> /// Common internal implementation for all 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; } 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 ICollection <ITextLine> CreateCobolLines(ColumnsLayout layout, int index, char indicator, string indent, string text) { return(CreateCobolLines(layout, index, indicator, indent, text, 65, 61, true)); }
/// <summary> /// Document line factory for the compiler processing steps : create new line from text /// </summary> protected CodeElementsLine CreateNewDocumentLine(ITextLine textLine, ColumnsLayout columnsLayout) { // Ensure all document lines are read-only snapshots ITextLine textLineSnapshot; if (!textLine.IsReadOnly) { textLineSnapshot = new TextLineSnapshot(textLine); } else { textLineSnapshot = textLine; } return new CodeElementsLine(textLineSnapshot, columnsLayout); }
public TextSourceInfo(string name, Encoding encodingForAlphanumericLiterals, ColumnsLayout columnsLayout) { Name = name; EncodingForAlphanumericLiterals = encodingForAlphanumericLiterals; ColumnsLayout = columnsLayout; }
public TextChangeMap(TextChange change, ColumnsLayout columnsLayout) : base(change.Type, change.LineIndex, change.NewLine) { NewLineMap = new CobolTextLine(NewLine, columnsLayout); }
/// <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; }
private static string Convert(ColumnsLayout layout, string text, char indicator, string indent) { string result = ""; if (layout == ColumnsLayout.FreeTextFormat) { result = (indicator == '*' ? "*" : "") + indent + text; } else { string end = ""; for (int c = text.Length; c < 65; c++) end += " "; result = " " + indicator + indent + text + end + " ";//+"000000"; } return result; }
private static ICollection<ITextLine> CreateCobolLines(ColumnsLayout layout, int index, char indicator, string indent, string text) { var result = new List<ITextLine>(); var lines = Split(text, 65); result.Add(new TextLineSnapshot(index, Convert(layout, lines[0], indicator, indent), null)); if (indicator == ' ') indicator = '-'; for (int i = 1; i < lines.Count; i++) { if (index > -1) index++; result.Add(new TextLineSnapshot(index, Convert(layout, lines[i], indicator, indent), null)); } return result; }