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.
14 ;;; functions, macros, and special forms
15 (defmethod documentation ((x function) (doc-type (eql 't)))
16 (if (typep x 'generic-function)
17 (slot-value x 'documentation)
20 (defmethod documentation ((x function) (doc-type (eql 'function)))
21 (if (typep x 'generic-function)
22 (slot-value x 'documentation)
25 (defmethod documentation ((x list) (doc-type (eql 'function)))
26 (and (legal-fun-name-p x)
28 (documentation (fdefinition x) t)))
30 (defmethod documentation ((x list) (doc-type (eql 'compiler-macro)))
31 (random-documentation x 'compiler-macro))
33 (defmethod documentation ((x symbol) (doc-type (eql 'function)))
34 (or (values (info :function :documentation x))
35 ;; Try the pcl function documentation.
36 (and (fboundp x) (documentation (fdefinition x) t))))
38 (defmethod documentation ((x symbol) (doc-type (eql 'compiler-macro)))
39 (random-documentation x 'compiler-macro))
41 (defmethod documentation ((x symbol) (doc-type (eql 'setf)))
42 (values (info :setf :documentation x)))
44 (defmethod (setf documentation) (new-value (x function) (doc-type (eql 't)))
45 (if (typep x 'generic-function)
46 (setf (slot-value x 'documentation) new-value)
47 (let ((name (%fun-name x)))
48 (when (and name (typep name '(or symbol cons)))
49 (setf (info :function :documentation name) new-value))))
52 (defmethod (setf documentation)
53 (new-value (x function) (doc-type (eql 'function)))
54 (if (typep x 'generic-function)
55 (setf (slot-value x 'documentation) new-value)
56 (let ((name (%fun-name x)))
57 (when (and name (typep name '(or symbol cons)))
58 (setf (info :function :documentation name) new-value))))
61 (defmethod (setf documentation) (new-value (x list) (doc-type (eql 'function)))
62 (setf (info :function :documentation x) new-value))
64 (defmethod (setf documentation)
65 (new-value (x list) (doc-type (eql 'compiler-macro)))
66 (setf (random-documentation x 'compiler-macro) new-value))
68 (defmethod (setf documentation) (new-value
70 (doc-type (eql 'function)))
71 (setf (info :function :documentation x) new-value))
73 (defmethod (setf documentation)
74 (new-value (x symbol) (doc-type (eql 'compiler-macro)))
75 (setf (random-documentation x 'compiler-macro) new-value))
77 (defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'setf)))
78 (setf (info :setf :documentation x) new-value))
80 ;;; method combinations
81 (defmethod documentation ((x method-combination) (doc-type (eql 't)))
82 (slot-value x 'documentation))
84 (defmethod documentation
85 ((x method-combination) (doc-type (eql 'method-combination)))
86 (slot-value x 'documentation))
88 (defmethod documentation ((x symbol) (doc-type (eql 'method-combination)))
89 (random-documentation x 'method-combination))
91 (defmethod (setf documentation)
92 (new-value (x method-combination) (doc-type (eql 't)))
93 (setf (slot-value x 'documentation) new-value))
95 (defmethod (setf documentation)
96 (new-value (x method-combination) (doc-type (eql 'method-combination)))
97 (setf (slot-value x 'documentation) new-value))
99 (defmethod (setf documentation)
100 (new-value (x symbol) (doc-type (eql 'method-combination)))
101 (setf (random-documentation x 'method-combination) new-value))
104 (defmethod documentation ((x standard-method) (doc-type (eql 't)))
105 (slot-value x 'documentation))
107 (defmethod (setf documentation)
108 (new-value (x standard-method) (doc-type (eql 't)))
109 (setf (slot-value x 'documentation) new-value))
113 ;;; KLUDGE: It's nasty having things like this accessor
114 ;;; (PACKAGE-DOC-STRING) floating around out in this mostly-unrelated
115 ;;; source file. Perhaps it would be better to support WARM-INIT-FORMS
116 ;;; by analogy with the existing !COLD-INIT-FORMS and have them be
117 ;;; EVAL'ed after basic warm load is done? That way things like this
118 ;;; could be defined alongside the other code which does low-level
119 ;;; hacking of packages.. -- WHN 19991203
121 (defmethod documentation ((x package) (doc-type (eql 't)))
122 (package-doc-string x))
124 (defmethod (setf documentation) (new-value (x package) (doc-type (eql 't)))
125 (setf (package-doc-string x) new-value))
127 ;;; types, classes, and structure names
128 (defmethod documentation ((x structure-class) (doc-type (eql 't)))
129 (values (info :type :documentation (class-name x))))
131 (defmethod documentation ((x structure-class) (doc-type (eql 'type)))
132 (values (info :type :documentation (class-name x))))
134 (defmethod documentation ((x standard-class) (doc-type (eql 't)))
135 (slot-value x 'documentation))
137 (defmethod documentation ((x standard-class) (doc-type (eql 'type)))
138 (slot-value x 'documentation))
140 (defmethod documentation ((x symbol) (doc-type (eql 'type)))
141 (or (values (info :type :documentation x))
142 (let ((class (find-class x nil)))
144 (slot-value class 'documentation)))))
146 (defmethod documentation ((x symbol) (doc-type (eql 'structure)))
147 (when (eq (info :type :kind x) :instance)
148 (values (info :type :documentation x))))
150 (defmethod (setf documentation) (new-value
153 (setf (info :type :documentation (class-name x)) new-value))
155 (defmethod (setf documentation) (new-value
157 (doc-type (eql 'type)))
158 (setf (info :type :documentation (class-name x)) new-value))
160 (defmethod (setf documentation) (new-value
163 (setf (slot-value x 'documentation) new-value))
165 (defmethod (setf documentation) (new-value
167 (doc-type (eql 'type)))
168 (setf (slot-value x 'documentation) new-value))
170 (defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'type)))
171 (if (or (structure-type-p x) (condition-type-p x))
172 (setf (info :type :documentation x) new-value)
173 (let ((class (find-class x nil)))
175 (setf (slot-value class 'documentation) new-value)
176 (setf (info :type :documentation x) new-value)))))
178 (defmethod (setf documentation) (new-value
180 (doc-type (eql 'structure)))
181 (unless (eq (info :type :kind x) :instance)
182 (error "~S is not the name of a structure type." x))
183 (setf (info :type :documentation x) new-value))
186 (defmethod documentation ((x symbol) (doc-type (eql 'variable)))
187 (values (info :variable :documentation x)))
189 (defmethod (setf documentation) (new-value
191 (doc-type (eql 'variable)))
192 (setf (info :variable :documentation x) new-value))
194 ;;; default if DOC-TYPE doesn't match one of the specified types
195 (defmethod documentation (object doc-type)
196 (warn "unsupported DOCUMENTATION: type ~S for object ~S"
201 ;;; default if DOC-TYPE doesn't match one of the specified types
202 (defmethod (setf documentation) (new-value object doc-type)
203 ;; CMU CL made this an error, but since ANSI says that even for supported
204 ;; doc types an implementation is permitted to discard docs at any time
205 ;; for any reason, this feels to me more like a warning. -- WHN 19991214
206 (warn "discarding unsupported DOCUMENTATION of type ~S for object ~S"
211 ;;; extra-standard methods, for getting at slot documentation
212 (defmethod documentation ((slotd standard-slot-definition) (doc-type (eql 't)))
213 (declare (ignore doc-type))
214 (slot-value slotd 'documentation))
216 (defmethod (setf documentation)
217 (new-value (slotd standard-slot-definition) (doc-type (eql 't)))
218 (declare (ignore doc-type))
219 (setf (slot-value slotd 'documentation) new-value))
221 ;;; Now that we have created the machinery for setting documentation, we can
222 ;;; set the documentation for the machinery for setting documentation.
224 (setf (documentation 'documentation 'function)
225 "Return the documentation string of Doc-Type for X, or NIL if
226 none exists. System doc-types are VARIABLE, FUNCTION, STRUCTURE, TYPE,