use of org.jetbrains.kotlin.js.backend.ast.JsExpression 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.JsExpression in project kotlin by JetBrains.
the class VariableAccessTranslator method translateAsGet.
@NotNull
@Override
public JsExpression translateAsGet() {
JsExpression e = CallTranslator.INSTANCE.translateGet(context(), resolvedCall, receiver);
CallableDescriptor original = resolvedCall.getResultingDescriptor().getOriginal();
if (original instanceof PropertyDescriptor) {
PropertyGetterDescriptor getter = ((PropertyDescriptor) original).getGetter();
if (InlineUtil.isInline(getter)) {
if (e instanceof JsNameRef) {
// Get was translated as a name reference
setInlineCallMetadata((JsNameRef) e, referenceExpression, getter);
} else {
setInlineCallMetadata(e, referenceExpression, getter, context());
}
}
}
return e;
}
use of org.jetbrains.kotlin.js.backend.ast.JsExpression 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.JsExpression in project kotlin by JetBrains.
the class PatternTranslator method getIsTypeCheckCallableForReifiedType.
@NotNull
private JsExpression getIsTypeCheckCallableForReifiedType(@NotNull TypeParameterDescriptor typeParameter) {
assert typeParameter.isReified() : "Expected reified type, actual: " + typeParameter;
DeclarationDescriptor containingDeclaration = typeParameter.getContainingDeclaration();
assert containingDeclaration instanceof CallableDescriptor : "Expected type parameter " + typeParameter + " to be contained in CallableDescriptor, actual: " + containingDeclaration.getClass();
JsExpression alias = context().getAliasForDescriptor(typeParameter);
assert alias != null : "No alias found for reified type parameter: " + typeParameter;
return alias;
}
use of org.jetbrains.kotlin.js.backend.ast.JsExpression in project kotlin by JetBrains.
the class PatternTranslator method translateCastExpression.
@NotNull
public JsExpression translateCastExpression(@NotNull KtBinaryExpressionWithTypeRHS expression) {
assert isCastExpression(expression) : "Expected cast expression, got " + expression;
KtExpression left = expression.getLeft();
JsExpression expressionToCast = Translation.translateAsExpression(left, context());
KtTypeReference typeReference = expression.getRight();
assert typeReference != null : "Cast expression must have type reference";
KotlinType leftType = context().bindingContext().getType(left);
if (leftType != null && KotlinBuiltIns.isChar(leftType)) {
expressionToCast = JsAstUtils.charToBoxedChar(expressionToCast);
}
TemporaryVariable temporary = context().declareTemporary(expressionToCast);
JsExpression isCheck = translateIsCheck(temporary.assignmentExpression(), typeReference);
if (isCheck == null)
return expressionToCast;
JsExpression onFail;
if (isSafeCast(expression)) {
onFail = JsLiteral.NULL;
} else {
JsExpression throwCCEFunRef = Namer.throwClassCastExceptionFunRef();
onFail = new JsInvocation(throwCCEFunRef);
}
JsExpression result = new JsConditional(isCheck, temporary.reference(), onFail);
KotlinType expressionType = context().bindingContext().getType(expression);
if (expressionType != null && KotlinBuiltIns.isCharOrNullableChar(expressionType)) {
result = JsAstUtils.boxedCharToChar(result);
}
return result;
}
Aggregations