diff options
Diffstat (limited to 'cmamut.lisp')
-rw-r--r-- | cmamut.lisp | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/cmamut.lisp b/cmamut.lisp index bacca56..6f20d3e 100644 --- a/cmamut.lisp +++ b/cmamut.lisp @@ -14,7 +14,6 @@ ; TODO: Use c2ffi to extract the spec.json using the header file as parameter (defvar enum-references (make-hash-table :test #'equal :size 256)) -(defvar type-associations (make-hash-table :test #'equal :size 256)) (defun get-spec () (json:from-file "~/common-lisp/cmamut/spec.json")) @@ -64,13 +63,7 @@ (cook-struct raw-type)) ((string= tag "union") (cook-union raw-type)) - (t - (let ((new-tag (gethash tag type-associations))) - (if new-tag - (progn - (setf (gethash "tag" raw-type) new-tag) - (cook-type raw-type)) - (error (format nil "Unknown type tag ~a" tag)))))))) + (t tag)))) (defun cook-function (raw-function &optional name-transformer) (let ((raw-params (gethash "parameters" raw-function)) @@ -185,18 +178,29 @@ (defun classify-definitions (spec) (let ((s (make-spec))) (dotimes (i (length spec)) - (cond ((string= (gethash "tag" (aref spec i)) "function") - (push (aref spec i) (spec-functions s))) - ((string= (gethash "tag" (aref spec i)) "typedef") - (push (aref spec i) (spec-typedefs s))) - ((string= (gethash "tag" (aref spec i)) "struct") - (push (aref spec i) (spec-structs s))) - ((string= (gethash "tag" (aref spec i)) "enum") - (push (aref spec i) (spec-enums s))) - ((string= (gethash "tag" (aref spec i)) "union") - (push (aref spec i) (spec-unions s))) - (t))) - s)) + (let ((tag (gethash "tag" (aref spec i)))) + (cond ((string= tag "function") + (push (aref spec i) (spec-functions s))) + ((string= tag "typedef") + (let ((internal-type (gethash "type" (aref spec i)))) + (cond ((string= (gethash "tag" internal-type) "struct") + (when (string= (gethash "name" internal-type) "") + (setf (gethash "name" internal-type) (gethash "name" (aref spec i)))) + (push (gethash "type" (aref spec i)) (spec-structs s)) + (setf (gethash "type" (aref spec i)) + (json:from-string + (format nil + "{ \"tag\": \":struct\", \"name\": ~s }" + (gethash "name" (aref spec i)))))) + (t (push (aref spec i) (spec-typedefs s)))))) + ((string= tag "struct") + (push (aref spec i) (spec-structs s))) + ((string= tag "enum") + (push (aref spec i) (spec-enums s))) + ((string= tag "union") + (push (aref spec i) (spec-unions s))) + (t)))) + s)) (defun codegen (spec) (clrhash enum-references) |