]> Cypherpunks repositories - gostls13.git/commitdiff
go/printer, gofmt: fix printing of labels,
authorRobert Griesemer <gri@golang.org>
Sat, 22 May 2010 03:25:08 +0000 (20:25 -0700)
committerRobert Griesemer <gri@golang.org>
Sat, 22 May 2010 03:25:08 +0000 (20:25 -0700)
apply gofmt to src, misc

Fixes #752.

R=rsc
CC=golang-dev
https://golang.org/cl/1240044

src/pkg/exp/draw/draw_test.go
src/pkg/fmt/print.go
src/pkg/go/parser/parser.go
src/pkg/go/printer/nodes.go
src/pkg/go/printer/testdata/statements.golden
src/pkg/go/printer/testdata/statements.input
src/pkg/net/ip.go
src/pkg/reflect/type.go

index 5dc9d9593cb480072e98d08fef7c59a593e596e6..675c4eaec5fb8d6230bd777bf669da5ca0932fbc 100644 (file)
@@ -134,7 +134,8 @@ func makeGolden(dst image.Image, t drawTest) image.Image {
 }
 
 func TestDraw(t *testing.T) {
-loop: for _, test := range drawTests {
+loop:
+       for _, test := range drawTests {
                dst := hgradRed(255)
                // Draw the (src, mask, op) onto a copy of dst using a slow but obviously correct implementation.
                golden := makeGolden(dst, test)
index 15b7c514529bf626a7e41850665f5de7571ff1b1..e4413efa470c4ad73f3303aed50e529ecfd2b801 100644 (file)
@@ -795,7 +795,8 @@ func (p *pp) doprintf(format string, a []interface{}) {
                i++
                // flags and widths
                p.fmt.clearflags()
-       F: for ; i < end; i++ {
+       F:
+               for ; i < end; i++ {
                        switch format[i] {
                        case '#':
                                p.fmt.sharp = true
index 52504994e65174f5f71ac435b4760649db063c34..f9264f03bb32880863b5402d7a1cbcf81ce8e997 100644 (file)
@@ -1224,7 +1224,8 @@ func (p *parser) parsePrimaryExpr() ast.Expr {
        }
 
        x := p.parseOperand()
-L: for {
+L:
+       for {
                switch p.tok {
                case token.PERIOD:
                        x = p.parseSelectorOrTypeAssertion(p.checkExpr(x))
index 044a08a21964d08128ca70669fd1107c81ca44e1..77287f82bde846821dc463619e4c626896e3f296 100644 (file)
@@ -1030,14 +1030,17 @@ func (p *printer) stmt(stmt ast.Stmt, nextIsRBrace bool, multiLine *bool) {
                // a "correcting" unindent immediately following a line break
                // is applied before the line break if there is no comment
                // between (see writeWhitespace)
-               p.print(unindent)
+               p.print(unindent, s.Pos())
                p.expr(s.Label, multiLine)
-               p.print(token.COLON, vtab, indent)
-               if _, isEmpty := s.Stmt.(*ast.EmptyStmt); isEmpty && !nextIsRBrace {
-                       p.print(token.SEMICOLON)
-                       break
+               p.print(token.COLON, indent)
+               if _, isEmpty := s.Stmt.(*ast.EmptyStmt); isEmpty {
+                       if !nextIsRBrace {
+                               p.print(newline, s.Stmt.Pos(), token.SEMICOLON)
+                               break
+                       }
+               } else {
+                       p.print(newline)
                }
-               p.linebreak(s.Stmt.Pos().Line, 0, 1, ignore, true)
                p.stmt(s.Stmt, nextIsRBrace, multiLine)
 
        case *ast.ExprStmt:
index eec4ae08d00d1f27a0ce445d5916defb5576b999..9087390e7c05fbbdc1d21f629bde64441c6886d6 100644 (file)
@@ -247,7 +247,6 @@ func _() {
 // Formatting around labels.
 func _() {
 L:
-
 }
 
 
@@ -260,36 +259,50 @@ L:        // no semicolon needed
 func _() {
        switch 0 {
        case 0:
-       L0:     ;       // semicolon required
+       L0:     // semicolon required
+               ;
        case 1:
-       L1:     ;       // semicolon required
+       L1:     // semicolon required
+               ;
        default:
        L2:     // no semicolon needed
        }
 }
 
 
+func _() {
+       f()
+L1:
+       f()
+L2:
+       ;
+L3:
+}
+
+
 func _() {
        // this comment should be indented
 L:
-
 }
 
 
 func _() {
-L:     _ = 0
+L:
+       _ = 0
 }
 
 
 func _() {
        // this comment should be indented
-L:     _ = 0
+L:
+       _ = 0
 }
 
 
 func _() {
        for {
-       L1:     _ = 0
+       L1:
+               _ = 0
        L2:
                _ = 0
        }
@@ -299,7 +312,8 @@ func _() {
 func _() {
        // this comment should be indented
        for {
-       L1:     _ = 0
+       L1:
+               _ = 0
        L2:
                _ = 0
        }
@@ -319,5 +333,6 @@ AnOverlongLabel:
        }
        _ = 0
 
-L:     _ = 0
+L:
+       _ = 0
 }
index 42d6a8780c60bafd0a94dc8e4095ab4d27527765..53f16c050a8fbca305056c70fd0da8491f27f248 100644 (file)
@@ -205,6 +205,16 @@ func _() {
 }
 
 
+func _() {
+       f()
+L1:
+       f()
+L2:
+       ;
+L3:
+}
+
+
 func _() {
        // this comment should be indented
        L:
index f7ccf567e0c54268dc7754b2219bf269b28c6158..bd0c75de69697ed24ea50771c80805397a732414 100644 (file)
@@ -346,7 +346,8 @@ func parseIPv6(s string) IP {
 
        // Loop, parsing hex numbers followed by colon.
        j := 0
-L: for j < IPv6len {
+L:
+       for j < IPv6len {
                // Hex number.
                n, i1, ok := xtoi(s, i)
                if !ok || n > 0xFFFF {
index eb1ba52a9f2bc06c597ff496390deb4de822a8d5..19290647c51d3430b56fcb33ffea60a9d3ff9e7e 100644 (file)
@@ -518,7 +518,8 @@ func (t *StructType) fieldByNameFunc(match func(string) bool, mark map[*StructTy
 
        var fi int // field index
        n := 0     // number of matching fields at depth fd
-L: for i, _ := range t.fields {
+L:
+       for i, _ := range t.fields {
                f := t.Field(i)
                d := inf
                switch {