| 1 |
;;;; -*- Mode: Lisp; Syntax: Common-Lisp; indent-tabs-mode: nil; Package: CLOS -*- |
| 2 |
;;;; vim: set filetype=lisp tabstop=8 shiftwidth=2 expandtab: |
| 3 |
|
| 4 |
;;;; |
| 5 |
;;;; Copyright (c) 1992, Giuseppe Attardi. |
| 6 |
;;;; Copyright (c) 2001, Juan Jose Garcia Ripoll. |
| 7 |
;;;; |
| 8 |
;;;; See file 'LICENSE' for the copyright details. |
| 9 |
|
| 10 |
(in-package "CLOS") |
| 11 |
|
| 12 |
;;; ---------------------------------------------------------------------- |
| 13 |
;;; INTERACTIVE NAVIGATION THROUGH OBJECTS |
| 14 |
;;; |
| 15 |
|
| 16 |
(defmethod select-clos-N ((instance standard-object)) |
| 17 |
(let* ((class (si:instance-class instance)) |
| 18 |
(local-slotds (class-local-slots class)) |
| 19 |
(class-slotds (class-class-slots class))) |
| 20 |
(if local-slotds |
| 21 |
(progn |
| 22 |
(si::inspect-indent) |
| 23 |
(format t "The local slots are:~%") |
| 24 |
(incf si::*inspect-level*) |
| 25 |
(dolist (slotd local-slotds) |
| 26 |
(si::inspect-indent-1) |
| 27 |
(format t "name : ~S" (clos::slot-definition-name slotd)) |
| 28 |
(if (slot-boundp instance (clos::slot-definition-name slotd)) |
| 29 |
(si::inspect-recursively "value:" |
| 30 |
(slot-value instance (clos::slot-definition-name slotd)) |
| 31 |
(slot-value instance (clos::slot-definition-name slotd))) |
| 32 |
(si::inspect-print "value: Unbound" |
| 33 |
nil |
| 34 |
(slot-value instance (clos::slot-definition-name slotd))))) |
| 35 |
(decf si::*inspect-level*)) |
| 36 |
(progn |
| 37 |
(si::inspect-indent) |
| 38 |
(format t "It has no local slots.~%"))) |
| 39 |
(if class-slotds |
| 40 |
(progn |
| 41 |
(si::inspect-indent) |
| 42 |
(format t "The class slots are:~%") |
| 43 |
(incf si::*inspect-level*) |
| 44 |
(dolist (slotd class-slotds) |
| 45 |
(si::inspect-indent-1) |
| 46 |
(format t "name : ~S" (clos::slot-definition-name slotd)) |
| 47 |
(if (slot-boundp instance (clos::slot-definition-name slotd)) |
| 48 |
(si::inspect-recursively "value:" |
| 49 |
(slot-value instance (clos::slot-definition-name slotd)) |
| 50 |
(slot-value instance (clos::slot-definition-name slotd))) |
| 51 |
(si::inspect-print "value: Unbound" |
| 52 |
nil |
| 53 |
(slot-value instance (clos::slot-definition-name slotd))))) |
| 54 |
(decf si::*inspect-level*)) |
| 55 |
(progn |
| 56 |
(si::inspect-indent) |
| 57 |
(format t "It has no class slots.~%"))))) |
| 58 |
|
| 59 |
(defun select-clos-N-inner-class (instance) |
| 60 |
(let* ((class (si:instance-class instance)) |
| 61 |
(local-slotds (class-local-slots class))) |
| 62 |
(if local-slotds |
| 63 |
(progn |
| 64 |
(si::inspect-indent) |
| 65 |
(format t "The (local) slots are:~%") |
| 66 |
(incf si::*inspect-level*) |
| 67 |
(dolist (slotd local-slotds) |
| 68 |
(si::inspect-indent-1) |
| 69 |
(format t "name : ~S" (clos::slot-definition-name slotd)) |
| 70 |
(if (slot-boundp instance (clos::slot-definition-name slotd)) |
| 71 |
(si::inspect-recursively "value:" |
| 72 |
(slot-value instance (clos::slot-definition-name slotd)) |
| 73 |
; (slot-value instance (clos::slot-definition-name slotd)) |
| 74 |
) |
| 75 |
(si::inspect-print "value: Unbound" |
| 76 |
nil |
| 77 |
; (slot-value instance (clos::slot-definition-name slotd)) |
| 78 |
))) |
| 79 |
(decf si::*inspect-level*)) |
| 80 |
(progn |
| 81 |
(si::inspect-indent) |
| 82 |
(format t "It has no (local) slots.~%"))))) |
| 83 |
|
| 84 |
(defmethod select-clos-N ((instance std-class)) |
| 85 |
(select-clos-N-inner-class instance)) |
| 86 |
|
| 87 |
(defmethod select-clos-N ((instance t)) |
| 88 |
(select-clos-N-inner-class instance)) |
| 89 |
|
| 90 |
(defmethod select-clos-L ((instance standard-object)) |
| 91 |
(let* ((class (si:instance-class instance)) |
| 92 |
(local-slotds (class-local-slots class)) |
| 93 |
(class-slotds (class-class-slots class))) |
| 94 |
(terpri) |
| 95 |
(if local-slotds |
| 96 |
(progn |
| 97 |
(format t "The names of the local slots are:~%") |
| 98 |
(dolist (slotd local-slotds) |
| 99 |
(format t " ~S~%" (clos::slot-definition-name slotd)))) |
| 100 |
(progn |
| 101 |
(format t "It has no local slots.~%"))) |
| 102 |
(terpri) |
| 103 |
(if class-slotds |
| 104 |
(progn |
| 105 |
(format t "The names of the class slots are:~%") |
| 106 |
(dolist (slotd class-slotds) |
| 107 |
(format t " ~S~%" (clos::slot-definition-name slotd)))) |
| 108 |
(progn |
| 109 |
(format t "It has no class slots.~%"))) |
| 110 |
(terpri))) |
| 111 |
|
| 112 |
(defun select-clos-L-inner-class (instance) |
| 113 |
(let* ((class (si:instance-class instance)) |
| 114 |
(local-slotds (class-local-slots class))) |
| 115 |
(terpri) |
| 116 |
(if local-slotds |
| 117 |
(progn |
| 118 |
(format t "The names of the (local) slots are:~%") |
| 119 |
(dolist (slotd local-slotds) |
| 120 |
(format t " ~S~%" (clos::slot-definition-name slotd)))) |
| 121 |
(progn |
| 122 |
(format t "It has no (local) slots.~%"))) |
| 123 |
(terpri))) |
| 124 |
|
| 125 |
(defmethod select-clos-L ((instance std-class)) |
| 126 |
(select-clos-L-inner-class instance)) |
| 127 |
|
| 128 |
(defmethod select-clos-L ((instance t)) |
| 129 |
(select-clos-L-inner-class instance)) |
| 130 |
|
| 131 |
(defmethod select-clos-J ((instance standard-object)) |
| 132 |
(let* ((class (si:instance-class instance)) |
| 133 |
(local-slotds (class-local-slots class)) |
| 134 |
(class-slotds (class-class-slots class)) |
| 135 |
(slotd (car (member (prog1 |
| 136 |
(read-preserving-whitespace *query-io*) |
| 137 |
(si::inspect-read-line)) |
| 138 |
(append local-slotds class-slotds) |
| 139 |
:key #'clos::slot-definition-name |
| 140 |
:test #'eq)))) |
| 141 |
(if slotd |
| 142 |
(progn |
| 143 |
(incf si::*inspect-level*) |
| 144 |
(si::inspect-indent-1) |
| 145 |
(format t "name : ~S" (clos::slot-definition-name slotd)) |
| 146 |
(if (slot-boundp instance (clos::slot-definition-name slotd)) |
| 147 |
(si::inspect-recursively "value:" |
| 148 |
(slot-value instance (clos::slot-definition-name slotd)) |
| 149 |
(slot-value instance (clos::slot-definition-name slotd))) |
| 150 |
(si::inspect-print "value: Unbound" |
| 151 |
nil |
| 152 |
(slot-value instance (clos::slot-definition-name slotd)))) |
| 153 |
(decf si::*inspect-level*)) |
| 154 |
(progn |
| 155 |
(terpri) |
| 156 |
(format t "~S is not a slot of the instance." (slot-definition-name slotd)) |
| 157 |
(terpri) |
| 158 |
(terpri))))) |
| 159 |
|
| 160 |
(defun select-clos-J-inner-class (instance) |
| 161 |
(let* ((class (si:instance-class instance)) |
| 162 |
(local-slotds (class-local-slots class)) |
| 163 |
(slotd (car (member (prog1 |
| 164 |
(read-preserving-whitespace *query-io*) |
| 165 |
(si::inspect-read-line)) |
| 166 |
local-slotds |
| 167 |
:key #'clos::slot-definition-name |
| 168 |
:test #'eq)))) |
| 169 |
(if slotd |
| 170 |
(progn |
| 171 |
(incf si::*inspect-level*) |
| 172 |
(si::inspect-indent-1) |
| 173 |
(format t "name : ~S" (clos::slot-definition-name slotd)) |
| 174 |
(if (slot-boundp instance (clos::slot-definition-name slotd)) |
| 175 |
(si::inspect-recursively "value:" |
| 176 |
(slot-value instance (clos::slot-definition-name slotd)) |
| 177 |
; (slot-value instance (clos::slot-definition-name slotd)) |
| 178 |
) |
| 179 |
(si::inspect-print "value: Unbound" |
| 180 |
nil |
| 181 |
; (slot-value instance (clos::slot-definition-name slotd)) |
| 182 |
)) |
| 183 |
(decf si::*inspect-level*)) |
| 184 |
(progn |
| 185 |
(terpri) |
| 186 |
(format t "~S is not a slot of the instance." (slot-definition-name slotd)) |
| 187 |
(terpri) |
| 188 |
(terpri))))) |
| 189 |
|
| 190 |
(defmethod select-clos-J ((instance std-class)) |
| 191 |
(select-clos-J-inner-class instance)) |
| 192 |
|
| 193 |
(defmethod select-clos-J ((instance t)) |
| 194 |
(select-clos-J-inner-class instance)) |
| 195 |
|
| 196 |
(defun select-clos-? () |
| 197 |
(declare (si::c-local)) |
| 198 |
(terpri) |
| 199 |
(format t |
| 200 |
"Inspect commands for clos instances:~%~ |
| 201 |
n (or N or Newline): inspects all slots of the class (recursively).~%~ |
| 202 |
s (or S): skips the field.~%~ |
| 203 |
p (or P): pretty-prints the field.~%~ |
| 204 |
a (or A): aborts the inspection of the rest of the fields.~%~ |
| 205 |
e (or E) form: evaluates and prints the form.~%~ |
| 206 |
l (or L): show the names of all slots.~%~ |
| 207 |
j (or J) slot-name: inspect the slot with the name requested.~%~ |
| 208 |
q (or Q): quits the inspection.~%~ |
| 209 |
?: prints this.~%~%" |
| 210 |
)) |
| 211 |
|
| 212 |
(defun class-local-slots (class) |
| 213 |
(remove :class (class-slots class) :key #'clos::slot-definition-allocation)) |
| 214 |
|
| 215 |
(defun class-class-slots (class) |
| 216 |
(remove :instance (class-slots class) :key #'clos::slot-definition-allocation)) |
| 217 |
|
| 218 |
(defmethod inspect-obj ((instance standard-object)) |
| 219 |
(unless (let ((metaclass (si:instance-class (si:instance-class instance)))) |
| 220 |
(or (eq metaclass (find-class 'STANDARD-CLASS)) |
| 221 |
(eq metaclass (find-class 'FUNCALLABLE-STANDARD-CLASS)))) |
| 222 |
(terpri) |
| 223 |
(format t "No applicable method CLOS::INSPECT-OBJ for an instance~%") |
| 224 |
(format t "of class ~S" (si:instance-class instance)) |
| 225 |
(throw 'SI::ABORT-INSPECT nil)) |
| 226 |
(decf si::*inspect-level*) |
| 227 |
(let* ((class (si:instance-class instance)) |
| 228 |
(local-slotds (class-local-slots class)) |
| 229 |
(class-slotds (class-class-slots class))) |
| 230 |
(declare (type class class)) |
| 231 |
(loop |
| 232 |
(format t "~S - clos object:" instance) |
| 233 |
(incf si::*inspect-level*) |
| 234 |
(si::inspect-indent) |
| 235 |
(format t "- it is an instance of class named ~S," |
| 236 |
(class-name class)) |
| 237 |
(si::inspect-indent) |
| 238 |
(format t "- it has ~A local slots and ~A class slots: " |
| 239 |
(length local-slotds) (length class-slotds)) |
| 240 |
(force-output) |
| 241 |
(case (do ((char (read-char *query-io*) (read-char *query-io*))) |
| 242 |
((and (char/= char #\Space) (char/= #\Tab)) char)) |
| 243 |
((#\Newline #\Return) |
| 244 |
(select-clos-N instance) |
| 245 |
(return nil)) |
| 246 |
((#\n #\N) |
| 247 |
(si::inspect-read-line) |
| 248 |
(select-clos-N instance) |
| 249 |
(return nil)) |
| 250 |
((#\s #\S) |
| 251 |
(si::inspect-read-line) |
| 252 |
(return nil)) |
| 253 |
((#\p #\P) |
| 254 |
(si::inspect-read-line) |
| 255 |
(si::select-P instance)) |
| 256 |
((#\a #\A) |
| 257 |
(si::inspect-read-line) |
| 258 |
(throw 'SI::ABORT-INSPECT nil)) |
| 259 |
((#\e #\E) |
| 260 |
(si::select-E)) |
| 261 |
((#\q #\Q) |
| 262 |
(si::inspect-read-line) |
| 263 |
(throw 'SI::QUIT-INSPECT nil)) |
| 264 |
((#\l #\L) |
| 265 |
(si::inspect-read-line) |
| 266 |
(select-clos-L instance)) |
| 267 |
((#\j #\J) |
| 268 |
(select-clos-J instance)) |
| 269 |
((#\?) |
| 270 |
(si::inspect-read-line) |
| 271 |
(select-clos-?)) |
| 272 |
(t |
| 273 |
(si::inspect-read-line))) |
| 274 |
(decf si::*inspect-level*) |
| 275 |
(si::inspect-indent))) |
| 276 |
(incf si::*inspect-level*)) |
| 277 |
|
| 278 |
(defun inspect-obj-inner-class (instance) |
| 279 |
(decf si::*inspect-level*) |
| 280 |
(let* ((class (si:instance-class instance)) |
| 281 |
(local-slotds (class-local-slots class))) |
| 282 |
(declare (type class class)) |
| 283 |
(loop |
| 284 |
(format t "~S - clos object:" instance) |
| 285 |
(incf si::*inspect-level*) |
| 286 |
(si::inspect-indent) |
| 287 |
(format t "- it is an instance of class named ~S," |
| 288 |
(class-name class)) |
| 289 |
(si::inspect-indent) |
| 290 |
(format t "- it has ~A local slots: " (length local-slotds)) |
| 291 |
(force-output) |
| 292 |
(case (do ((char (read-char *query-io*) (read-char *query-io*))) |
| 293 |
((and (char/= char #\Space) (char/= #\Tab)) char)) |
| 294 |
((#\Newline #\Return) |
| 295 |
(select-clos-N instance) |
| 296 |
(return nil)) |
| 297 |
((#\n #\N) |
| 298 |
(si::inspect-read-line) |
| 299 |
(select-clos-N instance) |
| 300 |
(return nil)) |
| 301 |
((#\s #\S) |
| 302 |
(si::inspect-read-line) |
| 303 |
(return nil)) |
| 304 |
((#\p #\P) |
| 305 |
(si::inspect-read-line) |
| 306 |
(si::select-P instance)) |
| 307 |
((#\a #\A) |
| 308 |
(si::inspect-read-line) |
| 309 |
(throw 'SI::ABORT-INSPECT nil)) |
| 310 |
((#\e #\E) |
| 311 |
(si::select-E)) |
| 312 |
((#\q #\Q) |
| 313 |
(si::inspect-read-line) |
| 314 |
(throw 'SI::QUIT-INSPECT nil)) |
| 315 |
((#\l #\L) |
| 316 |
(si::inspect-read-line) |
| 317 |
(select-clos-L instance)) |
| 318 |
((#\j #\J) |
| 319 |
(select-clos-J instance)) |
| 320 |
((#\?) |
| 321 |
(si::inspect-read-line) |
| 322 |
(select-clos-?)) |
| 323 |
(t |
| 324 |
(si::inspect-read-line))) |
| 325 |
(decf si::*inspect-level*) |
| 326 |
(si::inspect-indent))) |
| 327 |
(incf si::*inspect-level*)) |
| 328 |
|
| 329 |
(defmethod inspect-obj ((instance std-class)) |
| 330 |
(inspect-obj-inner-class instance)) |
| 331 |
|
| 332 |
(defmethod inspect-obj ((instance t)) |
| 333 |
(inspect-obj-inner-class instance)) |
| 334 |
|
| 335 |
;;; ------------------------------------------------------------------------- |
| 336 |
;;; |
| 337 |
;;; Documentation |
| 338 |
;;; |
| 339 |
|
| 340 |
(defconstant +valid-documentation-types+ |
| 341 |
'(compiler-macro function method-combination setf structure |
| 342 |
t type variable)) |
| 343 |
|
| 344 |
(defgeneric documentation (object doc-type)) |
| 345 |
(defgeneric (setf documentation) (new-value object doc-type)) |
| 346 |
|
| 347 |
(defmethod documentation ((object symbol) doc-type) |
| 348 |
(when (member doc-type +valid-documentation-types+) |
| 349 |
(case doc-type |
| 350 |
(type |
| 351 |
(let ((c (find-class object nil))) |
| 352 |
(if c |
| 353 |
(documentation c t) |
| 354 |
(si::get-documentation object doc-type)))) |
| 355 |
(function |
| 356 |
(or (si::get-documentation object doc-type) |
| 357 |
(and (fboundp object) |
| 358 |
(documentation (or (macro-function object) |
| 359 |
(fdefinition object)) |
| 360 |
doc-type)))) |
| 361 |
(otherwise |
| 362 |
(si::get-documentation object doc-type))))) |
| 363 |
|
| 364 |
(defmethod (setf documentation) (new-value (object symbol) doc-type) |
| 365 |
(when (member doc-type +valid-documentation-types+) |
| 366 |
(case doc-type |
| 367 |
(type |
| 368 |
(let ((c (find-class object nil))) |
| 369 |
(if c |
| 370 |
(progn |
| 371 |
(si::set-documentation object 'type nil) |
| 372 |
(si::set-documentation object 'structure nil) |
| 373 |
(setf (documentation c t) new-value)) |
| 374 |
(si::set-documentation object doc-type new-value)))) |
| 375 |
(function |
| 376 |
(if (fboundp object) |
| 377 |
(let ((c (or (macro-function object) (fdefinition object)))) |
| 378 |
(si::set-documentation c 'function nil) |
| 379 |
(setf (documentation c 'function) new-value)) |
| 380 |
(si::set-documentation object doc-type new-value))) |
| 381 |
(otherwise |
| 382 |
(si::set-documentation object doc-type new-value)))) |
| 383 |
new-value) |
| 384 |
|
| 385 |
(defmethod documentation ((object package) doc-type) |
| 386 |
(when (member doc-type '(t package)) |
| 387 |
(si::get-documentation object 'package))) |
| 388 |
|
| 389 |
(defmethod (setf documentation) (new-value (object package) doc-type) |
| 390 |
(when (member doc-type '(t package)) |
| 391 |
(si::set-documentation object 'package new-value))) |
| 392 |
|
| 393 |
(defmethod documentation ((object class) doc-type) |
| 394 |
(when (and (member doc-type '(t type)) (slot-boundp object 'docstring)) |
| 395 |
(slot-value object 'docstring))) |
| 396 |
|
| 397 |
(defmethod (setf documentation) (new-value (object class) doc-type) |
| 398 |
(when (member doc-type '(t type)) |
| 399 |
(setf (slot-value object 'docstring) new-value))) |
| 400 |
|
| 401 |
(defmethod documentation ((object structure-class) doc-type) |
| 402 |
(when (member doc-type '(t type)) |
| 403 |
(si::get-documentation (class-name object) 'structure))) |
| 404 |
|
| 405 |
(defmethod (setf documentation) (new-value (object structure-class) doc-type) |
| 406 |
(when (member doc-type '(t type)) |
| 407 |
(setf (documentation (class-name object) 'structure) new-value))) |
| 408 |
|
| 409 |
(defmethod documentation ((object list) doc-type) |
| 410 |
(when (member doc-type '(function compiler-macro)) |
| 411 |
(si::get-documentation object doc-type))) |
| 412 |
|
| 413 |
(defmethod (setf documentation) (new-value (object list) doc-type) |
| 414 |
(when (member doc-type '(function compiler-macro)) |
| 415 |
(si::set-documentation object doc-type new-value))) |
| 416 |
|
| 417 |
(defmethod documentation ((object standard-generic-function) doc-type) |
| 418 |
(when (member doc-type '(t function)) |
| 419 |
(slot-value object 'docstring))) |
| 420 |
|
| 421 |
(defmethod (setf documentation) (new-value (object standard-generic-function) doc-type) |
| 422 |
(when (member doc-type '(t function)) |
| 423 |
(setf (slot-value object 'docstring) new-value))) |
| 424 |
|
| 425 |
(defmethod documentation ((object standard-method) doc-type) |
| 426 |
(when (member doc-type '(t function)) |
| 427 |
(slot-value object 'docstring))) |
| 428 |
|
| 429 |
(defmethod (setf documentation) (new-value (object standard-method) doc-type) |
| 430 |
(when (member doc-type '(t function)) |
| 431 |
(setf (slot-value object 'docstring) new-value))) |
| 432 |
|
| 433 |
(defmethod documentation ((object function) doc-type) |
| 434 |
(when (member doc-type '(t function)) |
| 435 |
(si::get-documentation object doc-type))) |
| 436 |
|
| 437 |
(defmethod (setf documentation) (new-value (object function) doc-type) |
| 438 |
(when (member doc-type '(t function)) |
| 439 |
(si::set-documentation object doc-type new-value))) |
| 440 |
|
| 441 |
(defmethod documentation ((object slot-definition) doc-type) |
| 442 |
(when (member doc-type '(t function)) |
| 443 |
(slot-value object 'docstring))) |
| 444 |
|
| 445 |
(defmethod (setf documentation) (new-value (object slot-definition) doc-type) |
| 446 |
(when (member doc-type '(t function)) |
| 447 |
(setf (slot-value object 'docstring) new-value))) |
| 448 |
|