func (self *AST_Visitor) getlabel(n ast.Node) *tree.Node { node_type := reflect.TypeOf(n).String() name := node_type[5:] if f, ok := visitors[name]; ok { return f(name, n) } else if f, ok := visitors[node_type]; ok { return f(node_type, n) } else { return tree.NewNode(name) } panic("unreachable") }
func New() *AST_Visitor { v := new(AST_Visitor) v.parent = tree.NewNode("dummy") return v }
name := node_type[5:] if f, ok := visitors[name]; ok { return f(name, n) } else if f, ok := visitors[node_type]; ok { return f(node_type, n) } else { return tree.NewNode(name) } panic("unreachable") } var visitors = map[string]func(string, ast.Node) *tree.Node{ "Ident": func(name string, n ast.Node) *tree.Node { m := n.(*ast.Ident) p := tree.NewNode(name).AddKid(tree.NewNode(m.Name)) if m.IsExported() { p.AddKid(tree.NewNode("Exported")) } return p }, "BasicLit": func(name string, n ast.Node) *tree.Node { m := n.(*ast.BasicLit) parent := tree.NewNode(name) parent. AddKid(tree.NewNode(fmt.Sprint(m.Kind))). AddKid(tree.NewNode(m.Value)) return parent },