Search in sources :

Example 1 with JsBinaryOperation

use of org.jetbrains.kotlin.js.backend.ast.JsBinaryOperation 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 JsBinaryOperation

use of org.jetbrains.kotlin.js.backend.ast.JsBinaryOperation 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 JsBinaryOperation

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

the class VariableAccessTranslator method translateAsSet.

@NotNull
@Override
public JsExpression translateAsSet(@NotNull JsExpression setTo) {
    JsExpression e = CallTranslator.INSTANCE.translateSet(context(), resolvedCall, setTo, receiver);
    CallableDescriptor original = resolvedCall.getResultingDescriptor().getOriginal();
    if (original instanceof PropertyDescriptor) {
        PropertySetterDescriptor setter = ((PropertyDescriptor) original).getSetter();
        if (InlineUtil.isInline(setter)) {
            if (e instanceof JsBinaryOperation && ((JsBinaryOperation) e).getOperator().isAssignment()) {
                // Set was translated as an assignment
                setInlineCallMetadata((JsNameRef) (((JsBinaryOperation) e).getArg1()), referenceExpression, setter);
            } else {
                setInlineCallMetadata(e, referenceExpression, setter, context());
            }
        }
    }
    return e;
}
Also used : JsExpression(org.jetbrains.kotlin.js.backend.ast.JsExpression) JsBinaryOperation(org.jetbrains.kotlin.js.backend.ast.JsBinaryOperation) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with JsBinaryOperation

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

the class IncrementTranslator method asPrefix.

//TODO: decide if this expression can be optimised in case of direct access (not property)
@NotNull
private JsExpression asPrefix() {
    // code fragment: expr(a++)
    // generate: expr(a = a.inc(), a)
    JsExpression getExpression = accessTranslator.translateAsGet();
    JsExpression reassignment = variableReassignment(context().innerBlock(accessBlock), getExpression);
    accessBlock.getStatements().add(JsAstUtils.asSyntheticStatement(reassignment));
    JsExpression getNewValue = accessTranslator.translateAsGet();
    JsExpression result;
    if (accessBlock.getStatements().size() == 1) {
        result = new JsBinaryOperation(JsBinaryOperator.COMMA, reassignment, getNewValue);
    } else {
        context().getCurrentBlock().getStatements().addAll(accessBlock.getStatements());
        result = getNewValue;
    }
    MetadataProperties.setSynthetic(result, true);
    return result;
}
Also used : JsExpression(org.jetbrains.kotlin.js.backend.ast.JsExpression) JsBinaryOperation(org.jetbrains.kotlin.js.backend.ast.JsBinaryOperation) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with JsBinaryOperation

use of org.jetbrains.kotlin.js.backend.ast.JsBinaryOperation 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)

Aggregations

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