fix nested structures in fmt-c

This commit is contained in:
2025-08-06 15:33:18 +03:00
committed by Pavel Kulyov
parent 6c6e00e6dc
commit a6800aaeb6

View File

@@ -562,7 +562,7 @@
(cat (cat
(c-in-stmt (c-in-stmt
(if (list? body) (if (list? body)
(apply c-begin (map c-wrap-stmt (map c-param body))) (apply c-begin (map c-wrap-stmt (map c-field body)))
(c-wrap-stmt (c-expr body)))))) (c-wrap-stmt (c-expr body))))))
(if (pair? o) (cat " " (apply c-begin o)) (dsp "")))) (if (pair? o) (cat " " (apply c-begin o)) (dsp ""))))
(c-wrap-stmt (c-wrap-stmt
@@ -609,6 +609,22 @@
((pair? x) (c-type (car x) (cadr x))) ((pair? x) (c-type (car x) (cadr x)))
(else (cat (lambda (st) ((c-type (fmt-default-type st)) st)) " " x)))) (else (cat (lambda (st) ((c-type (fmt-default-type st)) st)) " " x))))
(define (c-field x)
(cond
((procedure? x) x)
((pair? x)
(if (list? (car x))
(case (caar x)
((union struct class)
(if (> (length x) 1)
(c-type (car x)
(cadr x))
(c-type (car x))))
(else (c-type (car x) (cadr x))))
(c-type (car x)
(fmt-join c-expr (cdr x) ", "))))
(else (cat (lambda (st) ((c-type (fmt-default-type st)) st)) " " x))))
(define (c-param-list ls) (define (c-param-list ls)
(c-in-expr (fmt-join/dot c-param (lambda (dot) (dsp "...")) ls ", "))) (c-in-expr (fmt-join/dot c-param (lambda (dot) (dsp "...")) ls ", ")))
@@ -655,7 +671,7 @@
name)))) name))))
((enum) (apply c-enum name (cdr type))) ((enum) (apply c-enum name (cdr type)))
((struct union class) ((struct union class)
(cat (apply c-struct/aux (car type) (cdr type)) " " name)) (cat (apply c-struct/aux (car type) (cdr type)) (if name (cat " " name) "")))
(else (fmt-join/last c-expr (lambda (x) (c-type x name)) type " ")))) (else (fmt-join/last c-expr (lambda (x) (c-type x name)) type " "))))
((not type) ((not type)
(lambda (st) ((c-type (or (fmt-default-type st) 'int) name) st))) (lambda (st) ((c-type (or (fmt-default-type st) 'int) name) st)))