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

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

Denote the support for SYS:SOURCE by exporting symbols

SYS:RECORD-SOURCE-INFORMATION-FOR-TYPE is now the official API point
to record source information for ABCL on the SYS:SOURCE property for
any given symbol.

SYS:RECORD-SOURCE-INFORMATION and SYS::%SOURCE are now marked for
deprecation in abcl-1.7

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.6 KB
Line 
1;;; fdefinition.lisp
2;;;
3;;; Copyright (C) 2005-2006 Peter Graves
4;;; $Id: fdefinition.lisp 14916 2016-11-24 10:31:33Z 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 SYS::*LOAD-TRUENAME-FASL*
113    (unless source-pathname
114      (setf source-pathname (or *source* :top-level)))
115    (unless source-position
116      (setf source-position *source-position*))
117    (let ((source (if source-position
118          (list source-pathname source-position)
119          (list source-pathname))))
120      (let ((sym (if (consp name) (second name) name)))
121  (put sym 'sys::source (cons `(,type ,(if (symbolp (car source)) (car source) (namestring (car source))) ,(second source)) (get sym  'sys::source nil)))))))
122
123;; Redefined in trace.lisp.
124(defun trace-redefined-update (&rest args)
125  (declare (ignore args)))
126
127;; Redefined in trace.lisp.
128(defun untraced-function (name)
129  (declare (ignore name))
130  nil)
131
132(defun fset (name function &optional source-position arglist documentation)
133  (cond ((symbolp name)
134         (check-redefinition name)
135         (record-source-information name nil source-position)
136         (when arglist
137           (%set-arglist function arglist))
138         (%set-documentation function 'function documentation)
139         (%set-symbol-function name function))
140        ((setf-function-name-p name)
141         (check-redefinition name)
142         (record-source-information name nil source-position)
143         ;; FIXME arglist documentation
144         (setf (get (%cadr name) 'setf-function) function))
145        (t
146         (require-type name '(or symbol (cons (eql setf) (cons symbol null))))))
147  (when (functionp function) ; FIXME Is this test needed?
148    (%set-lambda-name function name))
149  (trace-redefined-update name function)
150  function)
151
152(defun fdefinition (name)
153  (cond ((symbolp name)
154         (symbol-function name))
155        ((setf-function-name-p name)
156         (or (get (%cadr name) 'setf-function)
157             (error 'undefined-function :name name)))
158        (t
159         (require-type name '(or symbol (cons (eql setf) (cons symbol null)))))))
160
161(defun %set-fdefinition (name function)
162  (fset name function))
163
164(defsetf fdefinition %set-fdefinition)
Note: See TracBrowser for help on using the repository browser.