1 ;;;; implementation of CL:DOCUMENTATION
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is in the public domain and is provided with absolutely no
7 ;;;; warranty. See the COPYING and CREDITS files for more information.
11 ;;; FIXME: Lots of bare calls to INFO here could be handled
12 ;;; more cleanly by calling the FDOCUMENTATION function instead.
17 (slot-value x '%documentation))
19 (sb-eval:interpreted-function
20 (sb-eval:interpreted-function-documentation x))
24 ;;; functions, macros, and special forms
25 (defmethod documentation ((x function) (doc-type (eql 't)))
28 (defmethod documentation ((x function) (doc-type (eql 'function)))
31 (defmethod documentation ((x list) (doc-type (eql 'function)))
32 (and (legal-fun-name-p x)
34 (documentation (fdefinition x) t)))
36 (defmethod documentation ((x list) (doc-type (eql 'compiler-macro)))
37 (random-documentation x 'compiler-macro))
39 (defmethod documentation ((x symbol) (doc-type (eql 'function)))
40 (or (values (info :function :documentation x))
41 ;; Try the pcl function documentation.
42 (and (fboundp x) (documentation (fdefinition x) t))))
44 (defmethod documentation ((x symbol) (doc-type (eql 'compiler-macro)))
45 (random-documentation x 'compiler-macro))
47 (defmethod documentation ((x symbol) (doc-type (eql 'setf)))
48 (values (info :setf :documentation x)))
50 (defun (setf fun-doc) (new-value x)
53 (setf (slot-value x '%documentation) new-value))
55 (sb-eval:interpreted-function
56 (setf (sb-eval:interpreted-function-documentation x)
59 (let ((name (%fun-name x)))
60 (when (and name (typep name '(or symbol cons)))
61 (setf (info :function :documentation name) new-value)))))
65 (defmethod (setf documentation) (new-value (x function) (doc-type (eql 't)))
66 (setf (fun-doc x) new-value))
68 (defmethod (setf documentation) (new-value
70 (doc-type (eql 'function)))
71 (setf (fun-doc x) new-value))
73 (defmethod (setf documentation) (new-value (x list) (doc-type (eql 'function)))
74 (setf (info :function :documentation x) new-value))
76 (defmethod (setf documentation)
77 (new-value (x list) (doc-type (eql 'compiler-macro)))
78 (setf (random-documentation x 'compiler-macro) new-value))
80 (defmethod (setf documentation) (new-value
82 (doc-type (eql 'function)))
83 (setf (info :function :documentation x) new-value))
85 (defmethod (setf documentation)
86 (new-value (x symbol) (doc-type (eql 'compiler-macro)))
87 (setf (random-documentation x 'compiler-macro) new-value))
89 (defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'setf)))
90 (setf (info :setf :documentation x) new-value))
92 ;;; method combinations
93 (defmethod documentation ((x method-combination) (doc-type (eql 't)))
94 (slot-value x '%documentation))
96 (defmethod documentation
97 ((x method-combination) (doc-type (eql 'method-combination)))
98 (slot-value x '%documentation))
100 (defmethod documentation ((x symbol) (doc-type (eql 'method-combination)))
101 (random-documentation x 'method-combination))
103 (defmethod (setf documentation)
104 (new-value (x method-combination) (doc-type (eql 't)))
105 (setf (slot-value x '%documentation) new-value))
107 (defmethod (setf documentation)
108 (new-value (x method-combination) (doc-type (eql 'method-combination)))
109 (setf (slot-value x '%documentation) new-value))
111 (defmethod (setf documentation)
112 (new-value (x symbol) (doc-type (eql 'method-combination)))
113 (setf (random-documentation x 'method-combination) new-value))
116 (defmethod documentation ((x standard-method) (doc-type (eql 't)))
117 (slot-value x '%documentation))
119 (defmethod (setf documentation)
120 (new-value (x standard-method) (doc-type (eql 't)))
121 (setf (slot-value x '%documentation) new-value))
125 ;;; KLUDGE: It's nasty having things like this accessor
126 ;;; (PACKAGE-DOC-STRING) floating around out in this mostly-unrelated
127 ;;; source file. Perhaps it would be better to support WARM-INIT-FORMS
128 ;;; by analogy with the existing !COLD-INIT-FORMS and have them be
129 ;;; EVAL'ed after basic warm load is done? That way things like this
130 ;;; could be defined alongside the other code which does low-level
131 ;;; hacking of packages.. -- WHN 19991203
133 (defmethod documentation ((x package) (doc-type (eql 't)))
134 (package-doc-string x))
136 (defmethod (setf documentation) (new-value (x package) (doc-type (eql 't)))
137 (setf (package-doc-string x) new-value))
139 ;;; types, classes, and structure names
140 (defmethod documentation ((x structure-class) (doc-type (eql 't)))
141 (values (info :type :documentation (class-name x))))
143 (defmethod documentation ((x structure-class) (doc-type (eql 'type)))
144 (values (info :type :documentation (class-name x))))
146 (defmethod documentation ((x standard-class) (doc-type (eql 't)))
147 (slot-value x '%documentation))
149 (defmethod documentation ((x standard-class) (doc-type (eql 'type)))
150 (slot-value x '%documentation))
152 ;;; although the CLHS doesn't mention this, it is reasonable to assume
153 ;;; that parallel treatment of condition-class was intended (if
154 ;;; condition-class is in fact not implemented as a standard-class or
155 ;;; structure-class).
156 (defmethod documentation ((x condition-class) (doc-type (eql 't)))
157 (values (info :type :documentation (class-name x))))
159 (defmethod documentation ((x condition-class) (doc-type (eql 'type)))
160 (values (info :type :documentation (class-name x))))
162 (defmethod documentation ((x symbol) (doc-type (eql 'type)))
163 (or (values (info :type :documentation x))
164 (let ((class (find-class x nil)))
166 (slot-value class '%documentation)))))
168 (defmethod documentation ((x symbol) (doc-type (eql 'structure)))
170 ((structure-type-p x)
171 (values (info :type :documentation x)))
172 ((info :typed-structure :info x)
173 (values (info :typed-structure :documentation x)))
176 (defmethod (setf documentation) (new-value
179 (setf (info :type :documentation (class-name x)) new-value))
181 (defmethod (setf documentation) (new-value
183 (doc-type (eql 'type)))
184 (setf (info :type :documentation (class-name x)) new-value))
186 (defmethod (setf documentation) (new-value
189 (setf (slot-value x '%documentation) new-value))
191 (defmethod (setf documentation) (new-value
193 (doc-type (eql 'type)))
194 (setf (slot-value x '%documentation) new-value))
196 (defmethod (setf documentation) (new-value
199 (setf (info :type :documentation (class-name x)) new-value))
201 (defmethod (setf documentation) (new-value
203 (doc-type (eql 'type)))
204 (setf (info :type :documentation (class-name x)) new-value))
206 (defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'type)))
207 (if (or (structure-type-p x) (condition-type-p x))
208 (setf (info :type :documentation x) new-value)
209 (let ((class (find-class x nil)))
211 (setf (slot-value class '%documentation) new-value)
212 (setf (info :type :documentation x) new-value)))))
214 (defmethod (setf documentation) (new-value
216 (doc-type (eql 'structure)))
218 ((structure-type-p x)
219 (setf (info :type :documentation x) new-value))
220 ((info :typed-structure :info x)
221 (setf (info :typed-structure :documentation x) new-value))
225 (defmethod documentation ((x symbol) (doc-type (eql 'variable)))
226 (values (info :variable :documentation x)))
228 (defmethod (setf documentation) (new-value
230 (doc-type (eql 'variable)))
231 (setf (info :variable :documentation x) new-value))
233 ;;; default if DOC-TYPE doesn't match one of the specified types
234 (defmethod documentation (object doc-type)
235 (warn "unsupported DOCUMENTATION: type ~S for object ~S"
240 ;;; default if DOC-TYPE doesn't match one of the specified types
241 (defmethod (setf documentation) (new-value object doc-type)
242 ;; CMU CL made this an error, but since ANSI says that even for supported
243 ;; doc types an implementation is permitted to discard docs at any time
244 ;; for any reason, this feels to me more like a warning. -- WHN 19991214
245 (warn "discarding unsupported DOCUMENTATION of type ~S for object ~S"
250 ;;; extra-standard methods, for getting at slot documentation
251 (defmethod documentation ((slotd standard-slot-definition) (doc-type (eql 't)))
252 (declare (ignore doc-type))
253 (slot-value slotd '%documentation))
255 (defmethod (setf documentation)
256 (new-value (slotd standard-slot-definition) (doc-type (eql 't)))
257 (declare (ignore doc-type))
258 (setf (slot-value slotd '%documentation) new-value))
260 ;;; Now that we have created the machinery for setting documentation, we can
261 ;;; set the documentation for the machinery for setting documentation.
263 (setf (documentation 'documentation 'function)
264 "Return the documentation string of Doc-Type for X, or NIL if
265 none exists. System doc-types are VARIABLE, FUNCTION, STRUCTURE, TYPE,