Fix test failure as a result of #+immobile-code.
[sbcl.git] / src / pcl / generic-functions.lisp
blob8912db8854d400578fb2aaeaae40bf9c9dc910a1
1 ;;;; Mostly this file contains generic functions. The exceptions are hacks.
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
6 ;;;; This software is in the public domain and is provided with absolutely no
7 ;;;; warranty. See the COPYING and CREDITS files for more information.
9 (in-package "SB-PCL")
11 ;;;; readers
13 (defgeneric accessor-method-slot-definition (standard-accessor-method))
15 (defgeneric class-can-precede-list (pcl-class))
17 (defgeneric class-defstruct-constructor (structure-class))
19 (defgeneric class-defstruct-form (structure-class))
21 (defgeneric class-direct-subclasses (class))
23 (defgeneric class-direct-superclasses (class))
25 (defgeneric class-eq-specializer (class))
27 (defgeneric class-incompatible-superclass-list (pcl-class))
29 (defgeneric class-name (class))
31 (defgeneric class-precedence-list (pcl-class))
33 (defgeneric class-wrapper (pcl-class))
35 (defgeneric definition-source (definition-source-mixin))
37 (defgeneric eql-specializer-object (eql-specializer))
39 (defgeneric generic-function-declarations (standard-generic-function))
41 (defgeneric generic-function-method-class (standard-generic-function))
43 (defgeneric generic-function-method-combination (standard-generic-function))
45 (defgeneric generic-function-methods (standard-generic-function))
47 (defgeneric generic-function-name (standard-generic-function))
49 (defgeneric gf-arg-info (standard-generic-function))
51 (defgeneric gf-dfun-state (standard-generic-function))
53 (defgeneric generic-function-initial-methods (standard-generic-function))
55 (defgeneric long-method-combination-function (long-method-combination))
57 (defgeneric method-combination-documentation (standard-method-combination))
59 (defgeneric method-combination-options (standard-method-combination))
61 (defgeneric method-combination-type-name (standard-method-combination))
63 (defgeneric method-generic-function (standard-method))
65 (defgeneric object-plist (plist-mixin))
67 (defgeneric short-combination-identity-with-one-argument
68 (short-method-combination))
70 (defgeneric short-combination-operator (short-method-combination))
72 (defgeneric slot-definition-class (slot-definition))
74 (defgeneric slot-definition-defstruct-accessor-symbol
75 (structure-slot-definition))
77 (defgeneric slot-definition-initargs (slot-definition))
79 (defgeneric slot-definition-initform (slot-definition))
81 (defgeneric slot-definition-initfunction (slot-definition))
83 (defgeneric slot-definition-internal-reader-function
84 (structure-slot-definition))
86 (defgeneric slot-definition-internal-writer-function
87 (structure-slot-definition))
89 (defgeneric slot-definition-location (standard-effective-slot-definition))
91 (defgeneric slot-definition-name (slot-definition))
93 (defgeneric slot-definition-info (effective-slot-definition))
95 (defgeneric slot-definition-readers (slot-definition))
97 (defgeneric slot-definition-type (slot-definition))
99 (defgeneric slot-definition-writers (slot-definition))
101 (defgeneric specializer-object (class-eq-specializer))
103 (defgeneric specializer-type (specializer))
105 ;;;; writers
107 (defgeneric (setf class-defstruct-constructor) (new-value structure-class))
109 (defgeneric (setf class-defstruct-form) (new-value structure-class))
111 (defgeneric (setf class-direct-slots) (new-value slot-class))
113 (defgeneric (setf class-incompatible-superclass-list) (new-value pcl-class))
115 (defgeneric (setf class-name) (new-value class))
117 (defgeneric (setf class-slots) (new-value slot-class))
119 (defgeneric (setf generic-function-method-class) (new-value
120 standard-generic-function))
122 (defgeneric (setf generic-function-method-combination)
123 (new-value standard-generic-function))
125 (defgeneric (setf generic-function-declarations) (new-value
126 standard-generic-function))
128 (defgeneric (setf generic-function-methods) (new-value
129 standard-generic-function))
131 (defgeneric (setf generic-function-name) (new-value standard-generic-function))
133 (defgeneric (setf gf-dfun-state) (new-value standard-generic-function))
135 (defgeneric (setf generic-function-initial-methods)
136 (new-value standard-generic-function))
138 (defgeneric (setf method-generic-function) (new-value standard-method))
140 (defgeneric (setf object-plist) (new-value plist-mixin))
142 (defgeneric (setf slot-definition-allocation) (new-value
143 standard-slot-definition))
145 (defgeneric (setf slot-definition-class) (new-value slot-definition))
147 (defgeneric (setf slot-definition-defstruct-accessor-symbol)
148 (new-value structure-slot-definition))
150 (defgeneric (setf slot-definition-initargs) (new-value slot-definition))
152 (defgeneric (setf slot-definition-initform) (new-value slot-definition))
154 (defgeneric (setf slot-definition-initfunction) (new-value slot-definition))
156 (defgeneric (setf slot-definition-internal-reader-function)
157 (new-value structure-slot-definition))
159 (defgeneric (setf slot-definition-internal-writer-function)
160 (new-value structure-slot-definition))
162 (defgeneric (setf slot-definition-location)
163 (new-value standard-effective-slot-definition))
165 (defgeneric (setf slot-definition-name) (new-value slot-definition))
167 (defgeneric (setf slot-definition-info) (new-value effective-slot-definition))
169 (defgeneric (setf slot-definition-readers) (new-value slot-definition))
171 (defgeneric (setf slot-definition-type) (new-value slot-definition))
173 (defgeneric (setf slot-definition-writer-function)
174 (new-value effective-slot-definition))
176 (defgeneric (setf slot-definition-writers) (new-value slot-definition))
178 ;;;; 1 argument
180 (defgeneric accessor-method-slot-name (m))
182 (defgeneric class-default-initargs (class))
184 (defgeneric class-direct-default-initargs (class))
186 (defgeneric class-direct-slots (class))
188 (defgeneric class-finalized-p (class))
190 (defgeneric class-prototype (class))
192 (defgeneric class-slot-cells (class))
194 (defgeneric class-slots (class))
196 (defgeneric compute-class-precedence-list (root))
198 (defgeneric compute-default-initargs (class))
200 (defgeneric compute-discriminating-function (gf))
202 (defgeneric compute-discriminating-function-arglist-info (generic-function))
204 (defgeneric compute-slots (class))
206 (defgeneric finalize-inheritance (class))
208 (defgeneric function-keywords (method))
210 (defgeneric generic-function-argument-precedence-order (gf))
212 (defgeneric generic-function-lambda-list (gf))
214 (defgeneric generic-function-pretty-arglist (generic-function))
216 (defgeneric gf-fast-method-function-p (gf))
218 (defgeneric initialize-internal-slot-functions (slotd))
220 (defgeneric make-instances-obsolete (class))
222 (defgeneric method-function (method))
224 (defgeneric method-lambda-list (m))
226 (defgeneric method-qualifiers (m))
228 (defgeneric method-specializers (m))
230 (defgeneric raw-instance-allocator (class))
232 (defgeneric slot-definition-allocation (slotd))
234 (defgeneric slots-fetcher (class))
236 (defgeneric specializer-class (specializer))
238 (defgeneric specializer-direct-generic-functions (specializer))
240 (defgeneric specializer-direct-methods (specializer))
242 (defgeneric specializer-method-table (specializer))
244 (defgeneric specializer-method-holder (specializer &optional create))
246 (defgeneric update-constructors (class))
248 (defgeneric wrapper-fetcher (class))
250 ;;;; 2 arguments
252 (defgeneric add-dependent (metaobject dependent))
254 (defgeneric add-direct-method (specializer method))
256 (defgeneric add-direct-subclass (class subclass))
258 (defgeneric add-method (generic-function method))
260 (defgeneric (setf class-slot-cells) (new-value class))
262 (defgeneric class-slot-value (class slot-name))
264 (defgeneric compatible-meta-class-change-p (class proto-new-class))
266 (defgeneric compute-applicable-methods (generic-function arguments))
268 (defgeneric compute-applicable-methods-using-classes
269 (generic-function classes))
271 (defgeneric compute-effective-slot-definition-initargs (class direct-slotds))
273 (defgeneric describe-object (object stream))
275 (defgeneric direct-slot-definition-class (class &rest initargs))
277 (defgeneric effective-slot-definition-class (class &rest initargs))
279 (defgeneric make-boundp-method-function (class slot-name))
281 (defgeneric make-reader-method-function (class slot-name))
283 (defgeneric make-writer-method-function (class slot-name))
285 (defgeneric map-dependents (metaobject function))
287 (defgeneric parse-specializer-using-class (generic-function specializer-name))
289 (defgeneric remove-boundp-method (class generic-function))
291 (defgeneric remove-dependent (metaobject dependent))
293 (defgeneric remove-direct-method (specializer method))
295 (defgeneric remove-direct-subclass (class subclass))
297 (defgeneric remove-method (generic-function method))
299 (defgeneric remove-reader-method (class generic-function))
301 (defgeneric remove-writer-method (class generic-function))
303 (defgeneric same-specializer-p (specl1 specl2))
305 (defgeneric slot-accessor-function (slotd type))
307 (defgeneric slot-accessor-std-p (slotd type))
309 ;;; This controls DESCRIBE-OBJECT (SLOT-OBJECT STREAM) behavior.
310 (defgeneric slots-to-inspect (class object))
312 (defgeneric unparse-specializer-using-class (generic-function specializer))
314 (defgeneric validate-superclass (class superclass))
316 (defgeneric invalid-superclass (class superclass))
318 (defgeneric (setf documentation) (new-value slotd doc-type)
319 (:argument-precedence-order doc-type slotd new-value))
321 (defgeneric documentation (slotd doc-type)
322 (:argument-precedence-order doc-type slotd))
324 ;;;; 3 arguments
326 (defgeneric (setf class-slot-value) (nv class slot-name))
328 ;;; CMUCL comment (from Gerd Moellmann/Pierre Mai, 2002-10-19):
330 ;;; According to AMOP, COMPUTE-EFFECTIVE-METHOD should return two
331 ;;; values. Alas, the second value is only vaguely described in AMOP,
332 ;;; and, when asked on 2002-10-18, Gregor Kiczales said he couldn't
333 ;;; remember what the second value was supposed to be. So, PCL's
334 ;;; COMPUTE-EFFECTIVE-METHOD returns one value as do Allegro and
335 ;;; Lispworks.
336 (defgeneric compute-effective-method (generic-function
337 combin
338 applicable-methods))
340 (defgeneric compute-effective-slot-definition (class name dslotds))
342 (defgeneric compute-slot-accessor-info (slotd type gf))
344 (defgeneric find-method-combination (generic-function type options))
346 (defgeneric invalid-qualifiers (generic-function combin method))
348 (defgeneric (setf slot-accessor-function) (function slotd type))
350 (defgeneric (setf slot-accessor-std-p) (value slotd type))
352 (defgeneric slot-boundp-using-class (class object slotd))
354 (defgeneric slot-makunbound-using-class (class object slotd))
356 (defgeneric slot-unbound (class instance slot-name))
358 (defgeneric slot-value-using-class (class object slotd))
360 (defgeneric specializer-type-specifier
361 (proto-generic-function proto-method specializer)
362 #+sb-doc
363 (:documentation
364 "Return a type specifier for SPECIALIZER, a non-parsed specializer
365 form or a SPECIALIZER instance.
367 More specifically, SPECIALIZER can be
368 * a non-parsed specializer form such as
369 * a symbol naming a class
370 * a list of the form (eql OBJECT)
371 * a list of the form (SPECIALIZER-KIND &rest SPECIFIC-SYNTAX)
372 * an instance of a subclass of SPECIALIZER
374 When SPECIALIZER cannot be parsed/used as a specializer for
375 PROTO-GENERIC-FUNCTION and PROTO-METHOD, a STYLE-WARNING is signaled
376 and NIL is returned. No type declaration will be generated in this
377 case.
379 NIL can also be returned if SPECIALIZER is valid but its type should
380 not be declared, for example for efficiency reasons.
382 NOTE: This generic function is part of an SBCL-specific experimental
383 protocol. Interface subject to change."))
385 ;;;; 4 arguments
387 (defgeneric make-method-lambda
388 (proto-generic-function proto-method lambda-expression environment))
390 (defgeneric make-method-specializers-form
391 (proto-generic-function proto-method specializer-names environment))
393 ;;; MAKE-SPECIALIZER-FORM-USING-CLASS
395 ;;; To free every new custom generic function class from having to
396 ;;; implement iteration over specializers in
397 ;;; MAKE-METHOD-SPECIALIZERS-FORM, we provide a default method
399 ;;; make-method-specializers-form standard-g-f standard-method
401 ;;; which performs this iteration and calls the generic function
403 ;;; make-specializer-form-using-class proto-g-f proto-m specializer-name env
405 ;;; on which custom generic function classes can install methods to
406 ;;; handle their custom specializers. The generic function uses OR
407 ;;; method combination to allow the following idiom:
409 ;;; (defmethod make-specializer-form-using-class or
410 ;;; (proto-generic-function MY-GENERIC-FUNCTION)
411 ;;; (proto-method standard-method)
412 ;;; (specializer-name cons)
413 ;;; (environment t))
414 ;;; (when (typep specializer-name '(cons (eql MY-SPECIALIZER)))
415 ;;; MY-SPECIALIZER-FORM))
417 ;;; The OR method combination lets everything but (my-specializer ...)
418 ;;; fall through to the next methods which will, at some point, handle
419 ;;; class and eql specializers and eventually reach an error signaling
420 ;;; method for invalid specializers.
422 (defgeneric make-specializer-form-using-class
423 (proto-generic-function proto-method specializer-name environment)
424 (:method-combination or)
425 (:documentation
426 "Return a form which, when evaluated in the lexical environment
427 described by ENVIRONMENT, parses the specializer SPECIALIZER-NAME and
428 yields the appropriate specializer object.
430 Both PROTO-GENERIC-FUNCTION and PROTO-METHOD may be
431 uninitialized. However their classes and prototypes can be
432 inspected.
434 NOTE: This generic function is part of an SBCL-specific experimental
435 protocol. Interface subject to change."))
437 (defgeneric (setf slot-value-using-class) (new-value class object slotd))
439 ;;;; 5 arguments
441 ;;; FIXME: This is currently unused -- where should we call it? Or should we just
442 ;;; delete it.
443 (defgeneric add-boundp-method (class generic-function slot-name slot-documentation source-location))
445 (defgeneric add-reader-method (class generic-function slot-name slot-documentation source-location))
447 (defgeneric add-writer-method (class generic-function slot-name slot-documentation source-location))
449 (defgeneric make-method-initargs-form
450 (proto-generic-function proto-method lambda-expression lambda-list
451 environment))
453 ;;;; 6 arguments
455 (defgeneric make-method-lambda-using-specializers
456 (proto-generic-function proto-method qualifiers specializers
457 method-lambda environment)
458 (:documentation
459 "Compute a method lambda form based on METHOD-LAMBDA, possibly
460 taking into account PROTO-GENERIC-FUNCTION, PROTO-METHOD, QUALIFIERS,
461 SPECIALIZERS and ENVIRONMENT.
463 Both PROTO-GENERIC-FUNCTION and PROTO-METHOD may be
464 uninitialized. However, their classes and prototypes can be inspected.
466 SPECIALIZERS is a list of specializer objects (i.e. parsed).
468 Return three values:
469 1. the created method lambda form
470 2. initargs for the method instance
471 3. a (possibly modified) unspecialized method lambda list or nil if
472 the unspecialized lambda list contained in METHOD-LAMBDA should be
473 used
475 NOTE: This generic function is part of an SBCL-specific experimental
476 protocol. Interface subject to change."))
478 ;;;; optional arguments
480 (defgeneric get-method (generic-function
481 qualifiers
482 specializers
483 &optional errorp))
485 (defgeneric find-method (generic-function
486 qualifiers
487 specializers
488 &optional errorp))
490 (defgeneric slot-missing (class
491 instance
492 slot-name
493 operation
494 &optional new-value))
496 ;;;; &KEY arguments
498 ;;; FIXME: make the declared &KEY arguments here agree with those that
499 ;;; AMOP specifies.
500 (defgeneric allocate-instance (class &rest initargs))
502 (defgeneric ensure-class-using-class (class
503 name
504 &rest args
505 &key &allow-other-keys))
507 (defgeneric ensure-generic-function-using-class (generic-function
508 fun-name
509 &key &allow-other-keys))
511 (defgeneric initialize-instance (instance &rest initargs &key &allow-other-keys))
513 (defgeneric make-instance (class &rest initargs &key &allow-other-keys))
515 (defgeneric change-class (instance new-class-name &rest initargs &key &allow-other-keys))
517 (defgeneric no-applicable-method (generic-function &rest args))
519 (defgeneric no-next-method (generic-function method &rest args))
521 (defgeneric no-primary-method (generic-function &rest args))
523 (defgeneric reader-method-class (class direct-slot &rest initargs))
525 (defgeneric reinitialize-instance (instance &rest initargs &key &allow-other-keys))
527 (defgeneric shared-initialize (instance slot-names &rest initargs
528 &key &allow-other-keys))
530 (defgeneric update-dependent (metaobject dependent &rest initargs))
532 (defgeneric update-instance-for-different-class (previous
533 current
534 &rest initargs))
536 (defgeneric update-instance-for-redefined-class (instance
537 added-slots
538 discarded-slots
539 property-list
540 &rest initargs))
542 (defgeneric writer-method-class (class direct-slot &rest initargs))