anchor an if's arms only where the if is a statement
Every if had its arms anchored, including one inside an argument that the writer renders as ?:, so a #line landed between its parts and the C did not compile. -C output, with no directives, hid it. Fixes #54.
This commit is contained in:
@@ -46,10 +46,10 @@ source location. Only statement positions may be walked this way: a
|
||||
(append-map (lambda (s)
|
||||
(let ((src (form-source s)))
|
||||
(if src
|
||||
(list (line-directive src) (walk-expr s))
|
||||
(list (walk-expr s)))))
|
||||
(list (line-directive src) (walk-statement s))
|
||||
(list (walk-statement s)))))
|
||||
(pack-comments stmts))
|
||||
(map walk-expr (pack-comments stmts))))
|
||||
(map walk-statement (pack-comments stmts))))
|
||||
|
||||
(define (walk-stmt s)
|
||||
"A statement in a slot that holds exactly one form -- an `if' arm.
|
||||
@@ -59,8 +59,18 @@ as an `else if' chain, so the anchor and the statement are wrapped in
|
||||
surrounding c-block supplies them)."
|
||||
(let ((src (and (pair? s) (anchor-statements?) (form-source s))))
|
||||
(if src
|
||||
`(%begin ,(line-directive src) ,(walk-expr s))
|
||||
(walk-expr s))))
|
||||
`(%begin ,(line-directive src) ,(walk-statement s))
|
||||
(walk-statement s))))
|
||||
|
||||
;;; Only here is an `if' a statement, with statements for arms that can
|
||||
;;; each be anchored. Anywhere else it is `?:', and a #line between its
|
||||
;;; parts does not compile
|
||||
(define (walk-statement s)
|
||||
(match s
|
||||
(('if . clauses)
|
||||
(with-comments (filter comment-form? clauses)
|
||||
(cons 'if (walk-if-clauses (remove comment-form? clauses)))))
|
||||
(_ (walk-expr s))))
|
||||
|
||||
;;; A `;' comment reads as a form, so one written inside a construct
|
||||
;;; with positional slots lands in a slot and shifts everything after
|
||||
@@ -228,9 +238,7 @@ forms, and what remains."
|
||||
;; and each is spliced or wrapped according to what the
|
||||
;; corresponding fmt-c procedure accepts.
|
||||
(('do . stmts) (cons '%block-begin (walk-body stmts)))
|
||||
(('if . clauses)
|
||||
(with-comments (filter comment-form? clauses)
|
||||
(cons 'if (walk-if-clauses (remove comment-form? clauses)))))
|
||||
(('if . clauses) (cons 'if (map walk-expr (remove comment-form? clauses))))
|
||||
(('while . rest)
|
||||
(let-values (((comments slots body) (take-slots rest 1)))
|
||||
(with-comments comments
|
||||
|
||||
Reference in New Issue
Block a user