Open sundar-sarvam opened 1 year ago
https://github.com/aws-samples/aws-mainframe-modernization-carddemo/blob/main/app/cbl/CBACT02C.cbl#L1 is not line format TANDEM (which would start with line indicator in column 1), but seems to be line format FIXED.
Best Ulrich
Thanks this helped! To get the PERFORM and CALL statements (which change the control flow of the program), I was trying to use the below code:
Program program = parseCobolFile("..aws-mainframe-modernization-carddemo/app/cbl/CBACT02C.cbl");
List<CompilationUnit> programUnit3List = new ArrayList<>();
programUnit3List = program.getCompilationUnits();
for (CompilationUnit programUnit3 : programUnit3List) {
final ProgramUnit programUnit = programUnit3.getProgramUnit();
final ProcedureDivision procedureDivision = programUnit.getProcedureDivision();
final List<Paragraph> paragraphList = procedureDivision.getParagraphs();
for (Paragraph paragraph : paragraphList) {
System.out.println("Name: " + paragraph.getName());
System.out.println("Statements: " + paragraph.getStatements() );
System.out.println("Calls: "+ paragraph.getCalls());
}
}
But it prints the below as output:
Name: 9910-DISPLAY-IO-STATUS
Statements: [io.proleap.cobol.asg.metamodel.procedure.ifstmt.impl.IfStatementImpl@7a606260, io.proleap.cobol.asg.metamodel.procedure.exit.impl.ExitStatementImpl@5dbab232]
Calls: [name=[9910-DISPLAY-IO-STATUS], paragraph=[name=[9910-DISPLAY-IO-STATUS]], name=[9910-DISPLAY-IO-STATUS], paragraph=[name=[9910-DISPLAY-IO-STATUS]], name=[9910-DISPLAY-IO-STATUS], paragraph=[name=[9910-DISPLAY-IO-STATUS]]]
I need to get which PERFORM statements call which and which PROGRAMs CALL which other PROGRAMs (kind of like a dictionary with key being the caller and value being the called). How can I do this using Proleap COBOL parser? I tried different functions of paragraph
like getCalls
, etc. but none of them helps
Hello @sundar-sarvam , so in my understanding you want to navigate in the ASG (1) from a called Paragraph to all ProcedureCalls calling the Paragraph, and then (2) from each ProcedureCall to the containing PerformStatement.
(1) already works in your example.
(2) probably should work by calling ASGElement.getParent() on each ProcedureCall, which might give you a PerformProcedureStatement, and a second getParent() might give you the PerformStatement. You could write a helper function which calls getParent recursively until a certain condition is met or certain ancestor class has been found.
I did not implement this to try it out, but I am quite sure this should work. Else you can paste your code and I can take a look.
Best
Thanks @uwol . I will implement whatever you have mentioned. Also can you point to some examples where CALL <PROGRAM>
is parsed out? Typically a program can call another program as well right (which are in two different files)? To analyse these calls, I will need to parse out CALL statements. Also, will I be able to get the (start -> end) line numbers of a PERFORM statement in a file using the parser? Visual Studio Code (and other editors) using LSP offer folding ranges using which also you get the line numbers but was just wondering if it's possible through the parser itself!
Hi,
regarding calls, here you find a test: CallStatementTest.java
ASGElement.getCtx()
returns the ParserRuleContext
, i.e. the ANTLR AST element for every ASG element. ANTLR might offer some functionality to achieve this. However, COBOL has a preprocessor, which modifies line numbers in case of COPY preprocessor statements -> this would be a problem.Best Ulrich
I am trying to run the parser with this COBOL file (with the full repo downloaded): https://github.com/aws-samples/aws-mainframe-modernization-carddemo/blob/main/app/cbl/CBACT02C.cbl ( I think this is IBM dialect only). But I get the below error due to a comment line:
* You may obtain a copy of the License at
):Full error:
This isn't expected right?
My Java app:
Any clue why this might happen and workarounds for same? My aim is to find line range in a code file for different constructs like if-else, perform end-perform, etc.