commit 04dff697d9783cbe522075a84ada8e7efc1a0186 Author: osmedile Date: Thu Oct 27 22:59:31 2022 +0200 Replace ImmutableList by interface diff --git a/TypeCobol.Test/Parser/Scanner/ScannerUtils.cs b/TypeCobol.Test/Parser/Scanner/ScannerUtils.cs index 70a5db13a..a7b5cc13e 100644 --- a/TypeCobol.Test/Parser/Scanner/ScannerUtils.cs +++ b/TypeCobol.Test/Parser/Scanner/ScannerUtils.cs @@ -75,7 +75,7 @@ namespace TypeCobol.Test.Parser.Scanner tokensLinesList.AddRange(tokensLines); var initialScanState = new MultilineScanState(TextSourceInfo.EncodingForAlphanumericLiterals); - ScannerStep.ScanDocument(TextSourceInfo, tokensLinesList, CompilerOptions, CopyTextNameVariations, initialScanState); + ScannerStep.ScanDocument(TextSourceInfo, tokensLinesList.ToImmutable(), CompilerOptions, CopyTextNameVariations, initialScanState); StringBuilder sbResult = new StringBuilder(); for (int i = 0; i < tokensLines.Length; i++) diff --git a/TypeCobol/Compiler/CompilationDocument.cs b/TypeCobol/Compiler/CompilationDocument.cs index 3d24b3192..093e5b5c9 100644 --- a/TypeCobol/Compiler/CompilationDocument.cs +++ b/TypeCobol/Compiler/CompilationDocument.cs @@ -654,10 +654,10 @@ namespace TypeCobol.Compiler if (tokensDocument != null) { // Process all lines of the document for the first time - PreprocessorStep.ProcessDocument(this, ((ImmutableList)tokensDocument.Lines), _documentImporter, perfStatsForParserInvocation, out missingCopies); + PreprocessorStep.ProcessDocument(this, ((ISearchableReadOnlyList)tokensDocument.Lines), _documentImporter, perfStatsForParserInvocation, out missingCopies); // Create the first processed tokens document snapshot - ProcessedTokensDocumentSnapshot = CreateProcessedTokensDocument(new DocumentVersion(this), (ISearchableReadOnlyList) tokensDocument.Lines); + ProcessedTokensDocumentSnapshot = CreateProcessedTokensDocument(new DocumentVersion(this), (ISearchableReadOnlyList) tokensDocument.Lines); } else { @@ -667,9 +667,8 @@ namespace TypeCobol.Compiler } else { - ImmutableList.Builder processedTokensDocumentLines = ((ImmutableList) tokensDocument.Lines).ToBuilder(); IList> documentChanges = PreprocessorStep.ProcessChanges(this, - processedTokensDocumentLines, tokensLineChanges, PrepareDocumentLineForUpdate, + (ISearchableReadOnlyList)tokensDocument.Lines, tokensLineChanges, PrepareDocumentLineForUpdate, _documentImporter, perfStatsForParserInvocation, out missingCopies); // Create a new version of the document to track these changes @@ -685,7 +684,7 @@ namespace TypeCobol.Compiler ProcessedTokensDocumentSnapshot = CreateProcessedTokensDocument(currentProcessedTokensLineVersion, processedTokensDocumentLines.ToImmutable()); } - ProcessedTokensDocument CreateProcessedTokensDocument(DocumentVersion version, ISearchableReadOnlyList lines) + ProcessedTokensDocument CreateProcessedTokensDocument(DocumentVersion version, ISearchableReadOnlyList lines) { //Apply automatic replacing of partial-words for direct copy parsing mode return UseDirectCopyParsing diff --git a/TypeCobol/Compiler/CompilationUnit.cs b/TypeCobol/Compiler/CompilationUnit.cs index 4c64bad8e..87c6273ff 100644 --- a/TypeCobol/Compiler/CompilationUnit.cs +++ b/TypeCobol/Compiler/CompilationUnit.cs @@ -98,7 +98,7 @@ namespace TypeCobol.Compiler CodeElementsParserStep.ParseDocument(processedTokensDocument, CompilerOptions, perfStatsForParserInvocation); // Create the first code elements document snapshot - CodeElementsDocumentSnapshot = new CodeElementsDocument(processedTokensDocument, new DocumentVersion(this), ((ImmutableList)processedTokensDocument.Lines)); + CodeElementsDocumentSnapshot = new CodeElementsDocument(processedTokensDocument, new DocumentVersion(this), ((ISearchableReadOnlyList)processedTokensDocument.Lines)); } } else @@ -115,8 +115,7 @@ namespace TypeCobol.Compiler currentCodeElementsLinesVersion = currentCodeElementsLinesVersion.next; // Update the code elements document snapshot - ImmutableList.Builder codeElementsDocumentLines = ((ImmutableList)processedTokensDocument.Lines).ToBuilder(); - CodeElementsDocumentSnapshot = new CodeElementsDocument(processedTokensDocument, currentCodeElementsLinesVersion, codeElementsDocumentLines.ToImmutable()); + CodeElementsDocumentSnapshot = new CodeElementsDocument(processedTokensDocument, currentCodeElementsLinesVersion, (ISearchableReadOnlyList) processedTokensDocument.Lines); } // Stop perf measurement @@ -253,10 +252,9 @@ namespace TypeCobol.Compiler var customAnalyzers = _analyzerProvider?.CreateSyntaxDrivenAnalyzers(CompilerOptions, TextSourceInfo); // Program and Class parsing is not incremental : the objects are rebuilt each time this method is called - //TODO cast to ImmutableList sometimes fails here ProgramClassParserStep.CupParseProgramOrClass( TextSourceInfo, - (ImmutableList) codeElementsDocument.Lines, + codeElementsDocument.Lines, CompilerOptions, CustomSymbols, perfStatsForParserInvocation, diff --git a/TypeCobol/Compiler/CupParser/CodeElementTokenizer.cs b/TypeCobol/Compiler/CupParser/CodeElementTokenizer.cs index ae7fd126a..ec1157cab 100644 --- a/TypeCobol/Compiler/CupParser/CodeElementTokenizer.cs +++ b/TypeCobol/Compiler/CupParser/CodeElementTokenizer.cs @@ -31,7 +31,7 @@ namespace TypeCobol.Compiler.CupParser /// CodeElement lines to enumerate as symbols. /// Optional fake CodeElements to enumerate before real ones. /// Optional fake CodeElements to enumerate after real ones. - public CodeElementTokenizer(IEnumerable lines, IEnumerable before = null, IEnumerable after = null) + public CodeElementTokenizer(IEnumerable lines, IEnumerable before = null, IEnumerable after = null) : this(before?.Select(ToSymbol), lines, after?.Select(ToSymbol)) { @@ -53,7 +53,7 @@ namespace TypeCobol.Compiler.CupParser } - private CodeElementTokenizer(IEnumerable before, IEnumerable lines, IEnumerable after) + private CodeElementTokenizer(IEnumerable before, IEnumerable lines, IEnumerable after) { _enumerator = Enumerator(before, lines, after); } @@ -68,7 +68,7 @@ namespace TypeCobol.Compiler.CupParser return null; } - private IEnumerator Enumerator(IEnumerable before, IEnumerable lines, IEnumerable after) + private IEnumerator Enumerator(IEnumerable before, IEnumerable lines, IEnumerable after) { //symbols before if (before != null) diff --git a/TypeCobol/Compiler/CupParser/NodeBuilder/ProgramClassBuilder.cs b/TypeCobol/Compiler/CupParser/NodeBuilder/ProgramClassBuilder.cs index 29b0c1e3c..7ba00ecff 100644 --- a/TypeCobol/Compiler/CupParser/NodeBuilder/ProgramClassBuilder.cs +++ b/TypeCobol/Compiler/CupParser/NodeBuilder/ProgramClassBuilder.cs @@ -87,9 +87,9 @@ namespace TypeCobol.Compiler.CupParser.NodeBuilder private readonly SymbolTable TableOfIntrinsics; private readonly SymbolTable TableOfNamespaces; - private readonly IReadOnlyList _codeElementsLines; + private readonly IReadOnlyList _codeElementsLines; - public ProgramClassBuilder(IReadOnlyList codeElementsLines) + public ProgramClassBuilder(IReadOnlyList codeElementsLines) { // Intrinsics and Namespaces always exist. Intrinsic table has no enclosing scope. TableOfIntrinsics = new SymbolTable(null, SymbolTable.Scope.Intrinsic); diff --git a/TypeCobol/Compiler/Parser/ICodeElementsLine.cs b/TypeCobol/Compiler/Parser/ICodeElementsLine.cs index 957a44b30..d85472080 100644 --- a/TypeCobol/Compiler/Parser/ICodeElementsLine.cs +++ b/TypeCobol/Compiler/Parser/ICodeElementsLine.cs @@ -15,7 +15,12 @@ namespace TypeCobol.Compiler.Parser /// Code elements STARTING on this line /// IList CodeElements { get; } - + + /// + /// True if a code element starts on the current line + /// + bool HasCodeElements { get; } + /// /// Error and warning messages produced while parsing the source text line /// diff --git a/TypeCobol/Compiler/Parser/ProgramClassParserStep.cs b/TypeCobol/Compiler/Parser/ProgramClassParserStep.cs index f148ee5e0..241020579 100644 --- a/TypeCobol/Compiler/Parser/ProgramClassParserStep.cs +++ b/TypeCobol/Compiler/Parser/ProgramClassParserStep.cs @@ -42,7 +42,7 @@ namespace TypeCobol.Compiler.Parser } public static void CupParseProgramOrClass( TextSourceInfo textSourceInfo, - ISearchableReadOnlyList codeElementsLines, + ISearchableReadOnlyList codeElementsLines, TypeCobolOptions compilerOptions, SymbolTable customSymbols, PerfStatsForParserInvocation perfStatsForParserInvocation, diff --git a/TypeCobol/Compiler/Preprocessor/AutoReplacePartialWordsTokensDocument.cs b/TypeCobol/Compiler/Preprocessor/AutoReplacePartialWordsTokensDocument.cs index 5dcb793db..20c3fe1bb 100644 --- a/TypeCobol/Compiler/Preprocessor/AutoReplacePartialWordsTokensDocument.cs +++ b/TypeCobol/Compiler/Preprocessor/AutoReplacePartialWordsTokensDocument.cs @@ -82,7 +82,7 @@ namespace TypeCobol.Compiler.Preprocessor private readonly TypeCobolOptions _compilerOptions; - public AutoReplacePartialWordsTokensDocument(TokensDocument previousStepSnapshot, DocumentVersion processedTokensLinesVersion, ISearchableReadOnlyList processedTokensLines, TypeCobolOptions compilerOptions) + public AutoReplacePartialWordsTokensDocument(TokensDocument previousStepSnapshot, DocumentVersion processedTokensLinesVersion, ISearchableReadOnlyList processedTokensLines, TypeCobolOptions compilerOptions) : base(previousStepSnapshot, processedTokensLinesVersion, processedTokensLines, compilerOptions) { _compilerOptions = compilerOptions;