Java 类jdk.nashorn.internal.ir.BinaryNode 实例源码

项目:openjdk-jdk10    文件:Parser.java   
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;
}
项目:OpenJSharp    文件:CodeGenerator.java   
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();
}
项目:openjdk-jdk10    文件:AssignmentTreeImpl.java   
AssignmentTreeImpl(final BinaryNode node, final ExpressionTree left, final ExpressionTree right) {
    super(node);
    assert node.isAssignment() : "assignment node expected";
    this.var = left;
    this.expr = right;
    this.kind = getOperator(node.tokenType());
}
项目:OpenJSharp    文件:CodeGenerator.java   
private void loadASSIGN_DIV(final BinaryNode binaryNode) {
    new BinaryOptimisticSelfAssignment(binaryNode) {
        @Override
        protected void op(final OptimisticOperation oo) {
            method.div(oo.getProgramPoint());
        }
    }.store();
}
项目:openjdk-jdk10    文件:CodeGenerator.java   
private void loadASSIGN_BIT_XOR(final BinaryNode binaryNode) {
    new BinarySelfAssignment(binaryNode) {
        @Override
        protected void op() {
            method.xor();
        }
    }.store();
}
项目:OpenJSharp    文件:CodeGenerator.java   
private void loadBIT_OR(final BinaryNode binaryNode) {
    // Optimize x|0 to (int)x
    if (isRhsZero(binaryNode)) {
        loadExpressionAsType(binaryNode.lhs(), Type.INT);
    } else {
        loadBinaryOperands(binaryNode);
        method.or();
    }
}
项目:openjdk-jdk10    文件:Parser.java   
@Override
public boolean enterBinaryNode(final BinaryNode binaryNode) {
    if (binaryNode.isTokenType(ASSIGN)) {
        binaryNode.lhs().accept(this);
        // Initializer(rhs) can be any AssignmentExpression
        return false;
    } else {
        return enterDefault(binaryNode);
    }
}
项目:OpenJSharp    文件:CodeGenerator.java   
private void loadASSIGN_ADD(final BinaryNode binaryNode) {
    new BinaryOptimisticSelfAssignment(binaryNode) {
        @Override
        protected void op(final OptimisticOperation oo) {
            assert !(binaryNode.getType().isObject() && oo.isOptimistic);
            method.add(oo.getProgramPoint());
        }
    }.store();
}
项目:openjdk-jdk10    文件:Lower.java   
/**
 * Is this an assignment to the special variable that hosts scripting eval
 * results, i.e. __return__?
 *
 * @param expression expression to check whether it is $evalresult = X
 * @return true if an assignment to eval result, false otherwise
 */
private static boolean isEvalResultAssignment(final Node expression) {
    final Node e = expression;
    if (e instanceof BinaryNode) {
        final Node lhs = ((BinaryNode)e).lhs();
        if (lhs instanceof IdentNode) {
            return ((IdentNode)lhs).getName().equals(RETURN.symbolName());
        }
    }
    return false;
}
项目:openjdk-jdk10    文件:CodeGenerator.java   
private void loadMOD(final BinaryNode binaryNode, final TypeBounds resultBounds) {
    new BinaryArith() {
        @Override
        protected void op(final int programPoint) {
            method.rem(programPoint);
        }
    }.evaluate(binaryNode, resultBounds);
}
项目:OpenJSharp    文件:CodeGenerator.java   
private void loadSUB(final BinaryNode binaryNode, final TypeBounds resultBounds) {
    new BinaryArith() {
        @Override
        protected void op(final int programPoint) {
            method.sub(programPoint);
        }
    }.evaluate(binaryNode, resultBounds);
}
项目:openjdk-jdk10    文件:CodeGenerator.java   
private void loadDIV(final BinaryNode binaryNode, final TypeBounds resultBounds) {
    new BinaryArith() {
        @Override
        protected void op(final int programPoint) {
            method.div(programPoint);
        }
    }.evaluate(binaryNode, resultBounds);
}
项目:OpenJSharp    文件:AssignSymbols.java   
@Override
public Node leaveBinaryNode(final BinaryNode binaryNode) {
    if (binaryNode.isAssignment() && binaryNode.lhs() instanceof IdentNode) {
        checkConstAssignment((IdentNode) binaryNode.lhs());
    }
    switch (binaryNode.tokenType()) {
    case ASSIGN:
        return leaveASSIGN(binaryNode);
    default:
        return super.leaveBinaryNode(binaryNode);
    }
}
项目:OpenJSharp    文件:Lower.java   
/**
 * Is this an assignment to the special variable that hosts scripting eval
 * results, i.e. __return__?
 *
 * @param expression expression to check whether it is $evalresult = X
 * @return true if an assignment to eval result, false otherwise
 */
