use of org.jetbrains.kotlin.js.backend.ast.JsExpression in project kotlin by JetBrains.
the class PatternTranslator method translateIsCheck.
@Nullable
public JsExpression translateIsCheck(@NotNull JsExpression subject, @NotNull KtTypeReference targetTypeReference) {
KotlinType targetType = getTypeByReference(bindingContext(), targetTypeReference);
JsExpression checkFunReference = doGetIsTypeCheckCallable(targetType);
if (checkFunReference == null) {
return null;
}
boolean isReifiedType = isReifiedTypeParameter(targetType);
if (!isReifiedType && isNullableType(targetType) || isReifiedType && findChildByType(targetTypeReference, KtNodeTypes.NULLABLE_TYPE) != null) {
checkFunReference = namer().orNull(checkFunReference);
}
return new JsInvocation(checkFunReference, subject);
}
use of org.jetbrains.kotlin.js.backend.ast.JsExpression in project kotlin by JetBrains.
the class InOperationTranslator method translateInt.
@NotNull
private JsExpression translateInt(@NotNull KtExpression lowerExpression, @NotNull KtExpression upperExpression) {
JsExpression lower = Translation.translateAsExpression(lowerExpression, context());
JsExpression upper = Translation.translateAsExpression(upperExpression, context());
if (!negated) {
JsExpression first = JsAstUtils.greaterThanEq(left, lower);
JsExpression second = JsAstUtils.lessThanEq(left, upper);
return JsAstUtils.and(first, second);
} else {
JsExpression first = JsAstUtils.lessThan(left, lower);
JsExpression second = JsAstUtils.greaterThan(left, upper);
return JsAstUtils.or(first, second);
}
}
use of org.jetbrains.kotlin.js.backend.ast.JsExpression 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.JsExpression in project kotlin by JetBrains.
the class IncrementTranslator method asPostfix.
//TODO: decide if this expression can be optimised in case of direct access (not property)
@NotNull
private JsExpression asPostfix() {
// code fragment: expr(a++)
// generate: expr( (t1 = a, t2 = t1, a = t1.inc(), t2) )
TemporaryVariable t1 = context().declareTemporary(accessTranslator.translateAsGet());
accessBlock.getStatements().add(t1.assignmentStatement());
JsExpression variableReassignment = variableReassignment(context().innerBlock(accessBlock), t1.reference());
accessBlock.getStatements().add(JsAstUtils.asSyntheticStatement(variableReassignment));
JsExpression result;
if (accessBlock.getStatements().size() == 2) {
result = AstUtil.newSequence(t1.assignmentExpression(), variableReassignment, t1.reference());
} else {
context().getCurrentBlock().getStatements().addAll(accessBlock.getStatements());
result = t1.reference();
}
MetadataProperties.setSynthetic(result, true);
return result;
}
use of org.jetbrains.kotlin.js.backend.ast.JsExpression 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