Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Codegen/src/Generators/ExpandingCopyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ public void Generate(CompilationUnit compilationUnit, ColumnsLayout columns = Co

// 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);
compilationUnit.TextSourceInfo, processedTokensDocument.Lines, compilationUnit.CompilerOptions, null);

var stopwatch = Stopwatch.StartNew();

Expand Down
66 changes: 66 additions & 0 deletions Codegen/test/TestTypeCobolCodegen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,72 @@ public void TypedefBodyInsideCopy()
null, new List<string>() {copies});
}

[TestMethod]
[TestCategory("Codegen")]
[TestProperty("Time", "fast")]
public void CopyReplace4Colon()
{
string dir = System.IO.Directory.GetCurrentDirectory();
string copies = Path.Combine(dir, "resources", "input", "TypeCobol", "CopyReplace4Colon");
CodegenTestUtils.ParseGenerateCompare(Path.Combine("TypeCobol", "CopyReplace4Colon", "CopyReplace4Colon") + ".rdz.cbl", false,
null, new List<string>() { copies });
}

[TestMethod]
[TestCategory("Codegen")]
[TestProperty("Time", "fast")]
public void CopyReplace4Colon2()
{
string dir = System.IO.Directory.GetCurrentDirectory();
string copies = Path.Combine(dir, "resources", "input", "TypeCobol", "CopyReplace4Colon");
CodegenTestUtils.ParseGenerateCompare(Path.Combine("TypeCobol", "CopyReplace4Colon", "CopyReplace4Colon2") + ".rdz.cbl", false,
null, new List<string>() { copies });
}

[TestMethod]
[TestCategory("Codegen")]
[TestProperty("Time", "fast")]
public void CopyReplace4Colon3()
{
string dir = System.IO.Directory.GetCurrentDirectory();
string copies = Path.Combine(dir, "resources", "input", "TypeCobol", "CopyReplace4Colon");
CodegenTestUtils.ParseGenerateCompare(Path.Combine("TypeCobol", "CopyReplace4Colon", "CopyReplace4Colon3") + ".rdz.cbl", false,
null, new List<string>() { copies });
}

[TestMethod]
[TestCategory("Codegen")]
[TestProperty("Time", "fast")]
public void CopyReplace4Colon4()
{
string dir = System.IO.Directory.GetCurrentDirectory();
string copies = Path.Combine(dir, "resources", "input", "TypeCobol", "CopyReplace4Colon");
CodegenTestUtils.ParseGenerateCompare(Path.Combine("TypeCobol", "CopyReplace4Colon", "CopyReplace4Colon4") + ".rdz.cbl", false,
null, new List<string>() { copies });
}

[TestMethod]
[TestCategory("Codegen")]
[TestProperty("Time", "fast")]
public void CopyReplace4Colon5()
{
string dir = System.IO.Directory.GetCurrentDirectory();
string copies = Path.Combine(dir, "resources", "input", "TypeCobol", "CopyReplace4Colon");
CodegenTestUtils.ParseGenerateCompare(Path.Combine("TypeCobol", "CopyReplace4Colon", "CopyReplace4Colon5") + ".rdz.cbl", false,
null, new List<string>() { copies });
}

[TestMethod]
[TestCategory("Codegen")]
[TestProperty("Time", "fast")]
public void CopyReplace4Colon6()
{
string dir = System.IO.Directory.GetCurrentDirectory();
string copies = Path.Combine(dir, "resources", "input", "TypeCobol", "CopyReplace4Colon");
CodegenTestUtils.ParseGenerateCompare(Path.Combine("TypeCobol", "CopyReplace4Colon", "CopyReplace4Colon6") + ".rdz.cbl", false,
null, new List<string>() { copies });
}

/// <summary>
/// This test is for the issue https://github.com/TypeCobolTeam/TypeCobol/issues/1490
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. CPYRPL4C.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 xxxENT. COPY YxxxENT REPLACING ==::== BY ====.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe modify one of the test to have a non-empty replacement text.

PROCEDURE DIVISION.
MOVE 'A' TO xxxENT-FCT01-Var1.
END PROGRAM CPYRPL4C.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
 IDENTIFICATION DIVISION.
PROGRAM-ID. CPYRPL4C.

ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 xxxENT. COPY YxxxENT2 REPLACING ==::== BY ====.
PROCEDURE DIVISION.
MOVE 'A' TO xxxENT-FCT01-Var1.
MOVE 'A' TO xxxENT2-FCT01-Var1.
END PROGRAM CPYRPL4C.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
 IDENTIFICATION DIVISION.
