unused2: simplify debugging code
@@ -227,16 +227,12 @@ func (c *Checker) Check(prog *lint.Program, j *lint.Job) []Unused {
}
if c.Debug != nil {
- c.debugf("digraph{\n")
- c.debugf("n%d [label=\"Root\"];\n", graph.Root.id)
- for used, reasons := range graph.Root.used {
- for _, reason := range reasons {
- c.debugf("n%d -> n%d [label=%q];\n", graph.Root.id, used.id, reason)
- }
- }
- for _, node := range graph.Nodes {
+ debugNode := func(node *Node) {
+ if node.obj == nil {
+ c.debugf("n%d [label=\"Root\"];\n", node.id)
+ } else {
c.debugf("n%d [label=%q];\n", node.id, node.obj)
-
+ }
for used, reasons := range node.used {
for _, reason := range reasons {
c.debugf("n%d -> n%d [label=%q];\n", node.id, used.id, reason)
@@ -244,15 +240,13 @@ func (c *Checker) Check(prog *lint.Program, j *lint.Job) []Unused {
}
}
- graph.TypeNodes.Iterate(func(key types.Type, value interface{}) {
- node := value.(*Node)
- c.debugf("n%d [label=%q];\n", node.id, node.obj)
-
- for used, reasons := range node.used {
- for _, reason := range reasons {
- c.debugf("n%d -> n%d [label=%q];\n", node.id, used.id, reason)
- }
+ c.debugf("digraph{\n")
+ debugNode(graph.Root)
+ for _, node := range graph.Nodes {
+ debugNode(node)
}
+ graph.TypeNodes.Iterate(func(key types.Type, value interface{}) {
+ debugNode(value.(*Node))
})
c.debugf("}\n")
}
