]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile/internal/syntax: remove ShortString, use String instead
authorRobert Griesemer <gri@golang.org>
Fri, 8 Jan 2021 18:29:11 +0000 (10:29 -0800)
committerRobert Griesemer <gri@golang.org>
Fri, 8 Jan 2021 22:00:23 +0000 (22:00 +0000)
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>
src/cmd/compile/internal/syntax/printer.go
src/cmd/compile/internal/syntax/printer_test.go
src/cmd/compile/internal/types2/api_test.go
src/cmd/compile/internal/types2/assignments.go
src/cmd/compile/internal/types2/builtins_test.go
src/cmd/compile/internal/types2/errors.go
src/cmd/compile/internal/types2/operand.go

index 0a60e1753ded1e4f7000c933b3a363a45e9b8b4b..161eb0d092d40551a377a5e59581afed1689bfdd 100644 (file)
@@ -44,20 +44,17 @@ func Fprint(w io.Writer, x Node, form Form) (n int, err error) {
        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 (
index e83e9c1b2ccbc47a0f727a06f2a8d9de58cc13d9..bcae815a4680aeede496d72842bf6bf40b590f0a 100644 (file)
@@ -178,7 +178,7 @@ func TestShortString(t *testing.T) {
                        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])
                }
        }
index c1327b179ca6a6f7e9e4affdeb1ad2efa75d6aa3..d9647b943247e78b79afdf52c27dd7151dd08f1c 100644 (file)
@@ -151,7 +151,7 @@ func TestValuesInfo(t *testing.T) {
                // 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
                        }
@@ -306,7 +306,7 @@ func TestTypesInfo(t *testing.T) {
                // 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
                        }
@@ -454,7 +454,7 @@ func TestInferredInfo(t *testing.T) {
                        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
@@ -733,8 +733,8 @@ func TestPredicatesInfo(t *testing.T) {
                // 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
                        }
index 0fa9c6b8e6d749c3f92f134801006534c5ba99f1..3238b3ac37e7a2263bc7d4f42c05950cfd834bc5 100644 (file)
@@ -197,7 +197,7 @@ func (check *Checker) assignVar(lhs syntax.Expr, x *operand) Type {
                        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
                        }
                }
index 0fc7c17d3e693d54b48f3d78bee30446a04258eb..35c38518f6c372b9dd3cf65098cb52b58d2ad1e4 100644 (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
                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 {
index d74980253e14a57cc5ba1b7106beae1e049ff87d..62b1d39d836d2ca1023361b9ea163c18de29b6ff 100644 (file)
@@ -53,7 +53,7 @@ func (check *Checker) sprintf(format string, args ...interface{}) string {
                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:
index ab4a7eb4f39fcfb5f7c3c9e6d30b9799499cdb29..d5a10b2c292e8cdf659b581c79ad433c560b1016 100644 (file)
@@ -110,7 +110,7 @@ func operandString(x *operand, qf Qualifier) string {
 
        var expr string
        if x.expr != nil {
-               expr = syntax.ShortString(x.expr)
+               expr = syntax.String(x.expr)
        } else {
                switch x.mode {
                case builtin: