diff --git a/ssa/const.go b/ssa/const.go index 4b84be8c..bb1eb25f 100644 --- a/ssa/const.go +++ b/ssa/const.go @@ -66,27 +66,29 @@ func zeroConst(t types.Type) *Const { panic(fmt.Sprint("zeroConst: unexpected ", t)) } -func (c *Const) valstring() string { +func (c *Const) RelString(from *types.Package) string { + var s string if c.Value == nil { - return "nil" + s = "nil" } else if c.Value.Kind() == exact.String { - s := exact.StringVal(c.Value) + s = exact.StringVal(c.Value) const max = 20 if len(s) > max { s = s[:max-3] + "..." // abbreviate } - return strconv.Quote(s) + s = strconv.Quote(s) } else { - return c.Value.String() + s = c.Value.String() } + return s + ":" + relType(c.Type(), from) } func (c *Const) Name() string { - return fmt.Sprintf("%s:%s", c.valstring(), c.typ) + return c.RelString(nil) } -func (v *Const) String() string { - return v.Name() +func (c *Const) String() string { + return c.Name() } func (c *Const) Type() types.Type { diff --git a/ssa/print.go b/ssa/print.go index a64f9c93..2484baf3 100644 --- a/ssa/print.go +++ b/ssa/print.go @@ -32,7 +32,7 @@ func relName(v Value, i Instruction) string { case Member: // *Function or *Global return v.RelString(from) case *Const: - return v.valstring() + ":" + relType(v.Type(), from) + return v.RelString(from) } return v.Name() } @@ -380,19 +380,23 @@ func (p *Package) DumpTo(w io.Writer) { for _, name := range names { switch mem := p.Members[name].(type) { case *NamedConst: - fmt.Fprintf(w, " const %-*s %s = %s\n", maxname, name, mem.Name(), mem.Value.Name()) + fmt.Fprintf(w, " const %-*s %s = %s\n", + maxname, name, mem.Name(), mem.Value.RelString(p.Object)) case *Function: - fmt.Fprintf(w, " func %-*s %s\n", maxname, name, mem.Type()) + fmt.Fprintf(w, " func %-*s %s\n", + maxname, name, types.TypeString(p.Object, mem.Type())) case *Type: - fmt.Fprintf(w, " type %-*s %s\n", maxname, name, mem.Type().Underlying()) + fmt.Fprintf(w, " type %-*s %s\n", + maxname, name, types.TypeString(p.Object, mem.Type().Underlying())) for _, meth := range IntuitiveMethodSet(mem.Type()) { - fmt.Fprintf(w, " %s\n", meth) + fmt.Fprintf(w, " %s\n", types.SelectionString(p.Object, meth)) } case *Global: - fmt.Fprintf(w, " var %-*s %s\n", maxname, name, mem.Type().(*types.Pointer).Elem()) + fmt.Fprintf(w, " var %-*s %s\n", + maxname, name, types.TypeString(p.Object, mem.Type().(*types.Pointer).Elem())) } }