Commit 9e1f6a32 authored by Robert Griesemer's avatar Robert Griesemer

cmd/compile: implement fmt.Formatter for Op formats %s, %v

Change-Id: I59e18fab37fd688fc1e578e2192e32e29fdf37f0
Reviewed-on: https://go-review.googlesource.com/28331Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
parent adcd34c7
......@@ -213,25 +213,38 @@ var goopnames = []string{
}
func (o Op) String() string {
return oconv(o, 0)
return fmt.Sprintf("%v", o)
}
func (o Op) GoString() string {
return oconv(o, FmtSharp)
return fmt.Sprintf("%#v", o)
}
func oconv(o Op, flag FmtFlag) string {
func (o Op) Format(s fmt.State, format rune) {
switch format {
case 's', 'v':
o.oconv(s)
default:
fmt.Fprintf(s, "%%!%c(Op=%d)", format, o)
}
}
func (o Op) oconv(s fmt.State) {
flag := fmtFlag(s)
if (flag&FmtSharp != 0) || fmtmode != FDbg {
if o >= 0 && int(o) < len(goopnames) && goopnames[o] != "" {
return goopnames[o]
fmt.Fprint(s, goopnames[o])
return
}
}
if o >= 0 && int(o) < len(opnames) && opnames[o] != "" {
return opnames[o]
fmt.Fprint(s, opnames[o])
return
}
return fmt.Sprintf("O-%d", o)
fmt.Sprintf("O-%d", o)
}
var classnames = []string{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment