Exemple #1
0
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")
}
Exemple #2
0
func New() *AST_Visitor {
	v := new(AST_Visitor)
	v.parent = tree.NewNode("dummy")
	return v
}
Exemple #3
0
	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
	},