1 (in-package :lisp-on-lines
)
3 (define-layered-class direct-attribute-definition-class
4 (special-layered-direct-slot-definition
5 contextl
::singleton-direct-slot-definition
)
7 :accessor direct-attribute-properties
8 :documentation
"This is an plist to hold the values of
9 the attribute's properties as described by this direct
10 attribute definition.")))
12 (defmethod initialize-instance
13 :after
((attribute direct-attribute-definition-class
)
15 (setf (direct-attribute-properties attribute
) initargs
))
17 (define-layered-class effective-attribute-definition-class
18 (special-layered-effective-slot-definition)
20 :accessor attribute-direct-attributes
)
22 :accessor slot-definition-attribute-object
)
23 (attribute-object-initargs
24 :accessor attribute-object-initargs
)))
26 (defvar *function-access
* nil
27 "set/get a place's property function instead of its symbol value
28 when this is set to a non-nil value")
30 (defmacro with-function-access
(&body body
)
31 "executes body in an environment with *function-access* set to t"
32 `(let ((*function-access
* t
))
35 (defmacro without-function-access
(&body body
)
36 "executes body in an environment with *function-access* set to nil"
37 `(let ((*function-access
* nil
))
40 (define-layered-function property-access-function
(description attribute-name property-name
)
41 (:method
(description attribute-name property-name
)
42 (ensure-layered-function
44 (intern (format nil
"=PROPERTY-ACCESS-FUNCTION-FOR-~A->~A.~A="
45 (description-print-name description
)
48 :lambda-list
'(description))))
51 (defvar *init-time-description
* nil
)
53 (defmethod attribute-description :around
(attribute)
54 (handler-case (call-next-method)
57 *init-time-description
*
58 q
(call-next-method)))))
60 (define-layered-class attribute
()
61 ((description :initarg
:description
62 :accessor attribute-description
)
64 :layered-accessor attribute-name
66 (effective-attribute-definition
67 :initarg effective-attribute
68 :accessor attribute-effective-attribute-definition
)
70 :accessor attribute-class
71 :initarg
:attribute-class
72 :initform
'standard-attribute
75 :layered-accessor attribute-keyword
80 :layered-accessor attribute-object
81 :accessor described-object
87 (define-layered-class standard-attribute
(attribute)
89 :layered-accessor attribute-label
96 :layered-accessor attribute-function
100 :layered-accessor attribute-value
105 :layered-accessor attribute-active-p
106 :initarg
:activep
;depreciated
112 "Can be T, NIL or :WHEN. In the latter case, attribute is only active if the attribute value is non-null.")))
115 (define-layered-method attribute-object
((attribute standard-attribute
))
116 (if (slot-boundp attribute
'object
)
118 (described-object (attribute-description attribute
))))
121 (define-layered-method attribute-value
((attribute standard-attribute
))
122 (attribute-value-using-object (attribute-object attribute
) attribute
))
124 (define-layered-function attribute-value-using-object
(object attribute
))
126 (define-layered-method attribute-value-using-object
(object attribute
)
127 (let ((fn (handler-case (attribute-function attribute
)
128 (unbound-slot () nil
))))
131 (slot-value attribute
'value
))))
133 (defun ensure-access-function (class attribute property
)
134 (with-function-access
135 (if (slot-definition-specialp property
)
138 (slot-value-using-class
139 class attribute property
))))
140 (if (fboundp slot-symbol
)
141 (symbol-function slot-symbol
)
142 (setf (symbol-function slot-symbol
)
143 (property-access-function
144 (attribute-description attribute
)
145 (attribute-name attribute
)
146 (slot-definition-name property
)))))
147 (if (slot-boundp-using-class class attribute property
)
148 (slot-value-using-class class attribute property
)
149 (setf (slot-value-using-class class attribute property
)
150 (property-access-function
151 (attribute-description attribute
)
152 (attribute-name attribute
)
153 (slot-definition-name property
)))))))
155 (define-layered-method slot-boundp-using-layer
157 :around
(class (attribute standard-attribute
) property reader
)
159 ; (dprint "Checking boundp ~A ~A" (attribute-name attribute)
160 ; (slot-definition-name property))
162 (if (or *symbol-access
* *function-access
*)
164 (or (when (slot-definition-specialp property
)
165 (with-function-access
166 (slot-boundp-using-class class attribute property
)))
167 (if (generic-function-methods
168 (ensure-access-function class attribute property
))
172 (define-layered-method (setf slot-value-using-layer
)
173 :in-layer
(context t
)
175 (new-value class
(attribute standard-attribute
) property writer
)
177 ;; (dprint "Setting ~A ~A to : ~A" attribute property new-value)
179 (if (or *symbol-access
* *function-access
*)
182 (if (and (slot-definition-specialp property
)
183 (with-function-access
184 (without-symbol-access (slot-boundp-using-class class attribute property
))))
185 (with-function-access
188 ;;FIXME: this is wrong for so many reasons
189 (find-layer (first (remove nil
(closer-mop::class-precedence-list
(class-of context
))
190 :key
#'class-name
))))
191 (boundp (slot-boundp-using-class class attribute property
))
192 (fn (ensure-access-function class attribute property
)))
195 ;; * This slot has never been set before.
196 ;; create a method on property-accessor-function
197 ;; so subclasses can see this new property.
198 (ensure-layered-method
199 (layered-function-definer 'property-access-function
)
200 `(lambda (description attribute property
)
201 (declare (ignore description attribute property
))
206 (attribute-description attribute
))
207 (closer-mop:intern-eql-specializer
208 (attribute-name attribute
))
209 (closer-mop:intern-eql-specializer
210 (closer-mop:slot-definition-name property
)))))
212 ;; specialize this property to this description.
213 ;;(dprint "actrually specializering")
214 (ensure-layered-method
216 `(lambda (description)
220 :specializers
(list (class-of (attribute-description attribute
))))
222 ;; and return the set value as is custom
225 (define-layered-method slot-value-using-layer
227 :around
(class (attribute standard-attribute
) property reader
)
229 ; ;(dprint "Getting the slot value of ~A" property)
230 (if (or *symbol-access
* *function-access
*)
232 (let ((fn (ensure-access-function class attribute property
)))
234 (unless (slot-boundp-using-class class attribute property
)
235 (slot-unbound class attribute
(slot-definition-name property
)))
237 (if (slot-definition-specialp property
)
238 (if (with-function-access
239 (slot-boundp-using-class class attribute property
))
240 (with-function-access
241 (slot-value-using-class class attribute property
))
242 (funcall fn layer
(attribute-description attribute
)))
243 (funcall fn layer
(attribute-description attribute
))))))
250 (defmethod print-object ((object standard-attribute
) stream
)
251 (print-unreadable-object (object stream
:type nil
:identity t
)
252 (format stream
"ATTRIBUTE ~A" (or (ignore-errors (attribute-name object
)) "+unnamed-attribute+"))))
254 (defgeneric eval-property-initarg
(att initarg
)
255 (:method
((attribute standard-attribute
) initarg
)
257 (:method
((attribute standard-attribute
) (initarg (eql :function
)))
260 (defun prepare-initargs (att args
)
265 (if (eval-property-initarg att key
)
270 (defun attribute-value* (attribute)
271 (attribute-value *object
* attribute
))
273 (defmacro with-attributes
(names description
&body body
)
274 `(with-slots ,names
,description
,@body
))