Class VariableDependenciesVisitor

java.lang.Object
org.rumbledb.expressions.AbstractNodeVisitor<Void>
org.rumbledb.compiler.VariableDependenciesVisitor

public class VariableDependenciesVisitor extends AbstractNodeVisitor<Void>
This visitor resolves dependencies between variable and function declarations. If a variable $x depends on a variable $y, then $y must be evaluated before $x. Example: declare variable $y := 1; declare variable $x := $y; If a variable $x depends on a function f, then f's closure must be built before $x is evaluated. declare function f() { 1 }; declare variable $x := f(); If a function f depends on a variable $x, then $x must be evaluated before f's closure is built. declare variable $x := 1; declare function f() { $x }; Note that a function cannot depend on a function, as mutually recursive calls are allowed. Once all dependencies have been determined, the visitor builds a DAG, builds a topological ordering thereof, and re-sorts declarations in the prolog for further processing by other visitors.