1.0.5.30: small PCL re-organization
[sbcl/lichteblau.git] / contrib / sb-introspect / xref-test-data.lisp
blobf5298391e08c29b16dded8a19755752770a09c37
1 (defvar *a* nil)
2 (defconstant +z+ 'zzz)
4 (defun foo () 1)
5 (defun bar (x) x)
7 ;; Should:
8 ;; reference *a*
9 ;; call bar
10 ;; not call foo
11 ;; not call xref/2
12 (defun xref/1 ()
13 (flet ((foo ()
14 (bar *a*)))
15 (flet ((xref/2 ()
16 1))
17 (foo)
18 (xref/2))))
20 ;; Should:
21 ;; reference *a*, set *a*, bind *a*
22 ;; call xref/1
23 ;; not bind b
24 (defun xref/2 ()
25 (setf *a* *a*)
26 (let* ((b 1)
27 (*a* b))
28 (when nil
29 (xref/1))))
31 (let ((x 1))
32 ;; Should:
33 ;; call bar
34 ;; not reference *a*
35 (defun xref/3 ()
36 (bar x))
37 ;; Should:
38 ;; not call bar
39 ;; reference *a*
40 (defun xref/4 ()
41 (setf x *a*)))
44 (flet ((z ()
45 (xref/2)))
46 ;; Should:
47 ;; call xref/2
48 ;; not call z
49 (defun xref/5 ()
50 (z))
51 ;; Should:
52 ;; call xref/2
53 ;; not call z
54 (defun xref/6 ()
55 (z)))
57 (defun xref/7 ()
58 (flet ((a ()
59 (xref/6)))
60 #'a))
62 ;; call xref/2
63 (let ((a 1))
64 (defvar *b* (or (xref/2) a)))
66 ;; call xref/6
67 (defvar *c* (xref/6))
69 ;; call xref/2 twice (not three times)
70 (defun xref/8 ()
71 (flet ((a ()
72 (xref/2)))
73 (a)
74 (a)
75 (xref/2)))
77 ;; Methods work, even ones with lots of arguments.
78 (defmethod xref/10 (a b c d e f g h (i fixnum))
79 (xref/2))
81 ;; Separate methods are indeed separate
82 (defmethod xref/11 ((a fixnum))
83 (declare (ignore a))
84 (xref/2))
86 (defmethod xref/11 ((a float))
87 (declare (ignore a))
88 (xref/3))
90 (declaim (inline inline/1))
91 (defun inline/1 ()
92 (xref/3)
93 (values +z+ *a*))
95 (eval-when (:compile-toplevel :load-toplevel)
96 (defun xref/12 ()
97 (flet ((a ()
98 ;; Counts as calling xref/2
99 (xref/2)))
100 (declare (inline a))
102 ;; Doesn't count as calling xref/3, or referring to +z+ / *a*
103 (inline/1))))
105 ;; calling a function in a macro body
106 (defmacro macro/1 ()
107 (when nil
108 (xref/12))
109 nil)
111 ;; expanding a macro
112 (defun macro-use/1 ()
113 (macro/1))
115 ;; expanding a macro in an flet/labels
116 (defun macro-use/2 ()
117 (flet ((inner-flet ()
118 (macro/1)))
119 (inner-flet)))
121 ;; expanding a macro in an toplevel flet/labels
122 (flet ((outer-flet ()
123 (macro/1)))
124 (defun macro-use/3 ()
125 (outer-flet)))
127 ;; expanding a macro in an inlined flet/labels
128 (defun macro-use/4 ()
129 (flet ((inner-flet ()
130 (macro/1)))
131 (declare (inline inner-flet))
132 (inner-flet)))
134 (declaim (inline inline/2))
135 (defun inline/2 ()
136 (macro/1))
138 ;; Inlining inline/3 doesn't count as macroexpanding macro/1
139 (defun macro-use/5 ()
140 (inline/2))
142 ;;; Code in the macrolet definition bodies is currently not considered
143 ;;; at all for XREF. Maybe it should be, but it's slightly tricky to
144 ;;; implement.
145 #+nil
146 (progn
147 (defun macrolet/1 ()
148 (macrolet ((a ()
149 (inline/2)
151 (a)))
152 (defun macrolet/2 ()
153 (macrolet ((inner-m ()
154 (macro/1)))
155 (inner-m))))
157 ;;; Test references to / from compiler-macros