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