fix newline and whitespace after braces in generated C blocks
This commit is contained in:
45
fmt-c.scm
45
fmt-c.scm
@@ -26,6 +26,8 @@
|
|||||||
|
|
||||||
(define (c-in-expr proc) (fmt-let 'expression? #t proc))
|
(define (c-in-expr proc) (fmt-let 'expression? #t proc))
|
||||||
(define (c-in-stmt proc) (fmt-let 'expression? #f proc))
|
(define (c-in-stmt proc) (fmt-let 'expression? #f proc))
|
||||||
|
(define (c-reset-newline proc) (fmt-let 'newline-before-brace? #f proc))
|
||||||
|
|
||||||
(define (c-in-test proc) (fmt-let 'in-cond? #t (c-in-expr proc)))
|
(define (c-in-test proc) (fmt-let 'in-cond? #t (c-in-expr proc)))
|
||||||
(define (c-with-op op proc) (fmt-let 'op op proc))
|
(define (c-with-op op proc) (fmt-let 'op op proc))
|
||||||
|
|
||||||
@@ -487,8 +489,12 @@
|
|||||||
|
|
||||||
(define (c-open-brace st)
|
(define (c-open-brace st)
|
||||||
(if (fmt-newline-before-brace? st)
|
(if (fmt-newline-before-brace? st)
|
||||||
(cat nl (c-current-indent-string st) "{" nl)
|
(begin
|
||||||
(cat " {" nl)))
|
(fmt-set! st 'newline-before-brace? #t)
|
||||||
|
(cat "{" nl))
|
||||||
|
(begin
|
||||||
|
(fmt-set! st 'newline-before-brace? #t)
|
||||||
|
(cat " {" nl))))
|
||||||
|
|
||||||
(define (c-close-brace st)
|
(define (c-close-brace st)
|
||||||
(dsp "}"))
|
(dsp "}"))
|
||||||
@@ -590,18 +596,20 @@
|
|||||||
;; basic control structures
|
;; basic control structures
|
||||||
|
|
||||||
(define (c-while check . body)
|
(define (c-while check . body)
|
||||||
(cat (c-block (cat "while (" (c-in-test (c-expr check)) ")")
|
(c-reset-newline
|
||||||
(c-in-stmt (apply c-begin body)))
|
(cat (c-block (cat "while (" (c-in-test (c-expr check)) ")")
|
||||||
fl))
|
(c-in-stmt (apply c-begin body)))
|
||||||
|
fl)))
|
||||||
|
|
||||||
(define (c-for init check update . body)
|
(define (c-for init check update . body)
|
||||||
(cat
|
(c-reset-newline
|
||||||
(c-block
|
(cat
|
||||||
(c-in-expr
|
(c-block
|
||||||
(cat "for (" (c-expr init) "; " (c-in-test (c-expr check)) "; "
|
(c-in-expr
|
||||||
(c-expr update ) ")"))
|
(cat "for (" (c-expr init) "; " (c-in-test (c-expr check)) "; "
|
||||||
(c-in-stmt (apply c-begin body)))
|
(c-expr update ) ")"))
|
||||||
fl))
|
(c-in-stmt (apply c-begin body)))
|
||||||
|
fl)))
|
||||||
|
|
||||||
(define (c-param x)
|
(define (c-param x)
|
||||||
(cond
|
(cond
|
||||||
@@ -761,12 +769,13 @@
|
|||||||
(c-wrap-stmt (cat "goto " (c-expr label))))
|
(c-wrap-stmt (cat "goto " (c-expr label))))
|
||||||
|
|
||||||
(define (c-switch val . clauses)
|
(define (c-switch val . clauses)
|
||||||
(lambda (st)
|
(c-reset-newline
|
||||||
((cat "switch (" (c-in-expr val) ")" (c-open-brace st)
|
(lambda (st)
|
||||||
(c-indent/switch st)
|
((cat "switch (" (c-in-expr val) ")" (c-open-brace st)
|
||||||
(c-in-stmt (apply c-begin/aux #t (map c-switch-clause clauses))) fl
|
(c-indent/switch st)
|
||||||
(c-current-indent-string st) (c-close-brace st) fl)
|
(c-in-stmt (apply c-begin/aux #t (map c-switch-clause clauses))) fl
|
||||||
st)))
|
(c-current-indent-string st) (c-close-brace st) fl)
|
||||||
|
st))))
|
||||||
|
|
||||||
(define (c-switch-clause/breaks x)
|
(define (c-switch-clause/breaks x)
|
||||||
(lambda (st)
|
(lambda (st)
|
||||||
|
|||||||
Reference in New Issue
Block a user