/** * Gets the must reaching definition of a given node. The node must be one of the control flow * graph nodes. * * @param name name of the variable. It can only be names of local variable that are not function * parameters, escaped variables or variables declared in catch. * @param useNode the location of the use where the definition reaches. */ Node getDef(String name, Node useNode) { Preconditions.checkArgument(getCfg().hasNode(useNode)); GraphNode<Node, Branch> n = getCfg().getNode(useNode); FlowState<MustDef> state = n.getAnnotation(); Definition def = state.getIn().reachingDef.get(jsScope.getVar(name)); if (def == null) { return null; } else { return def.node; } }
boolean dependsOnOuterScopeVars(String name, Node useNode) { Preconditions.checkArgument(getCfg().hasNode(useNode)); GraphNode<Node, Branch> n = getCfg().getNode(useNode); FlowState<MustDef> state = n.getAnnotation(); Definition def = state.getIn().reachingDef.get(jsScope.getVar(name)); for (Var s : def.depends) { if (s.scope != jsScope) { return true; } } return false; }