diff options
| author | Matthew Dempsky <mdempsky@google.com> | 2020-11-13 18:33:19 -0800 |
|---|---|---|
| committer | Matthew Dempsky <mdempsky@google.com> | 2020-11-24 19:41:59 +0000 |
| commit | c767d73227704ba4e22e366e89d1885f52d4b6cc (patch) | |
| tree | 0117c4326bcaa4d7f717336be21adc7aa259b890 /src/cmd/compile/internal/gc/fmt.go | |
| parent | 6dae48fb0ba772d30c664a8a31732a46e980e536 (diff) | |
| download | go-git-c767d73227704ba4e22e366e89d1885f52d4b6cc.tar.gz | |
[dev.regabi] cmd/compile: remove CTRUNE
Since CL 255217, we've been able to rely on types.UntypedRune to
identify untyped rune literals, rather than needing Mpint.Rune /
CTRUNE. This makes way for switching to using go/constant, which
doesn't have a separate notion of rune constants distinct from integer
constants.
Passes toolstash-check.
Change-Id: I319861f4758aeea17345c101b167cb307e706a0e
Reviewed-on: https://go-review.googlesource.com/c/go/+/272652
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/gc/fmt.go')
| -rw-r--r-- | src/cmd/compile/internal/gc/fmt.go | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/src/cmd/compile/internal/gc/fmt.go b/src/cmd/compile/internal/gc/fmt.go index 9b57d131b1..740fdab977 100644 --- a/src/cmd/compile/internal/gc/fmt.go +++ b/src/cmd/compile/internal/gc/fmt.go @@ -526,28 +526,12 @@ func (v Val) Format(s fmt.State, verb rune) { func (v Val) vconv(s fmt.State, flag FmtFlag) { switch u := v.U.(type) { case *Mpint: - if !u.Rune { - if flag&FmtSharp != 0 { - fmt.Fprint(s, u.String()) - return - } - fmt.Fprint(s, u.GoString()) + if flag&FmtSharp != 0 { + fmt.Fprint(s, u.String()) return } - - switch x := u.Int64(); { - case ' ' <= x && x < utf8.RuneSelf && x != '\\' && x != '\'': - fmt.Fprintf(s, "'%c'", int(x)) - - case 0 <= x && x < 1<<16: - fmt.Fprintf(s, "'\\u%04x'", uint(int(x))) - - case 0 <= x && x <= utf8.MaxRune: - fmt.Fprintf(s, "'\\U%08x'", uint64(x)) - - default: - fmt.Fprintf(s, "('\\x00' + %v)", u) - } + fmt.Fprint(s, u.GoString()) + return case *Mpflt: if flag&FmtSharp != 0 { @@ -1336,19 +1320,40 @@ func (n *Node) exprfmt(s fmt.State, prec int, mode fmtMode) { } } + needUnparen := false if n.Type != nil && !n.Type.IsUntyped() { // Need parens when type begins with what might // be misinterpreted as a unary operator: * or <-. if n.Type.IsPtr() || (n.Type.IsChan() && n.Type.ChanDir() == types.Crecv) { - mode.Fprintf(s, "(%v)(%v)", n.Type, n.Val()) - return + mode.Fprintf(s, "(%v)(", n.Type) } else { - mode.Fprintf(s, "%v(%v)", n.Type, n.Val()) - return + mode.Fprintf(s, "%v(", n.Type) } + needUnparen = true } - mode.Fprintf(s, "%v", n.Val()) + if n.Type == types.UntypedRune { + u := n.Val().U.(*Mpint) + switch x := u.Int64(); { + case ' ' <= x && x < utf8.RuneSelf && x != '\\' && x != '\'': + fmt.Fprintf(s, "'%c'", int(x)) + + case 0 <= x && x < 1<<16: + fmt.Fprintf(s, "'\\u%04x'", uint(int(x))) + + case 0 <= x && x <= utf8.MaxRune: + fmt.Fprintf(s, "'\\U%08x'", uint64(x)) + + default: + fmt.Fprintf(s, "('\\x00' + %v)", u) + } + } else { + mode.Fprintf(s, "%v", n.Val()) + } + + if needUnparen { + mode.Fprintf(s, ")") + } // Special case: name used as local variable in export. // _ becomes ~b%d internally; print as _ for export |
