X-Git-Url: http://git.kpe.io/?p=clsql.git;a=blobdiff_plain;f=sql%2Fkmr-mop.lisp;h=017aa0b2222cdc157cfd1ba391a51567211ee4e6;hp=e82ac66ddb50d0804969804aaf30bcef73a9d172;hb=39e2802cd264ddacb3ca59b3b2c5c38f202149de;hpb=61fd5f068d2a5dc42c88731d672730ba6aa9a9ea diff --git a/sql/kmr-mop.lisp b/sql/kmr-mop.lisp index e82ac66..017aa0b 100644 --- a/sql/kmr-mop.lisp +++ b/sql/kmr-mop.lisp @@ -7,8 +7,6 @@ ;;;; Programmer: Kevin M. Rosenberg ;;;; Date Started: Apr 2003 ;;;; -;;;; $Id$ -;;;; ;;;; This file imports MOP symbols into the CLSQL-MOP package and then ;;;; re-exports into CLSQL-SYS them to hide differences in ;;;; MOP implementations. @@ -16,7 +14,7 @@ ;;;; This file was extracted from the KMRCL utilities ;;;; ************************************************************************* -(in-package #:clsql) +(in-package #:clsql-sys) #+lispworks (defun intern-eql-specializer (slot) @@ -25,8 +23,8 @@ (defmacro process-class-option (metaclass slot-name &optional required) #+lispworks `(defmethod clos:process-a-class-option ((class ,metaclass) - (name (eql ,slot-name)) - value) + (name (eql ,slot-name)) + value) (when (and ,required (null value)) (error "metaclass ~A class slot ~A must have a value" (quote ,metaclass) name)) (list name `',value)) @@ -37,10 +35,10 @@ (defmacro process-slot-option (metaclass slot-name) #+lispworks `(defmethod clos:process-a-slot-option ((class ,metaclass) - (option (eql ,slot-name)) - value - already-processed-options - slot) + (option (eql ,slot-name)) + value + already-processed-options + slot) (list* option `',value already-processed-options)) #-lispworks (declare (ignore metaclass slot-name)) @@ -55,10 +53,38 @@ (ecase (slot-definition-name (first slots)) (a) (b (pushnew :mop-slot-order-reversed cl:*features*))))) - + (defun ordered-class-slots (class) - #+mop-slot-order-reversed (class-slots class) - #-mop-slot-order-reversed (reverse (class-slots class))) + #+mop-slot-order-reversed (reverse (class-slots class)) + #-mop-slot-order-reversed (class-slots class)) + +(defun ordered-class-direct-slots (class) + "Gets an ordered list of direct class slots" + ;; NB: this used to return effective-slot-definitions in direct + ;; opposition to the function name. Not sure why + (setf class (to-class class)) + #+mop-slot-order-reversed (reverse (class-direct-slots class)) + #-mop-slot-order-reversed (class-direct-slots class)) + +(defun find-slot-by-name (class slot-name &optional direct? recurse?) + "Looks up a direct-slot-definition by name" + (setf class (to-class class) + slot-name (to-slot-name slot-name)) + (labels ((find-it (class) + (let* ((slots (if direct? + (ordered-class-direct-slots class) + (ordered-class-slots class))) + (it (find slot-name + slots + :key #'slot-definition-name))) + (if it + it + (when recurse? + (loop for sup in (class-direct-superclasses class) + for rtn = (find-it sup) + until rtn + finally (return rtn))))))) + (find-it class))) ;; Lispworks has symbol for slot rather than the slot instance (defun %svuc-slot-name (slot)