public static List <ITextLine> InsertChildren(SymbolTable table, DataDefinition type, int level, int indent) { var lines = new List <ITextLine>(); foreach (var child in type.Children) { if (child is TypedDataNode) { continue; } //Special case type BOOL if (child is TypeCobol.Compiler.Nodes.DataDescription) { string attr_type = (string)child["type"]; if (attr_type != null) { if (attr_type.ToUpper().Equals("BOOL")) { string attr_name = (string)child["name"]; string margin = ""; for (int i = 0; i < indent; i++) { margin += " "; } string slevel = level.ToString("00"); foreach (string str in BoolTypeTemplate) { string sline = string.Format(str, attr_name, slevel, margin); TextLineSnapshot line = new TextLineSnapshot(-1, sline, null); lines.Add(line); } continue; } } } var typed = (ITypedNode)child; var types = table.GetType(typed.DataType); bool isCustomTypeToo = !(child is TypeDefinition) && (types.Count > 0); if (child.CodeElement is DataDefinitionEntry) { lines.Add(CreateDataDefinition((DataDefinitionEntry)child.CodeElement, level, indent, isCustomTypeToo, false, isCustomTypeToo ? types[0] : null)); } else {//Humm ... It will be a bug. System.Diagnostics.Debug.Assert(child.CodeElement is DataDefinitionEntry); } if (isCustomTypeToo) { lines.AddRange(InsertChildren(table, types[0], level + 1, indent + 1)); } else { lines.AddRange(InsertChildren(table, child as DataDefinition, level + 1, indent + 1)); } } return(lines); }
public void CheckPerformance() { // Sample program properties string folder = "Parser" + 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, project); // 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.PerfStatsForTemporarySemantic.FirstCompilationTime + " ms : temporary semantic class parser"); report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForProgramCrossCheck.FirstCompilationTime + " ms : cross check 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.PerfStatsForTemporarySemantic.LastRefreshTime + " ms : temporary semantic class parser"); report.AppendLine("- " + compiler.CompilationResultsForProgram.PerfStatsForProgramCrossCheck.LastRefreshTime + " ms : cross check class parser"); Console.WriteLine(report.ToString()); }
public static TextChangedEvent UpdateLine(TextChangeType type, int line, string text, TextChangedEvent e = null) { if (e == null) { e = new TextChangedEvent(); } ITextLine snapshot = new TextLineSnapshot(line, text, null); e.TextChanges.Add(new TextChange(type, line, snapshot)); return(e); }
internal override TextChangedEvent Decode() { var result = new TextChangedEvent(); foreach (MsgPack item in msgpack.ForcePathObject("Events")) { TextChangeType type = (TextChangeType)item.AsArray[0].AsInteger; //Type int line = (int)item.AsArray[1].AsInteger; //Line string text = item.AsArray[2].AsString; //Text ITextLine snapshot = new TextLineSnapshot(line, text, null); result.TextChanges.Add(new TextChange(type, line, snapshot)); } //System.Console.WriteLine("TextChangedEventSerializer.Decode(): decoded "+result.TextChanges.Count+" events."); //foreach(var change in result.TextChanges) System.Console.WriteLine(" - "+change.ToString()); return(result); }
/// <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> /// Convert a line to a list of TextLines. /// </summary> /// <param name="line">The line to convert.</param> /// <returns>The list of TextLines</returns> internal static List<ITextLine> LineToTextLines(string line) { List<ITextLine> lines = new List<ITextLine>(); int lfIndex = line.IndexOf('\n'); if (lfIndex >= 0) { char[] sep = { '\n' }; string[] items = line.Split(sep); foreach (var item in items) { TextLineSnapshot tl = new TextLineSnapshot(-1, item, null); lines.Add(tl); } } else { TextLineSnapshot tl = new TextLineSnapshot(-1, line, null); lines.Add(tl); } return lines; }
public static void ExecuteInceremental(FileCompiler compiler, TestUtils.CompilationStats stats) { // Execute a first (complete) compilation compiler.CompileOnce(); //Iterate multiple times over an incremental change stats.IterationNumber = 20; for (int i = 0; i < stats.IterationNumber; i++) { // 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(); //Accumulate results stats.AverageTextUpdateTime += compiler.CompilationResultsForProgram.PerfStatsForText.LastRefreshTime; stats.AverageScannerTime += compiler.CompilationResultsForProgram.PerfStatsForScanner.LastRefreshTime; stats.AveragePreprocessorTime += compiler.CompilationResultsForProgram.PerfStatsForPreprocessor.LastRefreshTime; stats.AverageCodeElementParserTime += compiler.CompilationResultsForProgram.PerfStatsForCodeElementsParser.LastRefreshTime; stats.AverateTemporarySemanticsParserTime += compiler.CompilationResultsForProgram.PerfStatsForTemporarySemantic.LastRefreshTime; stats.AverageCrossCheckerParserTime += compiler.CompilationResultsForProgram.PerfStatsForProgramCrossCheck.LastRefreshTime; } //Compute average time needed for each phase stats.AverageTextUpdateTime = (int)stats.AverageTextUpdateTime / stats.IterationNumber; stats.AverageScannerTime = (int)stats.AverageScannerTime / stats.IterationNumber; stats.AveragePreprocessorTime = (int)stats.AveragePreprocessorTime / stats.IterationNumber; stats.AverageCodeElementParserTime = (int)stats.AverageCodeElementParserTime / stats.IterationNumber; stats.AverateTemporarySemanticsParserTime = (int)stats.AverateTemporarySemanticsParserTime / stats.IterationNumber; stats.AverageCrossCheckerParserTime = (int)stats.AverageCrossCheckerParserTime / stats.IterationNumber; stats.AverageTotalProcessingTime = stats.AverageCodeElementParserTime + stats.AverageCrossCheckerParserTime + stats.AveragePreprocessorTime + stats.AverageScannerTime + stats.AverageTextUpdateTime + stats.AverateTemporarySemanticsParserTime; }
/// <summary> /// Check if the given commented text is one of a Function declaration Header, if so the text is added to the /// Function Data commented header string buffer. /// </summary> /// <param name="nodes">The nodes indices that can correspond to afUnction Declaration node</param> /// <param name="text">The Commented Text</param> private void CheckFunctionDeclCommentedheader(LinearNodeSourceCodeMapper mapper, List <int> nodes, string text) { if (nodes == null) { return; } if (text == null) { return; } if (text.Length == 0) { return; } foreach (int node in nodes) { if (node >= 0 && mapper.Nodes[node] is LinearNodeSourceCodeMapper.NodeFunctionData) { LinearNodeSourceCodeMapper.NodeFunctionData fundata = (LinearNodeSourceCodeMapper.NodeFunctionData)mapper.Nodes[node]; if (fundata.CommentedHeader.Length == 0) {//Add a first empty comment line TextLineSnapshot h = new TextLineSnapshot(-1, "*", null); string crlf = ""; foreach (var hl in Indent(h, null)) { fundata.CommentedHeader.Append(crlf); fundata.CommentedHeader.Append(hl.Text.TrimEnd()); crlf = Environment.NewLine; } fundata.CommentedHeader.Append(crlf); } fundata.CommentedHeader.Append(text); fundata.CommentedHeader.Append(Environment.NewLine); } } }
public static List<ITextLine> InsertChildren(ColumnsLayout? layout, List<string> rootProcedures, List< Tuple<string,string> > rootVariableName, DataDefinition ownerDefinition, DataDefinition type, int level, int indent) { var lines = new List<ITextLine>(); foreach (var child in type.Children) { if (child is TypedDataNode) continue; //Special cases BOOL / POINTER if (child is TypeCobol.Compiler.Nodes.DataDescription) { // For BOOL string attr_type = (string)child["type"]; if (attr_type != null && attr_type.ToUpper().Equals("BOOL")) { string attr_name = (string)child["name"]; string margin = ""; for (int i = 0; i < indent; i++) margin += " "; string slevel = level.ToString("00"); string svalue = child["value"] as string; foreach (string str in BoolTypeTemplate) { string sline = string.Format(str, attr_name, slevel, margin, svalue?.Length == 0 ? "LOW-VALUE" : svalue); TextLineSnapshot line = new TextLineSnapshot(-1, sline, null); lines.Add(line); } continue; } else { // For POINTER var attr_usage = child["usage"]; if (attr_usage != null && attr_usage.ToString().ToUpper().Equals("POINTER")) { string attr_name = (string)child["name"]; string margin = ""; for (int i = 0; i < indent; i++) margin += " "; string slevel = level.ToString("00"); string shash = (string)child["hash"]; foreach (string str in PointerUsageTemplate) { string sline = string.Format(str, attr_name, slevel, margin, (level+1).ToString("00"), attr_name.Length > 22 ? attr_name.Substring(0, 22) : attr_name, shash); TextLineSnapshot line = new TextLineSnapshot(-1, sline, null); lines.Add(line); } continue; } } } if (child is IndexDefinition) continue;//Ignore Index Definition System.Diagnostics.Debug.Assert(child is DataDefinition); var typed = child is DataDefinition ? (DataDefinition)child : null; if (typed == null) {//Unexpected typed value. continue; } bool isCustomTypeToo = !(child is TypeDefinition) && (typed.TypeDefinition != null); var dataDefinitionEntry = typed.CodeElement as DataDefinitionEntry; if (dataDefinitionEntry != null) { lines.AddRange(CreateDataDefinition(child.SymbolTable, layout, rootProcedures, rootVariableName, typed, dataDefinitionEntry, level, indent, isCustomTypeToo, false, isCustomTypeToo ? typed.TypeDefinition : null)); } else {//Humm ... It will be a bug. System.Diagnostics.Debug.Assert(child.CodeElement is DataDefinitionEntry); } if (isCustomTypeToo) { List< Tuple<string,string> > newRootVariableName = new List<Tuple<string, string>>(); newRootVariableName.Add(new Tuple<string, string>(typed.Name, typed.TypeDefinition.Name)); newRootVariableName.AddRange(rootVariableName); lines.AddRange(InsertChildren(layout, rootProcedures, newRootVariableName, typed, typed.TypeDefinition, level + 1, indent + 1)); } else lines.AddRange(InsertChildren(layout, rootProcedures, rootVariableName, typed, typed, level + 1, indent + 1)); } return lines; }
public static List <ITextLine> InsertChildren(ColumnsLayout?layout, List <string> rootProcedures, List <Tuple <string, string> > rootVariableName, DataDefinition ownerDefinition, DataDefinition type, int level, int indent) { var lines = new List <ITextLine>(); foreach (var child in type.Children) { if (child is TypedDataNode) { continue; } //Special case type BOOL if (child is TypeCobol.Compiler.Nodes.DataDescription) { string attr_type = (string)child["type"]; if (attr_type != null) { if (attr_type.ToUpper().Equals("BOOL")) { string attr_name = (string)child["name"]; string margin = ""; for (int i = 0; i < indent; i++) { margin += " "; } string slevel = level.ToString("00"); string svalue = child["value"] as string; foreach (string str in BoolTypeTemplate) { string sline = string.Format(str, attr_name, slevel, margin, svalue?.Length == 0 ? "LOW-VALUE" : svalue); TextLineSnapshot line = new TextLineSnapshot(-1, sline, null); lines.Add(line); } continue; } } } if (child is IndexDefinition) { continue;//Ignore Index Definition } System.Diagnostics.Debug.Assert(child is DataDefinition); var typed = child is DataDefinition ? (DataDefinition)child : null; if (typed == null) {//Unexpected typed value. continue; } List <TypeDefinition> types = new List <TypeDefinition>(); if (types.Count == 0 && child.SymbolTable != null) { types = child.SymbolTable.GetType(typed.DataType); } bool isCustomTypeToo = !(child is TypeDefinition) && (types.Count > 0); var dataDefinitionEntry = typed.CodeElement as DataDefinitionEntry; if (dataDefinitionEntry != null) { lines.AddRange(CreateDataDefinition(child.SymbolTable, layout, rootProcedures, rootVariableName, typed, dataDefinitionEntry, level, indent, isCustomTypeToo, false, isCustomTypeToo ? types[0] : null)); } else {//Humm ... It will be a bug. System.Diagnostics.Debug.Assert(child.CodeElement is DataDefinitionEntry); } if (isCustomTypeToo) { List <Tuple <string, string> > newRootVariableName = new List <Tuple <string, string> >(); newRootVariableName.Add(new Tuple <string, string>(typed.Name, types[0].Name)); newRootVariableName.AddRange(rootVariableName); lines.AddRange(InsertChildren(layout, rootProcedures, newRootVariableName, typed, types[0], level + 1, indent + 1)); } else { lines.AddRange(InsertChildren(layout, rootProcedures, rootVariableName, typed, typed, level + 1, indent + 1)); } } return(lines); }