X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/3dca7758421664a838c54b273bd9221f02072045..08b6e064ab3b18bbc5a9af47418c02f0e7ebc52d:/src/c-types-impl.lisp diff --git a/src/c-types-impl.lisp b/src/c-types-impl.lisp index 4a0f6e2..cea3057 100644 --- a/src/c-types-impl.lisp +++ b/src/c-types-impl.lisp @@ -7,7 +7,7 @@ ;;;----- 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 @@ -141,7 +141,11 @@ ;; 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 @@ -156,6 +160,7 @@ (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") @@ -180,6 +185,16 @@ (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") @@ -400,7 +415,7 @@ ;; Function arguments. -(defun arguments-lists-equal-p (list-a list-b) +(defun argument-lists-equal-p (list-a list-b) "Return whether LIST-A and LIST-B match. They must have the same number of arguments, and each argument must have @@ -409,8 +424,9 @@ (every (lambda (arg-a arg-b) (if (eq arg-a :ellipsis) (eq arg-b :ellipsis) - (c-type-equal-p (argument-type arg-a) - (argument-type arg-b)))) + (and (argumentp arg-a) (argumentp arg-b) + (c-type-equal-p (argument-type arg-a) + (argument-type arg-b))))) list-a list-b))) ;; Class definition. @@ -418,32 +434,38 @@ (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 (if (and arguments - (null (cdr arguments)) - (not (eq (car arguments) :ellipsis)) - (eq (argument-type (car arguments)) - c-type-void)) - nil - arguments))) + :arguments arguments)) ;; Comparison protocol. (defmethod c-type-equal-p and ((type-a c-function-type) (type-b c-function-type)) (and (c-type-equal-p (c-type-subtype type-a) (c-type-subtype type-b)) - (arguments-lists-equal-p (c-function-arguments type-a) - (c-function-arguments type-b)))) + (argument-lists-equal-p (c-function-arguments type-a) + (c-function-arguments type-b)))) ;; C syntax output protocol. @@ -480,8 +502,7 @@ ~:>" (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)))) @@ -531,8 +552,7 @@ 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))