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.
14 (slot-value x '%documentation))
16 (sb-eval:interpreted-function
17 (sb-eval:interpreted-function-documentation x))
21 ;;; functions, macros, and special forms
22 (defmethod documentation ((x function) (doc-type (eql 't)))
25 (defmethod documentation ((x function) (doc-type (eql 'function)))
28 (defmethod documentation ((x list) (doc-type (eql 'function)))
29 (and (legal-fun-name-p x)
31 (documentation (fdefinition x) t)))
33 (defmethod documentation ((x list) (doc-type (eql 'compiler-macro)))
34 (random-documentation x 'compiler-macro))
36 (defmethod documentation ((x symbol) (doc-type (eql 'function)))
37 (or (fdocumentation x 'function)
38 ;; Try the pcl function documentation.
39 (and (fboundp x) (documentation (fdefinition x) t))))
41 (defmethod documentation ((x symbol) (doc-type (eql 'compiler-macro)))
42 (random-documentation x 'compiler-macro))
44 (defmethod documentation ((x symbol) (doc-type (eql 'setf)))
45 (fdocumentation x 'setf))
47 (defmethod documentation ((x symbol) (doc-type (eql 'optimize)))
48 (random-documentation x 'optimize))
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 (setf (focumentation (%fun-name x) 'function) new-value)))
63 (defmethod (setf documentation) (new-value (x function) (doc-type (eql 't)))
64 (setf (fun-doc x) new-value))
66 (defmethod (setf documentation) (new-value
68 (doc-type (eql 'function)))
69 (setf (fun-doc x) new-value))
71 (defmethod (setf documentation) (new-value (x list) (doc-type (eql 'function)))
72 (setf (fdocumentation x 'function) new-value))
74 (defmethod (setf documentation)
75 (new-value (x list) (doc-type (eql 'compiler-macro)))
76 (setf (random-documentation x 'compiler-macro) new-value))
78 (defmethod (setf documentation) (new-value
80 (doc-type (eql 'function)))
81 (setf (fdocumentation x 'function) new-value))
83 (defmethod (setf documentation)
84 (new-value (x symbol) (doc-type (eql 'compiler-macro)))
85 (setf (random-documentation x 'compiler-macro) new-value))
87 (defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'setf)))
88 (setf (fdocumentation x 'setf) new-value))
90 ;;; method combinations
91 (defmethod documentation ((x method-combination) (doc-type (eql 't)))
92 (slot-value x '%documentation))
94 (defmethod documentation
95 ((x method-combination) (doc-type (eql 'method-combination)))
96 (slot-value x '%documentation))
98 (defmethod documentation ((x symbol) (doc-type (eql 'method-combination)))
99 (random-documentation x 'method-combination))
101 (defmethod (setf documentation)
102 (new-value (x method-combination) (doc-type (eql 't)))
103 (setf (slot-value x '%documentation) new-value))
105 (defmethod (setf documentation)
106 (new-value (x method-combination) (doc-type (eql 'method-combination)))
107 (setf (slot-value x '%documentation) new-value))
109 (defmethod (setf documentation)
110 (new-value (x symbol) (doc-type (eql 'method-combination)))
111 (setf (random-documentation x 'method-combination) new-value))
114 (defmethod documentation ((x standard-method) (doc-type (eql 't)))
115 (slot-value x '%documentation))
117 (defmethod (setf documentation)
118 (new-value (x standard-method) (doc-type (eql 't)))
119 (setf (slot-value x '%documentation) new-value))
123 ;;; KLUDGE: It's nasty having things like this accessor
124 ;;; (PACKAGE-DOC-STRING) floating around out in this mostly-unrelated
125 ;;; source file. Perhaps it would be better to support WARM-INIT-FORMS
126 ;;; by analogy with the existing !COLD-INIT-FORMS and have them be
127 ;;; EVAL'ed after basic warm load is done? That way things like this
128 ;;; could be defined alongside the other code which does low-level
129 ;;; hacking of packages.. -- WHN 19991203
131 (defmethod documentation ((x package) (doc-type (eql 't)))
132 (package-doc-string x))
134 (defmethod (setf documentation) (new-value (x package) (doc-type (eql 't)))
135 (setf (package-doc-string x) new-value))
137 ;;; types, classes, and structure names
138 (defmethod documentation ((x structure-class) (doc-type (eql 't)))
139 (fdocumentation (class-name x) 'type))
141 (defmethod documentation ((x structure-class) (doc-type (eql 'type)))
142 (fdocumentation (class-name x) 'type))
144 (defmethod documentation ((x standard-class) (doc-type (eql 't)))
145 (slot-value x '%documentation))
147 (defmethod documentation ((x standard-class) (doc-type (eql 'type)))
148 (slot-value x '%documentation))
150 ;;; although the CLHS doesn't mention this, it is reasonable to assume
151 ;;; that parallel treatment of condition-class was intended (if
152 ;;; condition-class is in fact not implemented as a standard-class or
153 ;;; structure-class).
154 (defmethod documentation ((x condition-class) (doc-type (eql 't)))
155 (fdocumentation (class-name x) 'type))
157 (defmethod documentation ((x condition-class) (doc-type (eql 'type)))
158 (fdocumentation (class-name x) 'type))
160 (defmethod documentation ((x symbol) (doc-type (eql 'type)))
161 (or (fdocumentation x 'type)
162 (let ((class (find-class x nil)))
164 (slot-value class '%documentation)))))
166 (defmethod documentation ((x symbol) (doc-type (eql 'structure)))
167 (fdocumentation x 'structure))
169 (defmethod (setf documentation) (new-value
172 (setf (fdocumentation (class-name x) 'type) new-value))
174 (defmethod (setf documentation) (new-value
176 (doc-type (eql 'type)))
177 (setf (fdocumentation (class-name x) 'type) new-value))
179 (defmethod (setf documentation) (new-value
182 (setf (slot-value x '%documentation) new-value))
184 (defmethod (setf documentation) (new-value
186 (doc-type (eql 'type)))
187 (setf (slot-value x '%documentation) new-value))
189 (defmethod (setf documentation) (new-value
192 (setf (fdocumentation (class-name x) 'type) new-value))
194 (defmethod (setf documentation) (new-value
196 (doc-type (eql 'type)))
197 (setf (fdocumentation (class-name x) 'type) new-value))
199 (defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'type)))
200 (if (or (structure-type-p x) (condition-type-p x))
201 (setf (fdocumentation x 'type) new-value)
202 (let ((class (find-class x nil)))
204 (setf (slot-value class '%documentation) new-value)
205 (setf (fdocumentation x 'type) new-value)))))
207 (defmethod (setf documentation) (new-value
209 (doc-type (eql 'structure)))
210 (setf (fdocumentation x 'structure) new-value))
213 (defmethod documentation ((x symbol) (doc-type (eql 'variable)))
214 (fdocumentation x 'variable))
216 (defmethod (setf documentation) (new-value
218 (doc-type (eql 'variable)))
219 (setf (fdocumentation x 'variable) new-value))
221 ;;; default if DOC-TYPE doesn't match one of the specified types
222 (defmethod documentation (object doc-type)
223 (warn "unsupported DOCUMENTATION: type ~S for object ~S"
228 ;;; default if DOC-TYPE doesn't match one of the specified types
229 (defmethod (setf documentation) (new-value object doc-type)
230 ;; CMU CL made this an error, but since ANSI says that even for supported
231 ;; doc types an implementation is permitted to discard docs at any time
232 ;; for any reason, this feels to me more like a warning. -- WHN 19991214
233 (warn "discarding unsupported DOCUMENTATION of type ~S for object ~S"
238 ;;; extra-standard methods, for getting at slot documentation
239 (defmethod documentation ((slotd standard-slot-definition) (doc-type (eql 't)))
240 (declare (ignore doc-type))
241 (slot-value slotd '%documentation))
243 (defmethod (setf documentation)
244 (new-value (slotd standard-slot-definition) (doc-type (eql 't)))
245 (declare (ignore doc-type))
246 (setf (slot-value slotd '%documentation) new-value))
248 ;;; Now that we have created the machinery for setting documentation, we can
249 ;;; set the documentation for the machinery for setting documentation.
251 (setf (documentation 'documentation 'function)
252 "Return the documentation string of Doc-Type for X, or NIL if
253 none exists. System doc-types are VARIABLE, FUNCTION, STRUCTURE, TYPE,