]> asedeno.scripts.mit.edu Git - cl-protobufs.git/commitdiff
expand types in clos transformation when necessary
authorAlejandro R Sedeño <asedeno@google.com>
Mon, 10 Dec 2012 22:23:48 +0000 (17:23 -0500)
committerAlejandro R Sedeño <asedeno@google.com>
Mon, 10 Dec 2012 22:33:14 +0000 (17:33 -0500)
clos-transform.lisp
utilities.lisp

index 18a80d6a3683bf142d297f5205eeab640d6ca076..ab504d8300333638985216bffd74eca54cc8c564 100644 (file)
 (defun clos-type-to-protobuf-type (type &optional type-filter enum-filter)
   "Given a Lisp type, returns a Protobuf type, a class or primitive type,
    whether or not to pack the field, and (optionally) a set of enum values."
-  (let ((type (if type-filter (funcall type-filter type) type))
-        (list-of-list-of (list-of-list-of)))
-    (flet ()
-      (if (listp type)
+  (let* ((type (if type-filter (funcall type-filter type) type))
+         (list-of-list-of (list-of-list-of))
+         (expanded-type (type-expand type)))
+    (cond
+      ((listp type)
         (destructuring-bind (head &rest tail) type
           (case head
             ((or)
                (multiple-value-bind (type class)
                    (lisp-type-to-protobuf-type (first tail))
                  (values type class (packed-type-p class)))
-               (lisp-type-to-protobuf-type type)))))
-        (lisp-type-to-protobuf-type type)))))
+               (lisp-type-to-protobuf-type type))))))
+      ((not (equal type expanded-type))
+       (clos-type-to-protobuf-type expanded-type))
+      (t
+       (lisp-type-to-protobuf-type type)))))
 
 (defun lisp-type-to-protobuf-type (type)
   (case type
index d8fedc6a393308afd5265e5ba32d4d86c3b40ecc..7195f3ab33973913ed259a47f5c58a4f01f6807a 100644 (file)
 (deftype sfixed32 () '(signed-byte 32))
 (deftype sfixed64 () '(signed-byte 64))
 
+;; Type expansion
+(defun type-expand (type)
+  #+allegro (excl:normalize-type type :default type)
+  #+ccl (ccl::type-expand type)
+  #+clisp (ext:type-expand type)
+  #+cmu (kernel:type-expand type)
+  #+lispworks (type:expand-user-type type)
+  #+sbcl (sb-ext:typexpand type)
+  #-(or allegro ccl clisp cmu lispworks sbcl) type)
 
 ;;; Code generation utilities