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 structure-class) (doc-type (eql 't)))
72 (values (info :type :documentation (class-name x))))
74 (defmethod documentation ((x structure-class) (doc-type (eql 'type)))
75 (values (info :type :documentation (class-name x))))
77 (defmethod documentation ((x symbol) (doc-type (eql 'type)))
78 (or (values (info :type :documentation x))
79 (let ((class (find-class x nil)))
81 (plist-value class 'documentation)))))
83 (defmethod documentation ((x symbol) (doc-type (eql 'structure)))
84 (when (eq (info :type :kind x) :instance)
85 (values (info :type :documentation x))))
87 (defmethod (setf documentation) (new-value
90 (setf (info :type :documentation (class-name x)) new-value))
92 (defmethod (setf documentation) (new-value
94 (doc-type (eql 'type)))
95 (setf (info :type :documentation (class-name x)) new-value))
97 (defmethod (setf documentation) (new-value (x symbol) (doc-type (eql 'type)))
98 (if (or (structure-type-p x) (condition-type-p x))
99 (setf (info :type :documentation x) new-value)
100 (let ((class (find-class x nil)))
102 (setf (plist-value class 'documentation) new-value)
103 (setf (info :type :documentation x) new-value)))))
105 (defmethod (setf documentation) (new-value
107 (doc-type (eql 'structure)))
108 (unless (eq (info :type :kind x) :instance)
109 (error "~S is not the name of a structure type." x))
110 (setf (info :type :documentation x) new-value))
113 (defmethod documentation ((x symbol) (doc-type (eql 'variable)))
114 (values (info :variable :documentation x)))
116 (defmethod (setf documentation) (new-value
118 (doc-type (eql 'variable)))
119 (setf (info :variable :documentation x) new-value))
121 ;;; miscellaneous documentation. Compiler-macro documentation is stored
122 ;;; as random-documentation and handled here.
123 (defmethod documentation ((x symbol) (doc-type symbol))
125 (values (info :random-documentation :stuff x)))))
127 (defmethod (setf documentation) (new-value (x symbol) (doc-type symbol))
128 (let ((pair (assoc doc-type (info :random-documentation :stuff x))))
130 (setf (cdr pair) new-value)
131 (push (cons doc-type new-value)
132 (info :random-documentation :stuff x))))
135 ;;; FIXME: The ((X SYMBOL) (DOC-TYPE SYMBOL)) method and its setf method should
136 ;;; have parallel versions which accept LIST-valued X arguments (for function
137 ;;; names in the (SETF FOO) style).
139 ;;; Now that we have created the machinery for setting documentation, we can
140 ;;; set the documentation for the machinery for setting documentation.
142 (setf (documentation 'documentation 'function)
143 "Return the documentation string of Doc-Type for X, or NIL if
144 none exists. System doc-types are VARIABLE, FUNCTION, STRUCTURE, TYPE,