本文整理汇总了Java中jdk.nashorn.internal.ir.Expression类的典型用法代码示例。如果您正苦于以下问题:Java Expression类的具体用法?Java Expression怎么用?Java Expression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Expression类属于jdk.nashorn.internal.ir包,在下文中一共展示了Expression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:Parser.java
示例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()));
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:JSONParser.java
示例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;
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:AssignSymbols.java
示例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);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:Parser.java
示例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;
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:39,代码来源:Parser.java
示例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;
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:AssignSymbols.java
示例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);
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Parser.java
示例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);
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:Lower.java
示例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;
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:Lower.java
示例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);
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:CodeGenerator.java
示例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;
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:Lower.java
示例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;
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:TypeEvaluator.java
示例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);
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:BranchOptimizer.java
示例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;
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:LocalVariableTypesCalculator.java
示例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;
}
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:Parser.java
示例16: enterReturnNode
import jdk.nashorn.internal.ir.Expression; //导入依赖的package包/类
@Override
public boolean enterReturnNode(final ReturnNode returnNode) {
if(!method.isReachable()) {
return false;
}
enterStatement(returnNode);
method.registerReturn();
final Type returnType = lc.getCurrentFunction().getReturnType();
final Expression expression = returnNode.getExpression();
if (expression != null) {
loadExpressionUnbounded(expression);
} else {
method.loadUndefined(returnType);
}
method._return(returnType);
return false;
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:CodeGenerator.java
示例17: verifyDestructuringParameterBindingPattern
import jdk.nashorn.internal.ir.Expression; //导入依赖的package包/类
private void verifyDestructuringParameterBindingPattern(final Expression pattern, final long paramToken, final int paramLine, final String contextString) {
verifyDestructuringBindingPattern(pattern, new Consumer<IdentNode>() {
public void accept(final IdentNode identNode) {
verifyIdent(identNode, contextString);
final ParserContextFunctionNode currentFunction = lc.getCurrentFunction();
if (currentFunction != null) {
// declare function-scope variables for destructuring bindings
if (!env._parse_only) {
lc.getFunctionBody(currentFunction).appendStatement(new VarNode(paramLine, Token.recast(paramToken, VAR), pattern.getFinish(), identNode, null));
}
// detect duplicate bounds names in parameter list
currentFunction.addParameterBinding(identNode);
currentFunction.setSimpleParameterList(false);
}
}
});
}
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Parser.java
示例18: loadAndDiscard
import jdk.nashorn.internal.ir.Expression; //导入依赖的package包/类
private void loadAndDiscard(final Expression expr) {
// TODO: move checks for discarding to actual expression load code (e.g. as we do with void). That way we might
// be able to eliminate even more checks.
if(expr instanceof PrimitiveLiteralNode | isLocalVariable(expr)) {
assert lc.getCurrentDiscard() != expr;
// Don't bother evaluating expressions without side effects. Typical usage is "void 0" for reliably generating
// undefined.
return;
}
lc.pushDiscard(expr);
loadExpression(expr, TypeBounds.UNBOUNDED);
if (lc.getCurrentDiscard() == expr) {
assert !expr.isAssignment();
// NOTE: if we had a way to load with type void, we could avoid popping
method.pop();
lc.popDiscard();
}
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:CodeGenerator.java
示例19: loadASSIGN
import jdk.nashorn.internal.ir.Expression; //导入依赖的package包/类
private void loadASSIGN(final BinaryNode binaryNode) {
final Expression lhs = binaryNode.lhs();
final Expression rhs = binaryNode.rhs();
final Type rhsType = rhs.getType();
// Detect dead assignments
if(lhs instanceof IdentNode) {
final Symbol symbol = ((IdentNode)lhs).getSymbol();
if(!symbol.isScope() && !symbol.hasSlotFor(rhsType) && lc.getCurrentDiscard() == binaryNode) {
loadAndDiscard(rhs);
lc.popDiscard();
method.markDeadLocalVariable(symbol);
return;
}
}
new Store<BinaryNode>(binaryNode, lhs) {
@Override
protected void evaluate() {
// NOTE: we're loading with "at least as wide as" so optimistic operations on the right hand side
// remain optimistic, and then explicitly convert to the required type if needed.
loadExpressionAsType(rhs, rhsType);
}
}.store();
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:CodeGenerator.java
示例20: evaluate
import jdk.nashorn.internal.ir.Expression; //导入依赖的package包/类
@Override
protected void evaluate() {
final Expression lhs = assignNode.lhs();
final Expression rhs = assignNode.rhs();
final Type widestOperationType = assignNode.getWidestOperationType();
final TypeBounds bounds = new TypeBounds(assignNode.getType(), widestOperationType);
new OptimisticOperation(assignNode, bounds) {
@Override
void loadStack() {
final boolean forceConversionSeparation;
if (isValid(getProgramPoint()) || widestOperationType == Type.NUMBER) {
forceConversionSeparation = false;
} else {
final Type operandType = Type.widest(booleanToInt(objectToNumber(lhs.getType())), booleanToInt(objectToNumber(rhs.getType())));
forceConversionSeparation = operandType.narrowerThan(widestOperationType);
}
loadBinaryOperands(lhs, rhs, bounds, true, forceConversionSeparation);
}
@Override
void consumeStack() {
op(this);
}
}.emit(getOptimisticIgnoreCountForSelfModifyingExpression(lhs));
method.convert(assignNode.getType());
}
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:26,代码来源:CodeGenerator.java
注:本文中的jdk.nashorn.internal.ir.Expression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论