]> asedeno.scripts.mit.edu Git - cl-protobufs.git/blobdiff - printer.lisp
asdf-support: simplify do-process-import calling
[cl-protobufs.git] / printer.lisp
index c083f576fabcddc16a7d8ef4800cbd2346db294a..99354131fed0c07b3675d7ba2ab8fac58d18593f 100644 (file)
@@ -2,7 +2,7 @@
 ;;;                                                                  ;;;
 ;;; Free Software published under an MIT-like license. See LICENSE   ;;;
 ;;;                                                                  ;;;
-;;; Copyright (c) 2012 Google, Inc.  All rights reserved.            ;;;
+;;; Copyright (c) 2012-2013 Google, Inc.  All rights reserved.       ;;;
 ;;;                                                                  ;;;
 ;;; Original author: Scott McKay                                     ;;;
 ;;;                                                                  ;;;
               (and (not (zerop indentation)) indentation) line))))
 
 ;; Lisp was born in 1958 :-)
-(defvar *lisp-options* '(("lisp_package" string 195801)
-                         ("lisp_name"    string 195802)
-                         ("lisp_alias"   string 195803)
-                         ("lisp_type"    string 195804)
-                         ("lisp_class"   string 195805)
-                         ("lisp_slot"    string 195806)))
-
-(defvar *option-types* '(("ctype"                 symbol)
-                         ("deadline"               float)
-                         ("deprecated"            symbol)
-                         ("optimize_for"          symbol)
-                         ("packed"               boolean)
-                         ("protocol"              symbol)
-                         ("stream_type"           string)
-                         ;; Keep the rest of these in alphabetical order
-                         ("cc_api_version"       integer)
-                         ("cc_generic_services"   symbol)
-                         ("go_api_version"       integer)
-                         ("go_generic_services"   symbol)
-                         ("go_package"            string)
-                         ("java_api_version"     integer)
-                         ("java_generic_services" symbol)
-                         ("java_java5_enums"     boolean)
-                         ("java_multiple_files"  boolean)
-                         ("java_outer_classname"  string)
-                         ("java_package"          string)
-                         ("java_use_javaproto2"  boolean)
-                         ("py_api_version"       integer)
-                         ("py_generic_services"   symbol)))
+(defparameter *lisp-options* '(("lisp_package" string 195801)
+                               ("lisp_name"    string 195802)
+                               ("lisp_alias"   string 195803)
+                               ("lisp_type"    string 195804)
+                               ("lisp_class"   string 195805)
+                               ("lisp_slot"    string 195806)))
+
+(defparameter *option-types* '(("ctype"                 symbol)
+                               ("deadline"               float)
+                               ("deprecated"            symbol)
+                               ("optimize_for"          symbol)
+                               ("packed"               boolean)
+                               ("protocol"              symbol)
+                               ("stream_type"           string)
+                               ;; Keep the rest of these in alphabetical order
+                               ("cc_api_version"       integer)
+                               ("cc_generic_services"   symbol)
+                               ("go_api_version"       integer)
+                               ("go_generic_services"   symbol)
+                               ("go_package"            string)
+                               ("java_api_version"     integer)
+                               ("java_generic_services" symbol)
+                               ("java_java5_enums"     boolean)
+                               ("java_multiple_files"  boolean)
+                               ("java_outer_classname"  string)
+                               ("java_package"          string)
+                               ("java_use_javaproto2"  boolean)
+                               ("py_api_version"       integer)
+                               ("py_generic_services"   symbol)))
 
 (defmethod write-schema-header ((type (eql :proto)) (schema protobuf-schema) stream)
   (when (any-lisp-option schema)
                                 (proto-options schema)))
            (pkg      (and package (if (stringp package) package (string package))))
            (lisp-pkg (and lisp-package (if (stringp lisp-package) lisp-package (string lisp-package))))
+           (rpc-pkg  (and (or lisp-pkg pkg)
+                          (format nil "~A-~A" (or lisp-pkg pkg) 'rpc)))
            (*show-lisp-enum-indexes*  show-enum-indexes)
            (*show-lisp-field-indexes* show-field-indexes)
            (*use-common-lisp-package* use-common-lisp)
            (*protobuf-package* (find-proto-package lisp-pkg))
+           (*protobuf-rpc-package* (find-proto-package rpc-pkg))
            ;; If *protobuf-package* has not been defined, print symbols
            ;; from :common-lisp if *use-common-lisp-package* is true; or
            ;; :keyword otherwise.  This ensures that all symbols will be
            ;; Keywords are always printed as :keyword.)
            (*package* (or *protobuf-package*
                           (when *use-common-lisp-package* (find-package :common-lisp))
-                          (find-package :keyword))))
+                          (find-package :keyword)))
+           (exports (collect-exports schema)))
+      (when rpc-pkg
+        (let* ((pkg (string-upcase rpc-pkg))
+               (rpc-exports (remove-if-not
+                             #'(lambda (sym)
+                                 (string=
+                                  (package-name (symbol-package sym))
+                                  pkg))
+                             exports))
+               (*package* (or *protobuf-rpc-package*
+                              (when *use-common-lisp-package* (find-package :common-lisp))
+                              (find-package :keyword))))
+          (when rpc-exports
+            (format stream "~&(cl:eval-when (:execute :compile-toplevel :load-toplevel)~
+                            ~%  (cl:unless (cl:find-package \"~A\")~
+                            ~%    (cl:defpackage ~A (:use~@[ ~(~S~)~]))))~
+                            ~%(cl:in-package \"~A\")~
+                            ~%(cl:export '(~{~A~^~%             ~}))~%~%"
+                    pkg pkg (and *use-common-lisp-package* :common-lisp) pkg
+                    rpc-exports))))
       (when (or lisp-pkg pkg)
         (let ((pkg (string-upcase (or lisp-pkg pkg))))
           (format stream "~&(cl:eval-when (:execute :compile-toplevel :load-toplevel)~
                        (string=
                         (package-name (symbol-package sym))
                         pkg))
-                   (collect-exports schema)))))
+                   exports))))
       (when documentation
         (write-schema-documentation type documentation stream :indentation indentation))
       (format stream "~&(proto:define-schema ~(~A~)" (or class name))