PROGRAM-ID. CPYRPL4C.

ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 xxxENT. COPY YxxxENT3 REPLACING ==::== BY ====.
PROCEDURE DIVISION.
MOVE 'A' TO xxxENT-FCT01-Var1.
MOVE 'A' TO xxxENT2-FCT01-Var1.
MOVE 'A' TO xxxENT3-FCT01-Var1.
END PROGRAM CPYRPL4C.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
 IDENTIFICATION DIVISION.
PROGRAM-ID. CPYRPL4C.

ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 xxxENT. COPY YxxxENT REPLACING ==::== BY ====.
01 xxxENT2. COPY YxxxENT REPLACING ==::== BY ====.
PROCEDURE DIVISION.
MOVE 'A' TO xxxENT-FCT01-Var1 OF xxxENT.
MOVE 'A' TO xxxENT-FCT01-Var1 OF xxxENT2.
END PROGRAM CPYRPL4C.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
 IDENTIFICATION DIVISION.
PROGRAM-ID. CPYRPL4C.

ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 xxxENT. COPY YxxxENT REPLACING ==::== BY ====.
01 xxxENT2. COPY YxxxENT2 REPLACING ==::== BY ====.
PROCEDURE DIVISION.
MOVE 'A' TO xxxENT-FCT01-Var1 OF xxxENT.
MOVE 'A' TO xxxENT2-FCT01-Var1.
MOVE 'A' TO xxxENT-FCT01-Var1 OF xxxENT1.
END PROGRAM CPYRPL4C.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
 IDENTIFICATION DIVISION.
PROGRAM-ID. CPYRPL4C.

ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 xxxENT2. COPY YxxxENT REPLACING ==::== BY ====.
01 xxxENT3. COPY YxxxENT REPLACING ==::== BY ==S==.
PROCEDURE DIVISION.
MOVE 'A' TO xxxENTS-FCT01-Var1.
END PROGRAM CPYRPL4C.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
IDENTIFICATION DIVISION.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the test method for this sample.

PROGRAM-ID. CPYRPL4C.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 xxxENT. COPY YxxxENT REPLACING ==== BY ====.
PROCEDURE DIVISION.
MOVE 'A' TO xxxENT-FCT01-Var1.
END PROGRAM CPYRPL4C.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
 05 xxxENT::-FCT01.
10 xxxENT::-FCT01-Var1 PIC X(05).
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
 05 xxxENT::-FCT01.
10 xxxENT::-FCT01-Var1 PIC X(05).
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
 05 xxxENT2::-FCT01.
10 xxxENT2::-FCT01-Var1 PIC X(05).
01 xxxENT1. COPY YxxxENT REPLACING ==::== BY ====.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
 05 xxxENT3::-FCT01.
10 xxxENT3::-FCT01-Var1 PIC X(05).
01 xxxENT2. COPY YxxxENT2 REPLACING ==::== BY ====.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
 IDENTIFICATION DIVISION.
PROGRAM-ID. CPYRPL4C.

ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 xxxENT. COPY YxxxENT REPLACING ==::== BY ====.
PROCEDURE DIVISION.
MOVE 'A' TO xxxENT-FCT01-Var1.
END PROGRAM CPYRPL4C.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
 IDENTIFICATION DIVISION.
PROGRAM-ID. CPYRPL4C.

ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 xxxENT. COPY YxxxENT2 REPLACING ==::== BY ====.
PROCEDURE DIVISION.
MOVE 'A' TO xxxENT-FCT01-Var1.
MOVE 'A' TO xxxENT2-FCT01-Var1.
END PROGRAM CPYRPL4C.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
 IDENTIFICATION DIVISION.
PROGRAM-ID. CPYRPL4C.

ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 xxxENT. COPY YxxxENT3 REPLACING ==::== BY ====.
PROCEDURE DIVISION.
MOVE 'A' TO xxxENT-FCT01-Var1.
MOVE 'A' TO xxxENT2-FCT01-Var1.
MOVE 'A' TO xxxENT3-FCT01-Var1.
END PROGRAM CPYRPL4C.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
 IDENTIFICATION DIVISION.
