本文整理汇总了Java中com.google.javascript.rhino.jstype.TernaryValue.FALSE属性的典型用法代码示例。如果您正苦于以下问题:Java TernaryValue.FALSE属性的具体用法?Java TernaryValue.FALSE怎么用?Java TernaryValue.FALSE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.javascript.rhino.jstype.TernaryValue
的用法示例。
在下文中一共展示了TernaryValue.FALSE属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: tryFoldDo
/**
* 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;
}
示例2: isStrWhiteSpaceChar
/**
* 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;
}
}
示例3: isStrWhiteSpaceChar
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.
}
}
示例4: getBooleanValue
/**
* 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;
}
示例5: tryFoldWhile
/**
* 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;
}
示例6: tryFoldFor
/**
* 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;
}
示例7: visit
@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;
}
}
示例8: tryFoldWhile
/**
* 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;
}
示例9: tryFoldFor
/**
* 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;
}
示例10: tryFoldDo
/**
* 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;
}
示例11: visit
@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.getImpureBooleanValue(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;
}
}
示例12: areStringsEqual
/** Returns whether two JS strings are equal. */
private static TernaryValue areStringsEqual(String a, String b) {
// In JS, browsers parse \v differently. So do not consider strings
// equal if one contains \v.
if (a.indexOf('\u000B') != -1 ||
b.indexOf('\u000B') != -1) {
return TernaryValue.UNKNOWN;
} else {
return a.equals(b) ? TernaryValue.TRUE : TernaryValue.FALSE;
}
}
示例13: tryFoldWhile
/**
* Removes WHILEs that always evaluate to false.
*/
Node tryFoldWhile(Node n) {
checkArgument(n.isWhile());
Node cond = NodeUtil.getConditionExpression(n);
if (NodeUtil.getPureBooleanValue(cond) != TernaryValue.FALSE) {
return n;
}
NodeUtil.redeclareVarsInsideBranch(n);
compiler.reportChangeToEnclosingScope(n.getParent());
NodeUtil.removeChild(n.getParent(), n);
return null;
}
示例14: tryFoldDoAway
/**
* 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 tryFoldDoAway(Node n) {
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;
}
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.detach())
.srcref(cond);
parent.addChildAfter(condStatement, block);
}
compiler.reportChangeToEnclosingScope(parent);
return block;
}
示例15: tryFoldDoAway
/**
* 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 tryFoldDoAway(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 block;
}