本文整理汇总了Java中jdk.nashorn.internal.ir.Expression.isAlwaysTrue方法的典型用法代码示例。如果您正苦于以下问题:Java Expression.isAlwaysTrue方法的具体用法?Java Expression.isAlwaysTrue怎么用?Java Expression.isAlwaysTrue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.ir.Expression
的用法示例。
在下文中一共展示了Expression.isAlwaysTrue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enterIfNode
import jdk.nashorn.internal.ir.Expression; //导入方法依赖的package包/类
@Override
public boolean enterIfNode(final IfNode ifNode) {
if(!method.isReachable()) {
return false;
}
enterStatement(ifNode);
final Expression test = ifNode.getTest();
final Block pass = ifNode.getPass();
final Block fail = ifNode.getFail();
if (Expression.isAlwaysTrue(test)) {
loadAndDiscard(test);
pass.accept(this);
return false;
} else if (Expression.isAlwaysFalse(test)) {
loadAndDiscard(test);
if (fail != null) {
fail.accept(this);
}
return false;
}
final boolean hasFailConversion = LocalVariableConversion.hasLiveConversion(ifNode);
final Label failLabel = new Label("if_fail");
final Label afterLabel = (fail == null && !hasFailConversion) ? null : new Label("if_done");
emitBranch(test, failLabel, false);
pass.accept(this);
if(method.isReachable() && afterLabel != null) {
method._goto(afterLabel); //don't fallthru to fail block
}
method.label(failLabel);
if (fail != null) {
fail.accept(this);
} else if(hasFailConversion) {
method.beforeJoinPoint(ifNode);
}
if(afterLabel != null && afterLabel.isReachable()) {
method.label(afterLabel);
}
return false;
}
示例2: enterForOrWhile
import jdk.nashorn.internal.ir.Expression; //导入方法依赖的package包/类
private void enterForOrWhile(final LoopNode loopNode, final JoinPredecessorExpression modify) {
// NOTE: the usual pattern for compiling test-first loops is "GOTO test; body; test; IFNE body". We use the less
// conventional "test; IFEQ break; body; GOTO test; break;". It has one extra unconditional GOTO in each repeat
// of the loop, but it's not a problem for modern JIT compilers. We do this because our local variable type
// tracking is unfortunately not really prepared for out-of-order execution, e.g. compiling the following
// contrived but legal JavaScript code snippet would fail because the test changes the type of "i" from object
// to double: var i = {valueOf: function() { return 1} }; while(--i >= 0) { ... }
// Instead of adding more complexity to the local variable type tracking, we instead choose to emit this
// different code shape.
final int liveLocalsOnBreak = method.getUsedSlotsWithLiveTemporaries();
final JoinPredecessorExpression test = loopNode.getTest();
if(Expression.isAlwaysFalse(test)) {
loadAndDiscard(test);
return;
}
method.beforeJoinPoint(loopNode);
final Label continueLabel = loopNode.getContinueLabel();
final Label repeatLabel = modify != null ? new Label("for_repeat") : continueLabel;
method.label(repeatLabel);
final int liveLocalsOnContinue = method.getUsedSlotsWithLiveTemporaries();
final Block body = loopNode.getBody();
final Label breakLabel = loopNode.getBreakLabel();
final boolean testHasLiveConversion = test != null && LocalVariableConversion.hasLiveConversion(test);
if(Expression.isAlwaysTrue(test)) {
if(test != null) {
loadAndDiscard(test);
if(testHasLiveConversion) {
method.beforeJoinPoint(test);
}
}
} else if (test != null) {
if (testHasLiveConversion) {
emitBranch(test.getExpression(), body.getEntryLabel(), true);
method.beforeJoinPoint(test);
method._goto(breakLabel);
} else {
emitBranch(test.getExpression(), breakLabel, false);
}
}
body.accept(this);
if(repeatLabel != continueLabel) {
emitContinueLabel(continueLabel, liveLocalsOnContinue);
}
if (loopNode.hasPerIterationScope() && lc.getCurrentBlock().needsScope()) {
// ES6 for loops with LET init need a new scope for each iteration. We just create a shallow copy here.
method.loadCompilerConstant(SCOPE);
method.invoke(virtualCallNoLookup(ScriptObject.class, "copy", ScriptObject.class));
method.storeCompilerConstant(SCOPE);
}
if(method.isReachable()) {
if(modify != null) {
lineNumber(loopNode);
loadAndDiscard(modify);
method.beforeJoinPoint(modify);
}
method._goto(repeatLabel);
}
method.breakLabel(breakLabel, liveLocalsOnBreak);
}