PROGRAM-ID. CPYRPL4C.

ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 xxxENT. COPY YxxxENT REPLACING ==::== BY ====.
01 xxxENT2. COPY YxxxENT REPLACING ==::== BY ====.
PROCEDURE DIVISION.
MOVE 'A' TO xxxENT-FCT01-Var1 OF xxxENT.
MOVE 'A' TO xxxENT-FCT01-Var1 OF xxxENT2.
END PROGRAM CPYRPL4C.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
 IDENTIFICATION DIVISION.
PROGRAM-ID. CPYRPL4C.

ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 xxxENT. COPY YxxxENT REPLACING ==::== BY ====.
01 xxxENT2. COPY YxxxENT2 REPLACING ==::== BY ====.
PROCEDURE DIVISION.
MOVE 'A' TO xxxENT-FCT01-Var1 OF xxxENT.
MOVE 'A' TO xxxENT2-FCT01-Var1.
MOVE 'A' TO xxxENT-FCT01-Var1 OF xxxENT1.
END PROGRAM CPYRPL4C.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
 IDENTIFICATION DIVISION.
PROGRAM-ID. CPYRPL4C.

ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 xxxENT2. COPY YxxxENT REPLACING ==::== BY ====.
01 xxxENT3. COPY YxxxENT REPLACING ==::== BY ==S==.
PROCEDURE DIVISION.
MOVE 'A' TO xxxENTS-FCT01-Var1.
END PROGRAM CPYRPL4C.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty file ? Is the file actually required since no generation occurs because of previous errors ?

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. CPYRPL4C.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 xxxENT. COPY YxxxENT REPLACING ==== BY ====.
PROCEDURE DIVISION.
MOVE 'A' TO xxxENT-FCT01-Var1.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact the test also need to check that variable name inside the copy are correctly replaced;
Can you add this :
01 xxxENT2. COPY YxxxENT REPLACING ==::== BY ====.
01 xxxENT3. COPY YxxxENT REPLACING ==::== BY ==S==.

And this move:
MOVE 'A' TO xxxENTS-FCT01-Var1.

And also create the copy YxxxENT with same content as Codegen/test/resources/input/TypeCobol/CopyReplace4Colon/YxxxENT.cpy

Copy link
Contributor Author

@mayanje mayanje Oct 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I need also further tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a test with a mix of Empty and non-empty replacing, like:
Copy YDVZOSM:

       01  :MDVZOSM:-A::.
           05 :MDVZOSM:-A::-Var0 pic X.

And the source:

       IDENTIFICATION division.
       PROGRAM-ID. DVZS0OSM.
       data division.
       working-storage section.
       COPY YDVZOSM replacing ==::== by ====
                                         ==:MDVZOSM:== by ==MDVZOSM==.
       COPY YDVZOSM replacing ==::== by ==2==
                                         ==:MDVZOSM:== by ==Foo==.
       procedure division.
           move 'A' to MDVZOSM-A
           move 'A' to Foo-A2
           .
       end program DVZS0OSM.

END PROGRAM CPYRPL4C.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--- Diagnostics ---
Line 7[25,31] <27, Error, Syntax> - Syntax error : "REPLACE" Empty Comparison Pseudo Text.
Line 7[20,55] <28, Error, Directives> - Failed to load COPY : Cobol source file not found: YxxxENT
Line 7[12,17] <27, Error, Syntax> - Syntax error : A group item cannot be empty. OffendingSymbol=[12,17:xxxENT]<UserDefinedWord>
Line 9[24,40] <30, Error, Semantics> - Semantic error: Symbol xxxENT-FCT01-Var1 is not referenced OffendingSymbol=[24,40:xxxENT-FCT01-Var1]<UserDefinedWord>

--- Program ---
PROGRAM: CPYRPL4C common:False initial:False recursive:False
author: ? written: ? compiled: ? installation: ? security: ?
--- Intrinsic:Namespace:Program:Global:Local
-- DATA --------
xxxENT:Alphanumeric
--- Intrinsic
-- TYPES -------
BOOL:BOOL
DATE:DATE
CURRENCY:CURRENCY
STRING:STRING
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ Line 0[5,6] <21, Error, Tokens> - The delimiter character of this continuation l
=>continuation:[6,9:titi15]<UserDefinedWord>
[10,10: ]<SpaceSeparator>
[11,12:==]<PseudoTextDelimiter>
Line 0[11,12] <15, Error, Tokens> - Invalid character found after pseudo-text delimiter == : expecting space, comma, semicolon or period

