XTRAN Example — Module/Procedure Cross-Reference of PL/I

The following example uses an XTRAN rules file comprising 176 non-comment lines of XTRAN's rules language ("meta-code") to analyze all declarations of, and calls to, procedures in code, and output that information in the form of delimiter separated values (DSV).  This example uses PL/I code, but the XTRAN rules are not specific to PL/I; they are language-independent, and can therefore be used to analyze any language that allows declaration of, and calls to, procedures or functions.

We then use another XTRAN rules file comprising 259 non-comment lines of XTRAN's rules language to process the DSV module/function data accumulated across modules and create a module/function cross-reference, both directions.  Because this process reads and manipulates only DSV data, we use a rules-only version of XTRAN.

The DSV output from the code mining rules for this example can also be interactively queried, using existing XTRAN rules.

How can such powerful and generalized code analysis and reporting be automated in only 429 total code lines of XTRAN rules?  Because there is so much capability already available as part of XTRAN's rules language.  These rules take advantage of the following functionality:

The input to and output from XTRAN are untouched, except for the addition of line numbers to the input files for reference.


Process Flowchart

Here is a flowchart for this process, in which the elements are color coded:

process flowchart

Input to XTRAN:

File demmdf1.pli:

14 proc2:  PROCEDURE EXTERNAL;
15         END proc2;
16    
17 proc3:  PROCEDURE EXTERNAL;
18         END proc3;
19 
20 proc1:  PROCEDURE STATIC;
21         CALL proc2;
22         CALL proc3;
23 proc4:      PROCEDURE;                  /*nested PROCEDURE declaration*/
24             CALL proc2;
25             CALL proc4;                 /*recursive call*/
26             CALL proc3;
27             CALL proc1;                 /*recursive call to outer routine*/
28             CALL proc2;
29             END proc4;
30         CALL proc1;                     /*recursive call*/
31         CALL proc3;
32         END proc1;

File demmdf2.pli:

10 proc3:  PROCEDURE EXTERNAL;
11         END proc3;
12 
13 proc2:  PROCEDURE;
14         CALL proc3;
15         CALL proc3;
16         CALL proc2;                     /*recursive call*/
17         CALL proc3;
18         END proc2;


Output from XTRAN:


                      PL/I Module/Function Cross-reference

                               Module / Function

Legend:
        C => normal call
        D => declaration
        E => external global declaration
        I => internal global declaration
        N => nested declaration
        R => recursive call
        S => "static" declaration

demmdf1.pli
    proc1()  20:S, 27:R, 30:R
    proc2()  12:E, 21:C, 24:C, 28:C
    proc3()  17:E, 22:C, 26:C, 31:C
    proc4()  23:N, 25:R
demmdf2.pli
    proc2()  13:D, 16:R
    proc3()  10:E, 14:C, 15:C, 17:C
<FF>
                      PL/I Module/Function Cross-reference

                               Function / Module

Legend:
        C => call
        D => declaration
        E => external globaldeclaration
        I => internal global declaration
        N => nested declaration
        R => recursive call
        S => "static" declaration

proc1()
    demmdf1.pli  20:S, 27:R, 30:R
proc2()
    demmdf1.pli  12:E, 21:C, 24:C, 28:C
    demmdf2.pli  13:D, 16:R
proc3()
    demmdf1.pli  17:E, 22:C, 26:C, 31:C
    demmdf2.pli  10:E, 14:C, 15:C, 17:C
proc4()
    demmdf1.pli  23:N, 25:R