• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java LiveVariableLattice类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: tryRemoveDeadAssignments

import com.google.javascript.jscomp.LiveVariablesAnalysis.LiveVariableLattice; //导入依赖的package包/类
/**
 * Try to remove useless assignments from a control flow graph that has been
 * annotated with liveness information.
 *
 * @param t The node traversal.
 * @param cfg The control flow graph of the program annotated with liveness
 *        information.
 */
private void tryRemoveDeadAssignments(NodeTraversal t,
    ControlFlowGraph<Node> cfg) {
  List<DiGraphNode<Node, Branch>> nodes = cfg.getDirectedGraphNodes();

  for (DiGraphNode<Node, Branch> cfgNode : nodes) {
    FlowState<LiveVariableLattice> state =
        cfgNode.getAnnotation();
    Node n = cfgNode.getValue();
    if (n == null) {
      continue;
    }
    switch (n.getType()) {
      case Token.IF:
      case Token.WHILE:
      case Token.DO:
        tryRemoveAssignment(t, NodeUtil.getConditionExpression(n), state);
        continue;
      case Token.FOR:
        if (!NodeUtil.isForIn(n)) {
          tryRemoveAssignment(
              t, NodeUtil.getConditionExpression(n), state);
        }
        continue;
      case Token.SWITCH:
      case Token.CASE:
      case Token.RETURN:
        if (n.hasChildren()) {
          tryRemoveAssignment(t, n.getFirstChild(), state);
        }
        continue;
      // TODO(user): case Token.VAR: Remove var a=1;a=2;.....
    }
    
    tryRemoveAssignment(t, n, state);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:45,代码来源:DeadAssignmentsElimination.java


示例2: tryRemoveDeadAssignments

import com.google.javascript.jscomp.LiveVariablesAnalysis.LiveVariableLattice; //导入依赖的package包/类
/**
 * Try to remove useless assignments from a control flow graph that has been
 * annotated with liveness information.
 *
 * @param t The node traversal.
 * @param cfg The control flow graph of the program annotated with liveness
 *        information.
 */
private void tryRemoveDeadAssignments(NodeTraversal t,
    ControlFlowGraph<Node> cfg) {
  Iterable<DiGraphNode<Node, Branch>> nodes = cfg.getDirectedGraphNodes();

  for (DiGraphNode<Node, Branch> cfgNode : nodes) {
    FlowState<LiveVariableLattice> state =
        cfgNode.getAnnotation();
    Node n = cfgNode.getValue();
    if (n == null) {
      continue;
    }
    switch (n.getType()) {
      case Token.IF:
      case Token.WHILE:
      case Token.DO:
        tryRemoveAssignment(t, NodeUtil.getConditionExpression(n), state);
        continue;
      case Token.FOR:
        if (!NodeUtil.isForIn(n)) {
          tryRemoveAssignment(
              t, NodeUtil.getConditionExpression(n), state);
        }
        continue;
      case Token.SWITCH:
      case Token.CASE:
      case Token.RETURN:
        if (n.hasChildren()) {
          tryRemoveAssignment(t, n.getFirstChild(), state);
        }
        continue;
      // TODO(user): case Token.VAR: Remove var a=1;a=2;.....
    }

    tryRemoveAssignment(t, n, state);
  }
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:45,代码来源:DeadAssignmentsElimination.java


示例3: computeVariableNamesInterferenceGraph

import com.google.javascript.jscomp.LiveVariablesAnalysis.LiveVariableLattice; //导入依赖的package包/类
private UndiGraph<Var, Void> computeVariableNamesInterferenceGraph(
    NodeTraversal t, ControlFlowGraph<Node> cfg, Set<Var> escaped) {
  UndiGraph<Var, Void> interferenceGraph =
      new LinkedUndirectedGraph<Var, Void>();
  Scope scope = t.getScope();

  // First create a node for each non-escaped variable.
  for (Iterator<Var> i = scope.getVars(); i.hasNext();) {
    Var v = i.next();
    if (!escaped.contains(v)) {
      
      // TODO(user): In theory, we CAN coalesce function names just like
      // any variables. Our Liveness analysis captures this just like it as
      // described in the specification. However, we saw some zipped and
      // and unzipped size increase after this. We are not totally sure why
      // that is but, for now, we will respect the dead functions and not play
      // around with it.
      if (!NodeUtil.isFunction(v.getParentNode())) {
        interferenceGraph.createNode(v);
      }
    }
  }

  // Go through every single point of the program and look at each variable
  // pairs. If they are both live at the same time, at an edge between them.
  for (DiGraphNode<Node, Branch> cfgNode : cfg.getDirectedGraphNodes()) {
    FlowState<LiveVariableLattice> state = cfgNode.getAnnotation();
    if (cfg.isImplicitReturn(cfgNode)) {
      continue;
    }

    int varsInScope = scope.getVarCount();
    ArrayList<CombinedLiveRangeChecker> rangesToCheck =
        new ArrayList<CombinedLiveRangeChecker>(
            varsInScope * varsInScope);

    for (Iterator<Var> i1 = scope.getVars(); i1.hasNext();) {
      Var v1 = i1.next();
      for (Iterator<Var> i2 = scope.getVars(); i2.hasNext();) {
        Var v2 = i2.next();

        if (v1 == v2 || !interferenceGraph.hasNode(v1) ||
            !interferenceGraph.hasNode(v2)) {
          // Skip nodes that were not added. They are globals and escaped
          // locals. Also avoid merging a variable with itself.
          continue;
        }

        boolean v1OutLive = state.getOut().isLive(v1);
        boolean v2OutLive = state.getOut().isLive(v2);
        // Finally, check the live states and add edge when possible.
        if (v1.getParentNode().getType() == Token.LP &&
            v2.getParentNode().getType() == Token.LP) {
          interferenceGraph.connectIfNotFound(v1, null, v2);
        } else if ((state.getIn().isLive(v1) && state.getIn().isLive(v2)) ||
            (v1OutLive && v2OutLive)) {
          interferenceGraph.connectIfNotFound(v1, null, v2);
        } else {
          LiveRangeChecker checker1 =
              new LiveRangeChecker(v1, v2OutLive ? null : v2);
          LiveRangeChecker checker2 =
              new LiveRangeChecker(v2, v1OutLive ? null : v1);
          rangesToCheck.add(new CombinedLiveRangeChecker(checker1, checker2));
        }
      }
    }

    // Do the collected live range checks.
    checkRanges(rangesToCheck, cfgNode.getValue());
    for (CombinedLiveRangeChecker range : rangesToCheck) {
      range.connectIfCrossed(interferenceGraph);
    }
  }
  return interferenceGraph;
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:76,代码来源:CoalesceVariableNames.java


示例4: tryRemoveAssignment

import com.google.javascript.jscomp.LiveVariablesAnalysis.LiveVariableLattice; //导入依赖的package包/类
private void tryRemoveAssignment(NodeTraversal t, Node n,
    FlowState<LiveVariableLattice> state) {
  tryRemoveAssignment(t, n, n, state);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:5,代码来源:DeadAssignmentsElimination.java


示例5: computeVariableNamesInterferenceGraph

import com.google.javascript.jscomp.LiveVariablesAnalysis.LiveVariableLattice; //导入依赖的package包/类
private UndiGraph<Var, Void> computeVariableNamesInterferenceGraph(
    NodeTraversal t, ControlFlowGraph<Node> cfg, Set<Var> escaped) {
  UndiGraph<Var, Void> interferenceGraph =
      new LinkedUndirectedGraph<Var, Void>();
  Scope scope = t.getScope();

  // First create a node for each non-escaped variable.
  for (Iterator<Var> i = scope.getVars(); i.hasNext();) {
    Var v = i.next();
    if (!escaped.contains(v)) {

      // TODO(user): In theory, we CAN coalesce function names just like
      // any variables. Our Liveness analysis captures this just like it as
      // described in the specification. However, we saw some zipped and
      // and unzipped size increase after this. We are not totally sure why
      // that is but, for now, we will respect the dead functions and not play
      // around with it.
      if (!NodeUtil.isFunction(v.getParentNode())) {
        interferenceGraph.createNode(v);
      }
    }
  }

  // Go through every single point of the program and look at each variable
  // pairs. If they are both live at the same time, at an edge between them.
  for (DiGraphNode<Node, Branch> cfgNode : cfg.getDirectedGraphNodes()) {
    FlowState<LiveVariableLattice> state = cfgNode.getAnnotation();
    if (cfg.isImplicitReturn(cfgNode)) {
      continue;
    }

    int varsInScope = scope.getVarCount();
    ArrayList<CombinedLiveRangeChecker> rangesToCheck =
        new ArrayList<CombinedLiveRangeChecker>(
            varsInScope * varsInScope);

    for (Iterator<Var> i1 = scope.getVars(); i1.hasNext();) {
      Var v1 = i1.next();
      for (Iterator<Var> i2 = scope.getVars(); i2.hasNext();) {
        Var v2 = i2.next();

        if (v1 == v2 || !interferenceGraph.hasNode(v1) ||
            !interferenceGraph.hasNode(v2)) {
          // Skip nodes that were not added. They are globals and escaped
          // locals. Also avoid merging a variable with itself.
          continue;
        }

        boolean v1OutLive = state.getOut().isLive(v1);
        boolean v2OutLive = state.getOut().isLive(v2);
        // Finally, check the live states and add edge when possible.
        if (v1.getParentNode().getType() == Token.LP &&
            v2.getParentNode().getType() == Token.LP) {
          interferenceGraph.connectIfNotFound(v1, null, v2);
        } else if ((state.getIn().isLive(v1) && state.getIn().isLive(v2)) ||
            (v1OutLive && v2OutLive)) {
          interferenceGraph.connectIfNotFound(v1, null, v2);
        } else {
          LiveRangeChecker checker1 =
              new LiveRangeChecker(v1, v2OutLive ? null : v2);
          LiveRangeChecker checker2 =
              new LiveRangeChecker(v2, v1OutLive ? null : v1);
          rangesToCheck.add(new CombinedLiveRangeChecker(checker1, checker2));
        }
      }
    }

    // Do the collected live range checks.
    checkRanges(rangesToCheck, cfgNode.getValue());
    for (CombinedLiveRangeChecker range : rangesToCheck) {
      range.connectIfCrossed(interferenceGraph);
    }
  }
  return interferenceGraph;
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:76,代码来源:CoalesceVariableNames.java


示例6: tryRemoveDeadAssignments

import com.google.javascript.jscomp.LiveVariablesAnalysis.LiveVariableLattice; //导入依赖的package包/类
/**
 * Try to remove useless assignments from a control flow graph that has been
 * annotated with liveness information.
 *
 * @param t The node traversal.
 * @param cfg The control flow graph of the program annotated with liveness
 *        information.
 */
private void tryRemoveDeadAssignments(NodeTraversal t,
    ControlFlowGraph<Node> cfg,
    Map<String, Var> allVarsInFn) {
  Iterable<DiGraphNode<Node, Branch>> nodes = cfg.getDirectedGraphNodes();

  for (DiGraphNode<Node, Branch> cfgNode : nodes) {
    FlowState<LiveVariableLattice> state =
        cfgNode.getAnnotation();
    Node n = cfgNode.getValue();
    if (n == null) {
      continue;
    }
    switch (n.getToken()) {
      case IF:
      case WHILE:
      case DO:
        tryRemoveAssignment(t, NodeUtil.getConditionExpression(n), state, allVarsInFn);
        continue;
      case FOR:
      case FOR_IN:
      case FOR_OF:
        if (n.isVanillaFor()) {
          tryRemoveAssignment(t, NodeUtil.getConditionExpression(n), state, allVarsInFn);
        }
        continue;
      case SWITCH:
      case CASE:
      case RETURN:
        if (n.hasChildren()) {
          tryRemoveAssignment(t, n.getFirstChild(), state, allVarsInFn);
        }
        continue;
        // TODO(user): case VAR: Remove var a=1;a=2;.....
      default:
        break;
    }

    tryRemoveAssignment(t, n, state, allVarsInFn);
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:49,代码来源:DeadAssignmentsElimination.java


示例7: tryRemoveAssignment

import com.google.javascript.jscomp.LiveVariablesAnalysis.LiveVariableLattice; //导入依赖的package包/类
private void tryRemoveAssignment(NodeTraversal t, Node n,
    FlowState<LiveVariableLattice> state, Map<String, Var> allVarsInFn) {
  tryRemoveAssignment(t, n, n, state, allVarsInFn);
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:5,代码来源:DeadAssignmentsElimination.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FileUtils类代码示例发布时间:2022-05-22
下一篇:
Java AbstractCheckedFuture类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap