eieio-core.el: Always put a parent in the parents of a class
* lisp/emacs-lisp/eieio-core.el (eieio-defclass-internal): Always put a parent in the `parents` slot of the class. * lisp/emacs-lisp/eieio.el (eieio-class-parents): Remove the `eieio-default-superclass` if it's the only parent. (child-of-class-p): Handle all classes in the parents. (eieio-default-superclass): Adjust docstring.
This commit is contained in:
parent
7c127fc965
commit
945af4d9d1
2 changed files with 19 additions and 24 deletions
|
@ -293,8 +293,7 @@ See `defclass' for more information."
|
|||
;; reloading the file that does the `defclass', we don't
|
||||
;; want to create a new class object.
|
||||
(eieio--class-make cname)))
|
||||
(groups nil) ;; list of groups id'd from slots
|
||||
(clearparent nil))
|
||||
(groups nil)) ;; list of groups id'd from slots
|
||||
|
||||
;; If this class already existed, and we are updating its structure,
|
||||
;; make sure we keep the old child list. This can cause bugs, but
|
||||
|
@ -317,6 +316,9 @@ See `defclass' for more information."
|
|||
(setf (eieio--class-children newc) children)
|
||||
(remhash cname eieio-defclass-autoload-map))))
|
||||
|
||||
(unless (or superclasses (eq cname 'eieio-default-superclass))
|
||||
(setq superclasses '(eieio-default-superclass)))
|
||||
|
||||
(if superclasses
|
||||
(progn
|
||||
(dolist (p superclasses)
|
||||
|
@ -336,16 +338,13 @@ See `defclass' for more information."
|
|||
(push c (eieio--class-parents newc))))))
|
||||
;; Reverse the list of our parents so that they are prioritized in
|
||||
;; the same order as specified in the code.
|
||||
(cl-callf nreverse (eieio--class-parents newc)))
|
||||
;; If there is nothing to loop over, then inherit from the
|
||||
;; default superclass.
|
||||
(unless (eq cname 'eieio-default-superclass)
|
||||
;; adopt the default parent here, but clear it later...
|
||||
(setq clearparent t)
|
||||
;; save new child in parent
|
||||
(cl-pushnew cname (eieio--class-children eieio-default-superclass))
|
||||
;; save parent in child
|
||||
(setf (eieio--class-parents newc) (list eieio-default-superclass))))
|
||||
(cl-callf nreverse (eieio--class-parents newc))
|
||||
;; Before adding new slots, let's add all the methods and classes
|
||||
;; in from the parent class.
|
||||
(eieio-copy-parents-into-subclass newc))
|
||||
|
||||
(cl-assert (eq cname 'eieio-default-superclass))
|
||||
(setf (eieio--class-parents newc) (list (cl--find-class 'record))))
|
||||
|
||||
;; turn this into a usable self-pointing symbol; FIXME: Why?
|
||||
(when eieio-backward-compatibility
|
||||
|
@ -376,10 +375,6 @@ See `defclass' for more information."
|
|||
cname)
|
||||
"25.1")))
|
||||
|
||||
;; Before adding new slots, let's add all the methods and classes
|
||||
;; in from the parent class.
|
||||
(eieio-copy-parents-into-subclass newc)
|
||||
|
||||
;; Store the new class vector definition into the symbol. We need to
|
||||
;; do this first so that we can call defmethod for the accessor.
|
||||
;; The vector will be updated by the following while loop and will not
|
||||
|
@ -512,10 +507,6 @@ See `defclass' for more information."
|
|||
;; Set up the options we have collected.
|
||||
(setf (eieio--class-options newc) options)
|
||||
|
||||
;; if this is a superclass, clear out parent (which was set to the
|
||||
;; default superclass eieio-default-superclass)
|
||||
(if clearparent (setf (eieio--class-parents newc) nil))
|
||||
|
||||
;; Create the cached default object.
|
||||
(let ((cache (make-record newc
|
||||
(+ (length (eieio--class-slots newc))
|
||||
|
|
|
@ -449,7 +449,12 @@ If EXTRA, include that in the string returned to represent the symbol."
|
|||
(defun eieio-class-parents (class)
|
||||
;; FIXME: What does "(overload of variable)" mean here?
|
||||
"Return parent classes to CLASS. (overload of variable)."
|
||||
(eieio--class-parents (eieio--full-class-object class)))
|
||||
;; (declare (obsolete cl--class-parents "30.1"))
|
||||
(let ((parents (eieio--class-parents (eieio--full-class-object class))))
|
||||
(if (and (null (cdr parents))
|
||||
(eq (car parents) (cl--find-class 'eieio-default-superclass)))
|
||||
nil
|
||||
parents)))
|
||||
|
||||
(define-obsolete-function-alias 'class-parents #'eieio-class-parents "24.4")
|
||||
|
||||
|
@ -497,7 +502,7 @@ If EXTRA, include that in the string returned to represent the symbol."
|
|||
(setq class (eieio--class-object class))
|
||||
(cl-check-type class eieio--class)
|
||||
(while (and child (not (eq child class)))
|
||||
(setq p (append p (eieio--class-parents child))
|
||||
(setq p (append p (cl--class-parents child))
|
||||
child (pop p)))
|
||||
(if child t))))
|
||||
|
||||
|
@ -680,8 +685,7 @@ If SLOT is unbound, do nothing."
|
|||
(defclass eieio-default-superclass nil
|
||||
nil
|
||||
"Default parent class for classes with no specified parent class.
|
||||
Its slots are automatically adopted by classes with no specified parents.
|
||||
This class is not stored in the `parent' slot of a class vector."
|
||||
Its slots are automatically adopted by classes with no specified parents."
|
||||
:abstract t)
|
||||
|
||||
(setq eieio-default-superclass (cl--find-class 'eieio-default-superclass))
|
||||
|
|
Loading…
Add table
Reference in a new issue