Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.2.1 #2604

Merged
merged 5 commits into from
Jan 2, 2024
Merged

v2.2.1 #2604

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 TypeCobol.LanguageServer/Workspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ static object GetEnd(long start, long length)
private List<Tuple<int, DataDefinition, int>> CollectDataLayoutNodes(CompilationUnit compilationUnit)
{
var dataLayoutNodes = new List<Tuple<int, DataDefinition, int>>();
Node dataDivision = compilationUnit.TemporaryProgramClassDocumentSnapshot.Root.MainProgram.GetChildren<DataDivision>().FirstOrDefault();
Node dataDivision = compilationUnit?.TemporaryProgramClassDocumentSnapshot?.Root?.MainProgram?.GetChildren<DataDivision>()?.FirstOrDefault();
if (dataDivision != null)
{
// Consider data declared in the Working storage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,33 +115,36 @@
*** DIRECTIVE CBL|NOSUPPRESS|NOZC|TEST ([8,31:CBL NOSUPPRESS NOZC TEST]<COMPILER_DIRECTIVE>) ***

-- Line 39 --
[8,33:Invalid/not allowed syntax]<CommentLine>
*** DIRECTIVE CBL|VSAMOPENFS=SUCC|VS=C ([8,33:CBL VSAMOPENFS(SUCC) VS(C)]<COMPILER_DIRECTIVE>) ***

-- Line 40 --
*** DIRECTIVE INVALID SYNTAX -> CBL|AMODE=64 ([8,20:CBL AMODE(64)]<COMPILER_DIRECTIVE>) ***
[8,33:Invalid/not allowed syntax]<CommentLine>

-- Line 41 --
*** DIRECTIVE INVALID SYNTAX -> CBL|ALOWCOPYLOC ([8,22:CBL ALOWCOPYLOC]<COMPILER_DIRECTIVE>) ***
*** DIRECTIVE INVALID SYNTAX -> CBL|AMODE=64 ([8,20:CBL AMODE(64)]<COMPILER_DIRECTIVE>) ***

-- Line 42 --
*** DIRECTIVE INVALID SYNTAX -> CBL|ALOWDEFINE ([8,21:CBL ALOWDEFINE]<COMPILER_DIRECTIVE>) ***
*** DIRECTIVE INVALID SYNTAX -> CBL|ALOWCOPYLOC ([8,22:CBL ALOWCOPYLOC]<COMPILER_DIRECTIVE>) ***

-- Line 43 --
*** DIRECTIVE INVALID SYNTAX -> CBL|LP=64 ([8,17:CBL LP(64)]<COMPILER_DIRECTIVE>) ***
*** DIRECTIVE INVALID SYNTAX -> CBL|ALOWDEFINE ([8,21:CBL ALOWDEFINE]<COMPILER_DIRECTIVE>) ***

-- Line 44 --
*** DIRECTIVE INVALID SYNTAX -> CBL|LP=64 ([8,17:CBL LP(64)]<COMPILER_DIRECTIVE>) ***

-- Line 45 --
[8,21:IDENTIFICATION]<IDENTIFICATION>
[23,30:DIVISION]<DIVISION>
[31,32:. ]<PeriodSeparator>

-- Line 45 --
-- Line 46 --
[8,72:-Reason : AMEELIORATION PROCESS ACTIMAT ]<CommentLine>

-- Line 46 --
-- Line 47 --
[17,23:PERFORM]<PERFORM>
[25,49:PROCESSUS-INDEXATION-IMMO]<UserDefinedWord>
[50,51:. ]<PeriodSeparator>

-- Line 47 --
-- Line 48 --
[8,72:*** PROCESSUS DE MENAGE ]<CommentLine>

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ CBL COPYLOC, DEFINE(compilation-variable = 1), INITCHECK(LAX), INITIAL
PROCESS SSRANGE,OFFSET
000100 CBL NOCPLC, NODEF, NOIC, INVD(FNC,NOCS), NONUMCHECK, NONC
000110 CBL NOSUPPRESS NOZC TEST
000111 CBL VSAMOPENFS(SUCC) VS(C)
000120*Invalid/not allowed syntax
000130 CBL AMODE(64)
000140 CBL ALOWCOPYLOC
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Diagnostics
------------
None

--------- FIELD LEVEL|NAME ---------- START END LENGTH
1 group0 1 21 21
5 group1 1 10 10
10 var1 1 10 10
5 group2 1 20 20
10 var2 1 20 20
5 group3 1 3 3
10 var3 1 3 3
5 next-group 21 21 1
10 next-var 21 21 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
 IDENTIFICATION DIVISION.
PROGRAM-ID. PGMREDFT.
DATA DIVISION.
WORKING-STORAGE SECTION.

01 group0.
05 group1.
10 var1 PIC X(10).
05 group2 REDEFINES group1.
10 var2 PIC X(20).
05 group3 REDEFINES group2.
10 var3 PIC X(3).
05 next-group.
10 next-var PIC X.

PROCEDURE DIVISION.
GOBACK
.
END PROGRAM PGMREDFT.
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,9 @@ Line 0[1,15] <25, Error, Directives> - Invalid syntax for a CBL or PROCESS compi
*** DIRECTIVE INVALID SYNTAX -> CBL|ALOWDEFINE ([1,14:CBL ALOWDEFINE]<COMPILER_DIRECTIVE>) ***
Line 0[1,14] <25, Error, Directives> - Invalid syntax for a CBL or PROCESS compiler directive : each option should be separated by space or comma, and option parameters should be enclosed in parentheses

-- Line 61 --
*** DIRECTIVE CBL|VSAMOPENFS=S ([1,17:CBL VSAMOPENFS(S)]<COMPILER_DIRECTIVE>) ***

-- Line 62 --
*** DIRECTIVE CBL|VS=COMPAT ([1,14:CBL VS(COMPAT)]<COMPILER_DIRECTIVE>) ***

4 changes: 3 additions & 1 deletion TypeCobol.Test/Parser/Scanner/TestTokenTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,9 @@ public static void CheckCblProcessCompilerDirective()
"CBL OFFSET",
"CBL AMODE(64)",
"CBL ALOWCOPYLOC",
"CBL ALOWDEFINE"
"CBL ALOWDEFINE",
"CBL VSAMOPENFS(S)",
"CBL VS(COMPAT)"
};
string result = ScannerUtils.ScanLines(testLines);
ScannerUtils.CheckWithResultFile(result, testName);
Expand Down
39 changes: 25 additions & 14 deletions TypeCobol/Compiler/CodeModel/SymbolTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,28 +344,39 @@ void SearchChildren(IReadOnlyList<Node> children)
}
}

