[dev.typeparams] cmd/compile/internal/syntax: remove ShortString, use String instead

Follow-up on feedback by mdempsky@ in https://golang.org/cl/282552 .

Change-Id: I1e5bb2d67cc8ae29fed100b87d18a33b3e2069eb
Reviewed-on: https://go-review.googlesource.com/c/go/+/282672
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Robert Griesemer 2021-01-08 10:29:11 -08:00
parent d017a1b649
commit 822aeacd9e
7 changed files with 14 additions and 17 deletions

View file

@ -44,20 +44,17 @@ func Fprint(w io.Writer, x Node, form Form) (n int, err error) {
return return
} }
func asString(n Node, form Form) string { // String is a convenience functions that prints n in ShortForm
// and returns the printed string.
func String(n Node) string {
var buf bytes.Buffer var buf bytes.Buffer
_, err := Fprint(&buf, n, form) _, err := Fprint(&buf, n, ShortForm)
if err != nil { if err != nil {
fmt.Fprintf(&buf, "<<< ERROR: %s", err) fmt.Fprintf(&buf, "<<< ERROR: %s", err)
} }
return buf.String() return buf.String()
} }
// String and ShortString are convenience functions that print n in
// LineForm or ShortForm respectively, and return the printed string.
func String(n Node) string { return asString(n, LineForm) }
func ShortString(n Node) string { return asString(n, ShortForm) }
type ctrlSymbol int type ctrlSymbol int
const ( const (

View file

@ -178,7 +178,7 @@ func TestShortString(t *testing.T) {
continue continue
} }
x := ast.DeclList[0].(*VarDecl).Values x := ast.DeclList[0].(*VarDecl).Values
if got := ShortString(x); got != test[1] { if got := String(x); got != test[1] {
t.Errorf("%s: got %s, want %s", test[0], got, test[1]) t.Errorf("%s: got %s, want %s", test[0], got, test[1])
} }
} }

View file

@ -151,7 +151,7 @@ func TestValuesInfo(t *testing.T) {
// look for expression // look for expression
var expr syntax.Expr var expr syntax.Expr
for e := range info.Types { for e := range info.Types {
if syntax.ShortString(e) == test.expr { if syntax.String(e) == test.expr {
expr = e expr = e
break break
} }
@ -306,7 +306,7 @@ func TestTypesInfo(t *testing.T) {
// look for expression type // look for expression type
var typ Type var typ Type
for e, tv := range info.Types { for e, tv := range info.Types {
if syntax.ShortString(e) == test.expr { if syntax.String(e) == test.expr {
typ = tv.Type typ = tv.Type
break break
} }
@ -454,7 +454,7 @@ func TestInferredInfo(t *testing.T) {
default: default:
panic(fmt.Sprintf("unexpected call expression type %T", call)) panic(fmt.Sprintf("unexpected call expression type %T", call))
} }
if syntax.ShortString(fun) == test.fun { if syntax.String(fun) == test.fun {
targs = inf.Targs targs = inf.Targs
sig = inf.Sig sig = inf.Sig
break break
@ -733,8 +733,8 @@ func TestPredicatesInfo(t *testing.T) {
// look for expression predicates // look for expression predicates
got := "<missing>" got := "<missing>"
for e, tv := range info.Types { for e, tv := range info.Types {
//println(name, syntax.ShortString(e)) //println(name, syntax.String(e))
if syntax.ShortString(e) == test.expr { if syntax.String(e) == test.expr {
got = predString(tv) got = predString(tv)
break break
} }

View file

@ -197,7 +197,7 @@ func (check *Checker) assignVar(lhs syntax.Expr, x *operand) Type {
var op operand var op operand
check.expr(&op, sel.X) check.expr(&op, sel.X)
if op.mode == mapindex { if op.mode == mapindex {
check.errorf(&z, "cannot assign to struct field %s in map", syntax.ShortString(z.expr)) check.errorf(&z, "cannot assign to struct field %s in map", syntax.String(z.expr))
return nil return nil
} }
} }

View file

@ -176,7 +176,7 @@ func testBuiltinSignature(t *testing.T, name, src0, want string) {
// the recorded type for the built-in must match the wanted signature // the recorded type for the built-in must match the wanted signature
typ := types[fun].Type typ := types[fun].Type
if typ == nil { if typ == nil {
t.Errorf("%s: no type recorded for %s", src0, syntax.ShortString(fun)) t.Errorf("%s: no type recorded for %s", src0, syntax.String(fun))
return return
} }
if got := typ.String(); got != want { if got := typ.String(); got != want {

View file

@ -53,7 +53,7 @@ func (check *Checker) sprintf(format string, args ...interface{}) string {
case syntax.Pos: case syntax.Pos:
arg = a.String() arg = a.String()
case syntax.Expr: case syntax.Expr:
arg = syntax.ShortString(a) arg = syntax.String(a)
case Object: case Object:
arg = ObjectString(a, check.qualifier) arg = ObjectString(a, check.qualifier)
case Type: case Type:

View file

@ -110,7 +110,7 @@ func operandString(x *operand, qf Qualifier) string {
var expr string var expr string
if x.expr != nil { if x.expr != nil {
expr = syntax.ShortString(x.expr) expr = syntax.String(x.expr)
} else { } else {
switch x.mode { switch x.mode {
case builtin: case builtin: