Go to the first, previous, next, last section, table of contents.

Cross Reference Producer

This package provides a cross reference producer is a useful tool for debugging and program analysis. It can be used to produce the call graph of a program, and to produce a list of predicates that are used but not defined or vice versa. The graph processing utilities described in previous chapters may be used to analyze the call graphs.

To load the package, enter the query

| ?- use_module(library(xref)).
call_graph(:Files, -Graph)
Graph is the call graph (see section Unweighted Graph Operations) of the predicates in Files. The vertices of Graph are terms of the following types:
def
There is an edge from def to every predicate that is explicitly defined, declared, imported, or implicitly defined in a foreign/(2-3) fact.
use
There is an edge from use to every predicate that is used in a directive, exported, or declared as public. If a "hook" predicate such as user:portray/1 is defined, there is an edge from use to it too.
Module:Name/Arity
Denotes a predicate occurring in one of the Files. There is an edge from predicate P to predicate Q if P calls Q and Q is not a built-in predicate.
xref(:Files)
Files is a single file or a list of files, as accepted by consult/1 and friends. The predicate prints on the current output stream a list of predicates which are reachable from use in the call graph but not defined, followed by a list of predicates which are defined but not reachable from use.

There may be references not found by xref because of the dynamic nature of the Prolog language. Note that xref does not consider a predicate used unless it is reachable from a directive, an export list, or a public declaration. In non-module files, it is therefore recommended that the entry point predicates be declared as public. Predicates reached by meta-calls only may also have to be declared public to be considered used.

If a module file (file containing a module declaration) is encountered, the module specified is used for that file and subsequent files up to the next module file. This enables packages consisting of several files, which are to be loaded in the same module, to be correctly treated. The type-in module is the default module.


Go to the first, previous, next, last section, table of contents.