public void Init(string[] extensions = null, bool autoRemarks = false, bool AntlrProfiler = false) { DirectoryInfo localDirectory = new DirectoryInfo(Path.GetDirectoryName(Comparator?.paths?.SamplePath)); DocumentFormat format = Comparator?.GetSampleFormat(); TypeCobolOptions options = new TypeCobolOptions(); #if EUROINFO_RULES options.AutoRemarksEnable = autoRemarks; #endif 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, project); if (AntlrProfiler) { Compiler.CompilationResultsForProgram.PerfStatsForCodeElementsParser.ActivateDetailedAntlrPofiling = true; Compiler.CompilationResultsForProgram.PerfStatsForTemporarySemantic.ActivateDetailedAntlrPofiling = true; } }
public void IncrementalPerformance() { // 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); //Make an incremental change to the source code TestUtils.CompilationStats stats = new TestUtils.CompilationStats(); ExecuteInceremental(compiler, stats); // Display a performance report TestUtils.CreateRunReport(TestUtils.GetReportDirectoryPath(), compiler.CobolFile.Name + "-Incremental", stats, compiler.CompilationResultsForProgram); }
public void Parse(string path, TextChangedEvent e = null) { //if the server is restarted during Eclipse lifetime, then we need to init the parser //This is useful when debugging. Perhaps it'll be deleted at the end if (!Compilers.ContainsKey(path)) { Init(path, new TypeCobolOptions { ExecToStep = ExecutionStep.Generate }); } Compiler = Compilers[path]; Compiler.CompilationResultsForProgram.TextLinesChanged += OnTextLine; Compiler.CompilationResultsForProgram.CodeElementsLinesChanged += OnCodeElementLine; if (!Inits[path]) { Inits[path] = true; // no need to update with the same content as at compiler creation } else { Compiler.CompilationResultsForProgram.UpdateTextLines(e); } try { Compiler.CompileOnce(); } catch (Exception ex) { Observer.OnError(ex); System.Console.WriteLine(ex.ToString()); } MissingCopys = Compiler.CompilationProject.MissingCopys; Compiler.CompilationResultsForProgram.TextLinesChanged -= OnTextLine; Compiler.CompilationResultsForProgram.CodeElementsLinesChanged -= OnCodeElementLine; }
public static IEnumerable <CompletionItem> GetCompletionForType(FileCompiler fileCompiler, CodeElement codeElement, Token userFilterToken) { var node = GetMatchingNode(fileCompiler, codeElement); IEnumerable <TypeDefinition> types = null; if (node?.SymbolTable != null) { var userFilterText = userFilterToken == null ? string.Empty : userFilterToken.Text; types = node.SymbolTable.GetTypes( t => t.Name.StartsWith(userFilterText, StringComparison.InvariantCultureIgnoreCase) || (!t.IsFlagSet(Node.Flag.NodeIsIntrinsic) && t.VisualQualifiedName.ToString() .StartsWith(userFilterText, StringComparison.InvariantCultureIgnoreCase)), new List <SymbolTable.Scope> { SymbolTable.Scope.Declarations, SymbolTable.Scope.Global, SymbolTable.Scope.Intrinsic, SymbolTable.Scope.Namespace }); } return(CompletionFactoryHelpers.CreateCompletionItemsForType(types, node)); }
public void Init([NotNull] string path, TypeCobolOptions options, DocumentFormat format = null, IList <string> copies = null) { FileCompiler compiler; if (Compilers.TryGetValue(path, out compiler)) { return; } string filename = Path.GetFileName(path); var root = new DirectoryInfo(Directory.GetParent(path).FullName); if (format == null) { format = GetFormat(path); } CompilationProject project = new CompilationProject(path, root.FullName, Extensions, format.Encoding, format.EndOfLineDelimiter, format.FixedLineLength, format.ColumnsLayout, options); //Add copy folder into sourceFileProvider SourceFileProvider sourceFileProvider = project.SourceFileProvider; copies = copies ?? new List <string>(); foreach (var folder in copies) { sourceFileProvider.AddLocalDirectoryLibrary(folder, false, CopyExtensions, format.Encoding, format.EndOfLineDelimiter, format.FixedLineLength); } compiler = new FileCompiler(null, filename, project.SourceFileProvider, project, format.ColumnsLayout, options, CustomSymbols, false, project); Compilers.Add(path, compiler); Inits.Add(path, false); }
/// <summary> /// Get completion after OF Cobol Keyword. This method also adjust take in account the token before OF. /// </summary> /// <param name="fileCompiler"></param> /// <param name="codeElement"></param> /// <param name="userFilterToken"></param> /// <returns></returns> public static IEnumerable <CompletionItem> GetCompletionForOf(FileCompiler fileCompiler, CodeElement codeElement, Token userFilterToken, Position position) { IEnumerable <CompletionItem> completionItems = null; var userFilterText = userFilterToken == null ? string.Empty : userFilterToken.Text; var arrangedCodeElement = codeElement as CodeElementWrapper; var node = GetMatchingNode(fileCompiler, codeElement); var tokensUntilCursor = arrangedCodeElement?.ArrangedConsumedTokens .Except(new List <Token>() { userFilterToken }) .Where(t => (t.Line == position.line + 1 && t.StopIndex + 1 <= position.character) || t.Line < position.line + 1).Reverse(); //Detect what's before the OF token var tokenBeforeOf = tokensUntilCursor?.Skip(1).FirstOrDefault(); //Skip(1) will skip the OF token if (tokenBeforeOf == null || tokenBeforeOf.TokenType != TokenType.ADDRESS) //For now we only need to filter on adress. { return(completionItems); } switch (tokenBeforeOf.TokenType) //In the future, this will allow to switch between different token declared before OF. { case TokenType.ADDRESS: { var contextToken = tokensUntilCursor.Skip(2).FirstOrDefault(); //Try to get the token that may define the completion context completionItems = GetCompletionForAddressOf(node, contextToken, userFilterText); break; } } return(completionItems); }
/// <summary> /// Update the text contents of the file /// </summary> public void UpdateSourceFile(Uri fileUri, TextChangedEvent textChangedEvent, bool bAsync) { FileCompiler fileCompilerToUpdate = null; if (OpenedFileCompiler.TryGetValue(fileUri, out fileCompilerToUpdate)) { fileCompilerToUpdate.CompilationResultsForProgram.UpdateTextLines(textChangedEvent); if (!bAsync) {//Don't wait asynchroneous snapshot refresh. fileCompilerToUpdate.CompilationResultsForProgram.UpdateTokensLines( () => { fileCompilerToUpdate.CompilationResultsForProgram.RefreshTokensDocumentSnapshot(); fileCompilerToUpdate.CompilationResultsForProgram.RefreshProcessedTokensDocumentSnapshot(); fileCompilerToUpdate.CompilationResultsForProgram.RefreshCodeElementsDocumentSnapshot(); fileCompilerToUpdate.CompilationResultsForProgram.RefreshProgramClassDocumentSnapshot(); } ); } else { fileCompilerToUpdate.CompilationResultsForProgram.UpdateTokensLines(); } } }
public void Parse(string path, TextChangedEvent e = null) { //if the server is restarted during Eclipse lifetime, then we need to init the parser //This is useful when debugging. Perhaps it'll be deleted at the end if (!Compilers.ContainsKey(path)) { Init(path, new TypeCobolOptions { ExecToStep = ExecutionStep.Generate }); } Compiler = Compilers[path]; Compiler.CompilationResultsForProgram.TextLinesChanged += OnTextLine; Compiler.CompilationResultsForProgram.CodeElementsLinesChanged += OnCodeElementLine; if (!Inits[path]) { Inits[path] = true; // no need to update with the same content as at compiler creation } else if (e != null) { Compiler.CompilationResultsForProgram.UpdateTextLines(e); } try { Compiler.CompileOnce(); } catch (Exception ex) { throw new ParsingException(MessageCode.SyntaxErrorInParser, ex.Message, path, ex, true, true); } MissingCopys = Compiler.CompilationResultsForProgram.MissingCopies.Select(c => c.TextName).Distinct().ToList(); Compiler.CompilationResultsForProgram.TextLinesChanged -= OnTextLine; Compiler.CompilationResultsForProgram.CodeElementsLinesChanged -= OnCodeElementLine; }
private static CodeElement[] ParseCodeElements(string cobolString, out Diagnostic[] parserDiagnostics) { // Load text document from string var textDocument = new ReadOnlyTextDocument("test string", Encoding.Default, ColumnsLayout.FreeTextFormat, ""); textDocument.LoadChars(cobolString); // Create a compilation project and a compiler for this document var typeCobolOptions = new TypeCobolOptions(); var project = new CompilationProject("test project", ".", new[] { ".cbl", ".cpy" }, DocumentFormat.FreeTextFormat.Encoding, DocumentFormat.FreeTextFormat.EndOfLineDelimiter, DocumentFormat.FreeTextFormat.FixedLineLength, DocumentFormat.FreeTextFormat.ColumnsLayout, typeCobolOptions); var compiler = new FileCompiler(textDocument, project.SourceFileProvider, project, typeCobolOptions, false, project); // Execute compilation - until the CodeElements phase ONLY compiler.CompilationResultsForProgram.UpdateTokensLines(); compiler.CompilationResultsForProgram.RefreshTokensDocumentSnapshot(); compiler.CompilationResultsForProgram.RefreshProcessedTokensDocumentSnapshot(); compiler.CompilationResultsForProgram.RefreshCodeElementsDocumentSnapshot(); // Return CodeElements and Diagnostics var codeElementsDocument = compiler.CompilationResultsForProgram.CodeElementsDocumentSnapshot; var codeElements = codeElementsDocument.CodeElements.ToArray(); parserDiagnostics = codeElementsDocument.ParserDiagnostics.ToArray(); return(codeElements); }
public static CompilationUnit ParseCobolFile(string textName, DocumentFormat documentFormat = null, string folder = null, ExecutionStep execToStep = ExecutionStep.SemanticCheck) { if (folder == null) { folder = "Parser" + Path.DirectorySeparatorChar + "CodeElements"; } DirectoryInfo localDirectory = new DirectoryInfo(PlatformUtils.GetPathForProjectFile(folder)); if (!localDirectory.Exists) { throw new Exception(String.Format("Directory : {0} does not exist", localDirectory.FullName)); } if (documentFormat == null) { documentFormat = DocumentFormat.RDZReferenceFormat; } TypeCobolOptions options = new TypeCobolOptions { ExecToStep = execToStep }; //Create CompilerOptions. ExecToStep / AutoRemarks / HaltOnMissingCopy have to be set here. CompilationProject project = new CompilationProject("test", //First use *.cpy as tests will use file WITH extension for program but without extension for copy inside programs => small perf gain localDirectory.FullName, new string[] { ".cpy", ".cbl" }, documentFormat.Encoding, documentFormat.EndOfLineDelimiter, documentFormat.FixedLineLength, documentFormat.ColumnsLayout, options); FileCompiler compiler = new FileCompiler(null, textName, project.SourceFileProvider, project, documentFormat.ColumnsLayout, options, null, false, project); compiler.CompileOnce(); return(compiler.CompilationResultsForProgram); }
/// <summary> /// New implementation of the Init function, to allocate a BuildProject instance rather than a /// CompilationProject. /// </summary> /// <param name="path">The path of the file to parser</param> /// <param name="format">The resulting document format</param> /// <returns>The BuildProject instance created</returns> public new BuildProject Init(string path, DocumentFormat format = null) { FileCompiler compiler; if (Compilers.TryGetValue(path, out compiler)) { return(m_Projects[path]); } string directory = Directory.GetParent(path).FullName; string filename = Path.GetFileName(path); DirectoryInfo root = new DirectoryInfo(directory); if (format == null) { format = GetFormat(path); } TypeCobolOptions options = new TypeCobolOptions(); BuildProject project = new BuildProject(BuilderEngine, path, root.FullName, new string[] { "*.cbl", "*.cpy" }, format.Encoding, format.EndOfLineDelimiter, format.FixedLineLength, format.ColumnsLayout, options); m_Projects[path] = project; compiler = new FileCompiler(null, filename, project.SourceFileProvider, project, format.ColumnsLayout, options, CustomSymbols, false); Compilers.Add(path, compiler); Inits.Add(path, false); return(project); }
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, project); // 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"); }
ProjectCompileResult CompileFile(string srcFile) { CompileMessageCollection MessageCollection = new CompileMessageCollection(); FileCompiler compiler = new FileCompiler(); ProjectCompileResult result = compiler.Compile(srcFile, MessageCollection); return(result); }
/// <summary> /// Update the text contents of the file /// </summary> public void UpdateSourceFile(string fileName, TextChangedEvent textChangedEvent) { FileCompiler fileCompilerToUpdate = null; if (OpenedFileCompilers.TryGetValue(fileName, out fileCompilerToUpdate)) { fileCompilerToUpdate.CompilationResultsForProgram.UpdateTextLines(textChangedEvent); fileCompilerToUpdate.CompilationResultsForProgram.UpdateTokensLines(); } }
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()); }
/// <summary> /// Update the text contents of the file /// </summary> public void UpdateSourceFile(Uri fileUri, TextChangedEvent textChangedEvent) { FileCompiler fileCompilerToUpdate = null; if (OpenedFileCompiler.TryGetValue(fileUri, out fileCompilerToUpdate)) { _semanticUpdaterTimer?.Stop(); fileCompilerToUpdate.CompilationResultsForProgram.UpdateTextLines(textChangedEvent); if (IsLsrSourceTesting) { //Log text lines string var sb = new StringBuilder(); foreach (var cobolTextLine in fileCompilerToUpdate.CompilationResultsForProgram.CobolTextLines) { sb.AppendLine(cobolTextLine.SourceText); } _Logger(sb.ToString(), fileUri); } var handler = new Action <object, ExecutionStepEventArgs>((sender, args) => { ExecutionStepEventHandler(sender, args, fileUri); }); //Subscribe to FileCompilerEvent fileCompilerToUpdate.ExecutionStepEventHandler += handler.Invoke; var execStep = LsrTestOptions.ExecutionStep(fileCompilerToUpdate.CompilerOptions.ExecToStep); if (execStep > ExecutionStep.SyntaxCheck) { execStep = ExecutionStep.SyntaxCheck; //The maximum execstep authorize for incremental parsing is SyntaxCheck, } //further it's for semantic, which is handle by NodeRefresh method fileCompilerToUpdate.CompileOnce(execStep, fileCompilerToUpdate.CompilerOptions.HaltOnMissingCopy, fileCompilerToUpdate.CompilerOptions.UseAntlrProgramParsing); fileCompilerToUpdate.ExecutionStepEventHandler -= handler.Invoke; if (LsrTestOptions == LsrTestingOptions.NoLsrTesting || LsrTestOptions == LsrTestingOptions.LsrSemanticPhaseTesting) { if (!_timerDisabled) //If TimerDisabled is false, create a timer to automatically launch Node phase { lock (_fileCompilerWaittingForNodePhase) { if (!_fileCompilerWaittingForNodePhase.Contains(fileCompilerToUpdate)) { _fileCompilerWaittingForNodePhase.Add(fileCompilerToUpdate); //Store that this fileCompiler will soon need a Node Phase } } _semanticUpdaterTimer = new System.Timers.Timer(750); _semanticUpdaterTimer.Elapsed += (sender, e) => TimerEvent(sender, e, fileCompilerToUpdate); _semanticUpdaterTimer.Start(); } } } }
/// <summary> /// Get the matchig node for a given Token and a gien completion mode. Returning a matching Node or null. /// </summary> /// <param name="fileCompiler"></param> /// <param name="codeElement"></param> /// <returns></returns> public static Node GetMatchingNode(FileCompiler fileCompiler, CodeElement codeElement) { if (fileCompiler.CompilationResultsForProgram.ProgramClassDocumentSnapshot != null && fileCompiler.CompilationResultsForProgram.ProgramClassDocumentSnapshot.NodeCodeElementLinkers != null) { return (fileCompiler.CompilationResultsForProgram.ProgramClassDocumentSnapshot.NodeCodeElementLinkers .FirstOrDefault(t => t.Key.Equals(codeElement)).Value); } return(null); }
/// <summary> /// Start continuous background compilation on a newly opened file /// </summary> public void OpenSourceFile(string fileName, string sourceText) { ITextDocument initialTextDocumentLines = new ReadOnlyTextDocument(fileName, compilationProject.Encoding, compilationProject.ColumnsLayout, sourceText); FileCompiler fileCompiler = new FileCompiler(initialTextDocumentLines, compilationProject.SourceFileProvider, compilationProject, compilationProject.CompilationOptions, false, compilationProject); fileCompiler.CompilationResultsForProgram.UpdateTokensLines(); lock (OpenedFileCompilers) { OpenedFileCompilers.Add(fileName, fileCompiler); } fileCompiler.CompilationResultsForProgram.SetOwnerThread(Thread.CurrentThread); fileCompiler.StartContinuousBackgroundCompilation(200, 500, 1000, 3000); }
public ProjectCompileResult Compile(string srcFile) { MessageCollection.Clear(); //CompileMessageCollection MessageCollection = new CompileMessageCollection(); FileCompiler compiler = new FileCompiler(this.InitPorjectModel); ProjectCompileResult result = compiler.Compile(srcFile, MessageCollection); return(result); //ZProjectModel projectModel = Init(filePath); //ZProjectEngine builder = new ZProjectEngine(MessageCollection, projectModel); //ProjectCompileResult result = builder.Compile(); //return result; }
private static void CompileInputs(IList <string> inputs, IList <string> references, string output) { string[] referenceFilePaths = references .Select(reference => new DirectoryInfo(reference).FullName) .ToArray(); // todo: do something better? foreach (var reference in referenceFilePaths) { AssemblyLoadContext.Default.LoadFromAssemblyPath(reference); } FileCompiler.CompileFiles(inputs.ToArray(), referenceFilePaths, output); }
/// <summary> /// Stop continuous background compilation after a file has been closed /// </summary> public void CloseSourceFile(string fileName) { FileCompiler fileCompilerToClose = null; lock (OpenedFileCompilers) { if (OpenedFileCompilers.ContainsKey(fileName)) { fileCompilerToClose = OpenedFileCompilers[fileName]; OpenedFileCompilers.Remove(fileName); } } fileCompilerToClose.StopContinuousBackgroundCompilation(); }
private IEnumerable <CodeElementWrapper> CodeElementFinder(FileCompiler fileCompiler, Position position) { List <CodeElement> codeElements = new List <CodeElement>(); List <CodeElement> ignoredCodeElements = new List <CodeElement>(); int lineIndex = position.line; // Find the token located below the mouse pointer while (codeElements.Count == 0) { var codeElementsLine = fileCompiler.CompilationResultsForProgram.ProgramClassDocumentSnapshot.PreviousStepSnapshot.Lines[lineIndex]; if (codeElementsLine != null && codeElementsLine.CodeElements != null && !(codeElementsLine.CodeElements[0] is SentenceEnd)) { //Ignore all the EndOfFile token var tempCodeElements = codeElementsLine.CodeElements.Where(c => c.ConsumedTokens.Any(t => t.TokenType != TokenType.EndOfFile)); foreach (var tempCodeElement in tempCodeElements.Reverse()) { if (!tempCodeElement.ConsumedTokens.Any(t => /*CompletionElligibleTokens.IsCompletionElligibleToken(t) &&*/ ((t.Line == position.line + 1 && t.StopIndex + 1 <= position.character) || t.Line < position.line + 1))) { ignoredCodeElements.Add(tempCodeElement); } else { codeElements.Add(tempCodeElement); } } if (tempCodeElements.Any(c => c.ConsumedTokens.Any(t => t.TokenType == TokenType.PeriodSeparator && !(t is Compiler.AntlrUtils.MissingToken)))) { break; } } lineIndex--; //decrease lineIndex to get the previous line of TypeCobol Tree. } codeElements.AddRange(ignoredCodeElements); //Add the previously ignored Code Elements, may be they are usefull to help completion. if (!codeElements.Any(c => c.ConsumedTokens.Any(t => t.Line <= position.line + 1))) { return(null); //If nothing is found near the cursor we can't do anything } //Create a list of CodeElementWrapper in order to loose the ConsumedTokens ref. return(codeElements.Select(c => new CodeElementWrapper(c))); }
/// <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; var inputFileName = fileName.Substring(0, 8); 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); //Let's parse file for the first time after opening. } }
/// <summary> /// Stop continuous background compilation after a file has been closed /// </summary> public void CloseSourceFile(Uri fileUri) { FileCompiler fileCompilerToClose = null; lock (OpenedFileCompiler) { if (OpenedFileCompiler.ContainsKey(fileUri)) { fileCompilerToClose = OpenedFileCompiler[fileUri]; OpenedFileCompiler.Remove(fileUri); fileCompilerToClose.StopContinuousBackgroundCompilation(); fileCompilerToClose.CompilationResultsForProgram.ProgramClassChanged -= ProgramClassChanged; } } }
public static IEnumerable <CompletionItem> GetCompletionForProcedure(FileCompiler fileCompiler, CodeElement codeElement, Token userFilterToken, Dictionary <SignatureInformation, FunctionDeclaration> functionDeclarationSignatureDictionary) { var node = GetMatchingNode(fileCompiler, codeElement); IEnumerable <FunctionDeclaration> procedures = null; IEnumerable <DataDefinition> variables = null; var completionItems = new List <CompletionItem>(); if (node != null) { if (node.SymbolTable != null) { var userFilterText = userFilterToken == null ? string.Empty : userFilterToken.Text; procedures = node.SymbolTable.GetFunctions( f => f.VisualQualifiedName.ToString() .StartsWith(userFilterText, StringComparison.InvariantCultureIgnoreCase) || f.Name.StartsWith(userFilterText, StringComparison.InvariantCultureIgnoreCase), new List <SymbolTable.Scope> { SymbolTable.Scope.Declarations, SymbolTable.Scope.Intrinsic, SymbolTable.Scope.Namespace }); variables = node.SymbolTable.GetVariables(da => da.Picture != null && da.DataType == Compiler.CodeElements.DataType.Alphanumeric && da.Name.StartsWith(userFilterText, StringComparison.InvariantCultureIgnoreCase), new List <SymbolTable.Scope> { SymbolTable.Scope.Declarations, SymbolTable.Scope.Global }); } } completionItems.AddRange(CompletionFactoryHelpers.CreateCompletionItemsForProcedures(procedures, node, functionDeclarationSignatureDictionary)); foreach (var variable in variables) { var completionItem = new CompletionItem(string.Format("{0}", variable.Name)); completionItem.insertText = variable.Name; completionItem.kind = CompletionItemKind.Variable; completionItems.Add(completionItem); } return(completionItems); }
public static IEnumerable <CompletionItem> GetCompletionForVariable(FileCompiler fileCompiler, CodeElement codeElement, Expression <Func <DataDefinition, bool> > predicate) { var completionItems = new List <CompletionItem>(); var node = GetMatchingNode(fileCompiler, codeElement); if (node == null) { return(completionItems); } var variables = node.SymbolTable.GetVariables(predicate, SymbolTable.Scope.GlobalStorage); completionItems.AddRange(CompletionFactoryHelpers.CreateCompletionItemsForVariables(variables)); return(completionItems); }
public static IEnumerable <CompletionItem> GetCompletionForLibrary(FileCompiler fileCompiler, CodeElement codeElement, Token userFilterToken) { var callNode = GetMatchingNode(fileCompiler, codeElement); IEnumerable <Program> programs = null; if (callNode?.SymbolTable != null) { programs = callNode.SymbolTable.GetPrograms(userFilterToken != null ? userFilterToken.Text : string.Empty); } return(programs?.Select(prog => new CompletionItem(prog.Name) { kind = CompletionItemKind.Module }) ?? new List <CompletionItem>()); }
/// <summary> /// Get the paragraph that can be associated to PERFORM Completion token. /// </summary> /// <param name="fileCompiler">The target FileCompiler instance</param> /// <param name="performToken">The PERFORM token</param> /// <returns></returns> public static IEnumerable <CompletionItem> GetCompletionPerformParagraph(FileCompiler fileCompiler, CodeElement codeElement, Token userFilterToken) { var performNode = GetMatchingNode(fileCompiler, codeElement); IEnumerable <Paragraph> pargraphs = null; IEnumerable <DataDefinition> variables = null; var completionItems = new List <CompletionItem>(); if (performNode != null) { if (performNode.SymbolTable != null) { var userFilterText = userFilterToken == null ? string.Empty : userFilterToken.Text; pargraphs = performNode.SymbolTable.GetParagraphs(p => p.Name.StartsWith(userFilterText, StringComparison.InvariantCultureIgnoreCase)); variables = performNode.SymbolTable.GetVariables(da => da.Picture != null && da.DataType == Compiler.CodeElements.DataType.Numeric && da.Name.StartsWith(userFilterText, StringComparison .InvariantCultureIgnoreCase), new List <SymbolTable.Scope> { SymbolTable.Scope.Declarations, SymbolTable.Scope.Global }); } } if (pargraphs != null) { completionItems.AddRange(pargraphs.Select(para => new CompletionItem(para.Name) { kind = CompletionItemKind.Reference })); } if (variables != null) { foreach (var variable in variables) { var completionItem = new CompletionItem(string.Format("{0} PIC{1}", variable.Name, variable.Picture.NormalizedValue)); completionItem.insertText = variable.Name; completionItem.kind = CompletionItemKind.Variable; completionItems.Add(completionItem); } } return(completionItems); }
/// <summary> /// Event method called when the timer reach the Elapsed time /// </summary> /// <param name="sender"></param> /// <param name="eventArgs"></param> /// <param name="fileCompiler"></param> private void TimerEvent(object sender, ElapsedEventArgs eventArgs, FileCompiler fileCompiler) { try { _semanticUpdaterTimer.Stop(); Action nodeRefreshAction = () => { RefreshSyntaxTree(fileCompiler); }; lock (MessagesActionsQueue) { MessagesActionsQueue.Enqueue(new MessageActionWrapper(nodeRefreshAction)); } } catch (Exception e) { //In case Timer Thread crash ExceptionTriggered(null, new ThreadExceptionEventArgs(e)); } }
public static CompilationUnit ParseCobolString(string cobolString) { //Prepare var textDocument = new ReadOnlyTextDocument("Empty doc", Encoding.Default, ColumnsLayout.FreeTextFormat, ""); textDocument.LoadChars(cobolString); var typeCobolOptions = new TypeCobolOptions(); var project = new CompilationProject("Empty project", ".", new[] { ".cbl", ".cpy" }, DocumentFormat.FreeTextFormat.Encoding, DocumentFormat.FreeTextFormat.EndOfLineDelimiter, DocumentFormat.FreeTextFormat.FixedLineLength, DocumentFormat.FreeTextFormat.ColumnsLayout, typeCobolOptions); var compiler = new FileCompiler(textDocument, project.SourceFileProvider, project, typeCobolOptions, false, project); compiler.CompileOnce(); return(compiler.CompilationResultsForProgram); }