summaryrefslogtreecommitdiff
path: root/libgo/go/go/printer
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2018-01-09 01:23:08 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2018-01-09 01:23:08 +0000
commit1a2f01efa63036a5104f203a4789e682c0e0915d (patch)
tree373e15778dc8295354584e1f86915ae493b604ff /libgo/go/go/printer
parent8799df67f2dab88f9fda11739c501780a85575e2 (diff)
libgo: update to Go1.10beta1
Update the Go library to the 1.10beta1 release. Requires a few changes to the compiler for modifications to the map runtime code, and to handle some nowritebarrier cases in the runtime. Reviewed-on: https://go-review.googlesource.com/86455 gotools/: * Makefile.am (go_cmd_vet_files): New variable. (go_cmd_buildid_files, go_cmd_test2json_files): New variables. (s-zdefaultcc): Change from constants to functions. (noinst_PROGRAMS): Add vet, buildid, and test2json. (cgo$(EXEEXT)): Link against $(LIBGOTOOL). (vet$(EXEEXT)): New target. (buildid$(EXEEXT)): New target. (test2json$(EXEEXT)): New target. (install-exec-local): Install all $(noinst_PROGRAMS). (uninstall-local): Uninstasll all $(noinst_PROGRAMS). (check-go-tool): Depend on $(noinst_PROGRAMS). Copy down objabi.go. (check-runtime): Depend on $(noinst_PROGRAMS). (check-cgo-test, check-carchive-test): Likewise. (check-vet): New target. (check): Depend on check-vet. Look at cmd_vet-testlog. (.PHONY): Add check-vet. * Makefile.in: Rebuild. From-SVN: r256365
Diffstat (limited to 'libgo/go/go/printer')
-rw-r--r--libgo/go/go/printer/nodes.go72
-rw-r--r--libgo/go/go/printer/testdata/comments.golden28
-rw-r--r--libgo/go/go/printer/testdata/comments.input28
-rw-r--r--libgo/go/go/printer/testdata/expressions.golden49
-rw-r--r--libgo/go/go/printer/testdata/expressions.input40
-rw-r--r--libgo/go/go/printer/testdata/expressions.raw49
6 files changed, 233 insertions, 33 deletions
diff --git a/libgo/go/go/printer/nodes.go b/libgo/go/go/printer/nodes.go
index 4eaadeb448f..3e2ff4f5ae3 100644
--- a/libgo/go/go/printer/nodes.go
+++ b/libgo/go/go/printer/nodes.go
@@ -398,22 +398,33 @@ func (p *printer) fieldList(fields *ast.FieldList, isStruct, isIncomplete bool)
// no blank between keyword and {} in this case
p.print(lbrace, token.LBRACE, rbrace, token.RBRACE)
return
- } else if isStruct && p.isOneLineFieldList(list) { // for now ignore interfaces
+ } else if p.isOneLineFieldList(list) {
// small enough - print on one line
// (don't use identList and ignore source line breaks)
p.print(lbrace, token.LBRACE, blank)
f := list[0]
- for i, x := range f.Names {
- if i > 0 {
- // no comments so no need for comma position
- p.print(token.COMMA, blank)
+ if isStruct {
+ for i, x := range f.Names {
+ if i > 0 {
+ // no comments so no need for comma position
+ p.print(token.COMMA, blank)
+ }
+ p.expr(x)
+ }
+ if len(f.Names) > 0 {
+ p.print(blank)
+ }
+ p.expr(f.Type)
+ } else { // interface
+ if ftyp, isFtyp := f.Type.(*ast.FuncType); isFtyp {
+ // method
+ p.expr(f.Names[0])
+ p.signature(ftyp.Params, ftyp.Results)
+ } else {
+ // embedded interface
+ p.expr(f.Type)
}
- p.expr(x)
- }
- if len(f.Names) > 0 {
- p.print(blank)
}
- p.expr(f.Type)
p.print(blank, rbrace, token.RBRACE)
return
}
@@ -774,20 +785,35 @@ func (p *printer) expr1(expr ast.Expr, prec1, depth int) {
if x.Max != nil {
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 {
- // blanks around ":" if both sides exist and either side is a binary expression
- // TODO(gri) once we have committed a variant of a[i:j:k] we may want to fine-
- // 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)
+ if indices[i-1] != nil && needsBlanks {
+ p.print(blank)
+ }
+ p.print(token.COLON)
+ if x != nil && needsBlanks {
+ p.print(blank)
}
}
- if y != nil {
- p.expr0(y, depth+1)
+ if x != nil {
+ p.expr0(x, depth+1)
}
}
p.print(x.Rbrack, token.RBRACK)
@@ -837,7 +863,9 @@ func (p *printer) expr1(expr ast.Expr, prec1, depth int) {
if len(x.Elts) > 0 {
mode |= noExtraBlank
}
- p.print(mode, x.Rbrace, token.RBRACE, mode)
+ // need the initial indent to print lone comments with
+ // the proper level of indentation
+ p.print(indent, unindent, mode, x.Rbrace, token.RBRACE, mode)
p.level--
case *ast.Ellipsis:
diff --git a/libgo/go/go/printer/testdata/comments.golden b/libgo/go/go/printer/testdata/comments.golden
index 4d92e653279..e1818e5fd53 100644
--- a/libgo/go/go/printer/testdata/comments.golden
+++ b/libgo/go/go/printer/testdata/comments.golden
@@ -728,4 +728,32 @@ func _() {
*/
}
+var _ = []T{ /* lone comment */ }
+
+var _ = []T{
+ /* lone comment */
+}
+
+var _ = []T{
+ // lone comments
+ // in composite lit
+}
+
+var _ = [][]T{
+ {
+ // lone comments
+ // in composite lit
+ },
+}
+
+// TODO: gofmt doesn't add these tabs; make it so that these golden
+// tests run the printer in a way that it's exactly like gofmt.
+
+var _ = []T{ // lone comment
+}
+
+var _ = []T{ // lone comments
+ // in composite lit
+}
+
/* This comment is the last entry in this file. It must be printed and should be followed by a newline */
diff --git a/libgo/go/go/printer/testdata/comments.input b/libgo/go/go/printer/testdata/comments.input
index 40351eeef69..f3eda12c229 100644
--- a/libgo/go/go/printer/testdata/comments.input
+++ b/libgo/go/go/printer/testdata/comments.input
@@ -725,4 +725,32 @@ func _() {
*/
}
+var _ = []T{/* lone comment */}
+
+var _ = []T{
+/* lone comment */
+}
+
+var _ = []T{
+// lone comments
+// in composite lit
+}
+
+var _ = [][]T{
+ {
+ // lone comments
+ // in composite lit
+ },
+}
+
+// TODO: gofmt doesn't add these tabs; make it so that these golden
+// tests run the printer in a way that it's exactly like gofmt.
+
+var _ = []T{// lone comment
+}
+
+var _ = []T{// lone comments
+// in composite lit
+}
+
/* This comment is the last entry in this file. It must be printed and should be followed by a newline */
diff --git a/libgo/go/go/printer/testdata/expressions.golden b/libgo/go/go/printer/testdata/expressions.golden
index cab991fd883..16a68c7bf74 100644
--- a/libgo/go/go/printer/testdata/expressions.golden
+++ b/libgo/go/go/printer/testdata/expressions.golden
@@ -122,18 +122,47 @@ func _() {
// slice expressions with cap
func _() {
_ = x[a:b:c]
- _ = x[a:b : c+d]
+ _ = x[a : b : c+d]
_ = x[a : b+d : c]
_ = x[a : b+d : c+d]
- _ = x[a+d : b:c]
+ _ = x[a+d : b : c]
_ = x[a+d : b : c+d]
_ = x[a+d : b+d : c]
_ = x[a+d : b+d : c+d]
_ = x[:b:c]
- _ = x[:b : c+d]
- _ = x[:b+d : c]
- _ = x[:b+d : c+d]
+ _ = x[: b : c+d]
+ _ = x[: b+d : c]
+ _ = 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 _() {
@@ -261,6 +290,16 @@ func _() {
_ = struct{ x, y, z int }{0, 1, 2}
_ = struct{ int }{0}
_ = struct{ s struct{ int } }{struct{ int }{0}}
+
+ _ = (interface{})(nil)
+ _ = (interface{ String() string })(nil)
+ _ = (interface {
+ String() string
+ })(nil)
+ _ = (interface{ fmt.Stringer })(nil)
+ _ = (interface {
+ fmt.Stringer
+ })(nil)
}
func _() {
diff --git a/libgo/go/go/printer/testdata/expressions.input b/libgo/go/go/printer/testdata/expressions.input
index 7c88042dc17..8c523b60221 100644
--- a/libgo/go/go/printer/testdata/expressions.input
+++ b/libgo/go/go/printer/testdata/expressions.input
@@ -138,6 +138,35 @@ func _() {
_ = 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 _() {
_ = a+b
_ = a+b+c
@@ -266,8 +295,17 @@ func _() {
_ = struct{ x, y, z int }{0, 1, 2}
_ = struct{ int }{0}
_ = struct{ s struct { int } }{struct{ int}{0} }
-}
+ _ = (interface{})(nil)
+ _ = (interface{String() string})(nil)
+ _ = (interface{
+ String() string
+ })(nil)
+ _ = (interface{fmt.Stringer})(nil)
+ _ = (interface{
+ fmt.Stringer
+ })(nil)
+}
func _() {
// do not modify literals
diff --git a/libgo/go/go/printer/testdata/expressions.raw b/libgo/go/go/printer/testdata/expressions.raw
index d9060621ced..058fded4474 100644
--- a/libgo/go/go/printer/testdata/expressions.raw
+++ b/libgo/go/go/printer/testdata/expressions.raw
@@ -122,18 +122,47 @@ func _() {
// slice expressions with cap
func _() {
_ = x[a:b:c]
- _ = x[a:b : c+d]
+ _ = x[a : b : c+d]
_ = x[a : b+d : c]
_ = x[a : b+d : c+d]
- _ = x[a+d : b:c]
+ _ = x[a+d : b : c]
_ = x[a+d : b : c+d]
_ = x[a+d : b+d : c]
_ = x[a+d : b+d : c+d]
_ = x[:b:c]
- _ = x[:b : c+d]
- _ = x[:b+d : c]
- _ = x[:b+d : c+d]
+ _ = x[: b : c+d]
+ _ = x[: b+d : c]
+ _ = 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 _() {
@@ -261,6 +290,16 @@ func _() {
_ = struct{ x, y, z int }{0, 1, 2}
_ = struct{ int }{0}
_ = struct{ s struct{ int } }{struct{ int }{0}}
+
+ _ = (interface{})(nil)
+ _ = (interface{ String() string })(nil)
+ _ = (interface {
+ String() string
+ })(nil)
+ _ = (interface{ fmt.Stringer })(nil)
+ _ = (interface {
+ fmt.Stringer
+ })(nil)
}
func _() {