(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
(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