Commit 72fd5c80 authored by Robert Griesemer's avatar Robert Griesemer

go/printer, gofmt: fix printing of labels,

apply gofmt to src, misc

Fixes #752.

R=rsc
CC=golang-dev
https://golang.org/cl/1240044
parent 38b2d10b
...@@ -134,7 +134,8 @@ func makeGolden(dst image.Image, t drawTest) image.Image { ...@@ -134,7 +134,8 @@ func makeGolden(dst image.Image, t drawTest) image.Image {
} }
func TestDraw(t *testing.T) { func TestDraw(t *testing.T) {
loop: for _, test := range drawTests { loop:
for _, test := range drawTests {
dst := hgradRed(255) dst := hgradRed(255)
// Draw the (src, mask, op) onto a copy of dst using a slow but obviously correct implementation. // Draw the (src, mask, op) onto a copy of dst using a slow but obviously correct implementation.
golden := makeGolden(dst, test) golden := makeGolden(dst, test)
......
...@@ -795,7 +795,8 @@ func (p *pp) doprintf(format string, a []interface{}) { ...@@ -795,7 +795,8 @@ func (p *pp) doprintf(format string, a []interface{}) {
i++ i++
// flags and widths // flags and widths
p.fmt.clearflags() p.fmt.clearflags()
F: for ; i < end; i++ { F:
for ; i < end; i++ {
switch format[i] { switch format[i] {
case '#': case '#':
p.fmt.sharp = true p.fmt.sharp = true
......
...@@ -1224,7 +1224,8 @@ func (p *parser) parsePrimaryExpr() ast.Expr { ...@@ -1224,7 +1224,8 @@ func (p *parser) parsePrimaryExpr() ast.Expr {
} }
x := p.parseOperand() x := p.parseOperand()
L: for { L:
for {
switch p.tok { switch p.tok {
case token.PERIOD: case token.PERIOD:
x = p.parseSelectorOrTypeAssertion(p.checkExpr(x)) x = p.parseSelectorOrTypeAssertion(p.checkExpr(x))
......
...@@ -1030,14 +1030,17 @@ func (p *printer) stmt(stmt ast.Stmt, nextIsRBrace bool, multiLine *bool) { ...@@ -1030,14 +1030,17 @@ func (p *printer) stmt(stmt ast.Stmt, nextIsRBrace bool, multiLine *bool) {
// a "correcting" unindent immediately following a line break // a "correcting" unindent immediately following a line break
// is applied before the line break if there is no comment // is applied before the line break if there is no comment
// between (see writeWhitespace) // between (see writeWhitespace)
p.print(unindent) p.print(unindent, s.Pos())
p.expr(s.Label, multiLine) p.expr(s.Label, multiLine)
p.print(token.COLON, vtab, indent) p.print(token.COLON, indent)
if _, isEmpty := s.Stmt.(*ast.EmptyStmt); isEmpty && !nextIsRBrace { if _, isEmpty := s.Stmt.(*ast.EmptyStmt); isEmpty {
p.print(token.SEMICOLON) if !nextIsRBrace {
break 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) p.stmt(s.Stmt, nextIsRBrace, multiLine)
case *ast.ExprStmt: case *ast.ExprStmt:
......
...@@ -247,7 +247,6 @@ func _() { ...@@ -247,7 +247,6 @@ func _() {
// Formatting around labels. // Formatting around labels.
func _() { func _() {
L: L:
} }
...@@ -260,36 +259,50 @@ L: // no semicolon needed ...@@ -260,36 +259,50 @@ L: // no semicolon needed
func _() { func _() {
switch 0 { switch 0 {
case 0: case 0:
L0: ; // semicolon required L0: // semicolon required
;
case 1: case 1:
L1: ; // semicolon required L1: // semicolon required
;
default: default:
L2: // no semicolon needed L2: // no semicolon needed
} }
} }
func _() {
f()
L1:
f()
L2:
;
L3:
}
func _() { func _() {
// this comment should be indented // this comment should be indented
L: L:
} }
func _() { func _() {
L: _ = 0 L:
_ = 0
} }
func _() { func _() {
// this comment should be indented // this comment should be indented
L: _ = 0 L:
_ = 0
} }
func _() { func _() {
for { for {
L1: _ = 0 L1:
_ = 0
L2: L2:
_ = 0 _ = 0
} }
...@@ -299,7 +312,8 @@ func _() { ...@@ -299,7 +312,8 @@ func _() {
func _() { func _() {
// this comment should be indented // this comment should be indented
for { for {
L1: _ = 0 L1:
_ = 0
L2: L2:
_ = 0 _ = 0
} }
...@@ -319,5 +333,6 @@ AnOverlongLabel: ...@@ -319,5 +333,6 @@ AnOverlongLabel:
} }
_ = 0 _ = 0
L: _ = 0 L:
_ = 0
} }
...@@ -205,6 +205,16 @@ func _() { ...@@ -205,6 +205,16 @@ func _() {
} }
func _() {
f()
L1:
f()
L2:
;
L3:
}
func _() { func _() {
// this comment should be indented // this comment should be indented
L: L:
......
...@@ -346,7 +346,8 @@ func parseIPv6(s string) IP { ...@@ -346,7 +346,8 @@ func parseIPv6(s string) IP {
// Loop, parsing hex numbers followed by colon. // Loop, parsing hex numbers followed by colon.
j := 0 j := 0
L: for j < IPv6len { L:
for j < IPv6len {
// Hex number. // Hex number.
n, i1, ok := xtoi(s, i) n, i1, ok := xtoi(s, i)
if !ok || n > 0xFFFF { if !ok || n > 0xFFFF {
......
...@@ -518,7 +518,8 @@ func (t *StructType) fieldByNameFunc(match func(string) bool, mark map[*StructTy ...@@ -518,7 +518,8 @@ func (t *StructType) fieldByNameFunc(match func(string) bool, mark map[*StructTy
var fi int // field index var fi int // field index
n := 0 // number of matching fields at depth fd 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) f := t.Field(i)
d := inf d := inf
switch { switch {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment