walk a define's body, and parenthesise it
The body was pasted as read, so `cast' stayed a call and names kept their dashes; and fmt-c parenthesised only a function-like body, so an object-like one regrouped with the operator it was pasted under. Fixes #55.
This commit is contained in:
@@ -703,6 +703,21 @@ compiles."
|
||||
(test-assert "nor one behind a pointer"
|
||||
(emits? "(struct t ((z int))) (struct s ((a (¤ * struct t))))" "struct t* a[]")))
|
||||
|
||||
;; A define's body was pasted unwalked, and unparenthesised: `cast'
|
||||
;; stayed a call, and (* x D) regrouped with D's own operator
|
||||
(test-group "defines"
|
||||
(test-assert "an atom is left bare"
|
||||
(emits? "(define N 4)" "#define N 4"))
|
||||
(test-assert "and its name converted"
|
||||
(emits? "(define MAX-N MIN-N)" "#define MAX_N MIN_N"))
|
||||
(test-assert "an expression is walked and parenthesised"
|
||||
(emits? "(define K (/ (cast 255 float) (cast 60 float)))"
|
||||
"#define K ((float)255 / (float)60)"))
|
||||
(test-assert "so is a negative literal"
|
||||
(emits? "(define NEG -1)" "#define NEG (-1)"))
|
||||
(test-assert "a function-like one is converted too"
|
||||
(emits? "(define (sq-of x) (* x x))" "#define sq_of(x) ((x) * (x))")))
|
||||
|
||||
;; A typedef's target is a type, and was walked as an expression: a
|
||||
;; pointer read as a dereference, an array as a subscript
|
||||
(test-group "typedefs"
|
||||
|
||||
Reference in New Issue
Block a user