;;;----- Licensing notice ---------------------------------------------------
;;;
-;;; This file is part of the Sensble Object Design, an object system for C.
+;;; This file is part of the Sensible Object Design, an object system for C.
;;;
;;; SOD is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License as published by
;; Built-in C types.
-(export '(void float double long-double va-list size-t ptrdiff-t
+(export '(void
+ float double long-double
+ float-complex double-complex long-double-complex
+ float-imaginary double-imaginary long-double-imaginary
+ va-list size-t ptrdiff-t wchar-t
char unsigned-char uchar signed-char schar
int signed signed-int sint unsigned unsigned-int uint
short signed-short short-int signed-short-int sshort
(define-simple-c-type char "char")
(define-simple-c-type (unsigned-char uchar) "unsigned char")
(define-simple-c-type (signed-char schar) "signed char")
+(define-simple-c-type wchar-t "wchar-t")
(define-simple-c-type (int signed signed-int sint) "int")
(define-simple-c-type (unsigned unsigned-int uint) "unsigned")
(define-simple-c-type double "double")
(define-simple-c-type long-double "long double")
+(define-simple-c-type bool "_Bool")
+
+(define-simple-c-type float-complex "float _Complex")
+(define-simple-c-type double-complex "double _Complex")
+(define-simple-c-type long-double-complex "long double _Complex")
+
+(define-simple-c-type float-imaginary "float _Imaginary")
+(define-simple-c-type double-imaginary "double _Imaginary")
+(define-simple-c-type long-double-imaginary "long double _Imaginary")
+
(define-simple-c-type va-list "va_list")
(define-simple-c-type size-t "size_t")
(define-simple-c-type ptrdiff-t "ptrdiff_t")
(export '(c-function-type c-function-arguments))
(defclass c-function-type (c-type)
((subtype :initarg :subtype :type c-type :reader c-type-subtype)
- (arguments :initarg :arguments :type list :reader c-function-arguments))
+ (arguments :type list :reader c-function-arguments))
(:documentation
"C function types. The subtype is the return type, as implied by the C
syntax for function declarations."))
+(defmethod shared-initialize :after
+ ((type c-function-type) slot-names &key (arguments nil argsp))
+ (declare (ignore slot-names))
+ (when argsp
+ (setf (slot-value type 'arguments)
+ (if (and arguments
+ (null (cdr arguments))
+ (not (eq (car arguments) :ellipsis))
+ (eq (argument-type (car arguments)) c-type-void))
+ nil
+ arguments))))
+
;; Constructor function.
(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 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.
~:>"
(c-type-subtype type)
(mapcar (lambda (arg)
- (if (eq arg :ellipsis)
- arg
+ (if (eq arg :ellipsis) arg
(list (argument-name arg) (argument-type arg))))
(c-function-arguments type))))
-(export '(fun function func fn))
+(export '(fun function () func fn))
(define-c-type-syntax fun (ret &rest args)
"Return the type of functions which returns RET and has arguments ARGS.
That is, with each argument name passed through
`commentify-argument-name'."
(mapcar (lambda (arg)
- (if (eq arg :ellipsis)
- arg
+ (if (eq arg :ellipsis) arg
(make-argument (commentify-argument-name (argument-name arg))
(argument-type arg))))
arguments))