From b2dc84105a6882a46879e36e6e209de6a55e43fb Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Thu, 4 Jun 2020 12:32:42 +1000 Subject: [PATCH] Clean up more wuffs-c output (before clang-format) --- internal/cgen/builtin.go | 70 +++++++++++++------------- internal/cgen/cgen.go | 61 ++++++++++++---------- internal/cgen/expr.go | 8 +-- internal/cgen/func.go | 26 +++++----- internal/cgen/statement.go | 20 ++++---- internal/cgen/var.go | 26 +++++----- release/c/wuffs-unsupported-snapshot.c | 6 +++ 7 files changed, 116 insertions(+), 101 deletions(-) diff --git a/internal/cgen/builtin.go b/internal/cgen/builtin.go index 8846a34e..3ac6ce0a 100644 --- a/internal/cgen/builtin.go +++ b/internal/cgen/builtin.go @@ -59,7 +59,7 @@ func (g *gen) writeBuiltinCall(b *buffer, n *a.Expr, depth uint32) error { } for i, o := range n.Args() { - b.writeb(',') + b.writes(", ") if i == u64ToFlicksIndex { if o.AsArg().Name().Str(g.tm) != "duration" { return errors.New("cgen: internal error: inconsistent frame_config.set argument") @@ -106,7 +106,7 @@ func (g *gen) writeBuiltinCall(b *buffer, n *a.Expr, depth uint32) error { } args := n.Args() for _, o := range args[:len(args)-1] { - b.writeb(',') + b.writes(", ") if err := g.writeExpr(b, o.AsArg().Value(), depth); err != nil { return err } @@ -274,7 +274,7 @@ func (g *gen) writeBuiltinIOWriter(b *buffer, recv *a.Expr, method t.ID, args [] b.printf("wuffs_base__io_writer__limited_copy_u32_from_history%s(&%s%s, %s%s, %s%s", suffix, iopPrefix, name, io0Prefix, name, io2Prefix, name) for _, o := range args { - b.writeb(',') + b.writes(", ") if err := g.writeExpr(b, o.AsArg().Value(), depth); err != nil { return err } @@ -490,7 +490,7 @@ func (g *gen) writeBuiltinSlice(b *buffer, recv *a.Expr, method t.ID, args []*a. if err := g.writeExpr(b, recv, depth); err != nil { return err } - b.writeb(',') + b.writes(", ") return g.writeArgs(b, args, depth) case t.IDLength: @@ -507,7 +507,7 @@ func (g *gen) writeBuiltinSlice(b *buffer, recv *a.Expr, method t.ID, args []*a. if err := g.writeExpr(b, recv, depth); err != nil { return err } - b.writeb(',') + b.writes(", ") return g.writeArgs(b, args, depth) } return errNoSuchBuiltin @@ -600,7 +600,7 @@ func (g *gen) writeBuiltinTable(b *buffer, recv *a.Expr, method t.ID, args []*a. if err := g.writeExpr(b, recv, depth); err != nil { return err } - b.writeb(',') + b.writes(", ") return g.writeArgs(b, args, depth) } @@ -619,7 +619,7 @@ func (g *gen) writeBuiltinTable(b *buffer, recv *a.Expr, method t.ID, args []*a. func (g *gen) writeArgs(b *buffer, args []*a.Node, depth uint32) error { for i, o := range args { if i > 0 { - b.writeb(',') + b.writes(", ") } if err := g.writeExpr(b, o.AsArg().Value(), depth); err != nil { return err @@ -654,8 +654,8 @@ func (g *gen) writeBuiltinQuestionCall(b *buffer, n *a.Expr, depth uint32) error temp := g.currFunk.tempW g.currFunk.tempW++ - b.printf("if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {" + - "status = wuffs_base__make_status(wuffs_base__suspension__short_read); goto suspend; }") + b.printf("if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {\n" + + "status = wuffs_base__make_status(wuffs_base__suspension__short_read);\ngoto suspend;\n}\n") // TODO: watch for passing an array type to writeCTypeName? In C, an // array type can decay into a pointer. @@ -671,8 +671,8 @@ func (g *gen) writeBuiltinQuestionCall(b *buffer, n *a.Expr, depth uint32) error if err := g.writeCoroSuspPoint(b, false); err != nil { return err } - b.printf("if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {" + - "status = wuffs_base__make_status(wuffs_base__suspension__short_read); goto suspend; }") + b.printf("if (WUFFS_BASE__UNLIKELY(iop_a_src == io2_a_src)) {\n" + + "status = wuffs_base__make_status(wuffs_base__suspension__short_read);\ngoto suspend;\n}\n") b.printf("iop_a_src++;\n") return nil } @@ -696,7 +696,7 @@ func (g *gen) writeBuiltinQuestionCall(b *buffer, n *a.Expr, depth uint32) error b.printf("%s -= ((uint64_t)(io2_a_src - iop_a_src));\n", scratchName) b.printf("iop_a_src = io2_a_src;\n") - b.writes("status = wuffs_base__make_status(wuffs_base__suspension__short_read); goto suspend; }\n") + b.writes("status = wuffs_base__make_status(wuffs_base__suspension__short_read);\ngoto suspend;\n}\n") b.printf("iop_a_src += %s;\n", scratchName) return nil } @@ -731,7 +731,7 @@ func (g *gen) writeBuiltinQuestionCall(b *buffer, n *a.Expr, depth uint32) error return err } b.printf("if (iop_a_dst == io2_a_dst) {\n"+ - "status = wuffs_base__make_status(wuffs_base__suspension__short_write); goto suspend; }\n"+ + "status = wuffs_base__make_status(wuffs_base__suspension__short_write);\ngoto suspend;\n}\n"+ "*iop_a_dst++ = ((uint8_t)(%s));\n", scratchName) return nil } @@ -757,15 +757,15 @@ func (g *gen) writeReadUxxAsUyy(b *buffer, n *a.Expr, preName string, xx uint8, if err := g.writeCTypeName(b, n.MType(), tPrefix, fmt.Sprint(temp)); err != nil { return err } - b.writes(";") + b.writes(";\n") g.currFunk.usesScratch = true // TODO: don't hard-code [0], and allow recursive coroutines. scratchName := fmt.Sprintf("self->private_data.%s%s[0].scratch", sPrefix, g.currFunk.astFunc.FuncName().Str(g.tm)) - b.printf("if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= %d)) {", xx/8) - b.printf("%s%d =", tPrefix, temp) + b.printf("if (WUFFS_BASE__LIKELY(io2_a_src - iop_a_src >= %d)) {\n", xx/8) + b.printf("%s%d = ", tPrefix, temp) if xx != yy { b.printf("((uint%d_t)(", yy) } @@ -773,51 +773,51 @@ func (g *gen) writeReadUxxAsUyy(b *buffer, n *a.Expr, preName string, xx uint8, if xx != yy { b.writes("))") } - b.printf("; iop_a_src += %d;\n", xx/8) - b.printf("} else {") + b.printf(";\niop_a_src += %d;\n", xx/8) + b.printf("} else {\n") b.printf("%s = 0;\n", scratchName) if err := g.writeCoroSuspPoint(b, false); err != nil { return err } - b.printf("while (true) {") + b.printf("while (true) {\n") - b.printf("if (WUFFS_BASE__UNLIKELY(iop_%s == io2_%s)) {"+ - "status = wuffs_base__make_status(wuffs_base__suspension__short_read); goto suspend; }", + b.printf("if (WUFFS_BASE__UNLIKELY(iop_%s == io2_%s)) {\n"+ + "status = wuffs_base__make_status(wuffs_base__suspension__short_read);\ngoto suspend;\n}\n", preName, preName) - b.printf("uint64_t *scratch = &%s;", scratchName) + b.printf("uint64_t* scratch = &%s;\n", scratchName) b.printf("uint32_t num_bits_%d = ((uint32_t)(*scratch", temp) switch endianness { case 'b': - b.writes("& 0xFF)); *scratch >>= 8; *scratch <<= 8;") - b.printf("*scratch |= ((uint64_t)(*%s%s++)) << (56 - num_bits_%d);", + b.writes(" & 0xFF));\n*scratch >>= 8;\n*scratch <<= 8;\n") + b.printf("*scratch |= ((uint64_t)(*%s%s++)) << (56 - num_bits_%d);\n", iopPrefix, preName, temp) case 'l': - b.writes(">> 56)); *scratch <<= 8; *scratch >>= 8;") - b.printf("*scratch |= ((uint64_t)(*%s%s++)) << num_bits_%d;", + b.writes(" >> 56));\n*scratch <<= 8;\n*scratch >>= 8;\n") + b.printf("*scratch |= ((uint64_t)(*%s%s++)) << num_bits_%d;\n", iopPrefix, preName, temp) } - b.printf("if (num_bits_%d == %d) { %s%d = ((uint%d_t)(", temp, xx-8, tPrefix, temp, yy) + b.printf("if (num_bits_%d == %d) {\n%s%d = ((uint%d_t)(", temp, xx-8, tPrefix, temp, yy) switch endianness { case 'b': - b.printf("*scratch >> %d));", 64-xx) + b.printf("*scratch >> %d));\n", 64-xx) case 'l': - b.printf("*scratch));") + b.printf("*scratch));\n") } - b.printf("break;") - b.printf("}") + b.printf("break;\n") + b.printf("}\n") - b.printf("num_bits_%d += 8;", temp) + b.printf("num_bits_%d += 8;\n", temp) switch endianness { case 'b': - b.printf("*scratch |= ((uint64_t)(num_bits_%d));", temp) + b.printf("*scratch |= ((uint64_t)(num_bits_%d));\n", temp) case 'l': - b.printf("*scratch |= ((uint64_t)(num_bits_%d)) << 56;", temp) + b.printf("*scratch |= ((uint64_t)(num_bits_%d)) << 56;\n", temp) } - b.writes("}}\n") + b.writes("}\n}\n") return nil } diff --git a/internal/cgen/cgen.go b/internal/cgen/cgen.go index 81316f37..3c655297 100644 --- a/internal/cgen/cgen.go +++ b/internal/cgen/cgen.go @@ -497,7 +497,7 @@ func insertInterfaceDefinitions(buf *buffer) error { if err := g.writeFuncSignature(buf, f, wfsCDecl); err != nil { return err } - buf.writes(" {\n ") + buf.writes(" {\n") if err := writeFuncImplSelfMagicCheck(buf, g.tm, f); err != nil { return err } @@ -766,7 +766,7 @@ func (g *gen) genHeader(b *buffer) error { iQID := impl.AsTypeExpr().QID() iName := fmt.Sprintf("wuffs_%s__%s", iQID[0].Str(g.tm), iQID[1].Str(g.tm)) b.printf("static inline %s* //\n", iName) - b.printf("%s%s__alloc_as__%s(){\n", g.pkgPrefix, structName, iName) + b.printf("%s%s__alloc_as__%s() {\n", g.pkgPrefix, structName, iName) b.printf("return (%s*)(%s%s__alloc());\n", iName, g.pkgPrefix, structName) b.printf("}\n\n") } @@ -779,7 +779,7 @@ func (g *gen) genHeader(b *buffer) error { iQID := impl.AsTypeExpr().QID() iName := fmt.Sprintf("wuffs_%s__%s", iQID[0].Str(g.tm), iQID[1].Str(g.tm)) b.printf("static inline %s* //\n", iName) - b.printf("%s%s__upcast_as__%s(%s%s* p){\n", + b.printf("%s%s__upcast_as__%s(\n %s%s* p) {\n", g.pkgPrefix, structName, iName, g.pkgPrefix, structName) b.printf("return (%s*)p;\n", iName) b.printf("}\n\n") @@ -1017,13 +1017,16 @@ func (g *gen) writeConst(b *buffer, n *a.Const) error { func (g *gen) writeConstList(b *buffer, n *a.Expr) error { if n.Operator() == t.IDComma { b.writeb('{') - for _, o := range n.Args() { + for i, o := range n.Args() { + if i&7 == 0 { + b.writeb('\n') + } if err := g.writeConstList(b, o.AsExpr()); err != nil { return err } - b.writeb(',') + b.writes(", ") } - b.writeb('}') + b.writes("\n}") } else if cv := n.ConstValue(); cv != nil { b.writes(cv.String()) } else { @@ -1187,8 +1190,8 @@ func (g *gen) writeCppMethods(b *buffer, n *a.Struct) error { iQID := impl.AsTypeExpr().QID() iName := fmt.Sprintf("wuffs_%s__%s", iQID[0].Str(g.tm), iQID[1].Str(g.tm)) b.printf("\nstatic inline %s::unique_ptr //\n", iName) - b.printf("alloc_as__%s(){\n", iName) - b.printf("return %s::unique_ptr(%s%s__alloc_as__%s(), &free);\n", + b.printf("alloc_as__%s() {\n", iName) + b.printf("return %s::unique_ptr(\n%s%s__alloc_as__%s(), &free);\n", iName, g.pkgPrefix, structName, iName) b.printf("}\n") } @@ -1208,7 +1211,7 @@ func (g *gen) writeCppMethods(b *buffer, n *a.Struct) error { b.writes("// can write \"bar->baz(etc)\" instead of \"wuffs_foo__bar__baz(bar, etc)\".\n") b.printf("%s() = delete;\n", fullStructName) b.printf("%s(const %s&) = delete;\n", fullStructName, fullStructName) - b.printf("%s& operator=(const %s&) = delete;\n", fullStructName, fullStructName) + b.printf("%s& operator=(\nconst %s&) = delete;\n", fullStructName, fullStructName) b.writes("\n") b.writes("// As above, the size of the struct is not part of the public API, and unless\n") b.writes("// WUFFS_IMPLEMENTATION is #define'd, this struct type T should be heap\n") @@ -1224,15 +1227,15 @@ func (g *gen) writeCppMethods(b *buffer, n *a.Struct) error { // The empty // comment makes clang-format place the function name // at the start of a line. b.writes("inline wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //\n" + - "initialize(size_t sizeof_star_self, uint64_t wuffs_version, uint32_t initialize_flags) {\n") - b.printf("return %s%s__initialize(this, sizeof_star_self, wuffs_version, initialize_flags);\n}\n\n", + "initialize(\nsize_t sizeof_star_self,\nuint64_t wuffs_version,\nuint32_t initialize_flags) {\n") + b.printf("return %s%s__initialize(\nthis, sizeof_star_self, wuffs_version, initialize_flags);\n}\n\n", g.pkgPrefix, structName) for _, impl := range n.Implements() { iQID := impl.AsTypeExpr().QID() iName := fmt.Sprintf("wuffs_%s__%s", iQID[0].Str(g.tm), iQID[1].Str(g.tm)) b.printf("inline %s* //\n", iName) - b.printf("upcast_as__%s(){\n", iName) + b.printf("upcast_as__%s() {\n", iName) b.printf("return (%s*)this;\n", iName) b.printf("}\n\n") } @@ -1252,11 +1255,11 @@ func (g *gen) writeCppMethods(b *buffer, n *a.Struct) error { if err := g.writeFuncSignature(b, f, wfsCppDecl); err != nil { return err } - b.writes("{\n return ") + b.writes(" {\n return ") b.writes(g.funcCName(f)) b.writes("(this") for _, o := range f.In().Fields() { - b.writeb(',') + b.writes(", ") b.writes(aPrefix) b.writes(o.AsField().Name().Str(g.tm)) } @@ -1281,7 +1284,7 @@ func (g *gen) writeVTableImpl(b *buffer, n *a.Struct) error { nQID := n.QID() for _, impl := range impls { iQID := impl.AsTypeExpr().QID() - b.printf("const wuffs_%s__%s__func_ptrs %s%s__func_ptrs_for__wuffs_%s__%s = {", + b.printf("const wuffs_%s__%s__func_ptrs\n%s%s__func_ptrs_for__wuffs_%s__%s = {\n", iQID[0].Str(g.tm), iQID[1].Str(g.tm), g.pkgPrefix, nQID[1].Str(g.tm), iQID[0].Str(g.tm), iQID[1].Str(g.tm), @@ -1310,7 +1313,11 @@ func (g *gen) writeVTableImpl(b *buffer, n *a.Struct) error { func (g *gen) writeInitializerSignature(b *buffer, n *a.Struct, public bool) error { structName := n.QID().Str(g.tm) b.printf("wuffs_base__status WUFFS_BASE__WARN_UNUSED_RESULT //\n"+ - "%s%s__initialize(%s%s *self, size_t sizeof_star_self, uint64_t wuffs_version, uint32_t initialize_flags)", + "%s%s__initialize(\n"+ + " %s%s* self,\n"+ + " size_t sizeof_star_self,\n"+ + " uint64_t wuffs_version,\n"+ + " uint32_t initialize_flags)", g.pkgPrefix, structName, g.pkgPrefix, structName) return nil } @@ -1353,12 +1360,14 @@ func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error { return err } b.writes("{\n") - b.writes("if (!self) { return wuffs_base__make_status(wuffs_base__error__bad_receiver); }\n") + b.writes("if (!self) {\n") + b.writes(" return wuffs_base__make_status(wuffs_base__error__bad_receiver);\n") + b.writes("}\n") b.writes("if (sizeof(*self) != sizeof_star_self) {\n") b.writes(" return wuffs_base__make_status(wuffs_base__error__bad_sizeof_receiver);\n") b.writes("}\n") - b.writes("if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) || " + + b.writes("if (((wuffs_version >> 32) != WUFFS_VERSION_MAJOR) ||\n" + "(((wuffs_version >> 16) & 0xFFFF) > WUFFS_VERSION_MINOR)) {\n") b.writes(" return wuffs_base__make_status(wuffs_base__error__bad_wuffs_version);\n") b.writes("}\n\n") @@ -1419,9 +1428,9 @@ func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error { for _, impl := range n.Implements() { qid := impl.AsTypeExpr().QID() iName := fmt.Sprintf("wuffs_%s__%s", qid[0].Str(g.tm), qid[1].Str(g.tm)) - b.printf("self->private_impl.vtable_for__%s.vtable_name = "+ + b.printf("self->private_impl.vtable_for__%s.vtable_name =\n"+ "%s__vtable_name;\n", iName, iName) - b.printf("self->private_impl.vtable_for__%s.function_pointers = "+ + b.printf("self->private_impl.vtable_for__%s.function_pointers =\n"+ "(const void*)(&%s%s__func_ptrs_for__%s);\n", iName, g.pkgPrefix, n.QID().Str(g.tm), iName) } @@ -1433,21 +1442,21 @@ func (g *gen) writeInitializerImpl(b *buffer, n *a.Struct) error { if err := g.writeAllocSignature(b, n); err != nil { return err } - b.writes("{\n") - b.printf("%s%s* x = (%s%s*)(calloc(sizeof(%s%s), 1));\n", + b.writes(" {\n") + b.printf("%s%s* x =\n(%s%s*)(calloc(sizeof(%s%s), 1));\n", g.pkgPrefix, structName, g.pkgPrefix, structName, g.pkgPrefix, structName) - b.writes("if (!x) { return NULL; }\n") - b.printf("if (%s%s__initialize(x, sizeof(%s%s), "+ + b.writes("if (!x) {\nreturn NULL;\n}\n") + b.printf("if (%s%s__initialize(\nx, sizeof(%s%s), "+ "WUFFS_VERSION, WUFFS_INITIALIZE__ALREADY_ZEROED).repr) {\n", g.pkgPrefix, structName, g.pkgPrefix, structName) - b.writes("free(x); return NULL; }\n") + b.writes("free(x);\nreturn NULL;\n}\n") b.writes("return x;\n") b.writes("}\n\n") if err := g.writeSizeofSignature(b, n); err != nil { return err } - b.printf("{ return sizeof(%s%s); }\n\n", g.pkgPrefix, structName) + b.printf(" {\nreturn sizeof(%s%s);\n}\n\n", g.pkgPrefix, structName) } return nil } diff --git a/internal/cgen/expr.go b/internal/cgen/expr.go index 9474a4ab..4d98de7e 100644 --- a/internal/cgen/expr.go +++ b/internal/cgen/expr.go @@ -182,13 +182,13 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, depth uint32) error { } if mhs != nil { - b.writeb(',') + b.writes(", ") if err := g.writeExpr(b, mhs, depth); err != nil { return err } } if rhs != nil { - b.writeb(',') + b.writes(", ") if err := g.writeExpr(b, rhs, depth); err != nil { return err } @@ -263,7 +263,7 @@ func (g *gen) writeExprBinaryOp(b *buffer, n *a.Expr, depth uint32) error { uOp = "sub" } b.printf("wuffs_base__u%d__sat_%s", uBits, uOp) - opName = "," + opName = ", " case t.IDXBinaryAs: return g.writeExprAs(b, n.LHS().AsExpr(), n.RHS().AsTypeExpr(), depth) @@ -358,7 +358,7 @@ func (g *gen) writeExprUserDefinedCall(b *buffer, n *a.Expr, depth uint32) error return err } if len(n.Args()) > 0 { - b.writeb(',') + b.writes(", ") } } return g.writeArgs(b, n.Args(), depth) diff --git a/internal/cgen/func.go b/internal/cgen/func.go index 8920035c..6803d54e 100644 --- a/internal/cgen/func.go +++ b/internal/cgen/func.go @@ -201,7 +201,7 @@ func (g *gen) writeFuncImpl(b *buffer, n *a.Func) error { if err := g.writeFuncSignature(b, n, wfsCDecl); err != nil { return err } - b.writes("{\n") + b.writes(" {\n") if (len(n.Body()) != 0) || n.Effect().Coroutine() || (n.Out() != nil) { b.writex(k.bPrologue) @@ -212,7 +212,7 @@ func (g *gen) writeFuncImpl(b *buffer, n *a.Func) error { if n.Effect().Coroutine() { b.writex(k.bBodySuspend) } else if k.hasGotoOK { - b.writes("\ngoto ok;ok:\n") // The goto avoids the "unused label" warning. + b.writes("\ngoto ok;\nok:\n") // The goto avoids the "unused label" warning. } } @@ -307,7 +307,7 @@ func writeFuncImplSelfMagicCheck(b *buffer, tm *t.Map, f *a.Func) error { returnsStatus := f.Effect().Coroutine() || ((f.Out() != nil) && f.Out().IsStatus()) - b.writes("if (!self) {\n return ") + b.writes(" if (!self) {\n return ") if returnsStatus { b.writes("wuffs_base__make_status(wuffs_base__error__bad_receiver)") } else if err := writeOutParamZeroValue(b, tm, f.Out()); err != nil { @@ -353,7 +353,7 @@ func (g *gen) writeFuncImplPrologue(b *buffer) error { // For public coroutines, check that we are not suspended in an active // coroutine. if g.currFunk.astFunc.Effect().Coroutine() { - b.printf("if ((self->private_impl.active_coroutine != 0) && "+ + b.printf("if ((self->private_impl.active_coroutine != 0) &&\n"+ "(self->private_impl.active_coroutine != %d)) {\n", g.currFunk.coroID) b.writes("self->private_impl.magic = WUFFS_BASE__DISABLED;\n") b.writes("return wuffs_base__make_status(wuffs_base__error__interleaved_coroutine_calls);\n") @@ -426,12 +426,12 @@ func (g *gen) writeFuncImplBodySuspend(b *buffer) error { // We've reached the end of the function body. Reset the coroutine // suspension point so that the next call to this function starts at // the top. - b.writes("\ngoto ok;ok:") // The goto avoids the "unused label" warning. + b.writes("\ngoto ok;\nok:\n") // The goto avoids the "unused label" warning. b.printf("self->private_impl.%s%s[0] = 0;\n", pPrefix, g.currFunk.astFunc.FuncName().Str(g.tm)) - b.writes("goto exit; }\n\n") // Close the coroutine switch. + b.writes("goto exit;\n}\n\n") // Close the coroutine switch. - b.writes("goto suspend;suspend:") // The goto avoids the "unused label" warning. + b.writes("goto suspend;\nsuspend:\n") // The goto avoids the "unused label" warning. b.printf("self->private_impl.%s%s[0] = "+ "wuffs_base__status__is_suspension(&status) ? coro_susp_point : 0;\n", @@ -446,7 +446,7 @@ func (g *gen) writeFuncImplBodySuspend(b *buffer) error { b.writes("\n") } else if g.currFunk.astFunc.Effect().Coroutine() { - b.writes("\ngoto ok;ok:") // The goto avoids the "unused label" warning. + b.writes("\ngoto ok;\nok:\n") // The goto avoids the "unused label" warning. } return nil } @@ -456,11 +456,11 @@ func (g *gen) writeFuncImplEpilogue(b *buffer) error { if g.currFunk.astFunc.Effect().Coroutine() || (g.currFunk.returnsStatus && (len(g.currFunk.derivedVars) > 0)) { - b.writes("goto exit;exit:") // The goto avoids the "unused label" warning. + b.writes("goto exit;\nexit:\n") // The goto avoids the "unused label" warning. if g.currFunk.astFunc.Public() { - epilogue = "if (wuffs_base__status__is_error(&status)) { " + - "self->private_impl.magic = WUFFS_BASE__DISABLED; }\n" + + epilogue = "if (wuffs_base__status__is_error(&status)) {\n" + + "self->private_impl.magic = WUFFS_BASE__DISABLED;\n}\n" + "return status;\n" } else { epilogue = "return status;\n" @@ -540,10 +540,10 @@ func (g *gen) writeFuncImplArgChecks(b *buffer, n *a.Func) error { } b.writes(c) } - b.writes(") {") + b.writes(") {\n") b.writes("self->private_impl.magic = WUFFS_BASE__DISABLED;\n") if g.currFunk.astFunc.Effect().Coroutine() { - b.writes("return wuffs_base__make_status(wuffs_base__error__bad_argument);\n\n") + b.writes("return wuffs_base__make_status(wuffs_base__error__bad_argument);\n") } else { // TODO: don't assume that the return type is empty. b.printf("return wuffs_base__make_empty_struct();\n") diff --git a/internal/cgen/statement.go b/internal/cgen/statement.go index 783876bf..21ccc1c2 100644 --- a/internal/cgen/statement.go +++ b/internal/cgen/statement.go @@ -162,7 +162,7 @@ func (g *gen) writeStatementAssign0(b *buffer, op t.ID, lhs *a.Expr, rhs *a.Expr } if op != t.IDEqQuestion && rhs.Effect().Coroutine() { - b.writes("if (status.repr) { goto suspend; }\n") + b.writes("if (status.repr) {\ngoto suspend;\n}\n") } } @@ -285,7 +285,7 @@ func (g *gen) writeStatementIOBind(b *buffer, n *a.IOBind, depth uint32) error { } if n.Keyword() == t.IDIOBind { - b.printf("%s%s = wuffs_base__io_%s__set(&%s%s, &%s%s%s, &%s%s%s, &%s%s%s, &%s%s%s,", + b.printf("%s%s = wuffs_base__io_%s__set(&%s%s, &%s%s%s, &%s%s%s, &%s%s%s, &%s%s%s, ", prefix, name, cTyp, uPrefix, name, iopPrefix, prefix, name, io0Prefix, prefix, name, io1Prefix, prefix, name, io2Prefix, prefix, name) if err := g.writeExpr(b, n.Arg1(), 0); err != nil { @@ -387,7 +387,7 @@ func (g *gen) writeStatementIterate(b *buffer, n *a.Iterate, depth uint32) error // TODO: don't assume that the slice is a slice of base.u8. In // particular, the code gen can be subtle if the slice element type has // zero size, such as the empty struct. - b.printf("wuffs_base__slice_u8 %sslice_%s =", iPrefix, name) + b.printf("wuffs_base__slice_u8 %sslice_%s = ", iPrefix, name) if err := g.writeExpr(b, o.RHS(), 0); err != nil { return err } @@ -450,23 +450,23 @@ func (g *gen) writeStatementRet(b *buffer, n *a.Ret, depth uint32) error { return err } } - b.writes(";") + b.writes(";\n") if n.Keyword() == t.IDYield { return g.writeCoroSuspPoint(b, true) } if n.RetsError() { - b.writes("goto exit;") + b.writes("goto exit;\n") } else if isComplete { g.currFunk.hasGotoOK = true - b.writes("goto ok;") + b.writes("goto ok;\n") } else { g.currFunk.hasGotoOK = true // TODO: the "goto exit"s can be "goto ok". - b.writes("if (wuffs_base__status__is_error(&status)) { goto exit; }" + - "else if (wuffs_base__status__is_suspension(&status)) { " + - "status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension); goto exit; } goto ok;") + b.writes("if (wuffs_base__status__is_error(&status)) {\ngoto exit;\n} " + + "else if (wuffs_base__status__is_suspension(&status)) {\n" + + "status = wuffs_base__make_status(wuffs_base__error__cannot_return_a_suspension);\ngoto exit;\n}\ngoto ok;\n") } return nil } @@ -507,7 +507,7 @@ func (g *gen) writeStatementRet(b *buffer, n *a.Ret, depth uint32) error { } } - b.writeb(';') + b.writes(";\n") return nil } diff --git a/internal/cgen/var.go b/internal/cgen/var.go index 9c3e3d7c..a06eda92 100644 --- a/internal/cgen/var.go +++ b/internal/cgen/var.go @@ -115,27 +115,27 @@ func (g *gen) writeLoadDerivedVar(b *buffer, hack string, prefix string, name t. } if header { - b.printf("%s* %s%s = NULL;", elem, iopPrefix, preName) - b.printf("%s* %s%s WUFFS_BASE__POTENTIALLY_UNUSED = NULL;", elem, io0Prefix, preName) - b.printf("%s* %s%s WUFFS_BASE__POTENTIALLY_UNUSED = NULL;", elem, io1Prefix, preName) - b.printf("%s* %s%s WUFFS_BASE__POTENTIALLY_UNUSED = NULL;", elem, io2Prefix, preName) + b.printf("%s* %s%s = NULL;\n", elem, iopPrefix, preName) + b.printf("%s* %s%s WUFFS_BASE__POTENTIALLY_UNUSED = NULL;\n", elem, io0Prefix, preName) + b.printf("%s* %s%s WUFFS_BASE__POTENTIALLY_UNUSED = NULL;\n", elem, io1Prefix, preName) + b.printf("%s* %s%s WUFFS_BASE__POTENTIALLY_UNUSED = NULL;\n", elem, io2Prefix, preName) } - b.printf("if (%s) {", preName) + b.printf("if (%s) {\n", preName) if header { - b.printf("%s%s = %s->data.ptr;", io0Prefix, preName, preName) - b.printf("%s%s = %s%s + %s->%s;", io1Prefix, preName, io0Prefix, preName, preName, i1) - b.printf("%s%s = %s%s;", iopPrefix, preName, io1Prefix, preName) - b.printf("%s%s = %s%s + %s->%s;", io2Prefix, preName, io0Prefix, preName, preName, i2) + b.printf("%s%s = %s->data.ptr;\n", io0Prefix, preName, preName) + b.printf("%s%s = %s%s + %s->%s;\n", io1Prefix, preName, io0Prefix, preName, preName, i1) + b.printf("%s%s = %s%s;\n", iopPrefix, preName, io1Prefix, preName) + b.printf("%s%s = %s%s + %s->%s;\n", io2Prefix, preName, io0Prefix, preName, preName, i2) if q := typ.QID()[1]; (q == t.IDIOWriter) || (q == t.IDTokenWriter) { - b.printf("if (%s->meta.closed) {", preName) - b.printf("%s%s = %s%s;", io2Prefix, preName, iopPrefix, preName) + b.printf("if (%s->meta.closed) {\n", preName) + b.printf("%s%s = %s%s;\n", io2Prefix, preName, iopPrefix, preName) b.printf("}\n") } } else { - b.printf("%s%s = %s->data.ptr + %s->%s;", iopPrefix, preName, preName, preName, i1) + b.printf("%s%s = %s->data.ptr + %s->%s;\n", iopPrefix, preName, preName, preName, i1) } b.printf("}\n") @@ -173,7 +173,7 @@ func (g *gen) writeSaveDerivedVar(b *buffer, hack string, prefix string, name t. index = "wi" } - b.printf("if (%s) { %s->meta.%s = ((size_t)(%s%s - %s->data.ptr)); }\n", + b.printf("if (%s) {\n%s->meta.%s = ((size_t)(%s%s - %s->data.ptr));\n}\n", preName, preName, index, iopPrefix, preName, preName) return nil } diff --git a/release/c/wuffs-unsupported-snapshot.c b/release/c/wuffs-unsupported-snapshot.c index 189cde77..b9ce2700 100644 --- a/release/c/wuffs-unsupported-snapshot.c +++ b/release/c/wuffs-unsupported-snapshot.c @@ -13216,6 +13216,7 @@ label__outer__continue:; label__outer__break:; status = wuffs_base__make_status(NULL); goto ok; + goto ok; ok: goto exit; @@ -17734,6 +17735,7 @@ wuffs_gif__config_decoder__tell_me_more(wuffs_gif__config_decoder* self, self->private_impl.f_metadata_io_position = 0; status = wuffs_base__make_status(NULL); goto ok; + goto ok; ok: self->private_impl.p_tell_me_more[0] = 0; @@ -18166,6 +18168,7 @@ wuffs_gif__config_decoder__decode_frame( status = wuffs_base__make_status(wuffs_base__error__unsupported_method); goto exit; + goto ok; ok: goto exit; @@ -19559,6 +19562,7 @@ wuffs_gif__decoder__tell_me_more(wuffs_gif__decoder* self, self->private_impl.f_metadata_io_position = 0; status = wuffs_base__make_status(NULL); goto ok; + goto ok; ok: self->private_impl.p_tell_me_more[0] = 0; @@ -24293,6 +24297,7 @@ wuffs_json__decoder__decode_comment(wuffs_json__decoder* self, } status = wuffs_base__make_status(wuffs_json__error__bad_input); goto exit; + goto ok; ok: self->private_impl.p_decode_comment[0] = 0; @@ -25380,6 +25385,7 @@ wuffs_wbmp__decoder__tell_me_more(wuffs_wbmp__decoder* self, status = wuffs_base__make_status(wuffs_base__error__no_more_information); goto exit; + goto ok; ok: goto exit;