mirror of
https://github.com/golang/go
synced 2024-11-18 02:14:45 -07:00
cmd/compile: implement fmt.Formatter for Op formats %s, %v
Change-Id: I59e18fab37fd688fc1e578e2192e32e29fdf37f0 Reviewed-on: https://go-review.googlesource.com/28331 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
adcd34c732
commit
9e1f6a326e
@ -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{
|
||||
|
Loading…
Reference in New Issue
Block a user