Skip to content

Commit 041e5c2

Browse files
authored
WI #2037 Avoid creating CE diagnostics after CE build phase (#2043)
* WI #2037 Check CE diag count in DEBUG * WI #2037 Apply end misalignment diagnostic on Node instead of CE * WI #2037 Refactor formalized comments checks * WI #2037 Check no using on TC procedures * WI #2037 Move debugging mode check into CE phase instead of Node phase * WI #2037 Create diagnostic on node instead of CE for duplicate signature check * WI #2037 Fix indent
1 parent e2893cc commit 041e5c2

File tree

11 files changed

+202
-174
lines changed

11 files changed

+202
-174
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
ReturnCode=Warning_
22
6 errors in "input\DocGen.tcbl":
3-
Line 9[13,18] <37, Warning, General> - Warning: Type Definition does not support Parameters field
43
Line 9[13,18] <37, Warning, General> - Warning: Formalized comment field is declared more than once : params
54
Line 13[12,17] <37, Warning, General> - Warning: Formalized comment field is declared more than once : Params
5+
Line 9[13,18] <37, Warning, General> - Warning: Type Definition does not support Parameters field
66
Line 60[12,14] <37, Warning, General> - Warning: Parameter name does not match to any function parameter: blu
77
Line 65[21,26] <37, Warning, General> - Warning: Parameter does not have any description inside the formalized comments: myBool
88
Line 67[21,23] <37, Warning, General> - Warning: Parameter does not have any description inside the formalized comments: bli

CLI/test/ressources/outputSignature_1/output_expected/error.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
ReturnCode=Warning_
2-
4 errors in "input\Callee.rdz.tcbl":
2+
7 errors in "input\Callee.rdz.tcbl":
3+
Line 48[15,21] <37, Warning, General> - Warning: Parameter name does not match to any program parameter: MyType2
4+
Line 49[15,21] <37, Warning, General> - Warning: Parameter name does not match to any program parameter: MyType3
5+
Line 50[15,20] <37, Warning, General> - Warning: Parameter name does not match to any program parameter: Mydate
36
Line 78[17,22] <37, Warning, General> - Warning: Parameter does not have any description inside the formalized comments: mydate
47
Line 79[17,23] <37, Warning, General> - Warning: Parameter does not have any description inside the formalized comments: myDate2
58
Line 90[17,22] <37, Warning, General> - Warning: Parameter does not have any description inside the formalized comments: mydate

TypeCobol.LanguageServer.Test/LSRTests/FirstLineEditCommentBeforeIdentDiv/input/FirstLineEditCommentBeforeIdentDiv.tlsp

Lines changed: 14 additions & 14 deletions
Large diffs are not rendered by default.

