X-Git-Url: https://git.distorted.org.uk/~mdw/sod/blobdiff_plain/c28f6ae9d1bb9027ce143714b66673a5208cf5fe..1645e4335e58ef3a8f1cafb1834e93760d80d9ae:/src/c-types-parse.lisp diff --git a/src/c-types-parse.lisp b/src/c-types-parse.lisp index 45336a1..0a6b5ab 100644 --- a/src/c-types-parse.lisp +++ b/src/c-types-parse.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 @@ -70,7 +70,7 @@ ;; accessor functions later. ((label :type keyword :initarg :label :reader ds-label) (name :type string :initarg :name :reader ds-name) - (kind :type (member type sign size qualifier) + (kind :type (member type complexity sign size qualifier) :initarg :kind :reader ds-kind) (taggedp :type boolean :initarg :taggedp :initform nil :reader ds-taggedp)) @@ -89,7 +89,10 @@ (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 @@ :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 @@ ;; 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-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) @@ -189,10 +198,11 @@ (let ((type (ds-type specs)) (size (ds-size specs)) (sign (ds-sign specs)) + (cplx (ds-complexity specs)) (quals (mapcar #'ds-label (ds-qualifiers specs)))) (cond ((typep type 'c-type) (qualify-c-type type quals)) - ((or type size sign) + ((or type size sign cplx) (when (and sign (eq (ds-label sign) :signed) (eq (ds-label type) :int)) (setf sign nil)) @@ -204,7 +214,8 @@ (make-simple-type (format nil "~{~@[~A~^ ~]~}" (mapcar #'ds-name (remove nil - (list sign size type)))) + (list sign cplx + size type)))) quals)) (t nil)))) @@ -372,7 +383,7 @@ (cons #'identity name)))) (argument-list () - ;; [ argument [ `,' argument ]* [ `,' `...' ] ] | `...' + ;; [argument [`,' argument]* [`,' `...']] | `...' ;; ;; The possibility of a trailing `,' `...' means that we ;; can't use the standard `list' parser. Note that, unlike