mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Remove parenthesesPolicy, part 1 of N
This commit is contained in:
1 parent
a5b4838e8c
commit
f159bcdadc
1 file changed
+15
-6
@@ -234,11 +234,12 @@ func (g *gen) writeStatementIf(b *buffer, n *a.If, depth uint32) error {
|
||||
}
|
||||
}
|
||||
|
||||
b.writes("if (")
|
||||
if err := g.writeExpr(b, n.Condition(), replaceCallSuspendibles, parenthesesOptional, 0); err != nil {
|
||||
condition := buffer(nil)
|
||||
if err := g.writeExpr(&condition, n.Condition(), replaceCallSuspendibles, parenthesesMandatory, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(") {\n")
|
||||
// Calling trimParens avoids clang's -Wparentheses-equality warning.
|
||||
b.printf("if (%s) {\n", trimParens(condition))
|
||||
for _, o := range n.BodyIfTrue() {
|
||||
if err := g.writeStatement(b, o, depth); err != nil {
|
||||
return err
|
||||
@@ -423,11 +424,12 @@ func (g *gen) writeStatementWhile(b *buffer, n *a.While, depth uint32) error {
|
||||
}
|
||||
b.printf("label_%d_continue:;\n", jt)
|
||||
}
|
||||
b.writes("while (")
|
||||
if err := g.writeExpr(b, n.Condition(), replaceCallSuspendibles, parenthesesOptional, 0); err != nil {
|
||||
condition := buffer(nil)
|
||||
if err := g.writeExpr(&condition, n.Condition(), replaceCallSuspendibles, parenthesesMandatory, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
b.writes(") {\n")
|
||||
// Calling trimParens avoids clang's -Wparentheses-equality warning.
|
||||
b.printf("while (%s) {\n", trimParens(condition))
|
||||
for _, o := range n.Body() {
|
||||
if err := g.writeStatement(b, o, depth); err != nil {
|
||||
return err
|
||||
@@ -904,6 +906,13 @@ func (g *gen) writeReadUXX(b *buffer, n *a.Expr, name string, size uint32, endia
|
||||
return nil
|
||||
}
|
||||
|
||||
func trimParens(b []byte) []byte {
|
||||
if len(b) > 1 && b[0] == '(' && b[len(b)-1] == ')' {
|
||||
return b[1 : len(b)-1]
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func isInSrc(tm *t.Map, n *a.Expr, methodName t.ID, nArgs int) bool {
|
||||
callSuspendible := methodName != t.IDSinceMark &&
|
||||
methodName != t.IDSetMark &&
|
||||
|
||||
Reference in new issue
Block a user