src/c-types-impl.lisp: Handle `void' argument lists specially.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 15 Aug 2015 16:55:29 +0000 (17:55 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 15 Aug 2015 16:55:29 +0000 (17:55 +0100)
We'll treat them as equivalent to empty lists.  Otherwise it's just too
easy to declare a message as

void msg(void)

and end up with a horrible mess when the translator tries to turn that
into a direct method of the form

void msg(Thing *me, void)

which works less then brilliantly.

And, on output, we'll write an empty list as `void'.  This situation
doesn't arise in the current translator (I think), but might well do in
extensions.

src/c-types-impl.lisp

index 7dd7b84..be2c055 100644 (file)
 (export 'make-function-type)
 (defun make-function-type (subtype arguments)
   "Return a new function type, returning SUBTYPE and accepting ARGUMENTS."
-  (make-instance 'c-function-type :subtype subtype :arguments arguments))
+  (make-instance 'c-function-type :subtype subtype
+                :arguments (if (and arguments
+                                    (null (cdr arguments))
+                                    (eq (argument-type (car arguments))
+                                        c-type-void))
+                               nil
+                               arguments)))
 
 ;; Comparison protocol.
 
 
 ;; C syntax output protocol.
 
-(defmethod pprint-c-type ((type c-function-type) stream kernel)
-  (pprint-c-type (c-type-subtype type) stream
-                (lambda (stream prio spacep)
-                  (maybe-in-parens (stream (> prio 2))
-                    (when spacep (c-type-space stream))
-                    (funcall kernel stream 2 nil)
-                    (pprint-indent :block 4 stream)
-                    (pprint-logical-block
-                        (stream nil :prefix "(" :suffix ")")
-                      (let ((firstp t))
-                        (dolist (arg (c-function-arguments type))
-                          (if firstp
-                              (setf firstp nil)
-                              (format stream ", ~_"))
-                          (if (eq arg :ellipsis)
-                              (write-string "..." stream)
-                              (pprint-c-type (argument-type arg)
-                                             stream
-                                             (argument-name arg))))))))))
+(let ((void-arglist (list (make-argument nil c-type-void))))
+  (defmethod pprint-c-type ((type c-function-type) stream kernel)
+    (pprint-c-type (c-type-subtype type) stream
+                  (lambda (stream prio spacep)
+                    (maybe-in-parens (stream (> prio 2))
+                      (when spacep (c-type-space stream))
+                      (funcall kernel stream 2 nil)
+                      (pprint-indent :block 4 stream)
+                      (pprint-logical-block
+                          (stream nil :prefix "(" :suffix ")")
+                        (let ((firstp t))
+                          (dolist (arg (or (c-function-arguments type)
+                                           void-arglist))
+                            (if firstp
+                                (setf firstp nil)
+                                (format stream ", ~_"))
+                            (if (eq arg :ellipsis)
+                                (write-string "..." stream)
+                                (pprint-c-type (argument-type arg)
+                                               stream
+                                               (argument-name arg)))))))))))
 
 ;; S-expression notation protocol.