dotemacs

My Emacs configuration
git clone git://git.entf.net/dotemacs
Log | Files | Refs | LICENSE

xref.lisp (126418B)


      1 ;;; -*- Mode: LISP; Syntax: Common-lisp;  -*-
      2 ;;; Mon Jan 21 16:21:20 1991 by Mark Kantrowitz <mkant@GLINDA.OZ.CS.CMU.EDU>
      3 ;;; xref.lisp
      4 
      5 ;;; ****************************************************************
      6 ;;; List Callers: A Static Analysis Cross Referencing Tool for Lisp 
      7 ;;; ****************************************************************
      8 ;;; 
      9 ;;; The List Callers system is a portable Common Lisp cross referencing
     10 ;;; utility. It grovels over a set of files and compiles a database of the
     11 ;;; locations of all references for each symbol used in the files.
     12 ;;; List Callers is similar to the Symbolics Who-Calls and the
     13 ;;; Xerox Masterscope facilities.
     14 ;;;
     15 ;;; When you change a function or variable definition, it can be useful
     16 ;;; to know its callers, in order to update each of them to the new
     17 ;;; definition. Similarly, having a graphic display of the structure 
     18 ;;; (e.g., call graph) of a program can help make undocumented code more
     19 ;;; understandable. This static code analyzer facilitates both capabilities.
     20 ;;; The database compiled by xref is suitable for viewing by a graphical 
     21 ;;; browser. (Note: the reference graph is not necessarily a DAG. Since many
     22 ;;; graphical browsers assume a DAG, this will lead to infinite loops.
     23 ;;; Some code which is useful in working around this problem is included,
     24 ;;; as well as a sample text-indenting outliner and an interface to Bates'
     25 ;;; PSGraph Postscript Graphing facility.) 
     26 ;;;
     27 ;;; Written by Mark Kantrowitz, July 1990.
     28 ;;;
     29 ;;; Address: School of Computer Science
     30 ;;;          Carnegie Mellon University
     31 ;;;          Pittsburgh, PA 15213
     32 ;;;
     33 ;;; Copyright (c) 1990. All rights reserved.
     34 ;;;
     35 ;;; See general license below.
     36 ;;;
     37 
     38 ;;; ****************************************************************
     39 ;;; General License Agreement and Lack of Warranty *****************
     40 ;;; ****************************************************************
     41 ;;;
     42 ;;; This software is distributed in the hope that it will be useful (both
     43 ;;; in and of itself and as an example of lisp programming), but WITHOUT
     44 ;;; ANY WARRANTY. The author(s) do not accept responsibility to anyone for
     45 ;;; the consequences of using it or for whether it serves any particular
     46 ;;; purpose or works at all. No warranty is made about the software or its
     47 ;;; performance. 
     48 ;;; 
     49 ;;; Use and copying of this software and the preparation of derivative
     50 ;;; works based on this software are permitted, so long as the following
     51 ;;; conditions are met:
     52 ;;;	o  The copyright notice and this entire notice are included intact
     53 ;;;        and prominently carried on all copies and supporting documentation.
     54 ;;;	o  No fees or compensation are charged for use, copies, or
     55 ;;;	   access to this software. You may charge a nominal
     56 ;;;	   distribution fee for the physical act of transferring a
     57 ;;;	   copy, but you may not charge for the program itself. 
     58 ;;;	o  If you modify this software, you must cause the modified
     59 ;;;	   file(s) to carry prominent notices (a Change Log)
     60 ;;;	   describing the changes, who made the changes, and the date
     61 ;;;	   of those changes.
     62 ;;;	o  Any work distributed or published that in whole or in part
     63 ;;;	   contains or is a derivative of this software or any part 
     64 ;;;	   thereof is subject to the terms of this agreement. The 
     65 ;;;	   aggregation of another unrelated program with this software
     66 ;;;	   or its derivative on a volume of storage or distribution
     67 ;;;	   medium does not bring the other program under the scope
     68 ;;;	   of these terms.
     69 ;;;	o  Permission is granted to manufacturers and distributors of
     70 ;;;	   lisp compilers and interpreters to include this software
     71 ;;;	   with their distribution. 
     72 ;;;
     73 ;;; This software is made available AS IS, and is distributed without 
     74 ;;; warranty of any kind, either expressed or implied.
     75 ;;; 
     76 ;;; In no event will the author(s) or their institutions be liable to you
     77 ;;; for damages, including lost profits, lost monies, or other special,
     78 ;;; incidental or consequential damages arising out of or in connection
     79 ;;; with the use or inability to use (including but not limited to loss of
     80 ;;; data or data being rendered inaccurate or losses sustained by third
     81 ;;; parties or a failure of the program to operate as documented) the 
     82 ;;; program, even if you have been advised of the possibility of such
     83 ;;; damanges, or for any claim by any other party, whether in an action of
     84 ;;; contract, negligence, or other tortious action.
     85 ;;; 
     86 ;;; The current version of this software and a variety of related utilities
     87 ;;; may be obtained by anonymous ftp from ftp.cs.cmu.edu in the directory
     88 ;;;    user/ai/lang/lisp/code/tools/xref/
     89 ;;; 
     90 ;;; Please send bug reports, comments, questions and suggestions to
     91 ;;; mkant@cs.cmu.edu. We would also appreciate receiving any changes
     92 ;;; or improvements you may make. 
     93 ;;; 
     94 ;;; If you wish to be added to the Lisp-Utilities@cs.cmu.edu mailing list, 
     95 ;;; send email to Lisp-Utilities-Request@cs.cmu.edu with your name, email
     96 ;;; address, and affiliation. This mailing list is primarily for
     97 ;;; notification about major updates, bug fixes, and additions to the lisp
     98 ;;; utilities collection. The mailing list is intended to have low traffic.
     99 ;;;
    100 
    101 ;;; ********************************
    102 ;;; Change Log *********************
    103 ;;; ********************************
    104 ;;;
    105 ;;; 27-FEB-91 mk   Added insert arg to psgraph-xref to allow the postscript
    106 ;;;                graphs to be inserted in Scribe documents.
    107 ;;; 21-FEB-91 mk   Added warning if not compiled.
    108 ;;; 07-FEB-91 mk   Fixed bug in record-callers with regard to forms at 
    109 ;;;                toplevel.
    110 ;;; 21-JAN-91 mk   Added file xref-test.lisp to test xref.
    111 ;;; 16-JAN-91 mk   Added definition WHO-CALLS to parallel the Symbolics syntax.
    112 ;;; 16-JAN-91 mk   Added macroexpansion capability to record-callers. Also
    113 ;;;                added parameter *handle-macro-forms*, defaulting to T.
    114 ;;; 16-JAN-91 mk   Modified print-caller-tree and related functions
    115 ;;;                to allow the user to specify root nodes. If the user
    116 ;;;                doesn't specify them, it will default to all root
    117 ;;;                nodes, as before. 
    118 ;;; 16-JAN-91 mk   Added parameter *default-graphing-mode* to specify
    119 ;;;                the direction of the graphing. Either :call-graph,
    120 ;;;                where the children of a node are those functions called
    121 ;;;                by the node, or :caller-graph where the children of a
    122 ;;;                node are the callers of the node. :call-graph is the
    123 ;;;                default.
    124 ;;; 16-JAN-91 mk   Added parameter *indent-amount* to control the indentation
    125 ;;;                in print-indented-tree.
    126 ;;; 16-JUL-90 mk   Functions with argument lists of () were being ignored
    127 ;;;                because of a (when form) wrapped around the body of
    128 ;;;                record-callers. Then intent of (when form) was as an extra
    129 ;;;                safeguard against infinite looping. This wasn't really
    130 ;;;                necessary, so it has been removed.
    131 ;;; 16-JUL-90 mk   PSGraph-XREF now has keyword arguments, instead of
    132 ;;;                optionals.
    133 ;;; 16-JUL-90 mk   Added PRINT-CLASS-HIERARCHY to use psgraph to graph the
    134 ;;;                CLOS class hierarchy. This really doesn't belong here,
    135 ;;;                and should be moved to psgraph.lisp as an example of how
    136 ;;;                to use psgraph.
    137 ;;; 16-JUL-90 mk   Fixed several caller patterns. The pattern for member
    138 ;;;                had an error which caused many references to be missed.
    139 ;;; 16-JUL-90 mk   Added ability to save/load processed databases.
    140 ;;;  5-JUL-91 mk    Fixed warning of needing compilation to occur only when the
    141 ;;;                 source is loaded.
    142 ;;; 20-SEP-93 mk    Added fix from Peter Norvig to allow Xref to xref itself.
    143 ;;;                 The arg to macro-function must be a symbol.
    144 ;;;  7-APR-12 heller  Break lines at 80 columns.
    145 
    146 ;;; ********************************
    147 ;;; To Do **************************
    148 ;;; ********************************
    149 ;;;
    150 ;;; Verify that:
    151 ;;;    o  null forms don't cause it to infinite loop.
    152 ;;;    o  nil matches against null argument lists.
    153 ;;;    o  declarations and doc are being ignored.
    154 ;;;
    155 ;;; Would be nice if in addition to showing callers of a function, it
    156 ;;; displayed the context of the calls to the function (e.g., the
    157 ;;; immediately surrounding form). This entails storing entries of
    158 ;;; the form (symbol context*) in the database and augmenting
    159 ;;; record-callers to keep the context around. The only drawbacks is
    160 ;;; that it would cons a fair bit. If we do this, we should store
    161 ;;; additional information as well in the database, such as the caller
    162 ;;; pattern type (e.g., variable vs. function).
    163 ;;;
    164 ;;; Write a translator from BNF (at least as much of BNF as is used
    165 ;;; in CLtL2), to the format used here.
    166 ;;;
    167 ;;; Should automatically add new patterns for new functions and macros
    168 ;;; based on their arglists. Probably requires much more than this
    169 ;;; simple code walker, so there isn't much we can do.
    170 ;;;
    171 ;;; Defmacro is a problem, because it often hides internal function
    172 ;;; calls within backquote and quote, which we normally ignore. If
    173 ;;; we redefine QUOTE's pattern so that it treats the arg like a FORM,
    174 ;;; we'll probably get them (though maybe the syntax will be mangled),
    175 ;;; but most likely a lot of spurious things as well. 
    176 ;;;
    177 ;;; Define an operation for Defsystem which will run XREF-FILE on the
    178 ;;; files of the system. Or yet simpler, when XREF sees a LOAD form
    179 ;;; for which the argument is a string, tries to recursively call
    180 ;;; XREF-FILE on the specified file. Then one could just XREF-FILE
    181 ;;; the file which loads the system. (This should be a program
    182 ;;; parameter.)
    183 ;;;
    184 ;;; Have special keywords which the user may place in a file to have
    185 ;;; XREF-FILE ignore a region.
    186 ;;;
    187 ;;; Should we distinguish flet and labels from defun? I.e., note that
    188 ;;; flet's definitions are locally defined, instead of just lumping
    189 ;;; them in with regular definitions.
    190 ;;;
    191 ;;; Add patterns for series, loop macro.
    192 ;;;
    193 ;;; Need to integrate the variable reference database with the other
    194 ;;; databases, yet maintain separation. So we can distinguish all
    195 ;;; the different types of variable and function references, without
    196 ;;; multiplying databases.
    197 ;;;
    198 ;;; Would pay to comment record-callers and record-callers* in more
    199 ;;; depth.
    200 ;;; 
    201 ;;; (&OPTIONAL &REST &KEY &AUX &BODY &WHOLE &ALLOW-OTHER-KEYS &ENVIRONMENT)
    202 
    203 ;;; ********************************
    204 ;;; Notes **************************
    205 ;;; ********************************
    206 ;;;
    207 ;;;    XREF has been tested (successfully) in the following lisps:
    208 ;;;       CMU Common Lisp (M2.9 15-Aug-90, Compiler M1.8 15-Aug-90)
    209 ;;;       Macintosh Allegro Common Lisp (1.3.2)
    210 ;;;       ExCL (Franz Allegro CL 3.1.12 [DEC 3100] 3/30/90)
    211 ;;;       Lucid CL (Version 2.1 6-DEC-87)
    212 ;;;    
    213 ;;;    XREF has been tested (unsuccessfully) in the following lisps:
    214 ;;;       Ibuki Common Lisp (01/01, October 15, 1987)
    215 ;;;           - if interpreted, runs into stack overflow
    216 ;;;           - does not compile (tried ibcl on Suns, PMAXes and RTs)
    217 ;;;             seems to be due to a limitation in the c compiler.
    218 ;;;    
    219 ;;;    XREF needs to be tested in the following lisps:
    220 ;;;       Symbolics Common Lisp (8.0)
    221 ;;;       Lucid Common Lisp (3.0, 4.0)
    222 ;;;       KCL (June 3, 1987 or later)
    223 ;;;       AKCL (1.86, June 30, 1987 or later)
    224 ;;;       TI (Release 4.1 or later)
    225 ;;;       Golden Common Lisp (3.1 IBM-PC)
    226 ;;;       VAXLisp (2.0, 3.1)
    227 ;;;       HP Common Lisp (same as Lucid?)
    228 ;;;       Procyon Common Lisp
    229 
    230 
    231 ;;; ****************************************************************
    232 ;;; Documentation **************************************************
    233 ;;; ****************************************************************
    234 ;;;
    235 ;;; XREF analyzes a user's program, determining which functions call a
    236 ;;; given function, and the location of where variables are bound/assigned
    237 ;;; and used. The user may retrieve this information for either a single
    238 ;;; symbol, or display the call graph of portions of the program
    239 ;;; (including the entire program). This allows the programmer to debug
    240 ;;; and document the program's structure.
    241 ;;; 
    242 ;;; XREF is primarily intended for analyzing large programs, where it is
    243 ;;; difficult, if not impossible, for the programmer to grasp the structure
    244 ;;; of the whole program. Nothing precludes using XREF for smaller programs,
    245 ;;; where it can be useful for inspecting the relationships between pieces
    246 ;;; of the program and for documenting the program.
    247 ;;; 
    248 ;;; Two aspects of the Lisp programming language greatly simplify the
    249 ;;; analysis of Lisp programs:
    250 ;;; 	o  Lisp programs are naturally represented as data.
    251 ;;; 	   Successive definitions from a file are easily read in
    252 ;;; 	   as list structure.
    253 ;;; 	o  The basic syntax of Lisp is uniform. A list program
    254 ;;; 	   consists of a set of nested forms, where each form is
    255 ;;; 	   a list whose car is a tag (e.g., function name) that
    256 ;;; 	   specifies the structure of the rest of the form.
    257 ;;; Thus Lisp programs, when represented as data, can be considered to be
    258 ;;; parse trees. Given a grammar of syntax patterns for the language, XREF
    259 ;;; recursively descends the parse tree for a given definition, computing
    260 ;;; a set of relations that hold for the definition at each node in the
    261 ;;; tree. For example, one kind of relation is that the function defined
    262 ;;; by the definition calls the functions in its body. The relations are
    263 ;;; stored in a database for later examination by the user.
    264 ;;; 
    265 ;;; While XREF currently only works for programs written in Lisp, it could
    266 ;;; be extended to other programming languages by writing a function to
    267 ;;; generate parse trees for definitions in that language, and a core
    268 ;;; set of patterns for the language's syntax.
    269 ;;; 
    270 ;;; Since XREF normally does a static syntactic analysis of the program, 
    271 ;;; it does not detect references due to the expansion of a macro definition. 
    272 ;;; To do this in full generality XREF would have to have knowledge about the
    273 ;;; semantics of the program (e.g., macros which call other functions to
    274 ;;; do the expansion). This entails either modifying the compiler to
    275 ;;; record the relationships (e.g., Symbolics Who-Calls Database) or doing
    276 ;;; a walk of loaded code and macroexpanding as needed (PCL code walker).
    277 ;;; The former is not portable, while the latter requires that the code
    278 ;;; used by macros be loaded and in working order. On the other hand, then
    279 ;;; we would need no special knowledge about macros (excluding the 24 special
    280 ;;; forms of Lisp).
    281 ;;;
    282 ;;; Parameters may be set to enable macro expansion in XREF. Then XREF
    283 ;;; will expand any macros for which it does not have predefined patterns.
    284 ;;; (For example, most Lisps will implement dolist as a macro. Since XREF
    285 ;;; has a pattern defined for dolist, it will not call macroexpand-1 on
    286 ;;; a form whose car is dolist.) For this to work properly, the code must
    287 ;;; be loaded before being processed by XREF, and XREF's parameters should
    288 ;;; be set so that it processes forms in their proper packages. 
    289 ;;;
    290 ;;; If macro expansion is disabled, the default rules for handling macro
    291 ;;; references may not be sufficient for some user-defined macros, because
    292 ;;; macros allow a variety of non-standard syntactic extensions to the
    293 ;;; language. In this case, the user may specify additional templates in
    294 ;;; a manner similar to that in which the core Lisp grammar was specified.
    295 ;;;
    296 
    297 
    298 ;;; ********************************
    299 ;;; User Guide *********************
    300 ;;; ********************************
    301 ;;; -----
    302 ;;; The following functions are called to cross reference the source files.
    303 ;;;
    304 ;;; XREF-FILES (&rest files)                                      [FUNCTION]
    305 ;;;    Grovels over the lisp code located in source file FILES, using
    306 ;;;    xref-file.
    307 ;;;
    308 ;;; XREF-FILE (filename &optional clear-tables verbose)       [Function]
    309 ;;;    Cross references the function and variable calls in FILENAME by
    310 ;;;    walking over the source code located in the file. Defaults type of
    311 ;;;    filename to ".lisp". Chomps on the code using record-callers and
    312 ;;;    record-callers*. If CLEAR-TABLES is T (the default), it clears the
    313 ;;;    callers database before processing the file. Specify CLEAR-TABLES as
    314 ;;;    nil to append to the database. If VERBOSE is T (the default), prints
    315 ;;;    out the name of the file, one progress dot for each form processed,
    316 ;;;    and the total number of forms.
    317 ;;;
    318 ;;; -----
    319 ;;; The following functions display information about the uses of the 
    320 ;;; specified symbol as a function, variable, or constant.
    321 ;;;
    322 ;;; LIST-CALLERS (symbol)                                         [FUNCTION]
    323 ;;;    Lists all functions which call SYMBOL as a function (function
    324 ;;;    invocation).
    325 ;;;
    326 ;;; LIST-READERS (symbol)                                         [FUNCTION]
    327 ;;;    Lists all functions which refer to SYMBOL as a variable
    328 ;;;    (variable reference).
    329 ;;;
    330 ;;; LIST-SETTERS (symbol)                                         [FUNCTION]
    331 ;;;    Lists all functions which bind/set SYMBOL as a variable
    332 ;;;    (variable mutation).
    333 ;;;
    334 ;;; LIST-USERS (symbol)                                           [FUNCTION]
    335 ;;;    Lists all functions which use SYMBOL as a variable or function.
    336 ;;;
    337 ;;; WHO-CALLS (symbol &optional how)                              [FUNCTION]
    338 ;;;    Lists callers of symbol. HOW may be :function, :reader, :setter,
    339 ;;;    or :variable."
    340 ;;;
    341 ;;; WHAT-FILES-CALL (symbol)                                      [FUNCTION]
    342 ;;;    Lists names of files that contain uses of SYMBOL
    343 ;;;    as a function, variable, or constant.
    344 ;;;
    345 ;;; SOURCE-FILE (symbol)                                          [FUNCTION]
    346 ;;;    Lists the names of files in which SYMBOL is defined/used.
    347 ;;;
    348 ;;; LIST-CALLEES (symbol)                                         [FUNCTION]
    349 ;;;    Lists names of functions and variables called by SYMBOL.
    350 ;;;
    351 ;;; -----
    352 ;;; The following functions may be useful for viewing the database and
    353 ;;; debugging the calling patterns.
    354 ;;;
    355 ;;; *LAST-FORM* ()                                                [VARIABLE]
    356 ;;;    The last form read from the file. Useful for figuring out what went
    357 ;;;    wrong when xref-file drops into the debugger.
    358 ;;;
    359 ;;; *XREF-VERBOSE* t                                              [VARIABLE]
    360 ;;;    When T, xref-file(s) prints out the names of the files it looks at,
    361 ;;;    progress dots, and the number of forms read.
    362 ;;;
    363 ;;; *TYPES-TO-IGNORE* (quote (:lisp :lisp2))                      [VARIABLE]
    364 ;;;    Default set of caller types (as specified in the patterns) to ignore
    365 ;;;    in the database handling functions. :lisp is CLtL 1st edition,
    366 ;;;    :lisp2 is additional patterns from CLtL 2nd edition.
    367 ;;;
    368 ;;; *HANDLE-PACKAGE-FORMS* ()                                     [VARIABLE]
    369 ;;;    When non-NIL, and XREF-FILE sees a package-setting form like
    370 ;;;    IN-PACKAGE, sets the current package to the specified package by
    371 ;;;    evaluating the form. When done with the file, xref-file resets the
    372 ;;;    package to its original value. In some of the displaying functions,
    373 ;;;    when this variable is non-NIL one may specify that all symbols from a
    374 ;;;    particular set of packages be ignored. This is only useful if the
    375 ;;;    files use different packages with conflicting names.
    376 ;;;
    377 ;;; *HANDLE-FUNCTION-FORMS* t                                     [VARIABLE]
    378 ;;;    When T, XREF-FILE tries to be smart about forms which occur in
    379 ;;;    a function position, such as lambdas and arbitrary Lisp forms.
    380 ;;;    If so, it recursively calls record-callers with pattern 'FORM.
    381 ;;;    If the form is a lambda, makes the caller a caller of
    382 ;;;    :unnamed-lambda.
    383 ;;;
    384 ;;; *HANDLE-MACRO-FORMS* t                                        [VARIABLE]
    385 ;;;    When T, if the file was loaded before being processed by XREF, and
    386 ;;;    the car of a form is a macro, it notes that the parent calls the
    387 ;;;    macro, and then calls macroexpand-1 on the form.
    388 ;;;
    389 ;;; *DEFAULT-GRAPHING-MODE* :call-graph                           [VARIABLE]
    390 ;;;    Specifies whether we graph up or down. If :call-graph, the children
    391 ;;;    of a node are the functions it calls. If :caller-graph, the
    392 ;;;    children of a node are the functions that call it.
    393 ;;;
    394 ;;; *INDENT-AMOUNT* 3                                             [VARIABLE]
    395 ;;;    Number of spaces to indent successive levels in PRINT-INDENTED-TREE.
    396 ;;;
    397 ;;; DISPLAY-DATABASE (&optional database types-to-ignore)         [FUNCTION]
    398 ;;;    Prints out the name of each symbol and all its callers. Specify
    399 ;;;    database :callers (the default) to get function call references,
    400 ;;;    :file to the get files in which the symbol is called, :readers to get
    401 ;;;    variable references, and :setters to get variable binding and
    402 ;;;    assignments. Ignores functions of types listed in types-to-ignore.
    403 ;;;
    404 ;;; PRINT-CALLER-TREES (&key (mode *default-graphing-mode*)       [FUNCTION]
    405 ;;;                     (types-to-ignore *types-to-ignore*)
    406 ;;;                     compact root-nodes)
    407 ;;;    Prints the calling trees (which may actually be a full graph and not
    408 ;;;    necessarily a DAG) as indented text trees using
    409 ;;;    PRINT-INDENTED-TREE. MODE is :call-graph for trees where the children
    410 ;;;    of a node are the functions called by the node, or :caller-graph for
    411 ;;;    trees where the children of a node are the functions the node calls.
    412 ;;;    TYPES-TO-IGNORE is a list of funcall types (as specified in the
    413 ;;;    patterns) to ignore in printing out the database. For example,
    414 ;;;    '(:lisp) would ignore all calls to common lisp functions. COMPACT is
    415 ;;;    a flag to tell the program to try to compact the trees a bit by not
    416 ;;;    printing trees if they have already been seen. ROOT-NODES is a list
    417 ;;;    of root nodes of trees to display. If ROOT-NODES is nil, tries to
    418 ;;;    find all root nodes in the database.
    419 ;;;
    420 ;;; MAKE-CALLER-TREE (&optional (mode *default-graphing-mode*)    [FUNCTION]
    421 ;;;                   (types-to-ignore *types-to-ignore*)
    422 ;;;                   compact)
    423 ;;;    Outputs list structure of a tree which roughly represents the
    424 ;;;    possibly cyclical structure of the caller database.
    425 ;;;    If mode is :call-graph, the children of a node are the functions
    426 ;;;    it calls. If mode is :caller-graph, the children of a node are the
    427 ;;;    functions that call it.
    428 ;;;    If compact is T, tries to eliminate the already-seen nodes, so
    429 ;;;    that the graph for a node is printed at most once. Otherwise it will
    430 ;;;    duplicate the node's tree (except for cycles). This is usefull
    431 ;;;    because the call tree is actually a directed graph, so we can either
    432 ;;;    duplicate references or display only the first one.
    433 ;;;
    434 ;;; DETERMINE-FILE-DEPENDENCIES (&optional database)          [FUNCTION]
    435 ;;;    Makes a hash table of file dependencies for the references listed in
    436 ;;;    DATABASE. This function may be useful for automatically resolving
    437 ;;;    file references for automatic creation of a system definition
    438 ;;;    (defsystem).
    439 ;;;
    440 ;;; PRINT-FILE-DEPENDENCIES (&optional database)              [FUNCTION]
    441 ;;;    Prints a list of file dependencies for the references listed in
    442 ;;;    DATABASE. This function may be useful for automatically computing
    443 ;;;    file loading constraints for a system definition tool.
    444 ;;;
    445 ;;; WRITE-CALLERS-DATABASE-TO-FILE (filename)                     [FUNCTION]
    446 ;;;    Saves the contents of the current callers database to a file. This
    447 ;;;    file can be loaded to restore the previous contents of the
    448 ;;;    database. (For large systems it can take a long time to crunch
    449 ;;;    through the code, so this can save some time.)
    450 ;;;
    451 ;;; -----
    452 ;;; The following macros define new function and macro call patterns.
    453 ;;; They may be used to extend the static analysis tool to handle
    454 ;;; new def forms, extensions to Common Lisp, and program defs.
    455 ;;;
    456 ;;; DEFINE-PATTERN-SUBSTITUTION (name pattern)                    [MACRO]
    457 ;;;    Defines NAME to be equivalent to the specified pattern. Useful for
    458 ;;;    making patterns more readable. For example, the LAMBDA-LIST is
    459 ;;;    defined as a pattern substitution, making the definition of the
    460 ;;;    DEFUN caller-pattern simpler.
    461 ;;;
    462 ;;; DEFINE-CALLER-PATTERN (name pattern &optional caller-type)    [MACRO]
    463 ;;;    Defines NAME as a function/macro call with argument structure
    464 ;;;    described by PATTERN. CALLER-TYPE, if specified, assigns a type to
    465 ;;;    the pattern, which may be used to exclude references to NAME while
    466 ;;;    viewing the database. For example, all the Common Lisp definitions
    467 ;;;    have a caller-type of :lisp or :lisp2, so that you can exclude
    468 ;;;    references to common lisp functions from the calling tree.
    469 ;;;
    470 ;;; DEFINE-VARIABLE-PATTERN (name &optional caller-type)          [MACRO]
    471 ;;;    Defines NAME as a variable reference of type CALLER-TYPE. This is
    472 ;;;    mainly used to establish the caller-type of the variable.
    473 ;;;
    474 ;;; DEFINE-CALLER-PATTERN-SYNONYMS (source destinations)          [MACRO]
    475 ;;;    For defining function caller pattern syntax synonyms. For each name
    476 ;;;    in DESTINATIONS, defines its pattern as a copy of the definition
    477 ;;;    of SOURCE. Allows a large number of identical patterns to be defined
    478 ;;;    simultaneously. Must occur after the SOURCE has been defined.
    479 ;;;
    480 ;;; -----
    481 ;;; This system includes pattern definitions for the latest
    482 ;;; common lisp specification, as published in Guy Steele,
    483 ;;; Common Lisp: The Language, 2nd Edition.
    484 ;;;
    485 ;;; Patterns may be either structures to match, or a predicate
    486 ;;; like symbolp/numberp/stringp. The pattern specification language
    487 ;;; is similar to the notation used in CLtL2, but in a more lisp-like 
    488 ;;; form:
    489 ;;;    (:eq name)           The form element must be eq to the symbol NAME.
    490 ;;;    (:test test)         TEST must be true when applied to the form element.
    491 ;;;    (:typep type)        The form element must be of type TYPE.
    492 ;;;    (:or pat1 pat2 ...)  Tries each of the patterns in left-to-right order,
    493 ;;;                         until one succeeds.
    494 ;;;                         Equivalent to { pat1 | pat2 | ... }
    495 ;;;    (:rest pattern)      The remaining form elements are grouped into a
    496 ;;;                         list which is matched against PATTERN.
    497 ;;;    (:optional pat1 ...) The patterns may optionally match against the
    498 ;;;                         form element.
    499 ;;;                         Equivalent to [ pat1 ... ].
    500 ;;;    (:star pat1 ...)     The patterns may match against the patterns
    501 ;;;                         any number of times, including 0.
    502 ;;;                         Equivalent to { pat1 ... }*.
    503 ;;;    (:plus pat1 ...)     The patterns may match against the patterns
    504 ;;;                         any number of times, but at least once.
    505 ;;;                         Equivalent to { pat1 ... }+.
    506 ;;;    &optional, &key,     Similar in behavior to the corresponding
    507 ;;;    &rest                lambda-list keywords.
    508 ;;;    FORM                 A random lisp form. If a cons, assumes the
    509 ;;;                         car is a function or macro and tries to
    510 ;;;                         match the args against that symbol's pattern.
    511 ;;;                         If a symbol, assumes it's a variable reference.
    512 ;;;    :ignore              Ignores the corresponding form element.
    513 ;;;    NAME                 The corresponding form element should be
    514 ;;;                         the name of a new definition (e.g., the
    515 ;;;                         first arg in a defun pattern is NAME.
    516 ;;;    FUNCTION, MACRO      The corresponding form element should be
    517 ;;;                         a function reference not handled by FORM.
    518 ;;;                         Used in the definition of apply and funcall.
    519 ;;;    VAR                  The corresponding form element should be
    520 ;;;                         a variable definition or mutation. Used
    521 ;;;                         in the definition of let, let*, etc.
    522 ;;;    VARIABLE             The corresponding form element should be
    523 ;;;                         a variable reference. 
    524 ;;;
    525 ;;; In all other pattern symbols, it looks up the symbols pattern substitution
    526 ;;; and recursively matches against the pattern. Automatically destructures
    527 ;;; list structure that does not include consing dots.
    528 ;;;
    529 ;;; Among the pattern substitution names defined are:
    530 ;;;    STRING, SYMBOL, NUMBER    Appropriate :test patterns.
    531 ;;;    LAMBDA-LIST               Matches against a lambda list.
    532 ;;;    BODY                      Matches against a function body definition.
    533 ;;;    FN                        Matches against #'function, 'function,
    534 ;;;                              and lambdas. This is used in the definition
    535 ;;;                              of apply, funcall, and the mapping patterns.
    536 ;;;    and others...
    537 ;;;
    538 ;;; Here's some sample pattern definitions:
    539 ;;; (define-caller-pattern defun 
    540 ;;;   (name lambda-list
    541 ;;;	(:star (:or documentation-string declaration))
    542 ;;;	(:star form))
    543 ;;;  :lisp)
    544 ;;; (define-caller-pattern funcall (fn (:star form)) :lisp)
    545 ;;;
    546 ;;; In general, the system is intelligent enough to handle any sort of
    547 ;;; simple funcall. One only need specify the syntax for functions and
    548 ;;; macros which use optional arguments, keyword arguments, or some
    549 ;;; argument positions are special, such as in apply and funcall, or
    550 ;;; to indicate that the function is of the specified caller type.
    551 ;;;
    552 ;;;
    553 ;;; NOTES:
    554 ;;;
    555 ;;;    XRef assumes syntactically correct lisp code.
    556 ;;;
    557 ;;;    This is by no means perfect. For example, let and let* are treated
    558 ;;;    identically, instead of differentiating between serial and parallel
    559 ;;;    binding. But it's still a useful tool. It can be helpful in 
    560 ;;;    maintaining code, debugging problems with patch files, determining
    561 ;;;    whether functions are multiply defined, and help you remember where
    562 ;;;    a function is defined or called.
    563 ;;;
    564 ;;;    XREF runs best when compiled.
    565 
    566 ;;; ********************************
    567 ;;; References *********************
    568 ;;; ********************************
    569 ;;;
    570 ;;; Xerox Interlisp Masterscope Program:
    571 ;;;   Larry M Masinter, Global program analysis in an interactive environment
    572 ;;;   PhD Thesis, Stanford University, 1980. 
    573 ;;;
    574 ;;; Symbolics Who-Calls Database:
    575 ;;;   User's Guide to Symbolics Computers, Volume 1, Cambridge, MA, July 1986
    576 ;;;   Genera 7.0, pp 183-185.
    577 ;;;   
    578 
    579 ;;; ********************************
    580 ;;; Example ************************
    581 ;;; ********************************
    582 ;;; 
    583 ;;; Here is an example of running XREF on a short program.
    584 ;;; [In Scribe documentation, give a simple short program and resulting
    585 ;;;  XREF output, including postscript call graphs.]
    586 #|
    587 <cl> (xref:xref-file  "/afs/cs/user/mkant/Lisp/Graph-Dag/graph-dag.lisp")
    588 Cross-referencing file /afs/cs/user/mkant/Lisp/Graph-Dag/graph-dag.lisp.
    589 ................................................
    590 48 forms processed.
    591 <cl> (xref:display-database :readers)
    592 
    593 *DISPLAY-CUTOFF-DEPTH* is referenced by CALCULATE-LEVEL-POSITION
    594 CALCULATE-LEVEL-POSITION-BEFORE CALCULATE-POSITION-IN-LEVEL.
    595 *OFFSET-FROM-EDGE-OF-PANE* is referenced by CALCULATE-LEVEL-POSITION
    596 CALCULATE-LEVEL-POSITION-BEFORE.
    597 *WITHIN-LEVEL-SPACING* is referenced by BREADTH CALCULATE-POSITION-INFO.
    598 *DIRECTION* is referenced by CREATE-POSITION-INFO.
    599 *LINK-OFFSET* is referenced by OFFSET-OF-LINK-FROM-ATTACHMENT-POINT.
    600 *ROOT-IS-SEQUENCE* is referenced by GRAPH.
    601 *LEVEL-SPACING* is referenced by CALCULATE-LEVEL-POSITION
    602 CALCULATE-LEVEL-POSITION-BEFORE.
    603 *ORIENTATION* is referenced by BREADTH CALCULATE-LEVEL-POSITION
    604 CALCULATE-LEVEL-POSITION-BEFORE CALCULATE-POSITION-IN-LEVEL.
    605 *DEFAULT-GRAPH-POSITION* is referenced by CREATE-POSITION-INFO.
    606 *GRAPHING-CUTOFF-DEPTH* is referenced by CREATE-NODE-STRUCTURE.
    607 *LIST-OF-NODES* is referenced by CALCULATE-LEVEL-POSITION
    608 CALCULATE-LEVEL-POSITION-BEFORE CREATE-NODE FIND-NODE.
    609 *GRAPH-TYPE* is referenced by CREATE-NODE-STRUCTURE.
    610 <cl> (xref:print-caller-trees :root-nodes '(display-graph))
    611 
    612 Rooted calling trees:
    613   DISPLAY-GRAPH
    614      CREATE-POSITION-INFO
    615         CALCULATE-POSITION-INFO
    616            CALCULATE-POSITION
    617               NODE-POSITION-ALREADY-SET-FLAG
    618               NODE-LEVEL-ALREADY-SET-FLAG
    619               CALCULATE-POSITION-IN-LEVEL
    620                  NODE-CHILDREN
    621                  NODE-LEVEL
    622                  CALCULATE-POSITION
    623                  NEW-CALCULATE-BREADTH
    624                     NODE-CHILDREN
    625                     BREADTH
    626                        OPPOSITE-DIMENSION
    627                           NODE-HEIGHT
    628                           NODE-WIDTH
    629                     NEW-CALCULATE-BREADTH
    630                     NODE-PARENTS
    631                  OPPOSITE-DIMENSION
    632                     NODE-HEIGHT
    633                     NODE-WIDTH
    634                  OPPOSITE-POSITION
    635                     NODE-Y
    636                     NODE-X
    637         NODE-LEVEL
    638         CALCULATE-LEVEL-POSITION
    639            NODE-LEVEL
    640            NODE-POSITION
    641               NODE-X
    642               NODE-Y
    643            DIMENSION
    644               NODE-WIDTH
    645               NODE-HEIGHT
    646         CALCULATE-LEVEL-POSITION-BEFORE
    647            NODE-LEVEL
    648            NODE-POSITION
    649               NODE-X
    650               NODE-Y
    651            NODE-WIDTH
    652            NODE-HEIGHT
    653            DIMENSION
    654               NODE-WIDTH
    655               NODE-HEIGHT
    656 |#
    657 
    658 ;;; ****************************************************************
    659 ;;; List Callers ***************************************************
    660 ;;; ****************************************************************
    661 
    662 (defpackage :pxref
    663   (:use :common-lisp)
    664   (:export #:list-callers 
    665 	   #:list-users 
    666 	   #:list-readers 
    667 	   #:list-setters
    668 	   #:what-files-call
    669 	   #:who-calls 
    670 	   #:list-callees 
    671 	   #:source-file 
    672 	   #:clear-tables
    673 	   #:define-pattern-substitution 
    674 	   #:define-caller-pattern 
    675 	   #:define-variable-pattern 
    676 	   #:define-caller-pattern-synonyms
    677 	   #:clear-patterns
    678 	   #:*last-form* 
    679 	   #:*xref-verbose* 
    680 	   #:*handle-package-forms* 
    681 	   #:*handle-function-forms*
    682 	   #:*handle-macro-forms*
    683 	   #:*types-to-ignore*
    684 	   #:*last-caller-tree* 
    685 	   #:*default-graphing-mode* 
    686 	   #:*indent-amount*
    687 	   #:xref-file 
    688 	   #:xref-files
    689 	   #:write-callers-database-to-file
    690 	   #:display-database
    691 	   #:print-caller-trees 
    692 	   #:make-caller-tree 
    693 	   #:print-indented-tree 
    694 	   #:determine-file-dependencies 
    695 	   #:print-file-dependencies
    696 	   #:psgraph-xref
    697 	   ))
    698 
    699 (in-package "PXREF")
    700 
    701 ;;; Warn user if they're loading the source instead of compiling it first.
    702 ;(eval-when (compile load eval)
    703 ;  (defvar compiled-p nil))
    704 ;(eval-when (compile load)
    705 ;  (setq compiled-p t))
    706 ;(eval-when (load eval)
    707 ;  (unless compiled-p
    708 ;    (warn "This file should be compiled before loading for best results.")))
    709 (eval-when (eval)
    710    (warn "This file should be compiled before loading for best results."))
    711 
    712 
    713 ;;; ********************************
    714 ;;; Primitives *********************
    715 ;;; ********************************
    716 (defun lookup (symbol environment)
    717   (dolist (frame environment)
    718     (when (member symbol frame)
    719       (return symbol))))
    720 
    721 (defun car-eq (list item)
    722   (and (consp list)
    723        (eq (car list) item)))
    724 
    725 ;;; ********************************
    726 ;;; Callers Database ***************
    727 ;;; ********************************
    728 (defvar *file-callers-database* (make-hash-table :test #'equal)
    729   "Contains name and list of file callers (files which call) for that name.")
    730 (defvar *callers-database* (make-hash-table :test #'equal)
    731   "Contains name and list of callers (function invocation) for that name.")
    732 (defvar *readers-database* (make-hash-table :test #'equal)
    733   "Contains name and list of readers (variable use) for that name.")
    734 (defvar *setters-database* (make-hash-table :test #'equal)
    735   "Contains name and list of setters (variable mutation) for that name.")
    736 (defvar *callees-database* (make-hash-table :test #'equal)
    737   "Contains name and list of functions and variables it calls.")
    738 (defun callers-list (name &optional (database :callers))
    739   (case database
    740     (:file    (gethash name *file-callers-database*))
    741     (:callees (gethash name *callees-database*))
    742     (:callers (gethash name *callers-database*))
    743     (:readers (gethash name *readers-database*))
    744     (:setters (gethash name *setters-database*))))
    745 (defsetf callers-list (name &optional (database :callers)) (caller)
    746   `(setf (gethash ,name (case ,database
    747 			  (:file    *file-callers-database*)
    748 			  (:callees *callees-database*)
    749 			  (:callers *callers-database*)
    750 			  (:readers *readers-database*)
    751 			  (:setters *setters-database*)))
    752 	 ,caller))
    753 
    754 (defun list-callers (symbol)
    755   "Lists all functions which call SYMBOL as a function (function invocation)."
    756   (callers-list symbol :callers))
    757 (defun list-readers (symbol)
    758   "Lists all functions which refer to SYMBOL as a variable 
    759    (variable reference)."
    760   (callers-list symbol :readers))
    761 (defun list-setters (symbol)
    762   "Lists all functions which bind/set SYMBOL as a variable 
    763    (variable mutation)."
    764   (callers-list symbol :setters))
    765 (defun list-users (symbol)
    766   "Lists all functions which use SYMBOL as a variable or function."
    767   (values (list-callers symbol)
    768 	  (list-readers symbol)
    769 	  (list-setters symbol)))
    770 (defun who-calls (symbol &optional how)
    771   "Lists callers of symbol. HOW may be :function, :reader, :setter,
    772    or :variable."
    773   ;; would be nice to have :macro and distinguish variable
    774   ;; binding from assignment. (i.e., variable binding, assignment, and use)
    775   (case how
    776     (:function (list-callers symbol))
    777     (:reader   (list-readers symbol))
    778     (:setter   (list-setters symbol))
    779     (:variable (append (list-readers symbol) 
    780 		       (list-setters symbol)))
    781     (otherwise (append (list-callers symbol)
    782 		       (list-readers symbol)
    783 		       (list-setters symbol)))))
    784 (defun what-files-call (symbol)
    785   "Lists names of files that contain uses of SYMBOL 
    786    as a function, variable, or constant."
    787   (callers-list symbol :file))
    788 (defun list-callees (symbol)
    789   "Lists names of functions and variables called by SYMBOL."
    790   (callers-list symbol :callees))
    791 
    792 (defvar *source-file* (make-hash-table :test #'equal)
    793   "Contains function name and source file for that name.")
    794 (defun source-file (symbol)
    795   "Lists the names of files in which SYMBOL is defined/used."
    796   (gethash symbol *source-file*))
    797 (defsetf source-file (name) (value)
    798   `(setf (gethash ,name *source-file*) ,value))
    799 
    800 (defun clear-tables ()
    801   (clrhash *file-callers-database*)
    802   (clrhash *callers-database*)
    803   (clrhash *callees-database*)
    804   (clrhash *readers-database*)
    805   (clrhash *setters-database*)
    806   (clrhash *source-file*))
    807 
    808 
    809 ;;; ********************************
    810 ;;; Pattern Database ***************
    811 ;;; ********************************
    812 ;;; Pattern Types
    813 (defvar *pattern-caller-type* (make-hash-table :test #'equal))
    814 (defun pattern-caller-type (name)
    815   (gethash name *pattern-caller-type*))
    816 (defsetf pattern-caller-type (name) (value)
    817   `(setf (gethash ,name *pattern-caller-type*) ,value))
    818 
    819 ;;; Pattern Substitutions
    820 (defvar *pattern-substitution-table* (make-hash-table :test #'equal)
    821   "Stores general patterns for function destructuring.")
    822 (defun lookup-pattern-substitution (name)
    823   (gethash name *pattern-substitution-table*))
    824 (defmacro define-pattern-substitution (name pattern)
    825   "Defines NAME to be equivalent to the specified pattern. Useful for
    826    making patterns more readable. For example, the LAMBDA-LIST is 
    827    defined as a pattern substitution, making the definition of the
    828    DEFUN caller-pattern simpler."
    829   `(setf (gethash ',name *pattern-substitution-table*)
    830 	 ',pattern))
    831 
    832 ;;; Function/Macro caller patterns: 
    833 ;;; The car of the form is skipped, so we don't need to specify
    834 ;;; (:eq function-name) like we would for a substitution.
    835 ;;;
    836 ;;; Patterns must be defined in the XREF package because the pattern
    837 ;;; language is tested by comparing symbols (using #'equal) and not
    838 ;;; their printreps. This is fine for the lisp grammer, because the XREF
    839 ;;; package depends on the LISP package, so a symbol like 'xref::cons is
    840 ;;; translated automatically into 'lisp::cons. However, since
    841 ;;; (equal 'foo::bar 'baz::bar) returns nil unless both 'foo::bar and
    842 ;;; 'baz::bar are inherited from the same package (e.g., LISP), 
    843 ;;; if package handling is turned on the user must specify package 
    844 ;;; names in the caller pattern definitions for functions that occur
    845 ;;; in packages other than LISP, otherwise the symbols will not match.
    846 ;;; 
    847 ;;; Perhaps we should enforce the definition of caller patterns in the
    848 ;;; XREF package by wrapping the body of define-caller-pattern in
    849 ;;; the XREF package:
    850 ;;;    (defmacro define-caller-pattern (name value &optional caller-type)
    851 ;;;      (let ((old-package *package*))
    852 ;;;        (setf *package* (find-package "XREF"))
    853 ;;;        (prog1
    854 ;;;    	     `(progn
    855 ;;;    	        (when ',caller-type
    856 ;;;         	     (setf (pattern-caller-type ',name) ',caller-type))
    857 ;;;    	        (when ',value 
    858 ;;;    	          (setf (gethash ',name *caller-pattern-table*)
    859 ;;;    		        ',value)))
    860 ;;;          (setf *package* old-package)))) 
    861 ;;; Either that, or for the purpose of pattern testing we should compare
    862 ;;; printreps. [The latter makes the primitive patterns like VAR
    863 ;;; reserved words.]
    864 (defvar *caller-pattern-table* (make-hash-table :test #'equal)
    865   "Stores patterns for function destructuring.")
    866 (defun lookup-caller-pattern (name)
    867   (gethash name *caller-pattern-table*))
    868 (defmacro define-caller-pattern (name pattern &optional caller-type)
    869   "Defines NAME as a function/macro call with argument structure
    870    described by PATTERN. CALLER-TYPE, if specified, assigns a type to
    871    the pattern, which may be used to exclude references to NAME while
    872    viewing the database. For example, all the Common Lisp definitions
    873    have a caller-type of :lisp or :lisp2, so that you can exclude 
    874    references to common lisp functions from the calling tree."
    875   `(progn
    876      (when ',caller-type
    877        (setf (pattern-caller-type ',name) ',caller-type))
    878      (when ',pattern 
    879        (setf (gethash ',name *caller-pattern-table*)
    880 	     ',pattern))))
    881 
    882 ;;; For defining variables
    883 (defmacro define-variable-pattern (name &optional caller-type)
    884   "Defines NAME as a variable reference of type CALLER-TYPE. This is
    885    mainly used to establish the caller-type of the variable."
    886   `(progn
    887      (when ',caller-type
    888        (setf (pattern-caller-type ',name) ',caller-type))))
    889 
    890 ;;; For defining synonyms. Means much less space taken up by the patterns.
    891 (defmacro define-caller-pattern-synonyms (source destinations)
    892   "For defining function caller pattern syntax synonyms. For each name
    893    in DESTINATIONS, defines its pattern as a copy of the definition of SOURCE.
    894    Allows a large number of identical patterns to be defined simultaneously.
    895    Must occur after the SOURCE has been defined."
    896   `(let ((source-type (pattern-caller-type ',source))
    897 	 (source-pattern (gethash ',source *caller-pattern-table*)))
    898      (when source-type
    899        (dolist (dest ',destinations)
    900 	 (setf (pattern-caller-type dest) source-type)))
    901      (when source-pattern
    902        (dolist (dest ',destinations)
    903 	 (setf (gethash dest *caller-pattern-table*)
    904 	       source-pattern)))))
    905 
    906 (defun clear-patterns ()
    907   (clrhash *pattern-substitution-table*)
    908   (clrhash *caller-pattern-table*)
    909   (clrhash *pattern-caller-type*))
    910 
    911 ;;; ********************************
    912 ;;; Cross Reference Files **********
    913 ;;; ********************************
    914 (defvar *last-form* ()
    915   "The last form read from the file. Useful for figuring out what went wrong
    916    when xref-file drops into the debugger.")
    917 
    918 (defvar *xref-verbose* t
    919   "When T, xref-file(s) prints out the names of the files it looks at,
    920    progress dots, and the number of forms read.")
    921 
    922 ;;; This needs to first clear the tables?
    923 (defun xref-files (&rest files)
    924   "Grovels over the lisp code located in source file FILES, using xref-file."
    925   ;; If the arg is a list, use it.
    926   (when (listp (car files)) (setq files (car files)))
    927   (dolist (file files)
    928     (xref-file file nil))
    929   (values))
    930 
    931 (defvar *handle-package-forms* nil	;'(lisp::in-package)
    932   "When non-NIL, and XREF-FILE sees a package-setting form like IN-PACKAGE,
    933    sets the current package to the specified package by evaluating the
    934    form. When done with the file, xref-file resets the package to its 
    935    original value. In some of the displaying functions, when this variable
    936    is non-NIL one may specify that all symbols from a particular set of
    937    packages be ignored. This is only useful if the files use different
    938    packages with conflicting names.")
    939 
    940 (defvar *normal-readtable* (copy-readtable nil)
    941   "Normal, unadulterated CL readtable.")
    942 
    943 (defun xref-file (filename &optional (clear-tables t) (verbose *xref-verbose*))
    944   "Cross references the function and variable calls in FILENAME by
    945    walking over the source code located in the file. Defaults type of
    946    filename to \".lisp\". Chomps on the code using record-callers and
    947    record-callers*. If CLEAR-TABLES is T (the default), it clears the callers
    948    database before processing the file. Specify CLEAR-TABLES as nil to
    949    append to the database. If VERBOSE is T (the default), prints out the
    950    name of the file, one progress dot for each form processed, and the
    951    total number of forms."
    952   ;; Default type to "lisp"
    953   (when (and (null (pathname-type filename))
    954 	     (not  (probe-file filename)))
    955     (cond ((stringp filename)
    956 	   (setf filename (concatenate 'string filename ".lisp")))
    957 	  ((pathnamep filename)
    958 	   (setf filename (merge-pathnames filename
    959 					   (make-pathname :type "lisp"))))))
    960   (when clear-tables (clear-tables))
    961   (let ((count 0)
    962 	(old-package *package*)
    963 	(*readtable* *normal-readtable*))
    964     (when verbose
    965       (format t "~&Cross-referencing file ~A.~&" filename))
    966     (with-open-file (stream filename :direction :input)
    967       (do ((form (read stream nil :eof) (read stream nil :eof)))
    968 	  ((eq form :eof))
    969 	(incf count)
    970 	(when verbose
    971 	  (format *standard-output* ".")
    972 	  (force-output *standard-output*))
    973 	(setq *last-form* form)
    974 	(record-callers filename form)
    975 	;; Package Magic.
    976 	(when (and *handle-package-forms*
    977 		   (consp form)
    978 		   (member (car form) *handle-package-forms*))
    979 	  (eval form))))
    980     (when verbose 
    981       (format t "~&~D forms processed." count))
    982     (setq *package* old-package)
    983     (values)))
    984 
    985 (defvar *handle-function-forms* t
    986   "When T, XREF-FILE tries to be smart about forms which occur in
    987    a function position, such as lambdas and arbitrary Lisp forms.
    988    If so, it recursively calls record-callers with pattern 'FORM.
    989    If the form is a lambda, makes the caller a caller of :unnamed-lambda.") 
    990 
    991 (defvar *handle-macro-forms* t
    992   "When T, if the file was loaded before being processed by XREF, and the
    993    car of a form is a macro, it notes that the parent calls the macro,
    994    and then calls macroexpand-1 on the form.") 
    995 
    996 (defvar *callees-database-includes-variables* nil)
    997 
    998 (defun record-callers (filename form 
    999 				&optional pattern parent (environment nil)
   1000 				funcall)
   1001   "RECORD-CALLERS is the main routine used to walk down the code. It matches
   1002    the PATTERN against the FORM, possibly adding statements to the database.
   1003    PARENT is the name defined by the current outermost definition; it is
   1004    the caller of the forms in the body (e.g., FORM). ENVIRONMENT is used
   1005    to keep track of the scoping of variables. FUNCALL deals with the type
   1006    of variable assignment and hence how the environment should be modified.
   1007    RECORD-CALLERS handles atomic patterns and simple list-structure patterns.
   1008    For complex list-structure pattern destructuring, it calls RECORD-CALLERS*."
   1009 ;  (when form)
   1010   (unless pattern (setq pattern 'FORM))
   1011   (cond ((symbolp pattern)
   1012 	 (case pattern
   1013 	   (:IGNORE
   1014 	    ;; Ignores the rest of the form.
   1015 	    (values t parent environment))
   1016 	   (NAME    
   1017 	    ;; This is the name of a new definition.
   1018 	    (push filename (source-file form))
   1019 	    (values t form   environment))
   1020 	   ((FUNCTION MACRO)
   1021 	    ;; This is the name of a call.
   1022 	    (cond ((and *handle-function-forms* (consp form))
   1023 		   ;; If we're a cons and special handling is on,
   1024 		   (when (eq (car form) 'lambda)
   1025 		     (pushnew filename (callers-list :unnamed-lambda :file))
   1026 		     (when parent
   1027 		       (pushnew parent (callers-list :unnamed-lambda
   1028 						     :callers))
   1029 		       (pushnew :unnamed-lambda (callers-list parent
   1030 							      :callees))))
   1031 		   (record-callers filename form 'form parent environment))
   1032 		  (t 
   1033 		   ;; If we're just a regular function name call.
   1034 		   (pushnew filename (callers-list form :file))
   1035 		   (when parent
   1036 		     (pushnew parent (callers-list form :callers))
   1037 		     (pushnew form (callers-list parent :callees)))
   1038 		   (values t parent environment)))) 
   1039 	   (VAR     
   1040 	    ;; This is the name of a new variable definition.
   1041 	    ;; Includes arglist parameters.
   1042 	    (when (and (symbolp form) (not (keywordp form))
   1043 		       (not (member form lambda-list-keywords)))
   1044 	      (pushnew form (car environment))
   1045 	      (pushnew filename (callers-list form :file))
   1046 	      (when parent 
   1047 ;		  (pushnew form (callers-list parent :callees))
   1048 		(pushnew parent (callers-list form :setters)))
   1049 	      (values t parent environment)))
   1050 	   (VARIABLE
   1051 	    ;; VAR reference
   1052 	    (pushnew filename (callers-list form :file))
   1053 	    (when (and parent (not (lookup form environment)))
   1054 	      (pushnew parent (callers-list form :readers))
   1055 	      (when *callees-database-includes-variables*
   1056 		(pushnew form (callers-list parent :callees))))
   1057 	    (values t parent environment))
   1058 	   (FORM    
   1059 	    ;; A random form (var or funcall).
   1060 	    (cond ((consp form)
   1061 		   ;; Get new pattern from TAG.
   1062 		   (let ((new-pattern (lookup-caller-pattern (car form))))
   1063 		     (pushnew filename (callers-list (car form) :file))
   1064 		     (when parent
   1065 		       (pushnew parent (callers-list (car form) :callers))
   1066 		       (pushnew (car form) (callers-list parent :callees)))
   1067 		     (cond ((and new-pattern (cdr form))
   1068 			    ;; Special Pattern and there's stuff left
   1069 			    ;; to be processed. Note that we check if
   1070 			    ;; a pattern is defined for the form before
   1071 			    ;; we check to see if we can macroexpand it.
   1072 			    (record-callers filename (cdr form) new-pattern
   1073 					    parent environment :funcall))
   1074 			   ((and *handle-macro-forms*
   1075 				 (symbolp (car form)) ; pnorvig 9/9/93
   1076 				 (macro-function (car form)))
   1077 			    ;; The car of the form is a macro and
   1078 			    ;; macro processing is turned on. Macroexpand-1
   1079 			    ;; the form and try again.
   1080 			    (record-callers filename 
   1081 					    (macroexpand-1 form)
   1082 					    'form parent environment 
   1083 					    :funcall))
   1084 			   ((null (cdr form))
   1085 			    ;; No more left to be processed. Note that
   1086 			    ;; this must occur after the macros clause,
   1087 			    ;; since macros can expand into more code.
   1088 			    (values t parent environment))
   1089 			   (t
   1090 			    ;; Random Form. We assume it is a function call.
   1091 			    (record-callers filename (cdr form)
   1092 					    '((:star FORM))
   1093 					    parent environment :funcall)))))
   1094 		  (t 
   1095 		   (when (and (not (lookup form environment))
   1096 			      (not (numberp form))
   1097 			      ;; the following line should probably be 
   1098 			      ;; commented out?
   1099 			      (not (keywordp form))
   1100 			      (not (stringp form))
   1101 			      (not (eq form t))
   1102 			      (not (eq form nil)))
   1103 		     (pushnew filename (callers-list form :file))
   1104 		     ;; ??? :callers
   1105 		     (when parent
   1106 		       (pushnew parent (callers-list form :readers))
   1107 		       (when *callees-database-includes-variables*
   1108 			 (pushnew form (callers-list parent :callees)))))
   1109 		   (values t parent environment))))
   1110 	   (otherwise 
   1111 	    ;; Pattern Substitution
   1112 	    (let ((new-pattern (lookup-pattern-substitution pattern)))
   1113 	      (if new-pattern
   1114 		  (record-callers filename form new-pattern 
   1115 				  parent environment)
   1116 		  (when (eq pattern form)
   1117 		    (values t parent environment)))))))
   1118 	((consp pattern)
   1119 	 (case (car pattern)
   1120 	   (:eq    (when (eq (second pattern) form)
   1121 		     (values t parent environment)))
   1122 	   (:test  (when (funcall (eval (second pattern)) form)
   1123 		     (values t parent environment)))
   1124 	   (:typep (when (typep form (second pattern))
   1125 		     (values t parent environment)))
   1126 	   (:or    (dolist (subpat (rest pattern))
   1127 		     (multiple-value-bind (processed parent environment)
   1128 			 (record-callers filename form subpat
   1129 					 parent environment)
   1130 		       (when processed
   1131 			 (return (values processed parent environment))))))
   1132 	   (:rest			; (:star :plus :optional :rest)
   1133 	    (record-callers filename form (second pattern)
   1134 			    parent environment))
   1135 	   (otherwise
   1136 	    (multiple-value-bind (d p env)
   1137 		(record-callers* filename form pattern 
   1138 				 parent (cons nil environment))
   1139 	      (values d p (if funcall environment env))))))))
   1140 
   1141 (defun record-callers* (filename form pattern parent environment
   1142 				 &optional continuation 
   1143 				 in-optionals in-keywords)
   1144   "RECORD-CALLERS* handles complex list-structure patterns, such as
   1145    ordered lists of subpatterns, patterns involving :star, :plus,
   1146    &optional, &key, &rest, and so on. CONTINUATION is a stack of
   1147    unprocessed patterns, IN-OPTIONALS and IN-KEYWORDS are corresponding
   1148    stacks which determine whether &rest or &key has been seen yet in
   1149    the current pattern."   
   1150   ;; form must be a cons or nil.
   1151 ;  (when form)
   1152   (if (null pattern)
   1153       (if (null continuation)
   1154 	  (values t parent environment)
   1155 	  (record-callers* filename form (car continuation) parent environment
   1156 			   (cdr continuation) 
   1157 			   (cdr in-optionals)
   1158 			   (cdr in-keywords)))
   1159       (let ((pattern-elt (car pattern)))
   1160 	(cond ((car-eq pattern-elt :optional)
   1161 	       (if (null form) 
   1162 		   (values t parent environment)
   1163 		   (multiple-value-bind (processed par env)
   1164 		       (record-callers* filename form (cdr pattern-elt)
   1165 					parent environment
   1166 					(cons (cdr pattern) continuation)
   1167 					(cons (car in-optionals) in-optionals)
   1168 					(cons (car in-keywords) in-keywords))
   1169 		     (if processed
   1170 			 (values processed par env)
   1171 			 (record-callers* filename form (cdr pattern)
   1172 					  parent environment continuation
   1173 					  in-optionals in-keywords)))))
   1174 	      ((car-eq pattern-elt :star)
   1175 	       (if (null form)
   1176 		   (values t parent environment)
   1177 		   (multiple-value-bind (processed par env)
   1178 		       (record-callers* filename form (cdr pattern-elt)
   1179 					parent environment
   1180 					(cons pattern continuation)
   1181 					(cons (car in-optionals) in-optionals)
   1182 					(cons (car in-keywords) in-keywords))
   1183 		     (if processed
   1184 			 (values processed par env)
   1185 			 (record-callers* filename form (cdr pattern)
   1186 					  parent environment continuation
   1187 					  in-optionals in-keywords)))))
   1188 	      ((car-eq pattern-elt :plus)
   1189 	       (record-callers* filename form (cdr pattern-elt)
   1190 				parent environment
   1191 				(cons (cons (cons :star (cdr pattern-elt))
   1192 					    (cdr pattern))
   1193 				      continuation)
   1194 				(cons (car in-optionals) in-optionals)
   1195 				(cons (car in-keywords) in-keywords)))
   1196 	      ((car-eq pattern-elt :rest)
   1197 	       (record-callers filename form pattern-elt parent environment))
   1198 	      ((eq pattern-elt '&optional)
   1199 	       (record-callers* filename form (cdr pattern)
   1200 				parent environment continuation
   1201 				(cons t in-optionals)
   1202 				(cons (car in-keywords) in-keywords)))
   1203 	      ((eq pattern-elt '&rest)
   1204 	       (record-callers filename form (second pattern)
   1205 			       parent environment))
   1206 	      ((eq pattern-elt '&key)
   1207 	       (record-callers* filename form (cdr pattern)
   1208 				parent environment continuation
   1209 				(cons (car in-optionals) in-optionals)
   1210 				(cons t in-keywords)))
   1211 	      ((null form)
   1212 	       (when (or (car in-keywords) (car in-optionals))
   1213 		 (values t parent environment)))
   1214 	      ((consp form)
   1215 	       (multiple-value-bind (processed parent environment)
   1216 		   (record-callers filename (if (car in-keywords)
   1217 						(cadr form)
   1218 						(car form))
   1219 				   pattern-elt
   1220 				   parent environment)
   1221 		 (cond (processed
   1222 			(record-callers* filename (if (car in-keywords)
   1223 						      (cddr form)
   1224 						      (cdr form))
   1225 					 (cdr pattern)
   1226 					 parent environment
   1227 					 continuation
   1228 					 in-optionals in-keywords))
   1229 		       ((or (car in-keywords)
   1230 			    (car in-optionals))
   1231 			(values t parent environment)))))))))
   1232 
   1233 
   1234 ;;; ********************************
   1235 ;;; Misc Utilities *****************
   1236 ;;; ********************************
   1237 (defvar *types-to-ignore*
   1238   '(:lisp			; CLtL 1st Edition
   1239     :lisp2			; CLtL 2nd Edition additional patterns
   1240     )
   1241   "Default set of caller types (as specified in the patterns) to ignore
   1242    in the database handling functions. :lisp is CLtL 1st edition,
   1243    :lisp2 is additional patterns from CLtL 2nd edition.")
   1244 
   1245 (defun display-database (&optional (database :callers) 
   1246 				   (types-to-ignore *types-to-ignore*))
   1247   "Prints out the name of each symbol and all its callers. Specify database
   1248    :callers (the default) to get function call references, :fill to the get
   1249    files in which the symbol is called, :readers to get variable references,
   1250    and :setters to get variable binding and assignments. Ignores functions
   1251    of types listed in types-to-ignore."
   1252   (maphash #'(lambda (name callers)
   1253 	       (unless (or (member (pattern-caller-type name)
   1254 				   types-to-ignore)
   1255 			   ;; When we're doing fancy package crap,
   1256 			   ;; allow us to ignore symbols based on their
   1257 			   ;; packages.
   1258 			   (when *handle-package-forms*
   1259 			     (member (symbol-package name)
   1260 				     types-to-ignore
   1261 				     :key #'find-package)))
   1262 		 (format t "~&~S is referenced by~{ ~S~}."
   1263 			 name callers)))
   1264 	   (ecase database
   1265 	     (:file    *file-callers-database*)
   1266 	     (:callers *callers-database*)
   1267 	     (:readers *readers-database*)
   1268 	     (:setters *setters-database*))))
   1269 
   1270 (defun write-callers-database-to-file (filename)
   1271   "Saves the contents of the current callers database to a file. This
   1272    file can be loaded to restore the previous contents of the
   1273    database. (For large systems it can take a long time to crunch
   1274    through the code, so this can save some time.)"
   1275   (with-open-file (stream filename :direction :output)
   1276     (format stream "~&(clear-tables)")
   1277     (maphash #'(lambda (x y) 
   1278 		 (format stream "~&(setf (source-file '~S) '~S)"
   1279 			 x y))
   1280 	     *source-file*)
   1281     (maphash #'(lambda (x y) 
   1282 		 (format stream "~&(setf (callers-list '~S :file) '~S)"
   1283 			 x y))
   1284 	     *file-callers-database*)
   1285     (maphash #'(lambda (x y) 
   1286 		 (format stream "~&(setf (callers-list '~S :callers) '~S)"
   1287 			 x y))
   1288 	     *callers-database*)
   1289     (maphash #'(lambda (x y) 
   1290 		 (format stream "~&(setf (callers-list '~S :callees) '~S)"
   1291 			 x y))
   1292 	     *callees-database*)
   1293     (maphash #'(lambda (x y) 
   1294 		 (format stream "~&(setf (callers-list '~S :readers) '~S)"
   1295 			 x y))
   1296 	     *readers-database*)
   1297     (maphash #'(lambda (x y) 
   1298 		 (format stream "~&(setf (callers-list '~S :setters) '~S)"
   1299 			 x y))
   1300 	     *setters-database*)))
   1301 
   1302 
   1303 ;;; ********************************
   1304 ;;; Print Caller Trees *************
   1305 ;;; ********************************
   1306 ;;; The following function is useful for reversing a caller table into
   1307 ;;; a callee table. Possibly later we'll extend xref to create two 
   1308 ;;; such database hash tables. Needs to include vars as well.
   1309 (defun invert-hash-table (table &optional (types-to-ignore *types-to-ignore*))
   1310   "Makes a copy of the hash table in which (name value*) pairs
   1311    are inverted to (value name*) pairs."
   1312   (let ((target (make-hash-table :test #'equal)))
   1313     (maphash #'(lambda (key values)
   1314 		 (dolist (value values)
   1315 		   (unless (member (pattern-caller-type key) 
   1316 				   types-to-ignore)
   1317 		     (pushnew key (gethash value target)))))
   1318 	     table)
   1319     target))
   1320 
   1321 ;;; Resolve file references for automatic creation of a defsystem file.
   1322 (defun determine-file-dependencies (&optional (database *callers-database*))
   1323   "Makes a hash table of file dependencies for the references listed in
   1324    DATABASE. This function may be useful for automatically resolving
   1325    file references for automatic creation of a system definition (defsystem)."
   1326   (let ((file-ref-ht  (make-hash-table :test #'equal)))
   1327     (maphash #'(lambda (key values)
   1328 		 (let ((key-file (source-file key)))
   1329 		   (when key
   1330 		     (dolist (value values)
   1331 		       (let ((value-file (source-file value)))
   1332 			 (when value-file
   1333 			   (dolist (s key-file)
   1334 			     (dolist (d value-file)
   1335 			       (pushnew d (gethash s file-ref-ht))))))))))
   1336 	     database)
   1337     file-ref-ht))
   1338 
   1339 (defun print-file-dependencies (&optional (database *callers-database*))
   1340   "Prints a list of file dependencies for the references listed in DATABASE.
   1341    This function may be useful for automatically computing file loading
   1342    constraints for a system definition tool."
   1343   (maphash #'(lambda (key value) (format t "~&~S --> ~S" key value))
   1344 	   (determine-file-dependencies database)))
   1345 
   1346 ;;; The following functions demonstrate a possible way to interface
   1347 ;;; xref to a graphical browser such as psgraph to mimic the capabilities
   1348 ;;; of Masterscope's graphical browser. 
   1349 
   1350 (defvar *last-caller-tree* nil)
   1351 
   1352 (defvar *default-graphing-mode* :call-graph
   1353   "Specifies whether we graph up or down. If :call-graph, the children
   1354    of a node are the functions it calls. If :caller-graph, the children
   1355    of a node are the functions that call it.") 
   1356 
   1357 (defun gather-tree (parents &optional already-seen 
   1358 			    (mode *default-graphing-mode*)
   1359 			    (types-to-ignore *types-to-ignore*) compact)
   1360   "Extends the tree, copying it into list structure, until it repeats
   1361    a reference (hits a cycle)."
   1362   (let ((*already-seen* nil)
   1363 	(database (case mode
   1364 		    (:call-graph   *callees-database*)
   1365 		    (:caller-graph *callers-database*))))
   1366     (declare (special *already-seen*))
   1367     (labels 
   1368 	((amass-tree
   1369 	  (parents &optional already-seen)
   1370 	  (let (result this-item)
   1371 	    (dolist (parent parents)
   1372 	      (unless (member (pattern-caller-type parent)
   1373 			      types-to-ignore)
   1374 		(pushnew parent *already-seen*)
   1375 		(if (member parent already-seen)
   1376 		    (setq this-item nil) ; :ignore
   1377 		    (if compact 
   1378 			(multiple-value-setq (this-item already-seen)
   1379 			    (amass-tree (gethash parent database)
   1380 					(cons parent already-seen)))
   1381 			(setq this-item
   1382 			      (amass-tree (gethash parent database)
   1383 					  (cons parent already-seen)))))
   1384 		(setq parent (format nil "~S" parent))
   1385 		(when (consp parent) (setq parent (cons :xref-list parent)))
   1386 		(unless (eq this-item :ignore)
   1387 		  (push (if this-item
   1388 			    (list parent this-item)
   1389 			    parent) 
   1390 			result))))
   1391 	    (values result		;(reverse result)
   1392 		    already-seen))))
   1393       (values (amass-tree parents already-seen)
   1394 	      *already-seen*))))
   1395 
   1396 (defun find-roots-and-cycles (&optional (mode *default-graphing-mode*)
   1397 					(types-to-ignore *types-to-ignore*))
   1398   "Returns a list of uncalled callers (roots) and called callers (potential
   1399    cycles)."
   1400   (let ((uncalled-callers nil)
   1401 	(called-callers nil)
   1402 	(database (ecase mode
   1403 		    (:call-graph   *callers-database*)
   1404 		    (:caller-graph *callees-database*)))
   1405 	(other-database (ecase mode
   1406 			  (:call-graph   *callees-database*)
   1407 			  (:caller-graph *callers-database*))))
   1408     (maphash #'(lambda (name value)
   1409 		 (declare (ignore value))
   1410 		 (unless (member (pattern-caller-type name) 
   1411 				 types-to-ignore)
   1412 		   (if (gethash name database)
   1413 		       (push name called-callers)
   1414 		       (push name uncalled-callers))))
   1415 	     other-database)
   1416     (values uncalled-callers called-callers)))
   1417 
   1418 (defun make-caller-tree (&optional (mode *default-graphing-mode*)
   1419 				   (types-to-ignore *types-to-ignore*) compact)
   1420   "Outputs list structure of a tree which roughly represents the possibly
   1421    cyclical structure of the caller database.
   1422    If mode is :call-graph, the children of a node are the functions it calls.
   1423    If mode is :caller-graph, the children of a node are the functions that
   1424    call it.
   1425    If compact is T, tries to eliminate the already-seen nodes, so that
   1426    the graph for a node is printed at most once. Otherwise it will duplicate
   1427    the node's tree (except for cycles). This is usefull because the call tree
   1428    is actually a directed graph, so we can either duplicate references or
   1429    display only the first one."
   1430   ;; Would be nice to print out line numbers and whenever we skip a duplicated
   1431   ;; reference, print the line number of the full reference after the node.
   1432   (multiple-value-bind (uncalled-callers called-callers)
   1433       (find-roots-and-cycles mode types-to-ignore)
   1434     (multiple-value-bind (trees already-seen)
   1435 	(gather-tree uncalled-callers nil mode types-to-ignore compact)
   1436       (setq *last-caller-tree* trees)
   1437       (let ((more-trees (gather-tree (set-difference called-callers
   1438 						     already-seen)
   1439 				     already-seen 
   1440 				     mode types-to-ignore compact)))
   1441 	(values trees more-trees)))))
   1442 
   1443 (defvar *indent-amount* 3
   1444   "Number of spaces to indent successive levels in PRINT-INDENTED-TREE.")
   1445 
   1446 (defun print-indented-tree (trees &optional (indent 0))
   1447   "Simple code to print out a list-structure tree (such as those created
   1448    by make-caller-tree) as indented text."
   1449   (when trees
   1450     (dolist (tree trees)
   1451       (cond ((and (listp tree) (eq (car tree) :xref-list))
   1452 	     (format t "~&~VT~A" indent (cdr tree)))
   1453 	    ((listp tree)
   1454 	     (format t "~&~VT~A" indent (car tree))
   1455 	     (print-indented-tree (cadr tree) (+ indent *indent-amount*)))
   1456 	    (t
   1457 	     (format t "~&~VT~A" indent tree))))))
   1458 
   1459 (defun print-caller-trees (&key (mode *default-graphing-mode*)
   1460 				(types-to-ignore *types-to-ignore*)
   1461 				compact
   1462 				root-nodes)
   1463   "Prints the calling trees (which may actually be a full graph and not
   1464    necessarily a DAG) as indented text trees using PRINT-INDENTED-TREE.
   1465    MODE is :call-graph for trees where the children of a node are the
   1466    functions called by the node, or :caller-graph for trees where the
   1467    children of a node are the functions the node calls. TYPES-TO-IGNORE
   1468    is a list of funcall types (as specified in the patterns) to ignore
   1469    in printing out the database. For example, '(:lisp) would ignore all
   1470    calls to common lisp functions. COMPACT is a flag to tell the program
   1471    to try to compact the trees a bit by not printing trees if they have
   1472    already been seen. ROOT-NODES is a list of root nodes of trees to 
   1473    display. If ROOT-NODES is nil, tries to find all root nodes in the
   1474    database."
   1475   (multiple-value-bind (rooted cycles)
   1476       (if root-nodes
   1477 	  (values (gather-tree root-nodes nil mode types-to-ignore compact))
   1478 	  (make-caller-tree mode types-to-ignore compact))
   1479     (when rooted
   1480       (format t "~&Rooted calling trees:")
   1481       (print-indented-tree rooted 2))
   1482     (when cycles
   1483       (when rooted      
   1484 	(format t "~2%"))
   1485       (format t "~&Cyclic calling trees:")
   1486       (print-indented-tree cycles 2))))
   1487 
   1488 
   1489 ;;; ********************************
   1490 ;;; Interface to PSGraph ***********
   1491 ;;; ********************************
   1492 #|
   1493 ;;; Interface to Bates' PostScript Graphing Utility
   1494 (load "/afs/cs/user/mkant/Lisp/PSGraph/psgraph")
   1495 
   1496 (defparameter *postscript-output-directory* "")
   1497 (defun psgraph-xref (&key (mode *default-graphing-mode*)
   1498 			  (output-directory *postscript-output-directory*)
   1499 			  (types-to-ignore *types-to-ignore*)
   1500 			  (compact t)
   1501 			  (shrink t)
   1502 			  root-nodes
   1503 			  insert)
   1504   ;; If root-nodes is a non-nil list, uses that list as the starting
   1505   ;; position. Otherwise tries to find all roots in the database.
   1506   (multiple-value-bind (rooted cycles)
   1507       (if root-nodes
   1508 	  (values (gather-tree root-nodes nil mode types-to-ignore compact))
   1509 	  (make-caller-tree mode types-to-ignore compact))
   1510     (psgraph-output (append rooted cycles) output-directory shrink insert)))
   1511 
   1512 (defun psgraph-output (list-of-trees directory shrink &optional insert)
   1513   (let ((psgraph:*fontsize* 9)
   1514 	(psgraph:*second-fontsize* 7)
   1515 ;	(psgraph:*boxkind* "fill")
   1516 	(psgraph:*boxgray* "0") ; .8
   1517 	(psgraph:*edgewidth* "1")
   1518 	(psgraph:*edgegray* "0"))
   1519     (labels ((stringify (thing)
   1520 		(cond ((stringp thing) (string-downcase thing))
   1521 		      ((symbolp thing) (string-downcase (symbol-name thing)))
   1522 		      ((and (listp thing) (eq (car thing) :xref-list))
   1523 		       (stringify (cdr thing)))
   1524 		      ((listp thing) (stringify (car thing)))
   1525 		      (t (string thing)))))
   1526       (dolist (item list-of-trees)
   1527 	(let* ((fname (stringify item))
   1528 	       (filename (concatenate 'string directory
   1529 				      (string-trim '(#\: #\|) fname)
   1530 				      ".ps")))
   1531 	  (format t "~&Creating PostScript file ~S." filename)
   1532 	  (with-open-file (*standard-output* filename
   1533 					     :direction :output
   1534 					     :if-does-not-exist :create
   1535 					     :if-exists :supersede)
   1536 	    ;; Note that the #'eq prints the DAG as a tree. If
   1537 	    ;; you replace it with #'equal, it will print it as
   1538 	    ;; a DAG, which I think is slightly ugly.
   1539 	    (psgraph:psgraph item
   1540 			     #'caller-tree-children #'caller-info shrink
   1541 			     insert #'eq)))))))
   1542 
   1543 (defun caller-tree-children (tree)
   1544   (when (and tree (listp tree) (not (eq (car tree) :xref-list)))
   1545     (cadr tree)))
   1546 
   1547 (defun caller-tree-node (tree)
   1548   (when tree
   1549     (cond ((and (listp tree) (eq (car tree) :xref-list))
   1550 	   (cdr tree))
   1551 	  ((listp tree)
   1552 	   (car tree))
   1553 	  (t
   1554 	   tree))))
   1555 
   1556 (defun caller-info (tree)
   1557   (let ((node (caller-tree-node tree)))
   1558     (list node)))
   1559 |#
   1560 #|
   1561 ;;; Code to print out graphical trees of CLOS class hierarchies.
   1562 (defun print-class-hierarchy (&optional (start-class 'anything) 
   1563 					(file "classes.ps"))
   1564   (let ((start (find-class start-class)))
   1565     (when start
   1566       (with-open-file (*standard-output* file :direction :output)
   1567 	(psgraph:psgraph start 
   1568 			 #'clos::class-direct-subclasses
   1569 			 #'(lambda (x) 
   1570 			     (list (format nil "~A" (clos::class-name x))))
   1571 			 t nil #'eq)))))
   1572 
   1573 |#
   1574 
   1575 
   1576 ;;; ****************************************************************
   1577 ;;; Cross Referencing Patterns for Common Lisp *********************
   1578 ;;; ****************************************************************
   1579 (clear-patterns)
   1580 
   1581 ;;; ********************************
   1582 ;;; Pattern Substitutions **********
   1583 ;;; ********************************
   1584 (define-pattern-substitution integer (:test #'integerp))
   1585 (define-pattern-substitution rational (:test #'rationalp))
   1586 (define-pattern-substitution symbol  (:test #'symbolp))
   1587 (define-pattern-substitution string  (:test #'stringp))
   1588 (define-pattern-substitution number  (:test #'numberp))
   1589 (define-pattern-substitution lambda-list
   1590   ((:star var)
   1591    (:optional (:eq &optional)
   1592 	      (:star (:or var
   1593 			  (var (:optional form (:optional var))))))
   1594    (:optional (:eq &rest) var)
   1595    (:optional (:eq &key) (:star (:or var
   1596 			       ((:or var
   1597 				     (keyword var))
   1598 				(:optional form (:optional var)))))
   1599 	      (:optional &allow-other-keys))
   1600    (:optional (:eq &aux)
   1601 	      (:star (:or var
   1602 			  (var (:optional form)))))))
   1603 (define-pattern-substitution test form)
   1604 (define-pattern-substitution body
   1605   ((:star (:or declaration documentation-string))
   1606    (:star form)))
   1607 (define-pattern-substitution documentation-string string)
   1608 (define-pattern-substitution initial-value form)
   1609 (define-pattern-substitution tag symbol)
   1610 (define-pattern-substitution declaration ((:eq declare)(:rest :ignore)))
   1611 (define-pattern-substitution destination form)
   1612 (define-pattern-substitution control-string string)
   1613 (define-pattern-substitution format-arguments 
   1614   ((:star form)))
   1615 (define-pattern-substitution fn
   1616   (:or ((:eq quote) function) 
   1617        ((:eq function) function)
   1618        function))
   1619 
   1620 ;;; ********************************
   1621 ;;; Caller Patterns ****************
   1622 ;;; ********************************
   1623 
   1624 ;;; Types Related
   1625 (define-caller-pattern coerce (form :ignore) :lisp)
   1626 (define-caller-pattern type-of (form) :lisp)
   1627 (define-caller-pattern upgraded-array-element-type (:ignore) :lisp2)
   1628 (define-caller-pattern upgraded-complex-part-type (:ignore) :lisp2)
   1629 
   1630 ;;; Lambdas and Definitions
   1631 (define-variable-pattern lambda-list-keywords :lisp)
   1632 (define-variable-pattern lambda-parameters-limit :lisp)
   1633 (define-caller-pattern lambda (lambda-list (:rest body)) :lisp)
   1634 
   1635 (define-caller-pattern defun 
   1636   (name lambda-list
   1637 	(:star (:or documentation-string declaration))
   1638 	(:star form))
   1639   :lisp)
   1640 
   1641 ;;; perhaps this should use VAR, instead of NAME
   1642 (define-caller-pattern defvar 
   1643   (var (:optional initial-value (:optional documentation-string)))
   1644   :lisp)
   1645 (define-caller-pattern defparameter
   1646   (var initial-value (:optional documentation-string))
   1647   :lisp)
   1648 (define-caller-pattern defconstant
   1649   (var initial-value (:optional documentation-string))
   1650   :lisp)
   1651 
   1652 (define-caller-pattern eval-when
   1653   (:ignore				; the situations
   1654    (:star form))
   1655   :lisp)
   1656 
   1657 ;;; Logical Values
   1658 (define-variable-pattern nil :lisp)
   1659 (define-variable-pattern t :lisp)
   1660 
   1661 ;;; Predicates
   1662 (define-caller-pattern typep (form form) :lisp)
   1663 (define-caller-pattern subtypep (form form) :lisp)
   1664 
   1665 (define-caller-pattern null (form) :lisp)
   1666 (define-caller-pattern symbolp (form) :lisp)
   1667 (define-caller-pattern atom (form) :lisp)
   1668 (define-caller-pattern consp (form) :lisp)
   1669 (define-caller-pattern listp (form) :lisp)
   1670 (define-caller-pattern numberp (form) :lisp)
   1671 (define-caller-pattern integerp (form) :lisp)
   1672 (define-caller-pattern rationalp (form) :lisp)
   1673 (define-caller-pattern floatp (form) :lisp)
   1674 (define-caller-pattern realp (form) :lisp2)
   1675 (define-caller-pattern complexp (form) :lisp)
   1676 (define-caller-pattern characterp (form) :lisp)
   1677 (define-caller-pattern stringp (form) :lisp)
   1678 (define-caller-pattern bit-vector-p (form) :lisp)
   1679 (define-caller-pattern vectorp (form) :lisp)
   1680 (define-caller-pattern simple-vector-p (form) :lisp)
   1681 (define-caller-pattern simple-string-p (form) :lisp)
   1682 (define-caller-pattern simple-bit-vector-p (form) :lisp)
   1683 (define-caller-pattern arrayp (form) :lisp)
   1684 (define-caller-pattern packagep (form) :lisp)
   1685 (define-caller-pattern functionp (form) :lisp)
   1686 (define-caller-pattern compiled-function-p (form) :lisp)
   1687 (define-caller-pattern commonp (form) :lisp)
   1688 
   1689 ;;; Equality Predicates
   1690 (define-caller-pattern eq (form form) :lisp)
   1691 (define-caller-pattern eql (form form) :lisp)
   1692 (define-caller-pattern equal (form form) :lisp)
   1693 (define-caller-pattern equalp (form form) :lisp)
   1694 
   1695 ;;; Logical Operators
   1696 (define-caller-pattern not (form) :lisp)
   1697 (define-caller-pattern or ((:star form)) :lisp)
   1698 (define-caller-pattern and ((:star form)) :lisp)
   1699 
   1700 ;;; Reference
   1701 
   1702 ;;; Quote is a problem. In Defmacro & friends, we'd like to actually
   1703 ;;; look at the argument, 'cause it hides internal function calls
   1704 ;;; of the defmacro. 
   1705 (define-caller-pattern quote (:ignore) :lisp)
   1706 
   1707 (define-caller-pattern function ((:or fn form)) :lisp)
   1708 (define-caller-pattern symbol-value (form) :lisp)
   1709 (define-caller-pattern symbol-function (form) :lisp)
   1710 (define-caller-pattern fdefinition (form) :lisp2)
   1711 (define-caller-pattern boundp (form) :lisp)
   1712 (define-caller-pattern fboundp (form) :lisp)
   1713 (define-caller-pattern special-form-p (form) :lisp)
   1714 
   1715 ;;; Assignment
   1716 (define-caller-pattern setq ((:star var form)) :lisp)
   1717 (define-caller-pattern psetq ((:star var form)) :lisp)
   1718 (define-caller-pattern set (form form) :lisp)
   1719 (define-caller-pattern makunbound (form) :lisp)
   1720 (define-caller-pattern fmakunbound (form) :lisp)
   1721 
   1722 ;;; Generalized Variables
   1723 (define-caller-pattern setf ((:star form form)) :lisp)
   1724 (define-caller-pattern psetf ((:star form form)) :lisp)
   1725 (define-caller-pattern shiftf ((:plus form) form) :lisp)
   1726 (define-caller-pattern rotatef ((:star form)) :lisp)
   1727 (define-caller-pattern define-modify-macro 
   1728   (name
   1729    lambda-list
   1730    fn
   1731    (:optional documentation-string))
   1732   :lisp)
   1733 (define-caller-pattern defsetf 
   1734   (:or (name name (:optional documentation-string))
   1735        (name lambda-list (var)
   1736 	(:star (:or declaration documentation-string))
   1737 	(:star form)))
   1738   :lisp)
   1739 (define-caller-pattern define-setf-method
   1740   (name lambda-list
   1741    (:star (:or declaration documentation-string))
   1742    (:star form))
   1743   :lisp)
   1744 (define-caller-pattern get-setf-method (form) :lisp)
   1745 (define-caller-pattern get-setf-method-multiple-value (form) :lisp)
   1746 
   1747 
   1748 ;;; Function invocation
   1749 (define-caller-pattern apply (fn form (:star form)) :lisp)
   1750 (define-caller-pattern funcall (fn (:star form)) :lisp)
   1751 
   1752 
   1753 ;;; Simple sequencing
   1754 (define-caller-pattern progn ((:star form)) :lisp)
   1755 (define-caller-pattern prog1 (form (:star form)) :lisp)
   1756 (define-caller-pattern prog2 (form form (:star form)) :lisp)
   1757 
   1758 ;;; Variable bindings
   1759 (define-caller-pattern let
   1760   (((:star (:or var (var &optional form))))
   1761    (:star declaration)
   1762    (:star form))
   1763   :lisp)
   1764 (define-caller-pattern let*
   1765   (((:star (:or var (var &optional form))))
   1766     (:star declaration)
   1767     (:star form))
   1768   :lisp)
   1769 (define-caller-pattern compiler-let
   1770   (((:star (:or var (var form))))
   1771     (:star form))
   1772   :lisp)
   1773 (define-caller-pattern progv
   1774   (form form (:star form)) :lisp)
   1775 (define-caller-pattern flet
   1776   (((:star (name lambda-list 
   1777 		 (:star (:or declaration
   1778 			     documentation-string))
   1779 		 (:star form))))
   1780    (:star form))
   1781   :lisp)
   1782 (define-caller-pattern labels
   1783   (((:star (name lambda-list 
   1784 		 (:star (:or declaration
   1785 			     documentation-string))
   1786 		 (:star form))))
   1787    (:star form))
   1788   :lisp)
   1789 (define-caller-pattern macrolet
   1790   (((:star (name lambda-list 
   1791 		 (:star (:or declaration
   1792 			     documentation-string))
   1793 		 (:star form))))
   1794    (:star form))
   1795   :lisp)
   1796 (define-caller-pattern symbol-macrolet
   1797   (((:star (var form))) (:star declaration) (:star form))
   1798   :lisp2)
   1799 
   1800 ;;; Conditionals
   1801 (define-caller-pattern if (test form (:optional form)) :lisp)
   1802 (define-caller-pattern when (test (:star form)) :lisp)
   1803 (define-caller-pattern unless (test (:star form)) :lisp)
   1804 (define-caller-pattern cond ((:star (test (:star form)))) :lisp)
   1805 (define-caller-pattern case
   1806   (form
   1807    (:star ((:or symbol
   1808 		((:star symbol)))
   1809 	   (:star form)))) 
   1810   :lisp)
   1811 (define-caller-pattern typecase (form (:star (symbol (:star form)))) 
   1812   :lisp)
   1813 
   1814 ;;; Blocks and Exits
   1815 (define-caller-pattern block (name (:star form)) :lisp)
   1816 (define-caller-pattern return-from (function (:optional form)) :lisp)
   1817 (define-caller-pattern return ((:optional form)) :lisp)
   1818 
   1819 ;;; Iteration
   1820 (define-caller-pattern loop ((:star form)) :lisp)
   1821 (define-caller-pattern do
   1822   (((:star (:or var
   1823 		(var (:optional form (:optional form)))))) ; init step
   1824    (form (:star form)) ; end-test result
   1825    (:star declaration)
   1826    (:star (:or tag form)))		; statement
   1827   :lisp)
   1828 (define-caller-pattern do*
   1829   (((:star (:or var
   1830 		(var (:optional form (:optional form)))))) 
   1831    (form (:star form))
   1832    (:star declaration)
   1833    (:star (:or tag form)))
   1834   :lisp)
   1835 (define-caller-pattern dolist
   1836   ((var form (:optional form))
   1837    (:star declaration)
   1838    (:star (:or tag form)))
   1839   :lisp)
   1840 (define-caller-pattern dotimes
   1841   ((var form (:optional form))
   1842    (:star declaration)
   1843    (:star (:or tag form)))
   1844   :lisp)
   1845 
   1846 ;;; Mapping
   1847 (define-caller-pattern mapcar (fn form (:star form)) :lisp)
   1848 (define-caller-pattern maplist (fn form (:star form)) :lisp)
   1849 (define-caller-pattern mapc (fn form (:star form)) :lisp)
   1850 (define-caller-pattern mapl (fn form (:star form)) :lisp)
   1851 (define-caller-pattern mapcan (fn form (:star form)) :lisp)
   1852 (define-caller-pattern mapcon (fn form (:star form)) :lisp)
   1853 
   1854 ;;; The "Program Feature"
   1855 (define-caller-pattern tagbody ((:star (:or tag form))) :lisp)
   1856 (define-caller-pattern prog
   1857   (((:star (:or var (var (:optional form)))))
   1858    (:star declaration)
   1859    (:star (:or tag form)))
   1860   :lisp)
   1861 (define-caller-pattern prog*    
   1862   (((:star (:or var (var (:optional form)))))
   1863    (:star declaration)
   1864    (:star (:or tag form)))
   1865   :lisp)
   1866 (define-caller-pattern go (tag) :lisp)
   1867 
   1868 ;;; Multiple Values
   1869 (define-caller-pattern values ((:star form)) :lisp)
   1870 (define-variable-pattern multiple-values-limit :lisp)
   1871 (define-caller-pattern values-list (form) :lisp)
   1872 (define-caller-pattern multiple-value-list (form) :lisp)
   1873 (define-caller-pattern multiple-value-call (fn (:star form)) :lisp)
   1874 (define-caller-pattern multiple-value-prog1 (form (:star form)) :lisp)
   1875 (define-caller-pattern multiple-value-bind
   1876   (((:star var)) form
   1877    (:star declaration)
   1878    (:star form))
   1879   :lisp)
   1880 (define-caller-pattern multiple-value-setq (((:star var)) form) :lisp)
   1881 (define-caller-pattern nth-value (form form) :lisp2)
   1882 
   1883 ;;; Dynamic Non-Local Exits
   1884 (define-caller-pattern catch (tag (:star form)) :lisp)
   1885 (define-caller-pattern throw (tag form) :lisp)
   1886 (define-caller-pattern unwind-protect (form (:star form)) :lisp)
   1887 
   1888 ;;; Macros
   1889 (define-caller-pattern macro-function (form) :lisp)
   1890 (define-caller-pattern defmacro
   1891   (name
   1892    lambda-list
   1893    (:star (:or declaration documentation-string))
   1894    (:star form))
   1895   :lisp)
   1896 (define-caller-pattern macroexpand (form (:optional :ignore)) :lisp)
   1897 (define-caller-pattern macroexpand-1 (form (:optional :ignore)) :lisp)
   1898 (define-variable-pattern *macroexpand-hook* :lisp)
   1899 
   1900 ;;; Destructuring
   1901 (define-caller-pattern destructuring-bind 
   1902   (lambda-list form
   1903 	       (:star declaration)
   1904 	       (:star form))
   1905   :lisp2)
   1906 
   1907 ;;; Compiler Macros
   1908 (define-caller-pattern define-compiler-macro
   1909   (name lambda-list
   1910 	(:star (:or declaration documentation-string))
   1911 	(:star form))
   1912   :lisp2)
   1913 (define-caller-pattern compiler-macro-function (form) :lisp2)
   1914 (define-caller-pattern compiler-macroexpand (form (:optional :ignore)) :lisp2)
   1915 (define-caller-pattern compiler-macroexpand-1 (form (:optional :ignore))
   1916   :lisp2)
   1917 
   1918 ;;; Environments
   1919 (define-caller-pattern variable-information (form &optional :ignore) 
   1920   :lisp2)
   1921 (define-caller-pattern function-information (fn &optional :ignore) :lisp2)
   1922 (define-caller-pattern declaration-information (form &optional :ignore) :lisp2)
   1923 (define-caller-pattern augment-environment (form &key (:star :ignore)) :lisp2)
   1924 (define-caller-pattern define-declaration 
   1925   (name
   1926    lambda-list
   1927    (:star form)) 
   1928   :lisp2)
   1929 (define-caller-pattern parse-macro (name lambda-list form) :lisp2)
   1930 (define-caller-pattern enclose (form &optional :ignore) :lisp2)
   1931 
   1932 
   1933 ;;; Declarations
   1934 (define-caller-pattern declare ((:rest :ignore)) :lisp)
   1935 (define-caller-pattern proclaim ((:rest :ignore)) :lisp)
   1936 (define-caller-pattern locally ((:star declaration) (:star form)) :lisp)
   1937 (define-caller-pattern declaim ((:rest :ignore)) :lisp2)
   1938 (define-caller-pattern the (form form) :lisp)
   1939 
   1940 ;;; Symbols
   1941 (define-caller-pattern get (form form (:optional form)) :lisp)
   1942 (define-caller-pattern remprop (form form) :lisp)
   1943 (define-caller-pattern symbol-plist (form) :lisp)
   1944 (define-caller-pattern getf (form form (:optional form)) :lisp)
   1945 (define-caller-pattern remf (form form) :lisp)
   1946 (define-caller-pattern get-properties (form form) :lisp)
   1947 
   1948 (define-caller-pattern symbol-name (form) :lisp)
   1949 (define-caller-pattern make-symbol (form) :lisp)
   1950 (define-caller-pattern copy-symbol (form (:optional :ignore)) :lisp)
   1951 (define-caller-pattern gensym ((:optional :ignore)) :lisp)
   1952 (define-variable-pattern *gensym-counter* :lisp2)
   1953 (define-caller-pattern gentemp ((:optional :ignore :ignore)) :lisp)
   1954 (define-caller-pattern symbol-package (form) :lisp)
   1955 (define-caller-pattern keywordp (form) :lisp)
   1956 
   1957 ;;; Packages
   1958 (define-variable-pattern *package* :lisp)
   1959 (define-caller-pattern make-package ((:rest :ignore)) :lisp)
   1960 (define-caller-pattern in-package ((:rest :ignore)) :lisp)
   1961 (define-caller-pattern find-package ((:rest :ignore)) :lisp)
   1962 (define-caller-pattern package-name ((:rest :ignore)) :lisp)
   1963 (define-caller-pattern package-nicknames ((:rest :ignore)) :lisp)
   1964 (define-caller-pattern rename-package ((:rest :ignore)) :lisp)
   1965 (define-caller-pattern package-use-list ((:rest :ignore)) :lisp)
   1966 (define-caller-pattern package-used-by-list ((:rest :ignore)) :lisp)
   1967 (define-caller-pattern package-shadowing-symbols ((:rest :ignore)) :lisp)
   1968 (define-caller-pattern list-all-packages () :lisp)
   1969 (define-caller-pattern delete-package ((:rest :ignore)) :lisp2)
   1970 (define-caller-pattern intern (form &optional :ignore) :lisp)
   1971 (define-caller-pattern find-symbol (form &optional :ignore) :lisp)
   1972 (define-caller-pattern unintern (form &optional :ignore) :lisp)
   1973 
   1974 (define-caller-pattern export ((:or symbol ((:star symbol)))
   1975 			       &optional :ignore) :lisp)
   1976 (define-caller-pattern unexport ((:or symbol ((:star symbol)))
   1977 			       &optional :ignore) :lisp)
   1978 (define-caller-pattern import ((:or symbol ((:star symbol)))
   1979 			       &optional :ignore) :lisp)
   1980 (define-caller-pattern shadowing-import ((:or symbol ((:star symbol)))
   1981 			       &optional :ignore) :lisp)
   1982 (define-caller-pattern shadow ((:or symbol ((:star symbol)))
   1983 			       &optional :ignore) :lisp)
   1984 
   1985 (define-caller-pattern use-package ((:rest :ignore)) :lisp)
   1986 (define-caller-pattern unuse-package ((:rest :ignore)) :lisp)
   1987 (define-caller-pattern defpackage (name (:rest :ignore)) :lisp2)
   1988 (define-caller-pattern find-all-symbols (form) :lisp)
   1989 (define-caller-pattern do-symbols 
   1990   ((var (:optional form (:optional form)))
   1991    (:star declaration) 
   1992    (:star (:or tag form))) 
   1993   :lisp)
   1994 (define-caller-pattern do-external-symbols 
   1995   ((var (:optional form (:optional form)))
   1996    (:star declaration) 
   1997    (:star (:or tag form))) 
   1998   :lisp)
   1999 (define-caller-pattern do-all-symbols 
   2000   ((var (:optional form))
   2001    (:star declaration) 
   2002    (:star (:or tag form))) 
   2003   :lisp)
   2004 (define-caller-pattern with-package-iterator
   2005   ((name form (:plus :ignore))
   2006    (:star form))
   2007   :lisp2)
   2008 
   2009 ;;; Modules
   2010 (define-variable-pattern *modules* :lisp)
   2011 (define-caller-pattern provide (form) :lisp)
   2012 (define-caller-pattern require (form &optional :ignore) :lisp)
   2013 
   2014 
   2015 ;;; Numbers
   2016 (define-caller-pattern zerop (form) :lisp)
   2017 (define-caller-pattern plusp (form) :lisp)
   2018 (define-caller-pattern minusp (form) :lisp)
   2019 (define-caller-pattern oddp (form) :lisp)
   2020 (define-caller-pattern evenp (form) :lisp)
   2021 
   2022 (define-caller-pattern = (form (:star form)) :lisp)
   2023 (define-caller-pattern /= (form (:star form)) :lisp)
   2024 (define-caller-pattern > (form (:star form)) :lisp)
   2025 (define-caller-pattern < (form (:star form)) :lisp)
   2026 (define-caller-pattern <= (form (:star form)) :lisp)
   2027 (define-caller-pattern >= (form (:star form)) :lisp)
   2028 
   2029 (define-caller-pattern max (form (:star form)) :lisp)
   2030 (define-caller-pattern min (form (:star form)) :lisp)
   2031 
   2032 (define-caller-pattern - (form (:star form)) :lisp)
   2033 (define-caller-pattern + (form (:star form)) :lisp)
   2034 (define-caller-pattern * (form (:star form)) :lisp)
   2035 (define-caller-pattern / (form (:star form)) :lisp)
   2036 (define-caller-pattern 1+ (form) :lisp)
   2037 (define-caller-pattern 1- (form) :lisp)
   2038 
   2039 (define-caller-pattern incf (form form) :lisp)
   2040 (define-caller-pattern decf (form form) :lisp)
   2041 
   2042 (define-caller-pattern conjugate (form) :lisp)
   2043 
   2044 (define-caller-pattern gcd ((:star form)) :lisp)
   2045 (define-caller-pattern lcm ((:star form)) :lisp)
   2046 
   2047 (define-caller-pattern exp (form) :lisp)
   2048 (define-caller-pattern expt (form form) :lisp)
   2049 (define-caller-pattern log (form (:optional form)) :lisp)
   2050 (define-caller-pattern sqrt (form) :lisp)
   2051 (define-caller-pattern isqrt (form) :lisp)
   2052 
   2053 (define-caller-pattern abs (form) :lisp)
   2054 (define-caller-pattern phase (form) :lisp)
   2055 (define-caller-pattern signum (form) :lisp)
   2056 (define-caller-pattern sin (form) :lisp)
   2057 (define-caller-pattern cos (form) :lisp)
   2058 (define-caller-pattern tan (form) :lisp)
   2059 (define-caller-pattern cis (form) :lisp)
   2060 (define-caller-pattern asin (form) :lisp)
   2061 (define-caller-pattern acos (form) :lisp)
   2062 (define-caller-pattern atan (form &optional form) :lisp)
   2063 (define-variable-pattern pi :lisp)
   2064 
   2065 (define-caller-pattern sinh (form) :lisp)
   2066 (define-caller-pattern cosh (form) :lisp)
   2067 (define-caller-pattern tanh (form) :lisp)
   2068 (define-caller-pattern asinh (form) :lisp)
   2069 (define-caller-pattern acosh (form) :lisp)
   2070 (define-caller-pattern atanh (form) :lisp)
   2071 
   2072 ;;; Type Conversions and Extractions
   2073 (define-caller-pattern float (form (:optional form)) :lisp)
   2074 (define-caller-pattern rational (form) :lisp)
   2075 (define-caller-pattern rationalize (form) :lisp)
   2076 (define-caller-pattern numerator (form) :lisp)
   2077 (define-caller-pattern denominator (form) :lisp)
   2078 
   2079 (define-caller-pattern floor (form (:optional form)) :lisp)
   2080 (define-caller-pattern ceiling (form (:optional form)) :lisp)
   2081 (define-caller-pattern truncate (form (:optional form)) :lisp)
   2082 (define-caller-pattern round (form (:optional form)) :lisp)
   2083 
   2084 (define-caller-pattern mod (form form) :lisp)
   2085 (define-caller-pattern rem (form form) :lisp)
   2086 
   2087 (define-caller-pattern ffloor (form (:optional form)) :lisp)
   2088 (define-caller-pattern fceiling (form (:optional form)) :lisp)
   2089 (define-caller-pattern ftruncate (form (:optional form)) :lisp)
   2090 (define-caller-pattern fround (form (:optional form)) :lisp)
   2091 
   2092 (define-caller-pattern decode-float (form) :lisp)
   2093 (define-caller-pattern scale-float (form form) :lisp)
   2094 (define-caller-pattern float-radix (form) :lisp)
   2095 (define-caller-pattern float-sign (form (:optional form)) :lisp)
   2096 (define-caller-pattern float-digits (form) :lisp)
   2097 (define-caller-pattern float-precision (form) :lisp)
   2098 (define-caller-pattern integer-decode-float (form) :lisp)
   2099 
   2100 (define-caller-pattern complex (form (:optional form)) :lisp)
   2101 (define-caller-pattern realpart (form) :lisp)
   2102 (define-caller-pattern imagpart (form) :lisp)
   2103 
   2104 (define-caller-pattern logior ((:star form)) :lisp)
   2105 (define-caller-pattern logxor ((:star form)) :lisp)
   2106 (define-caller-pattern logand ((:star form)) :lisp)
   2107 (define-caller-pattern logeqv ((:star form)) :lisp)
   2108 
   2109 (define-caller-pattern lognand (form form) :lisp)
   2110 (define-caller-pattern lognor (form form) :lisp)
   2111 (define-caller-pattern logandc1 (form form) :lisp)
   2112 (define-caller-pattern logandc2 (form form) :lisp)
   2113 (define-caller-pattern logorc1 (form form) :lisp)
   2114 (define-caller-pattern logorc2 (form form) :lisp)
   2115 
   2116 (define-caller-pattern boole (form form form) :lisp)
   2117 (define-variable-pattern boole-clr :lisp)
   2118 (define-variable-pattern boole-set :lisp)
   2119 (define-variable-pattern boole-1 :lisp)
   2120 (define-variable-pattern boole-2 :lisp)
   2121 (define-variable-pattern boole-c1 :lisp)
   2122 (define-variable-pattern boole-c2 :lisp)
   2123 (define-variable-pattern boole-and :lisp)
   2124 (define-variable-pattern boole-ior :lisp)
   2125 (define-variable-pattern boole-xor :lisp)
   2126 (define-variable-pattern boole-eqv :lisp)
   2127 (define-variable-pattern boole-nand :lisp)
   2128 (define-variable-pattern boole-nor :lisp)
   2129 (define-variable-pattern boole-andc1 :lisp)
   2130 (define-variable-pattern boole-andc2 :lisp)
   2131 (define-variable-pattern boole-orc1 :lisp)
   2132 (define-variable-pattern boole-orc2 :lisp)
   2133 
   2134 (define-caller-pattern lognot (form) :lisp)
   2135 (define-caller-pattern logtest (form form) :lisp)
   2136 (define-caller-pattern logbitp (form form) :lisp)
   2137 (define-caller-pattern ash (form form) :lisp)
   2138 (define-caller-pattern logcount (form) :lisp)
   2139 (define-caller-pattern integer-length (form) :lisp)
   2140 
   2141 (define-caller-pattern byte (form form) :lisp)
   2142 (define-caller-pattern byte-size (form) :lisp)
   2143 (define-caller-pattern byte-position (form) :lisp)
   2144 (define-caller-pattern ldb (form form) :lisp)
   2145 (define-caller-pattern ldb-test (form form) :lisp)
   2146 (define-caller-pattern mask-field (form form) :lisp)
   2147 (define-caller-pattern dpb (form form form) :lisp)
   2148 (define-caller-pattern deposit-field (form form form) :lisp)
   2149 
   2150 ;;; Random Numbers
   2151 (define-caller-pattern random (form (:optional form)) :lisp)
   2152 (define-variable-pattern *random-state* :lisp)
   2153 (define-caller-pattern make-random-state ((:optional form)) :lisp)
   2154 (define-caller-pattern random-state-p (form) :lisp)
   2155 
   2156 ;;; Implementation Parameters
   2157 (define-variable-pattern most-positive-fixnum :lisp)
   2158 (define-variable-pattern most-negative-fixnum :lisp)
   2159 (define-variable-pattern most-positive-short-float :lisp)
   2160 (define-variable-pattern least-positive-short-float :lisp)
   2161 (define-variable-pattern least-negative-short-float :lisp)
   2162 (define-variable-pattern most-negative-short-float :lisp)
   2163 (define-variable-pattern most-positive-single-float :lisp)
   2164 (define-variable-pattern least-positive-single-float :lisp)
   2165 (define-variable-pattern least-negative-single-float :lisp)
   2166 (define-variable-pattern most-negative-single-float :lisp)
   2167 (define-variable-pattern most-positive-double-float :lisp)
   2168 (define-variable-pattern least-positive-double-float :lisp)
   2169 (define-variable-pattern least-negative-double-float :lisp)
   2170 (define-variable-pattern most-negative-double-float :lisp)
   2171 (define-variable-pattern most-positive-long-float :lisp)
   2172 (define-variable-pattern least-positive-long-float :lisp)
   2173 (define-variable-pattern least-negative-long-float :lisp)
   2174 (define-variable-pattern most-negative-long-float :lisp)
   2175 (define-variable-pattern least-positive-normalized-short-float :lisp2)
   2176 (define-variable-pattern least-negative-normalized-short-float :lisp2)
   2177 (define-variable-pattern least-positive-normalized-single-float :lisp2)
   2178 (define-variable-pattern least-negative-normalized-single-float :lisp2)
   2179 (define-variable-pattern least-positive-normalized-double-float :lisp2)
   2180 (define-variable-pattern least-negative-normalized-double-float :lisp2)
   2181 (define-variable-pattern least-positive-normalized-long-float :lisp2)
   2182 (define-variable-pattern least-negative-normalized-long-float :lisp2)
   2183 (define-variable-pattern short-float-epsilon :lisp)
   2184 (define-variable-pattern single-float-epsilon :lisp)
   2185 (define-variable-pattern double-float-epsilon :lisp)
   2186 (define-variable-pattern long-float-epsilon :lisp)
   2187 (define-variable-pattern short-float-negative-epsilon :lisp)
   2188 (define-variable-pattern single-float-negative-epsilon :lisp)
   2189 (define-variable-pattern double-float-negative-epsilon :lisp)
   2190 (define-variable-pattern long-float-negative-epsilon :lisp)
   2191 
   2192 ;;; Characters 
   2193 (define-variable-pattern char-code-limit :lisp)
   2194 (define-variable-pattern char-font-limit :lisp)
   2195 (define-variable-pattern char-bits-limit :lisp)
   2196 (define-caller-pattern standard-char-p (form) :lisp)
   2197 (define-caller-pattern graphic-char-p (form) :lisp)
   2198 (define-caller-pattern string-char-p (form) :lisp)
   2199 (define-caller-pattern alpha-char-p (form) :lisp)
   2200 (define-caller-pattern upper-case-p (form) :lisp)
   2201 (define-caller-pattern lower-case-p (form) :lisp)
   2202 (define-caller-pattern both-case-p (form) :lisp)
   2203 (define-caller-pattern digit-char-p (form (:optional form)) :lisp)
   2204 (define-caller-pattern alphanumericp (form) :lisp)
   2205 
   2206 (define-caller-pattern char= ((:star form)) :lisp)
   2207 (define-caller-pattern char/= ((:star form)) :lisp)
   2208 (define-caller-pattern char< ((:star form)) :lisp)
   2209 (define-caller-pattern char> ((:star form)) :lisp)
   2210 (define-caller-pattern char<= ((:star form)) :lisp)
   2211 (define-caller-pattern char>= ((:star form)) :lisp)
   2212 
   2213 (define-caller-pattern char-equal ((:star form)) :lisp)
   2214 (define-caller-pattern char-not-equal ((:star form)) :lisp)
   2215 (define-caller-pattern char-lessp ((:star form)) :lisp)
   2216 (define-caller-pattern char-greaterp ((:star form)) :lisp)
   2217 (define-caller-pattern char-not-greaterp ((:star form)) :lisp)
   2218 (define-caller-pattern char-not-lessp ((:star form)) :lisp)
   2219 
   2220 (define-caller-pattern char-code (form) :lisp)
   2221 (define-caller-pattern char-bits (form) :lisp)
   2222 (define-caller-pattern char-font (form) :lisp)
   2223 (define-caller-pattern code-char (form (:optional form form)) :lisp)
   2224 (define-caller-pattern make-char (form (:optional form form)) :lisp)
   2225 (define-caller-pattern characterp (form) :lisp)
   2226 (define-caller-pattern char-upcase (form) :lisp)
   2227 (define-caller-pattern char-downcase (form) :lisp)
   2228 (define-caller-pattern digit-char (form (:optional form form)) :lisp)
   2229 (define-caller-pattern char-int (form) :lisp)
   2230 (define-caller-pattern int-char (form) :lisp)
   2231 (define-caller-pattern char-name (form) :lisp)
   2232 (define-caller-pattern name-char (form) :lisp)
   2233 (define-variable-pattern char-control-bit :lisp)
   2234 (define-variable-pattern char-meta-bit :lisp)
   2235 (define-variable-pattern char-super-bit :lisp)
   2236 (define-variable-pattern char-hyper-bit :lisp)
   2237 (define-caller-pattern char-bit (form form) :lisp)
   2238 (define-caller-pattern set-char-bit (form form form) :lisp)
   2239 
   2240 ;;; Sequences
   2241 (define-caller-pattern complement (fn) :lisp2)
   2242 (define-caller-pattern elt (form form) :lisp)
   2243 (define-caller-pattern subseq (form form &optional form) :lisp)
   2244 (define-caller-pattern copy-seq (form) :lisp)
   2245 (define-caller-pattern length (form) :lisp)
   2246 (define-caller-pattern reverse (form) :lisp)
   2247 (define-caller-pattern nreverse (form) :lisp)
   2248 (define-caller-pattern make-sequence (form form &key form) :lisp)
   2249 
   2250 (define-caller-pattern concatenate (form (:star form)) :lisp)
   2251 (define-caller-pattern map (form fn form (:star form)) :lisp)
   2252 (define-caller-pattern map-into (form fn (:star form)) :lisp2)
   2253 
   2254 (define-caller-pattern some (fn form (:star form)) :lisp)
   2255 (define-caller-pattern every (fn form (:star form)) :lisp)
   2256 (define-caller-pattern notany (fn form (:star form)) :lisp)
   2257 (define-caller-pattern notevery (fn form (:star form)) :lisp)
   2258 
   2259 (define-caller-pattern reduce (fn form &key (:star form)) :lisp)
   2260 (define-caller-pattern fill (form form &key (:star form)) :lisp)
   2261 (define-caller-pattern replace (form form &key (:star form)) :lisp)
   2262 (define-caller-pattern remove (form form &key (:star form)) :lisp)
   2263 (define-caller-pattern remove-if (fn form &key (:star form)) :lisp)
   2264 (define-caller-pattern remove-if-not (fn form &key (:star form)) :lisp)
   2265 (define-caller-pattern delete (form form &key (:star form)) :lisp)
   2266 (define-caller-pattern delete-if (fn form &key (:star form)) :lisp)
   2267 (define-caller-pattern delete-if-not (fn form &key (:star form)) :lisp)
   2268 (define-caller-pattern remove-duplicates (form &key (:star form)) :lisp)
   2269 (define-caller-pattern delete-duplicates (form &key (:star form)) :lisp)
   2270 (define-caller-pattern substitute (form form form &key (:star form)) :lisp)
   2271 (define-caller-pattern substitute-if (form fn form &key (:star form)) :lisp)
   2272 (define-caller-pattern substitute-if-not (form fn form &key (:star form))
   2273   :lisp)
   2274 (define-caller-pattern nsubstitute (form form form &key (:star form)) :lisp)
   2275 (define-caller-pattern nsubstitute-if (form fn form &key (:star form)) :lisp)
   2276 (define-caller-pattern nsubstitute-if-not (form fn form &key (:star form))
   2277   :lisp)
   2278 (define-caller-pattern find (form form &key (:star form)) :lisp)
   2279 (define-caller-pattern find-if (fn form &key (:star form)) :lisp)
   2280 (define-caller-pattern find-if-not (fn form &key (:star form)) :lisp)
   2281 (define-caller-pattern position (form form &key (:star form)) :lisp)
   2282 (define-caller-pattern position-if (fn form &key (:star form)) :lisp)
   2283 (define-caller-pattern position-if-not (fn form &key (:star form)) :lisp)
   2284 (define-caller-pattern count (form form &key (:star form)) :lisp)
   2285 (define-caller-pattern count-if (fn form &key (:star form)) :lisp)
   2286 (define-caller-pattern count-if-not (fn form &key (:star form)) :lisp)
   2287 (define-caller-pattern mismatch (form form &key (:star form)) :lisp)
   2288 (define-caller-pattern search (form form &key (:star form)) :lisp)
   2289 (define-caller-pattern sort (form fn &key (:star form)) :lisp)
   2290 (define-caller-pattern stable-sort (form fn &key (:star form)) :lisp)
   2291 (define-caller-pattern merge (form form form fn &key (:star form)) :lisp)
   2292 
   2293 ;;; Lists
   2294 (define-caller-pattern car (form) :lisp)
   2295 (define-caller-pattern cdr (form) :lisp)
   2296 (define-caller-pattern caar (form) :lisp)
   2297 (define-caller-pattern cadr (form) :lisp)
   2298 (define-caller-pattern cdar (form) :lisp)
   2299 (define-caller-pattern cddr (form) :lisp)
   2300 (define-caller-pattern caaar (form) :lisp)
   2301 (define-caller-pattern caadr (form) :lisp)
   2302 (define-caller-pattern cadar (form) :lisp)
   2303 (define-caller-pattern caddr (form) :lisp)
   2304 (define-caller-pattern cdaar (form) :lisp)
   2305 (define-caller-pattern cdadr (form) :lisp)
   2306 (define-caller-pattern cddar (form) :lisp)
   2307 (define-caller-pattern cdddr (form) :lisp)
   2308 (define-caller-pattern caaaar (form) :lisp)
   2309 (define-caller-pattern caaadr (form) :lisp)
   2310 (define-caller-pattern caadar (form) :lisp)
   2311 (define-caller-pattern caaddr (form) :lisp)
   2312 (define-caller-pattern cadaar (form) :lisp)
   2313 (define-caller-pattern cadadr (form) :lisp)
   2314 (define-caller-pattern caddar (form) :lisp)
   2315 (define-caller-pattern cadddr (form) :lisp)
   2316 (define-caller-pattern cdaaar (form) :lisp)
   2317 (define-caller-pattern cdaadr (form) :lisp)
   2318 (define-caller-pattern cdadar (form) :lisp)
   2319 (define-caller-pattern cdaddr (form) :lisp)
   2320 (define-caller-pattern cddaar (form) :lisp)
   2321 (define-caller-pattern cddadr (form) :lisp)
   2322 (define-caller-pattern cdddar (form) :lisp)
   2323 (define-caller-pattern cddddr (form) :lisp)
   2324 
   2325 (define-caller-pattern cons (form form) :lisp)
   2326 (define-caller-pattern tree-equal (form form &key (:star fn)) :lisp)
   2327 (define-caller-pattern endp (form) :lisp)
   2328 (define-caller-pattern list-length (form) :lisp)
   2329 (define-caller-pattern nth (form form) :lisp)
   2330 
   2331 (define-caller-pattern first (form) :lisp)
   2332 (define-caller-pattern second (form) :lisp)
   2333 (define-caller-pattern third (form) :lisp)
   2334 (define-caller-pattern fourth (form) :lisp)
   2335 (define-caller-pattern fifth (form) :lisp)
   2336 (define-caller-pattern sixth (form) :lisp)
   2337 (define-caller-pattern seventh (form) :lisp)
   2338 (define-caller-pattern eighth (form) :lisp)
   2339 (define-caller-pattern ninth (form) :lisp)
   2340 (define-caller-pattern tenth (form) :lisp)
   2341 
   2342 (define-caller-pattern rest (form) :lisp)
   2343 (define-caller-pattern nthcdr (form form) :lisp)
   2344 (define-caller-pattern last (form (:optional form)) :lisp)
   2345 (define-caller-pattern list ((:star form)) :lisp)
   2346 (define-caller-pattern list* ((:star form)) :lisp)
   2347 (define-caller-pattern make-list (form &key (:star form)) :lisp)
   2348 (define-caller-pattern append ((:star form)) :lisp)
   2349 (define-caller-pattern copy-list (form) :lisp)
   2350 (define-caller-pattern copy-alist (form) :lisp)
   2351 (define-caller-pattern copy-tree (form) :lisp)
   2352 (define-caller-pattern revappend (form form) :lisp)
   2353 (define-caller-pattern nconc ((:star form)) :lisp)
   2354 (define-caller-pattern nreconc (form form) :lisp)
   2355 (define-caller-pattern push (form form) :lisp)
   2356 (define-caller-pattern pushnew (form form &key (:star form)) :lisp)
   2357 (define-caller-pattern pop (form) :lisp)
   2358 (define-caller-pattern butlast (form (:optional form)) :lisp)
   2359 (define-caller-pattern nbutlast (form (:optional form)) :lisp)
   2360 (define-caller-pattern ldiff (form form) :lisp)
   2361 (define-caller-pattern rplaca (form form) :lisp)
   2362 (define-caller-pattern rplacd (form form) :lisp)
   2363 
   2364 (define-caller-pattern subst (form form form &key (:star form)) :lisp)
   2365 (define-caller-pattern subst-if (form fn form &key (:star form)) :lisp)
   2366 (define-caller-pattern subst-if-not (form fn form &key (:star form)) :lisp)
   2367 (define-caller-pattern nsubst (form form form &key (:star form)) :lisp)
   2368 (define-caller-pattern nsubst-if (form fn form &key (:star form)) :lisp)
   2369 (define-caller-pattern nsubst-if-not (form fn form &key (:star form)) :lisp)
   2370 (define-caller-pattern sublis (form form &key (:star form)) :lisp)
   2371 (define-caller-pattern nsublis (form form &key (:star form)) :lisp)
   2372 (define-caller-pattern member (form form &key (:star form)) :lisp)
   2373 (define-caller-pattern member-if (fn form &key (:star form)) :lisp)
   2374 (define-caller-pattern member-if-not (fn form &key (:star form)) :lisp)
   2375 
   2376 (define-caller-pattern tailp (form form) :lisp)
   2377 (define-caller-pattern adjoin (form form &key (:star form)) :lisp)
   2378 (define-caller-pattern union (form form &key (:star form)) :lisp)
   2379 (define-caller-pattern nunion (form form &key (:star form)) :lisp)
   2380 (define-caller-pattern intersection (form form &key (:star form)) :lisp)
   2381 (define-caller-pattern nintersection (form form &key (:star form)) :lisp)
   2382 (define-caller-pattern set-difference (form form &key (:star form)) :lisp)
   2383 (define-caller-pattern nset-difference (form form &key (:star form)) :lisp)
   2384 (define-caller-pattern set-exclusive-or (form form &key (:star form)) :lisp)
   2385 (define-caller-pattern nset-exclusive-or (form form &key (:star form)) :lisp)
   2386 (define-caller-pattern subsetp (form form &key (:star form)) :lisp)
   2387 
   2388 (define-caller-pattern acons (form form form) :lisp)
   2389 (define-caller-pattern pairlis (form form (:optional form)) :lisp)
   2390 (define-caller-pattern assoc (form form &key (:star form)) :lisp)
   2391 (define-caller-pattern assoc-if (fn form) :lisp)
   2392 (define-caller-pattern assoc-if-not (fn form) :lisp)
   2393 (define-caller-pattern rassoc (form form &key (:star form)) :lisp)
   2394 (define-caller-pattern rassoc-if (fn form &key (:star form)) :lisp)
   2395 (define-caller-pattern rassoc-if-not (fn form &key (:star form)) :lisp)
   2396 
   2397 ;;; Hash Tables
   2398 (define-caller-pattern make-hash-table (&key (:star form)) :lisp)
   2399 (define-caller-pattern hash-table-p (form) :lisp)
   2400 (define-caller-pattern gethash (form form (:optional form)) :lisp)
   2401 (define-caller-pattern remhash (form form) :lisp)
   2402 (define-caller-pattern maphash (fn form) :lisp)
   2403 (define-caller-pattern clrhash (form) :lisp)
   2404 (define-caller-pattern hash-table-count (form) :lisp)
   2405 (define-caller-pattern with-hash-table-iterator
   2406   ((name form) (:star form)) :lisp2)
   2407 (define-caller-pattern hash-table-rehash-size (form) :lisp2)
   2408 (define-caller-pattern hash-table-rehash-threshold (form) :lisp2)
   2409 (define-caller-pattern hash-table-size (form) :lisp2)
   2410 (define-caller-pattern hash-table-test (form) :lisp2)
   2411 (define-caller-pattern sxhash (form) :lisp)
   2412 
   2413 ;;; Arrays
   2414 (define-caller-pattern make-array (form &key (:star form)) :lisp)
   2415 (define-variable-pattern array-rank-limit :lisp)
   2416 (define-variable-pattern array-dimension-limit :lisp)
   2417 (define-variable-pattern array-total-size-limit :lisp)
   2418 (define-caller-pattern vector ((:star form)) :lisp)
   2419 (define-caller-pattern aref (form (:star form)) :lisp)
   2420 (define-caller-pattern svref (form form) :lisp)
   2421 (define-caller-pattern array-element-type (form) :lisp)
   2422 (define-caller-pattern array-rank (form) :lisp)
   2423 (define-caller-pattern array-dimension (form form) :lisp)
   2424 (define-caller-pattern array-dimensions (form) :lisp)
   2425 (define-caller-pattern array-total-size (form) :lisp)
   2426 (define-caller-pattern array-in-bounds-p (form (:star form)) :lisp)
   2427 (define-caller-pattern array-row-major-index (form (:star form)) :lisp)
   2428 (define-caller-pattern row-major-aref (form form) :lisp2)
   2429 (define-caller-pattern adjustable-array-p (form) :lisp)
   2430 
   2431 (define-caller-pattern bit (form (:star form)) :lisp)
   2432 (define-caller-pattern sbit (form (:star form)) :lisp)
   2433 
   2434 (define-caller-pattern bit-and (form form (:optional form)) :lisp)
   2435 (define-caller-pattern bit-ior (form form (:optional form)) :lisp)
   2436 (define-caller-pattern bit-xor (form form (:optional form)) :lisp)
   2437 (define-caller-pattern bit-eqv (form form (:optional form)) :lisp)
   2438 (define-caller-pattern bit-nand (form form (:optional form)) :lisp)
   2439 (define-caller-pattern bit-nor (form form (:optional form)) :lisp)
   2440 (define-caller-pattern bit-andc1 (form form (:optional form)) :lisp)
   2441 (define-caller-pattern bit-andc2 (form form (:optional form)) :lisp)
   2442 (define-caller-pattern bit-orc1 (form form (:optional form)) :lisp)
   2443 (define-caller-pattern bit-orc2 (form form (:optional form)) :lisp)
   2444 (define-caller-pattern bit-not (form (:optional form)) :lisp)
   2445 
   2446 (define-caller-pattern array-has-fill-pointer-p (form) :lisp)
   2447 (define-caller-pattern fill-pointer (form) :lisp)
   2448 (define-caller-pattern vector-push (form form) :lisp)
   2449 (define-caller-pattern vector-push-extend (form form (:optional form)) :lisp)
   2450 (define-caller-pattern vector-pop (form) :lisp)
   2451 (define-caller-pattern adjust-array (form form &key (:star form)) :lisp)
   2452 
   2453 ;;; Strings
   2454 (define-caller-pattern char (form form) :lisp)
   2455 (define-caller-pattern schar (form form) :lisp)
   2456 (define-caller-pattern string= (form form &key (:star form)) :lisp)
   2457 (define-caller-pattern string-equal (form form &key (:star form)) :lisp)
   2458 (define-caller-pattern string< (form form &key (:star form)) :lisp)
   2459 (define-caller-pattern string> (form form &key (:star form)) :lisp)
   2460 (define-caller-pattern string<= (form form &key (:star form)) :lisp)
   2461 (define-caller-pattern string>= (form form &key (:star form)) :lisp)
   2462 (define-caller-pattern string/= (form form &key (:star form)) :lisp)
   2463 (define-caller-pattern string-lessp (form form &key (:star form)) :lisp)
   2464 (define-caller-pattern string-greaterp (form form &key (:star form)) :lisp)
   2465 (define-caller-pattern string-not-greaterp (form form &key (:star form)) :lisp)
   2466 (define-caller-pattern string-not-lessp (form form &key (:star form)) :lisp)
   2467 (define-caller-pattern string-not-equal (form form &key (:star form)) :lisp)
   2468 
   2469 (define-caller-pattern make-string (form &key (:star form)) :lisp)
   2470 (define-caller-pattern string-trim (form form) :lisp)
   2471 (define-caller-pattern string-left-trim (form form) :lisp)
   2472 (define-caller-pattern string-right-trim (form form) :lisp)
   2473 (define-caller-pattern string-upcase (form &key (:star form)) :lisp)
   2474 (define-caller-pattern string-downcase (form &key (:star form)) :lisp)
   2475 (define-caller-pattern string-capitalize (form &key (:star form)) :lisp)
   2476 (define-caller-pattern nstring-upcase (form &key (:star form)) :lisp)
   2477 (define-caller-pattern nstring-downcase (form &key (:star form)) :lisp)
   2478 (define-caller-pattern nstring-capitalize (form &key (:star form)) :lisp)
   2479 (define-caller-pattern string (form) :lisp)
   2480 
   2481 ;;; Structures
   2482 (define-caller-pattern defstruct 
   2483   ((:or name (name (:rest :ignore)))
   2484    (:optional documentation-string)
   2485    (:plus :ignore))
   2486   :lisp)
   2487 
   2488 ;;; The Evaluator
   2489 (define-caller-pattern eval (form) :lisp)
   2490 (define-variable-pattern *evalhook* :lisp)
   2491 (define-variable-pattern *applyhook* :lisp)
   2492 (define-caller-pattern evalhook (form fn fn &optional :ignore) :lisp)
   2493 (define-caller-pattern applyhook (fn form fn fn &optional :ignore) :lisp)
   2494 (define-caller-pattern constantp (form) :lisp)
   2495 
   2496 ;;; Streams
   2497 (define-variable-pattern *standard-input* :lisp)
   2498 (define-variable-pattern *standard-output* :lisp)
   2499 (define-variable-pattern *error-output* :lisp)
   2500 (define-variable-pattern *query-io* :lisp)
   2501 (define-variable-pattern *debug-io* :lisp)
   2502 (define-variable-pattern *terminal-io* :lisp)
   2503 (define-variable-pattern *trace-output* :lisp)
   2504 (define-caller-pattern make-synonym-stream (symbol) :lisp)
   2505 (define-caller-pattern make-broadcast-stream ((:star form)) :lisp)
   2506 (define-caller-pattern make-concatenated-stream ((:star form)) :lisp)
   2507 (define-caller-pattern make-two-way-stream (form form) :lisp)
   2508 (define-caller-pattern make-echo-stream (form form) :lisp)
   2509 (define-caller-pattern make-string-input-stream (form &optional form form)
   2510   :lisp)
   2511 (define-caller-pattern make-string-output-stream (&key (:star form)) :lisp)
   2512 (define-caller-pattern get-output-stream-string (form) :lisp)
   2513 
   2514 (define-caller-pattern with-open-stream
   2515   ((var form)
   2516    (:star declaration)
   2517    (:star form))
   2518   :lisp)
   2519 
   2520 (define-caller-pattern with-input-from-string
   2521   ((var form &key (:star form))
   2522    (:star declaration)
   2523    (:star form))
   2524   :lisp)
   2525 
   2526 (define-caller-pattern with-output-to-string
   2527   ((var (:optional form))
   2528    (:star declaration)
   2529    (:star form))
   2530   :lisp)
   2531 (define-caller-pattern streamp (form) :lisp)
   2532 (define-caller-pattern open-stream-p (form) :lisp2)
   2533 (define-caller-pattern input-stream-p (form) :lisp)
   2534 (define-caller-pattern output-stream-p (form) :lisp)
   2535 (define-caller-pattern stream-element-type (form) :lisp)
   2536 (define-caller-pattern close (form (:rest :ignore)) :lisp)
   2537 (define-caller-pattern broadcast-stream-streams (form) :lisp2)
   2538 (define-caller-pattern concatenated-stream-streams (form) :lisp2)
   2539 (define-caller-pattern echo-stream-input-stream (form) :lisp2)
   2540 (define-caller-pattern echo-stream-output-stream (form) :lisp2)
   2541 (define-caller-pattern synonym-stream-symbol (form) :lisp2)
   2542 (define-caller-pattern two-way-stream-input-stream (form) :lisp2)
   2543 (define-caller-pattern two-way-stream-output-stream (form) :lisp2)
   2544 (define-caller-pattern interactive-stream-p (form) :lisp2)
   2545 (define-caller-pattern stream-external-format (form) :lisp2)
   2546 
   2547 ;;; Reader
   2548 (define-variable-pattern *read-base* :lisp)
   2549 (define-variable-pattern *read-suppress* :lisp)
   2550 (define-variable-pattern *read-eval* :lisp2)
   2551 (define-variable-pattern *readtable* :lisp)
   2552 (define-caller-pattern copy-readtable (&optional form form) :lisp)
   2553 (define-caller-pattern readtablep (form) :lisp)
   2554 (define-caller-pattern set-syntax-from-char (form form &optional form form)
   2555   :lisp)
   2556 (define-caller-pattern set-macro-character (form fn &optional form) :lisp)
   2557 (define-caller-pattern get-macro-character (form (:optional form)) :lisp)
   2558 (define-caller-pattern make-dispatch-macro-character (form &optional form form)
   2559   :lisp)
   2560 (define-caller-pattern set-dispatch-macro-character
   2561   (form form fn (:optional form)) :lisp)
   2562 (define-caller-pattern get-dispatch-macro-character
   2563   (form form (:optional form)) :lisp)
   2564 (define-caller-pattern readtable-case (form) :lisp2)
   2565 (define-variable-pattern *print-readably* :lisp2)
   2566 (define-variable-pattern *print-escape* :lisp)
   2567 (define-variable-pattern *print-pretty* :lisp)
   2568 (define-variable-pattern *print-circle* :lisp)
   2569 (define-variable-pattern *print-base* :lisp)
   2570 (define-variable-pattern *print-radix* :lisp)
   2571 (define-variable-pattern *print-case* :lisp)
   2572 (define-variable-pattern *print-gensym* :lisp)
   2573 (define-variable-pattern *print-level* :lisp)
   2574 (define-variable-pattern *print-length* :lisp)
   2575 (define-variable-pattern *print-array* :lisp)
   2576 (define-caller-pattern with-standard-io-syntax 
   2577   ((:star declaration)
   2578    (:star form))
   2579   :lisp2)
   2580 
   2581 (define-caller-pattern read (&optional form form form form) :lisp)
   2582 (define-variable-pattern *read-default-float-format* :lisp)
   2583 (define-caller-pattern read-preserving-whitespace
   2584   (&optional form form form form) :lisp)
   2585 (define-caller-pattern read-delimited-list (form &optional form form) :lisp)
   2586 (define-caller-pattern read-line (&optional form form form form) :lisp)
   2587 (define-caller-pattern read-char (&optional form form form form) :lisp)
   2588 (define-caller-pattern unread-char (form (:optional form)) :lisp)
   2589 (define-caller-pattern peek-char (&optional form form form form) :lisp)
   2590 (define-caller-pattern listen ((:optional form)) :lisp)
   2591 (define-caller-pattern read-char-no-hang ((:star form)) :lisp)
   2592 (define-caller-pattern clear-input ((:optional form)) :lisp)
   2593 (define-caller-pattern read-from-string (form (:star form)) :lisp)
   2594 (define-caller-pattern parse-integer (form &rest :ignore) :lisp)
   2595 (define-caller-pattern read-byte ((:star form)) :lisp)
   2596 
   2597 (define-caller-pattern write (form &key (:star form)) :lisp)
   2598 (define-caller-pattern prin1 (form (:optional form)) :lisp)
   2599 (define-caller-pattern print (form (:optional form)) :lisp)
   2600 (define-caller-pattern pprint (form (:optional form)) :lisp)
   2601 (define-caller-pattern princ (form (:optional form)) :lisp)
   2602 (define-caller-pattern write-to-string (form &key (:star form)) :lisp)
   2603 (define-caller-pattern prin1-to-string (form) :lisp)
   2604 (define-caller-pattern princ-to-string (form) :lisp)
   2605 (define-caller-pattern write-char (form (:optional form)) :lisp)
   2606 (define-caller-pattern write-string (form &optional form &key (:star form))
   2607   :lisp)
   2608 (define-caller-pattern write-line (form &optional form &key (:star form))
   2609   :lisp)
   2610 (define-caller-pattern terpri ((:optional form)) :lisp)
   2611 (define-caller-pattern fresh-line ((:optional form)) :lisp)
   2612 (define-caller-pattern finish-output ((:optional form)) :lisp)
   2613 (define-caller-pattern force-output ((:optional form)) :lisp)
   2614 (define-caller-pattern clear-output ((:optional form)) :lisp)
   2615 (define-caller-pattern print-unreadable-object 
   2616   ((form form &key (:star form))
   2617    (:star declaration)
   2618    (:star form))
   2619   :lisp2)
   2620 (define-caller-pattern write-byte (form form) :lisp)
   2621 (define-caller-pattern format
   2622   (destination
   2623    control-string
   2624    (:rest format-arguments))
   2625   :lisp)
   2626 
   2627 (define-caller-pattern y-or-n-p (control-string (:star form)) :lisp)
   2628 (define-caller-pattern yes-or-no-p (control-string (:star form)) :lisp)
   2629 
   2630 ;;; Pathnames
   2631 (define-caller-pattern wild-pathname-p (form &optional form) :lisp2)
   2632 (define-caller-pattern pathname-match-p (form form) :lisp2)
   2633 (define-caller-pattern translate-pathname (form form form &key (:star form))
   2634   :lisp2)
   2635 
   2636 (define-caller-pattern logical-pathname (form) :lisp2)
   2637 (define-caller-pattern translate-logical-pathname (form &key (:star form))
   2638   :lisp2)
   2639 (define-caller-pattern logical-pathname-translations (form) :lisp2)
   2640 (define-caller-pattern load-logical-pathname-translations (form) :lisp2)
   2641 (define-caller-pattern compile-file-pathname (form &key form) :lisp2)
   2642 
   2643 (define-caller-pattern pathname (form) :lisp)
   2644 (define-caller-pattern truename (form) :lisp)
   2645 (define-caller-pattern parse-namestring ((:star form)) :lisp)
   2646 (define-caller-pattern merge-pathnames ((:star form)) :lisp)
   2647 (define-variable-pattern *default-pathname-defaults* :lisp)
   2648 (define-caller-pattern make-pathname ((:star form)) :lisp)
   2649 (define-caller-pattern pathnamep (form) :lisp)
   2650 (define-caller-pattern pathname-host (form) :lisp)
   2651 (define-caller-pattern pathname-device (form) :lisp)
   2652 (define-caller-pattern pathname-directory (form) :lisp)
   2653 (define-caller-pattern pathname-name (form) :lisp)
   2654 (define-caller-pattern pathname-type (form) :lisp)
   2655 (define-caller-pattern pathname-version (form) :lisp)
   2656 (define-caller-pattern namestring (form) :lisp)
   2657 (define-caller-pattern file-namestring (form) :lisp)
   2658 (define-caller-pattern directory-namestring (form) :lisp)
   2659 (define-caller-pattern host-namestring (form) :lisp)
   2660 (define-caller-pattern enough-namestring (form (:optional form)) :lisp)
   2661 (define-caller-pattern user-homedir-pathname (&optional form) :lisp)
   2662 (define-caller-pattern open (form &key (:star form)) :lisp)
   2663 (define-caller-pattern with-open-file
   2664   ((var form (:rest :ignore))
   2665    (:star declaration)
   2666    (:star form))
   2667  :lisp)
   2668 
   2669 (define-caller-pattern rename-file (form form) :lisp)
   2670 (define-caller-pattern delete-file (form) :lisp)
   2671 (define-caller-pattern probe-file (form) :lisp)
   2672 (define-caller-pattern file-write-date (form) :lisp)
   2673 (define-caller-pattern file-author (form) :lisp)
   2674 (define-caller-pattern file-position (form (:optional form)) :lisp)
   2675 (define-caller-pattern file-length (form) :lisp)
   2676 (define-caller-pattern file-string-length (form form) :lisp2)
   2677 (define-caller-pattern load (form &key (:star form)) :lisp)
   2678 (define-variable-pattern *load-verbose* :lisp)
   2679 (define-variable-pattern *load-print* :lisp2)
   2680 (define-variable-pattern *load-pathname* :lisp2)
   2681 (define-variable-pattern *load-truename* :lisp2)
   2682 (define-caller-pattern make-load-form (form) :lisp2)
   2683 (define-caller-pattern make-load-form-saving-slots (form &optional form)
   2684   :lisp2)
   2685 (define-caller-pattern directory (form &key (:star form)) :lisp)
   2686 
   2687 ;;; Errors
   2688 (define-caller-pattern error (form (:star form)) :lisp)
   2689 (define-caller-pattern cerror (form form (:star form)) :lisp)
   2690 (define-caller-pattern warn (form (:star form)) :lisp)
   2691 (define-variable-pattern *break-on-warnings* :lisp)
   2692 (define-caller-pattern break (&optional form (:star form)) :lisp)
   2693 (define-caller-pattern check-type (form form (:optional form)) :lisp)
   2694 (define-caller-pattern assert 
   2695   (form
   2696    (:optional ((:star var))
   2697 	      (:optional form (:star form)))) 
   2698   :lisp)
   2699 (define-caller-pattern etypecase (form (:star (symbol (:star form)))) :lisp)
   2700 (define-caller-pattern ctypecase (form (:star (symbol (:star form)))) :lisp)
   2701 (define-caller-pattern ecase
   2702   (form
   2703    (:star ((:or symbol ((:star symbol)))
   2704 	   (:star form))))
   2705   :lisp)
   2706 (define-caller-pattern ccase 
   2707   (form
   2708    (:star ((:or symbol ((:star symbol)))
   2709 	   (:star form))))
   2710   :lisp)
   2711 
   2712 ;;; The Compiler
   2713 (define-caller-pattern compile (form (:optional form)) :lisp)
   2714 (define-caller-pattern compile-file (form &key (:star form)) :lisp)
   2715 (define-variable-pattern *compile-verbose* :lisp2)
   2716 (define-variable-pattern *compile-print* :lisp2)
   2717 (define-variable-pattern *compile-file-pathname* :lisp2)
   2718 (define-variable-pattern *compile-file-truename* :lisp2)
   2719 (define-caller-pattern load-time-value (form (:optional form)) :lisp2)
   2720 (define-caller-pattern disassemble (form) :lisp)
   2721 (define-caller-pattern function-lambda-expression (fn) :lisp2)
   2722 (define-caller-pattern with-compilation-unit (((:star :ignore)) (:star form)) 
   2723   :lisp2)
   2724 
   2725 ;;; Documentation
   2726 (define-caller-pattern documentation (form form) :lisp)
   2727 (define-caller-pattern trace ((:star form)) :lisp)
   2728 (define-caller-pattern untrace ((:star form)) :lisp)
   2729 (define-caller-pattern step (form) :lisp)
   2730 (define-caller-pattern time (form) :lisp)
   2731 (define-caller-pattern describe (form &optional form) :lisp)
   2732 (define-caller-pattern describe-object (form &optional form) :lisp2)
   2733 (define-caller-pattern inspect (form) :lisp)
   2734 (define-caller-pattern room ((:optional form)) :lisp)
   2735 (define-caller-pattern ed ((:optional form)) :lisp)
   2736 (define-caller-pattern dribble ((:optional form)) :lisp)
   2737 (define-caller-pattern apropos (form (:optional form)) :lisp)
   2738 (define-caller-pattern apropos-list (form (:optional form)) :lisp)
   2739 (define-caller-pattern get-decoded-time () :lisp)
   2740 (define-caller-pattern get-universal-time () :lisp)
   2741 (define-caller-pattern decode-universal-time (form &optional form) :lisp)
   2742 (define-caller-pattern encode-universal-time 
   2743   (form form form form form form &optional form) :lisp)
   2744 (define-caller-pattern get-internal-run-time () :lisp)
   2745 (define-caller-pattern get-internal-real-time () :lisp)
   2746 (define-caller-pattern sleep (form) :lisp)
   2747 
   2748 (define-caller-pattern lisp-implementation-type () :lisp)
   2749 (define-caller-pattern lisp-implementation-version () :lisp)
   2750 (define-caller-pattern machine-type () :lisp)
   2751 (define-caller-pattern machine-version () :lisp)
   2752 (define-caller-pattern machine-instance () :lisp)
   2753 (define-caller-pattern software-type () :lisp)
   2754 (define-caller-pattern software-version () :lisp)
   2755 (define-caller-pattern short-site-name () :lisp)
   2756 (define-caller-pattern long-site-name () :lisp)
   2757 (define-variable-pattern *features* :lisp)
   2758 
   2759 (define-caller-pattern identity (form) :lisp)
   2760 
   2761 ;;; Pretty Printing
   2762 (define-variable-pattern *print-pprint-dispatch* :lisp2)
   2763 (define-variable-pattern *print-right-margin* :lisp2)
   2764 (define-variable-pattern *print-miser-width* :lisp2)
   2765 (define-variable-pattern *print-lines* :lisp2)
   2766 (define-caller-pattern pprint-newline (form &optional form) :lisp2)
   2767 (define-caller-pattern pprint-logical-block
   2768   ((var form &key (:star form))
   2769    (:star form))
   2770   :lisp2)
   2771 (define-caller-pattern pprint-exit-if-list-exhausted () :lisp2)
   2772 (define-caller-pattern pprint-pop () :lisp2)
   2773 (define-caller-pattern pprint-indent (form form &optional form) :lisp2)
   2774 (define-caller-pattern pprint-tab (form form form &optional form) :lisp2)
   2775 (define-caller-pattern pprint-fill (form form &optional form form) :lisp2)
   2776 (define-caller-pattern pprint-linear (form form &optional form form) :lisp2)
   2777 (define-caller-pattern pprint-tabular (form form &optional form form form)
   2778   :lisp2)
   2779 (define-caller-pattern formatter (control-string) :lisp2)
   2780 (define-caller-pattern copy-pprint-dispatch (&optional form) :lisp2)
   2781 (define-caller-pattern pprint-dispatch (form &optional form) :lisp2)
   2782 (define-caller-pattern set-pprint-dispatch (form form &optional form form)
   2783   :lisp2)
   2784 
   2785 ;;; CLOS
   2786 (define-caller-pattern add-method (fn form) :lisp2)
   2787 (define-caller-pattern call-method (form form) :lisp2)
   2788 (define-caller-pattern call-next-method ((:star form)) :lisp2)
   2789 (define-caller-pattern change-class (form form) :lisp2)
   2790 (define-caller-pattern class-name (form) :lisp2)
   2791 (define-caller-pattern class-of (form) :lisp2)
   2792 (define-caller-pattern compute-applicable-methods (fn (:star form)) :lisp2)
   2793 (define-caller-pattern defclass (name &rest :ignore) :lisp2)
   2794 (define-caller-pattern defgeneric (name lambda-list &rest :ignore) :lisp2)
   2795 (define-caller-pattern define-method-combination 
   2796   (name lambda-list ((:star :ignore))
   2797 	(:optional ((:eq :arguments) :ignore))
   2798 	(:optional ((:eq :generic-function) :ignore))
   2799 	(:star (:or declaration documentation-string))
   2800 	(:star form))
   2801   :lisp2)
   2802 (define-caller-pattern defmethod 
   2803   (name (:star symbol) lambda-list
   2804 	(:star (:or declaration documentation-string))
   2805 	(:star form))
   2806   :lisp2)
   2807 (define-caller-pattern ensure-generic-function (name &key (:star form)) :lisp2)
   2808 (define-caller-pattern find-class (form &optional form form) :lisp2)
   2809 (define-caller-pattern find-method (fn &rest :ignore) :lisp2)
   2810 (define-caller-pattern function-keywords (&rest :ignore) :lisp2)
   2811 (define-caller-pattern generic-flet (((:star (name lambda-list))) (:star form))
   2812   :lisp2)
   2813 (define-caller-pattern generic-labels 
   2814   (((:star (name lambda-list))) (:star form))
   2815   :lisp2)
   2816 (define-caller-pattern generic-function (lambda-list) :lisp2)
   2817 (define-caller-pattern initialize-instance (form &key (:star form)) :lisp2)
   2818 (define-caller-pattern invalid-method-error (fn form (:star form)) :lisp2)
   2819 (define-caller-pattern make-instance (fn (:star form)) :lisp2)
   2820 (define-caller-pattern make-instances-obsolete (fn) :lisp2)
   2821 (define-caller-pattern method-combination-error (form (:star form)) :lisp2)
   2822 (define-caller-pattern method-qualifiers (fn) :lisp2)
   2823 (define-caller-pattern next-method-p () :lisp2)
   2824 (define-caller-pattern no-applicable-method (fn (:star form)) :lisp2)
   2825 (define-caller-pattern no-next-method (fn (:star form)) :lisp2)
   2826 (define-caller-pattern print-object (form form) :lisp2)
   2827 (define-caller-pattern reinitialize-instance (form (:star form)) :lisp2)
   2828 (define-caller-pattern remove-method (fn form) :lisp2)
   2829 (define-caller-pattern shared-initialize (form form (:star form)) :lisp2)
   2830 (define-caller-pattern slot-boundp (form form) :lisp2)
   2831 (define-caller-pattern slot-exists-p (form form) :lisp2)
   2832 (define-caller-pattern slot-makeunbound (form form) :lisp2)
   2833 (define-caller-pattern slot-missing (fn form form form &optional form) :lisp2)
   2834 (define-caller-pattern slot-unbound (fn form form) :lisp2)
   2835 (define-caller-pattern slot-value (form form) :lisp2)
   2836 (define-caller-pattern update-instance-for-different-class 
   2837   (form form (:star form)) :lisp2)
   2838 (define-caller-pattern update-instance-for-redefined-class 
   2839   (form form (:star form)) :lisp2)
   2840 (define-caller-pattern with-accessors
   2841   (((:star :ignore)) form
   2842    (:star declaration)
   2843    (:star form))
   2844   :lisp2)
   2845 (define-caller-pattern with-added-methods
   2846   ((name lambda-list) form
   2847    (:star form))
   2848   :lisp2)
   2849 (define-caller-pattern with-slots
   2850   (((:star :ignore)) form
   2851    (:star declaration)
   2852    (:star form))
   2853   :lisp2)
   2854 
   2855 ;;; Conditions
   2856 (define-caller-pattern signal (form (:star form)) :lisp2)
   2857 (define-variable-pattern *break-on-signals* :lisp2)
   2858 (define-caller-pattern handler-case (form (:star (form ((:optional var))
   2859 						       (:star form))))
   2860   :lisp2)
   2861 (define-caller-pattern ignore-errors ((:star form)) :lisp2)
   2862 (define-caller-pattern handler-bind (((:star (form form)))
   2863 				     (:star form))
   2864   :lisp2)
   2865 (define-caller-pattern define-condition (name &rest :ignore) :lisp2)
   2866 (define-caller-pattern make-condition (form &rest :ignore) :lisp2)
   2867 (define-caller-pattern with-simple-restart
   2868   ((name form (:star form)) (:star form)) :lisp2)
   2869 (define-caller-pattern restart-case 
   2870   (form
   2871    (:star (form form (:star form))))
   2872   :lisp2)
   2873 (define-caller-pattern restart-bind
   2874   (((:star (name fn &key (:star form))))
   2875    (:star form))
   2876   :lisp2)
   2877 (define-caller-pattern with-condition-restarts
   2878   (form form
   2879 	(:star declaration)
   2880 	(:star form))
   2881   :lisp2)
   2882 (define-caller-pattern compute-restarts (&optional form) :lisp2)
   2883 (define-caller-pattern restart-name (form) :lisp2)
   2884 (define-caller-pattern find-restart (form &optional form) :lisp2)
   2885 (define-caller-pattern invoke-restart (form (:star form)) :lisp2)
   2886 (define-caller-pattern invoke-restart-interactively (form) :lisp2)
   2887 (define-caller-pattern abort (&optional form) :lisp2)
   2888 (define-caller-pattern continue (&optional form) :lisp2)
   2889 (define-caller-pattern muffle-warning (&optional form) :lisp2)
   2890 (define-caller-pattern store-value (form &optional form) :lisp2)
   2891 (define-caller-pattern use-value (form &optional form) :lisp2)
   2892 (define-caller-pattern invoke-debugger (form) :lisp2)
   2893 (define-variable-pattern *debugger-hook* :lisp2)
   2894 (define-caller-pattern simple-condition-format-string (form) :lisp2)
   2895 (define-caller-pattern simple-condition-format-arguments (form) :lisp2)
   2896 (define-caller-pattern type-error-datum (form) :lisp2)
   2897 (define-caller-pattern type-error-expected-type (form) :lisp2)
   2898 (define-caller-pattern package-error-package (form) :lisp2)
   2899 (define-caller-pattern stream-error-stream (form) :lisp2)
   2900 (define-caller-pattern file-error-pathname (form) :lisp2)
   2901 (define-caller-pattern cell-error-name (form) :lisp2)
   2902 (define-caller-pattern arithmetic-error-operation (form) :lisp2)
   2903 (define-caller-pattern arithmetic-error-operands (form) :lisp2)
   2904 
   2905 ;;; For ZetaLisp Flavors
   2906 (define-caller-pattern send (form fn (:star form)) :flavors)