1 | ;;; print-object.lisp |
---|
2 | ;;; |
---|
3 | ;;; Copyright (C) 2003-2005 Peter Graves |
---|
4 | ;;; $Id: print-object.lisp,v 1.12 2005-11-04 12:07:02 piso Exp $ |
---|
5 | ;;; |
---|
6 | ;;; This program is free software; you can redistribute it and/or |
---|
7 | ;;; modify it under the terms of the GNU General Public License |
---|
8 | ;;; as published by the Free Software Foundation; either version 2 |
---|
9 | ;;; of the License, or (at your option) any later version. |
---|
10 | ;;; |
---|
11 | ;;; This program is distributed in the hope that it will be useful, |
---|
12 | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | ;;; GNU General Public License for more details. |
---|
15 | ;;; |
---|
16 | ;;; You should have received a copy of the GNU General Public License |
---|
17 | ;;; along with this program; if not, write to the Free Software |
---|
18 | ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
19 | |
---|
20 | (in-package #:system) |
---|
21 | |
---|
22 | (require 'clos) |
---|
23 | |
---|
24 | (when (autoloadp 'print-object) |
---|
25 | (fmakunbound 'print-object)) |
---|
26 | |
---|
27 | (defgeneric print-object (object stream)) |
---|
28 | |
---|
29 | (defmethod print-object ((object t) stream) |
---|
30 | (print-unreadable-object (object stream :type t :identity t))) |
---|
31 | |
---|
32 | (defmethod print-object ((object structure-object) stream) |
---|
33 | (write-string (%write-to-string object) stream)) |
---|
34 | |
---|
35 | (defmethod print-object ((object standard-object) stream) |
---|
36 | (print-unreadable-object (object stream :identity t) |
---|
37 | (format stream "~S" (class-name (class-of object)))) |
---|
38 | object) |
---|
39 | |
---|
40 | (defmethod print-object ((class standard-class) stream) |
---|
41 | (print-unreadable-object (class stream :identity t) |
---|
42 | (format stream "~S ~S" |
---|
43 | (class-name (class-of class)) |
---|
44 | (class-name class))) |
---|
45 | class) |
---|
46 | |
---|
47 | (defmethod print-object ((gf standard-generic-function) stream) |
---|
48 | (print-unreadable-object (gf stream :identity t) |
---|
49 | (format stream "~S ~S" |
---|
50 | (class-name (class-of gf)) |
---|
51 | (%generic-function-name gf))) |
---|
52 | gf) |
---|
53 | |
---|
54 | (defmethod print-object ((method standard-method) stream) |
---|
55 | (print-unreadable-object (method stream :identity t) |
---|
56 | (format stream "~S ~S~{ ~S~} ~S" |
---|
57 | (class-name (class-of method)) |
---|
58 | (%generic-function-name |
---|
59 | (%method-generic-function method)) |
---|
60 | (method-qualifiers method) |
---|
61 | (mapcar #'class-name |
---|
62 | (%method-specializers method)))) |
---|
63 | method) |
---|
64 | |
---|
65 | (defmethod print-object ((restart restart) stream) |
---|
66 | (if *print-escape* |
---|
67 | (print-unreadable-object (restart stream :type t :identity t) |
---|
68 | (prin1 (restart-name restart) stream)) |
---|
69 | (restart-report restart stream))) |
---|
70 | |
---|
71 | (defmethod print-object ((c condition) stream) |
---|
72 | (if *print-escape* |
---|
73 | (call-next-method) |
---|
74 | (if (slot-boundp c 'format-control) |
---|
75 | (apply #'format stream |
---|
76 | (simple-condition-format-control c) |
---|
77 | (simple-condition-format-arguments c)) |
---|
78 | (call-next-method)))) |
---|
79 | |
---|
80 | (defmethod print-object ((c type-error) stream) |
---|
81 | (if *print-escape* |
---|
82 | (call-next-method) |
---|
83 | (if (slot-boundp c 'format-control) |
---|
84 | (apply 'format stream |
---|
85 | (simple-condition-format-control c) |
---|
86 | (simple-condition-format-arguments c)) |
---|
87 | (format stream "The value ~S is not of type ~S." |
---|
88 | (type-error-datum c) |
---|
89 | (type-error-expected-type c))))) |
---|
90 | |
---|
91 | (defmethod print-object ((x undefined-function) stream) |
---|
92 | (if *print-escape* |
---|
93 | (call-next-method) |
---|
94 | (format stream "The function ~S is undefined." (cell-error-name x)))) |
---|
95 | |
---|
96 | (provide 'print-object) |
---|