Mercurial > core / lisp/lib/doc/symbol.lisp
changeset 671: |
1f065ead57ca |
parent: |
b7183bfd7107
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Mon, 23 Sep 2024 21:22:28 -0400 |
permissions: |
-rw-r--r-- |
description: |
removed use of internal 'describe-block' |
1 ;;; lib/doc/symbol.lisp --- Symbol Documentation 8 (defmacro do-symbols* ((var &optional (package '*package*) result-form) 10 "Just like do-symbols, but makes sure a symbol is visited only once." 11 (let ((seen-ht (gensym "SEEN-HT"))) 12 `(let ((,seen-ht (make-hash-table :test #'eq))) 13 (do-symbols (,var ,package ,result-form) 14 (unless (gethash ,var ,seen-ht) 15 (setf (gethash ,var ,seen-ht) t) 45 (defun classify-symbol (symbol) 46 "Returns a list of classifiers that classify SYMBOL according to its 47 underneath objects (e.g. :BOUNDP if SYMBOL constitutes a special 48 variable.) The list may contain the following classification 49 keywords: :BOUNDP, :FBOUNDP, :CONSTANT, :GENERIC-FUNCTION, 50 :TYPESPEC, :CLASS, :MACRO, :SPECIAL-OPERATOR, and/or :PACKAGE" 51 (check-type symbol symbol) 52 (flet ((type-specifier-p (s) 53 (or (documentation s 'type) 54 (not (eq (deftype-lambda-list s) :not-available))))) 56 (when (boundp symbol) (push (if (constantp symbol) 57 :constant :boundp) result)) 58 (when (fboundp symbol) (push :function result)) 59 (when (type-specifier-p symbol) (push :type result)) 60 (when (find-class symbol nil) (push :class result)) 61 (when (typep symbol 'condition) (push :condition result)) 62 (when (typep symbol 'structure-class) (push :structure result)) 63 (when (alien-type-p symbol) (push :alien-type result)) 64 (when (vop-p symbol) (push :vop result)) 65 (when (macro-function symbol) (push :macro result)) 66 (when (special-operator-p symbol) (push :special-operator result)) 67 (when (find-package symbol) (push :package result)) 68 (when (compiler-macro-function symbol) (push :compiler-macro result)) 69 (when (compiled-function-p symbol) (push :compiled result)) 70 (when (and (fboundp symbol) 71 (typep (ignore-errors (fdefinition symbol)) 73 (push :generic-function result)) 76 (defun symbol-classification-string (symbol) 77 "Return a string in the form -f-c---- where each letter stands for 78 boundp fboundp generic-function class macro special-operator package" 79 (let ((letters "bfgctmsp") 80 (result (copy-seq "--------"))) 82 (setf (char result (position letter letters)) 84 (when (boundp symbol) (flip #\b)) 85 (when (fboundp symbol) 87 (when (typep (ignore-errors (fdefinition symbol)) 90 (when (deftype-lambda-list symbol) (flip #\t)) 91 (when (find-class symbol nil) (flip #\c) ) 92 (when (macro-function symbol) (flip #\m)) 93 (when (special-operator-p symbol) (flip #\s)) 94 (when (find-package symbol) (flip #\p)) 97 (defclass symbol-documentation (id) ;; package-id? (sb-c::symbol-package-id s) 98 ((symbol :initarg :symbol :type symbol :accessor doc-symbol) 99 (class :initarg :class :type list :accessor doc-class) 100 (definitions :initform nil :initarg :definitions :type list :accessor doc-definitions) 101 (specs :initform nil :initarg :specs :type list :accessor doc-specs) 102 (info :initarg :info :type (or null packed-info) :accessor doc-info) 103 (alloc :initarg :alloc :type list :accessor doc-alloc))) 107 (loop for x across (doc-symbols (package-documentation)) collect (doc-definitions x))) 111 (defun symbol-documentation (s) 112 "Return the SYMBOL-DOCUMENTATION object of S, a symbol." 113 (let ((class (classify-symbol s))) 114 (multiple-value-bind (defs specs) (find-definitions s) 115 (make-instance 'symbol-documentation 121 :info (symbol-dbinfo s) 122 :alloc (multiple-value-list (allocation-information s)))))) 124 (defmethod print-object ((self symbol-documentation) stream) 125 (with-slots (symbol class) self 126 (print-unreadable-object (self stream :type t) 127 (format stream "~S ~A" symbol class)))) 129 (defmethod doc-files ((self symbol-documentation)) 132 #'null ;; definition-source-pathname is allowed to be nil, 133 ;; indicating no path to definition. 134 (mapcar #'definition-source-pathname (doc-definitions self))))) 136 (defmethod describe-object ((self symbol-documentation) stream) 137 (with-slots (symbol id definitions specs alloc) self 138 (print-standard-describe-header self stream) 139 (describe symbol stream) 140 (format stream "~%Alloc Info: ~S" alloc) 141 (format stream "~%Definitions: ~%") 143 do (format stream " ~S ~S~%" s (definition-source-pathname (pop definitions))))))