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

Last change on this file since 14196 was 14112, checked in by ehuelsmann, 8 years ago

Use PROVIDE/REQUIRE to prevent multiple loading.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.9 KB
Line 
1;;; print-object.lisp
2;;;
3;;; Copyright (C) 2003-2006 Peter Graves
4;;; $Id: print-object.lisp 14112 2012-08-18 08:17:42Z ehuelsmann $
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
36(when (autoloadp 'print-object)
37  (fmakunbound 'print-object))
38
39(defgeneric print-object (object stream))
40
41(defmethod print-object ((object t) stream)
42  (print-unreadable-object (object stream :type t :identity t)
43     (write-string (%write-to-string object) stream)))
44
45(defmethod print-object ((object standard-object) stream)
46  (write-string (%write-to-string object) stream))
47
48(defmethod print-object ((object structure-object) stream)
49  (write-string (%write-to-string object) stream))
50
51(defmethod print-object ((class class) stream)
52  (print-unreadable-object (class stream :identity t)
53    ;; Avoid recursive errors for uninitialized class objects, e.g. when
54    ;; validate-superclass fails
55    (format stream "~S ~S" (class-name (class-of class)) (ignore-errors (class-name class))))
56  class)
57
58(defmethod print-object ((gf generic-function) stream)
59  (print-unreadable-object (gf stream :identity t)
60    (format stream "~S ~S"
61            (class-name (class-of gf))
62            (ignore-errors (mop:generic-function-name gf))))
63  gf)
64
65(defmethod print-object ((method method) stream)
66  (print-unreadable-object (method stream :identity t)
67    (format stream "~S ~S~{ ~S~} ~S"
68            (class-name (class-of method))
69            (mop:generic-function-name
70             (mop:method-generic-function method))
71            (method-qualifiers method)
72            (mapcar #'(lambda (c)
73                        (if (typep c 'mop:eql-specializer)
74                            `(eql ,(mop:eql-specializer-object c))
75                          (class-name c)))
76                    (mop:method-specializers method))))
77  method)
78
79(defmethod print-object ((method-combination method-combination) stream)
80  (print-unreadable-object (method-combination stream :identity t)
81    (format stream "~A ~S" (class-name (class-of method-combination))
82            (ignore-errors (mop::method-combination-name method-combination))))
83  method-combination)
84
85(defmethod print-object ((restart restart) stream)
86  (if *print-escape*
87      (print-unreadable-object (restart stream :type t :identity t)
88        (prin1 (restart-name restart) stream))
89      (restart-report restart stream)))
90
91(defmethod print-object ((c condition) stream)
92  (if *print-escape*
93      (call-next-method)
94      (if (slot-boundp c 'format-control)
95          (apply #'format stream
96                 (simple-condition-format-control c)
97                 (simple-condition-format-arguments c))
98          (call-next-method))))
99
100(defmethod print-object ((c type-error) stream)
101  (if *print-escape*
102      (call-next-method)
103      (if (slot-boundp c 'format-control)
104          (apply 'format stream
105                 (simple-condition-format-control c)
106                 (simple-condition-format-arguments c))
107          (format stream "The value ~S is not of type ~S."
108                  (type-error-datum c)
109                  (type-error-expected-type c)))))
110
111(defmethod print-object ((x undefined-function) stream)
112  (if *print-escape*
113      (call-next-method)
114      (format stream "The function ~S is undefined." (cell-error-name x))))
115
116(defmethod print-object ((x unbound-variable) stream)
117  (if *print-escape*
118      (print-unreadable-object (x stream :identity t)
119        (format stream "~S ~S"
120                (type-of x)
121                (cell-error-name x)))
122      (format stream "The variable ~S is unbound." (cell-error-name x))))
123
124(provide "PRINT-OBJECT")
Note: See TracBrowser for help on using the repository browser.