q/src/compiler/eachFunction.go

20 lines
506 B
Go

package compiler
import (
"git.urbach.dev/cli/q/src/core"
)
// eachFunction recursively finds all the calls to other functions.
// It avoids calling the same function twice with the help of a hashmap.
func (r *Result) eachFunction(caller *core.Function, traversed map[*core.Function]bool, call func(*core.Function)) {
call(caller)
traversed[caller] = true
for function := range caller.Dependencies.All() {
if traversed[function] {
continue
}
r.eachFunction(function, traversed, call)
}
}