-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
535 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Xml.Serialization; | ||
using TypeCobol.Compiler; | ||
using TypeCobol.Compiler.CodeElements; | ||
using TypeCobol.Compiler.CodeModel; | ||
using TypeCobol.Compiler.Diagnostics; | ||
using TypeCobol.Compiler.Nodes; | ||
using TypeCobol.Compiler.Text; | ||
|
||
namespace TypeCobol.Codegen.Generators | ||
{ | ||
/// <summary> | ||
/// Generator than create the documentation of all applicable Nodes | ||
/// </summary> | ||
class DocumentationGenerator : IGenerator | ||
{ | ||
private StringBuilder Destination { get; set; } | ||
public DocumentationGenerator(StringBuilder destination, string typeCobolVersion) | ||
{ | ||
this.Destination = destination; | ||
TypeCobolVersion = typeCobolVersion; | ||
} | ||
public void Generate(CompilationUnit compilationUnit, ColumnsLayout columns = ColumnsLayout.FreeTextFormat) | ||
{ | ||
Destination.Append(""); | ||
//Add version to output file | ||
if (!string.IsNullOrEmpty(TypeCobolVersion)) | ||
Destination.AppendLine(" *TypeCobol_Version:" + TypeCobolVersion); | ||
|
||
var sourceFile = compilationUnit.ProgramClassDocumentSnapshot.Root; | ||
var docBuilder = new DocumentationBuilder(); | ||
sourceFile.AcceptASTVisitor(docBuilder); | ||
|
||
// For now serialize as JSON | ||
foreach (var doc in docBuilder.DTOs) | ||
{ | ||
Destination.Append(doc.SerializeToJson()); | ||
} | ||
// this.Destination contains now the Json Documentation | ||
} | ||
|
||
public List<Diagnostic> Diagnostics { get; set; } | ||
public string TypeCobolVersion { get; set; } | ||
} | ||
|
||
class DocumentationBuilder : AbstractAstVisitor | ||
{ | ||
public List<Documentation> DTOs; | ||
|
||
public DocumentationBuilder() | ||
{ | ||
DTOs = new List<Documentation>(); | ||
} | ||
public override bool Visit(TypeDefinition node) | ||
{ | ||
DataTypeDescriptionEntry ce = node.CodeElement as DataTypeDescriptionEntry; | ||
if (ce != null && ce.Visibility == AccessModifier.Public) | ||
DTOs.Add(new DocumentationForType(node)); | ||
return true; | ||
} | ||
public override bool Visit(FunctionDeclaration node) | ||
{ | ||
FunctionDeclarationHeader ce = node.CodeElement as FunctionDeclarationHeader; | ||
if (ce != null && ce.Visibility == AccessModifier.Public) | ||
DTOs.Add(new DocumentationForFunction(node)); | ||
return true; | ||
} | ||
public override bool Visit(Program node) | ||
{ | ||
DTOs.Add(new DocumentationForProgram(node)); | ||
return true; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
Codegen/test/resources/input/TypeCobol/FormalizedComments.tcbl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
? IDENTIFICATION DIVISION. | ||
PROGRAM-ID. DocCodeGen. | ||
|
||
DATA DIVISION. | ||
LOCAL-STORAGE SECTION. | ||
|
||
*<<< | ||
@ description : inline typedef | ||
@ params: | ||
- none: Type doesn't have any params | ||
@deprec | ||
@Restriction : Do not Use BOOL var | ||
*>>> | ||
01 myType TYPEDEF STRICT PUBLIC pic X(01). | ||
|
||
*<<< Vect2D | ||
*>>> | ||
01 Vect2D TYPEDEF STRICT. | ||
02 Coord2d. | ||
03 X PIC 9(4). | ||
03 Y PIC 9(4). | ||
|
||
*<<< My program | ||
@ Description : description | ||
@deprecated: | ||
@ replacedBy : MyFonction2 | ||
@ rEsTrIcTiOn : Do not Use BOOL var | ||
@ need : some needs | ||
- description | ||
@ see : Thank you for your attention | ||
@ todo : | ||
- Add BOOL support | ||
- implement a call counter | ||
*>>> | ||
PROCEDURE DIVISION. | ||
|
||
*<<< MyProc info | ||
@ deprec : It is | ||
deprecated | ||
@ need : long need | ||
@ todo: | ||
- todo1 | ||
- todo 2 | ||
@ params: | ||
- myDate: just a date | ||
- bla: bla < 2 | ||
- toto: toto | ||
-blu: will be ignored | ||
*>>> | ||
DECLARE PROCEDURE MyProc PUBLIC | ||
INPUT myDate TYPE Date | ||
bla Pic S9(1)V9(12) | ||
IN-OUT myBool TYPE BOOL | ||
OUTPUT toto TYPE BOOL | ||
bli Pic PPP999PPP. | ||
PROCEDURE DIVISION. | ||
CONTINUE. | ||
END-DECLARE. | ||
|
||
END PROGRAM DocCodeGen. | ||
|
Oops, something went wrong.