forked from alex-eg/sex
keep what follows the star of a pointer to a tagged type
fmt-c wrote (const * struct what) as struct what*, and (* * struct what) as struct what*, a pointer short; a pointer to an enum crashed it, the star taken for the enum's values.
This commit is contained in:
@@ -664,7 +664,13 @@
|
||||
"")
|
||||
(if (not (null? body))
|
||||
(cat body)
|
||||
""))))))
|
||||
"")
|
||||
(c-type-words o))))))
|
||||
|
||||
;; MODIFIED FROM UPSTREAM fmt-c: what follows the first star of a
|
||||
;; tagged type, `* const' in (struct what * const), was dropped
|
||||
(define (c-type-words words)
|
||||
(fmt-join (lambda (word) (cat " " word)) words ""))
|
||||
|
||||
(define (c-struct . args) (apply c-struct/aux "struct" args))
|
||||
(define (c-union . args) (apply c-struct/aux "union" args))
|
||||
@@ -679,13 +685,15 @@
|
||||
(if (pair? x) (cat (car x) " = " (c-expr (cadr x))) (dsp x)))
|
||||
(let* ((name (if (null? o) (if (or (symbol? x) (string? x)) x #f) x))
|
||||
(vals (if name (if (null? o) #f (car o)) x)))
|
||||
(if vals
|
||||
;; MODIFIED FROM UPSTREAM fmt-c: (enum mood * const) is a
|
||||
;; pointer, and its star was taken for the list of values
|
||||
(if (pair? vals)
|
||||
(c-wrap-stmt
|
||||
(cat
|
||||
(c-braced-block
|
||||
(if name (cat "enum " name) (dsp "enum"))
|
||||
(c-in-expr (apply c-begin (map c-enum-one vals))))))
|
||||
(c-wrap-stmt (cat "enum " name)))))
|
||||
(c-wrap-stmt (cat "enum " name (or vals "") (c-type-words (if vals (cdr o) '())))))))
|
||||
|
||||
(define (c-attribute . args)
|
||||
(cat "__attribute__ ((" (fmt-join c-expr args ", ") "))"))
|
||||
|
||||
@@ -855,6 +855,22 @@
|
||||
(< (string-contains c "static int λ0_f (int x)")
|
||||
(string-contains c "(*f)(int) = λ0_f")))))
|
||||
|
||||
;; fmt-c kept the first star after a tag and dropped what followed it,
|
||||
;; and took an enum's star for its list of values
|
||||
(test-group "pointers to tagged types"
|
||||
(test-assert "a const pointer to a struct stays const"
|
||||
(emits? "(var q (const * struct what))" "struct what* const q;"))
|
||||
(test-assert "and one in an array"
|
||||
(emits? "(var a [const * struct what 4])" "struct what* const a[4];"))
|
||||
(test-assert "a pointer to a pointer keeps both stars"
|
||||
(emits? "(var pp (* * struct what))" "struct what* * pp;"))
|
||||
(test-assert "so does a union's"
|
||||
(emits? "(var u (const * union val))" "union val* const u;"))
|
||||
(test-assert "a pointer to an enum is a pointer"
|
||||
(emits? "(enum mood (glad sad)) (var e (* enum mood))" "enum mood* e;"))
|
||||
(test-assert "and a const one"
|
||||
(emits? "(enum mood (glad sad)) (var f (const * enum mood))" "enum mood* const f;")))
|
||||
|
||||
;; Toplevel forms used to be separated by a blank line unconditionally,
|
||||
;; which spread a block of adjacent typedefs over twice the lines its
|
||||
;; author wrote
|
||||
|
||||
Reference in New Issue
Block a user