introduced slot-def kind predicates (eg: join-slot-p key-slot-p)
[clsql.git] / sql / kmr-mop.lisp
index 172394017be36062da20cee7c6000cf2b2d43d23..017aa0b2222cdc157cfd1ba391a51567211ee4e6 100644 (file)
   #+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)
   #+lispworks slot