Search in sources :

Example 1 with JsBinaryOperator

use of org.jetbrains.kotlin.js.backend.ast.JsBinaryOperator in project kotlin by JetBrains.

the class IntrinsicAssignmentTranslator method translateAsPlainAssignmentOperation.

@NotNull
private JsExpression translateAsPlainAssignmentOperation() {
    context().addStatementsToCurrentBlockFrom(rightBlock);
    JsBinaryOperator operator = getAssignmentOperator();
    return new JsBinaryOperation(operator, accessTranslator.translateAsGet(), right);
}
Also used : JsBinaryOperator(org.jetbrains.kotlin.js.backend.ast.JsBinaryOperator) JsBinaryOperation(org.jetbrains.kotlin.js.backend.ast.JsBinaryOperation) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with JsBinaryOperator

use of org.jetbrains.kotlin.js.backend.ast.JsBinaryOperator in project kotlin by JetBrains.

the class CompareToTranslator method translate.

@NotNull
private JsExpression translate() {
    JsBinaryOperator correspondingOperator = OperatorTable.getBinaryOperator(getOperationToken(expression));
    JsExpression methodCall = BinaryOperationTranslator.translateAsOverloadedCall(expression, context());
    return new JsBinaryOperation(correspondingOperator, methodCall, context().program().getNumberLiteral(0));
}
Also used : JsExpression(org.jetbrains.kotlin.js.backend.ast.JsExpression) JsBinaryOperator(org.jetbrains.kotlin.js.backend.ast.JsBinaryOperator) JsBinaryOperation(org.jetbrains.kotlin.js.backend.ast.JsBinaryOperation) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with JsBinaryOperator

use of org.jetbrains.kotlin.js.backend.ast.JsBinaryOperator in project kotlin by JetBrains.

the class IntrinsicAssignmentTranslator method translateAsAssignToCounterpart.

@NotNull
private JsExpression translateAsAssignToCounterpart() {
    JsBinaryOperator operator = getCounterpartOperator();
    JsExpression oldValue = accessTranslator.translateAsGet();
    if (!rightExpressionTrivial) {
        oldValue = context().defineTemporary(oldValue);
    }
    JsBinaryOperation counterpartOperation = new JsBinaryOperation(operator, oldValue, right);
    context().addStatementsToCurrentBlockFrom(rightBlock);
    return accessTranslator.translateAsSet(counterpartOperation);
}
Also used : JsExpression(org.jetbrains.kotlin.js.backend.ast.JsExpression) JsBinaryOperator(org.jetbrains.kotlin.js.backend.ast.JsBinaryOperator) JsBinaryOperation(org.jetbrains.kotlin.js.backend.ast.JsBinaryOperation) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with JsBinaryOperator

use of org.jetbrains.kotlin.js.backend.ast.JsBinaryOperator in project kotlin by JetBrains.

the class TranslationUtils method isCacheNeeded.

public static boolean isCacheNeeded(@NotNull JsExpression expression) {
    if (expression instanceof JsLiteral.JsValueLiteral)
        return false;
    if (expression instanceof JsNameRef && ((JsNameRef) expression).getQualifier() == null)
        return false;
    if (expression instanceof JsBinaryOperation) {
        JsBinaryOperation operation = (JsBinaryOperation) expression;
        JsBinaryOperator operator = operation.getOperator();
        if (operator.isAssignment() || operator == COMMA)
            return true;
        return isCacheNeeded(operation.getArg1()) || isCacheNeeded(operation.getArg2());
    }
    if (expression instanceof JsUnaryOperation) {
        JsUnaryOperation operation = (JsUnaryOperation) expression;
        JsUnaryOperator operator = operation.getOperator();
        switch(operator) {
            case BIT_NOT:
            case NEG:
            case POS:
            case NOT:
            case TYPEOF:
            case VOID:
                return isCacheNeeded(operation.getArg());
            default:
                return true;
        }
    }
    return true;
}
Also used : JsBinaryOperator(org.jetbrains.kotlin.js.backend.ast.JsBinaryOperator)

Aggregations

JsBinaryOperator (org.jetbrains.kotlin.js.backend.ast.JsBinaryOperator)4 NotNull (org.jetbrains.annotations.NotNull)3 JsBinaryOperation (org.jetbrains.kotlin.js.backend.ast.JsBinaryOperation)3 JsExpression (org.jetbrains.kotlin.js.backend.ast.JsExpression)2