| 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.o |
| 6 |
;;;; Copyright (c) 2001, Juan Jose Garcia Ripoll. |
| 7 |
;;;; |
| 8 |
;;;; See file 'LICENSE' for the copyright details. |
| 9 |
|
| 10 |
(in-package "CLOS") |
| 11 |
|
| 12 |
(defmethod class-prototype ((class class)) |
| 13 |
(unless (slot-boundp class 'prototype) |
| 14 |
(setf (slot-value class 'prototype) (allocate-instance class))) |
| 15 |
(slot-value class 'prototype)) |
| 16 |
|
| 17 |
(defun slot-makunbound (self slot-name) |
| 18 |
(let* ((class (class-of self)) |
| 19 |
(slotd (find-slot-definition class slot-name))) |
| 20 |
(if slotd |
| 21 |
(slot-makunbound-using-class class self slotd) |
| 22 |
(slot-missing class self slot-name 'SLOT-MAKUNBOUND)) |
| 23 |
self)) |
| 24 |
|
| 25 |
(defmethod slot-value-using-class ((class std-class) self slotd) |
| 26 |
(declare (ignore class)) |
| 27 |
(let* ((location (slot-definition-location slotd)) |
| 28 |
(value (standard-instance-access self location))) |
| 29 |
(if (si:sl-boundp value) |
| 30 |
value |
| 31 |
(values (slot-unbound class self (slot-definition-name slotd)))))) |
| 32 |
|
| 33 |
(defmethod slot-boundp-using-class ((class std-class) self slotd) |
| 34 |
(declare (ignore class)) |
| 35 |
(si:sl-boundp (standard-instance-access self (slot-definition-location slotd)))) |
| 36 |
|
| 37 |
(defmethod (setf slot-value-using-class) (val (class std-class) self slotd) |
| 38 |
(declare (ignore class)) |
| 39 |
(setf (standard-instance-access self (slot-definition-location slotd)) val)) |
| 40 |
|
| 41 |
(defmethod slot-makunbound-using-class ((class std-class) instance slotd) |
| 42 |
(declare (ignore class)) |
| 43 |
(setf (standard-instance-access instance (slot-definition-location slotd)) (si:unbound)) |
| 44 |
instance) |
| 45 |
|
| 46 |
;;; |
| 47 |
;;; 3) Error messages related to slot access |
| 48 |
;;; |
| 49 |
|
| 50 |
(defmethod slot-missing ((class t) object slot-name operation |
| 51 |
&optional new-value) |
| 52 |
(declare (ignore operation new-value class)) |
| 53 |
(error "~A is not a slot of ~A" slot-name object)) |
| 54 |
|
| 55 |
(defmethod slot-unbound ((class t) object slot-name) |
| 56 |
(declare (ignore class)) |
| 57 |
(error 'unbound-slot :instance object :name slot-name)) |
| 58 |
|
| 59 |
;;; This method is non-standard. It is used by clos:safe-instance-ref to |
| 60 |
;;; signal an unbound slot error when only the index is known. |
| 61 |
(defmethod slot-unbound ((class null) object slot-index) |
| 62 |
(declare (ignore class)) |
| 63 |
(let* ((class (class-of object)) |
| 64 |
(slotd (find slot-index (slot-value class 'slots) |
| 65 |
:key #'slot-definition-location))) |
| 66 |
(values (slot-unbound class object (slot-definition-name slotd))))) |
| 67 |
|
| 68 |
;;; |
| 69 |
;;; For the next accessor we define a method. |
| 70 |
;;; |
| 71 |
|
| 72 |
(defmethod class-name ((class class)) |
| 73 |
(class-id class)) |
| 74 |
|
| 75 |
(defmethod (setf class-name) (new-value (class class)) |
| 76 |
(reinitialize-instance class :name new-value) |
| 77 |
new-value) |