From 4d89d941ae5c674e85ae5402361cb893c07ce65b Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sat, 15 Aug 2015 17:55:29 +0100 Subject: [PATCH] src/c-types-impl.lisp: Handle `void' argument lists specially. 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 | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/c-types-impl.lisp b/src/c-types-impl.lisp index 7dd7b84..be2c055 100644 --- a/src/c-types-impl.lisp +++ b/src/c-types-impl.lisp @@ -428,7 +428,13 @@ (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. @@ -440,25 +446,27 @@ ;; 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. -- 2.11.0