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 (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
)
74 :layered-accessor attribute-keyword
79 :layered-accessor attribute-object
80 :accessor described-object
84 (define-layered-class standard-attribute
(attribute)
86 :layered-accessor attribute-label
92 :layered-accessor attribute-label-formatter
93 :initarg
:label-formatter
99 :layered-accessor attribute-function
103 :layered-accessor attribute-value
108 :layered-accessor attribute-value-formatter
109 :initarg
:value-formatter
114 :layered-accessor attribute-active-p
115 :initarg
:activep
;depreciated
121 "Can be T, NIL or :WHEN. In the latter case, attribute is only active if the attribute value is non-null.")
122 (active-attributes :layered-accessor attribute-active-attributes
126 (active-descriptions :layered-accessor attribute-active-descriptions
131 (inactive-descriptions :layered-accessor attribute-inactive-descriptions
137 (define-layered-method attribute-label-formatter
:around
(attribute)
138 (or (slot-value attribute
'label-formatter
)
139 (attribute-value (find-attribute (attribute-description attribute
) 'label-formatter
))
140 (error "No Formatter .. fool!")))
142 (define-layered-method attribute-value-formatter
:around
(attribute)
144 (or (slot-value attribute
'value-formatter
)
145 (attribute-value (find-attribute (attribute-description attribute
) 'value-formatter
))
146 (error "No Formatter .. fool!")))
150 (define-layered-method attribute-object
((attribute standard-attribute
))
151 (if (slot-boundp attribute
'object
)
153 (described-object (attribute-description attribute
))))
156 (define-layered-function attribute-value-using-object
(object attribute
))
157 (define-layered-function (setf attribute-value-using-object
) (value object attribute
))
159 (define-layered-method attribute-value
((attribute standard-attribute
))
160 (attribute-value-using-object (attribute-object attribute
) attribute
))
162 (define-layered-method attribute-value-using-object
(object attribute
)
163 (let ((fn (handler-case (attribute-function attribute
)
164 (unbound-slot () nil
))))
167 (slot-value attribute
'value
))))
169 (define-layered-method (setf attribute-value
) (value (attribute standard-attribute
))
170 (setf (attribute-value-using-object (attribute-object attribute
) attribute
) value
))
172 (define-layered-method (setf attribute-value-using-object
) (value object attribute
)
173 (error "No (SETF ATTRIBUTE-VALUE-USING-OBJECT) for ~A ~A and we are not editable"
177 (defun ensure-access-function (class attribute property
)
178 (with-function-access
179 (if (slot-definition-specialp property
)
182 (slot-value-using-class
183 class attribute property
))))
184 (if (fboundp slot-symbol
)
185 (symbol-function slot-symbol
)
186 (setf (symbol-function slot-symbol
)
187 (property-access-function
188 (attribute-description attribute
)
189 (attribute-name attribute
)
190 (slot-definition-name property
)))))
191 (if (slot-boundp-using-class class attribute property
)
192 (slot-value-using-class class attribute property
)
193 (setf (slot-value-using-class class attribute property
)
194 (property-access-function
195 (attribute-description attribute
)
196 (attribute-name attribute
)
197 (slot-definition-name property
)))))))
199 (define-layered-method slot-boundp-using-layer
201 :around
(class (attribute standard-attribute
) property reader
)
203 ; (dprint "Checking boundp ~A ~A" (attribute-name attribute)
204 ; (slot-definition-name property))
206 (if (or *symbol-access
* *function-access
*)
208 (or (when (slot-definition-specialp property
)
209 (with-function-access
210 (slot-boundp-using-class class attribute property
)))
211 (if (generic-function-methods
212 (ensure-access-function class attribute property
))
216 (define-layered-method (setf slot-value-using-layer
)
217 :in-layer
(context t
)
219 (new-value class
(attribute standard-attribute
) property writer
)
221 ;; (dprint "Setting ~A ~A to : ~A" attribute property new-value)
223 (if (or *symbol-access
* *function-access
*)
226 (if (and (slot-definition-specialp property
)
227 (with-function-access
228 (without-symbol-access (slot-boundp-using-class class attribute property
))))
229 (with-function-access
232 ;;FIXME: this is wrong for so many reasons
233 (find-layer (first (remove nil
(closer-mop::class-precedence-list
(class-of context
))
234 :key
#'class-name
))))
235 (boundp (slot-boundp-using-class class attribute property
))
236 (fn (ensure-access-function class attribute property
)))
239 ;; * This slot has never been set before.
240 ;; create a method on property-accessor-function
241 ;; so subclasses can see this new property.
242 (ensure-layered-method
243 (layered-function-definer 'property-access-function
)
244 `(lambda (description attribute property
)
245 (declare (ignore description attribute property
))
250 (attribute-description attribute
))
251 (closer-mop:intern-eql-specializer
252 (attribute-name attribute
))
253 (closer-mop:intern-eql-specializer
254 (closer-mop:slot-definition-name property
)))))
256 ;; specialize this property to this description.
257 ;;(dprint "actrually specializering")
258 (ensure-layered-method
260 `(lambda (description)
264 :specializers
(list (class-of (attribute-description attribute
))))
266 ;; and return the set value as is custom
269 (define-layered-method slot-value-using-layer
271 :around
(class (attribute standard-attribute
) property reader
)
273 ; ;(dprint "Getting the slot value of ~A" property)
274 (if (or *symbol-access
* *function-access
*)
276 (let ((fn (ensure-access-function class attribute property
)))
278 (unless (slot-boundp-using-class class attribute property
)
279 (slot-unbound class attribute
(slot-definition-name property
)))
281 (if (slot-definition-specialp property
)
282 (if (with-function-access
283 (slot-boundp-using-class class attribute property
))
284 (with-function-access
285 (slot-value-using-class class attribute property
))
286 (funcall fn layer
(attribute-description attribute
)))
287 (funcall fn layer
(attribute-description attribute
))))))
294 (defmethod print-object ((object standard-attribute
) stream
)
295 (print-unreadable-object (object stream
:type nil
:identity t
)
296 (format stream
"ATTRIBUTE ~A" (or (ignore-errors (attribute-name object
)) "+unnamed-attribute+"))))
298 (defgeneric eval-property-initarg
(att initarg
)
299 (:method
((attribute standard-attribute
) initarg
)
301 (:method
((attribute standard-attribute
) (initarg (eql :function
)))
303 (:method
((attribute standard-attribute
) (initarg (eql :value
)))
306 (defun prepare-initargs (att args
)
311 (if (eval-property-initarg att key
)
316 (defun attribute-value* (attribute)
317 (attribute-value *object
* attribute
))
319 (defmacro with-attributes
(names description
&body body
)
320 `(let ,(loop for name in names collect
321 (list name
`(find-attribute ,description
',name
)))