diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2023-02-01 23:41:15 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2023-02-01 23:41:15 -0300 |
commit | 17586f249799df3f3b707e4711b6d6f82844dcea (patch) | |
tree | 57016e06dd2f198d836898360153ecff2236966c | |
parent | b3e058b72a7434cfda5c74f6ae64dcbc81ac1b38 (diff) | |
download | cmamut-17586f249799df3f3b707e4711b6d6f82844dcea.tar.gz cmamut-17586f249799df3f3b707e4711b6d6f82844dcea.zip |
WIP: Put structs internal to typedefs into the struct list
-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) |