@Override public void enterScope(NodeTraversal t) { if (NodeUtil.isValidCfgRoot(t.getScopeRoot())) { initScope(t.getControlFlowGraph()); } }
@Override public void enterScope(NodeTraversal t) { if (NodeUtil.isValidCfgRoot(t.getScopeRoot())) { initScope(t.getControlFlowGraph()); } }
@Override public void enterScope(NodeTraversal t) { JSType returnType = explicitReturnExpected(t.getScopeRoot()); if (returnType == null) { return; } if (fastAllPathsReturnCheck(t.getControlFlowGraph())) { return; } CheckPathsBetweenNodes<Node, ControlFlowGraph.Branch> test = new CheckPathsBetweenNodes<Node, Branch>( t.getControlFlowGraph(), t.getControlFlowGraph().getEntry(), t.getControlFlowGraph().getImplicitReturn(), IS_RETURN, GOES_THROUGH_TRUE_CONDITION_PREDICATE); if (!test.allPathsSatisfyPredicate()) { compiler.report( t.makeError(t.getScopeRoot(), MISSING_RETURN_STATEMENT, returnType.toString())); } }
@Override public void visit(NodeTraversal t, Node n, Node parent) { // Do the checks when 'n' is the block node and 'parent' is the function // node, so that getControlFlowGraph will return the graph inside // the function, rather than the graph of the enclosing scope. if (hasReturnDeclaredNullable(n) && !canReturnNull(t.getControlFlowGraph())) { String fnName = NodeUtil.getNearestFunctionName(parent); if (fnName != null && !fnName.isEmpty()) { compiler.report(t.makeError(parent, NULLABLE_RETURN_WITH_NAME, fnName)); } else { compiler.report(t.makeError(parent, NULLABLE_RETURN)); } } }
@Override public void visit(NodeTraversal t, Node n, Node parent) { // Do the checks when 'n' is the block node and 'parent' is the function // node, so that getControlFlowGraph will return the graph inside // the function, rather than the graph of the enclosing scope. if (hasReturnDeclaredNullable(n) && !canReturnNull(t.getControlFlowGraph())) { String fnName = NodeUtil.getNearestFunctionName(parent); if (fnName != null && !fnName.isEmpty()) { compiler.report(t.makeError(parent, NULLABLE_RETURN_WITH_NAME, fnName)); } else { compiler.report(t.makeError(parent, NULLABLE_RETURN)); } } }
@Override public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) { GraphNode<Node, Branch> gNode = t.getControlFlowGraph().getNode(n); if (gNode != null && gNode.getAnnotation() != GraphReachability.REACHABLE) { // Only report error when there are some line number informations. // There are synthetic nodes with no line number informations, nodes // introduce by other passes (although not likely since this pass should // be executed early) or some rhino bug. if (n.getLineno() != -1 && // Allow spurious semi-colons and spurious breaks. !n.isEmpty() && !n.isBreak()) { compiler.report(t.makeError(n, UNREACHABLE_CODE)); // From now on, we are going to assume the user fixed the error and not // give more warning related to code section reachable from this node. new GraphReachability<>(t.getControlFlowGraph()).recompute(n); // Saves time by not traversing children. return false; } } return true; }
if (fastAllPathsReturnCheck(t.getControlFlowGraph())) { return; t.getControlFlowGraph(), t.getControlFlowGraph().getEntry(), t.getControlFlowGraph().getImplicitReturn(), IS_RETURN, GOES_THROUGH_TRUE_CONDITION_PREDICATE);
@Override public void enterScope(NodeTraversal t) { ControlFlowGraph<Node> cfg = t.getControlFlowGraph(); for (DiGraphEdge<Node, Branch> s : cfg.getImplicitReturn().getInEdges()) { Node exitNode = s.getSource().getValue(); if (!exitNode.isReturn() || exitNode.getFirstChild() == null || !exitNode.getFirstChild().isThis()) { badFunctionNodes.add(t.getScopeRoot()); return; } } goodFunctionNodes.add(t.getScopeRoot()); }
@Override public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) { GraphNode<Node, Branch> gNode = t.getControlFlowGraph().getNode(n); if (gNode != null && gNode.getAnnotation() != GraphReachability.REACHABLE) { // Only report error when there are some line number informations. // There are synthetic nodes with no line number informations, nodes // introduce by other passes (although not likely since this pass should // be executed early) or some rhino bug. if (n.getLineno() != -1 && // Allow spurious semi-colons and spurious breaks. !n.isEmpty() && !n.isBreak()) { compiler.report(t.makeError(n, UNREACHABLE_CODE)); // From now on, we are going to assume the user fixed the error and not // give more warning related to code section reachable from this node. new GraphReachability<Node, Branch>( t.getControlFlowGraph()).recompute(n); // Saves time by not traversing children. return false; } } return true; }
@Override public void enterScope(NodeTraversal t) { /* * Local variables captured in scope are filtered at present. * LiveVariableAnalysis used to filter such variables. */ ControlFlowGraph<Node> cfg = t.getControlFlowGraph(); LiveVariablesAnalysis liveness = new LiveVariablesAnalysis(cfg, t.getTypedScope(), compiler); liveness.analyze(); for (TypedVar v : ((Set<TypedVar>) liveness.getEscapedLocals())) { eventfulObjectDisposed(t, v.getNode()); } }
ControlFlowGraph<Node> cfg = t.getControlFlowGraph(); liveness = new LiveVariablesAnalysis(
ControlFlowGraph<Node> cfg = t.getControlFlowGraph();
ControlFlowGraph<Node> cfg = traversal.getControlFlowGraph(); boolean hasDefaultBlock = false; for (DiGraph.DiGraphEdge<Node, ControlFlowGraph.Branch> outEdge : cfg.getOutEdges(node)) { } else if (NodeUtil.isLoopStructure(node)) { List<Node> blocks = getChildrenBlocks(node); ControlFlowGraph<Node> cfg = traversal.getControlFlowGraph(); for (DiGraph.DiGraphEdge<Node, ControlFlowGraph.Branch> outEdge : cfg.getOutEdges(node)) { if (outEdge.getValue() == ControlFlowGraph.Branch.ON_FALSE) {
@Override public void enterScope(NodeTraversal t) { Scope scope = t.getScope(); if (!shouldOptimizeScope(scope)) { return; } Preconditions.checkState(scope.isFunctionScope(), scope); ControlFlowGraph<Node> cfg = t.getControlFlowGraph(); LiveVariablesAnalysis liveness = new LiveVariablesAnalysis(cfg, scope, compiler); if (compiler.getOptions().getLanguageOut() == CompilerOptions.LanguageMode.ECMASCRIPT3) { // If the function has exactly 2 params, mark them as escaped. This is a work-around for a // bug in IE 8 and below, where it throws an exception if you write to the parameters of the // callback in a sort(). See http://blickly.github.io/closure-compiler-issues/#58 and // https://www.zachleat.com/web/array-sort/ if (NodeUtil.getFunctionParameters(scope.getRootNode()).getChildCount() == 2) { liveness.markAllParametersEscaped(); } } liveness.analyze(); UndiGraph<Var, Void> interferenceGraph = computeVariableNamesInterferenceGraph( t, cfg, (Set<Var>) liveness.getEscapedLocals()); GraphColoring<Var, Void> coloring = new GreedyGraphColoring<Var, Void>(interferenceGraph, coloringTieBreaker); coloring.color(); colorings.push(coloring); }
ControlFlowGraph<Node> cfg = t.getControlFlowGraph(); liveness = new LiveVariablesAnalysis(cfg, scope, compiler); liveness.analyze();