source: trunk/abcl/src/org/armedbear/lisp/print-object.lisp @ 11529

Last change on this file since 11529 was 11529, checked in by Mark Evenson, 12 years ago

Revert inadvertent r11528.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.0 KB
Line 
1;;; print-object.lisp
2;;;
3;;; Copyright (C) 2003-2006 Peter Graves
4;;; $Id: print-object.lisp 11529 2009-01-03 13:17:22Z mevenson $
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;;; As a special exception, the copyright holders of this library give you
21;;; permission to link this library with independent modules to produce an
22;;; executable, regardless of the license terms of these independent
23;;; modules, and to copy and distribute the resulting executable under
24;;; terms of your choice, provided that you also meet, for each linked
25;;; independent module, the terms and conditions of the license of that
26;;; module.  An independent module is a module which is not derived from
27;;; or based on this library.  If you modify this library, you may extend
28;;; this exception to your version of the library, but you are not
29;;; obligated to do so.  If you do not wish to do so, delete this
30;;; exception statement from your version.
31
32(in-package #:system)
33
34(require 'clos)
35(require 'java)
36
37(when (autoloadp 'print-object)
38  (fmakunbound 'print-object))
39
40(defgeneric print-object (object stream))
41
42(defmethod print-object ((object t) stream)
43  (print-unreadable-object (object stream :type t :identity t)))
44
45(defmethod print-object ((object structure-object) stream)
46  (write-string (%write-to-string object) stream))
47
48(defmethod print-object ((object standard-object) stream)
49  (print-unreadable-object (object stream :identity t)
50    (format stream "~S" (class-name (class-of object))))
51  object)
52
53(defmethod print-object ((class class) stream)
54  (print-unreadable-object (class stream :identity t)
55    (format stream "~S ~S"
56            (class-name (class-of class))
57            (class-name class)))
58  class)
59
60(defmethod print-object ((gf standard-generic-function) stream)
61  (print-unreadable-object (gf stream :identity t)
62    (format stream "~S ~S"
63            (class-name (class-of gf))
64            (%generic-function-name gf)))
65  gf)
66
67(defmethod print-object ((method standard-method) stream)
68  (print-unreadable-object (method stream :identity t)
69    (format stream "~S ~S~{ ~S~} ~S"
70            (class-name (class-of method))
71            (%generic-function-name
72             (%method-generic-function method))
73            (method-qualifiers method)
74            (mapcar #'(lambda (c)
75                        (if (typep c 'mop::eql-specializer)
76                            `(eql ,(mop::eql-specializer-object c))
77                          (class-name c)))
78                    (%method-specializers method))))
79  method)
80
81(defmethod print-object ((restart restart) stream)
82  (if *print-escape*
83      (print-unreadable-object (restart stream :type t :identity t)
84        (prin1 (restart-name restart) stream))
85      (restart-report restart stream)))
86
87(defmethod print-object ((c condition) stream)
88  (if *print-escape*
89      (call-next-method)
90      (if (slot-boundp c 'format-control)
91          (apply #'format stream
92                 (simple-condition-format-control c)
93                 (simple-condition-format-arguments c))
94          (call-next-method))))
95
96(defmethod print-object ((c type-error) stream)
97  (if *print-escape*
98      (call-next-method)
99      (if (slot-boundp c 'format-control)
100          (apply 'format stream
101                 (simple-condition-format-control c)
102                 (simple-condition-format-arguments c))
103          (format stream "The value ~S is not of type ~S."
104                  (type-error-datum c)
105                  (type-error-expected-type c)))))
106
107(defmethod print-object ((x undefined-function) stream)
108  (if *print-escape*
109      (call-next-method)
110      (format stream "The function ~S is undefined." (cell-error-name x))))
111
112(defmethod print-object ((x unbound-variable) stream)
113  (if *print-escape*
114      (print-unreadable-object (x stream :identity t)
115        (format stream "~S ~S"
116                (type-of x)
117                (cell-error-name x)))
118      (format stream "The variable ~S is unbound." (cell-error-name x))))
119
120(defmethod print-object ((e java:java-exception) stream)
121  (if *print-escape*
122      (print-unreadable-object (e stream :type t :identity t)
123        (format stream "~A"
124                (java:jcall (java:jmethod "java.lang.Object" "toString")
125                            (java:java-exception-cause e))))
126      (format stream "Java exception '~A'."
127              (java:jcall (java:jmethod "java.lang.Object" "toString")
128                          (java:java-exception-cause e)))))
129
130(provide 'print-object)
Note: See TracBrowser for help on using the repository browser.