1 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; This software is derived from the CMU CL system, which was
5 ;;;; written at Carnegie Mellon University and released into the
6 ;;;; public domain. The software is in the public domain and is
7 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
8 ;;;; files for more information.
10 (defpackage :sb-introspect-test
/xref
11 (:use
"SB-INTROSPECT" "CL" "SB-RT"))
13 (in-package :sb-introspect-test
/xref
)
16 (defconstant +z
+ 'zzz
)
35 ;; reference *a*, set *a*, bind *a*
78 (defvar *b
* (or (xref/2) a
)))
83 ;; call xref/2 twice (not three times)
91 ;; Methods work, even ones with lots of arguments.
92 (defmethod xref/10 (a b c d e f g h
(i fixnum
))
95 ;; Separate methods are indeed separate
96 (defmethod xref/11 ((a fixnum
))
100 (defmethod xref/11 ((a (eql 'z
)))
104 (defmethod xref/11 ((a float
))
108 (declaim (inline inline
/1))
113 (eval-when (:compile-toplevel
:load-toplevel
)
116 ;; Counts as calling xref/2
120 ;; Doesn't count as calling xref/3, or referring to +z+ / *a*
123 ;; last node of block should also be taken into account
130 (sb-ext:defglobal
**global
** 31)
138 ;; calling a function in a macro body
145 (defun macro-use/1 ()
148 ;; expanding a macro in an flet/labels
149 (defun macro-use/2 ()
150 (flet ((inner-flet ()
154 ;; expanding a macro in an toplevel flet/labels
155 (flet ((outer-flet ()
157 (defun macro-use/3 ()
160 ;; expanding a macro in an inlined flet/labels
161 (defun macro-use/4 ()
162 (flet ((inner-flet ()
164 (declare (inline inner-flet
))
167 (declaim (inline inline
/2))
171 ;; Inlining inline/3 doesn't count as macroexpanding macro/1
172 (defun macro-use/5 ()
175 ;;; Code in the macrolet definition bodies is currently not considered
176 ;;; at all for XREF. Maybe it should be, but it's slightly tricky to
186 (macrolet ((inner-m ()
190 ;;; Inlining functions with non-trivial lambda-lists.
191 (declaim (inline inline
/3))
192 (defun inline/3 (a &optional b
&key c d
)
194 (defun inline/3-user
/1 (a)
196 (defun inline/3-user
/2 (a b
)
198 (defun inline/3-user
/3 (a b c
)
200 (defun inline/3-user
/4 (a b c d
)
201 (inline/3 a b
:d d
:c c
))
203 (declaim (inline inline
/4))
204 (defun inline/4 (a &rest more
)
206 (defun inline/4-user
()
209 ;;; Test references to / from compiler-macros and source-transforms
211 (define-compiler-macro cmacro
(x)
213 (defstruct struct slot
)
214 (defun source-user (x)
215 (cmacro (struct-slot x
)))
217 ;;; Test specialization
219 (defclass a-class
() ())
220 (defclass a-subclass
(a-class) ())
222 (defstruct a-structure
)
223 (defstruct (a-substructure (:include a-structure
)))
225 (defvar *an-instance-of-a-class
* (make-instance 'a-class
))
226 (defvar *an-instance-of-a-subclass
* (make-instance 'a-subclass
))
228 (defvar *an-instance-of-a-structure
* (make-a-structure))
229 (defvar *an-instance-of-a-substructure
* (make-a-substructure))
231 (defmethod a-gf-1 ((x a-class
)))
232 (defmethod a-gf-1 ((x a-structure
)))
234 (defmethod a-gf-2 ((x (eql *an-instance-of-a-class
*))))
235 (defmethod a-gf-2 ((x (eql *an-instance-of-a-structure
*))))
237 (defmethod a-gf-3 ((x (eql *an-instance-of-a-subclass
*))))
238 (defmethod a-gf-3 ((x (eql *an-instance-of-a-substructure
*))))
240 (defun called-by-traced-fun ())
243 (called-by-traced-fun))
248 (defun called-by-interpreted-funs ())
250 (let ((sb-ext:*evaluator-mode
* :interpret
))
251 (eval '(defun interpreted-fun ()
252 (called-by-interpreted-funs))))
254 (let ((sb-ext:*evaluator-mode
* :interpret
))
255 (eval '(defun traced-interpreted-fun ()
256 (called-by-interpreted-funs))))
257 (trace traced-interpreted-fun
))