Next: , Previous: , Up: Cross-Referencing Facility   [Contents][Index]


12.2 Querying the cross-reference database

CMUCL provides a number of functions in the XREF package that may be used to query the cross-reference database:

Function: xref:who-calls function

Returns the list of xref-contexts where function (either a symbol that names a function, or a function object) may be called at runtime. XREF does not record calls to macro-functions (such as defun) or to special forms (such as eval-when).

Function: xref:who-references global-variable

Returns the list of program contexts that may reference global-variable.

Function: xref:who-binds global-variable

Returns a list of program contexts where the specified global variable may be bound at runtime (for example using LET).

Function: xref:who-sets global-variable

Returns a list of program contexts where the given global variable may be modified at runtime (for example using SETQ).

An xref-context is the originating site of a cross-reference. It identifies a portion of a program, and is defined by an xref-context structure, that comprises a name, a source file and a source-path.

Function: xref:xref-context-name context

Returns the name slot of an xref-context, which is one of:

  • a global function, which is named by a symbol or by a list of the form (setf foo).
  • a macro, named by a list (:macro foo).
  • an inner function (flet, labels, or anonymous lambdas) that is named by a list of the form (:internal outer inner).
  • a method, named by a list of the form (:method foo (specializer1 specializer2)).
  • a string "Top-Level Form" that identifies a reference from a top-level form. Note that multiple references from top-level forms will only be listed once.
  • a compiler-macro, named by a string of the form (:compiler-macro foo).
  • a string such as "DEFSTRUCT FOO", identifying a reference from within a structure accessor or constructor or copier.
  • a string such as
      "Creation Form for #<KERNEL::CLASS-CELL STRUCT-FOO>"
    
  • a string such as "defun foo", or "defmethod bar (t)", that identifies a reference from within code that has been generated by the compiler for that form. For example, the compilation of a defclass form causes accessor functions to be generated by the compiler; this code is compiler-generated (it does not appear in the source file), and so is identified by the XREF facility by a string.
Function: xref:xref-context-file context

Return the truename (in the sense of the variable compile-file-truename) of the source file from which the referencing forms were compiled. This slot will be nil if the code was compiled from a stream, or interactively from the listener.

Function: xref:xref-context-source-path context

Return a list of positive integers identifying the form that contains the cross-reference. The first integer in the source-path is the number of the top-level form containing the cross-reference (for example, 2 identifies the second top-level form in the source file). The second integer in the source-path identifies the form within this top-level form that contains the cross-reference, and so on. This function will always return nil if the file slot of an xref-context is nil.


Next: Example usage, Previous: Populating the cross-reference database, Up: Cross-Referencing Facility   [Contents][Index]