本文整理汇总了Java中jdk.nashorn.internal.ir.UnaryNode类的典型用法代码示例。如果您正苦于以下问题:Java UnaryNode类的具体用法?Java UnaryNode怎么用?Java UnaryNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnaryNode类属于jdk.nashorn.internal.ir包,在下文中一共展示了UnaryNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: leaveTYPEOF
import jdk.nashorn.internal.ir.UnaryNode; //导入依赖的package包/类
private Node leaveTYPEOF(final UnaryNode unaryNode) {
final Expression rhs = unaryNode.getExpression();
final List<Expression> args = new ArrayList<>();
if (rhs instanceof IdentNode && !isParamOrVar((IdentNode)rhs)) {
args.add(compilerConstantIdentifier(SCOPE));
args.add((Expression)LiteralNode.newInstance(rhs, ((IdentNode)rhs).getName()).accept(this)); //null
} else {
args.add(rhs);
args.add((Expression)LiteralNode.newInstance(unaryNode).accept(this)); //null, do not reuse token of identifier rhs, it can be e.g. 'this'
}
final Node runtimeNode = new RuntimeNode(unaryNode, Request.TYPEOF, args).accept(this);
end(unaryNode);
return runtimeNode;
}
示例2: branchOptimizer
import jdk.nashorn.internal.ir.UnaryNode; //导入依赖的package包/类
private void branchOptimizer(final UnaryNode unaryNode, final Label label, final boolean state) {
final Expression rhs = unaryNode.getExpression();
switch (unaryNode.tokenType()) {
case NOT:
branchOptimizer(rhs, label, !state);
return;
default:
if (unaryNode.getType().isBoolean()) {
branchOptimizer(rhs, label, state);
return;
}
break;
}
loadTestAndJump(unaryNode, label, state);
}
示例3: loadNOT
import jdk.nashorn.internal.ir.UnaryNode; //导入依赖的package包/类
private void loadNOT(final UnaryNode unaryNode) {
final Expression expr = unaryNode.getExpression();
if(expr instanceof UnaryNode && expr.isTokenType(TokenType.NOT)) {
// !!x is idiomatic boolean cast in JavaScript
loadExpressionAsBoolean(((UnaryNode)expr).getExpression());
} else {
final Label trueLabel = new Label("true");
final Label afterLabel = new Label("after");
emitBranch(expr, trueLabel, true);
method.load(true);
method._goto(afterLabel);
method.label(trueLabel);
method.load(false);
method.label(afterLabel);
}
}
示例4: loadSUB
import jdk.nashorn.internal.ir.UnaryNode; //导入依赖的package包/类
private void loadSUB(final UnaryNode unaryNode, final TypeBounds resultBounds) {
final Type type = unaryNode.getType();
assert type.isNumeric();
final TypeBounds numericBounds = resultBounds.booleanToInt();
new OptimisticOperation(unaryNode, numericBounds) {
@Override
void loadStack() {
final Expression expr = unaryNode.getExpression();
loadExpression(expr, numericBounds.notWiderThan(Type.NUMBER));
}
@Override
void consumeStack() {
// Must do an explicit conversion to the operation's type when it's double so that we correctly handle
// negation of an int 0 to a double -0. With this, we get the correct negation of a local variable after
// it deoptimized, e.g. "iload_2; i2d; dneg". Without this, we get "iload_2; ineg; i2d".
if(type.isNumber()) {
method.convert(type);
}
method.neg(getProgramPoint());
}
}.emit();
}
示例5: enterUnaryNode
import jdk.nashorn.internal.ir.UnaryNode; //导入依赖的package包/类
@Override
public boolean enterUnaryNode(final UnaryNode unaryNode) {
if (unaryNode.isTokenType(TokenType.NEW)) {
curExpr = new NewTreeImpl(unaryNode,
translateExpr(unaryNode.getExpression()));
} else if (unaryNode.isTokenType(TokenType.YIELD) ||
unaryNode.isTokenType(TokenType.YIELD_STAR)) {
curExpr = new YieldTreeImpl(unaryNode,
translateExpr(unaryNode.getExpression()));
} else if (unaryNode.isTokenType(TokenType.SPREAD_ARGUMENT) ||
unaryNode.isTokenType(TokenType.SPREAD_ARRAY)) {
curExpr = new SpreadTreeImpl(unaryNode,
translateExpr(unaryNode.getExpression()));
} else {
curExpr = new UnaryTreeImpl(unaryNode,
translateExpr(unaryNode.getExpression()));
}
return false;
}
示例6: enterLiteralNode
import jdk.nashorn.internal.ir.UnaryNode; //导入依赖的package包/类
@Override
public boolean enterLiteralNode(final LiteralNode<?> literalNode) {
if (literalNode.isArray()) {
if (((LiteralNode.ArrayLiteralNode)literalNode).hasSpread() && ((LiteralNode.ArrayLiteralNode)literalNode).hasTrailingComma()) {
throw error("Rest element must be last", literalNode.getElementExpressions().get(literalNode.getElementExpressions().size() - 1).getToken());
}
boolean restElement = false;
for (final Expression element : literalNode.getElementExpressions()) {
if (element != null) {
if (restElement) {
throw error("Unexpected element after rest element", element.getToken());
}
if (element.isTokenType(SPREAD_ARRAY)) {
restElement = true;
final Expression lvalue = ((UnaryNode) element).getExpression();
verifySpreadElement(lvalue);
}
element.accept(this);
}
}
return false;
} else {
return enterDefault(literalNode);
}
}
示例7: leaveTYPEOF
import jdk.nashorn.internal.ir.UnaryNode; //导入依赖的package包/类
private Node leaveTYPEOF(final UnaryNode unaryNode) {
final Expression rhs = unaryNode.getExpression();
final List<Expression> args = new ArrayList<>();
if (rhs instanceof IdentNode && !isParamOrVar((IdentNode)rhs)) {
args.add(compilerConstantIdentifier(SCOPE));
args.add(LiteralNode.newInstance(rhs, ((IdentNode)rhs).getName())); //null
} else {
args.add(rhs);
args.add(LiteralNode.newInstance(unaryNode)); //null, do not reuse token of identifier rhs, it can be e.g. 'this'
}
final Node runtimeNode = new RuntimeNode(unaryNode, Request.TYPEOF, args);
end(unaryNode);
return runtimeNode;
}
示例8: newExpression
import jdk.nashorn.internal.ir.UnaryNode; //导入依赖的package包/类
/**
* NewExpression :
* MemberExpression
* new NewExpression
*
* See 11.2
*
* Parse new expression.
* @return Expression node.
*/
private Expression newExpression() {
final long newToken = token;
// NEW is tested in caller.
next();
// Get function base.
final int callLine = line;
final Expression constructor = memberExpression();
if (constructor == null) {
return null;
}
// Get arguments.
ArrayList<Expression> arguments;
// Allow for missing arguments.
if (type == LPAREN) {
arguments = argumentList();
} else {
arguments = new ArrayList<>();
}
// Nashorn extension: This is to support the following interface implementation
// syntax:
//
// var r = new java.lang.Runnable() {
// run: function() { println("run"); }
// };
//
// The object literal following the "new Constructor()" expresssion
// is passed as an additional (last) argument to the constructor.
if (!env._no_syntax_extensions && type == LBRACE) {
arguments.add(objectLiteral());
}
final CallNode callNode = new CallNode(callLine, constructor.getToken(), finish, constructor, optimizeList(arguments), true);
return new UnaryNode(newToken, callNode);
}
示例9: enterUnaryNode
import jdk.nashorn.internal.ir.UnaryNode; //导入依赖的package包/类
@Override
public final boolean enterUnaryNode(final UnaryNode unaryNode) {
switch (unaryNode.tokenType()) {
case ADD:
return enterADD(unaryNode);
case BIT_NOT:
return enterBIT_NOT(unaryNode);
case DELETE:
return enterDELETE(unaryNode);
case NEW:
return enterNEW(unaryNode);
case NOT:
return enterNOT(unaryNode);
case SUB:
return enterSUB(unaryNode);
case TYPEOF:
return enterTYPEOF(unaryNode);
case VOID:
return enterVOID(unaryNode);
case DECPREFIX:
case DECPOSTFIX:
case INCPREFIX:
case INCPOSTFIX:
return enterDECINC(unaryNode);
default:
return super.enterUnaryNode(unaryNode);
}
}
示例10: leaveUnaryNode
import jdk.nashorn.internal.ir.UnaryNode; //导入依赖的package包/类
@Override
public final Node leaveUnaryNode(final UnaryNode unaryNode) {
switch (unaryNode.tokenType()) {
case ADD:
return leaveADD(unaryNode);
case BIT_NOT:
return leaveBIT_NOT(unaryNode);
case DELETE:
return leaveDELETE(unaryNode);
case NEW:
return leaveNEW(unaryNode);
case NOT:
return leaveNOT(unaryNode);
case SUB:
return leaveSUB(unaryNode);
case TYPEOF:
return leaveTYPEOF(unaryNode);
case VOID:
return leaveVOID(unaryNode);
case DECPREFIX:
case DECPOSTFIX:
case INCPREFIX:
case INCPOSTFIX:
return leaveDECINC(unaryNode);
default:
return super.leaveUnaryNode(unaryNode);
}
}
示例11: leaveUnaryNode
import jdk.nashorn.internal.ir.UnaryNode; //导入依赖的package包/类
@Override
public Node leaveUnaryNode(final UnaryNode unaryNode) {
if (unaryNode.isAssignment() && unaryNode.getExpression() instanceof IdentNode) {
checkConstAssignment((IdentNode) unaryNode.getExpression());
}
switch (unaryNode.tokenType()) {
case DELETE:
return leaveDELETE(unaryNode);
case TYPEOF:
return leaveTYPEOF(unaryNode);
default:
return super.leaveUnaryNode(unaryNode);
}
}
示例12: leaveUnaryNode
import jdk.nashorn.internal.ir.UnaryNode; //导入依赖的package包/类
@Override
public Node leaveUnaryNode(final UnaryNode unaryNode) {
final LiteralNode<?> literalNode = new UnaryNodeConstantEvaluator(unaryNode).eval();
if (literalNode != null) {
log.info("Unary constant folded ", unaryNode, " to ", literalNode);
return literalNode;
}
return unaryNode;
}
示例13: enterUnaryNode
import jdk.nashorn.internal.ir.UnaryNode; //导入依赖的package包/类
@Override
public boolean enterUnaryNode(final UnaryNode unaryNode) {
if(unaryNode.isTokenType(TokenType.NOT) || unaryNode.isTokenType(TokenType.NEW)) {
// Operand of boolean negation is never optimistic (always coerced to boolean).
// Operand of "new" is never optimistic (always coerced to Object).
tagNeverOptimistic(unaryNode.getExpression());
}
return true;
}
示例14: enterUnaryNode
import jdk.nashorn.internal.ir.UnaryNode; //导入依赖的package包/类
@Override
public boolean enterUnaryNode(final UnaryNode unaryNode) {
final Expression expr = unaryNode.getExpression();
expr.accept(this);
if(unaryNode.isSelfModifying()) {
if(expr instanceof IdentNode) {
final IdentNode ident = (IdentNode)expr;
onSelfAssignment(ident, unaryNode, getLocalVariableTypeIfBytecode(ident.getSymbol()));
}
}
return false;
}
示例15: loadADD
import jdk.nashorn.internal.ir.UnaryNode; //导入依赖的package包/类
private void loadADD(final UnaryNode unaryNode, final TypeBounds resultBounds) {
loadExpression(unaryNode.getExpression(), resultBounds.booleanToInt().notWiderThan(Type.NUMBER));
if(method.peekType() == Type.BOOLEAN) {
// It's a no-op in bytecode, but we must make sure it is treated as an int for purposes of type signatures
method.convert(Type.INT);
}
}