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.
12 (if (typep x 'generic-function)
13 (slot-value x '%documentation)
16 (defun (setf fun-doc) (new-value x)
17 (if (typep x 'generic-function)
18 (setf (slot-value x '%documentation) new-value)
19 (setf (%fun-doc x) new-value)))
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 (when (and (legal-fun-name-p x) (fboundp x))
30 (fun-doc (fdefinition x))))
32 (defmethod documentation ((x list) (doc-type (eql 'compiler-macro)))
33 (awhen (compiler-macro-function x)
34 (documentation it t)))
36 (defmethod documentation ((x symbol) (doc-type (eql 'function)))
37 (when (and (legal-fun-name-p x) (fboundp x))
38 (fun-doc (or (macro-function x) (fdefinition x)))))
40 (defmethod documentation ((x symbol) (doc-type (eql 'compiler-macro)))
41 (awhen (compiler-macro-function x)
42 (documentation it t)))
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 (defmethod (setf documentation) (new-value (x function) (doc-type (eql 't)))
51 (setf (fun-doc x) new-value))
53 (defmethod (setf documentation) (new-value (x function) (doc-type (eql 'function)))
54 (setf (fun-doc x) new-value))
56 (defmethod (setf documentation) (new-value (x list) (doc-type (eql 'function)))
57 (when (and (legal-fun-name-p x) (fboundp x))
58 (setf (documentation (fdefinition x) t) new-value)))
60 (defmethod (setf documentation) (new-value (x list) (doc-type (eql 'compiler-macro)))
61 (awhen (compiler-macro-function x)
62 (setf (documentation it t) new-value)))
64 (defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'function)))
65 (when (and (legal-fun-name-p x) (fboundp x))
66 (setf (documentation (symbol-function x) t) new-value)))
68 (defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'compiler-macro)))
69 (awhen (compiler-macro-function x)
70 (setf (documentation it t) new-value)))
72 (defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'setf)))
73 (setf (fdocumentation x 'setf) new-value))
75 ;;; method combinations
76 (defmethod documentation ((x method-combination) (doc-type (eql 't)))
77 (slot-value x '%documentation))
79 (defmethod documentation
80 ((x method-combination) (doc-type (eql 'method-combination)))
81 (slot-value x '%documentation))
83 (defmethod documentation ((x symbol) (doc-type (eql 'method-combination)))
84 (random-documentation x 'method-combination))
86 (defmethod (setf documentation)
87 (new-value (x method-combination) (doc-type (eql 't)))
88 (setf (slot-value x '%documentation) new-value))
90 (defmethod (setf documentation)
91 (new-value (x method-combination) (doc-type (eql 'method-combination)))
92 (setf (slot-value x '%documentation) new-value))
94 (defmethod (setf documentation)
95 (new-value (x symbol) (doc-type (eql 'method-combination)))
96 (setf (random-documentation x 'method-combination) new-value))
99 (defmethod documentation ((x standard-method) (doc-type (eql 't)))
100 (slot-value x '%documentation))
102 (defmethod (setf documentation)
103 (new-value (x standard-method) (doc-type (eql 't)))
104 (setf (slot-value x '%documentation) new-value))
108 ;;; KLUDGE: It's nasty having things like this accessor
109 ;;; (PACKAGE-DOC-STRING) floating around out in this mostly-unrelated
110 ;;; source file. Perhaps it would be better to support WARM-INIT-FORMS
111 ;;; by analogy with the existing !COLD-INIT-FORMS and have them be
112 ;;; EVAL'ed after basic warm load is done? That way things like this
113 ;;; could be defined alongside the other code which does low-level
114 ;;; hacking of packages.. -- WHN 19991203
116 (defmethod documentation ((x package) (doc-type (eql 't)))
117 (package-doc-string x))
119 (defmethod (setf documentation) (new-value (x package) (doc-type (eql 't)))
120 (setf (package-doc-string x) new-value))
122 ;;; types, classes, and structure names
123 (defmethod documentation ((x structure-class) (doc-type (eql 't)))
124 (fdocumentation (class-name x) 'type))
126 (defmethod documentation ((x structure-class) (doc-type (eql 'type)))
127 (fdocumentation (class-name x) 'type))
129 (defmethod documentation ((x standard-class) (doc-type (eql 't)))
130 (slot-value x '%documentation))
132 (defmethod documentation ((x standard-class) (doc-type (eql 'type)))
133 (slot-value x '%documentation))
135 ;;; although the CLHS doesn't mention this, it is reasonable to assume
136 ;;; that parallel treatment of condition-class was intended (if
137 ;;; condition-class is in fact not implemented as a standard-class or
138 ;;; structure-class).
139 (defmethod documentation ((x condition-class) (doc-type (eql 't)))
140 (fdocumentation (class-name x) 'type))
142 (defmethod documentation ((x condition-class) (doc-type (eql 'type)))
143 (fdocumentation (class-name x) 'type))
145 (defmethod documentation ((x symbol) (doc-type (eql 'type)))
146 (or (fdocumentation x 'type)
147 (let ((class (find-class x nil)))
149 (slot-value class '%documentation)))))
151 (defmethod documentation ((x symbol) (doc-type (eql 'structure)))
152 (fdocumentation x 'structure))
154 (defmethod (setf documentation) (new-value
157 (setf (fdocumentation (class-name x) 'type) new-value))
159 (defmethod (setf documentation) (new-value
161 (doc-type (eql 'type)))
162 (setf (fdocumentation (class-name x) 'type) new-value))
164 (defmethod (setf documentation) (new-value
167 (setf (slot-value x '%documentation) new-value))
169 (defmethod (setf documentation) (new-value
171 (doc-type (eql 'type)))
172 (setf (slot-value x '%documentation) new-value))
174 (defmethod (setf documentation) (new-value
177 (setf (fdocumentation (class-name x) 'type) new-value))
179 (defmethod (setf documentation) (new-value
181 (doc-type (eql 'type)))
182 (setf (fdocumentation (class-name x) 'type) new-value))
184 (defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'type)))
185 (if (or (structure-type-p x) (condition-type-p x))
186 (setf (fdocumentation x 'type) new-value)
187 (let ((class (find-class x nil)))
189 (setf (slot-value class '%documentation) new-value)
190 (setf (fdocumentation x 'type) new-value)))))
192 (defmethod (setf documentation) (new-value
194 (doc-type (eql 'structure)))
195 (setf (fdocumentation x 'structure) new-value))
198 (defmethod documentation ((x symbol) (doc-type (eql 'variable)))
199 (fdocumentation x 'variable))
201 (defmethod (setf documentation) (new-value
203 (doc-type (eql 'variable)))
204 (setf (fdocumentation x 'variable) new-value))
206 ;;; default if DOC-TYPE doesn't match one of the specified types
207 (defmethod documentation (object doc-type)
208 (warn "unsupported DOCUMENTATION: type ~S for object of type ~S"
213 ;;; default if DOC-TYPE doesn't match one of the specified types
214 (defmethod (setf documentation) (new-value object doc-type)
215 ;; CMU CL made this an error, but since ANSI says that even for supported
216 ;; doc types an implementation is permitted to discard docs at any time
217 ;; for any reason, this feels to me more like a warning. -- WHN 19991214
218 (warn "discarding unsupported DOCUMENTATION of type ~S for object ~S"
223 ;;; extra-standard methods, for getting at slot documentation
224 (defmethod documentation ((slotd standard-slot-definition) (doc-type (eql 't)))
225 (declare (ignore doc-type))
226 (slot-value slotd '%documentation))
228 (defmethod (setf documentation)
229 (new-value (slotd standard-slot-definition) (doc-type (eql 't)))
230 (declare (ignore doc-type))
231 (setf (slot-value slotd '%documentation) new-value))
233 ;;; Now that we have created the machinery for setting documentation, we can
234 ;;; set the documentation for the machinery for setting documentation.
236 (setf (documentation 'documentation 'function)
237 "Return the documentation string of Doc-Type for X, or NIL if
238 none exists. System doc-types are VARIABLE, FUNCTION, STRUCTURE, TYPE,