mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 16:52:18 +01:00
Stop dumbindent dropping blank lines near braces
This commit is contained in:
1 parent
58c0862c50
commit
b82396a3c6
5 files changed
+27
-26
No files matched your search
+14
-7
@@ -428,8 +428,7 @@ func insertInterfaceDeclarations(buf *buffer) error {
|
|||||||
}
|
}
|
||||||
buf.writes(");\n }\n\n")
|
buf.writes(");\n }\n\n")
|
||||||
}
|
}
|
||||||
buf.writes("#endif // __cplusplus\n\n")
|
buf.writes("#endif // __cplusplus\n")
|
||||||
|
|
||||||
buf.printf("}; // struct wuffs_base__%s__struct\n\n", n)
|
buf.printf("}; // struct wuffs_base__%s__struct\n\n", n)
|
||||||
|
|
||||||
buf.writes("#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)\n")
|
buf.writes("#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)\n")
|
||||||
@@ -1046,7 +1045,7 @@ func (g *gen) writeStructPrivateImpl(b *buffer, n *a.Struct) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if n.Classy() {
|
if n.Classy() {
|
||||||
b.writeb('\n')
|
needEmptyLine := true
|
||||||
for _, file := range g.files {
|
for _, file := range g.files {
|
||||||
for _, tld := range file.TopLevelDecls() {
|
for _, tld := range file.TopLevelDecls() {
|
||||||
if tld.Kind() != a.KFunc {
|
if tld.Kind() != a.KFunc {
|
||||||
@@ -1061,6 +1060,10 @@ func (g *gen) writeStructPrivateImpl(b *buffer, n *a.Struct) error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if needEmptyLine {
|
||||||
|
needEmptyLine = false
|
||||||
|
b.writeb('\n')
|
||||||
|
}
|
||||||
b.printf("uint32_t %s%s[%d];\n", pPrefix, o.FuncName().Str(g.tm), maxDepth)
|
b.printf("uint32_t %s%s[%d];\n", pPrefix, o.FuncName().Str(g.tm), maxDepth)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1083,10 +1086,8 @@ func (g *gen) writeStructPrivateImpl(b *buffer, n *a.Struct) error {
|
|||||||
}
|
}
|
||||||
b.writes(";\n")
|
b.writes(";\n")
|
||||||
}
|
}
|
||||||
if oldOuterLenB1 != len(*b) {
|
|
||||||
b.writeb('\n')
|
|
||||||
}
|
|
||||||
|
|
||||||
|
needEmptyLine := oldOuterLenB1 != len(*b)
|
||||||
for _, file := range g.files {
|
for _, file := range g.files {
|
||||||
for _, tld := range file.TopLevelDecls() {
|
for _, tld := range file.TopLevelDecls() {
|
||||||
if tld.Kind() != a.KFunc {
|
if tld.Kind() != a.KFunc {
|
||||||
@@ -1102,6 +1103,11 @@ func (g *gen) writeStructPrivateImpl(b *buffer, n *a.Struct) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
oldInnerLenB0 := len(*b)
|
oldInnerLenB0 := len(*b)
|
||||||
|
oldNeedEmptyLine := needEmptyLine
|
||||||
|
if needEmptyLine {
|
||||||
|
needEmptyLine = false
|
||||||
|
b.writeb('\n')
|
||||||
|
}
|
||||||
b.writes("struct {\n")
|
b.writes("struct {\n")
|
||||||
oldInnerLenB1 := len(*b)
|
oldInnerLenB1 := len(*b)
|
||||||
if k.coroSuspPoint != 0 {
|
if k.coroSuspPoint != 0 {
|
||||||
@@ -1116,6 +1122,7 @@ func (g *gen) writeStructPrivateImpl(b *buffer, n *a.Struct) error {
|
|||||||
b.printf("} %s%s[%d];\n", sPrefix, o.FuncName().Str(g.tm), maxDepth)
|
b.printf("} %s%s[%d];\n", sPrefix, o.FuncName().Str(g.tm), maxDepth)
|
||||||
} else {
|
} else {
|
||||||
*b = (*b)[:oldInnerLenB0]
|
*b = (*b)[:oldInnerLenB0]
|
||||||
|
needEmptyLine = oldNeedEmptyLine
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1240,7 +1247,7 @@ func (g *gen) writeCppMethods(b *buffer, n *a.Struct) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
b.writes("#endif // __cplusplus\n\n")
|
b.writes("#endif // __cplusplus\n")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -334,6 +334,8 @@ func writeFuncImplSelfMagicCheck(b *buffer, tm *t.Map, f *a.Func) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *gen) writeFuncImplPrologue(b *buffer) error {
|
func (g *gen) writeFuncImplPrologue(b *buffer) error {
|
||||||
|
oldLenB := len(*b)
|
||||||
|
|
||||||
// Check the initialized/disabled state and the "self" arg.
|
// Check the initialized/disabled state and the "self" arg.
|
||||||
if g.currFunk.astFunc.Public() && !g.currFunk.astFunc.Receiver().IsZero() {
|
if g.currFunk.astFunc.Public() && !g.currFunk.astFunc.Receiver().IsZero() {
|
||||||
if err := writeFuncImplSelfMagicCheck(b, g.tm, g.currFunk.astFunc); err != nil {
|
if err := writeFuncImplSelfMagicCheck(b, g.tm, g.currFunk.astFunc); err != nil {
|
||||||
@@ -365,10 +367,13 @@ func (g *gen) writeFuncImplPrologue(b *buffer) error {
|
|||||||
// TODO: rename the "status" variable to "ret"?
|
// TODO: rename the "status" variable to "ret"?
|
||||||
b.printf("wuffs_base__status status = wuffs_base__make_status(NULL);\n")
|
b.printf("wuffs_base__status status = wuffs_base__make_status(NULL);\n")
|
||||||
}
|
}
|
||||||
b.writes("\n")
|
|
||||||
|
if oldLenB != len(*b) {
|
||||||
|
b.writes("\n")
|
||||||
|
}
|
||||||
|
|
||||||
// Generate the local variables.
|
// Generate the local variables.
|
||||||
oldLenB := len(*b)
|
oldLenB = len(*b)
|
||||||
if err := g.writeVars(b, &g.currFunk, false); err != nil {
|
if err := g.writeVars(b, &g.currFunk, false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -173,11 +173,10 @@ func FormatBytes(dst []byte, src []byte, opts *Options) []byte {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nBlankLines := 0 // The number of preceding blank lines.
|
nBlankLines := 0 // The number of preceding blank lines.
|
||||||
nBraces := 0 // The number of unbalanced '{'s.
|
nBraces := 0 // The number of unbalanced '{'s.
|
||||||
nParens := 0 // The number of unbalanced '('s.
|
nParens := 0 // The number of unbalanced '('s.
|
||||||
openBrace := false // Whether the previous non-blank line ends with '{'.
|
hanging := false // Whether the previous non-blank line ends with '=' or '\\'.
|
||||||
hanging := false // Whether the previous non-blank line ends with '=' or '\\'.
|
|
||||||
|
|
||||||
outer:
|
outer:
|
||||||
for line, remaining := src, []byte(nil); len(src) > 0; src = remaining {
|
for line, remaining := src, []byte(nil); len(src) > 0; src = remaining {
|
||||||
@@ -198,9 +197,7 @@ outer:
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if nBlankLines > 0 {
|
if nBlankLines > 0 {
|
||||||
if !openBrace && (line[0] != '}') {
|
dst = appendRepeatedBytes(dst, newLines, nBlankLines)
|
||||||
dst = appendRepeatedBytes(dst, newLines, nBlankLines)
|
|
||||||
}
|
|
||||||
nBlankLines = 0
|
nBlankLines = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,7 +210,6 @@ outer:
|
|||||||
line = trimTrailingWhiteSpace(line)
|
line = trimTrailingWhiteSpace(line)
|
||||||
dst = append(dst, line...)
|
dst = append(dst, line...)
|
||||||
dst = append(dst, '\n')
|
dst = append(dst, '\n')
|
||||||
openBrace = false
|
|
||||||
hanging = lastNonWhiteSpace(line) == '\\'
|
hanging = lastNonWhiteSpace(line) == '\\'
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -264,7 +260,6 @@ outer:
|
|||||||
dst = append(dst, '\n')
|
dst = append(dst, '\n')
|
||||||
restOfLine := line[i+1:]
|
restOfLine := line[i+1:]
|
||||||
remaining = src[lineLength-len(restOfLine):]
|
remaining = src[lineLength-len(restOfLine):]
|
||||||
openBrace = true
|
|
||||||
hanging = false
|
hanging = false
|
||||||
continue outer
|
continue outer
|
||||||
}
|
}
|
||||||
@@ -281,7 +276,6 @@ outer:
|
|||||||
dst = append(dst, '\n')
|
dst = append(dst, '\n')
|
||||||
restOfLine := line[i+1:]
|
restOfLine := line[i+1:]
|
||||||
remaining = src[lineLength-len(restOfLine):]
|
remaining = src[lineLength-len(restOfLine):]
|
||||||
openBrace = false
|
|
||||||
hanging = false
|
hanging = false
|
||||||
continue outer
|
continue outer
|
||||||
}
|
}
|
||||||
@@ -323,7 +317,6 @@ outer:
|
|||||||
}
|
}
|
||||||
break inner
|
break inner
|
||||||
}
|
}
|
||||||
openBrace = last == '{'
|
|
||||||
hanging = hangingBytes[last]
|
hanging = hangingBytes[last]
|
||||||
|
|
||||||
// Output the line (minus any trailing space).
|
// Output the line (minus any trailing space).
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ func TestFormatBytes(tt *testing.T) {
|
|||||||
}, {
|
}, {
|
||||||
// Consecutive blank lines.
|
// Consecutive blank lines.
|
||||||
src: "f {\n\n\ng;\n\n\nh;\n\n\n}\n\n",
|
src: "f {\n\n\ng;\n\n\nh;\n\n\n}\n\n",
|
||||||
want: "f {\n g;\n\n\n h;\n}\n",
|
want: "f {\n\n\n g;\n\n\n h;\n\n\n}\n",
|
||||||
}, {
|
}, {
|
||||||
// Single-quote string.
|
// Single-quote string.
|
||||||
src: "a = '{'\nb = {\nc = 0\n",
|
src: "a = '{'\nb = {\nc = 0\n",
|
||||||
|
|||||||
@@ -4192,7 +4192,6 @@ struct wuffs_base__hasher_u32__struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
}; // struct wuffs_base__hasher_u32__struct
|
}; // struct wuffs_base__hasher_u32__struct
|
||||||
|
|
||||||
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
||||||
@@ -4414,7 +4413,6 @@ struct wuffs_base__image_decoder__struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
}; // struct wuffs_base__image_decoder__struct
|
}; // struct wuffs_base__image_decoder__struct
|
||||||
|
|
||||||
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
||||||
@@ -4493,7 +4491,6 @@ struct wuffs_base__io_transformer__struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
}; // struct wuffs_base__io_transformer__struct
|
}; // struct wuffs_base__io_transformer__struct
|
||||||
|
|
||||||
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
||||||
@@ -4572,7 +4569,6 @@ struct wuffs_base__token_decoder__struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
}; // struct wuffs_base__token_decoder__struct
|
}; // struct wuffs_base__token_decoder__struct
|
||||||
|
|
||||||
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
#endif // defined(__cplusplus) || defined(WUFFS_IMPLEMENTATION)
|
||||||
|
|||||||
Reference in new issue
Block a user