当前位置: 首页>>代码示例>>Java>>正文


Java InliningMode类代码示例

本文整理汇总了Java中com.google.javascript.jscomp.FunctionInjector.InliningMode的典型用法代码示例。如果您正苦于以下问题:Java InliningMode类的具体用法?Java InliningMode怎么用?Java InliningMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


InliningMode类属于com.google.javascript.jscomp.FunctionInjector包,在下文中一共展示了InliningMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: maybeAddReference

import com.google.javascript.jscomp.FunctionInjector.InliningMode; //导入依赖的package包/类
void maybeAddReference(NodeTraversal t, FunctionState fs,
    Node callNode, JSModule module) {
  if (!fs.canInline()) {
    return;
  }

  boolean referenceAdded = false;
  InliningMode mode = fs.canInlineDirectly()
       ? InliningMode.DIRECT : InliningMode.BLOCK;
  referenceAdded = maybeAddReferenceUsingMode(
      t, fs, callNode, module, mode);
  if (!referenceAdded &&
      mode == InliningMode.DIRECT && blockFunctionInliningEnabled) {
    // This reference can not be directly inlined, see if
    // block replacement inlining is possible.
    mode = InliningMode.BLOCK;
    referenceAdded = maybeAddReferenceUsingMode(
        t, fs, callNode, module, mode);
  }

  if (!referenceAdded) {
    // Don't try to remove a function if we can't inline all
    // the references.
    fs.setRemove(false);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:27,代码来源:InlineFunctions.java

示例2: maybeAddReferenceUsingMode

import com.google.javascript.jscomp.FunctionInjector.InliningMode; //导入依赖的package包/类
private boolean maybeAddReferenceUsingMode(
    NodeTraversal t, FunctionState fs, Node callNode,
    JSModule module, InliningMode mode) {
  CanInlineResult result = injector.canInlineReferenceToFunction(
      t, callNode, fs.getFn().getFunctionNode(),
      fs.getNamesToAlias(), mode, fs.getReferencesThis());
  if (result != CanInlineResult.NO) {
    // Yeah!
    boolean decompose =
      (result == CanInlineResult.AFTER_DECOMPOSITION);
    fs.addReference(new Reference(callNode, module, mode, decompose));
    return true;
  }

  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:17,代码来源:InlineFunctions.java

示例3: maybeAddReference

import com.google.javascript.jscomp.FunctionInjector.InliningMode; //导入依赖的package包/类
void maybeAddReference(NodeTraversal t, FunctionState functionState,
    Node callNode, JSModule module) {
  if (!functionState.canInline()) {
    return;
  }

  InliningMode mode = functionState.canInlineDirectly()
      ? InliningMode.DIRECT : InliningMode.BLOCK;
  boolean referenceAdded = maybeAddReferenceUsingMode(t, functionState, callNode, module, mode);
  if (!referenceAdded && mode == InliningMode.DIRECT) {
    // This reference can not be directly inlined, see if
    // block replacement inlining is possible.
    mode = InliningMode.BLOCK;
    referenceAdded = maybeAddReferenceUsingMode(t, functionState, callNode, module, mode);
  }

  if (!referenceAdded) {
    // Don't try to remove a function if we can't inline all
    // the references.
    functionState.setRemove(false);
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:23,代码来源:InlineFunctions.java

示例4: inlineFunction

import com.google.javascript.jscomp.FunctionInjector.InliningMode; //导入依赖的package包/类
/**
 * Inline a function into the call site.
 */
private void inlineFunction(
    NodeTraversal t, Node callNode, FunctionState fs, InliningMode mode) {
  Function fn = fs.getFn();
  String fnName = fn.getName();
  Node fnNode = fs.getSafeFnNode();

  Node newCode = injector.inline(t, callNode, fnName, fnNode, mode);
  t.getCompiler().reportCodeChange();
  t.getCompiler().addToDebugLog("Inlined function: " + fn.getName());
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:14,代码来源:InlineFunctions.java

示例5: removeBlockInliningReferences

import com.google.javascript.jscomp.FunctionInjector.InliningMode; //导入依赖的package包/类
void removeBlockInliningReferences() {
  Iterator<Entry<Node, Reference>> i;
  for (i = getReferencesInternal().entrySet().iterator(); i.hasNext();) {
    Entry<Node, Reference> entry = i.next();
    if (entry.getValue().mode == InliningMode.BLOCK) {
      i.remove();
    }
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:10,代码来源:InlineFunctions.java

示例6: hasBlockInliningReferences

import com.google.javascript.jscomp.FunctionInjector.InliningMode; //导入依赖的package包/类
public boolean hasBlockInliningReferences() {
  for (Reference r : getReferencesInternal().values()) {
    if (r.mode == InliningMode.BLOCK) {
      return true;
    }
  }
  return false;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:9,代码来源:InlineFunctions.java

示例7: helperCanInlineReferenceToFunction

import com.google.javascript.jscomp.FunctionInjector.InliningMode; //导入依赖的package包/类
public void helperCanInlineReferenceToFunction(
    final CanInlineResult expectedResult,
    final String code,
    final String fnName,
    final InliningMode mode,
    boolean allowDecomposition
    ) {
  final Compiler compiler = new Compiler();
  final FunctionInjector injector = new FunctionInjector(
      compiler, compiler.getUniqueNameIdSupplier(), allowDecomposition);
  final Node tree = parse(compiler, code);

  Node externsRoot = new Node(Token.EMPTY);
  Node mainRoot = tree;

  final Node fnNode = findFunction(tree, fnName);
  final Set<String> unsafe =
      FunctionArgumentInjector.findModifiedParameters(fnNode);

  // can-inline tester
  Method tester = new Method() {
    public boolean call(NodeTraversal t, Node n, Node parent) {
      CanInlineResult result = injector.canInlineReferenceToFunction(
          t, n, fnNode, unsafe, mode, NodeUtil.referencesThis(fnNode));
      assertEquals(expectedResult, result);
      return true;
    }
  };

  compiler.resetUniqueNameId();
  TestCallback test = new TestCallback(fnName, tester);
  NodeTraversal.traverse(compiler, tree, test);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:34,代码来源:FunctionInjectorTest.java

示例8: maybeAddReferenceUsingMode

import com.google.javascript.jscomp.FunctionInjector.InliningMode; //导入依赖的package包/类
private boolean maybeAddReferenceUsingMode(
    NodeTraversal t, FunctionState fs, Node callNode,
    JSModule module, InliningMode mode) {

  if (specializationState != null) {
    // If we're specializing, make sure we can fixup
    // the containing function before inlining
    Node containingFunction = getContainingFunction(t);
    if (containingFunction != null && !specializationState.canFixupFunction(
        containingFunction)) {
        return false;
    }
  }

  CanInlineResult result = injector.canInlineReferenceToFunction(
      t, callNode, fs.getFn().getFunctionNode(),
      fs.getNamesToAlias(), mode, fs.getReferencesThis(),
      fs.hasInnerFunctions());
  if (result != CanInlineResult.NO) {
    // Yeah!
    boolean decompose =
      (result == CanInlineResult.AFTER_DECOMPOSITION);
    fs.addReference(new Reference(callNode, module, mode, decompose));
    return true;
  }

  return false;
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:29,代码来源:InlineFunctions.java

示例9: helperCanInlineReferenceToFunction

import com.google.javascript.jscomp.FunctionInjector.InliningMode; //导入依赖的package包/类
public void helperCanInlineReferenceToFunction(
    final CanInlineResult expectedResult,
    final String code,
    final String fnName,
    final InliningMode mode,
    boolean allowDecomposition
    ) {
  final Compiler compiler = new Compiler();
  final FunctionInjector injector = new FunctionInjector(
      compiler, compiler.getUniqueNameIdSupplier(), allowDecomposition);
  final Node tree = parse(compiler, code);

  Node externsRoot = new Node(Token.EMPTY);
  Node mainRoot = tree;

  final Node fnNode = findFunction(tree, fnName);
  final Set<String> unsafe =
      FunctionArgumentInjector.findModifiedParameters(fnNode);

  // can-inline tester
  Method tester = new Method() {
    public boolean call(NodeTraversal t, Node n, Node parent) {
      CanInlineResult result = injector.canInlineReferenceToFunction(
          t, n, fnNode, unsafe, mode,
          NodeUtil.referencesThis(fnNode),
          NodeUtil.containsFunction(NodeUtil.getFunctionBody(fnNode)));
      assertEquals(expectedResult, result);
      return true;
    }
  };

  compiler.resetUniqueNameId();
  TestCallback test = new TestCallback(fnName, tester);
  NodeTraversal.traverse(compiler, tree, test);
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:36,代码来源:FunctionInjectorTest.java

示例10: maybeAddReferenceUsingMode

import com.google.javascript.jscomp.FunctionInjector.InliningMode; //导入依赖的package包/类
private boolean maybeAddReferenceUsingMode(
    NodeTraversal t, FunctionState fs, Node callNode,
    JSModule module, InliningMode mode) {

  if (specializationState != null) {
    // If we're specializing, make sure we can fixup
    // the containing function before inlining
    Node containingFunction = getContainingFunction(t);
    if (containingFunction != null && !specializationState.canFixupFunction(
        containingFunction)) {
        return false;
    }
  }

  CanInlineResult result = injector.canInlineReferenceToFunction(
      t, callNode, fs.getFn().getFunctionNode(),
      fs.getNamesToAlias(), mode, fs.getReferencesThis(),
      fs.hasInnerFunctions());
  if (result != CanInlineResult.NO) {
    // Yeah!
    boolean decompose =
      (result == CanInlineResult.AFTER_PREPARATION);
    fs.addReference(new Reference(callNode, module, mode, decompose));
    return true;
  }

  return false;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:29,代码来源:InlineFunctions.java

示例11: helperCanInlineReferenceToFunction

import com.google.javascript.jscomp.FunctionInjector.InliningMode; //导入依赖的package包/类
public void helperCanInlineReferenceToFunction(
    final CanInlineResult expectedResult,
    final String code,
    final String fnName,
    final InliningMode mode,
    boolean allowDecomposition) {
  final Compiler compiler = new Compiler();
  final FunctionInjector injector = new FunctionInjector(
      compiler, compiler.getUniqueNameIdSupplier(), allowDecomposition,
      assumeStrictThis,
      assumeMinimumCapture);
  final Node tree = parse(compiler, code);

  Node externsRoot = new Node(Token.EMPTY);
  Node mainRoot = tree;

  final Node fnNode = findFunction(tree, fnName);
  final Set<String> unsafe =
      FunctionArgumentInjector.findModifiedParameters(fnNode);

  // can-inline tester
  Method tester = new Method() {
    @Override
    public boolean call(NodeTraversal t, Node n, Node parent) {
      CanInlineResult result = injector.canInlineReferenceToFunction(
          t, n, fnNode, unsafe, mode,
          NodeUtil.referencesThis(fnNode),
          NodeUtil.containsFunction(NodeUtil.getFunctionBody(fnNode)));
      assertEquals(expectedResult, result);
      return true;
    }
  };

  compiler.resetUniqueNameId();
  TestCallback test = new TestCallback(fnName, tester);
  NodeTraversal.traverse(compiler, tree, test);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:38,代码来源:FunctionInjectorTest.java

示例12: maybeAddReferenceUsingMode

import com.google.javascript.jscomp.FunctionInjector.InliningMode; //导入依赖的package包/类
private boolean maybeAddReferenceUsingMode(
    NodeTraversal t, FunctionState functionState, Node callNode,
    JSModule module, InliningMode mode) {

  // If many functions are inlined into the same function F in the same
  // inlining round, then the size of F may exceed the max size.
  // This could be avoided if we bail later, during the inlining phase, eg,
  // in Inline#visitCallSite. However, that is not safe, because at that
  // point expression decomposition has already run, and we want to
  // decompose expressions only for the calls that are actually inlined.
  if (enforceMaxSizeAfterInlining && targetSizeAfterInlineExceedsLimit(t, functionState)) {
    return false;
  }

  Reference candidate = new Reference(callNode, t.getScope(), module, mode);
  CanInlineResult result =
      injector.canInlineReferenceToFunction(
          candidate,
          functionState.getFn().getFunctionNode(),
          functionState.getNamesToAlias(),
          functionState.getReferencesThis(),
          functionState.hasInnerFunctions());
  if (result != CanInlineResult.NO) {
    // Yeah!
    candidate.setRequiresDecomposition(result == CanInlineResult.AFTER_PREPARATION);
    functionState.addReference(candidate);
    return true;
  }

  return false;
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:32,代码来源:InlineFunctions.java

示例13: removeBlockInliningReferences

import com.google.javascript.jscomp.FunctionInjector.InliningMode; //导入依赖的package包/类
void removeBlockInliningReferences() {
  Iterator<Entry<Node, Reference>> i;
  for (i = getReferencesInternal().entrySet().iterator(); i.hasNext(); ) {
    Entry<Node, Reference> entry = i.next();
    if (entry.getValue().mode == InliningMode.BLOCK) {
      i.remove();
    }
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:10,代码来源:InlineFunctions.java

示例14: ClassStaticFunctionsInliner

import com.google.javascript.jscomp.FunctionInjector.InliningMode; //导入依赖的package包/类
private ClassStaticFunctionsInliner(
    Node root, String classFileName, Set<String> fnNamesToInline, InliningMode inliningMode) {
  this.root = root;
  this.classFileName = classFileName;
  this.fnNamesToInline = fnNamesToInline;
  this.inliningMode = inliningMode;

  this.injector = new FunctionInjector(compiler, safeNameIdSupplier, true, true, true);
  this.injector.setKnownConstants(fnNamesToInline);
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:11,代码来源:J2clPass.java

示例15: helperCanInlineReferenceToFunction

import com.google.javascript.jscomp.FunctionInjector.InliningMode; //导入依赖的package包/类
/**
 * Test case
 *
 * var a = {}, b = {}
 * a.test = "a", b.test = "b"
 * c = a;
 * foo() { c=b; return "a" }
 * c.teste
 *
 */

public void helperCanInlineReferenceToFunction(
    final CanInlineResult expectedResult,
    final String code,
    final String fnName,
    final InliningMode mode) {
  final Compiler compiler = new Compiler();
  final FunctionInjector injector = new FunctionInjector(
      compiler, compiler.getUniqueNameIdSupplier(), allowDecomposition,
      assumeStrictThis,
      assumeMinimumCapture);
  final Node tree = parse(compiler, code);

  final Node fnNode = findFunction(tree, fnName);
  final ImmutableSet<String> unsafe =
      ImmutableSet.copyOf(FunctionArgumentInjector.findModifiedParameters(fnNode));

  // can-inline tester
  Method tester = new Method() {
    @Override
    public boolean call(NodeTraversal t, Node n, Node parent) {
      Reference ref = new Reference(n, t.getScope(), t.getModule(), mode);
      CanInlineResult result = injector.canInlineReferenceToFunction(
          ref, fnNode, unsafe,
          NodeUtil.referencesThis(fnNode),
          NodeUtil.containsFunction(NodeUtil.getFunctionBody(fnNode)));
      assertEquals(expectedResult, result);
      return true;
    }
  };

  compiler.resetUniqueNameId();
  TestCallback test = new TestCallback(fnName, tester);
  NodeTraversal.traverseEs6(compiler, tree, test);
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:46,代码来源:FunctionInjectorTest.java


注:本文中的com.google.javascript.jscomp.FunctionInjector.InliningMode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。