Search in sources :

Example 1 with SLLogicalOrNode

use of com.oracle.truffle.sl.nodes.expression.SLLogicalOrNode in project graal by oracle.

the class SLNodeFactory method createBinary.

/**
 * Returns the corresponding subclass of {@link SLExpressionNode} for binary expressions. </br>
 * These nodes are currently not instrumented.
 *
 * @param opToken The operator of the binary expression
 * @param leftNode The left node of the expression
 * @param rightNode The right node of the expression
 * @return A subclass of SLExpressionNode using the given parameters based on the given opToken.
 *         null if either leftNode or rightNode is null.
 */
public SLExpressionNode createBinary(Token opToken, SLExpressionNode leftNode, SLExpressionNode rightNode) {
    if (leftNode == null || rightNode == null) {
        return null;
    }
    final SLExpressionNode leftUnboxed;
    if (leftNode instanceof SLBinaryNode) {
        // SLBinaryNode never returns boxed value
        leftUnboxed = leftNode;
    } else {
        leftUnboxed = SLUnboxNodeGen.create(leftNode);
    }
    final SLExpressionNode rightUnboxed;
    if (rightNode instanceof SLBinaryNode) {
        // SLBinaryNode never returns boxed value
        rightUnboxed = rightNode;
    } else {
        rightUnboxed = SLUnboxNodeGen.create(rightNode);
    }
    final SLExpressionNode result;
    switch(opToken.val) {
        case "+":
            result = SLAddNodeGen.create(leftUnboxed, rightUnboxed);
            break;
        case "*":
            result = SLMulNodeGen.create(leftUnboxed, rightUnboxed);
            break;
        case "/":
            result = SLDivNodeGen.create(leftUnboxed, rightUnboxed);
            break;
        case "-":
            result = SLSubNodeGen.create(leftUnboxed, rightUnboxed);
            break;
        case "<":
            result = SLLessThanNodeGen.create(leftUnboxed, rightUnboxed);
            break;
        case "<=":
            result = SLLessOrEqualNodeGen.create(leftUnboxed, rightUnboxed);
            break;
        case ">":
            result = SLLogicalNotNodeGen.create(SLLessOrEqualNodeGen.create(leftUnboxed, rightUnboxed));
            break;
        case ">=":
            result = SLLogicalNotNodeGen.create(SLLessThanNodeGen.create(leftUnboxed, rightUnboxed));
            break;
        case "==":
            result = SLEqualNodeGen.create(leftUnboxed, rightUnboxed);
            break;
        case "!=":
            result = SLLogicalNotNodeGen.create(SLEqualNodeGen.create(leftUnboxed, rightUnboxed));
            break;
        case "&&":
            result = new SLLogicalAndNode(leftUnboxed, rightUnboxed);
            break;
        case "||":
            result = new SLLogicalOrNode(leftUnboxed, rightUnboxed);
            break;
        default:
            throw new RuntimeException("unexpected operation: " + opToken.val);
    }
    int start = leftNode.getSourceCharIndex();
    int length = rightNode.getSourceEndIndex() - start;
    result.setSourceSection(start, length);
    return result;
}
Also used : SLLogicalAndNode(com.oracle.truffle.sl.nodes.expression.SLLogicalAndNode) SLExpressionNode(com.oracle.truffle.sl.nodes.SLExpressionNode) SLLogicalOrNode(com.oracle.truffle.sl.nodes.expression.SLLogicalOrNode) SLBinaryNode(com.oracle.truffle.sl.nodes.SLBinaryNode)

Aggregations

SLBinaryNode (com.oracle.truffle.sl.nodes.SLBinaryNode)1 SLExpressionNode (com.oracle.truffle.sl.nodes.SLExpressionNode)1 SLLogicalAndNode (com.oracle.truffle.sl.nodes.expression.SLLogicalAndNode)1 SLLogicalOrNode (com.oracle.truffle.sl.nodes.expression.SLLogicalOrNode)1