TypeCobol.LanguageServer.Test/LSRTests/FormalizedCommentIncScan/input/FormalizedCommentIncScan.tlsp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
{
1717
"category": 1,
18-
"message": "{\"jsonrpc\":\"2.0\",\"method\":\"textDocument/publishDiagnostics\",\"params\":{\"uri\":\"file:///C:/Users/MAYANJE/AppData/Local/Temp/1/tcbl/DVZZJCM54976774298083657321.cee\",\"diagnostics\":[]}}"
18+
"message": "{\"jsonrpc\":\"2.0\",\"method\":\"textDocument/publishDiagnostics\",\"params\":{\"uri\":\"file:///C:/Users/MAYANJE/AppData/Local/Temp/1/tcbl/DVZZJCM54976774298083657321.cee\",\"diagnostics\":[{\"range\":{\"start\":{\"line\":10,\"character\":18},\"end\":{\"line\":10,\"character\":22}},\"severity\":2,\"code\":\"37\",\"source\":\"\",\"message\":\"Warning: Parameter name does not match to any program parameter: bDate\"},{\"range\":{\"start\":{\"line\":11,\"character\":18},\"end\":{\"line\":11,\"character\":22}},\"severity\":2,\"code\":\"37\",\"source\":\"\",\"message\":\"Warning: Parameter name does not match to any program parameter: bTime\"}]}}"
1919
},
2020
{
2121
"category": 0,
@@ -35,7 +35,7 @@
3535
},
3636
{
3737
"category": 1,
38-
"message": "{\"jsonrpc\":\"2.0\",\"method\":\"textDocument/publishDiagnostics\",\"params\":{\"uri\":\"file:///C:/Users/MAYANJE/AppData/Local/Temp/1/tcbl/DVZZJCM54976774298083657321.cee\",\"diagnostics\":[]}}"
38+
"message": "{\"jsonrpc\":\"2.0\",\"method\":\"textDocument/publishDiagnostics\",\"params\":{\"uri\":\"file:///C:/Users/MAYANJE/AppData/Local/Temp/1/tcbl/DVZZJCM54976774298083657321.cee\",\"diagnostics\":[{\"range\":{\"start\":{\"line\":10,\"character\":18},\"end\":{\"line\":10,\"character\":22}},\"severity\":2,\"code\":\"37\",\"source\":\"\",\"message\":\"Warning: Parameter name does not match to any program parameter: bDate\"},{\"range\":{\"start\":{\"line\":11,\"character\":18},\"end\":{\"line\":11,\"character\":22}},\"severity\":2,\"code\":\"37\",\"source\":\"\",\"message\":\"Warning: Parameter name does not match to any program parameter: bTime\"}]}}"
3939
},
4040
{
4141
"category": 0,
@@ -59,7 +59,7 @@
5959
},
6060
{
6161
"category": 1,
62-
"message": "{\"jsonrpc\":\"2.0\",\"method\":\"textDocument/publishDiagnostics\",\"params\":{\"uri\":\"file:///C:/Users/MAYANJE/AppData/Local/Temp/1/tcbl/DVZZJCM54976774298083657321.cee\",\"diagnostics\":[]}}"
62+
"message": "{\"jsonrpc\":\"2.0\",\"method\":\"textDocument/publishDiagnostics\",\"params\":{\"uri\":\"file:///C:/Users/MAYANJE/AppData/Local/Temp/1/tcbl/DVZZJCM54976774298083657321.cee\",\"diagnostics\":[{\"range\":{\"start\":{\"line\":10,\"character\":18},\"end\":{\"line\":10,\"character\":22}},\"severity\":2,\"code\":\"37\",\"source\":\"\",\"message\":\"Warning: Parameter name does not match to any program parameter: bDate\"},{\"range\":{\"start\":{\"line\":11,\"character\":18},\"end\":{\"line\":11,\"character\":22}},\"severity\":2,\"code\":\"37\",\"source\":\"\",\"message\":\"Warning: Parameter name does not match to any program parameter: bTime\"}]}}"
6363
}
6464
],
6565
"didClose": "{\"jsonrpc\":\"2.0\",\"method\":\"textDocument/didClose\",\"params\":{\"textDocument\":{\"uri\":\"file:/C:/Users/MAYANJE/AppData/Local/Temp/1/tcbl/DVZZJCM54976774298083657321.cee\"}}}",

TypeCobol.Test/Parser/CodeElements/ParagraphCodeElements.rdz.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
--- Diagnostics ---
2+
Line 22[33,41] <37, Warning, General> - Warning: Debugging mode is active OffendingSymbol=[33,41:DEBUGGING]<DEBUGGING>
3+
Line 23[38,46] <37, Warning, General> - Warning: Debugging mode is active OffendingSymbol=[38,46:DEBUGGING]<DEBUGGING>
24
Line 55[22,23] <27, Error, Syntax> - Syntax error : Empty string cannot be used as currency symbol.
35
Line 56[43,44] <27, Error, Syntax> - Syntax error : Empty string cannot be used as currency symbol.
46
Line 57[17,27] <27, Error, Syntax> - Syntax error : Currency symbol must be one single character.

TypeCobol/Compiler/CompilationUnit.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ public void RefreshCodeElementsDocumentSnapshot()
129129
codeElementsLinesChanged(this, documentChangedEvent);
130130
}
131131
}
132+
133+
#if DEBUG
134+
//Update CE diag count for future checks
135+
_codeElementDiagnosticCount = OnlyCodeElementDiagnostics().Count;
136+
#endif
132137
}
133138

134139
/// <summary>
@@ -147,6 +152,23 @@ public void RefreshCodeElementsDocumentSnapshot()
147152
/// </summary>
148153
public PerfStatsForParsingStep PerfStatsForCodeElementsParser { get; private set; }
149154

