Skip to content

Commit

Permalink
Issue #1143: fix Signature Generator to work with FormCom & MultCom
Browse files Browse the repository at this point in the history
  • Loading branch information
Brochato committed Dec 18, 2018
1 parent 4049570 commit e2ed22e
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CLI/test/CLITest.cs
Expand Up @@ -131,7 +131,7 @@ public void TestReplacingSyntaxOption()
[TestMethod]
public void TestOutputFormat()
{
CLITestHelper.Test("outputSignature_1", ReturnCode.Success);
CLITestHelper.Test("outputSignature_1", ReturnCode.Warning);
}

/// <summary>
Expand Down
54 changes: 53 additions & 1 deletion CLI/test/ressources/outputSignature_1/input/Callee.rdz.tcbl
@@ -1,4 +1,8 @@
 IDENTIFICATION DIVISION.
*<<
Multiline comment
should be commented
*>>
PROGRAM-ID. Callee.

DATA DIVISION.
Expand All @@ -8,10 +12,16 @@
05 Var1 pic X.

01 TOto pic X.


*<<<
My public Type 2
*>>>
01 MyType2 TYPEDEF STRICT PUBLIC.
05 Var2 pic X.

*<<<
My private Type 3
*>>>
01 MyType3 TYPEDEF STRICT.
05 Var3 pic X.

Expand All @@ -26,6 +36,19 @@
01 MyType3 type MyType3.
01 Mydate type Date.

*<<< My program
@ Description description
@deprecated
@ replacedBy MyFonction2
@ need some needs
@ todo
- make my second type my first type
- get another type
@Params:
- MyType2: my second type
- MyType3: my third type
- Mydate: today date
*>>>
PROCEDURE DIVISION.

declare procedure check public
Expand All @@ -35,12 +58,22 @@
CONTINUE.
END-DECLARE.

*<<<
check if the given date is before today
@params:
- mydate: tyhe date to test
*>>>
declare procedure check2 public
input mydate TYPE Date
.
PROCEDURE DIVISION.
CONTINUE.
END-DECLARE.

*<<<
Same as check2 but with two dates
@see: check2
*>>>
declare procedure check2 public
input mydate TYPE Date
myDate2 type date
Expand All @@ -49,8 +82,27 @@
CONTINUE.
END-DECLARE.

*<<<
Private procedure should not have
its signature generated
*>>>
declare procedure check3 private
input mydate TYPE Date
myDate2 type date
.
PROCEDURE DIVISION.
CONTINUE.
END-DECLARE.

*<<
Multiline Comment here should be ignored
*>>
DECLARE PROCEDURE MyPublicProcedure PUBLIC
INPUT mydate TYPE Date
*<<
Multiline comment
should be commented
*>>
format PIC X(08)
OUTPUT okay TYPE Bool
actual-format PIC X(08).
Expand Down
@@ -1,30 +1,63 @@
 *TypeCobol_Version:0.1(alpha)
IDENTIFICATION DIVISION.
*<<
* Multiline comment
* should be commented
*>>
PROGRAM-ID. Callee.
DATA DIVISION.
working-storage section.
01 MyType1 TYPEDEF STRICT PUBLIC.
05 Var1 pic X.
*<<<
* My public Type 2
*>>>
01 MyType2 TYPEDEF STRICT PUBLIC.
05 Var2 pic X.
01 MyType5 TYPEDEF STRICT PUBLIC.
05 Var5 pic X.
*<<< My program
* @ Description description
* @deprecated
* @ replacedBy MyFonction2
* @ need some needs
* @ todo
* - make my second type my first type
* - get another type
* @Params:
* - MyType2: my second type
* - MyType3: my third type
* - Mydate: today date
*>>>
PROCEDURE DIVISION.
declare procedure check public
input mydate TYPE Date
.
END-DECLARE.
*<<<
* check if the given date is before today
* @params:
* - mydate: tyhe date to test
*>>>
declare procedure check2 public
input mydate TYPE Date
.
END-DECLARE.
*<<<
* Same as check2 but with two dates
* @see: check2
*>>>
declare procedure check2 public
input mydate TYPE Date
myDate2 type date
.
END-DECLARE.
DECLARE PROCEDURE MyPublicProcedure PUBLIC
INPUT mydate TYPE Date
*<<
* Multiline comment
* should be commented
*>>
format PIC X(08)
OUTPUT okay TYPE Bool
actual-format PIC X(08).
Expand Down
@@ -1,2 +1,6 @@
ReturnCode=Success_
No error in "input\Callee.rdz.tcbl".
ReturnCode=Warning_
4 errors in "input\Callee.rdz.tcbl":
Line 78[17,22] <37, Warning, General> - Warning: Parameter does not have any description inside the formalized comments: mydate
Line 79[17,23] <37, Warning, General> - Warning: Parameter does not have any description inside the formalized comments: myDate2
Line 90[17,22] <37, Warning, General> - Warning: Parameter does not have any description inside the formalized comments: mydate
Line 91[17,23] <37, Warning, General> - Warning: Parameter does not have any description inside the formalized comments: myDate2
24 changes: 24 additions & 0 deletions Codegen/src/Generators/SignaturesGenerator.cs
Expand Up @@ -12,6 +12,7 @@
using ProcedureDivision = TypeCobol.Compiler.Nodes.ProcedureDivision;
using WorkingStorageSection = TypeCobol.Compiler.Nodes.WorkingStorageSection;
using System.Text;
using TypeCobol.Compiler.Scanner;

namespace TypeCobol.Codegen.Generators
{
Expand Down Expand Up @@ -45,8 +46,31 @@ public class SignaturesGenerator : IGenerator
var sourceFile = compilationUnit.ProgramClassDocumentSnapshot.Root;
sourceFile.AcceptASTVisitor(new ExportToDependency());
var lines = sourceFile.SelfAndChildrenLines;
bool insideFormalizedComment = false;
bool insideMultilineComment = false;
foreach (var textLine in lines)
{
string text = textLine is TextLineSnapshot ?
CobolTextLine.Create(textLine.Text, ColumnsLayout.CobolReferenceFormat).First().Text :
textLine.Text;

ITokensLine tokensLine = textLine as ITokensLine;
if (tokensLine != null)
{
if (tokensLine.SourceTokens.Any(t => t.TokenType == TokenType.FORMALIZED_COMMENTS_START))
insideFormalizedComment = true;
if (tokensLine.SourceTokens.Any(t => t.TokenType == TokenType.MULTILINES_COMMENTS_START))
insideMultilineComment = true;

if (insideFormalizedComment || insideMultilineComment)
text = text.Substring(0, 6) + '*' + text.Substring(7, text.Length - 7);

if (tokensLine.SourceTokens.Any(t => t.TokenType == TokenType.FORMALIZED_COMMENTS_STOP))
insideFormalizedComment = false;
if (tokensLine.SourceTokens.Any(t => t.TokenType == TokenType.MULTILINES_COMMENTS_STOP))
insideMultilineComment = false;
}

if (textLine is TextLineSnapshot)
{
var test = CobolTextLine.Create(textLine.Text, ColumnsLayout.CobolReferenceFormat);
Expand Down

0 comments on commit e2ed22e

Please sign in to comment.