From 17586f249799df3f3b707e4711b6d6f82844dcea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Wed, 1 Feb 2023 23:41:15 -0300 Subject: WIP: Put structs internal to typedefs into the struct list --- cmamut.lisp | 44 ++++++++++++++++++++++++-------------------- 1 file 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) -- cgit v1.2.3