155+
#if DEBUG
156+
private int _codeElementDiagnosticCount;
157+
158+
/// <summary>
159+
/// Debug-only check to avoid creation of diagnostics on CodeElements after they have been created/refreshed.
160+
/// Must be called at the end of each compilation step defined after <see cref="RefreshCodeElementsDocumentSnapshot"/>.
161+
/// </summary>
162+
private void CheckCodeElementDiagnostics()
163+
{
164+
var actualCodeElementDiagnosticCount = OnlyCodeElementDiagnostics().Count;
165+
if (actualCodeElementDiagnosticCount != _codeElementDiagnosticCount)
166+
{
167+
System.Diagnostics.Debug.Fail("CodeElement diagnostics should not be created after CE phase !");
168+
}
169+
}
170+
#endif
171+
150172
public string AntlrResult {
151173
get
152174
{
@@ -213,6 +235,10 @@ public void RefreshProgramClassDocumentSnapshot()
213235
{
214236
programClassNotChanged(this, new ProgramClassEvent() { Version = ProgramClassDocumentSnapshot.CurrentVersion });
215237
}
238+
239+
#if DEBUG
240+
CheckCodeElementDiagnostics();
241+
#endif
216242
}
217243

218244
/// <summary>
@@ -287,6 +313,10 @@ public void ProduceTemporarySemanticDocument()
287313
PerfStatsForTemporarySemantic.OnStopRefreshParsingStep();
288314
}
289315
}
316+
317+
#if DEBUG
318+
CheckCodeElementDiagnostics();
319+
#endif
290320
}
291321

292322
/// <summary>
@@ -369,6 +399,10 @@ bool CodeAnalysisDocumentNeedsUpdate(out int newVersion)
369399
{
370400
codeAnalysisCompleted(this, new ProgramClassEvent() { Version = CodeAnalysisDocumentSnapshot.CurrentVersion });
371401
}
402+
403+
#if DEBUG
404+
CheckCodeElementDiagnostics();
405+
#endif
372406
}
373407

374408
/// <summary>

TypeCobol/Compiler/CupParser/NodeBuilder/ProgramClassBuilder.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -809,9 +809,6 @@ public virtual void EndFunctionDeclaration(FunctionDeclarationEnd end)
809809

810810
public virtual void StartFunctionProcedureDivision(ProcedureDivisionHeader header)
811811
{
812-
if (header.UsingParameters != null && header.UsingParameters.Count > 0)
813-
DiagnosticUtils.AddError(header, "TCRFUN_DECLARATION_NO_USING");//TODO#249
814-
815812
Enter(new ProcedureDivision(header), header);
816813
Dispatcher.StartFunctionProcedureDivision(header);
817814
}

TypeCobol/Compiler/Diagnostics/Cobol2002Checker.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,6 @@ public static void CheckTypeDefinition(TypeDefinition typeDefinition)
119119
}
120120
}
121121

122-
// Add a warning if a parameters field is set inside the formalized comment
123-
if (typeDefinition.CodeElement.FormalizedCommentDocumentation != null && typeDefinition.CodeElement.FormalizedCommentDocumentation.Parameters.Any())
124-
{
125-
var token = typeDefinition.CodeElement.ConsumedTokens
126-
.FirstOrDefault(t => t.TokenType == TokenType.FORMALIZED_COMMENTS_PARAMETERS);
127-
if (token != null)
128-
{
129-
DiagnosticUtils.AddError(typeDefinition.CodeElement,
130-
"Type Definition does not support Parameters field",
131-
token, code: MessageCode.Warning);
132-
}
133-
}
134-
135122
//Check circular reference if not already done by TypeCobolLinker
136123
TypeCobolLinker.CheckCircularReferences(typeDefinition);
137124
}

TypeCobol/Compiler/Diagnostics/CrossChecker.cs

Lines changed: 12 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public override bool BeginCodeElement(CodeElement codeElement)
8383
public override bool Visit(FunctionDeclaration functionDeclaration)
8484
{
8585
FunctionDeclarationChecker.OnNode(functionDeclaration);
86-
CheckMultipleFormComParam(functionDeclaration.CodeElement);
86+
FormalizedCommentsChecker.CheckFunctionComments(functionDeclaration);
8787
return true;
8888
}
8989

