Pennington / Example

XTRAN Demonstration:  Producing Module/Function Cross-Reference of C

The following analysis used an XTRAN rules file comprising just over 300 lines of "meta-code" (XTRAN's rules language) to analyze all declarations of, and calls to, C functions.  The XTRAN rules file itself is not specific to C; it is language-independent, and can be used to analyze any language that allows declaration of, and calls to, procedures or functions.



* Input to XTRAN:

File module1.c:

 1      extern void proc1(void);
 2      extern int  func1(int a, int b);
 3      extern void proc2(int a, int *b);
 4      extern int  func2(void);
 5
 6 void proc3(void)
 7 {
 8      int i, j;
 9
10      proc1();                        /*procedure call*/
11      i = func2();                    /*function call*/
12      i = j;                          /*no procedure or function call*/
13      func1(1, 2);                    /*function call*/
14      i = unksym1;                    /*reference to undeclared symbol*/
15      j = func1(1, 2) + func2();      /*2 function calls*/
16      j = func1(func2(), 2);          /*function call as function arg*/
17      proc3();                        /*recursive procedure call*/
18      j = func1(1, 2) + func1(2, 1);  /*2 calls to same function*/
19      proc2(i, &j);                   /*procedure call*/
20 }

File module2.c:

 1      extern int  func1(int, int);
 2      extern void proc2(int, int *);
 3      extern int  func2(void);
 4      extern void proc3(void);
 5
 6 static int func5(int arg)
 7 {
 8      int i;
 9
10      if (arg == 1)
11          return (1);                 /*stop recursion*/
12      else if (unksym2 == 1)          /*reference to undeclared symbol*/
13          proc3();                    /*procedure call*/
14      else
15          {
16          i = unksym3;                /*reference to undeclared symbol*/
17          i = func5(i - 1);           /*recursive call*/
18          i = func6();                /*recursive call via other func*/
19          }
20      return (i);
21 }
22
23 int func6(void)
24 {
25      int i, j;
26
27      proc3();                        /*procedure call*/
28      i = func1(1, 2);                /*function call*/
29      func1(1, 2);                    /*function call*/
30      i = j;                          /*no procedure or function call*/
31      i = func6();                    /*recursive procedure call*/
32      i = func5(j);                   /*call to function in same module*/
33      j = func2() + func2();          /*2 calls to same function*/
34      j = func1(func2(), 2);          /*function call as function arg*/
35      i = func6();                    /*recursive procedure call*/
36      proc2(i, *j);                   /*procedure call*/
37      return;
38 }


* Output from XTRAN:

module1.c(14):  ?XTRAN nonfatal error; status = -121:
        i = unksym1;                    /*reference to undeclared symbol*/
                   ^
%Undeclared symbol encountered!


module2.c(12):  ?XTRAN nonfatal error; status = -121:
        else if (unksym2 == 1)          /*reference to undeclared symbol*/
                        ^
%Undeclared symbol encountered!


module2.c(16):  ?XTRAN nonfatal error; status = -121:
            i = unksym3;                /*reference to undeclared symbol*/
                       ^
%Undeclared symbol encountered!

                       PROCEDURE/Function Cross-Reference

Legend:
        D    => declaration
        X    => external declaration
        N    => nested declaration
        R    => recursive call
        else => call

Declarations & calls for each procedure/function, by source file:

func1()
    module1.c. . . . . . . . . . . . . . . 2X, 13, 15, 16, 18
    module2.c. . . . . . . . . . . . . . . 1X, 28, 29, 34
func2()
    module1.c. . . . . . . . . . . . . . . 4X, 11, 15, 16
    module2.c. . . . . . . . . . . . . . . 3X, 33, 34
func5()
    module2.c. . . . . . . . . . . . . . . 6D, 17R, 32
func6()
    module2.c. . . . . . . . . . . . . . . 18, 23D, 31R, 35R
proc1()
    module1.c. . . . . . . . . . . . . . . 1X, 10
proc2()
    module1.c. . . . . . . . . . . . . . . 3X, 19
    module2.c. . . . . . . . . . . . . . . 2X, 36
proc3()
    module1.c. . . . . . . . . . . . . . . 6D, 17R
    module2.c. . . . . . . . . . . . . . . 4X, 13, 27

Procedure/function declarations & calls in each source file,
  by procedure/function name:


module1.c
    func1() . . . 2X, 13, 15, 16, 18
    func2() . . . 4X, 11, 15, 16
    proc1() . . . 1X, 10
    proc2() . . . 3X, 19
    proc3() . . . 6D, 17R
module2.c
    func1() . . . 1X, 28, 29, 34
    func2() . . . 3X, 33, 34
    func5() . . . 6D, 17R, 32
    func6() . . . 18, 23D, 31R, 35R
    proc2() . . . 2X, 36
    proc3() . . . 4X, 13, 27


COPYRIGHT 2008; reproduction prohibited without permission.  Revised 2006-11-27

XTRAN is a trademark of Pennington Systems Incorporated.

Pennington Systems Incorporated
8655 East Via de Ventura, Suite G200
Scottsdale, Arizona 85258-3321

Phone:  +1(480)626-5503
Fax:  +1(480)626-7618
Email:  Info@Pennington.com
Web:  http://WWW.Pennington.com

[home]Home