@Override public void process(Node externs, Node root) { Preconditions.checkState(compiler.getLifeCycleStage().isNormalized()); NodeTraversal.traverseEs6(compiler, root, new FindCandidateFunctions()); if (fns.isEmpty()) { return; // Nothing left to do. } NodeTraversal.traverseEs6(compiler, root, new FindCandidatesReferences(fns, anonFns)); trimCandidatesNotMeetingMinimumRequirements(); if (fns.isEmpty()) { return; // Nothing left to do. } // Store the set of function names eligible for inlining and use this to // prevent function names from being moved into temporaries during // expression decomposition. If this movement were allowed it would prevent // the Inline callback from finding the function calls. // // This pass already assumes these are constants, so this is safe for anyone // using function inlining. // Set<String> fnNames = new HashSet<>(fns.keySet()); injector.setKnownConstants(fnNames); trimCandidatesUsingOnCost(); if (fns.isEmpty()) { return; // Nothing left to do. } resolveInlineConflicts(); decomposeExpressions(); NodeTraversal.traverseEs6(compiler, root, new CallVisitor(fns, anonFns, new Inline(injector))); removeInlinedFunctions(); }
/** Inline a function into the call site. */ Node inline(NodeTraversal t, Node callNode, String fnName, Node fnNode, InliningMode mode) { Preconditions.checkState(compiler.getLifeCycleStage().isNormalized()); if (mode == InliningMode.DIRECT) { return inlineReturnValue(callNode, fnNode); } else { return inlineFunction(callNode, fnNode, fnName); } }
/** * Traverses the root, removing all unused variables. Multiple traversals may occur to ensure all * unused variables are removed. */ public void process(Node externs, Node root) { Preconditions.checkState(compiler.getLifeCycleStage().isNormalized()); SimpleDefinitionFinder defFinder = null; if (modifyCallSites) { // For testing, allow the SimpleDefinitionFinder to be build now. defFinder = new SimpleDefinitionFinder(compiler); defFinder.process(externs, root); } process(externs, root, defFinder); }