本文整理汇总了Java中jdk.nashorn.internal.ir.Expression类的典型用法代码示例。如果您正苦于以下问题:Java Expression类的具体用法?Java Expression怎么用?Java Expression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Expression类属于jdk.nashorn.internal.ir包,在下文中一共展示了Expression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertArrowFunctionParameterList
import jdk.nashorn.internal.ir.Expression; //导入依赖的package包/类
private List<IdentNode> convertArrowFunctionParameterList(final Expression paramListExpr, final int functionLine) {
final List<IdentNode> parameters;
if (paramListExpr == null) {
// empty parameter list, i.e. () =>
parameters = Collections.emptyList();
} else if (paramListExpr instanceof IdentNode || paramListExpr.isTokenType(ASSIGN) || isDestructuringLhs(paramListExpr)) {
parameters = Collections.singletonList(verifyArrowParameter(paramListExpr, 0, functionLine));
} else if (paramListExpr instanceof BinaryNode && Token.descType(paramListExpr.getToken()) == COMMARIGHT) {
parameters = new ArrayList<>();
Expression car = paramListExpr;
do {
final Expression cdr = ((BinaryNode) car).rhs();
parameters.add(0, verifyArrowParameter(cdr, parameters.size(), functionLine));
car = ((BinaryNode) car).lhs();
} while (car instanceof BinaryNode && Token.descType(car.getToken()) == COMMARIGHT);
parameters.add(0, verifyArrowParameter(car, parameters.size(), functionLine));
} else {
throw error(AbstractParser.message("expected.arrow.parameter"), paramListExpr.getToken());
}
return parameters;
}
示例2: propertyAssignment
import jdk.nashorn.internal.ir.Expression; //导入依赖的package包/类
/**
* Parse a property assignment from the token stream
* @return the property assignment as a Node
*/
private PropertyNode propertyAssignment() {
// Capture firstToken.
final long propertyToken = token;
LiteralNode<?> name = null;
if (type == STRING) {
name = getStringLiteral();
} else if (type == ESCSTRING) {
name = getLiteral();
}
if (name != null) {
expect(COLON);
final Expression value = jsonLiteral();
return new PropertyNode(propertyToken, value.getFinish(), name, value, null, null);
}
// Raise an error.
throw error(AbstractParser.message("expected", "string", type.getNameOrType()));
}
示例3: leaveTYPEOF
import jdk.nashorn.internal.ir.Expression; //导入依赖的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;
}
示例4: execString
import jdk.nashorn.internal.ir.Expression; //导入依赖的package包/类
/**
* Convert execString to a call to $EXEC.
*
* @param primaryToken Original string token.
* @return callNode to $EXEC.
*/
CallNode execString(final int primaryLine, final long primaryToken) {
// Synthesize an ident to call $EXEC.
final IdentNode execIdent = new IdentNode(primaryToken, finish, ScriptingFunctions.EXEC_NAME);
// Skip over EXECSTRING.
next();
// Set up argument list for call.
// Skip beginning of edit string expression.
expect(LBRACE);
// Add the following expression to arguments.
final List<Expression> arguments = Collections.singletonList(expression());
// Skip ending of edit string expression.
expect(RBRACE);
return new CallNode(primaryLine, primaryToken, finish, execIdent, arguments, false);
}
示例5: argumentList
import jdk.nashorn.internal.ir.Expression; //导入依赖的package包/类
/**
* Arguments :
* ( )
* ( ArgumentList )
*
* ArgumentList :
* AssignmentExpression
* ArgumentList , AssignmentExpression
*
* See 11.2
*
* Parse function call arguments.
* @return Argument list.
*/
private ArrayList<Expression> argumentList() {
// Prepare to accumulate list of arguments.
final ArrayList<Expression> nodeList = new ArrayList<>();
// LPAREN tested in caller.
next();
// Track commas.
boolean first = true;
while (type != RPAREN) {
// Comma prior to every argument except the first.
if (!first) {
expect(COMMARIGHT);
} else {
first = false;
}
// Get argument expression.
nodeList.add(assignmentExpression(false));
}
expect(RPAREN);
return nodeList;
}
示例6: leaveTYPEOF
import jdk.nashorn.internal.ir.Expression; //导入依赖的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;
}
示例7: verifyIncDecExpression
import jdk.nashorn.internal.ir.Expression; //导入依赖的package包/类
private Expression verifyIncDecExpression(final long unaryToken, final TokenType opType, final Expression lhs, final boolean isPostfix) {
assert lhs != null;
if (!(lhs instanceof AccessNode ||
lhs instanceof IndexNode ||
lhs instanceof IdentNode)) {
return referenceError(lhs, null, env._early_lvalue_error);
}
if (lhs instanceof IdentNode) {
if (!checkIdentLValue((IdentNode)lhs)) {
return referenceError(lhs, null, false);
}
verifyIdent((IdentNode)lhs, "operand for " + opType.getName() + " operator");
}
return incDecExpression(unaryToken, opType, lhs, isPostfix);
}
示例8: leaveExpressionStatement
import jdk.nashorn.internal.ir.Expression; //导入依赖的package包/类
@Override
public Node leaveExpressionStatement(final ExpressionStatement expressionStatement) {
final Expression expr = expressionStatement.getExpression();
ExpressionStatement node = expressionStatement;
final FunctionNode currentFunction = lc.getCurrentFunction();
if (currentFunction.isProgram()) {
if (!isInternalExpression(expr) && !isEvalResultAssignment(expr)) {
node = expressionStatement.setExpression(
new BinaryNode(
Token.recast(
expressionStatement.getToken(),
TokenType.ASSIGN),
compilerConstant(RETURN),
expr));
}
}
return addStatement(node);
}
示例9: leaveForNode
import jdk.nashorn.internal.ir.Expression; //导入依赖的package包/类
@Override
public Node leaveForNode(final ForNode forNode) {
ForNode newForNode = forNode;
final Expression test = forNode.getTest();
if (!forNode.isForIn() && isAlwaysTrue(test)) {
newForNode = forNode.setTest(lc, null);
}
newForNode = checkEscape(newForNode);
if(newForNode.isForIn()) {
// Wrap it in a block so its internally created iterator is restricted in scope
addStatementEnclosedInBlock(newForNode);
} else {
addStatement(newForNode);
}
return newForNode;
}
示例10: loadNOT
import jdk.nashorn.internal.ir.Expression; //导入依赖的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);
}
}
示例11: checkEval
import jdk.nashorn.internal.ir.Expression; //导入依赖的package包/类
/**
* Check whether a call node may be a call to eval. In that case we
* clone the args in order to create the following construct in
* {@link CodeGenerator}
*
* <pre>
* if (calledFuntion == buildInEval) {
* eval(cloned arg);
* } else {
* cloned arg;
* }
* </pre>
*
* @param callNode call node to check if it's an eval
*/
private CallNode checkEval(final CallNode callNode) {
if (callNode.getFunction() instanceof IdentNode) {
final List<Expression> args = callNode.getArgs();
final IdentNode callee = (IdentNode)callNode.getFunction();
// 'eval' call with at least one argument
if (args.size() >= 1 && EVAL.symbolName().equals(callee.getName())) {
final List<Expression> evalArgs = new ArrayList<>(args.size());
for(final Expression arg: args) {
evalArgs.add((Expression)ensureUniqueNamesIn(arg).accept(this));
}
return callNode.setEvalArgs(new CallNode.EvalArgs(evalArgs, evalLocation(callee)));
}
}
return callNode;
}
示例12: evaluateSafely
import jdk.nashorn.internal.ir.Expression; //导入依赖的package包/类
private Object evaluateSafely(final Expression expr) {
if (expr instanceof IdentNode) {
return runtimeScope == null ? null : evaluatePropertySafely(runtimeScope, ((IdentNode)expr).getName());
}
if (expr instanceof AccessNode) {
final AccessNode accessNode = (AccessNode)expr;
final Object base = evaluateSafely(accessNode.getBase());
if (!(base instanceof ScriptObject)) {
return null;
}
return evaluatePropertySafely((ScriptObject)base, accessNode.getProperty());
}
return null;
}
示例13: branchOptimizer
import jdk.nashorn.internal.ir.Expression; //导入依赖的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);
}
示例14: enterReturnNode
import jdk.nashorn.internal.ir.Expression; //导入依赖的package包/类
@Override
public boolean enterReturnNode(final ReturnNode returnNode) {
if(!reachable) {
return false;
}
final Expression returnExpr = returnNode.getExpression();
final Type returnExprType;
if(returnExpr != null) {
returnExpr.accept(this);
returnExprType = getType(returnExpr);
} else {
returnExprType = Type.UNDEFINED;
}
returnType = Type.widestReturnType(returnType, returnExprType);
doesNotContinueSequentially();
return false;
}
示例15: checkValidLValue
import jdk.nashorn.internal.ir.Expression; //导入依赖的package包/类
private boolean checkValidLValue(final Expression init, final String contextString) {
if (init instanceof IdentNode) {
if (!checkIdentLValue((IdentNode)init)) {
return false;
}
verifyIdent((IdentNode)init, contextString);
return true;
} else if (init instanceof AccessNode || init instanceof IndexNode) {
return true;
} else if (isDestructuringLhs(init)) {
verifyDestructuringAssignmentPattern(init, contextString);
return true;
} else {
return false;
}
}