go.tools/ssa: skip redundant identifier qualification in package dump.

(Reduces ssadump -build=P verbosity by 25%.)

R=gri
CC=golang-codereviews
https://golang.org/cl/52730044
This commit is contained in:
Alan Donovan 2014-01-15 13:51:50 -05:00
parent 8dabab4124
commit b75a5a4b65
2 changed files with 20 additions and 14 deletions

View File

@ -66,27 +66,29 @@ func zeroConst(t types.Type) *Const {
panic(fmt.Sprint("zeroConst: unexpected ", t)) 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 { if c.Value == nil {
return "nil" s = "nil"
} else if c.Value.Kind() == exact.String { } else if c.Value.Kind() == exact.String {
s := exact.StringVal(c.Value) s = exact.StringVal(c.Value)
const max = 20 const max = 20
if len(s) > max { if len(s) > max {
s = s[:max-3] + "..." // abbreviate s = s[:max-3] + "..." // abbreviate
} }
return strconv.Quote(s) s = strconv.Quote(s)
} else { } else {
return c.Value.String() s = c.Value.String()
} }
return s + ":" + relType(c.Type(), from)
} }
func (c *Const) Name() string { func (c *Const) Name() string {
return fmt.Sprintf("%s:%s", c.valstring(), c.typ) return c.RelString(nil)
} }
func (v *Const) String() string { func (c *Const) String() string {
return v.Name() return c.Name()
} }
func (c *Const) Type() types.Type { func (c *Const) Type() types.Type {

View File

@ -32,7 +32,7 @@ func relName(v Value, i Instruction) string {
case Member: // *Function or *Global case Member: // *Function or *Global
return v.RelString(from) return v.RelString(from)
case *Const: case *Const:
return v.valstring() + ":" + relType(v.Type(), from) return v.RelString(from)
} }
return v.Name() return v.Name()
} }
@ -380,19 +380,23 @@ func (p *Package) DumpTo(w io.Writer) {
for _, name := range names { for _, name := range names {
switch mem := p.Members[name].(type) { switch mem := p.Members[name].(type) {
case *NamedConst: 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: 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: 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()) { for _, meth := range IntuitiveMethodSet(mem.Type()) {
fmt.Fprintf(w, " %s\n", meth) fmt.Fprintf(w, " %s\n", types.SelectionString(p.Object, meth))
} }
case *Global: 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()))
} }
} }