private static boolean isEvalResultAssignment(final Node expression) {
    final Node e = expression;
    if (e instanceof BinaryNode) {
        final Node lhs = ((BinaryNode)e).lhs();
        if (lhs instanceof IdentNode) {
            return ((IdentNode)lhs).getName().equals(RETURN.symbolName());
        }
    }
    return false;
}
项目:openjdk-jdk10    文件:WeighNodes.java   
@Override
public Node leaveEQ_STRICT(final BinaryNode binaryNode) {
    return compareWeight(binaryNode);
}
项目:OpenJSharp    文件:ASTWriter.java   
private static void enqueueChildren(final Node node, final Class<?> nodeClass, final List<Field> children) {
    final Deque<Class<?>> stack = new ArrayDeque<>();

    /**
     * Here is some ugliness that can be overcome by proper ChildNode annotations
     * with proper orders. Right now we basically sort all classes up to Node
     * with super class first, as this often is the natural order, e.g. base
     * before index for an IndexNode.
     *
     * Also there are special cases as this is not true for UnaryNodes(lhs) and
     * BinaryNodes extends UnaryNode (with lhs), and TernaryNodes.
     *
     * TODO - generalize traversal with an order built on annotations and this
     * will go away.
     */
    Class<?> clazz = nodeClass;
    do {
        stack.push(clazz);
        clazz = clazz.getSuperclass();
    } while (clazz != null);

    if (node instanceof TernaryNode) {
        // HACK juggle "third"
        stack.push(stack.removeLast());
    }
    // HACK change operator order for BinaryNodes to get lhs first.
    final Iterator<Class<?>> iter = node instanceof BinaryNode ? stack.descendingIterator() : stack.iterator();

    while (iter.hasNext()) {
        final Class<?> c = iter.next();
        for (final Field f : c.getDeclaredFields()) {
            try {
                f.setAccessible(true);
                final Object child = f.get(node);
                if (child == null) {
                    continue;
                }

                if (child instanceof Node) {
                    children.add(f);
                } else if (child instanceof Collection) {
                    if (!((Collection<?>)child).isEmpty()) {
                        children.add(f);
                    }
                }
            } catch (final IllegalArgumentException | IllegalAccessException e) {
                return;
            }
        }
    }
}
项目:OpenJSharp    文件:WeighNodes.java   
@Override
public Node leaveBIND(final BinaryNode binaryNode) {
    return binaryNodeWeight(binaryNode);
}
项目:OpenJSharp    文件:WeighNodes.java   
@Override
public Node leaveASSIGN_BIT_OR(final BinaryNode binaryNode) {
    return binaryNodeWeight(binaryNode);
}
项目:OpenJSharp    文件:WeighNodes.java   
@Override
public Node leaveASSIGN(final BinaryNode binaryNode) {
    return binaryNodeWeight(binaryNode);
}
项目:openjdk-jdk10    文件:WeighNodes.java   
@Override
public Node leaveOR(final BinaryNode binaryNode) {
    return binaryNodeWeight(binaryNode);
}
项目:openjdk-jdk10    文件:CodeGenerator.java   
private void loadSAR(final BinaryNode binaryNode) {
    loadBinaryOperands(binaryNode);
    method.sar();
}
项目:openjdk-jdk10    文件:CodeGenerator.java   
private void loadCOMMALEFT(final BinaryNode binaryNode, final TypeBounds resultBounds) {
    loadMaybeDiscard(binaryNode, binaryNode.lhs(), resultBounds);
    loadAndDiscard(binaryNode.rhs());
}
项目:openjdk-jdk10    文件:WeighNodes.java   
@Override
public Node leaveASSIGN_SUB(final BinaryNode binaryNode) {
    return binaryNodeWeight(binaryNode);
}
项目:openjdk-jdk10    文件:ProgramPoints.java   
@Override
public Node leaveBinaryNode(final BinaryNode binaryNode) {
    return setProgramPoint(binaryNode);
}
项目:openjdk-jdk10    文件:WeighNodes.java   
@Override
public Node leaveASSIGN_ADD(final BinaryNode binaryNode) {
    weight += ADD_WEIGHT;
    return binaryNode;
}
项目:OpenJSharp    文件:WeighNodes.java   
@Override
public Node leaveGE(final BinaryNode binaryNode) {
    return compareWeight(binaryNode);
}
项目:openjdk-jdk10    文件:CodeGenerator.java   
BinarySelfAssignment(final BinaryNode node) {
    super(node, node.lhs());
}
项目:OpenJSharp    文件:WeighNodes.java   
@Override
public Node leaveGT(final BinaryNode binaryNode) {
    return compareWeight(binaryNode);
}
项目:OpenJSharp    文件:CodeGenerator.java   
BinarySelfAssignment(final BinaryNode node) {
    super(node, node.lhs());
}
项目:OpenJSharp    文件:WeighNodes.java   
@Override
public Node leaveSAR(final BinaryNode binaryNode) {
    return binaryNodeWeight(binaryNode);
}
项目:OpenJSharp    文件:WeighNodes.java   
@Override
public Node leaveEQ_STRICT(final BinaryNode binaryNode) {
    return compareWeight(binaryNode);
}
项目:OpenJSharp    文件:WeighNodes.java   
@Override
public Node leaveMOD(final BinaryNode binaryNode) {
    return binaryNodeWeight(binaryNode);
}
项目:openjdk-jdk10    文件:WeighNodes.java   
@Override
public Node leaveDIV(final BinaryNode binaryNode) {
    return binaryNodeWeight(binaryNode);
}
项目:OpenJSharp    文件:WeighNodes.java   
@Override
public Node leaveNE_STRICT(final BinaryNode binaryNode) {
    return compareWeight(binaryNode);
}
项目:OpenJSharp    文件:WeighNodes.java   
private Node compareWeight(final BinaryNode binaryNode) {
    weight += COMPARE_WEIGHT;
    return binaryNode;
}
项目:OpenJSharp    文件:CodeGenerator.java   
private void loadBIT_XOR(final BinaryNode binaryNode) {
    loadBinaryOperands(binaryNode);
    method.xor();
}
项目:openjdk-jdk10    文件:WeighNodes.java   
@Override
public Node leaveGE(final BinaryNode binaryNode) {
    return compareWeight(binaryNode);
}
项目:openjdk-jdk10    文件:Lower.java   
@Override
public Node leaveINSTANCEOF(final BinaryNode binaryNode) {
    return new RuntimeNode(binaryNode);
}
项目:OpenJSharp    文件:WeighNodes.java   
@Override
public Node leaveIN(final BinaryNode binaryNode) {
    weight += CALL_WEIGHT;
    return binaryNode;
}
项目:openjdk-jdk10    文件:WeighNodes.java   
@Override
public Node leaveBIT_AND(final BinaryNode binaryNode) {
    return binaryNodeWeight(binaryNode);
}