- support printing of expression and type lists in sprintf
- simplified some code in go/types/exprstring.go
- fixed a typo in syntax package
Change-Id: Ic4bc154200aad95958d5bc2904a9ea17cf518388
Reviewed-on: https://go-review.googlesource.com/c/go/+/377974
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
return
}
-// String is a convenience functions that prints n in ShortForm
+// String is a convenience function that prints n in ShortForm
// and returns the printed string.
func String(n Node) string {
var buf bytes.Buffer
arg = a.String()
case syntax.Expr:
arg = syntax.String(a)
+ case []syntax.Expr:
+ var buf bytes.Buffer
+ buf.WriteByte('[')
+ for i, x := range a {
+ if i > 0 {
+ buf.WriteString(", ")
+ }
+ buf.WriteString(syntax.String(x))
+ }
+ buf.WriteByte(']')
+ arg = buf.String()
case Object:
arg = ObjectString(a, qf)
case Type:
arg = typeString(a, qf, debug)
+ case []Type:
+ var buf bytes.Buffer
+ buf.WriteByte('[')
+ for i, x := range a {
+ if i > 0 {
+ buf.WriteString(", ")
+ }
+ buf.WriteString(typeString(x, qf, debug))
+ }
+ buf.WriteByte(']')
+ arg = buf.String()
}
args[i] = arg
}
package types
import (
+ "bytes"
"errors"
"fmt"
"go/ast"
}
case ast.Expr:
arg = ExprString(a)
+ case []ast.Expr:
+ var buf bytes.Buffer
+ buf.WriteByte('[')
+ writeExprList(&buf, a)
+ buf.WriteByte(']')
+ arg = buf.String()
case Object:
arg = ObjectString(a, qf)
case Type:
arg = typeString(a, qf, debug)
+ case []Type:
+ var buf bytes.Buffer
+ buf.WriteByte('[')
+ for i, x := range a {
+ if i > 0 {
+ buf.WriteString(", ")
+ }
+ buf.WriteString(typeString(x, qf, debug))
+ }
+ buf.WriteByte(']')
+ arg = buf.String()
}
args[i] = arg
}
ix := typeparams.UnpackIndexExpr(x)
WriteExpr(buf, ix.X)
buf.WriteByte('[')
- for i, e := range ix.Indices {
- if i > 0 {
- buf.WriteString(", ")
- }
- WriteExpr(buf, e)
- }
+ writeExprList(buf, ix.Indices)
buf.WriteByte(']')
case *ast.SliceExpr: