(base-char "base-char")
(t "character")))
-(declaim (ftype (function (t stream)) describe-object))
-(defgeneric describe-object (x stream))
-
-(defvar *in-describe* nil)
+(defun print-standard-describe-header (x stream)
+ (format stream "~&~A~% [~A]~%"
+ (object-self-string x)
+ (object-type-string x)))
-(defmethod describe-object :around (x s)
- (cond (*in-describe*
- (call-next-method))
- (t
- (format s "~&~A~% [~A]~%"
- (object-self-string x)
- (object-type-string x))
- (pprint-logical-block (s nil)
- (call-next-method x s)))))
+(defgeneric describe-object (x stream))
;;; Catch-all.
+
(defmethod describe-object ((x t) s)
- (values))
+ (print-standard-describe-header x s))
(defmethod describe-object ((x cons) s)
+ (print-standard-describe-header x s)
(describe-function x nil s))
(defmethod describe-object ((x function) s)
+ (print-standard-describe-header x s)
(describe-function nil x s))
(defmethod describe-object ((x class) s)
+ (print-standard-describe-header x s)
(describe-class nil x s)
(describe-instance x s))
(defmethod describe-object ((x sb-pcl::slot-object) s)
+ (print-standard-describe-header x s)
(describe-instance x s))
(defmethod describe-object ((x character) s)
+ (print-standard-describe-header x s)
(format s "~%:_Char-code: ~S" (char-code x))
(format s "~%:_Char-name: ~A~%_" (char-name x)))
(defmethod describe-object ((x array) s)
+ (print-standard-describe-header x s)
(format s "~%Element-type: ~S" (array-element-type x))
(if (vectorp x)
(if (array-has-fill-pointer-p x)
(terpri s)))
(defmethod describe-object ((x hash-table) s)
- ;; Don't print things which are already apparent from the printed representation
- ;; -- COUNT, TEST, and WEAKNESS
- (format s "~%Occupancy: ~,1F" (float (/ (hash-table-count x) (hash-table-size x))))
+ (print-standard-describe-header x s)
+ ;; Don't print things which are already apparent from the printed
+ ;; representation -- COUNT, TEST, and WEAKNESS
+ (format s "~%Occupancy: ~,1F" (float (/ (hash-table-count x)
+ (hash-table-size x))))
(format s "~%Rehash-threshold: ~S" (hash-table-rehash-threshold x))
(format s "~%Rehash-size: ~S" (hash-table-rehash-size x))
(format s "~%Size: ~S" (hash-table-size x))
(terpri s))
(defmethod describe-object ((symbol symbol) stream)
+ (print-standard-describe-header symbol stream)
;; Describe the value cell.
(let* ((kind (info :variable :kind symbol))
(wot (ecase kind
(terpri stream))))
(defmethod describe-object ((package package) stream)
- (describe-documentation package t stream)
- (flet ((humanize (list)
- (sort (mapcar (lambda (x)
- (if (packagep x)
- (package-name x)
- x))
- list)
- #'string<))
- (out (label list)
- (describe-stuff label list stream :escape nil)))
- (let ((implemented (humanize (package-implemented-by-list package)))
- (implements (humanize (package-implements-list package)))
- (nicks (humanize (package-nicknames package)))
- (uses (humanize (package-use-list package)))
- (used (humanize (package-used-by-list package)))
- (shadows (humanize (package-shadowing-symbols package)))
- (this (list (package-name package)))
- (exports nil))
- (do-external-symbols (ext package)
- (push ext exports))
- (setf exports (humanize exports))
- (when (package-locked-p package)
- (format stream "~@:_Locked."))
- (when (set-difference implemented this :test #'string=)
- (out "Implemented-by-list" implemented))
- (when (set-difference implements this :test #'string=)
- (out "Implements-list" implements))
- (out "Nicknames" nicks)
- (out "Use-list" uses)
- (out "Used-by-list" used)
- (out "Shadows" shadows)
- (out "Exports" exports)
- (format stream "~@:_~S internal symbols."
- (package-internal-symbol-count package))))
- (terpri stream))
+ (print-standard-describe-header package stream)
+ (pprint-logical-block (stream nil)
+ (describe-documentation package t stream)
+ (flet ((humanize (list)
+ (sort (mapcar (lambda (x)
+ (if (packagep x)
+ (package-name x)
+ x))
+ list)
+ #'string<))
+ (out (label list)
+ (describe-stuff label list stream :escape nil)))
+ (let ((implemented (humanize (package-implemented-by-list package)))
+ (implements (humanize (package-implements-list package)))
+ (nicks (humanize (package-nicknames package)))
+ (uses (humanize (package-use-list package)))
+ (used (humanize (package-used-by-list package)))
+ (shadows (humanize (package-shadowing-symbols package)))
+ (this (list (package-name package)))
+ (exports nil))
+ (do-external-symbols (ext package)
+ (push ext exports))
+ (setf exports (humanize exports))
+ (when (package-locked-p package)
+ (format stream "~@:_Locked."))
+ (when (set-difference implemented this :test #'string=)
+ (out "Implemented-by-list" implemented))
+ (when (set-difference implements this :test #'string=)
+ (out "Implements-list" implements))
+ (out "Nicknames" nicks)
+ (out "Use-list" uses)
+ (out "Used-by-list" used)
+ (out "Shadows" shadows)
+ (out "Exports" exports)
+ (format stream "~@:_~S internal symbols."
+ (package-internal-symbol-count package))))
+ (terpri stream)))
\f
;;;; Helpers to deal with shared functionality
(defun describe-function (name function stream)
(let ((name (if function (fun-name function) name)))
- (when (or function (and (legal-fun-name-p name) (fboundp name)))
- (multiple-value-bind (fun what lambda-list ftype from inline
- methods)
- (cond ((and (not function) (symbolp name) (special-operator-p name))
- (let ((fun (symbol-function name)))
- (values fun "a special operator" (%fun-lambda-list fun))))
- ((and (not function) (symbolp name) (macro-function name))
- (let ((fun (macro-function name)))
- (values fun "a macro" (%fun-lambda-list fun))))
- (t
- (let ((fun (or function (fdefinition name))))
- (multiple-value-bind (ftype from)
- (if function
- (values (%fun-type function) "Derived")
- (let ((ctype (info :function :type name)))
- (values (when ctype (type-specifier ctype))
- (when ctype
- (ecase (info :function :where-from name)
- (:declared "Declared")
- ;; This is hopefully clearer to users
- ((:defined-method :defined) "Derived"))))))
- (if (typep fun 'generic-function)
- (values fun
- "a generic function"
- (sb-mop:generic-function-lambda-list fun)
- ftype
- from
- nil
- (or (sb-mop:generic-function-methods fun)
- :none))
- (values fun
- (if (compiled-function-p fun)
- "a compiled function"
- "an interpreted function")
- (%fun-lambda-list fun)
- ftype
- from
- (unless function
- (cons
- (info :function :inlinep name)
- (info :function :inline-expansion-designator name)))))))))
- (pprint-logical-block (stream nil)
- (unless function
- (format stream "~%~A names ~A:" name what)
- (pprint-indent :block 2 stream))
- (describe-lambda-list lambda-list stream)
- (when ftype
- (format stream "~@:_~A type: ~S" from ftype))
- (describe-documentation name 'function stream)
- (when (car inline)
- (format stream "~@:_Inline proclamation: ~A (~:[no ~;~]inline expansion available)"
- (car inline)
- (cdr inline)))
- (when methods
- (format stream "~@:_Method-combination: ~S"
- (sb-pcl::method-combination-type-name
- (sb-pcl:generic-function-method-combination fun)))
- (cond ((eq :none methods)
- (format stream "~@:_No methods."))
+ (if (not (or function (and (legal-fun-name-p name) (fboundp name))))
+ ;; Not defined, but possibly the type is declared, or we have
+ ;; compiled calls to it.
+ (when (legal-fun-name-p name)
+ (multiple-value-bind (from sure) (info :function :where-from name)
+ (when (or (eq :declared from) (and sure (eq :assumed from)))
+ (pprint-logical-block (stream nil)
+ (format stream "~%~A names an undefined function" name)
+ (pprint-indent :block 2 stream)
+ (format stream "~@:_~:(~A~) type: ~S"
+ from
+ (type-specifier (info :function :type name)))))))
+ ;; Defined.
+ (multiple-value-bind (fun what lambda-list ftype from inline
+ methods)
+ (cond ((and (not function) (symbolp name) (special-operator-p name))
+ (let ((fun (symbol-function name)))
+ (values fun "a special operator" (%fun-lambda-list fun))))
+ ((and (not function) (symbolp name) (macro-function name))
+ (let ((fun (macro-function name)))
+ (values fun "a macro" (%fun-lambda-list fun))))
(t
- (pprint-newline :mandatory stream)
- (pprint-logical-block (stream nil)
- (format stream "Methods:")
- (dolist (method methods)
- (pprint-indent :block 2 stream)
- (format stream "~@:_(~A ~{~S ~}~:S)"
- name
- (method-qualifiers method)
- (sb-pcl::unparse-specializers fun (sb-mop:method-specializers method)))
- (pprint-indent :block 4 stream)
- (describe-documentation method t stream nil))))))
- (describe-function-source fun stream)
- (terpri stream)))))
+ (let ((fun (or function (fdefinition name))))
+ (multiple-value-bind (ftype from)
+ (if function
+ (values (%fun-type function) "Derived")
+ (let ((ctype (info :function :type name)))
+ (values (when ctype (type-specifier ctype))
+ (when ctype
+ ;; Ensure lazy pickup of information
+ ;; from methods.
+ (sb-c::maybe-update-info-for-gf name)
+ (ecase (info :function :where-from name)
+ (:declared "Declared")
+ ;; This is hopefully clearer to users
+ ((:defined-method :defined) "Derived"))))))
+ (if (typep fun 'generic-function)
+ (values fun
+ "a generic function"
+ (sb-mop:generic-function-lambda-list fun)
+ ftype
+ from
+ nil
+ (or (sb-mop:generic-function-methods fun)
+ :none))
+ (values fun
+ (if (compiled-function-p fun)
+ "a compiled function"
+ "an interpreted function")
+ (%fun-lambda-list fun)
+ ftype
+ from
+ (unless function
+ (cons
+ (info :function :inlinep name)
+ (info :function :inline-expansion-designator name)))))))))
+ (pprint-logical-block (stream nil)
+ (unless function
+ (format stream "~%~A names ~A:" name what)
+ (pprint-indent :block 2 stream))
+ (describe-lambda-list lambda-list stream)
+ (when (and ftype from)
+ (format stream "~@:_~A type: ~S" from ftype))
+ (describe-documentation name 'function stream)
+ (when (car inline)
+ (format stream "~@:_Inline proclamation: ~A (~:[no ~;~]inline expansion available)"
+ (car inline)
+ (cdr inline)))
+ (when methods
+ (format stream "~@:_Method-combination: ~S"
+ (sb-pcl::method-combination-type-name
+ (sb-pcl:generic-function-method-combination fun)))
+ (cond ((eq :none methods)
+ (format stream "~@:_No methods."))
+ (t
+ (pprint-newline :mandatory stream)
+ (pprint-logical-block (stream nil)
+ (format stream "Methods:")
+ (dolist (method methods)
+ (pprint-indent :block 2 stream)
+ (format stream "~@:_(~A ~{~S ~}~:S)"
+ name
+ (method-qualifiers method)
+ (sb-pcl::unparse-specializers fun (sb-mop:method-specializers method)))
+ (pprint-indent :block 4 stream)
+ (describe-documentation method t stream nil))))))
+ (describe-function-source fun stream)
+ (terpri stream)))))
(unless function
(awhen (and (legal-fun-name-p name) (compiler-macro-function name))
(pprint-logical-block (stream nil)