Hi all, This patch adds bitfield support to the groveller. Here is the usage:
In grovel file, write: (bitfield flags-ctype ((:flag-a "FLAG_A") :documentation "DOCU_A") ((:flag-b "FLAG_B") :documentation "DOCU_B") ((:flag-c "FLAG_C") :documentation "DOCU_C")) And if the C header file has: #define FLAG_A 1 #define FLAG_B 2 #define FLAG_C 4 This will generate: (cffi:defbitfield (flags-ctype) (:flag-a 1) (:flag-b 2) (:flag-c 4)) Documentation is also provided in the patch. Thanks
diff -rN -u old-cffi/grovel/grovel.lisp new-cffi/grovel/grovel.lisp --- old-cffi/grovel/grovel.lisp 2010-04-29 12:32:26.893132980 +0800 +++ new-cffi/grovel/grovel.lisp 2010-04-29 12:32:27.577135220 +0800 @@ -627,6 +627,32 @@ 'constant out `((,(intern (string lisp-name)) ,(car c-names)) ,@options))))) + +(define-grovel-syntax bitfield (name-and-opts &rest masks) + "Defines a bitfield, with elements specified as ((lisp-name c-name) +&key documentation). name-and-opts can be either a symbol as name, or +a list (name &key base-type)." + (destructuring-bind (name &key base-type) + (ensure-list name-and-opts) + (c-section-header out "bitfield" name) + (c-export out name) + (c-format out "(cffi:defbitfield (") + (c-print-symbol out name t) + (when base-type + (c-printf out " ") + (c-print-symbol out base-type t)) + (c-format out ")") + (dolist (mask masks) + (destructuring-bind ((lisp-name c-name) &key documentation) mask + (declare (ignore documentation)) + (check-type lisp-name symbol) + (check-type c-name string) + (c-format out "~% (") + (c-print-symbol out lisp-name) + (c-format out " ") + (c-printf out "%i" c-name) + (c-format out ")"))) + (c-format out ")~%"))) ;;;# Wrapper Generation
_______________________________________________ cffi-devel mailing list cffi-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel