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);
}
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));
}
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;
}
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;
}
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);
}
Aggregations