1N/AB::Xref - Generates cross reference reports for Perl programs 1N/AThe B::Xref module is used to generate a cross reference listing of all 1N/Adefinitions and uses of variables, subroutines and formats in a Perl program. 1N/AIt is implemented as a backend for the Perl compiler. 1N/AThe report generated is in the following format: 1N/A object1 line numbers 1N/A object2 line numbers 1N/AEach B<File> section reports on a single file. Each B<Subroutine> section 1N/Areports on a single subroutine apart from the special cases 1N/A"(definitions)" and "(main)". These report, respectively, on subroutine 1N/Adefinitions found by the initial symbol table walk and on the main part of 1N/Athe program or module external to all subroutines. 1N/AThe report is then grouped by the B<Package> of each variable, 1N/Asubroutine or format with the special case "(lexicals)" meaning 1N/Alexical variables. Each B<object> name (implicitly qualified by its 1N/Acontaining B<Package>) includes its type character(s) at the beginning 1N/Awhere possible. Lexical variables are easier to track and even 1N/Aincluded dereferencing information where possible. 1N/AThe C<line numbers> are a comma separated list of line numbers (some 1N/Apreceded by code letters) where that object is used in some way. 1N/ASimple uses aren't preceded by a code letter. Introductions (such as 1N/Awhere a lexical is first defined with C<my>) are indicated with the 1N/Aletter "i". Subroutine and method calls are indicated by the character 1N/A"&". Subroutine definitions are indicated by "s" and format 1N/AOption words are separated by commas (not whitespace) and follow the 1N/Ausual conventions of compiler backend options. 1N/ADirects output to C<FILENAME> instead of standard output. 1N/ARaw output. Instead of producing a human-readable report, outputs a line 1N/ADon't output the "(definitions)" sections. 1N/A(Internal) debug options, probably only useful if C<-r> included. 1N/AThe C<t> option prints the object on the top of the stack as it's 1N/Abeing tracked. The C<O> option prints each operator as it's being 1N/Aprocessed in the execution order of the program. 1N/ANon-lexical variables are quite difficult to track through a program. 1N/ASometimes the type of a non-lexical variable's use is impossible to 1N/Adetermine. Introductions of non-lexical non-scalars don't seem to be 1N/AMalcolm Beattie, mbeattie@sable.ox.ac.uk. 1N/Amy @
pad;
# lexicals in current pad 1N/A # as ["(lexical)", type, name] 1N/Amy %
done;
# keyed by $$op: set when each $op is done 1N/A # [pack, type, name] (pack can be "(lexical)") 1N/Amy $
file;
# shadows current filename 1N/Amy $
line;
# shadows current line number 1N/Amy %
table;
# Multi-level hash to record all uses etc. 1N/Amy @
todo = ();
# List of CVs that need processing 1N/A printf "%-16s %-12s %5d %-12s %4s %-16s %s\n",
1N/A # these pad GVs don't have corresponding names, so same @pad 1N/A # array can be used without collisions 1N/A # constant could be in the pad (under useithreads) 1N/A# Stuff for cross referencing definitions of variables and subs 1N/A #return if $done{$$cv}++; 1N/A print "File $file\n";
1N/A print " Subroutine $subname\n";
1N/A print " Package $pack\n";
1N/A open(
STDOUT,
">$arg")
or return "$arg: $!\n";
1N/A eval "xref_object(\\&$objname)";
1N/A die "xref_object(\\&$objname) failed: $@" if $@;