@@ -138,13 +138,6 @@ public override bool Visit(ProcedureDivision procedureDivision)
138138
LibraryChecker.CheckLibrary(procedureDivision);
139139
//initializing the current section to null
140140
_currentSection = null;
141-
ProcedureDivisionHeader ce = procedureDivision.CodeElement as ProcedureDivisionHeader;
142-
if (ce?.FormalizedCommentDocumentation != null && procedureDivision.Parent is FunctionDeclaration)
143-
{
144-
DiagnosticUtils.AddError(ce,
145-
"Formalized Comments can be placed above Procedure Division only for Programs",
146-
MessageCode.ErrorFormalizedCommentMissplaced);
147-
}
148141
return true;
149142
}
150143

@@ -501,66 +494,16 @@ public override bool Visit(TypeDefinition typeDefinition)
501494
//TODO need to clarify if we have 1 visitor per LanguageLevel
502495
//For performance reason it seems better to have only one here
503496
TypeDefinitionChecker.CheckTypeDefinition(typeDefinition);
504-
CheckMultipleFormComParam(typeDefinition.CodeElement);
497+
FormalizedCommentsChecker.CheckTypeComments(typeDefinition);
505498
return true;
506499
}
507500

508501
public override bool Visit(Program program)
509502
{
510503
// Check that program has a closing end
511504
CheckEndProgram(program);
512-
513-
//// Set a Warning if the FormCom parameter in unknown or if the program parameter have no description
514-
515-
ProcedureDivisionHeader procedureDivision =
516-
program.Children.FirstOrDefault(c => c is ProcedureDivision)?.CodeElement as ProcedureDivisionHeader;
517-
var formCom = procedureDivision?.FormalizedCommentDocumentation;
518-
519-
if (formCom != null && procedureDivision.UsingParameters != null)
520-
{
521-
CheckMultipleFormComParam(procedureDivision);
522-
// Get the parameters inside the Formalized Comment that are not inside the program parameters
523-
var formComParamOrphan = formCom.Parameters.Keys.Except(
524-
procedureDivision.UsingParameters.Select(p =>
525-
p.StorageArea.SymbolReference?.Name)) ?? Enumerable.Empty<string>();
526-
527-
// For each of them, place a warning on the orphan parameter definition (UserDefinedWord Token inside the FormCom)
528-
foreach (var orphan in formComParamOrphan)
529-
{
530-
var tokens =
531-
procedureDivision.ConsumedTokens.Where(t =>
532-
t.TokenType == TokenType.UserDefinedWord && t.Text == orphan);
533-
foreach (var token in tokens)
534-
{
535-
DiagnosticUtils.AddError(procedureDivision,
536-
"Parameter name does not match to any program parameter: " + orphan,
537-
token, code: MessageCode.Warning);
538-
}
539-
}
540-
541-
542-
// Get the parameters inside the program parameters that are not inside the Formalized Comment
543-
var sameParameters = procedureDivision.UsingParameters.Where(p =>
544-
formCom.Parameters.Keys.Contains(p.StorageArea.SymbolReference?.Name));
545-
546-
var programParamWithoutDesc = procedureDivision.UsingParameters.Except(sameParameters);
547-
548-
// For each of them, place a warning on the parameter definition
549-
foreach (var param in programParamWithoutDesc)
550-
{
551-
var tokens = procedureDivision.ConsumedTokens.Where(t =>
552-
t.TokenType == TokenType.UserDefinedWord &&
553-
t.Text == param.StorageArea.SymbolReference?.Name);
554-
foreach (var token in tokens)
555-
{
556-
DiagnosticUtils.AddError(procedureDivision,
557-
"Parameter does not have any description inside the formalized comments: " +
558-
param.StorageArea.SymbolReference?.Name,
559-
token, code: MessageCode.Warning);
560-
}
561-
}
562-
}
563-
505+
506+
FormalizedCommentsChecker.CheckProgramComments(program);
564507
return true;
565508
}
566509

