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:
parent
8dabab4124
commit
b75a5a4b65
18
ssa/const.go
18
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 {
|
||||
|
|
|
|||
16
ssa/print.go
16
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()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue