mirror of https://github.com/golang/go.git
go/printer: fix formatting of three-index slice expression
Apply gofmt to src, misc. Fixes #22111. Change-Id: Ib1bda0caaf2c1787a8137b7a61bbef7a341cc68c Reviewed-on: https://go-review.googlesource.com/67633 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
11f494f37e
commit
5d1addf45d
|
|
@ -8,5 +8,6 @@ import "C"
|
||||||
|
|
||||||
//export FromPkg
|
//export FromPkg
|
||||||
func FromPkg() int32 { return 1024 }
|
func FromPkg() int32 { return 1024 }
|
||||||
|
|
||||||
//export Divu
|
//export Divu
|
||||||
func Divu(a, b uint32) uint32 { return a / b }
|
func Divu(a, b uint32) uint32 { return a / b }
|
||||||
|
|
|
||||||
|
|
@ -774,20 +774,35 @@ func (p *printer) expr1(expr ast.Expr, prec1, depth int) {
|
||||||
if x.Max != nil {
|
if x.Max != nil {
|
||||||
indices = append(indices, x.Max)
|
indices = append(indices, x.Max)
|
||||||
}
|
}
|
||||||
for i, y := range indices {
|
// determine if we need extra blanks around ':'
|
||||||
|
var needsBlanks bool
|
||||||
|
if depth <= 1 {
|
||||||
|
var indexCount int
|
||||||
|
var hasBinaries bool
|
||||||
|
for _, x := range indices {
|
||||||
|
if x != nil {
|
||||||
|
indexCount++
|
||||||
|
if isBinary(x) {
|
||||||
|
hasBinaries = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if indexCount > 1 && hasBinaries {
|
||||||
|
needsBlanks = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for i, x := range indices {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
// blanks around ":" if both sides exist and either side is a binary expression
|
if indices[i-1] != nil && needsBlanks {
|
||||||
// TODO(gri) once we have committed a variant of a[i:j:k] we may want to fine-
|
p.print(blank)
|
||||||
// tune the formatting here
|
}
|
||||||
x := indices[i-1]
|
|
||||||
if depth <= 1 && x != nil && y != nil && (isBinary(x) || isBinary(y)) {
|
|
||||||
p.print(blank, token.COLON, blank)
|
|
||||||
} else {
|
|
||||||
p.print(token.COLON)
|
p.print(token.COLON)
|
||||||
|
if x != nil && needsBlanks {
|
||||||
|
p.print(blank)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if y != nil {
|
if x != nil {
|
||||||
p.expr0(y, depth+1)
|
p.expr0(x, depth+1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
p.print(x.Rbrack, token.RBRACK)
|
p.print(x.Rbrack, token.RBRACK)
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,35 @@ func _() {
|
||||||
_ = x[: b+d : c+d]
|
_ = x[: b+d : c+d]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func issue22111() {
|
||||||
|
_ = x[:]
|
||||||
|
|
||||||
|
_ = x[:b]
|
||||||
|
_ = x[:b+1]
|
||||||
|
|
||||||
|
_ = x[a:]
|
||||||
|
_ = x[a+1:]
|
||||||
|
|
||||||
|
_ = x[a:b]
|
||||||
|
_ = x[a+1 : b]
|
||||||
|
_ = x[a : b+1]
|
||||||
|
_ = x[a+1 : b+1]
|
||||||
|
|
||||||
|
_ = x[:b:c]
|
||||||
|
_ = x[: b+1 : c]
|
||||||
|
_ = x[: b : c+1]
|
||||||
|
_ = x[: b+1 : c+1]
|
||||||
|
|
||||||
|
_ = x[a:b:c]
|
||||||
|
_ = x[a+1 : b : c]
|
||||||
|
_ = x[a : b+1 : c]
|
||||||
|
_ = x[a+1 : b+1 : c]
|
||||||
|
_ = x[a : b : c+1]
|
||||||
|
_ = x[a+1 : b : c+1]
|
||||||
|
_ = x[a : b+1 : c+1]
|
||||||
|
_ = x[a+1 : b+1 : c+1]
|
||||||
|
}
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
_ = a + b
|
_ = a + b
|
||||||
_ = a + b + c
|
_ = a + b + c
|
||||||
|
|
|
||||||
|
|
@ -138,6 +138,35 @@ func _() {
|
||||||
_ = x[:b+d:c+d]
|
_ = x[:b+d:c+d]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func issue22111() {
|
||||||
|
_ = x[:]
|
||||||
|
|
||||||
|
_ = x[:b]
|
||||||
|
_ = x[:b+1]
|
||||||
|
|
||||||
|
_ = x[a:]
|
||||||
|
_ = x[a+1:]
|
||||||
|
|
||||||
|
_ = x[a:b]
|
||||||
|
_ = x[a+1:b]
|
||||||
|
_ = x[a:b+1]
|
||||||
|
_ = x[a+1:b+1]
|
||||||
|
|
||||||
|
_ = x[:b:c]
|
||||||
|
_ = x[:b+1:c]
|
||||||
|
_ = x[:b:c+1]
|
||||||
|
_ = x[:b+1:c+1]
|
||||||
|
|
||||||
|
_ = x[a:b:c]
|
||||||
|
_ = x[a+1:b:c]
|
||||||
|
_ = x[a:b+1:c]
|
||||||
|
_ = x[a+1:b+1:c]
|
||||||
|
_ = x[a:b:c+1]
|
||||||
|
_ = x[a+1:b:c+1]
|
||||||
|
_ = x[a:b+1:c+1]
|
||||||
|
_ = x[a+1:b+1:c+1]
|
||||||
|
}
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
_ = a+b
|
_ = a+b
|
||||||
_ = a+b+c
|
_ = a+b+c
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,35 @@ func _() {
|
||||||
_ = x[: b+d : c+d]
|
_ = x[: b+d : c+d]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func issue22111() {
|
||||||
|
_ = x[:]
|
||||||
|
|
||||||
|
_ = x[:b]
|
||||||
|
_ = x[:b+1]
|
||||||
|
|
||||||
|
_ = x[a:]
|
||||||
|
_ = x[a+1:]
|
||||||
|
|
||||||
|
_ = x[a:b]
|
||||||
|
_ = x[a+1 : b]
|
||||||
|
_ = x[a : b+1]
|
||||||
|
_ = x[a+1 : b+1]
|
||||||
|
|
||||||
|
_ = x[:b:c]
|
||||||
|
_ = x[: b+1 : c]
|
||||||
|
_ = x[: b : c+1]
|
||||||
|
_ = x[: b+1 : c+1]
|
||||||
|
|
||||||
|
_ = x[a:b:c]
|
||||||
|
_ = x[a+1 : b : c]
|
||||||
|
_ = x[a : b+1 : c]
|
||||||
|
_ = x[a+1 : b+1 : c]
|
||||||
|
_ = x[a : b : c+1]
|
||||||
|
_ = x[a+1 : b : c+1]
|
||||||
|
_ = x[a : b+1 : c+1]
|
||||||
|
_ = x[a+1 : b+1 : c+1]
|
||||||
|
}
|
||||||
|
|
||||||
func _() {
|
func _() {
|
||||||
_ = a + b
|
_ = a + b
|
||||||
_ = a + b + c
|
_ = a + b + c
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue