1.0.23.37: more CLOS and classoid thread safety
[sbcl/tcr.git] / contrib / sb-introspect / xref-test-data.lisp
bloba23c328493623bcdfbcfd43526125e4a1358c527
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 ;; last node of block should also be taken into account
106 (defun xref/13 (x)
107 (setf *a* x))
109 (defun xref/14 ()
110 *a*)
112 ;; calling a function in a macro body
113 (defmacro macro/1 ()
114 (when nil
115 (xref/12))
116 nil)
118 ;; expanding a macro
119 (defun macro-use/1 ()
120 (macro/1))
122 ;; expanding a macro in an flet/labels
123 (defun macro-use/2 ()
124 (flet ((inner-flet ()
125 (macro/1)))
126 (inner-flet)))
128 ;; expanding a macro in an toplevel flet/labels
129 (flet ((outer-flet ()
130 (macro/1)))
131 (defun macro-use/3 ()
132 (outer-flet)))
134 ;; expanding a macro in an inlined flet/labels
135 (defun macro-use/4 ()
136 (flet ((inner-flet ()
137 (macro/1)))
138 (declare (inline inner-flet))
139 (inner-flet)))
141 (declaim (inline inline/2))
142 (defun inline/2 ()
143 (macro/1))
145 ;; Inlining inline/3 doesn't count as macroexpanding macro/1
146 (defun macro-use/5 ()
147 (inline/2))
149 ;;; Code in the macrolet definition bodies is currently not considered
150 ;;; at all for XREF. Maybe it should be, but it's slightly tricky to
151 ;;; implement.
152 #+nil
153 (progn
154 (defun macrolet/1 ()
155 (macrolet ((a ()
156 (inline/2)
158 (a)))
159 (defun macrolet/2 ()
160 (macrolet ((inner-m ()
161 (macro/1)))
162 (inner-m))))
164 ;;; Test references to / from compiler-macros