public DataDefinition GetRedefinedVariable(DataRedefines redefinesNode, SymbolReference symbolReference)
public DataDefinition GetRedefinedVariable(DataRedefines redefinesNode)
{
var redefinesDataName = redefinesNode.CodeElement.RedefinesDataName.Name;
var childrens = redefinesNode.Parent.Children;
int index = redefinesNode.Parent.IndexOf(redefinesNode);

while (index >= 0)
{
CommonDataDescriptionAndDataRedefines child = childrens[index].CodeElement as CommonDataDescriptionAndDataRedefines;

if (child != null && (child is DataDescriptionEntry || child is DataRedefinesEntry))
var child = childrens[index];
if (child.Name != null)
{
if (child.DataName != null &&
string.Equals(child.DataName.Name, symbolReference.Name,
StringComparison.OrdinalIgnoreCase))
return childrens[index] as DataDefinition;
else if (child.DataName != null && child is DataDescriptionEntry &&
!string.Equals(child.DataName.Name, symbolReference.Name,
StringComparison.OrdinalIgnoreCase))
return null;
var type = child.CodeElement?.Type;
if (type == CodeElementType.DataDescriptionEntry || type == CodeElementType.DataRedefinesEntry)
{
if (string.Equals(child.Name, redefinesDataName, StringComparison.OrdinalIgnoreCase))
{
if (type == CodeElementType.DataRedefinesEntry)
{
// Transitive REDEFINES => continue until root one is reached
return ((DataRedefines)child).RedefinedVariable;
}

return (DataDefinition)child;
}

// Name differs
if (type == CodeElementType.DataDescriptionEntry)
{
// No more REDEFINES => not found
return null;
}
}
}
else
return null;

index--;
}
Expand Down
2 changes: 1 addition & 1 deletion TypeCobol/Compiler/Diagnostics/Cobol2002Checker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static void OnNode(DataRedefines redefinesNode)
}

