Merge branches 'mdw/kwargs-fixes' and 'mdw/c11-fixes'
[sod] / doc / list-exports.lisp
old mode 100644 (file)
new mode 100755 (executable)
index 5eab34e..00bb7af
@@ -1,3 +1,7 @@
+#! /bin/sh
+":"; CL_SOURCE_REGISTRY=$(pwd)/build/src/:; export CL_SOURCE_REGISTRY
+":"; exec cl-launch -X -l "sbcl cmucl" -s asdf -i "(sod-exports::main)" -- "$0" "$@" || exit 1
+
 (cl:defpackage #:sod-exports
   (:use #:common-lisp
        #+cmu #:mop
     (and export
         (list* (symbolicate code '-inst)
                (symbolicate 'make- code '-inst)
-               (mapcar (lambda (arg)
-                         (symbolicate 'inst- arg))
+               (mapcan (lambda (arg)
+                         (let ((sym (if (listp arg) (car arg) arg)))
+                           (cond ((char= (char (symbol-name sym) 0) #\&)
+                                  nil)
+                                 (t
+                                  (list (symbolicate 'inst- sym))))))
                        args)))))
 
 (defmethod form-list-exports ((head (eql 'sod::define-tagged-type)) tail)
          (symbolicate 'c- kind '-type)
          (symbolicate 'make- kind '-type))))
 
+(defmethod form-list-exports ((head (eql 'sod:defctype)) tail)
+  (destructuring-bind (names value &key export) tail
+    (declare (ignore value))
+    (let ((names (if (listp names) names (list names))))
+      (and export
+          (list* (symbolicate 'c-type- (car names)) names)))))
+
+(defmethod form-list-exports ((head (eql 'sod:define-simple-c-type)) tail)
+  (destructuring-bind (names type &key export) tail
+    (declare (ignore type))
+    (let ((names (if (listp names) names (list names))))
+      (and export
+          (list* (symbolicate 'c-type- (car names)) names)))))
+
 (defmethod form-list-exports ((head (eql 'cl:macrolet)) tail)
   (mapcan #'form-exports (cdr tail)))
 
 (defun analyse-generic-functions (package)
   (setf package (find-package package))
   (flet ((function-name-core (name)
-          (etypecase name
-            (symbol name)
-            ((cons (eql setf) t) (cadr name)))))
+          (typecase name
+            (symbol (values name t))
+            ((cons (eql setf) t) (values (cadr name) t))
+            (t (values nil nil)))))
     (let ((methods (make-hash-table))
          (functions (make-hash-table))
          (externs (make-hash-table)))
            (when class
              (dolist
                  (func (specializer-direct-generic-functions class))
-               (let ((name (function-name-core
-                            (generic-function-name func))))
-                 (when (or (not (eq (symbol-package name) package))
-                           (gethash name externs))
+               (multiple-value-bind (name knownp)
+                   (function-name-core (generic-function-name func))
+                 (when (and knownp
+                            (or (not (eq (symbol-package name) package))
+                                (gethash name externs)))
                    (setf (gethash func functions) t)
                    (dolist (method (specializer-direct-methods class))
                      (setf (gethash method methods) t)))))))))
                                       (class-direct-slots class)))
                              (exported (remove-if
                                         (lambda (sym)
-                                          (and (not (exported-symbol-p sym))
-                                               (eq (symbol-package sym)
-                                                   package)))
+                                          (or (not (symbol-package sym))
+                                              (and (not (exported-symbol-p
+                                                         sym))
+                                                   (eq (symbol-package sym)
+                                                       package))))
                                         slot-names)))
                         (and exported
                              (list (cons (class-name class)
     (report-symbols (mapcar #'file-name (list optparse)) "OPTPARSE")
     (report-symbols (mapcar #'file-name (list utilities)) "SOD-UTILITIES"))))
 
-#+interactive
-(with-open-file (*standard-output* #p"doc/SYMBOLS" :direction :output
-                :if-exists :supersede :if-does-not-exist :create)
-  (report-project-symbols))
+(defun main ()
+  (with-open-file (*standard-output* #p"doc/SYMBOLS"
+                  :direction :output
+                  :if-exists :supersede
+                  :if-does-not-exist :create)
+    (report-project-symbols)))
+
+#+interactive (main)