hold operators to the operands they take
Past them an operator was written as it came: (/ a) as /a, (! a b) as a ! b. (++ a b) steps each in turn, through a comma operator the writer lacked: bare in a for header, and in parens wherever else, since bare it would begin another declarator or argument.
This commit is contained in:
@@ -304,6 +304,7 @@
|
||||
((%prototype) ((apply c-prototype (cdr x)) st))
|
||||
((%var) ((apply c-var (cdr x)) st))
|
||||
((%begin) ((apply c-begin (cdr x)) st))
|
||||
((%comma) ((apply c-comma (cdr x)) st))
|
||||
((%attribute) ((apply c-attribute (cdr x)) st))
|
||||
((%line) ((apply cpp-line (cdr x)) st))
|
||||
((%pragma %error %warning)
|
||||
@@ -628,6 +629,19 @@
|
||||
(define (c-begin . args)
|
||||
(apply c-begin/aux #f args))
|
||||
|
||||
;; MODIFIED FROM UPSTREAM fmt-c, which has no comma operator: as a
|
||||
;; statement, statements; as a value, the expressions in parens, since
|
||||
;; bare they would be an initializer's next declarator or a call's next
|
||||
;; argument -- except where a for header says it may stand bare.
|
||||
(define (c-comma . exprs)
|
||||
(lambda (st)
|
||||
((if (fmt-expression? st)
|
||||
(let ((joined (fmt-join (lambda (e) (c-with-op 'comma (c-expr e)))
|
||||
exprs ", ")))
|
||||
(if (eq? (fmt-op st) 'comma) joined (cat "(" joined ")")))
|
||||
(apply c-begin exprs))
|
||||
st)))
|
||||
|
||||
(define (c-begin/aux ret? body0 . body)
|
||||
(if (null? body)
|
||||
(c-expr body0)
|
||||
@@ -719,13 +733,16 @@
|
||||
(c-in-stmt (apply c-begin body)))
|
||||
fl))))
|
||||
|
||||
;; MODIFIED FROM UPSTREAM fmt-c: a header's first and last slots are
|
||||
;; the one place a comma expression goes bare, so they say so.
|
||||
(define (c-for init check update . body)
|
||||
(c-reset-newline
|
||||
(cat
|
||||
(c-block
|
||||
(c-in-expr
|
||||
(cat "for (" (c-expr init) "; " (c-in-test (c-expr check)) "; "
|
||||
(c-expr update ) ")"))
|
||||
(cat "for (" (c-with-op 'comma (c-expr init)) "; "
|
||||
(c-in-test (c-expr check)) "; "
|
||||
(c-with-op 'comma (c-expr update)) ")"))
|
||||
(c-in-stmt (apply c-begin body)))
|
||||
fl)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user