var redefinesSymbolReference = redefinesNode.CodeElement.RedefinesDataName;
var redefinedVariable = redefinesNode.SymbolTable.GetRedefinedVariable(redefinesNode, redefinesSymbolReference);
var redefinedVariable = redefinesNode.RedefinedVariable;

if (redefinedVariable == null)
{
Expand Down
14 changes: 13 additions & 1 deletion TypeCobol/Compiler/Directives/IBMCompilerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ namespace TypeCobol.Compiler.Directives
// “MDECK” on page 332 NOMDECK NOMD|MD|MD(C|NOC)
// “OPTFILE” on page 338 None None
// “THREAD” on page 356 NOTHREAD None
// “VSAMOPENFS” on page 389 VSAMOPENFS(COMPAT) VS(C | S)
// --- Deprecated ---
// “LIB”

Expand Down Expand Up @@ -197,6 +198,7 @@ internal IBMCompilerOptionStatus(IBMCompilerOptionName name)
case IBMCompilerOptionName.THREAD: IsActivated = false; Value = null; break;
case IBMCompilerOptionName.TRUNC: IsActivated = true; Value = "STD"; break;
case IBMCompilerOptionName.VBREF: IsActivated = false; Value = null; break;
case IBMCompilerOptionName.VSAMOPENFS: IsActivated = true; Value = "COMPAT"; break;
case IBMCompilerOptionName.WORD: IsActivated = false; Value = null; break;
case IBMCompilerOptionName.XREF: IsActivated = true; Value = "FULL"; break;
case IBMCompilerOptionName.ZONECHECK: IsActivated = false; Value = null; break;
Expand Down Expand Up @@ -597,6 +599,12 @@ public class IBMCompilerOptions
/// </summary>
public IBMCompilerOptionStatus VBREF { get; private set; }

/// <summary>
/// The VSAMOPENFS option affects the user file status reported from successful VSAM OPEN statements that
/// require verified file integrity check.
/// </summary>
public IBMCompilerOptionStatus VSAMOPENFS { get; private set; }

/// <summary>
/// Use WORD(xxxx) to specify that an alternate reserved-word table is to be used during compilation.
/// </summary>
Expand All @@ -623,7 +631,7 @@ public class IBMCompilerOptions
public IBMCompilerOptionStatus ZWB { get; private set; }

// Conversion of option words in source text to option name enumeration
private readonly IDictionary<string, IBMCompilerOptionStatus> optionWordToOptionName = new Dictionary<string, IBMCompilerOptionStatus>(194, StringComparer.OrdinalIgnoreCase);
private readonly IDictionary<string, IBMCompilerOptionStatus> optionWordToOptionName = new Dictionary<string, IBMCompilerOptionStatus>(196, StringComparer.OrdinalIgnoreCase);

// Deprecated options which are not supported anymore with the corresponding warning message to be displayed
private static readonly IDictionary<string, string> deprecatedOptions = new Dictionary<string, string>(1, StringComparer.OrdinalIgnoreCase);
Expand Down Expand Up @@ -705,6 +713,7 @@ public IBMCompilerOptions()
THREAD = new IBMCompilerOptionStatus(IBMCompilerOptionName.THREAD);
TRUNC = new IBMCompilerOptionStatus(IBMCompilerOptionName.TRUNC);
VBREF = new IBMCompilerOptionStatus(IBMCompilerOptionName.VBREF);
VSAMOPENFS = new IBMCompilerOptionStatus(IBMCompilerOptionName.VSAMOPENFS);
WORD = new IBMCompilerOptionStatus(IBMCompilerOptionName.WORD);
XREF = new IBMCompilerOptionStatus(IBMCompilerOptionName.XREF);
ZONECHECK = new IBMCompilerOptionStatus(IBMCompilerOptionName.ZONECHECK);
Expand Down Expand Up @@ -779,6 +788,7 @@ public IBMCompilerOptions()
optionWordToOptionName["THREAD"] = THREAD; optionWordToOptionName["NOTHREAD"] = THREAD;
optionWordToOptionName["TRUNC"] = TRUNC;
optionWordToOptionName["VBREF"] = VBREF; optionWordToOptionName["NOVBREF"] = VBREF;
optionWordToOptionName["VSAMOPENFS"] = VSAMOPENFS; optionWordToOptionName["VS"] = VSAMOPENFS;
optionWordToOptionName["WORD"] = WORD; optionWordToOptionName["WD"] = WORD; optionWordToOptionName["NOWORD"] = WORD; optionWordToOptionName["NOWD"] = WORD;
optionWordToOptionName["XREF"] = XREF; optionWordToOptionName["X"] = XREF; optionWordToOptionName["NOXREF"] = XREF; optionWordToOptionName["NOX"] = XREF;
optionWordToOptionName["ZONECHECK"] = ZONECHECK; optionWordToOptionName["ZC"] = ZONECHECK; optionWordToOptionName["NOZONECHECK"] = ZONECHECK; optionWordToOptionName["NOZC"] = ZONECHECK;
Expand Down Expand Up @@ -992,6 +1002,8 @@ public enum IBMCompilerOptionName
TRUNC,
/* Use VBREF to get a cross-reference between all verbs used in the source program and the line numbers in which they are used. VBREF also produces a summary of the number of times each verb was used in the program. */
VBREF,
/* The VSAMOPENFS option affects the user file status reported from successful VSAM OPEN statements that require verified file integrity check. */
VSAMOPENFS,
/* Use WORD(xxxx) to specify that an alternate reserved-word table is to be used during compilation. */
WORD,
/* Use XREF to produce a sorted cross-reference listing. */
Expand Down
35 changes: 22 additions & 13 deletions TypeCobol/Compiler/Nodes/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ public TypeDefinition TypeDefinition

private IList<DataRedefines> _dataRedefines;

public IEnumerable<DataRedefines> DataRedefinitions => _dataRedefines;

public void AddDataRedefinition(DataRedefines dataRedefines)
{
if (_dataRedefines == null)
Expand Down Expand Up @@ -459,12 +461,9 @@ public long SlackBytes
{
DataRedefines redefines = parent.Children[index] as DataRedefines;
//Get the original redefined node
while (redefines != null)
if (redefines != null)
{
SymbolReference redefined = redefines.CodeElement.RedefinesDataName;
redefinedDataDefinition = redefines.SymbolTable.GetRedefinedVariable(redefines, redefined);

redefines = redefinedDataDefinition as DataRedefines;
redefinedDataDefinition = redefines.RedefinedVariable;
}

//Sum up all physical lengths except these from DataRedefines and the node that is redefined by the current node (if he is a DataRedefines)
Expand Down Expand Up @@ -537,12 +536,14 @@ public virtual long StartPosition
if (this is DataRedefines node)
{
//Get the start position from the node it redefines.
SymbolReference redefined = node.CodeElement.RedefinesDataName;
var result = SymbolTable.GetRedefinedVariable(node, redefined);
var result = node.RedefinedVariable;
if (result != null)
{
_startPosition = result.StartPosition + SlackBytes;
return _startPosition.Value;
}

_startPosition = result.StartPosition + SlackBytes;
return _startPosition.Value;

// Redefined variable does not exist -> handle node as a DataDescription
}

if (Parent is DataSection)
Expand All @@ -559,8 +560,8 @@ public virtual long StartPosition
if (i == Parent.ChildIndex(this) - 1)
{
int siblingIndex = i;
//Looks further up if the first position encountered is from a DataRedefines node.
while (sibling is DataRedefines)
//Looks further up if the first position encountered is from a DataRedefines node with an existing redefined variable.
while (sibling is DataRedefines dataRedefines && dataRedefines.RedefinedVariable != null)
{
sibling = Parent.Children[siblingIndex - 1];

Expand Down Expand Up @@ -764,11 +765,19 @@ public override bool VisitNode(IASTVisitor astVisitor)
}
}
public class DataRedefines: DataDefinition {
public DataRedefines([NotNull] DataRedefinesEntry entry) : base(entry) { }
public DataRedefines([NotNull] DataRedefinesEntry entry)
: base(entry)
{
_redefinedVariable = new Lazy<DataDefinition>(() => SymbolTable.GetRedefinedVariable(this));
}

[NotNull]
public new DataRedefinesEntry CodeElement => (DataRedefinesEntry) base.CodeElement;

private readonly Lazy<DataDefinition> _redefinedVariable;

public DataDefinition RedefinedVariable => _redefinedVariable.Value;

public override bool VisitNode(IASTVisitor astVisitor)
{
return base.VisitNode(astVisitor) && astVisitor.Visit(this);
Expand Down
Loading