chiark / gitweb /
src/{builtin,c-types-{impl,parse}}.lisp: Add some more builtin types.
authorMark Wooding <mdw@distorted.org.uk>
Tue, 17 Nov 2015 17:14:26 +0000 (17:14 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Tue, 17 Nov 2015 20:33:51 +0000 (20:33 +0000)
Add `wchar_t', `_Bool' and `bool', and the C99 complex and imaginary
types.

src/builtin.lisp
src/c-types-impl.lisp
src/c-types-parse.lisp

index 2d59158d644f02063f1557d463587fa465553c11..1dde0d59b224c0a6e4de4603847505d585b1755b 100644 (file)
@@ -316,7 +316,7 @@ (defun make-builtin-module ()
                                                    :case :common)
                               :state nil)))
     (with-module-environment (module)
-      (dolist (name '("va_list" "size_t" "ptrdiff_t"))
+      (dolist (name '("va_list" "size_t" "ptrdiff_t" "wchar_t"))
        (add-to-module module (make-instance 'type-item :name name)))
       (flet ((header-name (name)
               (concatenate 'string "\"" (string-downcase name) ".h\""))
index 7d5b1fc5400126064c0d7b4680679ec9706fd400..56eee890a0b64262957906a792690a0b8a3ee7ad 100644 (file)
@@ -141,7 +141,11 @@        (define-c-type-syntax ,(car names) (&rest quals)
 
 ;; 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 void "void")
 (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 float "float")
 (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")
index 42a23d3d27b19771db92ac7e3547da51148fabf5..018c108445bc87c2a12e91b795df38204b079be7 100644 (file)
@@ -89,7 +89,10 @@   (default-slot (ds 'name slot-names)
 
 (defparameter *declspec-map*
   (let ((map (make-hash-table :test #'equal)))
-    (dolist (item '((type :void :char :int :float :double)
+    (dolist (item '((type :void :char :int :float :double
+                         (:bool :name "_Bool"))
+                   (complexity (:complex :name "_Complex")
+                               (:imaginary :name "_Imaginary"))
                    ((type :taggedp t) :enum :struct :union)
                    (size :short :long (:long-long :name "long long"))
                    (sign :signed :unsigned)
@@ -110,6 +113,8 @@ (defparameter *declspec-map*
                                     :taggedp taggedp)))
              (setf (gethash name map) ds
                    (gethash label map) ds))))))
+    (dolist (label '(:complex :imaginary :bool))
+      (setf (gethash (string-downcase label) map) (gethash label map)))
     map)
   "Maps symbolic labels and textual names to `declspec' instances.")
 
@@ -119,6 +124,7 @@ (defclass declspecs ()
   ;; This could have been done with `defstruct' just as well, but a
   ;; `defclass' can be tweaked interactively, which is a win at the moment.
   ((type :initform nil :initarg :type :reader ds-type)
+   (complexity :initform nil :initarg :complexity :reader ds-complexity)
    (sign :initform nil :initarg :sign :reader ds-sign)
    (size :initform nil :initarg :size :reader ds-size)
    (qualifier :initform nil :initarg :qualifiers :reader ds-qualifiers))
@@ -142,19 +148,22 @@ (defmethod ds-name ((ty c-type)) (princ-to-string ty))
 (defmethod ds-kind ((ty c-type)) 'type)
 
 (defparameter *good-declspecs*
-  '(((:int) (:signed :unsigned) (:short :long :long-long))
-    ((:char) (:signed :unsigned) ())
-    ((:double) () (:long))
-    (t () ()))
+  '(((:int) (:signed :unsigned) (:short :long :long-long) ())
+    ((:char) (:signed :unsigned) () ())
+    ((:double) () (:long) (:complex :imaginary))
+    (t () () ()))
   "List of good collections of declaration specifiers.
 
-   Each item is a list of the form (TYPES SIGNS SIZES).  Each of TYPES, SIGNS
-   and SIZES is either a list of acceptable specifiers of the appropriate
-   kind, or T, which matches any specifier.")
+   Each item is a list of the form (TYPES SIGNS SIZES COMPLEXITIES).  Each of
+   TYPES, SIGNS, SIZES, and COMPLEXITIES, is either a list of acceptable
+   specifiers of the appropriate kind, or T, which matches any specifier.")
 
 (defun good-declspecs-p (specs)
   "Are SPECS a good collection of declaration specifiers?"
-  (let ((speclist (list (ds-type specs) (ds-sign specs) (ds-size specs))))
+  (let ((speclist (list (ds-type specs)
+                       (ds-sign specs)
+                       (ds-size specs)
+                       (ds-complexity specs))))
     (some (lambda (it)
            (every (lambda (spec pat)
                     (or (eq pat t) (null spec)