-- Line 43 --
[2,3:==]<PseudoTextDelimiter>
Expand Down
2 changes: 0 additions & 2 deletions TypeCobol.Test/Parser/Scanner/ResultFiles/PseudoText.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
[10,11:= ]<EqualOperator>
[12,13:==]<PseudoTextDelimiter>
[14,15:= ]<EqualOperator>
Line 0[12,13] <15, Error, Tokens> - Invalid character found after pseudo-text delimiter == : expecting space, comma, semicolon or period

-- Line 3 --
[1,2:==]<PseudoTextDelimiter>
Expand All @@ -31,7 +30,6 @@ Line 0[12,13] <15, Error, Tokens> - Invalid character found after pseudo-text de
[7,8:==]<PseudoTextDelimiter>
[9,10:==]<PseudoTextDelimiter>
[11,11:a]<UserDefinedWord>
Line 0[9,10] <15, Error, Tokens> - Invalid character found after pseudo-text delimiter == : expecting space, comma, semicolon or period

-- Line 4 --
[1,1: ]<SpaceSeparator>
Expand Down
39 changes: 35 additions & 4 deletions TypeCobol/Compiler/CompilationDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,23 @@ public class CompilationDocument
public List<RemarksDirective.TextNameVariation> CopyTextNamesVariations { get; set; }

public List<CopyDirective> MissingCopies { get; set; }
/// <summary>
/// Is this Compilation Document for a Copy.
/// </summary>
internal bool IsForCopy
{
get;
set;
Comment on lines +60 to +63
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CompilationUnit is for programs so this property can be made readonly and set at construction time (default true, false when called from CompilationUnit constructor)

}

/// <summary>
/// Issue #315
/// </summary>
private MultilineScanState initialScanStateForCopy;
public MultilineScanState InitialScanStateForCopy
{
get;
set;
}

/// <summary>
/// Informations used to track the performance of each compilation step
Expand Down Expand Up @@ -181,7 +193,7 @@ public CompilationDocument(TextSourceInfo textSourceInfo, IEnumerable<ITextLine>
PerfStatsForScanner = new PerfStatsForCompilationStep(CompilationStep.Scanner);
PerfStatsForPreprocessor = new PerfStatsForParsingStep(CompilationStep.Preprocessor);

initialScanStateForCopy = scanState;
InitialScanStateForCopy = scanState;
}

/// <summary>
Expand Down Expand Up @@ -476,14 +488,33 @@ public void UpdateTokensLines(System.Action onVersion = null)
// Apply text changes to the compilation document
if (scanAllDocumentLines)
{
ScannerStep.ScanDocument(TextSourceInfo, compilationDocumentLines, CompilerOptions, CopyTextNamesVariations, initialScanStateForCopy);
bool saveOpt = CompilerOptions.AreForCopyParsing;
try
{
CompilerOptions.AreForCopyParsing = this.IsForCopy;
ScannerStep.ScanDocument(TextSourceInfo, compilationDocumentLines, CompilerOptions, CopyTextNamesVariations, InitialScanStateForCopy);
}
finally
{
CompilerOptions.AreForCopyParsing = saveOpt;
}
// Notify all listeners that the whole document has changed.
EventHandler wholeDocumentChanged = WholeDocumentChanged; // avoid race condition
wholeDocumentChanged?.Invoke(this, EventArgs.Empty);
}
else
{
IList<DocumentChange<ITokensLine>> documentChanges = ScannerStep.ScanTextLinesChanges(TextSourceInfo, compilationDocumentLines, textLineChanges, PrepareDocumentLineForUpdate, CompilerOptions, CopyTextNamesVariations, initialScanStateForCopy);
bool saveOpt = CompilerOptions.AreForCopyParsing;
IList<DocumentChange<ITokensLine>> documentChanges = null;
try
{
CompilerOptions.AreForCopyParsing = IsForCopy;
documentChanges = ScannerStep.ScanTextLinesChanges(TextSourceInfo, compilationDocumentLines, textLineChanges, PrepareDocumentLineForUpdate, CompilerOptions, CopyTextNamesVariations, InitialScanStateForCopy);
}
finally
{
CompilerOptions.AreForCopyParsing = saveOpt;
}

// Create a new version of the document to track these changes
currentTokensLinesVersion.changes = documentChanges;
Expand Down
Loading