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

Java TernaryValue类代码示例

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

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



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

示例1: apply

import com.google.javascript.rhino.jstype.TernaryValue; //导入依赖的package包/类
@Override
public boolean apply(EdgeTuple<Node, Branch> input) {
  Branch branch = input.edge;
  if (!branch.isConditional()) {
    return true;
  }
  Node predecessor = input.sourceNode;
  Node condition = NodeUtil.getConditionExpression(predecessor);

  // TODO(user): Handle more complicated expression like true == true,
  // etc....
  if (condition != null) {
    TernaryValue val = NodeUtil.getBooleanValue(condition);
    if (val != TernaryValue.UNKNOWN) {
      return val.toBoolean(true) == (branch == Branch.ON_TRUE);
    }
  }
  return true;
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:20,代码来源:CheckUnreachableCode.java


示例2: tryFoldDo

import com.google.javascript.rhino.jstype.TernaryValue; //导入依赖的package包/类
/**
 * Removes DOs that always evaluate to false. This leaves the
 * statements that were in the loop in a BLOCK node.
 * The block will be removed in a later pass, if possible.
 */
Node tryFoldDo(Node n) {
  Preconditions.checkArgument(n.getType() == Token.DO);

  Node cond = NodeUtil.getConditionExpression(n);
  if (NodeUtil.getBooleanValue(cond) != TernaryValue.FALSE) {
    return n;
  }

  // TODO(johnlenz): The do-while can be turned into a label with
  // named breaks and the label optimized away (maybe).
  if (hasBreakOrContinue(n)) {
    return n;
  }

  Preconditions.checkState(
      NodeUtil.isControlStructureCodeBlock(n, n.getFirstChild()));
  Node block = n.removeFirstChild();

  n.getParent().replaceChild(n, block);
  reportCodeChange();

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


示例3: apply

import com.google.javascript.rhino.jstype.TernaryValue; //导入依赖的package包/类
public boolean apply(DiGraphEdge<Node, ControlFlowGraph.Branch> input) {
  // First skill all exceptions.
  Branch branch = input.getValue();
  if (branch == Branch.ON_EX) {
    return false;
  } else if (branch.isConditional()) {
    Node condition = NodeUtil.getConditionExpression(
        input.getSource().getValue());
    // TODO(user): We CAN make this bit smarter just looking at
    // constants. We DO have a full blown ReverseAbstractInterupter and
    // type system that can evaluate some impressions' boolean value but
    // for now we will keep this pass lightweight.
    if (condition != null) {
      TernaryValue val = NodeUtil.getBooleanValue(condition);
      if (val != TernaryValue.UNKNOWN) {
        return val.toBoolean(true) == (Branch.ON_TRUE == branch);
      }
    }
  }
  return true;
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:22,代码来源:CheckMissingReturn.java


示例4: isStrWhiteSpaceChar

import com.google.javascript.rhino.jstype.TernaryValue; //导入依赖的package包/类
/**
 * Copied from Rhino's ScriptRuntime
 */
public static TernaryValue isStrWhiteSpaceChar(int c) {
  switch (c) {
    case '\u000B': // <VT>
      return TernaryValue.UNKNOWN;  // IE says "no", ECMAScript says "yes"
    case ' ': // <SP>
    case '\n': // <LF>
    case '\r': // <CR>
    case '\t': // <TAB>
    case '\u00A0': // <NBSP>
    case '\u000C': // <FF>
    case '\u2028': // <LS>
    case '\u2029': // <PS>
    case '\uFEFF': // <BOM>
      return TernaryValue.TRUE;
    default:
      return (Character.getType(c) == Character.SPACE_SEPARATOR)
          ? TernaryValue.TRUE : TernaryValue.FALSE;
  }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:23,代码来源:NodeUtil.java


示例5: apply

import com.google.javascript.rhino.jstype.TernaryValue; //导入依赖的package包/类
@Override
public boolean apply(EdgeTuple<Node, Branch> input) {
  Branch branch = input.edge;
  if (!branch.isConditional()) {
    return true;
  }
  Node predecessor = input.sourceNode;
  Node condition = NodeUtil.getConditionExpression(predecessor);

  // TODO(user): Handle more complicated expression like true == true,
  // etc....
  if (condition != null) {
    TernaryValue val = NodeUtil.getImpureBooleanValue(condition);
    if (val != TernaryValue.UNKNOWN) {
      return val.toBoolean(true) == (branch == Branch.ON_TRUE);
    }
  }
  return true;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:20,代码来源:CheckUnreachableCode.java


示例6: apply

import com.google.javascript.rhino.jstype.TernaryValue; //导入依赖的package包/类
@Override
public boolean apply(DiGraphEdge<Node, ControlFlowGraph.Branch> input) {
  // First skill all exceptions.
  Branch branch = input.getValue();
  if (branch == Branch.ON_EX) {
    return false;
  } else if (branch.isConditional()) {
    Node condition = NodeUtil.getConditionExpression(
        input.getSource().getValue());
    // TODO(user): We CAN make this bit smarter just looking at
    // constants. We DO have a full blown ReverseAbstractInterupter and
    // type system that can evaluate some impressions' boolean value but
    // for now we will keep this pass lightweight.
    if (condition != null) {
      TernaryValue val = NodeUtil.getImpureBooleanValue(condition);
      if (val != TernaryValue.UNKNOWN) {
        return val.toBoolean(true) == (Branch.ON_TRUE == branch);
      }
    }
  }
  return true;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:23,代码来源:CheckMissingReturn.java


示例7: getNormalizedNodeType

import com.google.javascript.rhino.jstype.TernaryValue; //导入依赖的package包/类
/**
 * @return Translate NOT expressions into TRUE or FALSE when possible.
 */
private static int getNormalizedNodeType(Node n) {
  int type = n.getType();
  if (type == Token.NOT) {
    TernaryValue value = NodeUtil.getPureBooleanValue(n);
    switch (value) {
      case TRUE:
        return Token.TRUE;
      case FALSE:
        return Token.FALSE;
      case UNKNOWN:
        return type;
    }
  }
  return type;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:PeepholeFoldConstants.java


示例8: isStrWhiteSpaceChar

import com.google.javascript.rhino.jstype.TernaryValue; //导入依赖的package包/类
public static TernaryValue isStrWhiteSpaceChar(int c) {
  switch (c) {
    case '\u000B': // <VT>
      return TernaryValue.UNKNOWN;  // Legacy IE says "no", ECMAScript says "yes"
    case ' ': // <SP>
    case '\n': // <LF>
    case '\r': // <CR>
    case '\t': // <TAB>
    case '\u00A0': // <NBSP>
    case '\u000C': // <FF>
    case '\u2028': // <LS>
    case '\u2029': // <PS>
    case '\uFEFF': // <BOM>
      return TernaryValue.TRUE;
    default:
      return TernaryValue.FALSE; // TODO(moz): Correct this.
  }
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:19,代码来源:TokenUtil.java


示例9: getBooleanValue

import com.google.javascript.rhino.jstype.TernaryValue; //导入依赖的package包/类
/**
 * Gets the boolean value of a node that represents a literal. This method
 * effectively emulates the <code>Boolean()</code> JavaScript cast function.
 */
static TernaryValue getBooleanValue(Node n) {
  switch (n.getType()) {
    case Token.STRING:
      return TernaryValue.forBoolean(n.getString().length() > 0);

    case Token.NUMBER:
      return TernaryValue.forBoolean(n.getDouble() != 0);

    case Token.NULL:
    case Token.FALSE:
    case Token.VOID:
      return TernaryValue.FALSE;

    case Token.NAME:
      String name = n.getString();
      if ("undefined".equals(name)
          || "NaN".equals(name)) {
        // We assume here that programs don't change the value of the keyword
        // undefined to something other than the value undefined.
        return TernaryValue.FALSE;
      } else if ("Infinity".equals(name)) {
        return TernaryValue.TRUE;
      }
      break;

    case Token.TRUE:
    case Token.ARRAYLIT:
    case Token.OBJECTLIT:
    case Token.REGEXP:
      return TernaryValue.TRUE;
  }

  return TernaryValue.UNKNOWN;
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:39,代码来源:NodeUtil.java


示例10: tryFoldHook

import com.google.javascript.rhino.jstype.TernaryValue; //导入依赖的package包/类
/**
 * Try folding HOOK (?:) if the condition results of the condition is known.
 * @return the replacement node, if changed, or the original if not
 */
private Node tryFoldHook(Node n) {
  Preconditions.checkState(n.getType() == Token.HOOK);
  Node parent = n.getParent();
  Preconditions.checkNotNull(parent);
  Node cond = n.getFirstChild();
  Node thenBody = cond.getNext();
  Node elseBody = thenBody.getNext();

  TernaryValue condValue = NodeUtil.getExpressionBooleanValue(cond);
  if (condValue == TernaryValue.UNKNOWN) {
    return n;  // We can't remove branches otherwise!
  }

  // Transform "(a = 2) ? x =2 : y" into "a=2,x=2"
  n.detachChildren();
  Node branchToKeep = condValue.toBoolean(true) ? thenBody : elseBody;
  Node replacement;
  if (mayHaveSideEffects(cond)) {
    replacement = new Node(Token.COMMA).copyInformationFrom(n);
    replacement.addChildToFront(cond);
    replacement.addChildToBack(branchToKeep);
  } else {
    replacement = branchToKeep;
  }

  parent.replaceChild(n, replacement);
  reportCodeChange();
  return replacement;
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:34,代码来源:PeepholeRemoveDeadCode.java


示例11: tryFoldWhile

import com.google.javascript.rhino.jstype.TernaryValue; //导入依赖的package包/类
/**
 * Removes WHILEs that always evaluate to false.
 */
Node tryFoldWhile(Node n) {
  Preconditions.checkArgument(n.getType() == Token.WHILE);
  Node cond = NodeUtil.getConditionExpression(n);
  if (NodeUtil.getBooleanValue(cond) != TernaryValue.FALSE) {
    return n;
  }
  NodeUtil.redeclareVarsInsideBranch(n);
  NodeUtil.removeChild(n.getParent(), n);
  reportCodeChange();

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


示例12: tryFoldFor

import com.google.javascript.rhino.jstype.TernaryValue; //导入依赖的package包/类
/**
 * Removes FORs that always evaluate to false.
 */
Node tryFoldFor(Node n) {
  Preconditions.checkArgument(n.getType() == Token.FOR);
  // If this is a FOR-IN loop skip it.
  if (NodeUtil.isForIn(n)) {
    return n;
  }

  Node init = n.getFirstChild();
  Node cond = init.getNext();
  Node increment = cond.getNext();

  if (init.getType() != Token.EMPTY && init.getType() != Token.VAR) {
    init = trySimpilifyUnusedResult(init, false);
  }

  if (increment.getType() != Token.EMPTY) {
    increment = trySimpilifyUnusedResult(increment, false);
  }

  // There is an initializer skip it
  if (n.getFirstChild().getType() != Token.EMPTY) {
    return n;
  }

  if (NodeUtil.getBooleanValue(cond) != TernaryValue.FALSE) {
    return n;
  }

  NodeUtil.redeclareVarsInsideBranch(n);
  NodeUtil.removeChild(n.getParent(), n);
  reportCodeChange();
  return null;
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:37,代码来源:PeepholeRemoveDeadCode.java


示例13: tryFoldForCondition

import com.google.javascript.rhino.jstype.TernaryValue; //导入依赖的package包/类
/**
 * Remove always true loop conditions.
 */
private void tryFoldForCondition(Node forCondition) {
  if (NodeUtil.getBooleanValue(forCondition) == TernaryValue.TRUE) {
    forCondition.getParent().replaceChild(forCondition,
        new Node(Token.EMPTY));
    reportCodeChange();
  }
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:11,代码来源:PeepholeRemoveDeadCode.java


示例14: visit

import com.google.javascript.rhino.jstype.TernaryValue; //导入依赖的package包/类
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
  switch (n.getType()) {
    case Token.LABEL:
      tryMinimizeExits(
          n.getLastChild(), Token.BREAK, n.getFirstChild().getString());
      break;

    case Token.FOR:
    case Token.WHILE:
      tryMinimizeExits(
          NodeUtil.getLoopCodeBlock(n), Token.CONTINUE, null);
      break;

    case Token.DO:
      tryMinimizeExits(
          NodeUtil.getLoopCodeBlock(n), Token.CONTINUE, null);

      Node cond = NodeUtil.getConditionExpression(n);
      if (NodeUtil.getBooleanValue(cond) == TernaryValue.FALSE) {
        // Normally, we wouldn't be able to optimize BREAKs inside a loop
        // but as we know the condition will always false, we can treat them
        // as we would a CONTINUE.
        tryMinimizeExits(
            n.getFirstChild(), Token.BREAK, null);
      }
      break;

    case Token.FUNCTION:
      tryMinimizeExits(
          n.getLastChild(), Token.RETURN, null);
      break;
  }
}
 
开发者ID:ehsan,项目名称:js-symbolic-executor,代码行数:35,代码来源:MinimizeExitPoints.java


示例15: trimJsWhiteSpace

import com.google.javascript.rhino.jstype.TernaryValue; //导入依赖的package包/类
static String trimJsWhiteSpace(String s) {
  int start = 0;
  int end = s.length();
  while (end > 0
      && isStrWhiteSpaceChar(s.charAt(end - 1)) == TernaryValue.TRUE) {
    end--;
  }
  while (start < end
      && isStrWhiteSpaceChar(s.charAt(start)) == TernaryValue.TRUE) {
    start++;
  }
  return s.substring(start, end);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:14,代码来源:NodeUtil.java


示例16: tryFoldHook

import com.google.javascript.rhino.jstype.TernaryValue; //导入依赖的package包/类
/**
 * Try folding HOOK (?:) if the condition results of the condition is known.
 * @return the replacement node, if changed, or the original if not
 */
private Node tryFoldHook(Node n) {
  Preconditions.checkState(n.isHook());
  Node parent = n.getParent();
  Preconditions.checkNotNull(parent);
  Node cond = n.getFirstChild();
  Node thenBody = cond.getNext();
  Node elseBody = thenBody.getNext();

  TernaryValue condValue = NodeUtil.getImpureBooleanValue(cond);
  if (condValue == TernaryValue.UNKNOWN) {
    // If the result nodes are equivalent, then one of the nodes can be
    // removed and it doesn't matter which.
    if (!areNodesEqualForInlining(thenBody, elseBody)) {
      return n;  // We can't remove branches otherwise!
    }
  }

  // Transform "(a = 2) ? x =2 : y" into "a=2,x=2"
  n.detachChildren();
  Node branchToKeep = condValue.toBoolean(true) ? thenBody : elseBody;
  Node replacement;
  if (mayHaveSideEffects(cond)) {
    replacement = IR.comma(cond, branchToKeep).srcref(n);
  } else {
    replacement = branchToKeep;
  }

  parent.replaceChild(n, replacement);
  reportCodeChange();
  return replacement;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:36,代码来源:PeepholeRemoveDeadCode.java


示例17: tryFoldWhile

import com.google.javascript.rhino.jstype.TernaryValue; //导入依赖的package包/类
/**
 * Removes WHILEs that always evaluate to false.
 */
Node tryFoldWhile(Node n) {
  Preconditions.checkArgument(n.isWhile());
  Node cond = NodeUtil.getConditionExpression(n);
  if (NodeUtil.getPureBooleanValue(cond) != TernaryValue.FALSE) {
    return n;
  }
  NodeUtil.redeclareVarsInsideBranch(n);
  NodeUtil.removeChild(n.getParent(), n);
  reportCodeChange();

  return null;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:16,代码来源:PeepholeRemoveDeadCode.java


示例18: tryFoldFor

import com.google.javascript.rhino.jstype.TernaryValue; //导入依赖的package包/类
/**
 * Removes FORs that always evaluate to false.
 */
Node tryFoldFor(Node n) {
  Preconditions.checkArgument(n.isFor());
  // If this is a FOR-IN loop skip it.
  if (NodeUtil.isForIn(n)) {
    return n;
  }

  Node init = n.getFirstChild();
  Node cond = init.getNext();
  Node increment = cond.getNext();

  if (!init.isEmpty() && !init.isVar()) {
    init = trySimplifyUnusedResult(init, false);
  }

  if (!increment.isEmpty()) {
    increment = trySimplifyUnusedResult(increment, false);
  }

  // There is an initializer skip it
  if (!n.getFirstChild().isEmpty()) {
    return n;
  }

  if (NodeUtil.getImpureBooleanValue(cond) != TernaryValue.FALSE) {
    return n;
  }

  NodeUtil.redeclareVarsInsideBranch(n);
  if (!mayHaveSideEffects(cond)) {
    NodeUtil.removeChild(n.getParent(), n);
  } else {
    Node statement = IR.exprResult(cond.detachFromParent())
        .copyInformationFrom(cond);
    n.getParent().replaceChild(n, statement);
  }
  reportCodeChange();
  return null;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:43,代码来源:PeepholeRemoveDeadCode.java


示例19: tryFoldDo

import com.google.javascript.rhino.jstype.TernaryValue; //导入依赖的package包/类
/**
 * Removes DOs that always evaluate to false. This leaves the
 * statements that were in the loop in a BLOCK node.
 * The block will be removed in a later pass, if possible.
 */
Node tryFoldDo(Node n) {
  Preconditions.checkArgument(n.isDo());

  Node cond = NodeUtil.getConditionExpression(n);
  if (NodeUtil.getImpureBooleanValue(cond) != TernaryValue.FALSE) {
    return n;
  }

  // TODO(johnlenz): The do-while can be turned into a label with
  // named breaks and the label optimized away (maybe).
  if (hasBreakOrContinue(n)) {
    return n;
  }

  Preconditions.checkState(
      NodeUtil.isControlStructureCodeBlock(n, n.getFirstChild()));
  Node block = n.removeFirstChild();

  Node parent =  n.getParent();
  parent.replaceChild(n, block);
  if (mayHaveSideEffects(cond)) {
    Node condStatement = IR.exprResult(cond.detachFromParent())
        .srcref(cond);
    parent.addChildAfter(condStatement, block);
  }
  reportCodeChange();

  return n;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:35,代码来源:PeepholeRemoveDeadCode.java


示例20: tryFoldForCondition

import com.google.javascript.rhino.jstype.TernaryValue; //导入依赖的package包/类
/**
 * Remove always true loop conditions.
 */
private void tryFoldForCondition(Node forCondition) {
  if (NodeUtil.getPureBooleanValue(forCondition) == TernaryValue.TRUE) {
    forCondition.getParent().replaceChild(forCondition,
        IR.empty());
    reportCodeChange();
  }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:11,代码来源:PeepholeRemoveDeadCode.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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