PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/local-lisp/slime/swank-cmucl.lisp

https://bitbucket.org/sakito/dot.emacs.d/
Lisp | 2578 lines | 2025 code | 318 blank | 235 comment | 69 complexity | ff4a846397a167fa5dd1d90df48a40dc MD5 | raw file
Possible License(s): GPL-3.0, CC-BY-SA-4.0, GPL-2.0, Unlicense

Large files files are truncated, but you can click here to view the full file

  1. ;;; -*- indent-tabs-mode: nil; outline-regexp: ";;;;+" -*-
  2. ;;;
  3. ;;; License: Public Domain
  4. ;;;
  5. ;;;; Introduction
  6. ;;;
  7. ;;; This is the CMUCL implementation of the `swank-backend' package.
  8. (in-package :swank-backend)
  9. (import-swank-mop-symbols :pcl '(:slot-definition-documentation))
  10. (defun swank-mop:slot-definition-documentation (slot)
  11. (documentation slot t))
  12. ;;;; "Hot fixes"
  13. ;;;
  14. ;;; Here are necessary bugfixes to the oldest supported version of
  15. ;;; CMUCL (currently 18e). Any fixes placed here should also be
  16. ;;; submitted to the `cmucl-imp' mailing list and confirmed as
  17. ;;; good. When a new release is made that includes the fixes we should
  18. ;;; promptly delete them from here. It is enough to be compatible with
  19. ;;; the latest release.
  20. (in-package :lisp)
  21. ;;; `READ-SEQUENCE' with large sequences has problems in 18e. This new
  22. ;;; definition works better.
  23. #+cmu18
  24. (progn
  25. (let ((s (find-symbol (string :*enable-package-locked-errors*) :lisp)))
  26. (when s
  27. (setf (symbol-value s) nil)))
  28. (defun read-into-simple-string (s stream start end)
  29. (declare (type simple-string s))
  30. (declare (type stream stream))
  31. (declare (type index start end))
  32. (unless (subtypep (stream-element-type stream) 'character)
  33. (error 'type-error
  34. :datum (read-char stream nil #\Null)
  35. :expected-type (stream-element-type stream)
  36. :format-control "Trying to read characters from a binary stream."))
  37. ;; Let's go as low level as it seems reasonable.
  38. (let* ((numbytes (- end start))
  39. (total-bytes 0))
  40. ;; read-n-bytes may return fewer bytes than requested, so we need
  41. ;; to keep trying.
  42. (loop while (plusp numbytes) do
  43. (let ((bytes-read (system:read-n-bytes stream s start numbytes nil)))
  44. (when (zerop bytes-read)
  45. (return-from read-into-simple-string total-bytes))
  46. (incf total-bytes bytes-read)
  47. (incf start bytes-read)
  48. (decf numbytes bytes-read)))
  49. total-bytes))
  50. (let ((s (find-symbol (string :*enable-package-locked-errors*) :lisp)))
  51. (when s
  52. (setf (symbol-value s) t)))
  53. )
  54. (in-package :swank-backend)
  55. ;;;; TCP server
  56. ;;;
  57. ;;; In CMUCL we support all communication styles. By default we use
  58. ;;; `:SIGIO' because it is the most responsive, but it's somewhat
  59. ;;; dangerous: CMUCL is not in general "signal safe", and you don't
  60. ;;; know for sure what you'll be interrupting. Both `:FD-HANDLER' and
  61. ;;; `:SPAWN' are reasonable alternatives.
  62. (defimplementation preferred-communication-style ()
  63. :sigio)
  64. #-(or darwin mips)
  65. (defimplementation create-socket (host port)
  66. (let* ((addr (resolve-hostname host))
  67. (addr (if (not (find-symbol "SOCKET-ERROR" :ext))
  68. (ext:htonl addr)
  69. addr)))
  70. (ext:create-inet-listener port :stream :reuse-address t :host addr)))
  71. ;; There seems to be a bug in create-inet-listener on Mac/OSX and Irix.
  72. #+(or darwin mips)
  73. (defimplementation create-socket (host port)
  74. (declare (ignore host))
  75. (ext:create-inet-listener port :stream :reuse-address t))
  76. (defimplementation local-port (socket)
  77. (nth-value 1 (ext::get-socket-host-and-port (socket-fd socket))))
  78. (defimplementation close-socket (socket)
  79. (let ((fd (socket-fd socket)))
  80. (sys:invalidate-descriptor fd)
  81. (ext:close-socket fd)))
  82. (defimplementation accept-connection (socket &key
  83. external-format buffering timeout)
  84. (declare (ignore timeout))
  85. (make-socket-io-stream (ext:accept-tcp-connection socket)
  86. (or buffering :full)
  87. (or external-format :iso-8859-1)))
  88. ;;;;; Sockets
  89. (defimplementation socket-fd (socket)
  90. "Return the filedescriptor for the socket represented by SOCKET."
  91. (etypecase socket
  92. (fixnum socket)
  93. (sys:fd-stream (sys:fd-stream-fd socket))))
  94. (defun resolve-hostname (hostname)
  95. "Return the IP address of HOSTNAME as an integer (in host byte-order)."
  96. (let ((hostent (ext:lookup-host-entry hostname)))
  97. (car (ext:host-entry-addr-list hostent))))
  98. (defvar *external-format-to-coding-system*
  99. '((:iso-8859-1
  100. "latin-1" "latin-1-unix" "iso-latin-1-unix"
  101. "iso-8859-1" "iso-8859-1-unix")
  102. #+unicode
  103. (:utf-8 "utf-8" "utf-8-unix")))
  104. (defimplementation find-external-format (coding-system)
  105. (car (rassoc-if (lambda (x) (member coding-system x :test #'equal))
  106. *external-format-to-coding-system*)))
  107. (defun make-socket-io-stream (fd buffering external-format)
  108. "Create a new input/output fd-stream for FD."
  109. #-unicode(declare (ignore external-format))
  110. (sys:make-fd-stream fd :input t :output t :element-type 'base-char
  111. :buffering buffering
  112. #+unicode :external-format
  113. #+unicode external-format))
  114. (defimplementation make-fd-stream (fd external-format)
  115. (make-socket-io-stream fd :full external-format))
  116. (defimplementation dup (fd)
  117. (multiple-value-bind (clone error) (unix:unix-dup fd)
  118. (unless clone (error "dup failed: ~a" (unix:get-unix-error-msg error)))
  119. clone))
  120. (defimplementation command-line-args ()
  121. ext:*command-line-strings*)
  122. (defimplementation exec-image (image-file args)
  123. (multiple-value-bind (ok error)
  124. (unix:unix-execve (car (command-line-args))
  125. (list* (car (command-line-args))
  126. "-core" image-file
  127. "-noinit"
  128. args))
  129. (error "~a" (unix:get-unix-error-msg error))
  130. ok))
  131. ;;;;; Signal-driven I/O
  132. (defimplementation install-sigint-handler (function)
  133. (sys:enable-interrupt :sigint (lambda (signal code scp)
  134. (declare (ignore signal code scp))
  135. (funcall function))))
  136. (defvar *sigio-handlers* '()
  137. "List of (key . function) pairs.
  138. All functions are called on SIGIO, and the key is used for removing
  139. specific functions.")
  140. (defun reset-sigio-handlers () (setq *sigio-handlers* '()))
  141. ;; All file handlers are invalid afer reload.
  142. (pushnew 'reset-sigio-handlers ext:*after-save-initializations*)
  143. (defun set-sigio-handler ()
  144. (sys:enable-interrupt :sigio (lambda (signal code scp)
  145. (sigio-handler signal code scp))))
  146. (defun sigio-handler (signal code scp)
  147. (declare (ignore signal code scp))
  148. (mapc #'funcall (mapcar #'cdr *sigio-handlers*)))
  149. (defun fcntl (fd command arg)
  150. "fcntl(2) - manipulate a file descriptor."
  151. (multiple-value-bind (ok error) (unix:unix-fcntl fd command arg)
  152. (cond (ok)
  153. (t (error "fcntl: ~A" (unix:get-unix-error-msg error))))))
  154. (defimplementation add-sigio-handler (socket fn)
  155. (set-sigio-handler)
  156. (let ((fd (socket-fd socket)))
  157. (fcntl fd unix:f-setown (unix:unix-getpid))
  158. (let ((old-flags (fcntl fd unix:f-getfl 0)))
  159. (fcntl fd unix:f-setfl (logior old-flags unix:fasync)))
  160. (assert (not (assoc fd *sigio-handlers*)))
  161. (push (cons fd fn) *sigio-handlers*)))
  162. (defimplementation remove-sigio-handlers (socket)
  163. (let ((fd (socket-fd socket)))
  164. (when (assoc fd *sigio-handlers*)
  165. (setf *sigio-handlers* (remove fd *sigio-handlers* :key #'car))
  166. (let ((old-flags (fcntl fd unix:f-getfl 0)))
  167. (fcntl fd unix:f-setfl (logandc2 old-flags unix:fasync)))
  168. (sys:invalidate-descriptor fd))
  169. (assert (not (assoc fd *sigio-handlers*)))
  170. (when (null *sigio-handlers*)
  171. (sys:default-interrupt :sigio))))
  172. ;;;;; SERVE-EVENT
  173. (defimplementation add-fd-handler (socket fn)
  174. (let ((fd (socket-fd socket)))
  175. (sys:add-fd-handler fd :input (lambda (_) _ (funcall fn)))))
  176. (defimplementation remove-fd-handlers (socket)
  177. (sys:invalidate-descriptor (socket-fd socket)))
  178. (defimplementation wait-for-input (streams &optional timeout)
  179. (assert (member timeout '(nil t)))
  180. (loop
  181. (let ((ready (remove-if-not #'listen streams)))
  182. (when ready (return ready)))
  183. (when timeout (return nil))
  184. (multiple-value-bind (in out) (make-pipe)
  185. (let* ((f (constantly t))
  186. (handlers (loop for s in (cons in (mapcar #'to-fd-stream streams))
  187. collect (add-one-shot-handler s f))))
  188. (unwind-protect
  189. (let ((*interrupt-queued-handler* (lambda ()
  190. (write-char #\! out))))
  191. (when (check-slime-interrupts) (return :interrupt))
  192. (sys:serve-event))
  193. (mapc #'sys:remove-fd-handler handlers)
  194. (close in)
  195. (close out))))))
  196. (defun to-fd-stream (stream)
  197. (etypecase stream
  198. (sys:fd-stream stream)
  199. (synonym-stream
  200. (to-fd-stream
  201. (symbol-value (synonym-stream-symbol stream))))
  202. (two-way-stream
  203. (to-fd-stream (two-way-stream-input-stream stream)))))
  204. (defun add-one-shot-handler (stream function)
  205. (let (handler)
  206. (setq handler (sys:add-fd-handler (sys:fd-stream-fd stream) :input
  207. (lambda (fd)
  208. (declare (ignore fd))
  209. (sys:remove-fd-handler handler)
  210. (funcall function stream))))))
  211. (defun make-pipe ()
  212. (multiple-value-bind (in out) (unix:unix-pipe)
  213. (values (sys:make-fd-stream in :input t :buffering :none)
  214. (sys:make-fd-stream out :output t :buffering :none))))
  215. ;;;; Stream handling
  216. ;;; XXX: How come we don't use Gray streams in CMUCL too? -luke (15/May/2004)
  217. (defimplementation make-output-stream (write-string)
  218. (make-slime-output-stream write-string))
  219. (defimplementation make-input-stream (read-string)
  220. (make-slime-input-stream read-string))
  221. (defstruct (slime-output-stream
  222. (:include lisp::lisp-stream
  223. (lisp::misc #'sos/misc)
  224. (lisp::out #'sos/write-char)
  225. (lisp::sout #'sos/write-string))
  226. (:conc-name sos.)
  227. (:print-function %print-slime-output-stream)
  228. (:constructor make-slime-output-stream (output-fn)))
  229. (output-fn nil :type function)
  230. (buffer (make-string 4000) :type string)
  231. (index 0 :type kernel:index)
  232. (column 0 :type kernel:index))
  233. (defun %print-slime-output-stream (s stream d)
  234. (declare (ignore d))
  235. (print-unreadable-object (s stream :type t :identity t)))
  236. (defun sos/write-char (stream char)
  237. (let ((pending-output nil))
  238. (system:without-interrupts
  239. (let ((buffer (sos.buffer stream))
  240. (index (sos.index stream)))
  241. (setf (schar buffer index) char)
  242. (setf (sos.index stream) (1+ index))
  243. (incf (sos.column stream))
  244. (when (char= #\newline char)
  245. (setf (sos.column stream) 0)
  246. #+(or)(setq pending-output (sos/reset-buffer stream))
  247. )
  248. (when (= index (1- (length buffer)))
  249. (setq pending-output (sos/reset-buffer stream)))))
  250. (when pending-output
  251. (funcall (sos.output-fn stream) pending-output)))
  252. char)
  253. (defun sos/write-string (stream string start end)
  254. (loop for i from start below end
  255. do (sos/write-char stream (aref string i))))
  256. (defun sos/flush (stream)
  257. (let ((string (sos/reset-buffer stream)))
  258. (when string
  259. (funcall (sos.output-fn stream) string))
  260. nil))
  261. (defun sos/reset-buffer (stream)
  262. (system:without-interrupts
  263. (let ((end (sos.index stream)))
  264. (unless (zerop end)
  265. (prog1 (subseq (sos.buffer stream) 0 end)
  266. (setf (sos.index stream) 0))))))
  267. (defun sos/misc (stream operation &optional arg1 arg2)
  268. (declare (ignore arg1 arg2))
  269. (case operation
  270. ((:force-output :finish-output) (sos/flush stream))
  271. (:charpos (sos.column stream))
  272. (:line-length 75)
  273. (:file-position nil)
  274. (:element-type 'base-char)
  275. (:get-command nil)
  276. (:close nil)
  277. (t (format *terminal-io* "~&~Astream: ~S~%" stream operation))))
  278. (defstruct (slime-input-stream
  279. (:include string-stream
  280. (lisp::in #'sis/in)
  281. (lisp::misc #'sis/misc))
  282. (:conc-name sis.)
  283. (:print-function %print-slime-output-stream)
  284. (:constructor make-slime-input-stream (input-fn)))
  285. (input-fn nil :type function)
  286. (buffer "" :type string)
  287. (index 0 :type kernel:index))
  288. (defun sis/in (stream eof-errorp eof-value)
  289. (let ((index (sis.index stream))
  290. (buffer (sis.buffer stream)))
  291. (when (= index (length buffer))
  292. (let ((string (funcall (sis.input-fn stream))))
  293. (cond ((zerop (length string))
  294. (return-from sis/in
  295. (if eof-errorp
  296. (error (make-condition 'end-of-file :stream stream))
  297. eof-value)))
  298. (t
  299. (setf buffer string)
  300. (setf (sis.buffer stream) buffer)
  301. (setf index 0)))))
  302. (prog1 (aref buffer index)
  303. (setf (sis.index stream) (1+ index)))))
  304. (defun sis/misc (stream operation &optional arg1 arg2)
  305. (declare (ignore arg2))
  306. (ecase operation
  307. (:file-position nil)
  308. (:file-length nil)
  309. (:unread (setf (aref (sis.buffer stream)
  310. (decf (sis.index stream)))
  311. arg1))
  312. (:clear-input
  313. (setf (sis.index stream) 0
  314. (sis.buffer stream) ""))
  315. (:listen (< (sis.index stream) (length (sis.buffer stream))))
  316. (:charpos nil)
  317. (:line-length nil)
  318. (:get-command nil)
  319. (:element-type 'base-char)
  320. (:close nil)
  321. (:interactive-p t)))
  322. ;;;; Compilation Commands
  323. (defvar *previous-compiler-condition* nil
  324. "Used to detect duplicates.")
  325. (defvar *previous-context* nil
  326. "Previous compiler error context.")
  327. (defvar *buffer-name* nil
  328. "The name of the Emacs buffer we are compiling from.
  329. NIL if we aren't compiling from a buffer.")
  330. (defvar *buffer-start-position* nil)
  331. (defvar *buffer-substring* nil)
  332. (defimplementation call-with-compilation-hooks (function)
  333. (let ((*previous-compiler-condition* nil)
  334. (*previous-context* nil)
  335. (*print-readably* nil))
  336. (handler-bind ((c::compiler-error #'handle-notification-condition)
  337. (c::style-warning #'handle-notification-condition)
  338. (c::warning #'handle-notification-condition))
  339. (funcall function))))
  340. (defimplementation swank-compile-file (input-file output-file
  341. load-p external-format
  342. &key policy)
  343. (declare (ignore external-format policy))
  344. (clear-xref-info input-file)
  345. (with-compilation-hooks ()
  346. (let ((*buffer-name* nil)
  347. (ext:*ignore-extra-close-parentheses* nil))
  348. (multiple-value-bind (output-file warnings-p failure-p)
  349. (compile-file input-file :output-file output-file)
  350. (values output-file warnings-p
  351. (or failure-p
  352. (when load-p
  353. ;; Cache the latest source file for definition-finding.
  354. (source-cache-get input-file
  355. (file-write-date input-file))
  356. (not (load output-file)))))))))
  357. (defimplementation swank-compile-string (string &key buffer position filename
  358. policy)
  359. (declare (ignore filename policy))
  360. (with-compilation-hooks ()
  361. (let ((*buffer-name* buffer)
  362. (*buffer-start-position* position)
  363. (*buffer-substring* string)
  364. (source-info (list :emacs-buffer buffer
  365. :emacs-buffer-offset position
  366. :emacs-buffer-string string)))
  367. (with-input-from-string (stream string)
  368. (let ((failurep (ext:compile-from-stream stream :source-info
  369. source-info)))
  370. (not failurep))))))
  371. ;;;;; Trapping notes
  372. ;;;
  373. ;;; We intercept conditions from the compiler and resignal them as
  374. ;;; `SWANK:COMPILER-CONDITION's.
  375. (defun handle-notification-condition (condition)
  376. "Handle a condition caused by a compiler warning."
  377. (unless (eq condition *previous-compiler-condition*)
  378. (let ((context (c::find-error-context nil)))
  379. (setq *previous-compiler-condition* condition)
  380. (setq *previous-context* context)
  381. (signal-compiler-condition condition context))))
  382. (defun signal-compiler-condition (condition context)
  383. (signal (make-condition
  384. 'compiler-condition
  385. :original-condition condition
  386. :severity (severity-for-emacs condition)
  387. :message (compiler-condition-message condition)
  388. :source-context (compiler-error-context context)
  389. :location (if (read-error-p condition)
  390. (read-error-location condition)
  391. (compiler-note-location context)))))
  392. (defun severity-for-emacs (condition)
  393. "Return the severity of CONDITION."
  394. (etypecase condition
  395. ((satisfies read-error-p) :read-error)
  396. (c::compiler-error :error)
  397. (c::style-warning :note)
  398. (c::warning :warning)))
  399. (defun read-error-p (condition)
  400. (eq (type-of condition) 'c::compiler-read-error))
  401. (defun compiler-condition-message (condition)
  402. "Briefly describe a compiler error for Emacs.
  403. When Emacs presents the message it already has the source popped up
  404. and the source form highlighted. This makes much of the information in
  405. the error-context redundant."
  406. (princ-to-string condition))
  407. (defun compiler-error-context (error-context)
  408. "Describe context information for Emacs."
  409. (declare (type (or c::compiler-error-context null) error-context))
  410. (multiple-value-bind (enclosing source)
  411. (if error-context
  412. (values (c::compiler-error-context-enclosing-source error-context)
  413. (c::compiler-error-context-source error-context)))
  414. (if (or enclosing source)
  415. (format nil "~@[--> ~{~<~%--> ~1:;~A ~>~}~%~]~
  416. ~@[==>~{~&~A~}~]"
  417. enclosing source))))
  418. (defun read-error-location (condition)
  419. (let* ((finfo (car (c::source-info-current-file c::*source-info*)))
  420. (file (c::file-info-name finfo))
  421. (pos (c::compiler-read-error-position condition)))
  422. (cond ((and (eq file :stream) *buffer-name*)
  423. (make-location (list :buffer *buffer-name*)
  424. (list :offset *buffer-start-position* pos)))
  425. ((and (pathnamep file) (not *buffer-name*))
  426. (make-location (list :file (unix-truename file))
  427. (list :position (1+ pos))))
  428. (t (break)))))
  429. (defun compiler-note-location (context)
  430. "Derive the location of a complier message from its context.
  431. Return a `location' record, or (:error REASON) on failure."
  432. (if (null context)
  433. (note-error-location)
  434. (with-struct (c::compiler-error-context- file-name
  435. original-source
  436. original-source-path) context
  437. (or (locate-compiler-note file-name original-source
  438. (reverse original-source-path))
  439. (note-error-location)))))
  440. (defun note-error-location ()
  441. "Pseudo-location for notes that can't be located."
  442. (cond (*compile-file-truename*
  443. (make-location (list :file (unix-truename *compile-file-truename*))
  444. (list :eof)))
  445. (*buffer-name*
  446. (make-location (list :buffer *buffer-name*)
  447. (list :position *buffer-start-position*)))
  448. (t (list :error "No error location available."))))
  449. (defun locate-compiler-note (file source source-path)
  450. (cond ((and (eq file :stream) *buffer-name*)
  451. ;; Compiling from a buffer
  452. (make-location (list :buffer *buffer-name*)
  453. (list :offset *buffer-start-position*
  454. (source-path-string-position
  455. source-path *buffer-substring*))))
  456. ((and (pathnamep file) (null *buffer-name*))
  457. ;; Compiling from a file
  458. (make-location (list :file (unix-truename file))
  459. (list :position (1+ (source-path-file-position
  460. source-path file)))))
  461. ((and (eq file :lisp) (stringp source))
  462. ;; No location known, but we have the source form.
  463. ;; XXX How is this case triggered? -luke (16/May/2004)
  464. ;; This can happen if the compiler needs to expand a macro
  465. ;; but the macro-expander is not yet compiled. Calling the
  466. ;; (interpreted) macro-expander triggers IR1 conversion of
  467. ;; the lambda expression for the expander and invokes the
  468. ;; compiler recursively.
  469. (make-location (list :source-form source)
  470. (list :position 1)))))
  471. (defun unix-truename (pathname)
  472. (ext:unix-namestring (truename pathname)))
  473. ;;;; XREF
  474. ;;;
  475. ;;; Cross-reference support is based on the standard CMUCL `XREF'
  476. ;;; package. This package has some caveats: XREF information is
  477. ;;; recorded during compilation and not preserved in fasl files, and
  478. ;;; XREF recording is disabled by default. Redefining functions can
  479. ;;; also cause duplicate references to accumulate, but
  480. ;;; `swank-compile-file' will automatically clear out any old records
  481. ;;; from the same filename.
  482. ;;;
  483. ;;; To enable XREF recording, set `c:*record-xref-info*' to true. To
  484. ;;; clear out the XREF database call `xref:init-xref-database'.
  485. (defmacro defxref (name function)
  486. `(defimplementation ,name (name)
  487. (xref-results (,function name))))
  488. (defxref who-calls xref:who-calls)
  489. (defxref who-references xref:who-references)
  490. (defxref who-binds xref:who-binds)
  491. (defxref who-sets xref:who-sets)
  492. ;;; More types of XREF information were added since 18e:
  493. ;;;
  494. #-cmu18
  495. (progn
  496. (defxref who-macroexpands xref:who-macroexpands)
  497. ;; XXX
  498. (defimplementation who-specializes (symbol)
  499. (let* ((methods (xref::who-specializes (find-class symbol)))
  500. (locations (mapcar #'method-location methods)))
  501. (mapcar #'list methods locations))))
  502. (defun xref-results (contexts)
  503. (mapcar (lambda (xref)
  504. (list (xref:xref-context-name xref)
  505. (resolve-xref-location xref)))
  506. contexts))
  507. (defun resolve-xref-location (xref)
  508. (let ((name (xref:xref-context-name xref))
  509. (file (xref:xref-context-file xref))
  510. (source-path (xref:xref-context-source-path xref)))
  511. (cond ((and file source-path)
  512. (let ((position (source-path-file-position source-path file)))
  513. (make-location (list :file (unix-truename file))
  514. (list :position (1+ position)))))
  515. (file
  516. (make-location (list :file (unix-truename file))
  517. (list :function-name (string name))))
  518. (t
  519. `(:error ,(format nil "Unknown source location: ~S ~S ~S "
  520. name file source-path))))))
  521. (defun clear-xref-info (namestring)
  522. "Clear XREF notes pertaining to NAMESTRING.
  523. This is a workaround for a CMUCL bug: XREF records are cumulative."
  524. (when c:*record-xref-info*
  525. (let ((filename (truename namestring)))
  526. (dolist (db (list xref::*who-calls*
  527. #-cmu18 xref::*who-is-called*
  528. #-cmu18 xref::*who-macroexpands*
  529. xref::*who-references*
  530. xref::*who-binds*
  531. xref::*who-sets*))
  532. (maphash (lambda (target contexts)
  533. ;; XXX update during traversal?
  534. (setf (gethash target db)
  535. (delete filename contexts
  536. :key #'xref:xref-context-file
  537. :test #'equalp)))
  538. db)))))
  539. ;;;; Find callers and callees
  540. ;;;
  541. ;;; Find callers and callees by looking at the constant pool of
  542. ;;; compiled code objects. We assume every fdefn object in the
  543. ;;; constant pool corresponds to a call to that function. A better
  544. ;;; strategy would be to use the disassembler to find actual
  545. ;;; call-sites.
  546. (labels ((make-stack () (make-array 100 :fill-pointer 0 :adjustable t))
  547. (map-cpool (code fun)
  548. (declare (type kernel:code-component code) (type function fun))
  549. (loop for i from vm:code-constants-offset
  550. below (kernel:get-header-data code)
  551. do (funcall fun (kernel:code-header-ref code i))))
  552. (callees (fun)
  553. (let ((callees (make-stack)))
  554. (map-cpool (vm::find-code-object fun)
  555. (lambda (o)
  556. (when (kernel:fdefn-p o)
  557. (vector-push-extend (kernel:fdefn-function o)
  558. callees))))
  559. (coerce callees 'list)))
  560. (callers (fun)
  561. (declare (function fun))
  562. (let ((callers (make-stack)))
  563. (ext:gc :full t)
  564. ;; scan :dynamic first to avoid the need for even more gcing
  565. (dolist (space '(:dynamic :read-only :static))
  566. (vm::map-allocated-objects
  567. (lambda (obj header size)
  568. (declare (type fixnum header) (ignore size))
  569. (when (= vm:code-header-type header)
  570. (map-cpool obj
  571. (lambda (c)
  572. (when (and (kernel:fdefn-p c)
  573. (eq (kernel:fdefn-function c) fun))
  574. (vector-push-extend obj callers))))))
  575. space)
  576. (ext:gc))
  577. (coerce callers 'list)))
  578. (entry-points (code)
  579. (loop for entry = (kernel:%code-entry-points code)
  580. then (kernel::%function-next entry)
  581. while entry
  582. collect entry))
  583. (guess-main-entry-point (entry-points)
  584. (or (find-if (lambda (fun)
  585. (ext:valid-function-name-p
  586. (kernel:%function-name fun)))
  587. entry-points)
  588. (car entry-points)))
  589. (fun-dspec (fun)
  590. (list (kernel:%function-name fun) (function-location fun)))
  591. (code-dspec (code)
  592. (let ((eps (entry-points code))
  593. (di (kernel:%code-debug-info code)))
  594. (cond (eps (fun-dspec (guess-main-entry-point eps)))
  595. (di (list (c::debug-info-name di)
  596. (debug-info-function-name-location di)))
  597. (t (list (princ-to-string code)
  598. `(:error "No src-loc available")))))))
  599. (declare (inline map-cpool))
  600. (defimplementation list-callers (symbol)
  601. (mapcar #'code-dspec (callers (coerce symbol 'function) )))
  602. (defimplementation list-callees (symbol)
  603. (mapcar #'fun-dspec (callees symbol))))
  604. (defun test-list-callers (count)
  605. (let ((funsyms '()))
  606. (do-all-symbols (s)
  607. (when (and (fboundp s)
  608. (functionp (symbol-function s))
  609. (not (macro-function s))
  610. (not (special-operator-p s)))
  611. (push s funsyms)))
  612. (let ((len (length funsyms)))
  613. (dotimes (i count)
  614. (let ((sym (nth (random len) funsyms)))
  615. (format t "~s -> ~a~%" sym (mapcar #'car (list-callers sym))))))))
  616. ;; (test-list-callers 100)
  617. ;;;; Resolving source locations
  618. ;;;
  619. ;;; Our mission here is to "resolve" references to code locations into
  620. ;;; actual file/buffer names and character positions. The references
  621. ;;; we work from come out of the compiler's statically-generated debug
  622. ;;; information, such as `code-location''s and `debug-source''s. For
  623. ;;; more details, see the "Debugger Programmer's Interface" section of
  624. ;;; the CMUCL manual.
  625. ;;;
  626. ;;; The first step is usually to find the corresponding "source-path"
  627. ;;; for the location. Once we have the source-path we can pull up the
  628. ;;; source file and `READ' our way through to the right position. The
  629. ;;; main source-code groveling work is done in
  630. ;;; `swank-source-path-parser.lisp'.
  631. (defvar *debug-definition-finding* nil
  632. "When true don't handle errors while looking for definitions.
  633. This is useful when debugging the definition-finding code.")
  634. (defvar *source-snippet-size* 256
  635. "Maximum number of characters in a snippet of source code.
  636. Snippets at the beginning of definitions are used to tell Emacs what
  637. the definitions looks like, so that it can accurately find them by
  638. text search.")
  639. (defmacro safe-definition-finding (&body body)
  640. "Execute BODY and return the source-location it returns.
  641. If an error occurs and `*debug-definition-finding*' is false, then
  642. return an error pseudo-location.
  643. The second return value is NIL if no error occurs, otherwise it is the
  644. condition object."
  645. `(flet ((body () ,@body))
  646. (if *debug-definition-finding*
  647. (body)
  648. (handler-case (values (progn ,@body) nil)
  649. (error (c) (values `(:error ,(trim-whitespace (princ-to-string c)))
  650. c))))))
  651. (defun trim-whitespace (string)
  652. (string-trim #(#\newline #\space #\tab) string))
  653. (defun code-location-source-location (code-location)
  654. "Safe wrapper around `code-location-from-source-location'."
  655. (safe-definition-finding
  656. (source-location-from-code-location code-location)))
  657. (defun source-location-from-code-location (code-location)
  658. "Return the source location for CODE-LOCATION."
  659. (let ((debug-fun (di:code-location-debug-function code-location)))
  660. (when (di::bogus-debug-function-p debug-fun)
  661. ;; Those lousy cheapskates! They've put in a bogus debug source
  662. ;; because the code was compiled at a low debug setting.
  663. (error "Bogus debug function: ~A" debug-fun)))
  664. (let* ((debug-source (di:code-location-debug-source code-location))
  665. (from (di:debug-source-from debug-source))
  666. (name (di:debug-source-name debug-source)))
  667. (ecase from
  668. (:file
  669. (location-in-file name code-location debug-source))
  670. (:stream
  671. (location-in-stream code-location debug-source))
  672. (:lisp
  673. ;; The location comes from a form passed to `compile'.
  674. ;; The best we can do is return the form itself for printing.
  675. (make-location
  676. (list :source-form (with-output-to-string (*standard-output*)
  677. (debug::print-code-location-source-form
  678. code-location 100 t)))
  679. (list :position 1))))))
  680. (defun location-in-file (filename code-location debug-source)
  681. "Resolve the source location for CODE-LOCATION in FILENAME."
  682. (let* ((code-date (di:debug-source-created debug-source))
  683. (root-number (di:debug-source-root-number debug-source))
  684. (source-code (get-source-code filename code-date)))
  685. (with-input-from-string (s source-code)
  686. (make-location (list :file (unix-truename filename))
  687. (list :position (1+ (code-location-stream-position
  688. code-location s root-number)))
  689. `(:snippet ,(read-snippet s))))))
  690. (defun location-in-stream (code-location debug-source)
  691. "Resolve the source location for a CODE-LOCATION from a stream.
  692. This only succeeds if the code was compiled from an Emacs buffer."
  693. (unless (debug-source-info-from-emacs-buffer-p debug-source)
  694. (error "The code is compiled from a non-SLIME stream."))
  695. (let* ((info (c::debug-source-info debug-source))
  696. (string (getf info :emacs-buffer-string))
  697. (position (code-location-string-offset
  698. code-location
  699. string)))
  700. (make-location
  701. (list :buffer (getf info :emacs-buffer))
  702. (list :offset (getf info :emacs-buffer-offset) position)
  703. (list :snippet (with-input-from-string (s string)
  704. (file-position s position)
  705. (read-snippet s))))))
  706. ;;;;; Function-name locations
  707. ;;;
  708. (defun debug-info-function-name-location (debug-info)
  709. "Return a function-name source-location for DEBUG-INFO.
  710. Function-name source-locations are a fallback for when precise
  711. positions aren't available."
  712. (with-struct (c::debug-info- (fname name) source) debug-info
  713. (with-struct (c::debug-source- info from name) (car source)
  714. (ecase from
  715. (:file
  716. (make-location (list :file (namestring (truename name)))
  717. (list :function-name (string fname))))
  718. (:stream
  719. (assert (debug-source-info-from-emacs-buffer-p (car source)))
  720. (make-location (list :buffer (getf info :emacs-buffer))
  721. (list :function-name (string fname))))
  722. (:lisp
  723. (make-location (list :source-form (princ-to-string (aref name 0)))
  724. (list :position 1)))))))
  725. (defun debug-source-info-from-emacs-buffer-p (debug-source)
  726. "Does the `info' slot of DEBUG-SOURCE contain an Emacs buffer location?
  727. This is true for functions that were compiled directly from buffers."
  728. (info-from-emacs-buffer-p (c::debug-source-info debug-source)))
  729. (defun info-from-emacs-buffer-p (info)
  730. (and info
  731. (consp info)
  732. (eq :emacs-buffer (car info))))
  733. ;;;;; Groveling source-code for positions
  734. (defun code-location-stream-position (code-location stream root)
  735. "Return the byte offset of CODE-LOCATION in STREAM. Extract the
  736. toplevel-form-number and form-number from CODE-LOCATION and use that
  737. to find the position of the corresponding form.
  738. Finish with STREAM positioned at the start of the code location."
  739. (let* ((location (debug::maybe-block-start-location code-location))
  740. (tlf-offset (- (di:code-location-top-level-form-offset location)
  741. root))
  742. (form-number (di:code-location-form-number location)))
  743. (let ((pos (form-number-stream-position tlf-offset form-number stream)))
  744. (file-position stream pos)
  745. pos)))
  746. (defun form-number-stream-position (tlf-number form-number stream)
  747. "Return the starting character position of a form in STREAM.
  748. TLF-NUMBER is the top-level-form number.
  749. FORM-NUMBER is an index into a source-path table for the TLF."
  750. (multiple-value-bind (tlf position-map) (read-source-form tlf-number stream)
  751. (let* ((path-table (di:form-number-translations tlf 0))
  752. (source-path
  753. (if (<= (length path-table) form-number) ; source out of sync?
  754. (list 0) ; should probably signal a condition
  755. (reverse (cdr (aref path-table form-number))))))
  756. (source-path-source-position source-path tlf position-map))))
  757. (defun code-location-string-offset (code-location string)
  758. "Return the byte offset of CODE-LOCATION in STRING.
  759. See CODE-LOCATION-STREAM-POSITION."
  760. (with-input-from-string (s string)
  761. (code-location-stream-position code-location s 0)))
  762. ;;;; Finding definitions
  763. ;;; There are a great many different types of definition for us to
  764. ;;; find. We search for definitions of every kind and return them in a
  765. ;;; list.
  766. (defimplementation find-definitions (name)
  767. (append (function-definitions name)
  768. (setf-definitions name)
  769. (variable-definitions name)
  770. (class-definitions name)
  771. (type-definitions name)
  772. (compiler-macro-definitions name)
  773. (source-transform-definitions name)
  774. (function-info-definitions name)
  775. (ir1-translator-definitions name)
  776. (template-definitions name)
  777. (primitive-definitions name)
  778. (vm-support-routine-definitions name)
  779. ))
  780. ;;;;; Functions, macros, generic functions, methods
  781. ;;;
  782. ;;; We make extensive use of the compile-time debug information that
  783. ;;; CMUCL records, in particular "debug functions" and "code
  784. ;;; locations." Refer to the "Debugger Programmer's Interface" section
  785. ;;; of the CMUCL manual for more details.
  786. (defun function-definitions (name)
  787. "Return definitions for NAME in the \"function namespace\", i.e.,
  788. regular functions, generic functions, methods and macros.
  789. NAME can any valid function name (e.g, (setf car))."
  790. (let ((macro? (and (symbolp name) (macro-function name)))
  791. (function? (and (ext:valid-function-name-p name)
  792. (ext:info :function :definition name)
  793. (if (symbolp name) (fboundp name) t))))
  794. (cond (macro?
  795. (list `((defmacro ,name)
  796. ,(function-location (macro-function name)))))
  797. (function?
  798. (let ((function (fdefinition name)))
  799. (if (genericp function)
  800. (gf-definitions name function)
  801. (list (list `(function ,name)
  802. (function-location function)))))))))
  803. ;;;;;; Ordinary (non-generic/macro/special) functions
  804. ;;;
  805. ;;; First we test if FUNCTION is a closure created by defstruct, and
  806. ;;; if so extract the defstruct-description (`dd') from the closure
  807. ;;; and find the constructor for the struct. Defstruct creates a
  808. ;;; defun for the default constructor and we use that as an
  809. ;;; approximation to the source location of the defstruct.
  810. ;;;
  811. ;;; For an ordinary function we return the source location of the
  812. ;;; first code-location we find.
  813. ;;;
  814. (defun function-location (function)
  815. "Return the source location for FUNCTION."
  816. (cond ((struct-closure-p function)
  817. (struct-closure-location function))
  818. ((c::byte-function-or-closure-p function)
  819. (byte-function-location function))
  820. (t
  821. (compiled-function-location function))))
  822. (defun compiled-function-location (function)
  823. "Return the location of a regular compiled function."
  824. (multiple-value-bind (code-location error)
  825. (safe-definition-finding (function-first-code-location function))
  826. (cond (error (list :error (princ-to-string error)))
  827. (t (code-location-source-location code-location)))))
  828. (defun function-first-code-location (function)
  829. "Return the first code-location we can find for FUNCTION."
  830. (and (function-has-debug-function-p function)
  831. (di:debug-function-start-location
  832. (di:function-debug-function function))))
  833. (defun function-has-debug-function-p (function)
  834. (di:function-debug-function function))
  835. (defun function-code-object= (closure function)
  836. (and (eq (vm::find-code-object closure)
  837. (vm::find-code-object function))
  838. (not (eq closure function))))
  839. (defun byte-function-location (fun)
  840. "Return the location of the byte-compiled function FUN."
  841. (etypecase fun
  842. ((or c::hairy-byte-function c::simple-byte-function)
  843. (let* ((di (kernel:%code-debug-info (c::byte-function-component fun))))
  844. (if di
  845. (debug-info-function-name-location di)
  846. `(:error
  847. ,(format nil "Byte-function without debug-info: ~a" fun)))))
  848. (c::byte-closure
  849. (byte-function-location (c::byte-closure-function fun)))))
  850. ;;; Here we deal with structure accessors. Note that `dd' is a
  851. ;;; "defstruct descriptor" structure in CMUCL. A `dd' describes a
  852. ;;; `defstruct''d structure.
  853. (defun struct-closure-p (function)
  854. "Is FUNCTION a closure created by defstruct?"
  855. (or (function-code-object= function #'kernel::structure-slot-accessor)
  856. (function-code-object= function #'kernel::structure-slot-setter)
  857. (function-code-object= function #'kernel::%defstruct)))
  858. (defun struct-closure-location (function)
  859. "Return the location of the structure that FUNCTION belongs to."
  860. (assert (struct-closure-p function))
  861. (safe-definition-finding
  862. (dd-location (struct-closure-dd function))))
  863. (defun struct-closure-dd (function)
  864. "Return the defstruct-definition (dd) of FUNCTION."
  865. (assert (= (kernel:get-type function) vm:closure-header-type))
  866. (flet ((find-layout (function)
  867. (sys:find-if-in-closure
  868. (lambda (x)
  869. (let ((value (if (di::indirect-value-cell-p x)
  870. (c:value-cell-ref x)
  871. x)))
  872. (when (kernel::layout-p value)
  873. (return-from find-layout value))))
  874. function)))
  875. (kernel:layout-info (find-layout function))))
  876. (defun dd-location (dd)
  877. "Return the location of a `defstruct'."
  878. ;; Find the location in a constructor.
  879. (function-location (struct-constructor dd)))
  880. (defun struct-constructor (dd)
  881. "Return a constructor function from a defstruct definition.
  882. Signal an error if no constructor can be found."
  883. (let* ((constructor (or (kernel:dd-default-constructor dd)
  884. (car (kernel::dd-constructors dd))))
  885. (sym (if (consp constructor) (car constructor) constructor)))
  886. (unless sym
  887. (error "Cannot find structure's constructor: ~S" (kernel::dd-name dd)))
  888. (coerce sym 'function)))
  889. ;;;;;; Generic functions and methods
  890. (defun gf-definitions (name function)
  891. "Return the definitions of a generic function and its methods."
  892. (cons (list `(defgeneric ,name) (gf-location function))
  893. (gf-method-definitions function)))
  894. (defun gf-location (gf)
  895. "Return the location of the generic function GF."
  896. (definition-source-location gf (pcl::generic-function-name gf)))
  897. (defun gf-method-definitions (gf)
  898. "Return the locations of all methods of the generic function GF."
  899. (mapcar #'method-definition (pcl::generic-function-methods gf)))
  900. (defun method-definition (method)
  901. (list (method-dspec method)
  902. (method-location method)))
  903. (defun method-dspec (method)
  904. "Return a human-readable \"definition specifier\" for METHOD."
  905. (let* ((gf (pcl:method-generic-function method))
  906. (name (pcl:generic-function-name gf))
  907. (specializers (pcl:method-specializers method))
  908. (qualifiers (pcl:method-qualifiers method)))
  909. `(method ,name ,@qualifiers ,(pcl::unparse-specializers specializers))))
  910. ;; XXX maybe special case setters/getters
  911. (defun method-location (method)
  912. (function-location (or (pcl::method-fast-function method)
  913. (pcl:method-function method))))
  914. (defun genericp (fn)
  915. (typep fn 'generic-function))
  916. ;;;;;; Types and classes
  917. (defun type-definitions (name)
  918. "Return `deftype' locations for type NAME."
  919. (maybe-make-definition (ext:info :type :expander name) 'deftype name))
  920. (defun maybe-make-definition (function kind name)
  921. "If FUNCTION is non-nil then return its definition location."
  922. (if function
  923. (list (list `(,kind ,name) (function-location function)))))
  924. (defun class-definitions (name)
  925. "Return the definition locations for the class called NAME."
  926. (if (symbolp name)
  927. (let ((class (kernel::find-class name nil)))
  928. (etypecase class
  929. (null '())
  930. (kernel::structure-class
  931. (list (list `(defstruct ,name) (dd-location (find-dd name)))))
  932. #+(or)
  933. (conditions::condition-class
  934. (list (list `(define-condition ,name)
  935. (condition-class-location class))))
  936. (kernel::standard-class
  937. (list (list `(defclass ,name)
  938. (class-location (find-class name)))))
  939. ((or kernel::built-in-class
  940. conditions::condition-class
  941. kernel:funcallable-structure-class)
  942. (list (list `(kernel::define-type-class ,name)
  943. `(:error
  944. ,(format nil "No source info for ~A" name)))))))))
  945. (defun class-location (class)
  946. "Return the `defclass' location for CLASS."
  947. (definition-source-location class (pcl:class-name class)))
  948. (defun find-dd (name)
  949. "Find the defstruct-definition by the name of its structure-class."
  950. (let ((layout (ext:info :type :compiler-layout name)))
  951. (if layout
  952. (kernel:layout-info layout))))
  953. (defun condition-class-location (class)
  954. (let ((slots (conditions::condition-class-slots class))
  955. (name (conditions::condition-class-name class)))
  956. (cond ((null slots)
  957. `(:error ,(format nil "No location info for condition: ~A" name)))
  958. (t
  959. ;; Find the class via one of its slot-reader methods.
  960. (let* ((slot (first slots))
  961. (gf (fdefinition
  962. (first (conditions::condition-slot-readers slot)))))
  963. (method-location
  964. (first
  965. (pcl:compute-applicable-methods-using-classes
  966. gf (list (find-class name))))))))))
  967. (defun make-name-in-file-location (file string)
  968. (multiple-value-bind (filename c)
  969. (ignore-errors
  970. (unix-truename (merge-pathnames (make-pathname :type "lisp")
  971. file)))
  972. (cond (filename (make-location `(:file ,filename)
  973. `(:function-name ,(string string))))
  974. (t (list :error (princ-to-string c))))))
  975. (defun source-location-form-numbers (location)
  976. (c::decode-form-numbers (c::form-numbers-form-numbers location)))
  977. (defun source-location-tlf-number (location)
  978. (nth-value 0 (source-location-form-numbers location)))
  979. (defun source-location-form-number (location)
  980. (nth-value 1 (source-location-form-numbers location)))
  981. (defun resolve-file-source-location (location)
  982. (let ((filename (c::file-source-location-pathname location))
  983. (tlf-number (source-location-tlf-number location))
  984. (form-number (source-location-form-number location)))
  985. (with-open-file (s filename)
  986. (let ((pos (form-number-stream-position tlf-number form-number s)))
  987. (make-location `(:file ,(unix-truename filename))
  988. `(:position ,(1+ pos)))))))
  989. (defun resolve-stream-source-location (location)
  990. (let ((info (c::stream-source-location-user-info location))
  991. (tlf-number (source-location-tlf-number location))
  992. (form-number (source-location-form-number location)))
  993. ;; XXX duplication in frame-source-location
  994. (assert (info-from-emacs-buffer-p info))
  995. (destructuring-bind (&key emacs-buffer emacs-buffer-string
  996. emacs-buffer-offset) info
  997. (with-input-from-string (s emacs-buffer-string)
  998. (let ((pos (form-number-stream-position tlf-number form-number s)))
  999. (make-location `(:buffer ,emacs-buffer)
  1000. `(:offset ,emacs-buffer-offset ,pos)))))))
  1001. ;; XXX predicates for 18e backward compatibilty. Remove them when
  1002. ;; we're 19a only.
  1003. (defun file-source-location-p (object)
  1004. (when (fboundp 'c::file-source-location-p)
  1005. (c::file-source-location-p object)))
  1006. (defun stream-source-location-p (object)
  1007. (when (fboundp 'c::stream-source-location-p)
  1008. (c::stream-source-location-p object)))
  1009. (defun source-location-p (object)
  1010. (or (file-source-location-p object)
  1011. (stream-source-location-p object)))
  1012. (defun resolve-source-location (location)
  1013. (etypecase location
  1014. ((satisfies file-source-location-p)
  1015. (resolve-file-source-location location))
  1016. ((satisfies stream-source-location-p)
  1017. (resolve-stream-source-location location))))
  1018. (defun definition-source-location (object name)
  1019. (let ((source (pcl::definition-source object)))
  1020. (etypecase source
  1021. (null
  1022. `(:error ,(format nil "No source info for: ~A" object)))
  1023. ((satisfies source-location-p)
  1024. (resolve-source-location source))
  1025. (pathname
  1026. (make-name-in-file-location source name))
  1027. (cons
  1028. (destructuring-bind ((dg name) pathname) source
  1029. (declare (ignore dg))
  1030. (etypecase pathname
  1031. (pathname (make-name-in-file-location pathname (string name)))
  1032. (null `(:error ,(format nil "Cannot resolve: ~S" source)))))))))
  1033. (defun setf-definitions (name)
  1034. (let ((f (or (ext:info :setf :inverse name)
  1035. (ext:info :setf :expander name)
  1036. (and (symbolp name)
  1037. (fboundp `(setf ,name))
  1038. (fdefinition `(setf ,name))))))
  1039. (if f
  1040. `(((setf ,name) ,(function-location (cond ((functionp f) f)
  1041. ((macro-function f))
  1042. ((fdefinition f)))))))))
  1043. (defun variable-location (symbol)
  1044. (multiple-value-bind (location foundp)
  1045. ;; XXX for 18e compatibilty. rewrite this when we drop 18e
  1046. ;; support.
  1047. (ignore-errors (eval `(ext:info :source-location :defvar ',symbol)))
  1048. (if (and foundp location)
  1049. (resolve-source-location location)
  1050. `(:error ,(format nil "No source info for variable ~S" symbol)))))
  1051. (defun variable-definitions (name)
  1052. (if (symbolp name)
  1053. (multiple-value-bind (kind recorded-p) (ext:info :variable :kind name)
  1054. (if recorded-p
  1055. (list (list `(variable ,kind ,name)
  1056. (variable-location name)))))))
  1057. (defun compiler-macro-definitions (symbol)
  1058. (maybe-make-definition (compiler-macro-function symbol)
  1059. 'define-compiler-macro
  1060. symbol))
  1061. (defun source-transform-definitions (name)
  1062. (maybe-make-definition (ext:info :function :source-transform name)
  1063. 'c:def-source-transform
  1064. name))
  1065. (defun function-info-definitions (name)
  1066. (let ((info (ext:info :function :info name)))
  1067. (if info
  1068. (append (loop for transform in (c::function-info-transforms info)
  1069. collect (list `(c:deftransform ,name
  1070. ,(c::type-specifier
  1071. (c::transform-type transform)))
  1072. (function-location (c::transform-function
  1073. transform))))
  1074. (maybe-make-definition (c::function-info-derive-type info)
  1075. 'c::derive-type name)
  1076. (maybe-make-definition (c::function-info-optimizer info)
  1077. 'c::optimizer name)
  1078. (maybe-make-definition (c::function-info-ltn-annotate info)
  1079. 'c::ltn-annotate name)
  1080. (maybe-make-definition (c::function-info-ir2-convert info)
  1081. 'c::ir2-convert name)
  1082. (loop for template in (c::function-info-templates info)
  1083. collect (list `(,(type-of template)
  1084. ,(c::template-name templ…

Large files files are truncated, but you can click here to view the full file