…lines 1–39 unchanged (39 lines)
40 private final AbstractCompiler compiler;
41 private final boolean allowDecomposition;
42 private Set<String> knownConstants = Sets.newHashSet();
43 private final boolean assumeStrictThis;
44 private final boolean assumeMinimumCapture;
45 private final Supplier<String> safeNameIdSupplier;
46 private final Supplier<String> throwawayNameSupplier =
47 new Supplier<String>() {
48 private int nextId = 0;
49 @Override
50 public String get() {
51 return String.valueOf(nextId++);
52 }
53 };
54
55 /**
56 * @param allowDecomposition Whether an effort should be made to break down
57 * expressions into simpler expressions to allow functions to be injected
58 * where they would otherwise be disallowed.
59 */
…lines 60–209 unchanged (150 lines)
210 // TODO(johnlenz): Allow 'this' references to be replaced with a
211 // global 'this' object.
212 return CanInlineResult.NO;
213 }
214
215 if (mode == InliningMode.DIRECT) {
216 return canInlineReferenceDirectly(callNode, fnNode, needAliases);
217 } else {
218 return canInlineReferenceAsStatementBlock(
219 t, callNode, fnNode, needAliases);
220 }
221 }
222
…lines 223–691 unchanged (469 lines)
692 * <pre>
693 * function foo(a) { return a + a }
694 * x = foo(i++);
695 * </pre>
696 */
697 private CanInlineResult canInlineReferenceDirectly(
698 Node callNode, Node fnNode, Set<String> namesToAlias) {
699 if (!isDirectCallNodeReplacementPossible(fnNode)) {
700 return CanInlineResult.NO;
701 }
702
703 // CALL NODE: [ NAME, ARG1, ARG2, ... ]
704 Node cArg = callNode.getFirstChild().getNext();
705
706 // Functions called via 'call' and 'apply' have a this-object as
707 // the first parameter, but this is not part of the called function's
708 // parameter list.
…lines 709–714 unchanged (6 lines)
715 cArg = cArg.getNext();
716 } else {
717 // ".apply" call should be filtered before this.
718 Preconditions.checkState(!NodeUtil.isFunctionObjectApply(callNode));
719 }
720 }
721
722 Map<String, Node> args =
723 FunctionArgumentInjector.getFunctionCallParameterMap(
724 fnNode, callNode, this.throwawayNameSupplier);
725 boolean hasArgs = !args.isEmpty();
726 if (hasArgs) {
727 // Limit the inlining
728 Set<String> allNamesToAlias = Sets.newHashSet(namesToAlias);
729 FunctionArgumentInjector.maybeAddTempsForCallArguments(
730 fnNode, args, allNamesToAlias, compiler.getCodingConvention());
731 if (!allNamesToAlias.isEmpty()) {
732 return CanInlineResult.NO;
733 }
734 }
735
736 return CanInlineResult.YES;
737 }
738
739 /**
740 * Determine if inlining the function is likely to reduce the code size.
…lines 741–927 unchanged (187 lines)