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 ;;; Note some cases are handled by the documentation methods in
13 ;;; FIXME: Those should probably be moved into this file too.
15 ;;; FIXME: Lots of bare calls to INFO here could be handled
16 ;;; more cleanly by calling the FDOCUMENTATION function instead.
18 ;;; FIXME: Neither SBCL nor Debian CMU CL 2.4.17 handles
20 ;;; (SETF (DOCUMENTATION #'FOO 'FUNCTION) "testing")
22 ;;; Can't change the documentation of #<interpreted function FOO {900BF51}>.
23 ;;; The coverage of the DOCUMENTATION methods ought to be systematically
24 ;;; compared to the ANSI specification of DOCUMENTATION.
26 ;;; functions, macros, and special forms
27 (defmethod documentation ((x function) (doc-type (eql 't)))
30 (defmethod documentation ((x function) (doc-type (eql 'function)))
33 (defmethod documentation ((x list) (doc-type (eql 'function)))
34 (and (legal-fun-name-p x)
36 (documentation (fdefinition x) t)))
38 (defmethod documentation ((x symbol) (doc-type (eql 'function)))
39 (or (values (info :function :documentation x))
40 ;; Try the pcl function documentation.
41 (and (fboundp x) (documentation (fdefinition x) t))))
43 (defmethod documentation ((x symbol) (doc-type (eql 'setf)))
44 (values (info :setf :documentation x)))
46 (defmethod (setf documentation) (new-value (x list) (doc-type (eql 'function)))
47 (setf (info :function :documentation x) new-value))
49 (defmethod (setf documentation) (new-value
51 (doc-type (eql 'function)))
52 (setf (info :function :documentation x) new-value))
54 (defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'setf)))
55 (setf (info :setf :documentation x) new-value))
58 (defmethod documentation ((x package) (doc-type (eql 't)))
59 (package-doc-string x))
61 (defmethod (setf documentation) (new-value (x package) (doc-type (eql 't)))
62 (setf (package-doc-string x) new-value))
63 ;;; KLUDGE: It's nasty having things like this accessor floating around
64 ;;; out in this mostly-unrelated source file. Perhaps it would be
65 ;;; better to support WARM-INIT-FORMS by analogy with the existing
66 ;;; !COLD-INIT-FORMS and have them be EVAL'ed after basic warm load is
67 ;;; done? That way things like this could be defined alongside the
68 ;;; other code which does low-level hacking of packages.. -- WHN 19991203
70 ;;; types, classes, and structure names
71 (defmethod documentation ((x cl:structure-class) (doc-type (eql 't)))
72 (values (info :type :documentation (cl:class-name x))))
74 (defmethod documentation ((x structure-class) (doc-type (eql 't)))
75 (values (info :type :documentation (class-name x))))
77 (defmethod documentation ((x cl:standard-class) (doc-type (eql 't)))
78 (or (values (info :type :documentation (cl:class-name x)))
79 (let ((pcl-class (sb-kernel:class-pcl-class x)))
80 (and pcl-class (plist-value pcl-class 'documentation)))))
82 (defmethod documentation ((x cl:structure-class) (doc-type (eql 'type)))
83 (values (info :type :documentation (cl:class-name x))))
85 (defmethod documentation ((x structure-class) (doc-type (eql 'type)))
86 (values (info :type :documentation (class-name x))))
88 (defmethod documentation ((x cl:standard-class) (doc-type (eql 'type)))
89 (or (values (info :type :documentation (cl:class-name x)))
90 (let ((pcl-class (sb-kernel:class-pcl-class x)))
91 (and pcl-class (plist-value pcl-class 'documentation)))))
93 (defmethod documentation ((x symbol) (doc-type (eql 'type)))
94 (or (values (info :type :documentation x))
95 (let ((class (find-class x nil)))
97 (plist-value class 'documentation)))))
99 (defmethod documentation ((x symbol) (doc-type (eql 'structure)))
100 (when (eq (info :type :kind x) :instance)
101 (values (info :type :documentation x))))
103 (defmethod (setf documentation) (new-value
104 (x cl:structure-class)
106 (setf (info :type :documentation (cl:class-name x)) new-value))
108 (defmethod (setf documentation) (new-value
111 (setf (info :type :documentation (class-name x)) new-value))
113 (defmethod (setf documentation) (new-value
114 (x cl:structure-class)
115 (doc-type (eql 'type)))
116 (setf (info :type :documentation (cl:class-name x)) new-value))
118 (defmethod (setf documentation) (new-value
120 (doc-type (eql 'type)))
121 (setf (info :type :documentation (class-name x)) new-value))
123 (defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'type)))
124 (if (structure-type-p x) ; Catch structures first.
125 (setf (info :type :documentation x) new-value)
126 (let ((class (find-class x nil)))
128 (setf (plist-value class 'documentation) new-value)
129 (setf (info :type :documentation x) new-value)))))
131 (defmethod (setf documentation) (new-value
133 (doc-type (eql 'structure)))
134 (unless (eq (info :type :kind x) :instance)
135 (error "~S is not the name of a structure type." x))
136 (setf (info :type :documentation x) new-value))
139 (defmethod documentation ((x symbol) (doc-type (eql 'variable)))
140 (values (info :variable :documentation x)))
142 (defmethod (setf documentation) (new-value
144 (doc-type (eql 'variable)))
145 (setf (info :variable :documentation x) new-value))
147 ;;; miscellaneous documentation. Compiler-macro documentation is stored
148 ;;; as random-documentation and handled here.
149 (defmethod documentation ((x symbol) (doc-type symbol))
151 (values (info :random-documentation :stuff x)))))
153 (defmethod (setf documentation) (new-value (x symbol) (doc-type symbol))
154 (let ((pair (assoc doc-type (info :random-documentation :stuff x))))
156 (setf (cdr pair) new-value)
157 (push (cons doc-type new-value)
158 (info :random-documentation :stuff x))))
161 ;;; FIXME: The ((X SYMBOL) (DOC-TYPE SYMBOL)) method and its setf method should
162 ;;; have parallel versions which accept LIST-valued X arguments (for function
163 ;;; names in the (SETF FOO) style).
165 ;;; Now that we have created the machinery for setting documentation, we can
166 ;;; set the documentation for the machinery for setting documentation.
168 (setf (documentation 'documentation 'function)
169 "Return the documentation string of Doc-Type for X, or NIL if
170 none exists. System doc-types are VARIABLE, FUNCTION, STRUCTURE, TYPE,