source: trunk/abcl/src/org/armedbear/lisp/fdefinition.lisp @ 14933

Last change on this file since 14933 was 14933, checked in by Mark Evenson, 5 years ago

(Alan Ruttenberg) small changes to enable better introspection

Small jss tweak that caused some trouble.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.9 KB
Line 
1;;; fdefinition.lisp
2;;;
3;;; Copyright (C) 2005-2006 Peter Graves
4;;; $Id: fdefinition.lisp 14933 2016-12-28 09:19:00Z mevenson $
5;;;
6;;; This program is free software; you can redistribute it and/or
7;;; modify it under the terms of the GNU General Public License
8;;; as published by the Free Software Foundation; either version 2
9;;; of the License, or (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19;;;
20;;; As a special exception, the copyright holders of this library give you
21;;; permission to link this library with independent modules to produce an
22;;; executable, regardless of the license terms of these independent
23;;; modules, and to copy and distribute the resulting executable under
24;;; terms of your choice, provided that you also meet, for each linked
25;;; independent module, the terms and conditions of the license of that
26;;; module.  An independent module is a module which is not derived from
27;;; or based on this library.  If you modify this library, you may extend
28;;; this exception to your version of the library, but you are not
29;;; obligated to do so.  If you do not wish to do so, delete this
30;;; exception statement from your version.
31
32(in-package #:system)
33
34(export '(record-source-information untraced-function))
35
36(defun check-redefinition (name)
37  (when (and *warn-on-redefinition* (fboundp name) (not (autoloadp name)))
38    (when (and (symbolp name)
39               (source-pathname name))
40      ;; SOURCE-PATHNAME is badly named as it is either a PATHNAMAE
41      ;; or the symbol :TOP-LEVEL
42      (let ((old-source 
43             (if (keywordp (source-pathname name))
44                 (source-pathname name)
45                 (probe-file (source-pathname name))))
46            (current-source 
47             (if (not *source*) 
48                 :top-level
49                 (probe-file *source*))))
50        (cond ((equal old-source 
51                      current-source)) ; OK
52              (t
53               (if (eq current-source :top-level)
54                   (style-warn "redefining ~S at top level" name)
55                   (let ((*package* +cl-package+))
56                     (if (eq old-source :top-level)
57                         (style-warn "redefining ~S in ~S (previously defined at top level)"
58                                     name current-source)
59                         (style-warn "redefining ~S in ~S (previously defined in ~S)"
60                                     name current-source old-source))))))))))
61
62;;; DEPRECATED:  to be removed in abcl-1.7
63(defun record-source-information (name &optional source-pathname source-position)
64  (unless source-pathname
65    (setf source-pathname (or *source* :top-level)))
66  (unless source-position
67    (setf source-position *source-position*))
68  (let ((source (if source-position
69                    (cons source-pathname source-position)
70                    source-pathname)))
71    (cond ((symbolp name)
72           (put name '%source source)))))
73
74(defun record-source-information-for-type (name type &optional source-pathname source-position)
75  "Record source information on the SYS:SOURCE property for symbol with NAME
76
77TYPE is either a symbol or list.
78
79Source information for functions, methods, and generic functions are
80represented as lists of the following form:
81
82    (:generic-function function-name)
83    (:function function-name)
84    (:method method-name qualifiers specializers)
85
86Where FUNCTION-NAME or METHOD-NAME can be a either be of the form
87'symbol or '(setf symbol).
88
89Source information for all other forms have a symbol for TYPE which is
90one of the following:
91
92:class, :variable, :condition, :constant, :compiler-macro, :macro
93:package, :structure, :type, :setf-expander, :source-transform
94
95These values follow SBCL'S implemenation in SLIME
96c.f. <https://github.com/slime/slime/blob/bad2acf672c33b913aabc1a7facb9c3c16a4afe9/swank/sbcl.lisp#L748>
97
98"
99#|
100Modifications are in two places, one at the definitions, calling
101record-source-information-by-type and then again in the file-compiler,
102which writes forms like
103
104(put 'source name (cons (list type pathname position) (get 'source name)))
105
106In theory this can lead to redundancy if a fasl is loaded again and
107again. I'm not sure how to fix this yet. Forms in the __loader__ get
108called early in build when many of the sequence functions aren't
109present.  Will probably just filter when presenting in slime.
110
111|# 
112    (unless source-pathname
113      (setf source-pathname (or *source* :top-level)))
114    (unless source-position
115      (setf source-position *source-position*))
116    (let ((source (if source-position
117          (list source-pathname source-position)
118          (list source-pathname))))
119      (let ((sym (if (consp name) (second name) name))
120            (new `(,type ,(if (symbolp (car source)) (car source) (namestring (car source))) ,(second source))))
121        (if (autoloadp 'delete)
122   (put sym 'sys::source (cons new (get sym  'sys::source nil)))
123         (put sym 'sys::source (cons new (delete new (get sym  'sys::source nil) 
124               :test (lambda(a b) (and (equalp (car a) (car b)) (equalp (second a) (second b) ))))))))))
125
126;; Redefined in trace.lisp.
127(defun trace-redefined-update (&rest args)
128  (declare (ignore args)))
129
130;; Redefined in trace.lisp.
131(defun untraced-function (name)
132  (declare (ignore name))
133  nil)
134
135(%defvar '*fset-hooks* nil)
136
137(defun fset (name function &optional source-position arglist documentation)
138  (cond ((symbolp name)
139         (check-redefinition name)
140         (record-source-information name nil source-position)
141         (when arglist
142           (%set-arglist function arglist))
143         (%set-documentation function 'function documentation)
144         (%set-symbol-function name function))
145        ((setf-function-name-p name)
146         (check-redefinition name)
147         (record-source-information name nil source-position)
148         ;; FIXME arglist documentation
149         (setf (get (%cadr name) 'setf-function) function))
150        (t
151         (require-type name '(or symbol (cons (eql setf) (cons symbol null))))))
152  (when (functionp function) ; FIXME Is this test needed?
153    (%set-lambda-name function name))
154  (dolist (hook *fset-hooks*) (ignore-errors (funcall hook name function)))
155  (trace-redefined-update name function)
156  function)
157
158(defun fdefinition (name)
159  (cond ((symbolp name)
160         (symbol-function name))
161        ((setf-function-name-p name)
162         (or (get (%cadr name) 'setf-function)
163             (error 'undefined-function :name name)))
164        (t
165         (require-type name '(or symbol (cons (eql setf) (cons symbol null)))))))
166
167(defun %set-fdefinition (name function)
168  (fset name function))
169
170(defsetf fdefinition %set-fdefinition)
Note: See TracBrowser for help on using the repository browser.