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 float))
104 (declaim (inline inline/1))
109 (eval-when (:compile-toplevel :load-toplevel)
112 ;; Counts as calling xref/2
116 ;; Doesn't count as calling xref/3, or referring to +z+ / *a*
119 ;; last node of block should also be taken into account
126 ;; calling a function in a macro body
133 (defun macro-use/1 ()
136 ;; expanding a macro in an flet/labels
137 (defun macro-use/2 ()
138 (flet ((inner-flet ()
142 ;; expanding a macro in an toplevel flet/labels
143 (flet ((outer-flet ()
145 (defun macro-use/3 ()
148 ;; expanding a macro in an inlined flet/labels
149 (defun macro-use/4 ()
150 (flet ((inner-flet ()
152 (declare (inline inner-flet))
155 (declaim (inline inline/2))
159 ;; Inlining inline/3 doesn't count as macroexpanding macro/1
160 (defun macro-use/5 ()
163 ;;; Code in the macrolet definition bodies is currently not considered
164 ;;; at all for XREF. Maybe it should be, but it's slightly tricky to
174 (macrolet ((inner-m ()
178 ;;; Inlining functions with non-trivial lambda-lists.
179 (declaim (inline inline/3))
180 (defun inline/3 (a &optional b &key c d)
182 (defun inline/3-user/1 (a)
184 (defun inline/3-user/2 (a b)
186 (defun inline/3-user/3 (a b c)
188 (defun inline/3-user/4 (a b c d)
189 (inline/3 a b :d d :c c))
191 (declaim (inline inline/4))
192 (defun inline/4 (a &rest more)
194 (defun inline/4-user ()
197 ;;; Test references to / from compiler-macros and source-transforms
199 (define-compiler-macro cmacro (x)
201 (defstruct struct slot)
202 (defun source-user (x)
203 (cmacro (struct-slot x)))
205 ;;; Test specialization
207 (defclass a-class () ())
208 (defclass a-subclass (a-class) ())
210 (defstruct a-structure)
211 (defstruct (a-substructure (:include a-structure)))
213 (defvar *an-instance-of-a-class* (make-instance 'a-class))
214 (defvar *an-instance-of-a-subclass* (make-instance 'a-subclass))
216 (defvar *an-instance-of-a-structure* (make-a-structure))
217 (defvar *an-instance-of-a-substructure* (make-a-substructure))
219 (defmethod a-gf-1 ((x a-class)))
220 (defmethod a-gf-1 ((x a-structure)))
222 (defmethod a-gf-2 ((x (eql *an-instance-of-a-class*))))
223 (defmethod a-gf-2 ((x (eql *an-instance-of-a-structure*))))
225 (defmethod a-gf-3 ((x (eql *an-instance-of-a-subclass*))))
226 (defmethod a-gf-3 ((x (eql *an-instance-of-a-substructure*))))