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>
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
- _, err := Fprint(&buf, n, form)
+ _, err := Fprint(&buf, n, ShortForm)
if err != nil {
fmt.Fprintf(&buf, "<<< ERROR: %s", err)
}
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
const (
continue
}
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])
}
}
// look for expression
var expr syntax.Expr
for e := range info.Types {
- if syntax.ShortString(e) == test.expr {
+ if syntax.String(e) == test.expr {
expr = e
break
}
// look for expression type
var typ Type
for e, tv := range info.Types {
- if syntax.ShortString(e) == test.expr {
+ if syntax.String(e) == test.expr {
typ = tv.Type
break
}
default:
panic(fmt.Sprintf("unexpected call expression type %T", call))
}
- if syntax.ShortString(fun) == test.fun {
+ if syntax.String(fun) == test.fun {
targs = inf.Targs
sig = inf.Sig
break
// look for expression predicates
got := "<missing>"
for e, tv := range info.Types {
- //println(name, syntax.ShortString(e))
- if syntax.ShortString(e) == test.expr {
+ //println(name, syntax.String(e))
+ if syntax.String(e) == test.expr {
got = predString(tv)
break
}
var op operand
check.expr(&op, sel.X)
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
}
}
// the recorded type for the built-in must match the wanted signature
typ := types[fun].Type
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
}
if got := typ.String(); got != want {
case syntax.Pos:
arg = a.String()
case syntax.Expr:
- arg = syntax.ShortString(a)
+ arg = syntax.String(a)
case Object:
arg = ObjectString(a, check.qualifier)
case Type:
var expr string
if x.expr != nil {
- expr = syntax.ShortString(x.expr)
+ expr = syntax.String(x.expr)
} else {
switch x.mode {
case builtin: