2019-04-09 11:52:21 -04:00
|
|
|
package ast
|
2019-06-11 12:38:22 -04:00
|
|
|
|
2019-06-04 00:14:04 -04:00
|
|
|
/*
|
2019-04-09 11:52:21 -04:00
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GetAllNodesOfType returns all of the nodes of the tree that match the type
|
|
|
|
// provided. The type should be a pointer to an object in the ast package.
|
|
|
|
//
|
|
|
|
// The nodes returned may reference each other and there is no guaranteed order
|
|
|
|
// in which the nodes are returned.
|
|
|
|
func GetAllNodesOfType(root Node, t reflect.Type) []Node {
|
|
|
|
nodes := []Node{}
|
|
|
|
|
|
|
|
if root == nil {
|
|
|
|
return []Node{}
|
|
|
|
}
|
|
|
|
|
|
|
|
if reflect.TypeOf(root) == t {
|
|
|
|
nodes = append(nodes, root)
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range root.Children() {
|
|
|
|
nodes = append(nodes, GetAllNodesOfType(c, t)...)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nodes
|
2019-06-04 00:14:04 -04:00
|
|
|
}*/
|