@@ -702,7 +645,7 @@ public override bool Visit(End end)
702645
CodeElement parentCodeElement = end.Parent.CodeElement; ;
703646
if (parentCodeElement?.IsInsideCopy() == false && end.IsInsideCopy() == false)
704647
{
705-
CheckEndNode(parentCodeElement, end.CodeElement);
648+
CheckEndNode(parentCodeElement, end);
706649
}
707650
}
708651
return true;
@@ -717,7 +660,7 @@ public override bool Visit(FunctionEnd functionEnd)
717660
if (parentCodeElement?.IsInsideCopy() == false && functionEnd.IsInsideCopy() == false)
718661
{
719662
Token openingDeclareToken = parentCodeElement.ConsumedTokens.FirstOrDefault(t => t.TokenType == TokenType.DECLARE);
720-
CheckEndNode(openingDeclareToken, functionEnd.CodeElement);
663+
CheckEndNode(openingDeclareToken, functionEnd);
721664
}
722665
}
723666
return true;
@@ -752,16 +695,6 @@ public override bool Visit(DataDescription dataDescription)
752695
return true;
753696
}
754697

755-
public override bool Visit(SourceComputer sourceComputer)
756-
{
757-
if (sourceComputer.CodeElement.DebuggingMode?.Value == true)
758-
{
759-
Token token = sourceComputer.CodeElement.DebuggingMode.Token;
760-
DiagnosticUtils.AddError(sourceComputer.CodeElement, "Debugging mode is active", token, null, MessageCode.Warning);
761-
}
762-
return true;
763-
}
764-
765698
/// <summary>
766699
/// Test if the received DataDefinition has other children than DataConditionEntry or DataRenamesEntry
767700
/// </summary>
@@ -1101,26 +1034,6 @@ private static void IndexAndFlagDataDefiniton(DataDefinitionPath dataDefinitionP
11011034
}
11021035
}
11031036

1104-
/// <summary>
1105-
/// Add a warning if a Field is set more than one time
1106-
/// </summary>
1107-
private static void CheckMultipleFormComParam(CodeElement codeElement)
1108-
{
1109-
var tokenGroups = codeElement.ConsumedTokens.GroupBy(t => t.TokenType);
1110-
foreach (var tokenGroup in tokenGroups)
1111-
{
1112-
if ((int) tokenGroup.Key >= 513 && (int) tokenGroup.Key <= 520 && tokenGroup.Count() > 1)
1113-
{
1114-
foreach (var token in tokenGroup)
1115-
{
1116-
DiagnosticUtils.AddError(codeElement,
1117-
"Formalized comment field is declared more than once : " + token.Text,
1118-
token, code: MessageCode.Warning);
1119-
}
1120-
}
1121-
}
1122-
}
1123-
11241037
private static void FlagNodeAndCreateQualifiedStorageAreas(Node.Flag flag, Node node, StorageArea storageArea,
11251038
DataDefinitionPath dataDefinitionPath)
11261039
{
@@ -1132,13 +1045,17 @@ private static void FlagNodeAndCreateQualifiedStorageAreas(Node.Flag flag, Node
11321045
node.QualifiedStorageAreas.Add(storageArea, dataDefinitionPath);
11331046
}
11341047

1135-
private void CheckEndNode([CanBeNull]IToken openingToken, CodeElement endCodeElement)
1048+
private void CheckEndNode([CanBeNull]IToken openingToken, Node endNode)
11361049
{
1050+
System.Diagnostics.Debug.Assert(endNode is End || endNode is FunctionEnd);
1051+
System.Diagnostics.Debug.Assert(endNode.CodeElement != null);
1052+
11371053
// Check end statement is aligned with the matching opening statement
1054+
var endCodeElement = endNode.CodeElement;
11381055
if (openingToken != null && openingToken.Line != endCodeElement.Line &&
11391056
openingToken.StartIndex != endCodeElement.StartIndex)
11401057
{
1141-
DiagnosticUtils.AddError(endCodeElement,
1058+
DiagnosticUtils.AddError(endNode,
11421059
"a End statement is not aligned with the matching opening statement",
11431060
_compilerOptions.CheckEndAlignment.GetMessageCode());
11441061
}

0 commit comments

Comments
 (0)